@microvac/adapter-codex-local 0.0.0-stage → 0.1.0-rc.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/format-event.d.ts +2 -0
- package/dist/cli/format-event.d.ts.map +1 -0
- package/dist/cli/format-event.js +218 -0
- package/dist/cli/format-event.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/quota-probe.d.ts +3 -0
- package/dist/cli/quota-probe.d.ts.map +1 -0
- package/dist/cli/quota-probe.js +104 -0
- package/dist/cli/quota-probe.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +268 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +125 -0
- package/dist/index.test.js.map +1 -0
- package/dist/server/acp.cli-version.test.d.ts +2 -0
- package/dist/server/acp.cli-version.test.d.ts.map +1 -0
- package/dist/server/acp.cli-version.test.js +151 -0
- package/dist/server/acp.cli-version.test.js.map +1 -0
- package/dist/server/acp.d.ts +31 -0
- package/dist/server/acp.d.ts.map +1 -0
- package/dist/server/acp.js +608 -0
- package/dist/server/acp.js.map +1 -0
- package/dist/server/acp.quota.test.d.ts +2 -0
- package/dist/server/acp.quota.test.d.ts.map +1 -0
- package/dist/server/acp.quota.test.js +176 -0
- package/dist/server/acp.quota.test.js.map +1 -0
- package/dist/server/acp.test.d.ts +2 -0
- package/dist/server/acp.test.d.ts.map +1 -0
- package/dist/server/acp.test.js +1263 -0
- package/dist/server/acp.test.js.map +1 -0
- package/dist/server/adapter-auth-promotion.d.ts +102 -0
- package/dist/server/adapter-auth-promotion.d.ts.map +1 -0
- package/dist/server/adapter-auth-promotion.js +210 -0
- package/dist/server/adapter-auth-promotion.js.map +1 -0
- package/dist/server/adapter-auth-promotion.test.d.ts +2 -0
- package/dist/server/adapter-auth-promotion.test.d.ts.map +1 -0
- package/dist/server/adapter-auth-promotion.test.js +615 -0
- package/dist/server/adapter-auth-promotion.test.js.map +1 -0
- package/dist/server/auth-check.d.ts +8 -0
- package/dist/server/auth-check.d.ts.map +1 -0
- package/dist/server/auth-check.js +8 -0
- package/dist/server/auth-check.js.map +1 -0
- package/dist/server/auth-precedence.d.ts +16 -0
- package/dist/server/auth-precedence.d.ts.map +1 -0
- package/dist/server/auth-precedence.js +20 -0
- package/dist/server/auth-precedence.js.map +1 -0
- package/dist/server/auth-precedence.test.d.ts +2 -0
- package/dist/server/auth-precedence.test.d.ts.map +1 -0
- package/dist/server/auth-precedence.test.js +100 -0
- package/dist/server/auth-precedence.test.js.map +1 -0
- package/dist/server/cli-version.d.ts +45 -0
- package/dist/server/cli-version.d.ts.map +1 -0
- package/dist/server/cli-version.js +95 -0
- package/dist/server/cli-version.js.map +1 -0
- package/dist/server/codex-args.d.ts +13 -0
- package/dist/server/codex-args.d.ts.map +1 -0
- package/dist/server/codex-args.js +64 -0
- package/dist/server/codex-args.js.map +1 -0
- package/dist/server/codex-args.test.d.ts +2 -0
- package/dist/server/codex-args.test.d.ts.map +1 -0
- package/dist/server/codex-args.test.js +257 -0
- package/dist/server/codex-args.test.js.map +1 -0
- package/dist/server/codex-auth-cache.d.ts +179 -0
- package/dist/server/codex-auth-cache.d.ts.map +1 -0
- package/dist/server/codex-auth-cache.js +520 -0
- package/dist/server/codex-auth-cache.js.map +1 -0
- package/dist/server/codex-auth-cache.test.d.ts +2 -0
- package/dist/server/codex-auth-cache.test.d.ts.map +1 -0
- package/dist/server/codex-auth-cache.test.js +530 -0
- package/dist/server/codex-auth-cache.test.js.map +1 -0
- package/dist/server/codex-auth-copyback.d.ts +53 -0
- package/dist/server/codex-auth-copyback.d.ts.map +1 -0
- package/dist/server/codex-auth-copyback.js +123 -0
- package/dist/server/codex-auth-copyback.js.map +1 -0
- package/dist/server/codex-auth-copyback.test.d.ts +2 -0
- package/dist/server/codex-auth-copyback.test.d.ts.map +1 -0
- package/dist/server/codex-auth-copyback.test.js +507 -0
- package/dist/server/codex-auth-copyback.test.js.map +1 -0
- package/dist/server/codex-auth-merge-decision.cjs +170 -0
- package/dist/server/codex-auth-merge-decision.d.ts +22 -0
- package/dist/server/codex-auth-merge-decision.d.ts.map +1 -0
- package/dist/server/codex-auth-merge-decision.js +58 -0
- package/dist/server/codex-auth-merge-decision.js.map +1 -0
- package/dist/server/codex-auth-merge-decision.test.d.ts +2 -0
- package/dist/server/codex-auth-merge-decision.test.d.ts.map +1 -0
- package/dist/server/codex-auth-merge-decision.test.js +215 -0
- package/dist/server/codex-auth-merge-decision.test.js.map +1 -0
- package/dist/server/codex-auth-merge-extract.sh +73 -0
- package/dist/server/codex-auth-merge-scripts.d.ts +21 -0
- package/dist/server/codex-auth-merge-scripts.d.ts.map +1 -0
- package/dist/server/codex-auth-merge-scripts.js +40 -0
- package/dist/server/codex-auth-merge-scripts.js.map +1 -0
- package/dist/server/codex-auth-merge.test.d.ts +2 -0
- package/dist/server/codex-auth-merge.test.d.ts.map +1 -0
- package/dist/server/codex-auth-merge.test.js +714 -0
- package/dist/server/codex-auth-merge.test.js.map +1 -0
- package/dist/server/codex-auth-seed-write.d.ts +30 -0
- package/dist/server/codex-auth-seed-write.d.ts.map +1 -0
- package/dist/server/codex-auth-seed-write.js +41 -0
- package/dist/server/codex-auth-seed-write.js.map +1 -0
- package/dist/server/codex-home.d.ts +169 -0
- package/dist/server/codex-home.d.ts.map +1 -0
- package/dist/server/codex-home.js +822 -0
- package/dist/server/codex-home.js.map +1 -0
- package/dist/server/codex-home.test.d.ts +2 -0
- package/dist/server/codex-home.test.d.ts.map +1 -0
- package/dist/server/codex-home.test.js +1287 -0
- package/dist/server/codex-home.test.js.map +1 -0
- package/dist/server/config-schema.d.ts +3 -0
- package/dist/server/config-schema.d.ts.map +1 -0
- package/dist/server/config-schema.js +67 -0
- package/dist/server/config-schema.js.map +1 -0
- package/dist/server/device-login-export.d.ts +56 -0
- package/dist/server/device-login-export.d.ts.map +1 -0
- package/dist/server/device-login-export.js +230 -0
- package/dist/server/device-login-export.js.map +1 -0
- package/dist/server/device-login-export.test.d.ts +2 -0
- package/dist/server/device-login-export.test.d.ts.map +1 -0
- package/dist/server/device-login-export.test.js +245 -0
- package/dist/server/device-login-export.test.js.map +1 -0
- package/dist/server/device-login-parse.d.ts +20 -0
- package/dist/server/device-login-parse.d.ts.map +1 -0
- package/dist/server/device-login-parse.js +155 -0
- package/dist/server/device-login-parse.js.map +1 -0
- package/dist/server/device-login-parse.test.d.ts +2 -0
- package/dist/server/device-login-parse.test.d.ts.map +1 -0
- package/dist/server/device-login-parse.test.js +269 -0
- package/dist/server/device-login-parse.test.js.map +1 -0
- package/dist/server/device-login-runner.d.ts +69 -0
- package/dist/server/device-login-runner.d.ts.map +1 -0
- package/dist/server/device-login-runner.js +110 -0
- package/dist/server/device-login-runner.js.map +1 -0
- package/dist/server/device-login-runner.test.d.ts +2 -0
- package/dist/server/device-login-runner.test.d.ts.map +1 -0
- package/dist/server/device-login-runner.test.js +201 -0
- package/dist/server/device-login-runner.test.js.map +1 -0
- package/dist/server/engine-availability.test.d.ts +2 -0
- package/dist/server/engine-availability.test.d.ts.map +1 -0
- package/dist/server/engine-availability.test.js +41 -0
- package/dist/server/engine-availability.test.js.map +1 -0
- package/dist/server/execute.acp-fallback.test.d.ts +2 -0
- package/dist/server/execute.acp-fallback.test.d.ts.map +1 -0
- package/dist/server/execute.acp-fallback.test.js +123 -0
- package/dist/server/execute.acp-fallback.test.js.map +1 -0
- package/dist/server/execute.auth-precedence.test.d.ts +2 -0
- package/dist/server/execute.auth-precedence.test.d.ts.map +1 -0
- package/dist/server/execute.auth-precedence.test.js +137 -0
- package/dist/server/execute.auth-precedence.test.js.map +1 -0
- package/dist/server/execute.auth.test.d.ts +2 -0
- package/dist/server/execute.auth.test.d.ts.map +1 -0
- package/dist/server/execute.auth.test.js +197 -0
- package/dist/server/execute.auth.test.js.map +1 -0
- package/dist/server/execute.d.ts +40 -0
- package/dist/server/execute.d.ts.map +1 -0
- package/dist/server/execute.js +1485 -0
- package/dist/server/execute.js.map +1 -0
- package/dist/server/execute.remote.test.d.ts +2 -0
- package/dist/server/execute.remote.test.d.ts.map +1 -0
- package/dist/server/execute.remote.test.js +851 -0
- package/dist/server/execute.remote.test.js.map +1 -0
- package/dist/server/execute.ssh-host-auth.test.d.ts +2 -0
- package/dist/server/execute.ssh-host-auth.test.d.ts.map +1 -0
- package/dist/server/execute.ssh-host-auth.test.js +214 -0
- package/dist/server/execute.ssh-host-auth.test.js.map +1 -0
- package/dist/server/execute.stderr-error.test.d.ts +2 -0
- package/dist/server/execute.stderr-error.test.d.ts.map +1 -0
- package/dist/server/execute.stderr-error.test.js +142 -0
- package/dist/server/execute.stderr-error.test.js.map +1 -0
- package/dist/server/execute.test.d.ts +2 -0
- package/dist/server/execute.test.d.ts.map +1 -0
- package/dist/server/execute.test.js +300 -0
- package/dist/server/execute.test.js.map +1 -0
- package/dist/server/index.d.ts +18 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +84 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/output-inactivity-monitor.d.ts +62 -0
- package/dist/server/output-inactivity-monitor.d.ts.map +1 -0
- package/dist/server/output-inactivity-monitor.integration.test.d.ts +2 -0
- package/dist/server/output-inactivity-monitor.integration.test.d.ts.map +1 -0
- package/dist/server/output-inactivity-monitor.integration.test.js +136 -0
- package/dist/server/output-inactivity-monitor.integration.test.js.map +1 -0
- package/dist/server/output-inactivity-monitor.js +112 -0
- package/dist/server/output-inactivity-monitor.js.map +1 -0
- package/dist/server/output-inactivity-monitor.test.d.ts +2 -0
- package/dist/server/output-inactivity-monitor.test.d.ts.map +1 -0
- package/dist/server/output-inactivity-monitor.test.js +284 -0
- package/dist/server/output-inactivity-monitor.test.js.map +1 -0
- package/dist/server/parse.d.ts +69 -0
- package/dist/server/parse.d.ts.map +1 -0
- package/dist/server/parse.js +278 -0
- package/dist/server/parse.js.map +1 -0
- package/dist/server/parse.test.d.ts +2 -0
- package/dist/server/parse.test.d.ts.map +1 -0
- package/dist/server/parse.test.js +203 -0
- package/dist/server/parse.test.js.map +1 -0
- package/dist/server/process-activity-monitor.d.ts +21 -0
- package/dist/server/process-activity-monitor.d.ts.map +1 -0
- package/dist/server/process-activity-monitor.js +103 -0
- package/dist/server/process-activity-monitor.js.map +1 -0
- package/dist/server/process-activity-monitor.test.d.ts +2 -0
- package/dist/server/process-activity-monitor.test.d.ts.map +1 -0
- package/dist/server/process-activity-monitor.test.js +82 -0
- package/dist/server/process-activity-monitor.test.js.map +1 -0
- package/dist/server/quota-spawn-error.test.d.ts +2 -0
- package/dist/server/quota-spawn-error.test.d.ts.map +1 -0
- package/dist/server/quota-spawn-error.test.js +343 -0
- package/dist/server/quota-spawn-error.test.js.map +1 -0
- package/dist/server/quota.d.ts +66 -0
- package/dist/server/quota.d.ts.map +1 -0
- package/dist/server/quota.js +577 -0
- package/dist/server/quota.js.map +1 -0
- package/dist/server/runtime-config.d.ts +11 -0
- package/dist/server/runtime-config.d.ts.map +1 -0
- package/dist/server/runtime-config.js +389 -0
- package/dist/server/runtime-config.js.map +1 -0
- package/dist/server/runtime-config.test.d.ts +2 -0
- package/dist/server/runtime-config.test.d.ts.map +1 -0
- package/dist/server/runtime-config.test.js +389 -0
- package/dist/server/runtime-config.test.js.map +1 -0
- package/dist/server/skills.d.ts +8 -0
- package/dist/server/skills.d.ts.map +1 -0
- package/dist/server/skills.js +26 -0
- package/dist/server/skills.js.map +1 -0
- package/dist/server/ssh-host-runtime.d.ts +24 -0
- package/dist/server/ssh-host-runtime.d.ts.map +1 -0
- package/dist/server/ssh-host-runtime.js +84 -0
- package/dist/server/ssh-host-runtime.js.map +1 -0
- package/dist/server/ssh-session-state.d.ts +18 -0
- package/dist/server/ssh-session-state.d.ts.map +1 -0
- package/dist/server/ssh-session-state.js +11 -0
- package/dist/server/ssh-session-state.js.map +1 -0
- package/dist/server/test.d.ts +3 -0
- package/dist/server/test.d.ts.map +1 -0
- package/dist/server/test.js +531 -0
- package/dist/server/test.js.map +1 -0
- package/dist/server/test.remote.test.d.ts +2 -0
- package/dist/server/test.remote.test.d.ts.map +1 -0
- package/dist/server/test.remote.test.js +596 -0
- package/dist/server/test.remote.test.js.map +1 -0
- package/dist/ui/build-config.d.ts +10 -0
- package/dist/ui/build-config.d.ts.map +1 -0
- package/dist/ui/build-config.js +284 -0
- package/dist/ui/build-config.js.map +1 -0
- package/dist/ui/build-config.test.d.ts +2 -0
- package/dist/ui/build-config.test.d.ts.map +1 -0
- package/dist/ui/build-config.test.js +367 -0
- package/dist/ui/build-config.test.js.map +1 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +8 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/parse-stdout.d.ts +3 -0
- package/dist/ui/parse-stdout.d.ts.map +1 -0
- package/dist/ui/parse-stdout.js +265 -0
- package/dist/ui/parse-stdout.js.map +1 -0
- package/dist/ui/parse-stdout.test.d.ts +2 -0
- package/dist/ui/parse-stdout.test.d.ts.map +1 -0
- package/dist/ui/parse-stdout.test.js +77 -0
- package/dist/ui/parse-stdout.test.js.map +1 -0
- package/package.json +55 -4
- package/skills/agentmail/SKILL.md +70 -0
- package/skills/complain/LICENSE +27 -0
- package/skills/complain/SKILL.md +68 -0
- package/skills/paperclip/SKILL.md +864 -0
- package/skills/paperclip/references/api-reference.md +1814 -0
- package/skills/paperclip/references/artifacts.md +163 -0
- package/skills/paperclip/references/cases.md +570 -0
- package/skills/paperclip/references/company-skills.md +266 -0
- package/skills/paperclip/references/issue-documents.md +58 -0
- package/skills/paperclip/references/issue-workspaces.md +94 -0
- package/skills/paperclip/references/routines.md +249 -0
- package/skills/paperclip/references/run-diagnostics.md +28 -0
- package/skills/paperclip/references/workflows.md +141 -0
- package/skills/paperclip/scripts/paperclip-issue-update.sh +166 -0
- package/skills/paperclip/scripts/paperclip-upload-artifact.sh +603 -0
- package/skills/paperclip/scripts/submit-agent-commentary.mjs +52 -0
- package/skills/paperclip-board/SKILL.md +633 -0
- package/skills/paperclip-converting-plans-to-tasks/SKILL.md +28 -0
- package/skills/paperclip-create-agent/SKILL.md +213 -0
- package/skills/paperclip-create-agent/references/agent-instruction-templates.md +24 -0
- package/skills/paperclip-create-agent/references/agents/coder.md +18 -0
- package/skills/paperclip-create-agent/references/agents/qa.md +18 -0
- package/skills/paperclip-create-agent/references/agents/securityengineer.md +26 -0
- package/skills/paperclip-create-agent/references/agents/uxdesigner.md +18 -0
- package/skills/paperclip-create-agent/references/api-reference.md +110 -0
- package/skills/paperclip-create-agent/references/baseline-role-guide.md +22 -0
- package/skills/paperclip-create-agent/references/draft-review-checklist.md +29 -0
- package/skills/para-memory-files/SKILL.md +100 -0
- package/skills/para-memory-files/references/schemas.md +35 -0
- package/skills/slack/SKILL.md +92 -0
- package/skills/suggestion-box/LICENSE +27 -0
- package/skills/suggestion-box/SKILL.md +77 -0
- package/README.md +0 -3
|
@@ -0,0 +1,851 @@
|
|
|
1
|
+
import { cp, mkdir, mkdtemp, readdir, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
const { runChildProcess, executeAcp, ensureCommandResolvable, resolveCommandForLogs, prepareWorkspaceForSshExecution, restoreWorkspaceFromSshExecution, runSshCommand, syncDirectoryToSsh, startAdapterExecutionTargetPaperclipBridge, } = vi.hoisted(() => ({
|
|
8
|
+
executeAcp: vi.fn(async (_ctx) => ({ exitCode: 0, signal: null, timedOut: false, resultJson: { engine: "acp" } })),
|
|
9
|
+
runChildProcess: vi.fn(async () => ({
|
|
10
|
+
exitCode: 1,
|
|
11
|
+
signal: null,
|
|
12
|
+
timedOut: false,
|
|
13
|
+
stdout: "",
|
|
14
|
+
stderr: "remote failure",
|
|
15
|
+
pid: 123,
|
|
16
|
+
startedAt: new Date().toISOString(),
|
|
17
|
+
})),
|
|
18
|
+
ensureCommandResolvable: vi.fn(async () => undefined),
|
|
19
|
+
resolveCommandForLogs: vi.fn(async () => "/usr/bin/codex"),
|
|
20
|
+
prepareWorkspaceForSshExecution: vi.fn(async () => ({ gitBacked: false })),
|
|
21
|
+
restoreWorkspaceFromSshExecution: vi.fn(async () => undefined),
|
|
22
|
+
runSshCommand: vi.fn(async (_spec, _command) => ({ stdout: Buffer.from("{}").toString("base64"), stderr: "" })),
|
|
23
|
+
syncDirectoryToSsh: vi.fn(async (_input) => undefined),
|
|
24
|
+
startAdapterExecutionTargetPaperclipBridge: vi.fn(async () => ({
|
|
25
|
+
env: {
|
|
26
|
+
PAPERCLIP_API_URL: "http://127.0.0.1:4310",
|
|
27
|
+
PAPERCLIP_API_KEY: "bridge-token",
|
|
28
|
+
PAPERCLIP_API_BRIDGE_MODE: "queue_v1",
|
|
29
|
+
},
|
|
30
|
+
stop: async () => { },
|
|
31
|
+
})),
|
|
32
|
+
}));
|
|
33
|
+
vi.mock("./acp.js", async (importOriginal) => {
|
|
34
|
+
const actual = await importOriginal();
|
|
35
|
+
return { ...actual, createCodexAcpExecutor: () => executeAcp };
|
|
36
|
+
});
|
|
37
|
+
vi.mock("@paperclipai/adapter-utils/server-utils", async () => {
|
|
38
|
+
const actual = await vi.importActual("@paperclipai/adapter-utils/server-utils");
|
|
39
|
+
return {
|
|
40
|
+
...actual,
|
|
41
|
+
ensureCommandResolvable,
|
|
42
|
+
resolveCommandForLogs,
|
|
43
|
+
runChildProcess,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
vi.mock("@paperclipai/adapter-utils/ssh", async () => {
|
|
47
|
+
const actual = await vi.importActual("@paperclipai/adapter-utils/ssh");
|
|
48
|
+
return {
|
|
49
|
+
...actual,
|
|
50
|
+
prepareWorkspaceForSshExecution,
|
|
51
|
+
restoreWorkspaceFromSshExecution,
|
|
52
|
+
runSshCommand,
|
|
53
|
+
syncDirectoryToSsh,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
vi.mock("@paperclipai/adapter-utils/execution-target", async () => {
|
|
57
|
+
const actual = await vi.importActual("@paperclipai/adapter-utils/execution-target");
|
|
58
|
+
return {
|
|
59
|
+
...actual,
|
|
60
|
+
startAdapterExecutionTargetPaperclipBridge,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
import { createPromptContextFixture } from "@paperclipai/adapter-utils/test-fixtures/prompt-context";
|
|
64
|
+
import { execute } from "./execute.js";
|
|
65
|
+
import { sessionCodec } from "./index.js";
|
|
66
|
+
describe("codex remote execution", () => {
|
|
67
|
+
const cleanupDirs = [];
|
|
68
|
+
afterEach(async () => {
|
|
69
|
+
vi.clearAllMocks();
|
|
70
|
+
while (cleanupDirs.length > 0) {
|
|
71
|
+
const dir = cleanupDirs.pop();
|
|
72
|
+
if (!dir)
|
|
73
|
+
continue;
|
|
74
|
+
await rm(dir, { recursive: true, force: true }).catch(() => undefined);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
function managedSshAcpContext(engine) {
|
|
78
|
+
return {
|
|
79
|
+
runId: "managed-ssh-acp", agent: { id: "agent-1", companyId: "company-1", name: "Selected agent", adapterType: "codex_local", adapterConfig: {} },
|
|
80
|
+
runtime: { sessionId: null, sessionParams: null, sessionDisplayId: null, taskKey: "task" },
|
|
81
|
+
config: { engine, managedAiConnection: { provider: "openai", method: "subscription", identity: "selected-account" },
|
|
82
|
+
env: { OPENAI_API_KEY: "fixture-selected-token" } },
|
|
83
|
+
context: {}, onLog: async () => { },
|
|
84
|
+
executionTarget: { kind: "remote", transport: "ssh", remoteCwd: "/remote/workspace",
|
|
85
|
+
spec: { useHostAuth: false, host: "ssh.example.test", port: 22, username: "agent", remoteCwd: "/remote/workspace", remoteWorkspacePath: "/remote/workspace", privateKey: null, knownHosts: null, strictHostKeyChecking: true },
|
|
86
|
+
workspaceRealization: { mode: "copy", authoritativeRoot: "/remote/workspace", pathAliases: [], outboundRestorePaths: [] } },
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
it.each([undefined, "acp"].flatMap(engine => ["copy", "in_place"].map(mode => ({ engine, mode }))))("admits managed SSH ACP through the public execution entry (engine=$engine, workspace=$mode)", async ({ engine, mode }) => {
|
|
90
|
+
const ctx = managedSshAcpContext(engine);
|
|
91
|
+
ctx.executionTarget.workspaceRealization.mode = mode;
|
|
92
|
+
const actual = await vi.importActual("@paperclipai/adapter-utils/server-utils");
|
|
93
|
+
const bin = await mkdtemp(path.join(os.tmpdir(), "paperclip-ssh-client-probe-"));
|
|
94
|
+
cleanupDirs.push(bin);
|
|
95
|
+
await writeFile(path.join(bin, "ssh"), "#!/bin/sh\nexit 0\n", { mode: 0o700 });
|
|
96
|
+
const originalResolve = ensureCommandResolvable.getMockImplementation();
|
|
97
|
+
ensureCommandResolvable.mockImplementationOnce(actual.ensureCommandResolvable);
|
|
98
|
+
const previousPath = process.env.PATH;
|
|
99
|
+
process.env.PATH = bin;
|
|
100
|
+
const previous = process.env.OPENAI_API_KEY;
|
|
101
|
+
process.env.OPENAI_API_KEY = "fixture-server-secret";
|
|
102
|
+
try {
|
|
103
|
+
expect(await execute(ctx)).toMatchObject({ exitCode: 0, resultJson: { engine: "acp" } });
|
|
104
|
+
expect(executeAcp).toHaveBeenCalledWith(ctx);
|
|
105
|
+
const probe = ensureCommandResolvable.mock.calls[0];
|
|
106
|
+
expect(probe[0]).toBe("codex-acp");
|
|
107
|
+
expect(Object.keys(probe[2])).toEqual(["PATH"]);
|
|
108
|
+
expect(probe[2].PATH === bin).toBe(true);
|
|
109
|
+
expect(probe[3]).toMatchObject({ remoteExecution: { host: "ssh.example.test", useHostAuth: false } });
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
ensureCommandResolvable.mockReset().mockImplementation(originalResolve);
|
|
113
|
+
if (previousPath === undefined)
|
|
114
|
+
delete process.env.PATH;
|
|
115
|
+
else
|
|
116
|
+
process.env.PATH = previousPath;
|
|
117
|
+
if (previous === undefined)
|
|
118
|
+
delete process.env.OPENAI_API_KEY;
|
|
119
|
+
else
|
|
120
|
+
process.env.OPENAI_API_KEY = previous;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
it.each(["host auth", "legacy auth", "missing account", "confinement", "missing SSH client"])("rejects unsupported SSH ACP at the public execution entry: %s", async (reason) => {
|
|
124
|
+
const ctx = managedSshAcpContext("acp");
|
|
125
|
+
const originalResolve = ensureCommandResolvable.getMockImplementation();
|
|
126
|
+
if (reason === "host auth")
|
|
127
|
+
ctx.executionTarget.spec.useHostAuth = true;
|
|
128
|
+
if (reason === "legacy auth")
|
|
129
|
+
ctx.executionTarget.spec.useHostAuth = undefined;
|
|
130
|
+
if (reason === "missing account")
|
|
131
|
+
delete ctx.config.managedAiConnection;
|
|
132
|
+
if (reason === "confinement")
|
|
133
|
+
ctx.config.filesystemScope = "workspace";
|
|
134
|
+
const previousPath = process.env.PATH;
|
|
135
|
+
if (reason === "missing SSH client") {
|
|
136
|
+
const bin = await mkdtemp(path.join(os.tmpdir(), "paperclip-no-ssh-client-"));
|
|
137
|
+
cleanupDirs.push(bin);
|
|
138
|
+
process.env.PATH = bin;
|
|
139
|
+
const actual = await vi.importActual("@paperclipai/adapter-utils/server-utils");
|
|
140
|
+
ensureCommandResolvable.mockImplementationOnce(actual.ensureCommandResolvable);
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
expect(await execute(ctx)).toMatchObject({ exitCode: 1, errorCode: "adapter_engine_unavailable" });
|
|
144
|
+
expect(executeAcp).not.toHaveBeenCalled();
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
ensureCommandResolvable.mockReset().mockImplementation(originalResolve);
|
|
148
|
+
if (previousPath === undefined)
|
|
149
|
+
delete process.env.PATH;
|
|
150
|
+
else
|
|
151
|
+
process.env.PATH = previousPath;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
it.each([false, true])("retains a managed SSH Codex conversation across turns and removes credentials (second turn throws=%s)", async (fails) => {
|
|
155
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "paperclip-codex-ssh-resume-"));
|
|
156
|
+
cleanupDirs.push(root);
|
|
157
|
+
const workspace = path.join(root, "workspace"), home = path.join(root, "account"), secondHome = path.join(root, "next-invocation");
|
|
158
|
+
await mkdir(workspace);
|
|
159
|
+
await mkdir(home);
|
|
160
|
+
await mkdir(secondHome);
|
|
161
|
+
const auth = (account, marker, last_refresh) => JSON.stringify({ tokens: {
|
|
162
|
+
account_id: account, access_token: `fixture-access-${marker}`, refresh_token: `fixture-refresh-${marker}`, id_token: `fixture-id-${marker}`,
|
|
163
|
+
}, last_refresh });
|
|
164
|
+
const credential = auth("selected", "before", "2000-01-01T00:00:00Z");
|
|
165
|
+
const refreshed = auth("selected", "after", new Date().toISOString());
|
|
166
|
+
const otherCredential = auth("other", "other", "2000-01-01T00:00:00Z");
|
|
167
|
+
await writeFile(path.join(home, "auth.json"), credential);
|
|
168
|
+
await writeFile(path.join(secondHome, "auth.json"), credential);
|
|
169
|
+
const executeShell = promisify(execFile);
|
|
170
|
+
const originalRun = runChildProcess.getMockImplementation();
|
|
171
|
+
let firstRemoteHome;
|
|
172
|
+
let otherRemoteHome;
|
|
173
|
+
const privateRoots = [];
|
|
174
|
+
let calls = 0;
|
|
175
|
+
runSshCommand.mockImplementation(async (_spec, command) => {
|
|
176
|
+
const result = await executeShell("sh", ["-c", command]);
|
|
177
|
+
if (command.includes("mktemp -d"))
|
|
178
|
+
privateRoots.push(result.stdout.trim());
|
|
179
|
+
return result;
|
|
180
|
+
});
|
|
181
|
+
syncDirectoryToSsh.mockImplementation(async (input) => { await cp(input.localDir, input.remoteDir, { recursive: true }); });
|
|
182
|
+
runChildProcess.mockImplementation(async (...args) => {
|
|
183
|
+
const env = args[3].env;
|
|
184
|
+
const remoteHome = env.CODEX_HOME;
|
|
185
|
+
calls++;
|
|
186
|
+
expect(await readFile(path.join(remoteHome, "auth.json"), "utf8")).toBe(calls === 1 ? credential : calls === 2 ? refreshed : otherCredential);
|
|
187
|
+
if (calls === 1) {
|
|
188
|
+
firstRemoteHome = remoteHome;
|
|
189
|
+
await mkdir(path.join(remoteHome, "sessions"));
|
|
190
|
+
await writeFile(path.join(remoteHome, "sessions", "rollout.jsonl"), "fixture conversation");
|
|
191
|
+
await writeFile(path.join(remoteHome, "state_5.sqlite"), "fixture native index");
|
|
192
|
+
await writeFile(path.join(remoteHome, "auth.json"), refreshed);
|
|
193
|
+
}
|
|
194
|
+
else if (calls === 2) {
|
|
195
|
+
expect(remoteHome).toBe(firstRemoteHome);
|
|
196
|
+
expect(args[2]).toContain("resume");
|
|
197
|
+
expect(args[2]).toContain("ssh-thread");
|
|
198
|
+
expect(await readFile(path.join(remoteHome, "sessions", "rollout.jsonl"), "utf8")).toBe("fixture conversation");
|
|
199
|
+
expect(await readFile(path.join(remoteHome, "state_5.sqlite"), "utf8")).toBe("fixture native index");
|
|
200
|
+
if (fails)
|
|
201
|
+
throw new Error("fixture provider failed");
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
if (calls === 3)
|
|
205
|
+
otherRemoteHome = remoteHome;
|
|
206
|
+
expect(remoteHome).not.toBe(firstRemoteHome);
|
|
207
|
+
expect(args[2]).not.toContain("resume");
|
|
208
|
+
await expect(readFile(path.join(remoteHome, "sessions", "rollout.jsonl"))).rejects.toThrow("ENOENT");
|
|
209
|
+
if (calls === 3) {
|
|
210
|
+
await mkdir(path.join(remoteHome, "sessions"));
|
|
211
|
+
await writeFile(path.join(remoteHome, "sessions", "rollout.jsonl"), "other conversation");
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return { exitCode: 0, signal: null, timedOut: false, stdout: JSON.stringify({ type: "thread.started", thread_id: calls < 3 ? "ssh-thread" : "other-thread" }) + '\n{"type":"turn.completed","usage":{"input_tokens":1,"output_tokens":1}}\n', stderr: "", pid: 123, startedAt: new Date().toISOString() };
|
|
215
|
+
});
|
|
216
|
+
const ctx = {
|
|
217
|
+
agent: { id: "agent-1", companyId: "company-1", name: "Selected agent", adapterType: "codex_local", adapterConfig: {} },
|
|
218
|
+
config: { engine: "cli", command: "codex", managedAiConnection: { identity: "generation-one", sessionIdentity: "selected-account", provider: "openai", method: "subscription" }, env: { CODEX_HOME: home, OPENAI_API_KEY: "" } },
|
|
219
|
+
context: { paperclipWorkspace: { cwd: workspace, source: "project_primary" } },
|
|
220
|
+
executionTarget: { kind: "remote", transport: "ssh", remoteCwd: workspace,
|
|
221
|
+
spec: { useHostAuth: false, host: "127.0.0.1", port: 2222, username: "fixture", remoteCwd: workspace, remoteWorkspacePath: workspace, privateKey: null, knownHosts: null, strictHostKeyChecking: true },
|
|
222
|
+
workspaceRealization: { mode: "in_place", authoritativeRoot: workspace, pathAliases: [], outboundRestorePaths: [] } }, onLog: async () => { },
|
|
223
|
+
};
|
|
224
|
+
try {
|
|
225
|
+
const first = await execute({ ...ctx, runId: "first", runtime: { sessionId: null, sessionParams: null, sessionDisplayId: null, taskKey: "task-one" } });
|
|
226
|
+
expect(first.sessionId).toBe("ssh-thread");
|
|
227
|
+
const saved = sessionCodec.deserialize(JSON.parse(JSON.stringify(sessionCodec.serialize(first.sessionParams))));
|
|
228
|
+
expect(saved).toMatchObject({ remoteExecution: first.sessionParams.remoteExecution,
|
|
229
|
+
sshCodexConversationId: first.sessionParams.sshCodexConversationId, sshCodexAccountScope: first.sessionParams.sshCodexAccountScope });
|
|
230
|
+
expect(await readFile(path.join(home, "auth.json"), "utf8")).toBe(refreshed);
|
|
231
|
+
await writeFile(path.join(secondHome, "auth.json"), refreshed);
|
|
232
|
+
expect(await readdir(firstRemoteHome)).toEqual(expect.arrayContaining(["sessions", "state_5.sqlite"]));
|
|
233
|
+
expect(await readdir(firstRemoteHome)).not.toContain("auth.json");
|
|
234
|
+
const second = execute({ ...ctx, runId: "second", config: { ...ctx.config,
|
|
235
|
+
managedAiConnection: { ...ctx.config.managedAiConnection, identity: "generation-two" }, env: { CODEX_HOME: secondHome, OPENAI_API_KEY: "" } },
|
|
236
|
+
runtime: { sessionId: first.sessionId, sessionParams: saved, sessionDisplayId: first.sessionId, taskKey: "task-one" } });
|
|
237
|
+
if (fails)
|
|
238
|
+
await expect(second).rejects.toThrow("fixture provider failed");
|
|
239
|
+
else
|
|
240
|
+
expect((await second).sessionId).toBe("ssh-thread");
|
|
241
|
+
expect(calls).toBe(2);
|
|
242
|
+
expect((await readdir(firstRemoteHome)).sort()).toEqual(["sessions", "state_5.sqlite"]);
|
|
243
|
+
expect((await stat(firstRemoteHome)).mode & 0o077).toBe(0);
|
|
244
|
+
if (!fails) {
|
|
245
|
+
await writeFile(path.join(secondHome, "auth.json"), otherCredential);
|
|
246
|
+
const switched = await execute({ ...ctx, runId: "other-account", config: { ...ctx.config,
|
|
247
|
+
managedAiConnection: { ...ctx.config.managedAiConnection, identity: "other-account", sessionIdentity: "other-account" }, env: { CODEX_HOME: secondHome, OPENAI_API_KEY: "" } },
|
|
248
|
+
runtime: { sessionId: first.sessionId, sessionParams: first.sessionParams, sessionDisplayId: first.sessionId, taskKey: "task-one" } });
|
|
249
|
+
expect(switched.sessionId).toBe("other-thread");
|
|
250
|
+
expect(switched.sessionParams?.sshCodexAccountScope).not.toBe(first.sessionParams?.sshCodexAccountScope);
|
|
251
|
+
expect(switched.resultJson).toMatchObject({ sessionReset: { code: "codex_ssh_session_state_unavailable" } });
|
|
252
|
+
expect(await readdir(otherRemoteHome)).not.toContain("auth.json");
|
|
253
|
+
expect(await readFile(path.join(firstRemoteHome, "sessions", "rollout.jsonl"), "utf8")).toBe("fixture conversation");
|
|
254
|
+
const oldShape = { sessionId: switched.sessionId, cwd: workspace, remoteExecution: switched.sessionParams.remoteExecution };
|
|
255
|
+
const legacy = await execute({ ...ctx, runId: "old-saved-shape", config: { ...ctx.config,
|
|
256
|
+
managedAiConnection: { ...ctx.config.managedAiConnection, identity: "other-account", sessionIdentity: "other-account" }, env: { CODEX_HOME: secondHome, OPENAI_API_KEY: "" } },
|
|
257
|
+
runtime: { sessionId: switched.sessionId, sessionParams: oldShape, sessionDisplayId: switched.sessionId, taskKey: "task-one" } });
|
|
258
|
+
expect(legacy.resultJson).toMatchObject({ sessionReset: { code: "codex_ssh_session_state_unavailable" } });
|
|
259
|
+
expect(await readFile(path.join(otherRemoteHome, "sessions", "rollout.jsonl"), "utf8")).toBe("other conversation");
|
|
260
|
+
}
|
|
261
|
+
for (const dir of privateRoots)
|
|
262
|
+
await expect(stat(dir)).rejects.toThrow("ENOENT");
|
|
263
|
+
}
|
|
264
|
+
finally {
|
|
265
|
+
runChildProcess.mockImplementation(originalRun);
|
|
266
|
+
runSshCommand.mockReset().mockResolvedValue({ stdout: Buffer.from("{}").toString("base64"), stderr: "" });
|
|
267
|
+
syncDirectoryToSsh.mockReset().mockResolvedValue(undefined);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
it("stages only the selected agent subscription and returns SSH refreshes to that account", async () => {
|
|
271
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "paperclip-codex-selected-ssh-"));
|
|
272
|
+
cleanupDirs.push(root);
|
|
273
|
+
const workspace = path.join(root, "workspace"), home = path.join(root, "selected-account");
|
|
274
|
+
await mkdir(workspace);
|
|
275
|
+
await mkdir(home);
|
|
276
|
+
const auth = (marker, last_refresh) => JSON.stringify({
|
|
277
|
+
tokens: { account_id: "selected-account", access_token: `fixture-access-${marker}`, refresh_token: `fixture-refresh-${marker}`, id_token: `fixture-id-${marker}` }, last_refresh,
|
|
278
|
+
});
|
|
279
|
+
await writeFile(path.join(home, "auth.json"), auth("before", "2000-01-01T00:00:00Z"), { mode: 0o600 });
|
|
280
|
+
const refreshed = auth("after", new Date().toISOString());
|
|
281
|
+
runSshCommand.mockImplementation(async (_spec, command) => ({ stdout: command?.includes("mktemp -d")
|
|
282
|
+
? "/tmp/paperclip-ssh-runtime.selected\n" : Buffer.from(refreshed).toString("base64"), stderr: "" }));
|
|
283
|
+
try {
|
|
284
|
+
await execute({ runId: "selected", agent: { id: "agent-1", companyId: "company-1", name: "Selected agent", adapterType: "codex_local", adapterConfig: {} },
|
|
285
|
+
runtime: { sessionId: null, sessionParams: null, sessionDisplayId: null, taskKey: null },
|
|
286
|
+
config: { engine: "cli", command: "codex", managedAiConnection: { identity: "selected-account", provider: "openai", method: "subscription" }, env: { CODEX_HOME: home, OPENAI_API_KEY: "" } },
|
|
287
|
+
context: { paperclipWorkspace: { cwd: workspace, source: "project_primary" } },
|
|
288
|
+
executionTransport: { remoteExecution: { useHostAuth: false, host: "127.0.0.1", port: 2222, username: "fixture", remoteCwd: "/workspace", remoteWorkspacePath: "/workspace", privateKey: null, knownHosts: null, strictHostKeyChecking: true } }, onLog: async () => { },
|
|
289
|
+
});
|
|
290
|
+
const invocation = runChildProcess.mock.calls[0];
|
|
291
|
+
expect(invocation[3].env).toMatchObject({ CODEX_HOME: "/tmp/paperclip-ssh-runtime.selected/home", HOME: "/tmp/paperclip-ssh-runtime.selected", OPENAI_API_KEY: "" });
|
|
292
|
+
expect(await readFile(path.join(home, "auth.json"), "utf8")).toBe(refreshed);
|
|
293
|
+
expect(runSshCommand).toHaveBeenCalledWith(expect.anything(), "rm -rf -- '/tmp/paperclip-ssh-runtime.selected'", expect.anything());
|
|
294
|
+
}
|
|
295
|
+
finally {
|
|
296
|
+
runSshCommand.mockReset().mockResolvedValue({ stdout: Buffer.from("{}").toString("base64"), stderr: "" });
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
it("prepares the workspace, syncs CODEX_HOME, and restores workspace changes for remote SSH execution", async () => {
|
|
300
|
+
const rootDir = await mkdtemp(path.join(os.tmpdir(), "paperclip-codex-remote-"));
|
|
301
|
+
cleanupDirs.push(rootDir);
|
|
302
|
+
const workspaceDir = path.join(rootDir, "workspace");
|
|
303
|
+
const codexHomeDir = path.join(rootDir, "codex-home");
|
|
304
|
+
const managedRemoteWorkspace = "/remote/workspace/.paperclip-runtime/runs/run-1/workspace";
|
|
305
|
+
await mkdir(workspaceDir, { recursive: true });
|
|
306
|
+
await mkdir(codexHomeDir, { recursive: true });
|
|
307
|
+
await writeFile(path.join(rootDir, "instructions.md"), "Use the remote workspace.\n", "utf8");
|
|
308
|
+
await writeFile(path.join(codexHomeDir, "auth.json"), "{}", "utf8");
|
|
309
|
+
const alternateWorkspaceDir = path.join(rootDir, "alternate-workspace");
|
|
310
|
+
await mkdir(alternateWorkspaceDir, { recursive: true });
|
|
311
|
+
await execute({
|
|
312
|
+
runId: "run-1",
|
|
313
|
+
agent: {
|
|
314
|
+
id: "agent-1",
|
|
315
|
+
companyId: "company-1",
|
|
316
|
+
name: "CodexCoder",
|
|
317
|
+
adapterType: "codex_local",
|
|
318
|
+
adapterConfig: {},
|
|
319
|
+
},
|
|
320
|
+
runtime: {
|
|
321
|
+
sessionId: null,
|
|
322
|
+
sessionParams: null,
|
|
323
|
+
sessionDisplayId: null,
|
|
324
|
+
taskKey: null,
|
|
325
|
+
},
|
|
326
|
+
config: {
|
|
327
|
+
engine: "cli",
|
|
328
|
+
command: "codex",
|
|
329
|
+
env: {
|
|
330
|
+
CODEX_HOME: codexHomeDir,
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
context: {
|
|
334
|
+
paperclipWorkspace: {
|
|
335
|
+
cwd: workspaceDir,
|
|
336
|
+
source: "project_primary",
|
|
337
|
+
strategy: "git_worktree",
|
|
338
|
+
workspaceId: "workspace-1",
|
|
339
|
+
repoUrl: "https://github.com/paperclipai/paperclip.git",
|
|
340
|
+
repoRef: "main",
|
|
341
|
+
branchName: "feature/remote-codex",
|
|
342
|
+
worktreePath: workspaceDir,
|
|
343
|
+
},
|
|
344
|
+
paperclipWorkspaces: [
|
|
345
|
+
{
|
|
346
|
+
workspaceId: "workspace-1",
|
|
347
|
+
cwd: workspaceDir,
|
|
348
|
+
repoUrl: "https://github.com/paperclipai/paperclip.git",
|
|
349
|
+
repoRef: "main",
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
workspaceId: "workspace-2",
|
|
353
|
+
cwd: alternateWorkspaceDir,
|
|
354
|
+
repoUrl: "https://github.com/paperclipai/paperclip.git",
|
|
355
|
+
repoRef: "feature/other",
|
|
356
|
+
},
|
|
357
|
+
],
|
|
358
|
+
},
|
|
359
|
+
executionTransport: {
|
|
360
|
+
remoteExecution: {
|
|
361
|
+
host: "127.0.0.1",
|
|
362
|
+
port: 2222,
|
|
363
|
+
username: "fixture",
|
|
364
|
+
remoteWorkspacePath: "/remote/workspace",
|
|
365
|
+
remoteCwd: "/remote/workspace",
|
|
366
|
+
privateKey: "PRIVATE KEY",
|
|
367
|
+
knownHosts: "[127.0.0.1]:2222 ssh-ed25519 AAAA",
|
|
368
|
+
strictHostKeyChecking: true,
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
onLog: async () => { },
|
|
372
|
+
});
|
|
373
|
+
expect(prepareWorkspaceForSshExecution).toHaveBeenCalledTimes(1);
|
|
374
|
+
expect(prepareWorkspaceForSshExecution).toHaveBeenCalledWith(expect.objectContaining({
|
|
375
|
+
localDir: workspaceDir,
|
|
376
|
+
remoteDir: managedRemoteWorkspace,
|
|
377
|
+
}));
|
|
378
|
+
expect(syncDirectoryToSsh).toHaveBeenCalledTimes(1);
|
|
379
|
+
// The home asset now syncs a curated *staged* allowlist dir, not the raw
|
|
380
|
+
// managed CODEX_HOME, and carries no `exclude` denylist.
|
|
381
|
+
const homeSyncArgs = syncDirectoryToSsh.mock.calls[0]?.[0];
|
|
382
|
+
expect(homeSyncArgs.localDir).not.toBe(codexHomeDir);
|
|
383
|
+
expect(homeSyncArgs.localDir).toContain("paperclip-codex-home-sync");
|
|
384
|
+
expect(homeSyncArgs.remoteDir).toBe(`${managedRemoteWorkspace}/.paperclip-runtime/codex/home`);
|
|
385
|
+
expect(homeSyncArgs.followSymlinks).toBe(true);
|
|
386
|
+
expect(homeSyncArgs.exclude).toBeUndefined();
|
|
387
|
+
expect(runChildProcess).toHaveBeenCalledTimes(1);
|
|
388
|
+
const call = runChildProcess.mock.calls[0];
|
|
389
|
+
expect(call?.[2]).not.toContain("--skip-git-repo-check");
|
|
390
|
+
expect(call?.[3].env.CODEX_HOME).toBe(`${managedRemoteWorkspace}/.paperclip-runtime/codex/home`);
|
|
391
|
+
expect(call?.[3].env.PAPERCLIP_WORKSPACE_CWD).toBe(managedRemoteWorkspace);
|
|
392
|
+
expect(call?.[3].env.PAPERCLIP_WORKSPACE_WORKTREE_PATH).toBeUndefined();
|
|
393
|
+
expect(JSON.parse(call?.[3].env.PAPERCLIP_WORKSPACES_JSON ?? "[]")).toEqual([
|
|
394
|
+
{
|
|
395
|
+
workspaceId: "workspace-1",
|
|
396
|
+
cwd: managedRemoteWorkspace,
|
|
397
|
+
repoUrl: "https://github.com/paperclipai/paperclip.git",
|
|
398
|
+
repoRef: "main",
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
workspaceId: "workspace-2",
|
|
402
|
+
repoUrl: "https://github.com/paperclipai/paperclip.git",
|
|
403
|
+
repoRef: "feature/other",
|
|
404
|
+
},
|
|
405
|
+
]);
|
|
406
|
+
expect(call?.[3].env.PAPERCLIP_API_URL).toBe("http://127.0.0.1:4310");
|
|
407
|
+
expect(call?.[3].env.PAPERCLIP_API_BRIDGE_MODE).toBe("queue_v1");
|
|
408
|
+
expect(call?.[3].remoteExecution?.remoteCwd).toBe(managedRemoteWorkspace);
|
|
409
|
+
expect(startAdapterExecutionTargetPaperclipBridge).toHaveBeenCalledTimes(1);
|
|
410
|
+
expect(restoreWorkspaceFromSshExecution).toHaveBeenCalledTimes(1);
|
|
411
|
+
expect(restoreWorkspaceFromSshExecution).toHaveBeenCalledWith(expect.objectContaining({
|
|
412
|
+
localDir: workspaceDir,
|
|
413
|
+
remoteDir: managedRemoteWorkspace,
|
|
414
|
+
}));
|
|
415
|
+
});
|
|
416
|
+
it("stages only the allowlist into the home asset: keeps config.toml/skills/auth, drops session+sqlite state, no exclude", async () => {
|
|
417
|
+
const rootDir = await mkdtemp(path.join(os.tmpdir(), "paperclip-codex-allowlist-"));
|
|
418
|
+
cleanupDirs.push(rootDir);
|
|
419
|
+
const workspaceDir = path.join(rootDir, "workspace");
|
|
420
|
+
const codexHomeDir = path.join(rootDir, "codex-home");
|
|
421
|
+
await mkdir(workspaceDir, { recursive: true });
|
|
422
|
+
await mkdir(codexHomeDir, { recursive: true });
|
|
423
|
+
// Seed the managed home with the files Codex needs (config.toml carries a
|
|
424
|
+
// provider-routing block; skills injected) plus large runtime decoys the
|
|
425
|
+
// old 4-name denylist missed.
|
|
426
|
+
await writeFile(path.join(codexHomeDir, "auth.json"), '{"tokens":{"account_id":"a","refresh_token":"r"}}', "utf8");
|
|
427
|
+
await writeFile(path.join(codexHomeDir, "config.toml"), 'model_provider = "bifrost"\n\n[model_providers.bifrost]\nname = "bifrost"\n', "utf8");
|
|
428
|
+
await writeFile(path.join(codexHomeDir, "instructions.md"), "hi\n", "utf8");
|
|
429
|
+
await mkdir(path.join(codexHomeDir, "skills", "demo"), { recursive: true });
|
|
430
|
+
await writeFile(path.join(codexHomeDir, "skills", "demo", "SKILL.md"), "# demo\n", "utf8");
|
|
431
|
+
// Decoys:
|
|
432
|
+
await writeFile(path.join(codexHomeDir, "logs_2.sqlite"), "x", "utf8");
|
|
433
|
+
await writeFile(path.join(codexHomeDir, "state_5.sqlite"), "x", "utf8");
|
|
434
|
+
await mkdir(path.join(codexHomeDir, "sessions"), { recursive: true });
|
|
435
|
+
await writeFile(path.join(codexHomeDir, "sessions", "rollout.jsonl"), "x", "utf8");
|
|
436
|
+
await mkdir(path.join(codexHomeDir, "tmp"), { recursive: true });
|
|
437
|
+
await symlink("/usr/bin/env", path.join(codexHomeDir, "tmp", "arg0"));
|
|
438
|
+
// Snapshot the staged dir contents at sync time — execute() removes the
|
|
439
|
+
// staged temp dir on teardown, so we cannot read it after execute returns.
|
|
440
|
+
let stagedSnapshot = null;
|
|
441
|
+
syncDirectoryToSsh.mockImplementationOnce(async (args) => {
|
|
442
|
+
const entries = (await readdir(args.localDir)).sort();
|
|
443
|
+
const skillEntries = entries.includes("skills")
|
|
444
|
+
? (await readdir(path.join(args.localDir, "skills"))).sort()
|
|
445
|
+
: [];
|
|
446
|
+
const configToml = entries.includes("config.toml")
|
|
447
|
+
? await readFile(path.join(args.localDir, "config.toml"), "utf8")
|
|
448
|
+
: "";
|
|
449
|
+
const authJson = entries.includes("auth.json")
|
|
450
|
+
? await readFile(path.join(args.localDir, "auth.json"), "utf8")
|
|
451
|
+
: "";
|
|
452
|
+
stagedSnapshot = { localDir: args.localDir, entries, skillEntries, configToml, authJson };
|
|
453
|
+
});
|
|
454
|
+
await execute({
|
|
455
|
+
runId: "run-allowlist",
|
|
456
|
+
agent: {
|
|
457
|
+
id: "agent-1",
|
|
458
|
+
companyId: "company-1",
|
|
459
|
+
name: "CodexCoder",
|
|
460
|
+
adapterType: "codex_local",
|
|
461
|
+
adapterConfig: {},
|
|
462
|
+
},
|
|
463
|
+
runtime: {
|
|
464
|
+
sessionId: null,
|
|
465
|
+
sessionParams: null,
|
|
466
|
+
sessionDisplayId: null,
|
|
467
|
+
taskKey: null,
|
|
468
|
+
},
|
|
469
|
+
config: {
|
|
470
|
+
engine: "cli",
|
|
471
|
+
command: "codex",
|
|
472
|
+
env: {
|
|
473
|
+
CODEX_HOME: codexHomeDir,
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
context: {
|
|
477
|
+
paperclipWorkspace: {
|
|
478
|
+
cwd: workspaceDir,
|
|
479
|
+
source: "project_primary",
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
executionTransport: {
|
|
483
|
+
remoteExecution: {
|
|
484
|
+
host: "127.0.0.1",
|
|
485
|
+
port: 2222,
|
|
486
|
+
username: "fixture",
|
|
487
|
+
remoteWorkspacePath: "/remote/workspace",
|
|
488
|
+
remoteCwd: "/remote/workspace",
|
|
489
|
+
privateKey: "PRIVATE KEY",
|
|
490
|
+
knownHosts: "[127.0.0.1]:2222 ssh-ed25519 AAAA",
|
|
491
|
+
strictHostKeyChecking: true,
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
onLog: async () => { },
|
|
495
|
+
});
|
|
496
|
+
expect(stagedSnapshot).not.toBeNull();
|
|
497
|
+
const snap = stagedSnapshot;
|
|
498
|
+
// Allowlist present; decoys gone.
|
|
499
|
+
expect(snap.entries).toEqual(["auth.json", "config.json", "config.toml", "instructions.md", "skills"]
|
|
500
|
+
.filter((e) => e !== "config.json") // no config.json was seeded
|
|
501
|
+
.sort());
|
|
502
|
+
for (const decoy of ["logs_2.sqlite", "state_5.sqlite", "sessions", "tmp", "plugins"]) {
|
|
503
|
+
expect(snap.entries).not.toContain(decoy);
|
|
504
|
+
}
|
|
505
|
+
// Phase-3 behavioral invariants: provider routing + skills + auth survive staging.
|
|
506
|
+
expect(snap.configToml).toContain("[model_providers.bifrost]");
|
|
507
|
+
expect(snap.configToml).toContain("model_provider");
|
|
508
|
+
expect(snap.skillEntries).toContain("demo");
|
|
509
|
+
expect(snap.authJson).toContain("refresh_token");
|
|
510
|
+
// The staged temp dir is removed after execute completes (cleanup on teardown).
|
|
511
|
+
await expect(readdir(snap.localDir)).rejects.toMatchObject({ code: "ENOENT" });
|
|
512
|
+
});
|
|
513
|
+
it("does not resume saved Codex sessions for remote SSH execution without a matching remote identity", async () => {
|
|
514
|
+
const rootDir = await mkdtemp(path.join(os.tmpdir(), "paperclip-codex-remote-resume-"));
|
|
515
|
+
cleanupDirs.push(rootDir);
|
|
516
|
+
const workspaceDir = path.join(rootDir, "workspace");
|
|
517
|
+
const codexHomeDir = path.join(rootDir, "codex-home");
|
|
518
|
+
await mkdir(workspaceDir, { recursive: true });
|
|
519
|
+
await mkdir(codexHomeDir, { recursive: true });
|
|
520
|
+
await writeFile(path.join(codexHomeDir, "auth.json"), "{}", "utf8");
|
|
521
|
+
await execute({
|
|
522
|
+
runId: "run-ssh-no-resume",
|
|
523
|
+
agent: {
|
|
524
|
+
id: "agent-1",
|
|
525
|
+
companyId: "company-1",
|
|
526
|
+
name: "CodexCoder",
|
|
527
|
+
adapterType: "codex_local",
|
|
528
|
+
adapterConfig: {},
|
|
529
|
+
},
|
|
530
|
+
runtime: {
|
|
531
|
+
sessionId: "session-123",
|
|
532
|
+
sessionParams: {
|
|
533
|
+
sessionId: "session-123",
|
|
534
|
+
cwd: "/remote/workspace",
|
|
535
|
+
},
|
|
536
|
+
sessionDisplayId: "session-123",
|
|
537
|
+
taskKey: null,
|
|
538
|
+
},
|
|
539
|
+
config: {
|
|
540
|
+
engine: "cli",
|
|
541
|
+
command: "codex",
|
|
542
|
+
env: {
|
|
543
|
+
CODEX_HOME: codexHomeDir,
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
context: {
|
|
547
|
+
paperclipWorkspace: {
|
|
548
|
+
cwd: workspaceDir,
|
|
549
|
+
source: "project_primary",
|
|
550
|
+
},
|
|
551
|
+
},
|
|
552
|
+
executionTransport: {
|
|
553
|
+
remoteExecution: {
|
|
554
|
+
host: "127.0.0.1",
|
|
555
|
+
port: 2222,
|
|
556
|
+
username: "fixture",
|
|
557
|
+
remoteWorkspacePath: "/remote/workspace",
|
|
558
|
+
remoteCwd: "/remote/workspace",
|
|
559
|
+
privateKey: "PRIVATE KEY",
|
|
560
|
+
knownHosts: "[127.0.0.1]:2222 ssh-ed25519 AAAA",
|
|
561
|
+
strictHostKeyChecking: true,
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
onLog: async () => { },
|
|
565
|
+
});
|
|
566
|
+
expect(runChildProcess).toHaveBeenCalledTimes(1);
|
|
567
|
+
const call = runChildProcess.mock.calls[0];
|
|
568
|
+
expect(call?.[2].slice(call[2].indexOf("exec"))).toEqual([
|
|
569
|
+
"exec",
|
|
570
|
+
"--json",
|
|
571
|
+
"--dangerously-bypass-approvals-and-sandbox",
|
|
572
|
+
"-",
|
|
573
|
+
]);
|
|
574
|
+
});
|
|
575
|
+
it("resumes saved Codex sessions for remote SSH execution when the remote identity matches", async () => {
|
|
576
|
+
const rootDir = await mkdtemp(path.join(os.tmpdir(), "paperclip-codex-remote-resume-match-"));
|
|
577
|
+
cleanupDirs.push(rootDir);
|
|
578
|
+
const workspaceDir = path.join(rootDir, "workspace");
|
|
579
|
+
const codexHomeDir = path.join(rootDir, "codex-home");
|
|
580
|
+
const managedRemoteWorkspace = "/remote/workspace/.paperclip-runtime/runs/run-ssh-resume/workspace";
|
|
581
|
+
await mkdir(workspaceDir, { recursive: true });
|
|
582
|
+
await mkdir(codexHomeDir, { recursive: true });
|
|
583
|
+
await writeFile(path.join(codexHomeDir, "auth.json"), "{}", "utf8");
|
|
584
|
+
await execute({
|
|
585
|
+
runId: "run-ssh-resume",
|
|
586
|
+
agent: {
|
|
587
|
+
id: "agent-1",
|
|
588
|
+
companyId: "company-1",
|
|
589
|
+
name: "CodexCoder",
|
|
590
|
+
adapterType: "codex_local",
|
|
591
|
+
adapterConfig: {},
|
|
592
|
+
},
|
|
593
|
+
runtime: {
|
|
594
|
+
sessionId: "session-123",
|
|
595
|
+
sessionParams: {
|
|
596
|
+
sessionId: "session-123",
|
|
597
|
+
cwd: managedRemoteWorkspace,
|
|
598
|
+
remoteExecution: {
|
|
599
|
+
transport: "ssh",
|
|
600
|
+
host: "127.0.0.1",
|
|
601
|
+
port: 2222,
|
|
602
|
+
username: "fixture",
|
|
603
|
+
remoteCwd: managedRemoteWorkspace,
|
|
604
|
+
},
|
|
605
|
+
},
|
|
606
|
+
sessionDisplayId: "session-123",
|
|
607
|
+
taskKey: null,
|
|
608
|
+
},
|
|
609
|
+
config: {
|
|
610
|
+
engine: "cli",
|
|
611
|
+
command: "codex",
|
|
612
|
+
env: {
|
|
613
|
+
CODEX_HOME: codexHomeDir,
|
|
614
|
+
},
|
|
615
|
+
},
|
|
616
|
+
context: {
|
|
617
|
+
paperclipWorkspace: {
|
|
618
|
+
cwd: workspaceDir,
|
|
619
|
+
source: "project_primary",
|
|
620
|
+
},
|
|
621
|
+
},
|
|
622
|
+
executionTransport: {
|
|
623
|
+
remoteExecution: {
|
|
624
|
+
host: "127.0.0.1",
|
|
625
|
+
port: 2222,
|
|
626
|
+
username: "fixture",
|
|
627
|
+
remoteWorkspacePath: "/remote/workspace",
|
|
628
|
+
remoteCwd: "/remote/workspace",
|
|
629
|
+
privateKey: "PRIVATE KEY",
|
|
630
|
+
knownHosts: "[127.0.0.1]:2222 ssh-ed25519 AAAA",
|
|
631
|
+
strictHostKeyChecking: true,
|
|
632
|
+
},
|
|
633
|
+
},
|
|
634
|
+
onLog: async () => { },
|
|
635
|
+
});
|
|
636
|
+
expect(runChildProcess).toHaveBeenCalledTimes(1);
|
|
637
|
+
const call = runChildProcess.mock.calls[0];
|
|
638
|
+
expect(call?.[2].slice(call[2].indexOf("exec"))).toEqual([
|
|
639
|
+
"exec",
|
|
640
|
+
"--json",
|
|
641
|
+
"--dangerously-bypass-approvals-and-sandbox",
|
|
642
|
+
"resume",
|
|
643
|
+
"session-123",
|
|
644
|
+
"-",
|
|
645
|
+
]);
|
|
646
|
+
});
|
|
647
|
+
it("uses the provider-neutral execution target contract for remote SSH execution", async () => {
|
|
648
|
+
const rootDir = await mkdtemp(path.join(os.tmpdir(), "paperclip-codex-target-"));
|
|
649
|
+
cleanupDirs.push(rootDir);
|
|
650
|
+
const workspaceDir = path.join(rootDir, "workspace");
|
|
651
|
+
const codexHomeDir = path.join(rootDir, "codex-home");
|
|
652
|
+
const managedRemoteWorkspace = "/remote/workspace/.paperclip-runtime/runs/run-target/workspace";
|
|
653
|
+
await mkdir(workspaceDir, { recursive: true });
|
|
654
|
+
await mkdir(codexHomeDir, { recursive: true });
|
|
655
|
+
await writeFile(path.join(codexHomeDir, "auth.json"), "{}", "utf8");
|
|
656
|
+
await execute({
|
|
657
|
+
runId: "run-target",
|
|
658
|
+
agent: {
|
|
659
|
+
id: "agent-1",
|
|
660
|
+
companyId: "company-1",
|
|
661
|
+
name: "CodexCoder",
|
|
662
|
+
adapterType: "codex_local",
|
|
663
|
+
adapterConfig: {},
|
|
664
|
+
},
|
|
665
|
+
runtime: {
|
|
666
|
+
sessionId: "session-123",
|
|
667
|
+
sessionParams: {
|
|
668
|
+
sessionId: "session-123",
|
|
669
|
+
cwd: managedRemoteWorkspace,
|
|
670
|
+
remoteExecution: {
|
|
671
|
+
transport: "ssh",
|
|
672
|
+
host: "127.0.0.1",
|
|
673
|
+
port: 2222,
|
|
674
|
+
username: "fixture",
|
|
675
|
+
remoteCwd: managedRemoteWorkspace,
|
|
676
|
+
},
|
|
677
|
+
},
|
|
678
|
+
sessionDisplayId: "session-123",
|
|
679
|
+
taskKey: null,
|
|
680
|
+
},
|
|
681
|
+
config: {
|
|
682
|
+
engine: "cli",
|
|
683
|
+
command: "codex",
|
|
684
|
+
env: {
|
|
685
|
+
CODEX_HOME: codexHomeDir,
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
context: {
|
|
689
|
+
paperclipWorkspace: {
|
|
690
|
+
cwd: workspaceDir,
|
|
691
|
+
source: "project_primary",
|
|
692
|
+
},
|
|
693
|
+
},
|
|
694
|
+
executionTarget: {
|
|
695
|
+
kind: "remote",
|
|
696
|
+
transport: "ssh",
|
|
697
|
+
remoteCwd: "/remote/workspace",
|
|
698
|
+
spec: {
|
|
699
|
+
host: "127.0.0.1",
|
|
700
|
+
port: 2222,
|
|
701
|
+
username: "fixture",
|
|
702
|
+
remoteWorkspacePath: "/remote/workspace",
|
|
703
|
+
remoteCwd: "/remote/workspace",
|
|
704
|
+
privateKey: "PRIVATE KEY",
|
|
705
|
+
knownHosts: "[127.0.0.1]:2222 ssh-ed25519 AAAA",
|
|
706
|
+
strictHostKeyChecking: true,
|
|
707
|
+
},
|
|
708
|
+
},
|
|
709
|
+
onLog: async () => { },
|
|
710
|
+
});
|
|
711
|
+
expect(syncDirectoryToSsh).toHaveBeenCalledTimes(1);
|
|
712
|
+
expect(runChildProcess).toHaveBeenCalledTimes(1);
|
|
713
|
+
const call = runChildProcess.mock.calls[0];
|
|
714
|
+
expect(call?.[2].slice(call[2].indexOf("exec"))).toEqual([
|
|
715
|
+
"exec",
|
|
716
|
+
"--json",
|
|
717
|
+
"--dangerously-bypass-approvals-and-sandbox",
|
|
718
|
+
"resume",
|
|
719
|
+
"session-123",
|
|
720
|
+
"-",
|
|
721
|
+
]);
|
|
722
|
+
expect(call?.[3].env.CODEX_HOME).toBe(`${managedRemoteWorkspace}/.paperclip-runtime/codex/home`);
|
|
723
|
+
expect(call?.[3].remoteExecution?.remoteCwd).toBe(managedRemoteWorkspace);
|
|
724
|
+
});
|
|
725
|
+
it("runs in place at the authoritative root without archive prepare or restore", async () => {
|
|
726
|
+
const rootDir = await mkdtemp(path.join(os.tmpdir(), "paperclip-codex-in-place-"));
|
|
727
|
+
cleanupDirs.push(rootDir);
|
|
728
|
+
const workspaceDir = path.join(rootDir, "workspace");
|
|
729
|
+
const codexHomeDir = path.join(rootDir, "codex-home");
|
|
730
|
+
await mkdir(workspaceDir, { recursive: true });
|
|
731
|
+
await mkdir(codexHomeDir, { recursive: true });
|
|
732
|
+
await writeFile(path.join(codexHomeDir, "auth.json"), "{}", "utf8");
|
|
733
|
+
await execute({
|
|
734
|
+
runId: "run-in-place",
|
|
735
|
+
agent: {
|
|
736
|
+
id: "agent-1",
|
|
737
|
+
companyId: "company-1",
|
|
738
|
+
name: "CodexCoder",
|
|
739
|
+
adapterType: "codex_local",
|
|
740
|
+
adapterConfig: {},
|
|
741
|
+
},
|
|
742
|
+
runtime: { sessionId: null, sessionParams: null, sessionDisplayId: null, taskKey: null },
|
|
743
|
+
config: { engine: "cli", command: "codex", env: { CODEX_HOME: codexHomeDir } },
|
|
744
|
+
context: {
|
|
745
|
+
paperclipWorkspace: {
|
|
746
|
+
cwd: workspaceDir,
|
|
747
|
+
source: "task_session",
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
executionTarget: {
|
|
751
|
+
kind: "remote",
|
|
752
|
+
transport: "ssh",
|
|
753
|
+
remoteCwd: "/copied/workspace",
|
|
754
|
+
workspaceRealization: {
|
|
755
|
+
mode: "in_place",
|
|
756
|
+
authoritativeRoot: "/app",
|
|
757
|
+
pathAliases: [],
|
|
758
|
+
outboundRestorePaths: [],
|
|
759
|
+
},
|
|
760
|
+
spec: {
|
|
761
|
+
host: "127.0.0.1",
|
|
762
|
+
port: 2222,
|
|
763
|
+
username: "fixture",
|
|
764
|
+
remoteWorkspacePath: "/app",
|
|
765
|
+
remoteCwd: "/app",
|
|
766
|
+
privateKey: "PRIVATE KEY",
|
|
767
|
+
knownHosts: "[127.0.0.1]:2222 ssh-ed25519 AAAA",
|
|
768
|
+
strictHostKeyChecking: true,
|
|
769
|
+
},
|
|
770
|
+
},
|
|
771
|
+
onLog: async () => { },
|
|
772
|
+
});
|
|
773
|
+
expect(prepareWorkspaceForSshExecution).not.toHaveBeenCalled();
|
|
774
|
+
expect(syncDirectoryToSsh).toHaveBeenCalledTimes(1);
|
|
775
|
+
expect(restoreWorkspaceFromSshExecution).not.toHaveBeenCalled();
|
|
776
|
+
const homeSyncArgs = syncDirectoryToSsh.mock.calls[0]?.[0];
|
|
777
|
+
expect(homeSyncArgs.localDir).toContain("paperclip-codex-home-sync");
|
|
778
|
+
expect(homeSyncArgs.remoteDir).toBe("/app/.paperclip-runtime/codex/home");
|
|
779
|
+
const call = runChildProcess.mock.calls[0];
|
|
780
|
+
expect(call?.[3].env.PAPERCLIP_WORKSPACE_CWD).toBe("/app");
|
|
781
|
+
expect(call?.[3].env.PAPERCLIP_WORKSPACE_REALIZATION_MODE).toBe("in_place");
|
|
782
|
+
expect(call?.[3].env.PAPERCLIP_WORKSPACE_AUTHORITATIVE_ROOT).toBe("/app");
|
|
783
|
+
expect(call?.[3].env.CODEX_HOME).toBe("/app/.paperclip-runtime/codex/home");
|
|
784
|
+
expect(call?.[3].remoteExecution?.remoteCwd).toBe("/app");
|
|
785
|
+
});
|
|
786
|
+
it("reselects the full assignment and bootstrap guidance after a failed resume", async () => {
|
|
787
|
+
const rootDir = await mkdtemp(path.join(os.tmpdir(), "paperclip-codex-cli-fallback-context-"));
|
|
788
|
+
cleanupDirs.push(rootDir);
|
|
789
|
+
const workspaceDir = path.join(rootDir, "workspace");
|
|
790
|
+
await mkdir(workspaceDir, { recursive: true });
|
|
791
|
+
runChildProcess
|
|
792
|
+
.mockResolvedValueOnce({
|
|
793
|
+
exitCode: 1,
|
|
794
|
+
signal: null,
|
|
795
|
+
timedOut: false,
|
|
796
|
+
stdout: "",
|
|
797
|
+
stderr: "unknown thread id session-old",
|
|
798
|
+
pid: 123,
|
|
799
|
+
startedAt: new Date().toISOString(),
|
|
800
|
+
})
|
|
801
|
+
.mockResolvedValueOnce({
|
|
802
|
+
exitCode: 0,
|
|
803
|
+
signal: null,
|
|
804
|
+
timedOut: false,
|
|
805
|
+
stdout: [
|
|
806
|
+
JSON.stringify({ type: "thread.started", thread_id: "session-fresh" }),
|
|
807
|
+
JSON.stringify({ type: "turn.completed", usage: { input_tokens: 1, output_tokens: 1 } }),
|
|
808
|
+
].join("\\n"),
|
|
809
|
+
stderr: "",
|
|
810
|
+
pid: 124,
|
|
811
|
+
startedAt: new Date().toISOString(),
|
|
812
|
+
});
|
|
813
|
+
await execute({
|
|
814
|
+
runId: "run-codex-cli-fallback-context",
|
|
815
|
+
agent: {
|
|
816
|
+
id: "agent-1",
|
|
817
|
+
companyId: "company-1",
|
|
818
|
+
name: "Codex Coder",
|
|
819
|
+
adapterType: "codex_local",
|
|
820
|
+
adapterConfig: {},
|
|
821
|
+
},
|
|
822
|
+
runtime: {
|
|
823
|
+
sessionId: "session-old",
|
|
824
|
+
sessionParams: { sessionId: "session-old", cwd: workspaceDir },
|
|
825
|
+
sessionDisplayId: "session-old",
|
|
826
|
+
taskKey: null,
|
|
827
|
+
},
|
|
828
|
+
config: {
|
|
829
|
+
engine: "cli",
|
|
830
|
+
command: "codex",
|
|
831
|
+
env: { OPENAI_API_KEY: "fixture-openai-key" },
|
|
832
|
+
},
|
|
833
|
+
context: {
|
|
834
|
+
...createPromptContextFixture(),
|
|
835
|
+
paperclipWorkspace: { cwd: workspaceDir, source: "project_primary" },
|
|
836
|
+
},
|
|
837
|
+
onLog: async () => { },
|
|
838
|
+
});
|
|
839
|
+
expect(runChildProcess).toHaveBeenCalledTimes(2);
|
|
840
|
+
const first = runChildProcess.mock.calls[0][3]?.stdin ?? "";
|
|
841
|
+
const retry = runChildProcess.mock.calls[1][3]?.stdin ?? "";
|
|
842
|
+
expect(first).toContain("## Compact assignment");
|
|
843
|
+
expect(first).not.toContain("Explain the next step before starting work.");
|
|
844
|
+
expect(retry).toContain("## Owned assignment");
|
|
845
|
+
expect(retry).toContain("Explain the next step before starting work.");
|
|
846
|
+
expect(retry).not.toContain("## Compact assignment");
|
|
847
|
+
expect(retry.indexOf("comment-first")).toBeLessThan(retry.indexOf("comment-second"));
|
|
848
|
+
expect(retry.split("Append the same ledger entry.")).toHaveLength(3);
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
//# sourceMappingURL=execute.remote.test.js.map
|