@neuralnomads/codenomad-dev 0.18.0-dev-20260716-40cee071 → 0.18.0-dev-20260718-8f6aa44b
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/auth/manager.js +1 -1
- package/dist/filesystem/__tests__/search-cache.test.js +5 -5
- package/dist/filesystem/search-cache.js +1 -1
- package/dist/index.js +25 -0
- package/dist/index.test.js +40 -10
- package/dist/opencode-update/service.js +150 -0
- package/dist/opencode-update/service.test.js +107 -0
- package/dist/server/__tests__/remote-proxy.test.js +64 -56
- package/dist/server/http-server.js +7 -1
- package/dist/server/remote-proxy.js +68 -98
- package/dist/server/routes/opencode-update.js +37 -0
- package/dist/server/routes/opencode-update.test.js +34 -0
- package/dist/server/routes/remote-servers.js +1 -1
- package/dist/server/routes/workspaces.test.js +38 -0
- package/dist/server/tls.js +2 -2
- package/dist/settings/binaries.test.js +2 -7
- package/dist/shutdown.js +67 -59
- package/dist/shutdown.test.js +115 -78
- package/dist/ui/remote-ui.js +2 -2
- package/dist/usage/providers/api-key.js +3 -3
- package/dist/usage/providers/google.js +1 -1
- package/dist/usage/providers/special.js +3 -3
- package/dist/usage/service.js +1 -1
- package/dist/usage/service.test.js +1 -1
- package/dist/usage/shared.js +4 -4
- package/dist/usage/shared.test.js +1 -1
- package/dist/workspaces/__tests__/spawn.test.js +2 -2
- package/dist/workspaces/__tests__/workspace-identity.test.js +94 -286
- package/dist/workspaces/binary-path.test.js +10 -0
- package/dist/workspaces/instance-client.js +4 -3
- package/dist/workspaces/launch-cleanup.test.js +21 -25
- package/dist/workspaces/manager.js +300 -351
- package/dist/workspaces/manager.test.js +209 -237
- package/dist/workspaces/process-identity.darwin.test.js +88 -0
- package/dist/workspaces/process-identity.js +172 -149
- package/dist/workspaces/process-identity.test.js +86 -140
- package/dist/workspaces/runtime.js +261 -373
- package/dist/workspaces/runtime.test.js +222 -547
- package/package.json +1 -1
- package/public/assets/{FilesTab-BjztpSdj.js → FilesTab-B0-DlSCT.js} +2 -2
- package/public/assets/{GitChangesTab-B9XraSoR.js → GitChangesTab-CxjbNBVr.js} +2 -2
- package/public/assets/{SplitFilePanel-Cu_5-Z-E.js → SplitFilePanel-CLQb-6uX.js} +1 -1
- package/public/assets/{StatusTab-D_IE79r-.js → StatusTab-CBGAuhmp.js} +1 -1
- package/public/assets/{align-justify-BKS9gyRk.js → align-justify-s5mnjsP0.js} +1 -1
- package/public/assets/{bundle-full-CXGXXlzR.js → bundle-full-lwIMY5om.js} +1 -1
- package/public/assets/{diff-viewer-CSNOYoEB.js → diff-viewer-CDtmFe6e.js} +1 -1
- package/public/assets/index-6ABz_Izb.js +1 -0
- package/public/assets/index-BPdjM9ZI.css +1 -0
- package/public/assets/index-BQK8um1r.js +1 -0
- package/public/assets/index-BkUAI4ZY.js +1 -0
- package/public/assets/index-D8bkUvEd.js +2 -0
- package/public/assets/index-DY_sbCt9.js +1 -0
- package/public/assets/index-DhmUOdAI.js +1 -0
- package/public/assets/{index-sLe9hEfQ.js → index-DupnEKCQ.js} +1 -1
- package/public/assets/index-HhZzWWha.js +1 -0
- package/public/assets/{index-DVc4ls8c.js → index-lBAEWdAF.js} +1 -1
- package/public/assets/index-nVII4VJz.js +1 -0
- package/public/assets/index-p1Sble5V.js +1 -0
- package/public/assets/{loading-CDmt9OJU.js → loading-h8DvUqqc.js} +1 -1
- package/public/assets/main-BxUSjoWA.js +68 -0
- package/public/assets/{markdown-1ZLSxCFT.js → markdown-Djug_spc.js} +3 -3
- package/public/assets/{monaco-viewer-D6JgH76W.js → monaco-viewer-lkUcsK65.js} +2 -2
- package/public/assets/{tool-call-CyXb63LH.js → tool-call-C4YH896w.js} +3 -3
- package/public/assets/{unified-picker-DCCdSVwI.js → unified-picker-DwNZOVlY.js} +1 -1
- package/public/assets/{wrap-text-pNMdTIq3.js → wrap-text-BLVYxvcj.js} +1 -1
- package/public/index.html +4 -4
- package/public/loading.html +4 -4
- package/public/sw.js +1 -1
- package/dist/workspaces/launch-cleanup.js +0 -132
- package/public/assets/index-B3YjNCh4.js +0 -1
- package/public/assets/index-B3ZD2_SU.js +0 -1
- package/public/assets/index-Bh2ofaQo.js +0 -1
- package/public/assets/index-CM0c9xRZ.js +0 -1
- package/public/assets/index-CdDxouJl.js +0 -2
- package/public/assets/index-D06Y2cFq.js +0 -1
- package/public/assets/index-PmE51vPh.js +0 -1
- package/public/assets/index-Qj63IiSj.css +0 -1
- package/public/assets/index-VY_zwmsG.js +0 -1
- package/public/assets/index-qiiH7egV.js +0 -1
- package/public/assets/main-CTN6Wwz1.js +0 -68
|
@@ -4,29 +4,20 @@ import { PassThrough } from "node:stream";
|
|
|
4
4
|
import { describe, it } from "node:test";
|
|
5
5
|
import pino from "pino";
|
|
6
6
|
import { EventBus } from "../events/bus";
|
|
7
|
-
import { WorkspaceRuntime, WorkspaceRuntimeIdentityCaptureError,
|
|
7
|
+
import { WorkspaceRuntime, WorkspaceRuntimeIdentityCaptureError, WorkspaceStopTimeoutError, WorkspaceWindowsTreeCleanupIncompleteError } from "./runtime";
|
|
8
8
|
class ManualTimers {
|
|
9
9
|
constructor() {
|
|
10
|
-
this.
|
|
10
|
+
this.id = 0;
|
|
11
11
|
this.pending = new Map();
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
this.pending.set(id, { callback, delayMs });
|
|
15
|
-
return id;
|
|
16
|
-
};
|
|
17
|
-
this.clearTimeout = (timer) => {
|
|
18
|
-
this.pending.delete(timer);
|
|
19
|
-
};
|
|
12
|
+
this.set = (callback, delay) => { const id = ++this.id; this.pending.set(id, { callback, delay }); return id; };
|
|
13
|
+
this.clear = (timer) => this.pending.delete(timer);
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
const next =
|
|
15
|
+
run() {
|
|
16
|
+
const next = [...this.pending].sort((a, b) => a[1].delay - b[1].delay || a[0] - b[0])[0];
|
|
23
17
|
assert.ok(next, "expected a pending timer");
|
|
24
18
|
this.pending.delete(next[0]);
|
|
25
19
|
next[1].callback();
|
|
26
20
|
}
|
|
27
|
-
get size() {
|
|
28
|
-
return this.pending.size;
|
|
29
|
-
}
|
|
30
21
|
}
|
|
31
22
|
class FakeChild extends EventEmitter {
|
|
32
23
|
constructor(pid = 4242) {
|
|
@@ -34,570 +25,254 @@ class FakeChild extends EventEmitter {
|
|
|
34
25
|
this.pid = pid;
|
|
35
26
|
this.stdout = new PassThrough();
|
|
36
27
|
this.stderr = new PassThrough();
|
|
37
|
-
this.liveSignals = [];
|
|
38
28
|
this.exitCode = null;
|
|
39
29
|
this.signalCode = null;
|
|
30
|
+
this.signals = [];
|
|
40
31
|
}
|
|
41
|
-
kill(signal = "SIGTERM") {
|
|
42
|
-
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
exit(code, signal) {
|
|
46
|
-
this.exitCode = code;
|
|
47
|
-
this.signalCode = signal;
|
|
48
|
-
this.emit("exit", code, signal);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function result(stdout = "", status = 0, stderr = "") {
|
|
52
|
-
return { pid: 1, output: [null, stdout, stderr], stdout, stderr, status, signal: null };
|
|
53
|
-
}
|
|
54
|
-
function linuxRows(rows, bootId = "boot-a") {
|
|
55
|
-
return rows.map(([pid, parentPid, groupId, start]) => `${pid}|${parentPid}|${groupId}|${start}|${bootId}|${start}`).join("\n");
|
|
56
|
-
}
|
|
57
|
-
function windowsRows(rows) {
|
|
58
|
-
return rows.map(([pid, parentPid, start], index) => `${pid}|${parentPid}|0|${start}||${100 + index}`).join("\n");
|
|
59
|
-
}
|
|
60
|
-
function guardedRows(matched, rows, cutoff, bootId = "boot-a") {
|
|
61
|
-
const targets = rows.map(([pid, parentPid, groupId, start]) => `CODENOMAD_TARGET|${pid}|${parentPid}|${groupId}|${start}|${bootId}|${start}`);
|
|
62
|
-
return [...targets, `CODENOMAD_RESULT|${matched ? "1" : "0"}|${cutoff ?? ""}|${targets.length > 0 ? "1" : "0"}`].join("\n");
|
|
63
|
-
}
|
|
64
|
-
function tokenSignalRows(rows, bootId = "boot-a") {
|
|
65
|
-
return [
|
|
66
|
-
...rows.map(([pid, parentPid, groupId, start]) => `CODENOMAD_TARGET|${pid}|${parentPid}|${groupId}|${start}|${bootId}|${start}`),
|
|
67
|
-
`CODENOMAD_RESULT|${rows.length > 0 ? "1" : "0"}`,
|
|
68
|
-
].join("\n");
|
|
69
|
-
}
|
|
70
|
-
function isTokenCleanup(args) {
|
|
71
|
-
return args.includes("codenomad-token-cleanup");
|
|
32
|
+
kill(signal = "SIGTERM") { this.signals.push(signal); return true; }
|
|
33
|
+
exit(code = 0, signal = null) { this.exitCode = code; this.signalCode = signal; this.emit("exit", code, signal); }
|
|
72
34
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
35
|
+
const result = (stdout = "", status = 0, stderr = "") => ({ pid: 1, output: [null, stdout, stderr], stdout, stderr, status, signal: null });
|
|
36
|
+
const posix = (rows, boot = "boot-a") => rows.map(([pid, ppid, pgid, start]) => `${pid}|${ppid}|${pgid}|${start}|${boot}|${start}`).join("\n");
|
|
37
|
+
const portable = (rows) => rows.map(([pid, ppid, pgid, start, command]) => `${pid} ${ppid} ${pgid} ${start} ${command}`).join("\n");
|
|
38
|
+
const windows = (rows) => rows.map(([pid, ppid, start], i) => `${pid}|${ppid}|0|${start}||${100 + i}`).join("\n");
|
|
39
|
+
const guarded = (matched, rows, boot = "boot-a") => [
|
|
40
|
+
...rows.map(([pid, ppid, pgid, start]) => `CODENOMAD_TARGET|${pid}|${ppid}|${pgid}|${start}|${boot}|${start}`),
|
|
41
|
+
`CODENOMAD_RESULT|${matched ? "1" : "0"}|200|${rows.length ? "1" : "0"}`,
|
|
42
|
+
].join("\n");
|
|
43
|
+
const token = (rows, signal, boot = "boot-a") => [
|
|
44
|
+
...rows.map(([pid, ppid, pgid, start]) => `${signal ? "CODENOMAD_TARGET" : "CODENOMAD_PROCESS"}|${pid}|${ppid}|${pgid}|${start}|${boot}|${start}`),
|
|
45
|
+
...(signal ? [`CODENOMAD_RESULT|${rows.length ? "1" : "0"}`] : []),
|
|
46
|
+
].join("\n");
|
|
47
|
+
const isToken = (args) => args.includes("codenomad-token-cleanup");
|
|
48
|
+
const isSignal = (args) => isToken(args) && (args.includes("TERM") || args.includes("KILL"));
|
|
49
|
+
const isGuarded = (args) => !isToken(args) && args.some((arg) => arg.includes("guarded-signal") || arg.includes("CODENOMAD_RESULT"));
|
|
50
|
+
async function harness(options = {}) {
|
|
80
51
|
const child = new FakeChild();
|
|
81
52
|
const timers = new ManualTimers();
|
|
53
|
+
const calls = [];
|
|
82
54
|
const platform = options.platform ?? "linux";
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
? result(windowsRows([[4242, 1, "win-start"]]))
|
|
96
|
-
: result(linuxRows([[4242, 1, 4242, "100"]]));
|
|
55
|
+
const command = options.spawnSync ?? ((command, args) => {
|
|
56
|
+
calls.push({ command, args: [...args] });
|
|
57
|
+
const alive = child.exitCode === null && child.signalCode === null;
|
|
58
|
+
if (isToken(args))
|
|
59
|
+
return result(token(alive ? [[4242, 1, 4242, "100"]] : [], isSignal(args)));
|
|
60
|
+
if (isGuarded(args))
|
|
61
|
+
return result(platform === "win32"
|
|
62
|
+
? "CODENOMAD_TARGET|4242|1|0|win-start||100\nCODENOMAD_RESULT|1||1"
|
|
63
|
+
: guarded(true, [[4242, 1, 4242, "100"]]));
|
|
64
|
+
return result(platform === "win32"
|
|
65
|
+
? windows(alive ? [[4242, 1, "win-start"]] : [])
|
|
66
|
+
: posix(alive ? [[4242, 1, 4242, "100"]] : [[1, 0, 1, "10"]]));
|
|
97
67
|
});
|
|
98
68
|
const runtime = new WorkspaceRuntime(new EventBus(), pino({ level: "silent" }), {
|
|
99
|
-
gracefulStopTimeoutMs: 10,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
...options,
|
|
103
|
-
setTimeout: timers.setTimeout,
|
|
104
|
-
clearTimeout: timers.clearTimeout,
|
|
105
|
-
spawn: (() => {
|
|
106
|
-
if (reportPort)
|
|
107
|
-
queueMicrotask(() => child.stdout.write("opencode server listening on http://127.0.0.1:4321\n"));
|
|
108
|
-
return child;
|
|
109
|
-
}),
|
|
69
|
+
platform, gracefulStopTimeoutMs: 10, forcedStopTimeoutMs: 10, ...options,
|
|
70
|
+
spawnSync: command, setTimeout: timers.set, clearTimeout: timers.clear,
|
|
71
|
+
spawn: (() => child),
|
|
110
72
|
});
|
|
111
|
-
const
|
|
112
|
-
|
|
73
|
+
const abort = new AbortController();
|
|
74
|
+
const folder = platform === "win32" && process.platform !== "win32" ? `/${process.cwd()}` : process.cwd();
|
|
75
|
+
const launch = runtime.launch({ workspaceId: "w", folder, binaryPath: options.binary ?? "opencode", signal: abort.signal });
|
|
76
|
+
if (options.report !== false) {
|
|
77
|
+
queueMicrotask(() => child.stdout.write(options.output ?? "opencode server listening on http://127.0.0.1:4321\n"));
|
|
113
78
|
await launch;
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
function setWslIdentity(runtime) {
|
|
117
|
-
const managed = runtime.processes.get("workspace-1");
|
|
118
|
-
assert.ok(managed);
|
|
119
|
-
managed.processKind = "wsl";
|
|
120
|
-
managed.wsl = {
|
|
121
|
-
distro: "Ubuntu",
|
|
122
|
-
linuxPid: 99,
|
|
123
|
-
linuxPgid: 99,
|
|
124
|
-
leaderStartTime: "50",
|
|
125
|
-
bootId: "wsl-boot",
|
|
126
|
-
members: new Map([[99, { pid: 99, parentPid: 1, groupId: 99, startTime: "50", bootId: "wsl-boot", startOrder: "50" }]]),
|
|
127
|
-
};
|
|
79
|
+
}
|
|
80
|
+
return { runtime, child, timers, calls, launch, abort };
|
|
128
81
|
}
|
|
129
|
-
describe("workspace runtime
|
|
130
|
-
it("
|
|
131
|
-
|
|
82
|
+
describe("workspace runtime lifecycle contracts", () => {
|
|
83
|
+
it("cancels before spawn and while waiting for a port without losing retryable cleanup", async () => {
|
|
84
|
+
let spawned = false;
|
|
132
85
|
const runtime = new WorkspaceRuntime(new EventBus(), pino({ level: "silent" }), {
|
|
133
|
-
|
|
134
|
-
spawn: (() => child),
|
|
135
|
-
spawnSync: (() => result()),
|
|
86
|
+
spawn: (() => { spawned = true; return new FakeChild(); }),
|
|
136
87
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
assert.
|
|
140
|
-
|
|
141
|
-
it("rejects a direct Windows launch without immutable process identity", async () => {
|
|
142
|
-
let commandCalls = 0;
|
|
143
|
-
const harness = await createRuntime({
|
|
144
|
-
platform: "win32",
|
|
145
|
-
spawnSync: (() => {
|
|
146
|
-
commandCalls += 1;
|
|
147
|
-
return result("", 1, "CIM unavailable");
|
|
148
|
-
}),
|
|
149
|
-
}, false, "opencode.exe");
|
|
150
|
-
await assert.rejects(harness.launch, WorkspaceRuntimeIdentityCaptureError);
|
|
151
|
-
assert.ok(commandCalls >= 1);
|
|
152
|
-
assert.deepEqual(harness.child.liveSignals, ["SIGTERM"]);
|
|
153
|
-
harness.child.exit(null, "SIGTERM");
|
|
154
|
-
});
|
|
155
|
-
it("stops an identity-matched direct Windows process tree", async () => {
|
|
88
|
+
const pre = new AbortController();
|
|
89
|
+
pre.abort(new Error("pre-cancelled"));
|
|
90
|
+
await assert.rejects(runtime.launch({ workspaceId: "pre", folder: process.cwd(), binaryPath: "opencode", signal: pre.signal }), /pre-cancelled/);
|
|
91
|
+
assert.equal(spawned, false);
|
|
156
92
|
let alive = true;
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
assert.
|
|
177
|
-
|
|
178
|
-
|
|
93
|
+
const h = await harness({ report: false, spawnSync: ((_command, args) => {
|
|
94
|
+
if (isToken(args))
|
|
95
|
+
return result(token(alive ? [[4242, 1, 4242, "100"]] : [], isSignal(args)));
|
|
96
|
+
if (isGuarded(args))
|
|
97
|
+
return result(guarded(true, [[4242, 1, 4242, "100"]]));
|
|
98
|
+
return result(posix(alive ? [[4242, 1, 4242, "100"]] : [[1, 0, 1, "10"]]));
|
|
99
|
+
}) });
|
|
100
|
+
h.abort.abort(new Error("port-cancelled"));
|
|
101
|
+
await assert.rejects(h.launch, /port-cancelled/);
|
|
102
|
+
const first = h.runtime.stop("w");
|
|
103
|
+
h.timers.run();
|
|
104
|
+
h.timers.run();
|
|
105
|
+
await assert.rejects(first, WorkspaceStopTimeoutError);
|
|
106
|
+
alive = false;
|
|
107
|
+
const retry = h.runtime.stop("w");
|
|
108
|
+
h.child.exit();
|
|
109
|
+
await retry;
|
|
110
|
+
const direct = await harness({ report: false });
|
|
111
|
+
const stopped = direct.runtime.stop("w");
|
|
112
|
+
await assert.rejects(direct.launch, /runtime launch was cancelled/);
|
|
113
|
+
direct.child.exit();
|
|
114
|
+
await stopped;
|
|
179
115
|
});
|
|
180
|
-
it("
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
harness.timers.runNext();
|
|
193
|
-
harness.timers.runNext();
|
|
194
|
-
await assert.rejects(stop, WorkspaceStopTimeoutError);
|
|
195
|
-
assert.equal(commands.filter(({ args }) => isGuarded(args)).length, 2);
|
|
196
|
-
assert.equal(commands.some(({ command }) => command === "taskkill.exe"), false);
|
|
197
|
-
assert.deepEqual(harness.child.liveSignals, []);
|
|
116
|
+
it("rejects launches whose immutable identity cannot be captured and safely cleans up", async () => {
|
|
117
|
+
for (const scenario of [{ platform: "linux", binary: "opencode" }, { platform: "win32", binary: "opencode.exe" }]) {
|
|
118
|
+
const child = new FakeChild(scenario.platform === "linux" ? undefined : 4242);
|
|
119
|
+
const runtime = new WorkspaceRuntime(new EventBus(), pino({ level: "silent" }), {
|
|
120
|
+
platform: scenario.platform,
|
|
121
|
+
spawn: (() => child),
|
|
122
|
+
spawnSync: (() => result("", 1, "identity unavailable")),
|
|
123
|
+
});
|
|
124
|
+
await assert.rejects(runtime.launch({ workspaceId: scenario.platform, folder: process.cwd(), binaryPath: scenario.binary }), WorkspaceRuntimeIdentityCaptureError);
|
|
125
|
+
assert.deepEqual(child.signals, ["SIGTERM"]);
|
|
126
|
+
assert.doesNotThrow(() => child.emit("error", new Error("late spawn error")));
|
|
127
|
+
}
|
|
198
128
|
});
|
|
199
|
-
it("
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
platform: "win32",
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
129
|
+
it("signals identity-matched POSIX, Windows, and WSL processes", async () => {
|
|
130
|
+
const scenarios = [
|
|
131
|
+
{ name: "POSIX", platform: "linux", binary: "opencode", marker: "codenomad-guarded-signal" },
|
|
132
|
+
{ name: "Windows", platform: "win32", binary: "opencode.exe", marker: "CODENOMAD_RESULT" },
|
|
133
|
+
{ name: "WSL", platform: "win32", binary: "\\\\wsl$\\Ubuntu\\usr\\bin\\opencode", marker: "codenomad-wsl-guarded-signal",
|
|
134
|
+
output: "__CODENOMAD_WSL_PID__:99:99:50:wsl-boot\nopencode server listening on http://127.0.0.1:4321\n" },
|
|
135
|
+
];
|
|
136
|
+
for (const scenario of scenarios) {
|
|
137
|
+
let alive = true;
|
|
138
|
+
const calls = [];
|
|
139
|
+
const h = await harness({ platform: scenario.platform, binary: scenario.binary, output: scenario.output, spawnSync: ((command, args) => {
|
|
140
|
+
calls.push({ command, args: [...args] });
|
|
141
|
+
const wsl = scenario.name === "WSL";
|
|
142
|
+
if (wsl && command === "powershell.exe")
|
|
143
|
+
return result(windows([[4242, 1, "host-start"]]));
|
|
144
|
+
if (isToken(args)) {
|
|
145
|
+
const rows = alive ? [[wsl ? 99 : 4242, 1, wsl ? 99 : 4242, wsl ? "50" : "100"]] : [];
|
|
146
|
+
if (isSignal(args))
|
|
147
|
+
alive = false;
|
|
148
|
+
return result(token(rows, isSignal(args), wsl ? "wsl-boot" : "boot-a"));
|
|
213
149
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (stage === "tree") {
|
|
218
|
-
return result(windowsRows([[4242, 1, "win-start"], [4243, 4242, "descendant-start"]]));
|
|
219
|
-
}
|
|
220
|
-
if (stage === "descendant") {
|
|
221
|
-
return result(windowsRows([[4243, 1, "descendant-start"]]));
|
|
222
|
-
}
|
|
223
|
-
return result(windowsRows([[7, 1, "other-start"]]));
|
|
224
|
-
}),
|
|
225
|
-
}, true, "opencode.exe");
|
|
226
|
-
let settled = false;
|
|
227
|
-
const stop = harness.runtime.stop("workspace-1").finally(() => { settled = true; });
|
|
228
|
-
await Promise.resolve();
|
|
229
|
-
assert.equal(settled, false);
|
|
230
|
-
harness.timers.runNext();
|
|
231
|
-
harness.timers.runNext();
|
|
232
|
-
await stop;
|
|
233
|
-
assert.equal(guardedCalls, 2);
|
|
234
|
-
});
|
|
235
|
-
it("cleans a token-matching descendant that survives its unidentified wrapper", async () => {
|
|
236
|
-
const child = new FakeChild();
|
|
237
|
-
const timers = new ManualTimers();
|
|
238
|
-
let tokenAlive = true;
|
|
239
|
-
let spawnedToken = "";
|
|
240
|
-
let logs = "";
|
|
241
|
-
const tokenSignals = [];
|
|
242
|
-
const runtime = new WorkspaceRuntime(new EventBus(), pino({ level: "trace" }, {
|
|
243
|
-
write: (chunk) => { logs += chunk; },
|
|
244
|
-
}), {
|
|
245
|
-
platform: "linux",
|
|
246
|
-
spawnSync: ((_command, args) => {
|
|
247
|
-
if (isTokenCleanup(args)) {
|
|
248
|
-
if (isTokenSignal(args)) {
|
|
249
|
-
const rows = tokenAlive
|
|
250
|
-
? [[5000, 1, 4242, "150"]]
|
|
251
|
-
: [];
|
|
252
|
-
tokenSignals.push(rows.map(([pid]) => pid));
|
|
253
|
-
tokenAlive = false;
|
|
254
|
-
return result(tokenSignalRows(rows));
|
|
150
|
+
if (isGuarded(args)) {
|
|
151
|
+
alive = false;
|
|
152
|
+
return result(wsl ? guarded(true, [[99, 1, 99, "50"]], "wsl-boot") : scenario.platform === "win32" ? "CODENOMAD_TARGET|4242|1|0|win-start||100\nCODENOMAD_RESULT|1||1" : guarded(true, [[4242, 1, 4242, "100"]]));
|
|
255
153
|
}
|
|
256
|
-
return result(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
assert.equal(runtime.processes.size, 0);
|
|
269
|
-
assert.deepEqual(child.liveSignals, ["SIGTERM"]);
|
|
270
|
-
assert.match(spawnedToken, /^[a-f0-9]{64}$/);
|
|
271
|
-
assert.equal(logs.includes(spawnedToken), false);
|
|
272
|
-
assert.match(logs, /\[REDACTED\]/);
|
|
273
|
-
assert.deepEqual(tokenSignals, [[5000]]);
|
|
274
|
-
});
|
|
275
|
-
it("uses one guarded command per signal", async () => {
|
|
276
|
-
const guardedInvocations = [];
|
|
277
|
-
const mutableInvocations = guardedInvocations;
|
|
278
|
-
const spawnCommand = ((_command, args) => {
|
|
279
|
-
if (isTokenCleanup(args)) {
|
|
280
|
-
return isTokenSignal(args)
|
|
281
|
-
? result(tokenSignalRows([[4242, 1, 4242, "100"]]))
|
|
282
|
-
: result(linuxRows([[4242, 1, 4242, "100"]]));
|
|
283
|
-
}
|
|
284
|
-
if (isGuarded(args)) {
|
|
285
|
-
mutableInvocations.push([...args]);
|
|
286
|
-
return result(guardedRows(true, [[4242, 1, 4242, "100"]], "200"));
|
|
287
|
-
}
|
|
288
|
-
return result(linuxRows([[4242, 1, 4242, "100"]]));
|
|
289
|
-
});
|
|
290
|
-
const harness = await createRuntime({
|
|
291
|
-
platform: "linux",
|
|
292
|
-
spawnSync: spawnCommand,
|
|
293
|
-
});
|
|
294
|
-
const stop = harness.runtime.stop("workspace-1");
|
|
295
|
-
harness.timers.runNext();
|
|
296
|
-
harness.timers.runNext();
|
|
297
|
-
await assert.rejects(stop, WorkspaceStopTimeoutError);
|
|
298
|
-
assert.equal(guardedInvocations.length, 2);
|
|
299
|
-
assert.ok(guardedInvocations.every((args) => args.includes("codenomad-guarded-signal")));
|
|
300
|
-
});
|
|
301
|
-
it("sends no second command when the guarded operation reports identity mismatch", async () => {
|
|
302
|
-
let launchProbe = true;
|
|
303
|
-
let guardedCommands = 0;
|
|
304
|
-
const spawnCommand = ((_command, args) => {
|
|
305
|
-
if (isTokenCleanup(args))
|
|
306
|
-
return result(isTokenSignal(args) ? tokenSignalRows([]) : "");
|
|
307
|
-
if (isGuarded(args)) {
|
|
308
|
-
guardedCommands += 1;
|
|
309
|
-
return result("CODENOMAD_RESULT|0||0");
|
|
310
|
-
}
|
|
311
|
-
if (launchProbe) {
|
|
312
|
-
launchProbe = false;
|
|
313
|
-
return result(linuxRows([[4242, 1, 4242, "100"]]));
|
|
314
|
-
}
|
|
315
|
-
return result(linuxRows([[4242, 1, 4242, "300"]]));
|
|
316
|
-
});
|
|
317
|
-
const harness = await createRuntime({ platform: "linux", spawnSync: spawnCommand });
|
|
318
|
-
const stop = harness.runtime.stop("workspace-1");
|
|
319
|
-
await stop;
|
|
320
|
-
assert.equal(guardedCommands, 1);
|
|
321
|
-
});
|
|
322
|
-
it("tracks a descendant forked between the precheck and SIGTERM dispatch", async () => {
|
|
323
|
-
let phase = "launch";
|
|
324
|
-
const guardedTargets = [];
|
|
325
|
-
const spawnCommand = ((_command, args) => {
|
|
326
|
-
if (isTokenCleanup(args)) {
|
|
327
|
-
const rows = phase === "after-term" ? [[5000, 4242, 4242, "120"]] : [];
|
|
328
|
-
return result(isTokenSignal(args) ? tokenSignalRows(rows) : linuxRows(rows));
|
|
329
|
-
}
|
|
330
|
-
if (isGuarded(args)) {
|
|
331
|
-
guardedTargets.push([...args]);
|
|
332
|
-
if (phase === "launch") {
|
|
333
|
-
phase = "after-term";
|
|
334
|
-
return result(guardedRows(true, [[4242, 1, 4242, "100"], [5000, 4242, 4242, "120"]], "200"));
|
|
335
|
-
}
|
|
336
|
-
phase = "after-kill";
|
|
337
|
-
return result(guardedRows(false, [[5000, 4242, 4242, "120"]]));
|
|
338
|
-
}
|
|
339
|
-
if (phase === "launch")
|
|
340
|
-
return result(linuxRows([[4242, 1, 4242, "100"]]));
|
|
341
|
-
if (phase === "after-term")
|
|
342
|
-
return result(linuxRows([[5000, 1, 4242, "120"]]));
|
|
343
|
-
return result(linuxRows([[7, 1, 7, "10"]]));
|
|
344
|
-
});
|
|
345
|
-
const harness = await createRuntime({ platform: "linux", spawnSync: spawnCommand });
|
|
346
|
-
const stop = harness.runtime.stop("workspace-1");
|
|
347
|
-
harness.timers.runNext();
|
|
348
|
-
harness.timers.runNext();
|
|
349
|
-
await stop;
|
|
350
|
-
assert.ok(guardedTargets[1]?.includes("5000"));
|
|
351
|
-
assert.ok(guardedTargets[1]?.includes("120"));
|
|
352
|
-
});
|
|
353
|
-
it("adopts a descendant forked after SIGTERM and before the returned cutoff", async () => {
|
|
354
|
-
let phase = "launch";
|
|
355
|
-
const guardedTargets = [];
|
|
356
|
-
const spawnCommand = ((_command, args) => {
|
|
357
|
-
if (isTokenCleanup(args)) {
|
|
358
|
-
const rows = phase === "after-term" ? [[5000, 1, 4242, "150"]] : [];
|
|
359
|
-
return result(isTokenSignal(args) ? tokenSignalRows(rows) : linuxRows(rows));
|
|
360
|
-
}
|
|
361
|
-
if (isGuarded(args)) {
|
|
362
|
-
guardedTargets.push([...args]);
|
|
363
|
-
if (phase === "launch") {
|
|
364
|
-
phase = "after-term";
|
|
365
|
-
return result(guardedRows(true, [[4242, 1, 4242, "100"]], "200"));
|
|
366
|
-
}
|
|
367
|
-
phase = "after-kill";
|
|
368
|
-
return result(guardedRows(false, [[5000, 4242, 4242, "150"]]));
|
|
369
|
-
}
|
|
370
|
-
if (phase === "launch")
|
|
371
|
-
return result(linuxRows([[4242, 1, 4242, "100"]]));
|
|
372
|
-
if (phase === "after-term") {
|
|
373
|
-
return result(linuxRows([[5000, 1, 4242, "150"]]));
|
|
374
|
-
}
|
|
375
|
-
return result(linuxRows([[7, 1, 7, "10"]]));
|
|
376
|
-
});
|
|
377
|
-
const harness = await createRuntime({ platform: "linux", spawnSync: spawnCommand });
|
|
378
|
-
const stop = harness.runtime.stop("workspace-1");
|
|
379
|
-
harness.child.exit(0, null);
|
|
380
|
-
harness.timers.runNext();
|
|
381
|
-
harness.timers.runNext();
|
|
382
|
-
await stop;
|
|
383
|
-
assert.equal(guardedTargets.length, 2);
|
|
384
|
-
assert.ok(guardedTargets[1]?.includes("5000"), "SIGKILL must include the newly tracked immutable descendant");
|
|
385
|
-
assert.ok(guardedTargets[1]?.includes("150"));
|
|
154
|
+
return result(wsl
|
|
155
|
+
? posix(alive ? [[99, 1, 99, "50"]] : [[1, 0, 1, "10"]], "wsl-boot")
|
|
156
|
+
: scenario.platform === "win32"
|
|
157
|
+
? windows(alive ? [[4242, 1, "win-start"]] : [[1, 0, "system-start"]])
|
|
158
|
+
: posix(alive ? [[4242, 1, 4242, "100"]] : [[1, 0, 1, "10"]]));
|
|
159
|
+
}) });
|
|
160
|
+
const stop = h.runtime.stop("w");
|
|
161
|
+
h.child.exit();
|
|
162
|
+
await stop;
|
|
163
|
+
assert.ok(calls.some(({ args }) => args.some((arg) => arg.includes(scenario.marker))), `${scenario.name} signal`);
|
|
164
|
+
assert.equal(calls.some(({ command }) => command === "taskkill.exe"), false);
|
|
165
|
+
}
|
|
386
166
|
});
|
|
387
|
-
it("does not
|
|
167
|
+
it("does not signal a reused PID or process group", async () => {
|
|
388
168
|
let launched = false;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
? result(linuxRows([[4242, 1, 4242, "300"], [6000, 4242, 4242, "150"]]))
|
|
405
|
-
: result(linuxRows([[4242, 1, 4242, "100"]]));
|
|
406
|
-
});
|
|
407
|
-
const harness = await createRuntime({ platform: "linux", spawnSync: spawnCommand });
|
|
408
|
-
const stop = harness.runtime.stop("workspace-1");
|
|
409
|
-
await stop;
|
|
410
|
-
assert.equal(guardedCommands, 1);
|
|
169
|
+
const calls = [];
|
|
170
|
+
const h = await harness({ spawnSync: ((_command, args) => {
|
|
171
|
+
calls.push([...args]);
|
|
172
|
+
if (isToken(args))
|
|
173
|
+
return result(token([], isSignal(args)));
|
|
174
|
+
if (isGuarded(args))
|
|
175
|
+
return result(guarded(true, [[4242, 1, 4242, "100"]]));
|
|
176
|
+
if (!launched) {
|
|
177
|
+
launched = true;
|
|
178
|
+
return result(posix([[4242, 1, 4242, "100"]]));
|
|
179
|
+
}
|
|
180
|
+
return result(posix([[4242, 1, 4242, "300"], [6000, 4242, 4242, "150"]]));
|
|
181
|
+
}) });
|
|
182
|
+
await h.runtime.stop("w");
|
|
183
|
+
assert.ok(calls.every((args) => !args.includes("6000") && !args.includes("300")));
|
|
411
184
|
});
|
|
412
|
-
it("
|
|
185
|
+
it("retains and cleans a portable process group after its leader exits", async () => {
|
|
186
|
+
const start = "Fri Jul 10 12:34:56 2026";
|
|
413
187
|
let alive = true;
|
|
414
|
-
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
const rows = alive ? [[99, 1, 99, "50"]] : [];
|
|
420
|
-
if (isTokenSignal(args))
|
|
188
|
+
let leaderExited = false;
|
|
189
|
+
const guardedCalls = [];
|
|
190
|
+
const h = await harness({ platform: "darwin", spawnSync: ((_command, args) => {
|
|
191
|
+
if (isGuarded(args)) {
|
|
192
|
+
guardedCalls.push([...args]);
|
|
421
193
|
alive = false;
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
await stop;
|
|
438
|
-
assert.equal(guardedCommands.length, 1);
|
|
439
|
-
assert.ok(guardedCommands[0]?.includes("wsl-boot"));
|
|
194
|
+
return result(`CODENOMAD_TARGET_B64|5000|1|4242|${Buffer.from(start).toString("base64")}|${Buffer.from("opencode-child").toString("base64")}\nCODENOMAD_RESULT|1||1`);
|
|
195
|
+
}
|
|
196
|
+
const rows = !alive
|
|
197
|
+
? []
|
|
198
|
+
: leaderExited
|
|
199
|
+
? [[5000, 4242, 4242, start, "opencode-child"]]
|
|
200
|
+
: [[4242, 1, 4242, start, "opencode"]];
|
|
201
|
+
return result(portable(rows));
|
|
202
|
+
}) });
|
|
203
|
+
leaderExited = true;
|
|
204
|
+
h.child.exit(1);
|
|
205
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
206
|
+
assert.equal(guardedCalls.length, 1);
|
|
207
|
+
assert.equal(guardedCalls[0]?.[7], "1");
|
|
208
|
+
assert.equal(h.runtime.processes.size, 0);
|
|
440
209
|
});
|
|
441
|
-
it("
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
210
|
+
it("refuses a leaderless portable group when no retained identity anchor remains", async () => {
|
|
211
|
+
const start = "Fri Jul 10 12:34:56 2026";
|
|
212
|
+
let leaderExited = false;
|
|
213
|
+
const guardedCalls = [];
|
|
214
|
+
const h = await harness({ platform: "darwin", spawnSync: ((_command, args) => {
|
|
215
|
+
if (isGuarded(args)) {
|
|
216
|
+
guardedCalls.push([...args]);
|
|
217
|
+
return result("CODENOMAD_RESULT|0||0");
|
|
218
|
+
}
|
|
219
|
+
return result(portable(leaderExited
|
|
220
|
+
? [[6000, 1, 4242, "Fri Jul 10 99:99:99 2026", "unverified-process"]]
|
|
221
|
+
: [[4242, 1, 4242, start, "opencode"]]));
|
|
222
|
+
}) });
|
|
223
|
+
leaderExited = true;
|
|
224
|
+
h.child.exit(1);
|
|
225
|
+
const cleanup = h.runtime.stop("w");
|
|
226
|
+
h.timers.run();
|
|
227
|
+
h.timers.run();
|
|
228
|
+
await assert.rejects(cleanup, (error) => error instanceof WorkspaceStopTimeoutError && /no longer has a verified identity anchor/.test(error.message));
|
|
229
|
+
assert.equal(guardedCalls.length, 2);
|
|
230
|
+
assert.ok(guardedCalls.every((args) => args[7] === "1" && !args.includes("6000")));
|
|
231
|
+
assert.equal(h.runtime.processes.size, 1);
|
|
453
232
|
});
|
|
454
|
-
it("
|
|
455
|
-
const
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
assert.
|
|
466
|
-
["/PID", "4242", "/T"],
|
|
467
|
-
["/PID", "4242", "/T", "/F"],
|
|
468
|
-
]);
|
|
469
|
-
harness.child.exit(0, null);
|
|
470
|
-
await stop;
|
|
233
|
+
it("bounds direct Windows cleanup without falling back to taskkill", async () => {
|
|
234
|
+
const calls = [];
|
|
235
|
+
const h = await harness({ platform: "win32", binary: "opencode.exe", spawnSync: ((command, args) => {
|
|
236
|
+
calls.push({ command, args: [...args] });
|
|
237
|
+
return isGuarded(args) ? result("CODENOMAD_TARGET|4242|1|0|win-start||100\nCODENOMAD_RESULT|1||1") : result(windows([[4242, 1, "win-start"]]));
|
|
238
|
+
}) });
|
|
239
|
+
const stop = h.runtime.stop("w");
|
|
240
|
+
h.timers.run();
|
|
241
|
+
h.timers.run();
|
|
242
|
+
await assert.rejects(stop, WorkspaceStopTimeoutError);
|
|
243
|
+
assert.equal(calls.some(({ command }) => command === "taskkill.exe"), false);
|
|
244
|
+
assert.equal(calls.filter(({ args }) => isGuarded(args)).length, 2);
|
|
471
245
|
});
|
|
472
|
-
it("
|
|
246
|
+
it("escalates wrapper cleanup, reports incomplete exited trees, and permits retry", async () => {
|
|
473
247
|
let available = false;
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
assert.match(error.message, /taskkill \/T \/F failed: taskkill unavailable/);
|
|
485
|
-
return true;
|
|
486
|
-
});
|
|
248
|
+
const calls = [];
|
|
249
|
+
const h = await harness({ platform: "win32", binary: "opencode.cmd", spawnSync: ((command, args) => {
|
|
250
|
+
calls.push({ command, args: [...args] });
|
|
251
|
+
return available ? result() : result("", 1, "taskkill unavailable");
|
|
252
|
+
}) });
|
|
253
|
+
const first = h.runtime.stop("w");
|
|
254
|
+
h.timers.run();
|
|
255
|
+
h.timers.run();
|
|
256
|
+
await assert.rejects(first, (error) => error instanceof WorkspaceStopTimeoutError && /\/T \/F failed/.test(error.message));
|
|
257
|
+
assert.deepEqual(calls.map(({ args }) => args), [["/PID", "4242", "/T"], ["/PID", "4242", "/T", "/F"]]);
|
|
487
258
|
available = true;
|
|
488
|
-
const retry =
|
|
489
|
-
|
|
259
|
+
const retry = h.runtime.stop("w");
|
|
260
|
+
h.child.exit();
|
|
490
261
|
await retry;
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
spawnSync: ((_command, args) => {
|
|
497
|
-
invocations.push([...args]);
|
|
498
|
-
return result("", 1, "taskkill unavailable");
|
|
499
|
-
}),
|
|
500
|
-
}, true, "opencode");
|
|
501
|
-
const first = harness.runtime.stop("workspace-1");
|
|
502
|
-
harness.child.exit(1, null);
|
|
503
|
-
await assert.rejects(first, WorkspaceWindowsTreeCleanupIncompleteError);
|
|
504
|
-
assert.equal(harness.runtime.processes.size, 1);
|
|
505
|
-
assert.deepEqual(invocations, [["/PID", "4242", "/T"]]);
|
|
506
|
-
const second = harness.runtime.stop("workspace-1");
|
|
507
|
-
await assert.rejects(second, (error) => {
|
|
508
|
-
assert.ok(error instanceof WorkspaceWindowsTreeCleanupIncompleteError);
|
|
509
|
-
assert.match(error.message, /taskkill unavailable/);
|
|
510
|
-
return true;
|
|
511
|
-
});
|
|
512
|
-
assert.equal(harness.runtime.processes.size, 1);
|
|
513
|
-
assert.deepEqual(invocations, [["/PID", "4242", "/T"]]);
|
|
514
|
-
});
|
|
515
|
-
it("persists confirmed wrapper tree cleanup across a later exit and retry", async () => {
|
|
516
|
-
const invocations = [];
|
|
517
|
-
const harness = await createRuntime({
|
|
518
|
-
platform: "win32",
|
|
519
|
-
spawnSync: ((_command, args) => {
|
|
520
|
-
invocations.push([...args]);
|
|
521
|
-
return result();
|
|
522
|
-
}),
|
|
523
|
-
}, true, "opencode.cmd");
|
|
524
|
-
const first = harness.runtime.stop("workspace-1");
|
|
525
|
-
harness.timers.runNext();
|
|
526
|
-
harness.timers.runNext();
|
|
527
|
-
await assert.rejects(first, WorkspaceStopTimeoutError);
|
|
528
|
-
harness.child.exit(0, null);
|
|
529
|
-
await harness.runtime.stop("workspace-1");
|
|
530
|
-
assert.deepEqual(invocations, [
|
|
531
|
-
["/PID", "4242", "/T"],
|
|
532
|
-
["/PID", "4242", "/T", "/F"],
|
|
533
|
-
]);
|
|
534
|
-
assert.equal(harness.runtime.processes.size, 0);
|
|
535
|
-
});
|
|
536
|
-
it("retains launch identity so a transient stop failure can recover on retry", async () => {
|
|
537
|
-
let available = true;
|
|
538
|
-
let alive = true;
|
|
539
|
-
let guardedCommands = 0;
|
|
540
|
-
const spawnCommand = ((_command, args) => {
|
|
541
|
-
if (isTokenCleanup(args)) {
|
|
542
|
-
if (!available)
|
|
543
|
-
return result("", 1, "identity service unavailable");
|
|
544
|
-
const rows = alive ? [[4242, 1, 4242, "100"]] : [];
|
|
545
|
-
if (isTokenSignal(args))
|
|
546
|
-
alive = false;
|
|
547
|
-
return result(isTokenSignal(args) ? tokenSignalRows(rows) : linuxRows(rows));
|
|
548
|
-
}
|
|
549
|
-
if (isGuarded(args)) {
|
|
550
|
-
guardedCommands += 1;
|
|
551
|
-
if (!available)
|
|
552
|
-
return result("", 1, "identity service unavailable");
|
|
553
|
-
alive = false;
|
|
554
|
-
return result(guardedRows(true, [[4242, 1, 4242, "100"]], "200"));
|
|
555
|
-
}
|
|
556
|
-
if (!available)
|
|
557
|
-
return result("", 1, "identity service unavailable");
|
|
558
|
-
return result(alive ? linuxRows([[4242, 1, 4242, "100"]]) : linuxRows([[7, 1, 7, "10"]]));
|
|
559
|
-
});
|
|
560
|
-
const harness = await createRuntime({ platform: "linux", spawnSync: spawnCommand });
|
|
561
|
-
available = false;
|
|
562
|
-
const first = harness.runtime.stop("workspace-1");
|
|
563
|
-
harness.timers.runNext();
|
|
564
|
-
harness.timers.runNext();
|
|
565
|
-
await assert.rejects(first, /cleanup could not be confirmed/);
|
|
566
|
-
available = true;
|
|
567
|
-
const retry = harness.runtime.stop("workspace-1");
|
|
568
|
-
await retry;
|
|
569
|
-
assert.equal(guardedCommands, 3);
|
|
262
|
+
const exited = await harness({ platform: "win32", binary: "opencode.cmd", spawnSync: (() => result("", 1, "taskkill unavailable")) });
|
|
263
|
+
const incomplete = exited.runtime.stop("w");
|
|
264
|
+
exited.child.exit(1);
|
|
265
|
+
await assert.rejects(incomplete, WorkspaceWindowsTreeCleanupIncompleteError);
|
|
266
|
+
await assert.rejects(exited.runtime.stop("w"), WorkspaceWindowsTreeCleanupIncompleteError);
|
|
570
267
|
});
|
|
571
268
|
it("shares one bounded stop operation across concurrent callers", async () => {
|
|
572
|
-
const
|
|
573
|
-
const first =
|
|
574
|
-
const second =
|
|
269
|
+
const h = await harness();
|
|
270
|
+
const first = h.runtime.stop("w");
|
|
271
|
+
const second = h.runtime.stop("w");
|
|
575
272
|
assert.strictEqual(first, second);
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
const
|
|
579
|
-
assert.
|
|
580
|
-
assert.equal(results[1].status, "rejected");
|
|
581
|
-
});
|
|
582
|
-
it("cancels a no-port launch while retaining retryable stop state", async () => {
|
|
583
|
-
let alive = true;
|
|
584
|
-
const spawnCommand = ((_command, args) => {
|
|
585
|
-
if (isTokenCleanup(args)) {
|
|
586
|
-
const rows = alive ? [[4242, 1, 4242, "100"]] : [];
|
|
587
|
-
return result(isTokenSignal(args) ? tokenSignalRows(rows) : linuxRows(rows));
|
|
588
|
-
}
|
|
589
|
-
if (isGuarded(args))
|
|
590
|
-
return result(guardedRows(true, [[4242, 1, 4242, "100"]], "200"));
|
|
591
|
-
return result(alive ? linuxRows([[4242, 1, 4242, "100"]]) : linuxRows([[7, 1, 7, "10"]]));
|
|
592
|
-
});
|
|
593
|
-
const harness = await createRuntime({ platform: "linux", spawnSync: spawnCommand }, false);
|
|
594
|
-
const firstStop = harness.runtime.stop("workspace-1");
|
|
595
|
-
await assert.rejects(harness.launch, WorkspaceRuntimeLaunchCancelledError);
|
|
596
|
-
harness.timers.runNext();
|
|
597
|
-
harness.timers.runNext();
|
|
598
|
-
await assert.rejects(firstStop, WorkspaceStopTimeoutError);
|
|
599
|
-
alive = false;
|
|
600
|
-
const retry = harness.runtime.stop("workspace-1");
|
|
601
|
-
await retry;
|
|
273
|
+
h.timers.run();
|
|
274
|
+
h.timers.run();
|
|
275
|
+
const outcomes = await Promise.allSettled([first, second]);
|
|
276
|
+
assert.deepEqual(outcomes.map(({ status }) => status), ["rejected", "rejected"]);
|
|
602
277
|
});
|
|
603
278
|
});
|