From 718b526b2e4687a1aafd4f67d62be606b4d41266 Mon Sep 17 00:00:00 2001 From: probe Date: Tue, 10 Nov 2026 08:20:30 +0800 Subject: [PATCH] test(webui): stop three tests depending on the machine and on request order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new baseline fails 15 tests on macOS in CI. Three more failed only on a machine with its own `~/.ssh/config`, and one of the fifteen failed here too because it read a race rather than a request. The SSH test claimed that a host named in the config file keeps its alias, but it injected no discovery, so the runtime read the machine's real `~/.ssh/config`. On a machine that does not declare `textvision.top` the host is absent from the config and the save is refused; on a CI machine the file does not exist, the config is unreadable, and the runtime says nothing about the alias — so the test passed there by accident. The repository already has the right pattern: `ssh-connection-service.test.ts` injects a synthetic discovery and reads without touching the machine's own. This file was the one that missed it. The two model-stub tests read `stub.requests[0]` as the user's turn, but the runtime sends the background session-title request to the same endpoint and it can win the race. Worse, waiting for "at least one request" is satisfied by the title request, so the assertion ran before the turn's request had been sent at all. The turn's own stream is now consumed first — the turn is not over until the runtime has sent it — and the turn request is identified by the absence of the `submit_session_title` tool. The expected values do not change; only what is read, and when. Verified against the reverse: injecting a config that declares a different alias fails before this change and passes after it; filtering for the title request instead of the turn fails; and dropping the stream consumption fails two times out of three. The three files pass four consecutive runs. The 15 remaining failures are the ones the baseline already fails in CI, and the upstream repair for them is in progress at PR #11. --- .../real-host-capability-surface.test.ts | 7 ++++++- .../real-host-skill-catalog.test.ts | 7 ++++++- packages/webui/test/unit/ssh-endpoint.test.ts | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/webui/test/integration/real-host-capability-surface.test.ts b/packages/webui/test/integration/real-host-capability-surface.test.ts index 0f8463f3..f6600f4f 100644 --- a/packages/webui/test/integration/real-host-capability-surface.test.ts +++ b/packages/webui/test/integration/real-host-capability-surface.test.ts @@ -286,8 +286,13 @@ describe("the real host, the capability surface a turn offers", () => { content: "what can you do?", }); expect(sent.ok).toBe(true); + // The turn's own stream is consumed before anything is asserted: the request this + // file reads is the turn's, and the turn is not over until the runtime has sent it. if (sent.ok) for await (const _frame of sent.source) void _frame; - // 后台标题请求也使用该端点,不能把先到的请求当成用户 turn。 + // The runtime sends the background title request to the same model endpoint, and it can + // win the race to it. The title request carries `submit_session_title`; the user's turn + // does not. Reading the first request therefore reads whichever arrived first, which on + // a machine where the title wins is not the turn whose skills and tools this file reads. const turnRequests = stub.requests .map((request) => JSON.parse(request.body) as ModelRequest) .filter((request) => !extractToolNames(request).includes("submit_session_title")); diff --git a/packages/webui/test/integration/real-host-skill-catalog.test.ts b/packages/webui/test/integration/real-host-skill-catalog.test.ts index 26f21dbf..358eb702 100644 --- a/packages/webui/test/integration/real-host-skill-catalog.test.ts +++ b/packages/webui/test/integration/real-host-skill-catalog.test.ts @@ -246,8 +246,13 @@ async function runTurnAndReadCatalog(betaMcodeTools: boolean | undefined): Promi const sent = await port.sendMessage({ id: sessionId as string, content: "hello stub" }); expect(sent.ok).toBe(true); + // The turn's own stream is consumed before anything is asserted: the request this file + // reads is the turn's, and the turn is not over until the runtime has sent it. if (sent.ok) for await (const _frame of sent.source) void _frame; - // The background title request can win the race to the same model endpoint. + // The runtime sends the background title request to the same model endpoint, and it can + // win the race to it. The title request carries `submit_session_title`; the user's turn + // does not. Reading the first request therefore reads whichever arrived first, which on + // a machine where the title wins is not the turn whose skill catalog this file reads. const turnRequests = stub.requests.filter((request) => { const body = JSON.parse(request.body) as { readonly tools?: ReadonlyArray<{ readonly function?: { readonly name?: string } }>; diff --git a/packages/webui/test/unit/ssh-endpoint.test.ts b/packages/webui/test/unit/ssh-endpoint.test.ts index 9a074247..50a654e9 100644 --- a/packages/webui/test/unit/ssh-endpoint.test.ts +++ b/packages/webui/test/unit/ssh-endpoint.test.ts @@ -21,6 +21,7 @@ import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { buildSshArgs, SSH_PROBE_MARKER } from "../../src/runtime/ssh/command.js"; +import type { SshDiscoveryDependencies } from "../../src/runtime/ssh/host-discovery.js"; import { createSshRuntime } from "../../src/runtime/ssh/index.js"; import type { SshTransport } from "../../src/runtime/ssh/transport.js"; import { normalizeSshIdentityFile } from "../../src/runtime/ssh/validators.js"; @@ -63,6 +64,24 @@ afterEach(() => { } }); +/** + * A config file that declares one host, read without touching the machine's own. + * + * The runtime asks the discovery whether the config still declares an alias before it + * saves a host that is reached by that alias alone. Without an injected discovery the + * runtime reads the machine's real `~/.ssh/config`, so this file's claim — that a host + * named in the config file keeps its alias — would hold only on a machine that happens + * to declare this alias. The dependency is what makes the claim true everywhere. + */ +function syntheticDiscovery(alias: string): SshDiscoveryDependencies { + return { + readTextFile: async () => `Host ${alias}\n HostName example.com\n User builder\n`, + listFiles: async () => [], + runCommand: async () => ({ stdout: "", stderr: "" }), + homeDirectory: () => HOME, + }; +} + describe("a key path", () => { it("expands the tilde the way OpenSSH writes it", () => { expect(normalizeSshIdentityFile("~/.ssh/id_ed25519", HOME)).toBe(path.join(HOME, ".ssh", "id_ed25519")); @@ -111,6 +130,7 @@ describe("a saved host", () => { dataDir: temporaryDataDir(), transport, homeDirectory: () => HOME, + discovery: syntheticDiscovery("textvision.top"), }); const saved = await runtime.connections.save({