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({