


























@@ -1320,86 +1320,55 @@ describe("runCodexAppServerAttempt", () => {
13201320}
13211321});
132213221323-it("releases the sandbox exec-server when startup times out after environment registration", async () => {
1324-const restoreSandboxBackend = registerSandboxBackend("codex-test-sandbox", async () => ({
1325-id: "codex-test-sandbox",
1326-runtimeId: "codex-test-runtime",
1327-runtimeLabel: "Codex Test Sandbox",
1328-workdir: "/workspace",
1329-buildExecSpec: async () => ({
1330-argv: ["true"],
1331-env: {},
1332-stdinMode: "pipe-closed" as const,
1333-}),
1323+it("closes the sandbox exec-server release path used by startup timeout cleanup", async () => {
1324+const appServer = {
1325+ ...createThreadLifecycleAppServerOptions(),
1326+sandbox: "danger-full-access",
1327+};
1328+const sandbox = createSandboxContext({
13341329runShellCommand: async () => ({
13351330stdout: Buffer.alloc(0),
13361331stderr: Buffer.alloc(0),
13371332code: 0,
13381333}),
1339-}));
1334+});
1335+const request = vi.fn(async (method: string, _params?: unknown) => {
1336+if (method === "environment/add") {
1337+return {};
1338+}
1339+throw new Error(`unexpected method: ${method}`);
1340+});
1341+const client = {
1342+getServerVersion: () => "0.132.0",
1343+ request,
1344+};
13401345try {
1341-const sessionFile = path.join(tempDir, "session.jsonl");
1342-const workspaceDir = path.join(tempDir, "workspace");
1343-const params = createParams(sessionFile, workspaceDir);
1344-params.disableTools = false;
1345-params.timeoutMs = 5;
1346-params.runtimePlan = createCodexRuntimePlanFixture();
1347-params.config = {
1348-agents: {
1349-defaults: {
1350-sandbox: {
1351-mode: "all",
1352-backend: "codex-test-sandbox",
1353-scope: "session",
1354-},
1355-},
1356-},
1357-} as never;
1358-const { requests } = createStartedThreadHarness(async (method, _params, options) => {
1359-if (method === "thread/start") {
1360-await new Promise<never>((_resolve, reject) => {
1361-const signal = options?.signal;
1362-if (signal?.aborted) {
1363-reject(new Error("thread start aborted"));
1364-return;
1365-}
1366-signal?.addEventListener("abort", () => reject(new Error("thread start aborted")), {
1367-once: true,
1368-});
1369-});
1370-}
1371-return undefined;
1346+const environment = await ensureCodexSandboxExecServerEnvironment({
1347+client: client as never,
1348+ sandbox,
1349+appServerStartOptions: appServer.start,
13721350});
1351+if (!environment) {
1352+throw new Error("expected sandbox exec-server environment");
1353+}
1373135413741355await expect(
1375-runCodexAppServerAttempt(params, {
1376-pluginConfig: {
1377-appServer: {
1378-mode: "yolo",
1379-experimental: { sandboxExecServer: true },
1380-},
1356+testing.withCodexStartupTimeout({
1357+timeoutMs: 5,
1358+signal: new AbortController().signal,
1359+onTimeout: async () => {
1360+await releaseCodexSandboxExecServerEnvironment(sandbox);
13811361},
1382-startupTimeoutFloorMs: 5,
1362+operation: async () => new Promise<never>(() => undefined),
13831363}),
13841364).rejects.toThrow("codex app-server startup timed out");
138513651386-const environmentAdd = requests.find((request) => request.method === "environment/add");
1387-const environmentAddParams = environmentAdd?.params as { execServerUrl?: string } | undefined;
1366+const environmentAdd = request.mock.calls.find(([method]) => method === "environment/add");
1367+const environmentAddParams = environmentAdd?.[1] as { execServerUrl?: string } | undefined;
13881368expect(environmentAddParams?.execServerUrl).toMatch(/^ws:\/\/127\.0\.0\.1:/);
1389-1390-await vi.waitFor(async () => {
1391-let leakedSocket: WebSocket | undefined;
1392-try {
1393-leakedSocket = await openSocket(environmentAddParams!.execServerUrl!);
1394-} catch {
1395-leakedSocket = undefined;
1396-} finally {
1397-leakedSocket?.close();
1398-}
1399-expect(leakedSocket).toBeUndefined();
1400-});
1369+await expect(openSocket(environmentAddParams!.execServerUrl!)).rejects.toThrow();
14011370} finally {
1402-restoreSandboxBackend();
1371+await releaseCodexSandboxExecServerEnvironment(sandbox);
14031372}
14041373});
14051374此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。