Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }>;
Expand Down
20 changes: 20 additions & 0 deletions packages/webui/test/unit/ssh-endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -111,6 +130,7 @@ describe("a saved host", () => {
dataDir: temporaryDataDir(),
transport,
homeDirectory: () => HOME,
discovery: syntheticDiscovery("textvision.top"),
});

const saved = await runtime.connections.save({
Expand Down
Loading