mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-23 08:45:14 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
184328e6fb | ||
|
|
07235fe2ea | ||
|
|
3389138eb7 |
@@ -340,6 +340,11 @@ jobs:
|
||||
src/server/plugins/index.posix.test.ts \
|
||||
-t "reaps compiler children" --bail=1
|
||||
|
||||
- name: Verify plugin session sockets survive a dead plugin child
|
||||
run: |
|
||||
npm run test:unit --workspace=@getpaseo/server -- \
|
||||
src/server/plugins/session-socket.posix.test.ts --bail=1
|
||||
|
||||
desktop-tests-ubuntu:
|
||||
name: desktop-tests (ubuntu-latest)
|
||||
needs: changes
|
||||
|
||||
@@ -94,6 +94,19 @@ describe("Hub session protocol", () => {
|
||||
expect(SessionOutboundMessageSchema.parse(response)).toEqual(response);
|
||||
});
|
||||
|
||||
test("round-trips the working directory on named-agent validation", () => {
|
||||
const request = {
|
||||
type: "hub.execution.agent.validate.request",
|
||||
requestId: "validate-workspace",
|
||||
provider: "opencode",
|
||||
model: "workspace-model",
|
||||
cwd: "/workspace",
|
||||
};
|
||||
|
||||
expect(SessionInboundMessageSchema.parse(request)).toEqual(request);
|
||||
expect(SessionInboundMessageSchema.safeParse({ ...request, cwd: 123 }).success).toBe(false);
|
||||
});
|
||||
|
||||
test("accepts the Hub execution create request", () => {
|
||||
const message = {
|
||||
type: "hub.execution.agent.create.request",
|
||||
|
||||
@@ -3465,6 +3465,7 @@ export const HubExecutionAgentValidateRequestSchema = z.object({
|
||||
type: z.literal("hub.execution.agent.validate.request"),
|
||||
requestId: z.string(),
|
||||
provider: z.string(),
|
||||
cwd: z.string().optional(),
|
||||
model: z.string().optional(),
|
||||
modeId: z.string().optional(),
|
||||
thinkingOptionId: z.string().optional(),
|
||||
|
||||
@@ -6,6 +6,7 @@ import { filterSelectableAgentModels } from "./agent-sdk-types.js";
|
||||
|
||||
export interface AgentConfigurationValidationInput {
|
||||
provider: string;
|
||||
cwd?: string;
|
||||
model?: string;
|
||||
modeId?: string;
|
||||
thinkingOptionId?: string;
|
||||
|
||||
@@ -321,6 +321,40 @@ describe("ProviderSnapshotManager public surface", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("validates workspace-only models against the requested working directory", async () => {
|
||||
const cwd = resolveSnapshotCwd("/tmp/workspace-models");
|
||||
const model = { provider: "opencode", id: "workspace-model", label: "Workspace model" };
|
||||
const manager = new ProviderSnapshotManager({
|
||||
logger: createTestLogger(),
|
||||
extraClients: {
|
||||
opencode: createExtraClient("opencode", {
|
||||
isAvailable: async () => true,
|
||||
fetchCatalog: async (options) => ({
|
||||
models: options.scope === "workspace" && options.cwd === cwd ? [model] : [],
|
||||
modes: [],
|
||||
}),
|
||||
}),
|
||||
},
|
||||
});
|
||||
const input = { provider: model.provider, model: model.id };
|
||||
const unavailable = [
|
||||
{
|
||||
path: ["model"],
|
||||
message: "Model 'workspace-model' is not available for provider 'opencode'",
|
||||
},
|
||||
];
|
||||
|
||||
try {
|
||||
await expect(manager.validateAgentConfiguration(input)).resolves.toEqual(unavailable);
|
||||
await expect(manager.validateAgentConfiguration({ ...input, cwd })).resolves.toEqual([]);
|
||||
await expect(
|
||||
manager.validateAgentConfiguration({ ...input, cwd: "/tmp/missing-workspace" }),
|
||||
).resolves.toEqual(unavailable);
|
||||
} finally {
|
||||
manager.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
test("accepts a legacy Ultra Code choice on a model with an independent effort catalog", async () => {
|
||||
const manager = new ProviderSnapshotManager({
|
||||
logger: createTestLogger(),
|
||||
|
||||
@@ -650,6 +650,7 @@ export class ProviderSnapshotManager {
|
||||
|
||||
const provider = await this.getProvider({
|
||||
provider: input.provider,
|
||||
cwd: input.cwd,
|
||||
wait: true,
|
||||
});
|
||||
if (!provider.enabled) {
|
||||
|
||||
@@ -86,23 +86,29 @@ class RejectingHubExecutionAgents implements HubExecutionAgents {
|
||||
}
|
||||
|
||||
describe("HubExecutionController", () => {
|
||||
test("validates a named agent through the daemon provider registry", async () => {
|
||||
test.each([
|
||||
{ cwd: "/workspace", valid: true },
|
||||
{ cwd: undefined, valid: false },
|
||||
{ cwd: "/missing-workspace", valid: false },
|
||||
])("validates a named agent with cwd $cwd", async ({ cwd, valid }) => {
|
||||
const messages: SessionOutboundMessage[] = [];
|
||||
const unavailable = { path: ["model"], message: "Model is unavailable" };
|
||||
const validateAgentConfiguration = async (
|
||||
message: Omit<HubExecutionAgentValidateRequest, "type" | "requestId">,
|
||||
) =>
|
||||
message.model === "missing" ? [{ path: ["model"], message: "Model is unavailable" }] : [];
|
||||
input: Omit<HubExecutionAgentValidateRequest, "type" | "requestId">,
|
||||
) => (input.model === "workspace-model" && input.cwd === "/workspace" ? [] : [unavailable]);
|
||||
const controller = new HubExecutionController({
|
||||
agents: new ControlledHubExecutionAgents(),
|
||||
validateAgentConfiguration,
|
||||
send: (message) => messages.push(message),
|
||||
});
|
||||
|
||||
const scope = cwd === undefined ? {} : { cwd };
|
||||
await controller.validateAgent({
|
||||
type: "hub.execution.agent.validate.request",
|
||||
requestId: "validate-agent",
|
||||
provider: "codex",
|
||||
model: "missing",
|
||||
provider: "opencode",
|
||||
model: "workspace-model",
|
||||
...scope,
|
||||
});
|
||||
|
||||
expect(messages).toEqual([
|
||||
@@ -110,8 +116,8 @@ describe("HubExecutionController", () => {
|
||||
type: "hub.execution.agent.validate.response",
|
||||
payload: {
|
||||
requestId: "validate-agent",
|
||||
valid: false,
|
||||
issues: [{ path: ["model"], message: "Model is unavailable" }],
|
||||
valid,
|
||||
issues: valid ? [] : [unavailable],
|
||||
error: null,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -87,6 +87,7 @@ export class HubExecutionController {
|
||||
try {
|
||||
issues = await this.validateAgentConfiguration({
|
||||
provider: message.provider,
|
||||
cwd: message.cwd,
|
||||
model: message.model,
|
||||
modeId: message.modeId,
|
||||
thinkingOptionId: message.thinkingOptionId,
|
||||
|
||||
@@ -1,16 +1,46 @@
|
||||
import { fork } from "node:child_process";
|
||||
import { type ChildProcess, execFileSync, fork } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { PluginProcessMessage } from "./plugin-process-protocol.js";
|
||||
import { PluginSessionSocket } from "./session-socket.js";
|
||||
|
||||
function forkEchoChild(): ChildProcess {
|
||||
return fork(
|
||||
fileURLToPath(new URL("./test-fixtures/plugin-session-echo.cjs", import.meta.url)),
|
||||
[],
|
||||
{ serialization: "advanced", stdio: ["ignore", "ignore", "ignore", "ipc"] },
|
||||
);
|
||||
}
|
||||
|
||||
async function waitForSpawn(child: ChildProcess): Promise<number> {
|
||||
await new Promise<void>((resolve) => child.once("spawn", () => resolve()));
|
||||
if (child.pid === undefined) throw new Error("Child process has no pid");
|
||||
return child.pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocks the event loop until the child is dead, so the parent has not yet read the
|
||||
* IPC hang-up: `child.connected` is still true and the next write fails with EPIPE.
|
||||
* A busy daemon sits in the same window between a plugin dying and Node noticing.
|
||||
*/
|
||||
function killAndWaitUnnoticed(child: ChildProcess, pid: number): void {
|
||||
child.kill("SIGKILL");
|
||||
execFileSync("sh", [
|
||||
"-c",
|
||||
'while kill -0 "$1" 2>/dev/null && [ "$(ps -o stat= -p "$1" | cut -c1)" != Z ]; do sleep 0.01; done',
|
||||
"sh",
|
||||
String(pid),
|
||||
]);
|
||||
}
|
||||
|
||||
async function settle(): Promise<void> {
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
}
|
||||
|
||||
describe("PluginSessionSocket child-process transport", () => {
|
||||
it("round-trips ordered text and binary frames through a real child process", async () => {
|
||||
const child = fork(
|
||||
fileURLToPath(new URL("./test-fixtures/plugin-session-echo.cjs", import.meta.url)),
|
||||
[],
|
||||
{ serialization: "advanced", stdio: ["ignore", "ignore", "ignore", "ipc"] },
|
||||
);
|
||||
const child = forkEchoChild();
|
||||
const socket = new PluginSessionSocket(child);
|
||||
const received: Array<string | Uint8Array> = [];
|
||||
socket.on("message", (data) => received.push(data as string | Uint8Array));
|
||||
@@ -29,4 +59,57 @@ describe("PluginSessionSocket child-process transport", () => {
|
||||
child.kill();
|
||||
}
|
||||
});
|
||||
|
||||
// Without an "error" listener, an error event on the child is an uncaught exception
|
||||
// that crashes the daemon. The listeners below only record what the daemon would throw.
|
||||
// Waiting for the child without running the event loop needs `sh`, `kill` and `ps`.
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"closes after a frame write to a dead child fails with EPIPE",
|
||||
async () => {
|
||||
const child = forkEchoChild();
|
||||
const pid = await waitForSpawn(child);
|
||||
const childErrors: unknown[] = [];
|
||||
child.on("error", (error) => childErrors.push(error));
|
||||
const socket = new PluginSessionSocket(child);
|
||||
let closed = false;
|
||||
socket.on("close", () => {
|
||||
closed = true;
|
||||
});
|
||||
let sendError: Error | undefined;
|
||||
|
||||
killAndWaitUnnoticed(child, pid);
|
||||
// The websocket server's outbound transport closes the socket when a write fails.
|
||||
socket.send("frame", (error) => {
|
||||
sendError = error;
|
||||
socket.close();
|
||||
});
|
||||
await settle();
|
||||
|
||||
expect(sendError).toMatchObject({ code: "EPIPE" });
|
||||
expect(closed).toBe(true);
|
||||
expect(childErrors).toEqual([]);
|
||||
},
|
||||
);
|
||||
|
||||
it("closes after the child's IPC channel has disconnected", async () => {
|
||||
const child = forkEchoChild();
|
||||
await waitForSpawn(child);
|
||||
const childErrors: unknown[] = [];
|
||||
child.on("error", (error) => childErrors.push(error));
|
||||
const socket = new PluginSessionSocket(child);
|
||||
let closed = false;
|
||||
socket.on("close", () => {
|
||||
closed = true;
|
||||
});
|
||||
const disconnected = new Promise<void>((resolve) => child.once("disconnect", () => resolve()));
|
||||
|
||||
child.kill("SIGKILL");
|
||||
await disconnected;
|
||||
socket.close();
|
||||
await settle();
|
||||
|
||||
expect(child.connected).toBe(false);
|
||||
expect(closed).toBe(true);
|
||||
expect(childErrors).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,11 +57,9 @@ export class PluginSessionSocket {
|
||||
close(code?: number, reason?: string): void {
|
||||
if (this.readyState === 3) return;
|
||||
this.readyState = 3;
|
||||
try {
|
||||
this.child.send({ type: "paseo_close" });
|
||||
} catch {
|
||||
// The child has already gone; local session cleanup still has to run.
|
||||
}
|
||||
// Node reports a failed send to the callback, or else as an "error" event on the child,
|
||||
// which nothing handles. The child may already be gone; local cleanup still has to run.
|
||||
this.child.send({ type: "paseo_close" }, () => undefined);
|
||||
this.emit("close", code, reason);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user