architecture-harness 0.25.1 → 0.26.0
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/package.json +2 -18
- package/src/cli/ask.mjs +42 -0
- package/src/cli/ask.test.mjs +40 -0
- package/src/cli/check-commands.mjs +104 -7
- package/src/cli/check-commands.test.mjs +281 -7
- package/src/cli/check-full.test.mjs +152 -0
- package/src/cli/check.mjs +113 -0
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +47 -9
- package/src/cli/ci-failures.test.mjs +116 -10
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -0
- package/src/cli/ci-state.mjs +2 -2
- package/src/cli/ci-state.test.mjs +8 -8
- package/src/cli/ci-template.test.mjs +79 -1
- package/src/cli/codex-implement.mjs +373 -44
- package/src/cli/codex-implement.test.mjs +775 -14
- package/src/cli/codex-limit.test.mjs +1 -1
- package/src/cli/codex-verify.mjs +230 -0
- package/src/cli/codex-verify.test.mjs +402 -0
- package/src/cli/comment-watch.mjs +391 -0
- package/src/cli/comment-watch.test.mjs +392 -0
- package/src/cli/commit-guard.mjs +3 -3
- package/src/cli/commit-guard.test.mjs +9 -3
- package/src/cli/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -0
- package/src/cli/dispatch-guard.test.mjs +7 -7
- package/src/cli/dispatch-reminder.mjs +18 -8
- package/src/cli/dispatch-reminder.test.mjs +46 -10
- package/src/cli/dispatch-slot.mjs +2 -2
- package/src/cli/dispatch-slot.test.mjs +18 -19
- package/src/cli/dispatch.test.mjs +3 -3
- package/src/cli/fleet.mjs +180 -0
- package/src/cli/fleet.test.mjs +213 -0
- package/src/cli/gate-slot.mjs +2 -1
- package/src/cli/gh-merge-command.mjs +5 -3
- package/src/cli/gh-merge-command.test.mjs +4 -0
- package/src/cli/gh-run.mjs +50 -7
- package/src/cli/gh-run.test.mjs +35 -5
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +35 -26
- package/src/cli/integration-lane.mjs +3 -5
- package/src/cli/integration-lane.test.mjs +2 -2
- package/src/cli/ledger.test.mjs +12 -3
- package/src/cli/legs.mjs +53 -0
- package/src/cli/legs.test.mjs +70 -0
- package/src/cli/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +96 -43
- package/src/cli/merge-guard.test.mjs +272 -111
- package/src/cli/metrics.mjs +53 -0
- package/src/cli/metrics.test.mjs +73 -0
- package/src/cli/milestone.mjs +297 -0
- package/src/cli/milestone.test.mjs +294 -0
- package/src/cli/mutate.mjs +203 -0
- package/src/cli/mutate.test.mjs +134 -0
- package/src/cli/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -0
- package/src/cli/platform-risk.mjs +46 -0
- package/src/cli/platform-risk.test.mjs +38 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/qc.mjs +76 -20
- package/src/cli/qc.test.mjs +35 -1
- package/src/cli/retry-failed.mjs +3 -1
- package/src/cli/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- package/src/cli/skill-length.test.mjs +8 -0
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/watch.mjs +21 -8
- package/src/cli/watch.test.mjs +45 -21
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +1 -1
- package/src/cli/workflow-settings.mjs +3 -2
- package/src/cli/workflow-settings.test.mjs +11 -1
- package/src/config.mjs +64 -2
- package/src/config.test.mjs +93 -20
- package/src/consumer-package.test.mjs +3 -18
- package/src/descriptions.mjs +1 -0
- package/src/eslint/index.mjs +2 -0
- package/src/eslint/preset.mjs +12 -1
- package/src/eslint/preset.test.mjs +1 -1
- package/src/eslint/rules/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +34 -0
- package/src/gates/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -0
- package/src/global-skills.test.mjs +0 -1
- package/templates/docs/enforcement.md +12 -2
- package/templates/github/workflows/ci.yml +51 -4
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -85
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -133
- package/src/cli/throwaway-db.test.mjs +0 -137
- package/src/screens/auth-context.test.mjs +0 -41
- package/src/screens/auth-run.test.mjs +0 -147
- package/src/screens/auth.mjs +0 -223
- package/src/screens/auth.test.mjs +0 -76
- package/src/screens/capture-idle.test.mjs +0 -27
- package/src/screens/capture.browser-test.mjs +0 -73
- package/src/screens/capture.mjs +0 -176
- package/src/screens/capture.test.mjs +0 -28
- package/src/screens/catalog.browser-test.mjs +0 -32
- package/src/screens/catalog.mjs +0 -72
- package/src/screens/catalog.test.mjs +0 -36
- package/src/screens/chrome.mjs +0 -21
- package/src/screens/compare.mjs +0 -41
- package/src/screens/compare.test.mjs +0 -30
- package/src/screens/discovery.browser-test.mjs +0 -29
- package/src/screens/discovery.mjs +0 -158
- package/src/screens/discovery.test.mjs +0 -27
- package/src/screens/inventory.mjs +0 -69
- package/src/screens/inventory.test.mjs +0 -10
- package/src/screens/map.mjs +0 -63
- package/src/screens/map.test.mjs +0 -35
- package/src/screens/open.browser-test.mjs +0 -50
- package/src/screens/regions.mjs +0 -138
- package/src/screens/regions.test.mjs +0 -38
- package/src/screens/session-files.mjs +0 -39
- package/src/screens/session-files.test.mjs +0 -39
- package/src/screens/setup.browser-test.mjs +0 -49
- package/src/screens/setup.mjs +0 -79
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -107
- package/src/screens/stack-auth.test.mjs +0 -65
- package/src/screens/write-guard.mjs +0 -26
- package/src/stack/stack.mjs +0 -131
- package/src/stack/stack.test.mjs +0 -60
- package/src/stack/supervisor.mjs +0 -30
|
@@ -132,7 +132,7 @@ test("writeLimit refuses a symbolic link for its state folder", async (t) => {
|
|
|
132
132
|
test("writeLimit replaces a state-file link without changing its target", async (t) => {
|
|
133
133
|
const { writeLimit, readLimit } = await limit();
|
|
134
134
|
const { dir, file } = setup(t);
|
|
135
|
-
mkdirSync(path.dirname(file));
|
|
135
|
+
mkdirSync(path.dirname(file), { mode: 0o700 });
|
|
136
136
|
const target = path.join(dir, "target.txt");
|
|
137
137
|
writeFileSync(target, "keep");
|
|
138
138
|
linkSync(target, file);
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// Brief preflight and runner-owned verification proof.
|
|
2
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
3
|
+
import { appendFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { ledgerFileOf, readLedger, shaMatches } from "./ledger.mjs";
|
|
7
|
+
import { redactOutput } from "./output-redaction.mjs";
|
|
8
|
+
|
|
9
|
+
/** Refuses ambiguous ownership and manifest changes without a dependency design. */
|
|
10
|
+
export function validatePaths(brief) {
|
|
11
|
+
for (const [, value] of brief.matchAll(/^Paths:[ \t]*(.+)$/gm)) {
|
|
12
|
+
if (/^none\.(?:\s|$)/i.test(value)) continue;
|
|
13
|
+
const leftover = value.replace(/`[^`]+`/g, "").replace(/\band\b|,/g, "").trim();
|
|
14
|
+
if (leftover) throw Object.assign(new Error(`Paths: name each path in backticks; unparsed text: "${leftover}"`), { refusal: "brief:paths" });
|
|
15
|
+
for (const [, file] of value.matchAll(/`([^`]+)`/g)) {
|
|
16
|
+
if (/(?:^|[\\/])(?:package\.json|pyproject\.toml|Cargo\.toml|go\.mod|[^\\/]+\.csproj)$/.test(file) && !/^## Design[ \t]*\r?$/m.test(brief)) {
|
|
17
|
+
throw Object.assign(new Error(`## Design is required when Paths: names ${file}; list each added dependency there`), { refusal: "brief:design" });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Adds branch review history and the previous code report's runner proof to a review prompt. */
|
|
24
|
+
export function reviewContext(brief, settings, branch) {
|
|
25
|
+
if (!settings.review) return "";
|
|
26
|
+
const ledger = ledgerFileOf(settings.worktree);
|
|
27
|
+
const reviews = (ledger ? readLedger(ledger) : []).filter((record) => record.type === "verdict"
|
|
28
|
+
&& ["codex", "branch"].includes(record.kind) && record.branch === branch && typeof record.sha === "string");
|
|
29
|
+
const last = reviews.at(-1)?.sha;
|
|
30
|
+
const explicit = /^Reviewed:[ \t]*(.*?)\s*$/m.exec(brief);
|
|
31
|
+
const requested = explicit?.[1].replace(/^`(.*)`$/, "$1");
|
|
32
|
+
if (explicit && !/^[0-9a-f]{7,40}$/.test(requested)) {
|
|
33
|
+
throw new Error("Reviewed: use a 7 to 40 character lowercase hexadecimal SHA");
|
|
34
|
+
}
|
|
35
|
+
const sha = explicit ? reviews.findLast((record) => shaMatches(record.sha, requested))?.sha : last;
|
|
36
|
+
if (explicit && !sha) throw new Error(`Reviewed: ${requested} is not a reviewed head of ${branch}; the last one is ${last ?? "none"}`);
|
|
37
|
+
let context = sha ? `\n\nReviewed: ${sha}\nReview git diff ${sha}..HEAD.` : "";
|
|
38
|
+
const proof = /^Proof:[ \t]*(.+)$/m.exec(brief)?.[1].trim().replace(/^`(.*)`$/, "$1");
|
|
39
|
+
if (proof) {
|
|
40
|
+
const report = readFileSync(path.resolve(path.dirname(settings.brief), proof), "utf8");
|
|
41
|
+
const block = [...report.matchAll(/^## Runner proof[ \t]*\r?\n[\s\S]*?(?=^## |$(?![\s\S]))/gm)].at(-1)?.[0];
|
|
42
|
+
if (block) context += `\n\n${block.trimEnd()}\nThe runner ran these commands. Do not run them again.`;
|
|
43
|
+
}
|
|
44
|
+
return context;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Reads ordered shell commands without silently dropping an unquoted command. */
|
|
48
|
+
export function commandsOf(brief, label) {
|
|
49
|
+
return [...brief.matchAll(new RegExp(`^${label}:[ \t]*(.*)$`, "gm"))].flatMap(([, value]) => {
|
|
50
|
+
if (value.trim() === "none") return [];
|
|
51
|
+
const commands = [...value.matchAll(/`([^`]+)`/g)].map((match) => match[1]);
|
|
52
|
+
const leftover = value.replace(/`[^`]+`/g, "").replace(/\band\b|,/g, "").trim();
|
|
53
|
+
if (!commands.length || commands.some((command) => !command.trim()) || leftover) throw Object.assign(new Error(`${label}: name each command in backticks`), { refusal: `brief:${label.toLowerCase()}` });
|
|
54
|
+
return commands;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Captures runner-owned commands and their proof destination before the child can edit the brief. */
|
|
59
|
+
export function verificationPolicy(brief, settings) {
|
|
60
|
+
const verify = commandsOf(brief, "Verify");
|
|
61
|
+
const live = commandsOf(brief, "Live");
|
|
62
|
+
const named = /^Report:[ \t]*(.+)$/m.exec(brief)?.[1].trim().replace(/^`(.*)`$/, "$1");
|
|
63
|
+
const report = named ? path.resolve(path.dirname(settings.brief), named) : `${settings.progress}.report.md`;
|
|
64
|
+
return { verify, live, report };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Runs through the platform shell, retaining a bounded output tail and enforcing a deadline. */
|
|
68
|
+
export function runShell(command, { cwd, env = process.env, timeout = 15 * 60 * 1000 }) {
|
|
69
|
+
return new Promise((resolve) => {
|
|
70
|
+
const started = Date.now();
|
|
71
|
+
const lines = [];
|
|
72
|
+
let nextLine = 0;
|
|
73
|
+
let timedOut = false;
|
|
74
|
+
let timer;
|
|
75
|
+
const emitLine = (line, order = nextLine++) => {
|
|
76
|
+
const text = line.trim() ? redactOutput(line.replace(/\r$/, "")) : "";
|
|
77
|
+
lines.push({ text, order });
|
|
78
|
+
lines.sort((a, b) => a.order - b.order);
|
|
79
|
+
let blanks = 0;
|
|
80
|
+
for (let index = 0; index < lines.length; index++) {
|
|
81
|
+
blanks = lines[index].text ? 0 : blanks + 1;
|
|
82
|
+
if (blanks > 10) lines.splice(index--, 1);
|
|
83
|
+
}
|
|
84
|
+
if (lines.length > 200) lines.shift();
|
|
85
|
+
};
|
|
86
|
+
const recorder = () => {
|
|
87
|
+
let group = null;
|
|
88
|
+
let blankOrders = [];
|
|
89
|
+
const heldEntries = () => [
|
|
90
|
+
...(group ? [group] : []),
|
|
91
|
+
...blankOrders.map((order) => ({ text: "", order })),
|
|
92
|
+
];
|
|
93
|
+
const emit = (line) => {
|
|
94
|
+
const entry = { text: line.replace(/\r$/, ""), order: nextLine++ };
|
|
95
|
+
if (!entry.text.trim()) {
|
|
96
|
+
blankOrders.push(entry.order);
|
|
97
|
+
if (blankOrders.length > 10) blankOrders.shift();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const entries = heldEntries();
|
|
101
|
+
const redacted = redactOutput([...entries.map(({ text }) => text), entry.text].join("\n")).split("\n");
|
|
102
|
+
for (let index = 0; index < redacted.length - 1; index++) emitLine(redacted[index], entries[index].order);
|
|
103
|
+
// Keep completion order when a held line is emitted after another stream's lines.
|
|
104
|
+
group = { text: redacted.at(-1), order: entry.order };
|
|
105
|
+
blankOrders = [];
|
|
106
|
+
};
|
|
107
|
+
let buffer = "";
|
|
108
|
+
let end = "";
|
|
109
|
+
let dropping = false;
|
|
110
|
+
let prefix = "";
|
|
111
|
+
const consume = (value, discard = false) => {
|
|
112
|
+
const length = value.length;
|
|
113
|
+
const inSpan = Boolean(end);
|
|
114
|
+
let lastMarker = 0;
|
|
115
|
+
if (discard && prefix) emit(prefix);
|
|
116
|
+
let output = discard ? "" : prefix;
|
|
117
|
+
prefix = "";
|
|
118
|
+
while (value || end) {
|
|
119
|
+
if (end) {
|
|
120
|
+
const index = value.indexOf(end);
|
|
121
|
+
if (index < 0) {
|
|
122
|
+
if (!discard) prefix = output;
|
|
123
|
+
return lastMarker;
|
|
124
|
+
}
|
|
125
|
+
value = value.slice(index + end.length);
|
|
126
|
+
lastMarker = length - value.length;
|
|
127
|
+
end = "";
|
|
128
|
+
} else {
|
|
129
|
+
const begin = /-----BEGIN ([A-Z ]*PRIVATE KEY)-----/.exec(value);
|
|
130
|
+
if (!begin) {
|
|
131
|
+
if (!discard) output += value;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
if (discard) emit("[REDACTED]");
|
|
135
|
+
else output += value.slice(0, begin.index) + "[REDACTED]";
|
|
136
|
+
// Match the BEGIN label, as in output-redaction.mjs:7.
|
|
137
|
+
end = `-----END ${begin[1]}-----`;
|
|
138
|
+
value = value.slice(begin.index + begin[0].length);
|
|
139
|
+
lastMarker = length - value.length;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (!discard && (output || !inSpan)) emit(output);
|
|
143
|
+
return lastMarker;
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
record(chunk) {
|
|
147
|
+
buffer += chunk;
|
|
148
|
+
let newline;
|
|
149
|
+
while ((newline = buffer.indexOf("\n")) >= 0) {
|
|
150
|
+
const line = buffer.slice(0, newline);
|
|
151
|
+
consume(line, dropping || newline >= 64 * 1024);
|
|
152
|
+
buffer = buffer.slice(newline + 1);
|
|
153
|
+
dropping = false;
|
|
154
|
+
}
|
|
155
|
+
if (buffer.length > 64 * 1024 || dropping) {
|
|
156
|
+
// Retain enough overlap to recognize a BEGIN or matching END split across chunks.
|
|
157
|
+
const lastMarker = consume(buffer, true);
|
|
158
|
+
// Never scan a complete marker twice when it falls inside the overlap.
|
|
159
|
+
buffer = buffer.slice(Math.max(lastMarker, buffer.length - 100));
|
|
160
|
+
dropping = true;
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
flush() {
|
|
164
|
+
if (buffer) consume(buffer, dropping);
|
|
165
|
+
if (prefix) emit(prefix);
|
|
166
|
+
const entries = heldEntries();
|
|
167
|
+
const redacted = redactOutput(entries.map(({ text }) => text).join("\n")).split("\n");
|
|
168
|
+
for (let index = 0; index < entries.length && index < redacted.length; index++) emitLine(redacted[index], entries[index].order);
|
|
169
|
+
group = null;
|
|
170
|
+
blankOrders = [];
|
|
171
|
+
buffer = "";
|
|
172
|
+
prefix = "";
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
const stdout = recorder();
|
|
177
|
+
const stderr = recorder();
|
|
178
|
+
const child = spawn(command, [], { cwd, env, shell: true, detached: process.platform !== "win32", windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
179
|
+
child.stdout.setEncoding("utf8").on("data", stdout.record);
|
|
180
|
+
child.stderr.setEncoding("utf8").on("data", stderr.record);
|
|
181
|
+
child.on("error", (error) => stderr.record(error.message));
|
|
182
|
+
timer = setTimeout(() => {
|
|
183
|
+
timedOut = true;
|
|
184
|
+
if (process.platform === "win32") {
|
|
185
|
+
spawnSync("taskkill", ["/pid", String(child.pid), "/T", "/F"], { windowsHide: true, timeout: 5000, stdio: "ignore" });
|
|
186
|
+
} else {
|
|
187
|
+
try { process.kill(-child.pid, "SIGKILL"); } catch { child.kill("SIGKILL"); }
|
|
188
|
+
}
|
|
189
|
+
}, timeout);
|
|
190
|
+
child.on("close", (status) => {
|
|
191
|
+
clearTimeout(timer);
|
|
192
|
+
stdout.flush();
|
|
193
|
+
stderr.flush();
|
|
194
|
+
if (timedOut) emitLine("command timed out");
|
|
195
|
+
while (lines.length && !lines.at(-1).text.trim()) lines.pop();
|
|
196
|
+
resolve({ status: timedOut ? 124 : status ?? 1, seconds: (Date.now() - started) / 1000, tail: lines.slice(-10).map(({ text }) => text).join("\n").trimEnd() });
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** A marker is accepted only after Verify and Live succeed and their proof has been saved. */
|
|
202
|
+
export async function verifyBrief(settings, { env = process.env, policy, outcome = {} } = {}) {
|
|
203
|
+
outcome.verify = null;
|
|
204
|
+
outcome.live = null;
|
|
205
|
+
if (settings.review) return true;
|
|
206
|
+
const { verify, live, report } = policy ?? verificationPolicy(readFileSync(settings.brief, "utf8"), settings);
|
|
207
|
+
if (!verify.length && !live.length) return true;
|
|
208
|
+
mkdirSync(path.dirname(report), { recursive: true });
|
|
209
|
+
appendFileSync(report, "\n## Runner proof\n");
|
|
210
|
+
for (const [commands, isolated, group] of [[verify, false, "verify"], [live, true, "live"]]) {
|
|
211
|
+
let passed = 0;
|
|
212
|
+
for (const command of commands) {
|
|
213
|
+
let folder;
|
|
214
|
+
let result;
|
|
215
|
+
try {
|
|
216
|
+
folder = isolated ? mkdtempSync(path.join(os.tmpdir(), "qc-codex-live-")) : undefined;
|
|
217
|
+
result = await runShell(command, { cwd: folder ?? settings.worktree, env: isolated ? { ...env, QC_WORKTREE: settings.worktree } : env });
|
|
218
|
+
} catch (error) {
|
|
219
|
+
result = { status: 1, seconds: 0, tail: error.message };
|
|
220
|
+
} finally {
|
|
221
|
+
if (folder) rmSync(folder, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
222
|
+
}
|
|
223
|
+
if (result.status !== 0) outcome[group] = "fail";
|
|
224
|
+
else if (++passed === commands.length) outcome[group] = "pass";
|
|
225
|
+
appendFileSync(report, `${redactOutput(command)}: exit ${result.status} in ${result.seconds} s\n${result.status !== 0 && result.tail ? redactOutput(result.tail) + "\n" : ""}`);
|
|
226
|
+
if (result.status !== 0) return false;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import { generateKeyPairSync } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import { commandsOf, runShell, validatePaths, verifyBrief } from "./codex-verify.mjs";
|
|
8
|
+
|
|
9
|
+
const pem = (edge, label) => ["-----", edge, " ", label, " PRIVATE", " KEY-----"].join("");
|
|
10
|
+
|
|
11
|
+
function fixture(t) {
|
|
12
|
+
const dir = mkdtempSync(path.join(os.tmpdir(), "qc-verify-"));
|
|
13
|
+
t.after(() => rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
|
|
14
|
+
return { worktree: dir, brief: path.join(dir, "brief.md"), progress: path.join(dir, "progress.md") };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test("Paths accepts quoted ownership, a manifest design, and the read-only review form", () => {
|
|
18
|
+
for (const brief of ['Paths: `src/a.mjs`, and `src/b.mjs`', 'Paths: `package.json`\n## Design\nDependencies: none', 'Paths: none. Read-only review.']) {
|
|
19
|
+
assert.doesNotThrow(() => validatePaths(brief));
|
|
20
|
+
}
|
|
21
|
+
for (const value of ['src/a.mjs', '`src/a.mjs` prose', '`src/a.mjs` andmore', '``']) {
|
|
22
|
+
assert.throws(() => validatePaths(`Paths: ${value}`), /unparsed text/);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("Verify and Live commands preserve shell syntax and reject unquoted commands", () => {
|
|
27
|
+
assert.deepEqual(commandsOf('Verify: `echo one && echo two`, and `echo three`\nVerify: `echo four`', "Verify"), ['echo one && echo two', 'echo three', 'echo four']);
|
|
28
|
+
assert.deepEqual(commandsOf('Paths: `src`', "Live"), []);
|
|
29
|
+
for (const label of ["Verify", "Live"]) {
|
|
30
|
+
assert.deepEqual(commandsOf(`${label}: none\n`, label), []);
|
|
31
|
+
for (const value of ["", "none prose", "node check.mjs", "``"]) {
|
|
32
|
+
assert.throws(() => commandsOf(`${label}: ${value}\n`, label), new RegExp(`${label}: name each command in backticks`));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const value of ['node check.mjs', '`echo ok`, node check.mjs', '']) {
|
|
36
|
+
assert.throws(() => commandsOf(`Verify: ${value}`, "Verify"), /Verify:.*backticks/);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("shell verification supports operators, worktree cwd, output tails and nonzero exits", async (t) => {
|
|
41
|
+
const f = fixture(t);
|
|
42
|
+
const result = await runShell('echo first && node -e "console.log(process.cwd()); console.error(\'last\'); process.exit(6)"', { cwd: f.worktree });
|
|
43
|
+
assert.equal(result.status, 6);
|
|
44
|
+
assert.ok(result.tail.includes(f.worktree));
|
|
45
|
+
assert.match(result.tail, /last/);
|
|
46
|
+
assert.ok(result.seconds >= 0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("shell proof preserves each held blank line's order across streams", async (t) => {
|
|
50
|
+
const f = fixture(t);
|
|
51
|
+
writeFileSync(path.join(f.worktree, "print-order.cjs"), `
|
|
52
|
+
const wait = () => new Promise((resolve) => setTimeout(resolve, 100));
|
|
53
|
+
(async () => {
|
|
54
|
+
process.stdout.write("first\\n\\n");
|
|
55
|
+
await wait();
|
|
56
|
+
process.stderr.write("middle\\n");
|
|
57
|
+
await wait();
|
|
58
|
+
process.stdout.write("\\nend\\n");
|
|
59
|
+
})();
|
|
60
|
+
`);
|
|
61
|
+
const result = await runShell("node print-order.cjs", { cwd: f.worktree });
|
|
62
|
+
assert.equal(result.status, 0);
|
|
63
|
+
assert.equal(result.tail, "first\n\nmiddle\n\nend");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("shell proof keeps the latest ten held blank orders across streams", async (t) => {
|
|
67
|
+
const f = fixture(t);
|
|
68
|
+
writeFileSync(path.join(f.worktree, "print-order.cjs"), `
|
|
69
|
+
const wait = () => new Promise((resolve) => setTimeout(resolve, 100));
|
|
70
|
+
(async () => {
|
|
71
|
+
process.stdout.write("first\\n" + "\\n".repeat(10));
|
|
72
|
+
await wait();
|
|
73
|
+
process.stderr.write("middle\\n");
|
|
74
|
+
await wait();
|
|
75
|
+
process.stdout.write("\\nend\\n");
|
|
76
|
+
})();
|
|
77
|
+
`);
|
|
78
|
+
const result = await runShell("node print-order.cjs", { cwd: f.worktree });
|
|
79
|
+
assert.equal(result.status, 0);
|
|
80
|
+
assert.match(result.tail, /middle\n\nend$/);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("a timed out shell command fails and terminates its process tree", async (t) => {
|
|
84
|
+
const f = fixture(t);
|
|
85
|
+
writeFileSync(path.join(f.worktree, "descendant.cjs"), 'require("node:fs").writeFileSync("descendant.pid", String(process.pid)); setInterval(() => {}, 1000);');
|
|
86
|
+
writeFileSync(path.join(f.worktree, "parent.cjs"), 'require("node:child_process").spawn(process.execPath, ["descendant.cjs"], { stdio: "inherit" }); setInterval(() => {}, 1000);');
|
|
87
|
+
const pidFile = path.join(f.worktree, "descendant.pid");
|
|
88
|
+
t.after(() => {
|
|
89
|
+
if (existsSync(pidFile)) {
|
|
90
|
+
try { process.kill(Number(readFileSync(pidFile, "utf8")), "SIGKILL"); } catch (error) { if (error.code !== "ESRCH") throw error; }
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const start = Date.now();
|
|
94
|
+
const result = await runShell("node parent.cjs", { cwd: f.worktree, timeout: 1500 });
|
|
95
|
+
assert.equal(result.status, 124);
|
|
96
|
+
assert.match(result.tail, /timed out/);
|
|
97
|
+
assert.ok(Date.now() - start < 10000);
|
|
98
|
+
assert.equal(existsSync(pidFile), true, "the descendant must start before the timeout");
|
|
99
|
+
const pid = Number(readFileSync(pidFile, "utf8"));
|
|
100
|
+
const reapDeadline = Date.now() + 3000;
|
|
101
|
+
while (Date.now() < reapDeadline) {
|
|
102
|
+
try { process.kill(pid, 0); } catch (error) {
|
|
103
|
+
if (error.code === "ESRCH") break;
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(50, Math.max(0, reapDeadline - Date.now()))));
|
|
107
|
+
}
|
|
108
|
+
assert.throws(() => process.kill(pid, 0), { code: "ESRCH" }, "the descendant must be gone after timeout");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("review roles skip Verify and Live and a brief with neither needs no report", async (t) => {
|
|
112
|
+
const f = fixture(t);
|
|
113
|
+
writeFileSync(f.brief, 'Verify: `node -e "process.exit(9)"`\nLive: `node -e "process.exit(9)"`');
|
|
114
|
+
assert.equal(await verifyBrief({ ...f, review: true }), true);
|
|
115
|
+
writeFileSync(f.brief, "Paths: `src`\n");
|
|
116
|
+
assert.equal(await verifyBrief(f), true);
|
|
117
|
+
assert.equal(existsSync(`${f.progress}.report.md`), false);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("Live failures keep proof, stop later commands and clean their temporary directory", async (t) => {
|
|
121
|
+
const f = fixture(t);
|
|
122
|
+
writeFileSync(f.brief, 'Live: `node -e "console.log(process.cwd()); process.exit(8)"`, `node -e "process.exit(9)"`\n');
|
|
123
|
+
assert.equal(await verifyBrief(f), false);
|
|
124
|
+
const proof = readFileSync(`${f.progress}.report.md`, "utf8");
|
|
125
|
+
assert.match(proof, /exit 8 in [\d.]+ s/);
|
|
126
|
+
assert.doesNotMatch(proof, /exit 9 in/);
|
|
127
|
+
const folder = proof.trimEnd().split(/\r?\n/).at(-1);
|
|
128
|
+
assert.equal(existsSync(folder), false);
|
|
129
|
+
assert.ok(path.basename(folder).startsWith("qc-codex-live-"));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("Verify failures redact secrets in both the command and its output proof", async (t) => {
|
|
133
|
+
const f = fixture(t);
|
|
134
|
+
const token = ["ghp", "_", "a".repeat(36)].join("");
|
|
135
|
+
const command = `node -e "console.log('${token}'); process.exit(7)"`;
|
|
136
|
+
writeFileSync(f.brief, `Verify: \`${command}\`\n`);
|
|
137
|
+
assert.equal(await verifyBrief(f), false);
|
|
138
|
+
const proof = readFileSync(`${f.progress}.report.md`, "utf8");
|
|
139
|
+
assert.ok(!proof.includes(token));
|
|
140
|
+
assert.match(proof, /node -e "console\.log\('\[REDACTED\]'\); process\.exit\(7\)": exit 7 in [\d.]+ s\n\[REDACTED\]\n$/);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("Verify failures redact private keys whose BEGIN header falls outside the proof tail", async (t) => {
|
|
144
|
+
const { privateKey } = generateKeyPairSync("rsa", {
|
|
145
|
+
modulusLength: 2048,
|
|
146
|
+
privateKeyEncoding: { type: "pkcs1", format: "pem" },
|
|
147
|
+
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
148
|
+
});
|
|
149
|
+
const keyLines = privateKey.trimEnd().split(/\r?\n/);
|
|
150
|
+
assert.ok(keyLines.length > 10);
|
|
151
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
152
|
+
const f = fixture(t);
|
|
153
|
+
writeFileSync(path.join(f.worktree, "key.pem"), privateKey.trimEnd());
|
|
154
|
+
writeFileSync(path.join(f.worktree, "print-key.cjs"), `
|
|
155
|
+
const lines = require("node:fs").readFileSync("key.pem", "utf8").split("\\n");
|
|
156
|
+
process.${stream}.write(lines.shift() + "\\n");
|
|
157
|
+
setImmediate(() => {
|
|
158
|
+
process.${stream}.write(lines.join("\\n"));
|
|
159
|
+
process.exitCode = 7;
|
|
160
|
+
});
|
|
161
|
+
`);
|
|
162
|
+
writeFileSync(f.brief, 'Verify: `node print-key.cjs`\n');
|
|
163
|
+
assert.equal(await verifyBrief(f), false);
|
|
164
|
+
const proof = readFileSync(`${f.progress}.report.md`, "utf8");
|
|
165
|
+
for (const line of keyLines) assert.ok(!proof.includes(line), "private key line must not reach the report");
|
|
166
|
+
assert.match(proof, /exit 7 in [\d.]+ s\n\[REDACTED\]\n$/);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("shell proof redacts a private key after 65,536 characters on one line", async (t) => {
|
|
171
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
172
|
+
const f = fixture(t);
|
|
173
|
+
const output = "x".repeat(65536) + `${pem("BEGIN", "RSA")}\nlong-line-key-secret\n${pem("END", "RSA")}\n`;
|
|
174
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `process.${stream}.write(${JSON.stringify(output)});`);
|
|
175
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
176
|
+
assert.equal(result.status, 0);
|
|
177
|
+
assert.ok(result.tail.length > 0, "the key span must leave a redaction marker");
|
|
178
|
+
assert.doesNotMatch(result.tail, /long-line-key-secret|-----BEGIN|-----END/);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("shell proof redacts a token before stdout and stderr are merged", async (t) => {
|
|
183
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
184
|
+
const f = fixture(t);
|
|
185
|
+
const other = stream === "stdout" ? "stderr" : "stdout";
|
|
186
|
+
const token = ["ghp", "_", "a".repeat(200)].join("");
|
|
187
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `
|
|
188
|
+
(async () => {
|
|
189
|
+
const write = (stream, text) => new Promise((resolve) => stream.write(text, resolve));
|
|
190
|
+
const pause = () => new Promise((resolve) => setTimeout(resolve, 50));
|
|
191
|
+
await write(process.${stream}, ${JSON.stringify(token.slice(0, 140))});
|
|
192
|
+
await pause();
|
|
193
|
+
await write(process.${other}, "other-stream\\n".repeat(20));
|
|
194
|
+
await pause();
|
|
195
|
+
await write(process.${stream}, ${JSON.stringify(token.slice(140) + "\n")});
|
|
196
|
+
})();
|
|
197
|
+
`);
|
|
198
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
199
|
+
assert.equal(result.status, 0);
|
|
200
|
+
assert.equal(result.tail, [...Array(9).fill("other-stream"), "[REDACTED]"].join("\n"));
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("shell proof keeps AWS label context across blank lines on each stream", async (t) => {
|
|
205
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
206
|
+
const f = fixture(t);
|
|
207
|
+
const output = "aws_secret_access_key=" + "\n".repeat(13) + "A".repeat(40);
|
|
208
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `process.${stream}.write(${JSON.stringify(output)});`);
|
|
209
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
210
|
+
assert.equal(result.status, 0);
|
|
211
|
+
assert.doesNotMatch(result.tail, /AAAA/);
|
|
212
|
+
assert.match(result.tail, /\[REDACTED\]/);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("shell proof caps whitespace-only runs before the end sentinel", async (t) => {
|
|
217
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
218
|
+
const f = fixture(t);
|
|
219
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `
|
|
220
|
+
process.${stream}.write((" ".repeat(1024) + "\\n").repeat(20000) + "end-sentinel");
|
|
221
|
+
`);
|
|
222
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
223
|
+
assert.equal(result.status, 0);
|
|
224
|
+
assert.equal(result.tail, "\n".repeat(9) + "end-sentinel");
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("shell proof skips trailing blank lines before taking the tail", async (t) => {
|
|
229
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
230
|
+
const f = fixture(t);
|
|
231
|
+
const output = "failure-sentinel" + "\n".repeat(202);
|
|
232
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `process.${stream}.write(${JSON.stringify(output)});`);
|
|
233
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
234
|
+
assert.equal(result.status, 0);
|
|
235
|
+
assert.equal(result.tail, "failure-sentinel");
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("shell proof discards the rest of a 70000-character cut line", async (t) => {
|
|
240
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
241
|
+
const f = fixture(t);
|
|
242
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `
|
|
243
|
+
process.${stream}.write("x".repeat(70000), () => {
|
|
244
|
+
setTimeout(() => process.${stream}.write("cut-line-remainder\\nretained-sentinel\\n"), 50);
|
|
245
|
+
});
|
|
246
|
+
`);
|
|
247
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
248
|
+
assert.equal(result.status, 0);
|
|
249
|
+
assert.equal(result.tail, "retained-sentinel");
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test("shell proof keeps one, two, three in line completion order", async (t) => {
|
|
254
|
+
const f = fixture(t);
|
|
255
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `
|
|
256
|
+
process.stdout.write("one\\n", () => {
|
|
257
|
+
setTimeout(() => process.stderr.write("two\\n", () => {
|
|
258
|
+
setTimeout(() => process.stdout.write("three\\n"), 50);
|
|
259
|
+
}), 50);
|
|
260
|
+
});
|
|
261
|
+
`);
|
|
262
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
263
|
+
assert.equal(result.status, 0);
|
|
264
|
+
assert.equal(result.tail, "one\ntwo\nthree");
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test("shell proof keeps one key marker when a dropped line overlaps a key boundary", async (t) => {
|
|
268
|
+
const begin = pem("BEGIN", "RSA");
|
|
269
|
+
const end = pem("END", "RSA");
|
|
270
|
+
for (const chunks of [
|
|
271
|
+
["x".repeat(70000) + begin + "secret" + end, "\nsafe\n"],
|
|
272
|
+
[begin + "\n", "secret".repeat(14000), "\n" + end + "\nsafe\n"],
|
|
273
|
+
["x".repeat(70000) + begin.slice(0, 12), begin.slice(12) + "\nsecret\n" + end + "\nsafe\n"],
|
|
274
|
+
]) {
|
|
275
|
+
const f = fixture(t);
|
|
276
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `
|
|
277
|
+
(async () => {
|
|
278
|
+
for (const chunk of ${JSON.stringify(chunks)}) {
|
|
279
|
+
await new Promise((resolve) => process.stdout.write(chunk, resolve));
|
|
280
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
281
|
+
}
|
|
282
|
+
})();
|
|
283
|
+
`);
|
|
284
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
285
|
+
assert.equal(result.status, 0);
|
|
286
|
+
assert.equal(result.tail, "[REDACTED]\nsafe");
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test("shell proof keeps redacting until the private key END label matches", async (t) => {
|
|
291
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
292
|
+
const f = fixture(t);
|
|
293
|
+
const output = `${pem("BEGIN", "RSA")}\n${pem("END", "EC")}\nsecret-after-wrong-end\n${pem("END", "RSA")}\nsafe-after-key\n`;
|
|
294
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `process.${stream}.write(${JSON.stringify(output)});`);
|
|
295
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
296
|
+
assert.equal(result.status, 0);
|
|
297
|
+
assert.equal(result.tail, "[REDACTED]\nsafe-after-key");
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test("shell proof retains a sentinel after 65,536 characters and drops the cut line", async (t) => {
|
|
302
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
303
|
+
const f = fixture(t);
|
|
304
|
+
const output = "x".repeat(65536) + "\nretained-sentinel\n";
|
|
305
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `process.${stream}.write(${JSON.stringify(output)});`);
|
|
306
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
307
|
+
assert.equal(result.status, 0);
|
|
308
|
+
assert.ok(result.tail.length < 65536, "the proof must stay bounded after dropping the partial line");
|
|
309
|
+
assert.equal(result.tail, "retained-sentinel");
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test("shell proof preserves text around a private key across stream chunks", async (t) => {
|
|
314
|
+
for (const stream of ["stdout", "stderr"]) {
|
|
315
|
+
const f = fixture(t);
|
|
316
|
+
const chunks = [`before ${pem("BEGIN", "RSA").slice(0, 7)}`, `${pem("BEGIN", "RSA").slice(7)}\nsecret`, `\n${pem("END", "RSA").slice(0, 17)}`, `${pem("END", "RSA").slice(17)} after\n`];
|
|
317
|
+
writeFileSync(path.join(f.worktree, "print-output.cjs"), `
|
|
318
|
+
(async () => {
|
|
319
|
+
for (const chunk of ${JSON.stringify(chunks)}) {
|
|
320
|
+
await new Promise((resolve) => process.${stream}.write(chunk, resolve));
|
|
321
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
322
|
+
}
|
|
323
|
+
})();
|
|
324
|
+
`);
|
|
325
|
+
const result = await runShell("node print-output.cjs", { cwd: f.worktree });
|
|
326
|
+
assert.equal(result.status, 0);
|
|
327
|
+
assert.equal(result.tail, "before [REDACTED] after");
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("proof-write failures prevent acceptance of an otherwise successful command", async (t) => {
|
|
332
|
+
const f = fixture(t);
|
|
333
|
+
writeFileSync(f.brief, 'Report: .\nVerify: `echo ok`\n');
|
|
334
|
+
await assert.rejects(verifyBrief(f), /EISDIR|EPERM|EACCES/);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("verification preflight accepts none and rejects commandless lines before launch", async (t) => {
|
|
338
|
+
const { spawnSync } = await import("node:child_process");
|
|
339
|
+
const { DONE_MARKER, runCodexImplement } = await import("./codex-implement.mjs");
|
|
340
|
+
for (const label of ["Verify", "Live"]) {
|
|
341
|
+
for (const value of ["none", "", "node check.mjs", "none prose"]) {
|
|
342
|
+
const f = fixture(t);
|
|
343
|
+
f.worktree = path.join(f.worktree, "worktree");
|
|
344
|
+
mkdirSync(f.worktree);
|
|
345
|
+
assert.equal(spawnSync("git", ["init", "-q", f.worktree]).status, 0);
|
|
346
|
+
writeFileSync(f.brief, `# Brief\nPaths: \`src\`\n## Product decisions\nKeep the policy.\n${label}: ${value}\n`);
|
|
347
|
+
let launched = false;
|
|
348
|
+
const messages = [];
|
|
349
|
+
const result = await runCodexImplement(["--brief", f.brief, "--progress", f.progress, "--worktree", f.worktree], {
|
|
350
|
+
say: (line) => messages.push(line), out: () => {}, run: async () => {
|
|
351
|
+
launched = true;
|
|
352
|
+
writeFileSync(f.progress, `${DONE_MARKER}\n`);
|
|
353
|
+
return { status: 0 };
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
assert.equal(result, value === "none" ? 0 : 1);
|
|
357
|
+
assert.equal(launched, value === "none");
|
|
358
|
+
if (value !== "none") assert.ok(messages.some((line) => line.includes(`${label}: name each command in backticks`)));
|
|
359
|
+
assert.equal(existsSync(`${f.progress}.report.md`), false);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test("later sessions cannot replace frozen Verify or Live commands with malformed policy", async (t) => {
|
|
365
|
+
const { spawnSync } = await import("node:child_process");
|
|
366
|
+
const { DONE_MARKER, runCodexImplement } = await import("./codex-implement.mjs");
|
|
367
|
+
const f = fixture(t);
|
|
368
|
+
f.worktree = path.join(f.worktree, "worktree");
|
|
369
|
+
mkdirSync(f.worktree);
|
|
370
|
+
assert.equal(spawnSync("git", ["init", "-q", f.worktree]).status, 0);
|
|
371
|
+
const brief = '# Brief\nPaths: `src`\n## Product decisions\nKeep the policy.\n';
|
|
372
|
+
writeFileSync(f.brief, `${brief}Verify: \`echo original-verify\`\nLive: \`echo original-live\`\n`);
|
|
373
|
+
let launches = 0;
|
|
374
|
+
assert.equal(await runCodexImplement(["--brief", f.brief, "--progress", f.progress, "--worktree", f.worktree, "--max-runs", "2"], {
|
|
375
|
+
say: () => {}, out: () => {}, run: async () => {
|
|
376
|
+
launches += 1;
|
|
377
|
+
writeFileSync(f.brief, `${brief}Verify: unquoted replacement\nLive: unquoted replacement\n`);
|
|
378
|
+
if (launches === 2) writeFileSync(f.progress, `${DONE_MARKER}\n`);
|
|
379
|
+
return { status: 0 };
|
|
380
|
+
},
|
|
381
|
+
}), 0);
|
|
382
|
+
assert.equal(launches, 2);
|
|
383
|
+
const proof = readFileSync(`${f.progress}.report.md`, "utf8");
|
|
384
|
+
assert.match(proof, /echo original-verify: exit 0/);
|
|
385
|
+
assert.match(proof, /echo original-live: exit 0/);
|
|
386
|
+
assert.doesNotMatch(proof, /replacement/);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test("completion still requires the progress marker after verification commands finish", async (t) => {
|
|
390
|
+
const { spawnSync } = await import("node:child_process");
|
|
391
|
+
const { DONE_MARKER, runCodexImplement } = await import("./codex-implement.mjs");
|
|
392
|
+
const f = fixture(t);
|
|
393
|
+
const initialized = spawnSync("git", ["init", "-q", f.worktree], { encoding: "utf8" });
|
|
394
|
+
assert.equal(initialized.status, 0, initialized.stderr);
|
|
395
|
+
writeFileSync(f.progress, `${DONE_MARKER}\n`);
|
|
396
|
+
writeFileSync(f.brief, '# Brief\nPaths: `src`\n## Product decisions\nKeep the marker.\nVerify: `node -e "require(\'node:fs\').unlinkSync(\'progress.md\')"`\n');
|
|
397
|
+
const lines = [];
|
|
398
|
+
assert.equal(await runCodexImplement(["--brief", f.brief, "--progress", f.progress, "--worktree", f.worktree], {
|
|
399
|
+
say: () => {}, out: (line) => lines.push(line), run: async () => assert.fail("marker exists at startup"),
|
|
400
|
+
}), 3);
|
|
401
|
+
assert.deepEqual(lines, ["exit 3"]);
|
|
402
|
+
});
|