@gtrabanco/agentic-workflow 0.1.0 → 0.1.1
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/bin/{agwo.mjs → agentic-workflow.mjs} +7 -7
- package/package.json +14 -5
- package/src/edit/schema.mjs +1 -1
- package/test/edit.test.mjs +0 -358
- package/test/fixtures.mjs +0 -326
- package/test/path-guard.engine.test.mjs +0 -304
- package/test/turn-contract.engine.test.mjs +0 -103
- package/test/turn-contract.parity.test.mjs +0 -20
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* agentic-workflow — CLI router for agentic-workflow typed file services.
|
|
4
4
|
*
|
|
5
5
|
* Usage:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* agentic-workflow unit-doc <NN-slug> [--dir <root>] <op> [args...]
|
|
7
|
+
* agentic-workflow roadmap <op> [args...]
|
|
8
|
+
* agentic-workflow changelog <op> [args...]
|
|
9
|
+
* agentic-workflow budgets <op> [args...]
|
|
10
|
+
* agentic-workflow manifest <op> [args...]
|
|
11
11
|
*
|
|
12
12
|
* --json prints the operation receipt as JSON.
|
|
13
13
|
* Every operation prints a fixed receipt block to stdout.
|
|
@@ -63,7 +63,7 @@ function refuse(reason) {
|
|
|
63
63
|
|
|
64
64
|
const command = process.argv[2];
|
|
65
65
|
if (!command) {
|
|
66
|
-
console.error("usage:
|
|
66
|
+
console.error("usage: agentic-workflow <unit-doc|roadmap|changelog|budgets|manifest> ...");
|
|
67
67
|
process.exit(1);
|
|
68
68
|
}
|
|
69
69
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtrabanco/agentic-workflow",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Deterministic runner for the agentic-workflow lane: file services (agwo edit), sensors, guards and receipts. No dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Gabriel Trabanco <1969593+gtrabanco@users.noreply.github.com>",
|
|
7
7
|
"repository": {
|
|
@@ -11,10 +11,19 @@
|
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
13
13
|
"bin": {
|
|
14
|
-
"
|
|
14
|
+
"agentic-workflow": "./bin/agentic-workflow.mjs"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=18",
|
|
18
18
|
"bun": ">=1.4"
|
|
19
|
-
}
|
|
20
|
-
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "bun test test/",
|
|
22
|
+
"test:node": "node --test"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"bin",
|
|
26
|
+
"src",
|
|
27
|
+
"README.md"
|
|
28
|
+
]
|
|
29
|
+
}
|
package/src/edit/schema.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* File-schema vocabularies for
|
|
2
|
+
* File-schema vocabularies for agentic-workflow edit typed file services.
|
|
3
3
|
*
|
|
4
4
|
* Canonical definitions: section lists, table columns, operation names,
|
|
5
5
|
* and operation receipts. Consumers in UnitDoc, Roadmap, Changelog,
|
package/test/edit.test.mjs
DELETED
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for agwo edit — typed file services SDK.
|
|
3
|
-
*
|
|
4
|
-
* Uses node:test with temp directories for isolation.
|
|
5
|
-
* Covers: UnitDoc, Roadmap, Changelog, Budgets, Manifest, receipts, CLI smoke.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { describe, it, before, after } from "node:test";
|
|
9
|
-
import { strictEqual, ok, throws } from "node:assert";
|
|
10
|
-
import { mkdtempSync, writeFileSync, readFileSync, rmSync, existsSync, mkdirSync } from "node:fs";
|
|
11
|
-
import { tmpdir } from "node:os";
|
|
12
|
-
import { join } from "node:path";
|
|
13
|
-
import { spawn } from "node:child_process";
|
|
14
|
-
|
|
15
|
-
// ── SDK imports ──────────────────────────────────────────────────────────
|
|
16
|
-
import { create, setSection, evidence_addRow, progress_logEntry, validate } from "../src/edit/UnitDoc.mjs";
|
|
17
|
-
import { rowUpsert, annotate } from "../src/edit/Roadmap.mjs";
|
|
18
|
-
import { rowAdd } from "../src/edit/Changelog.mjs";
|
|
19
|
-
import { ceilingRebase } from "../src/edit/Budgets.mjs";
|
|
20
|
-
import { skillAdd, skillRemove } from "../src/edit/Manifest.mjs";
|
|
21
|
-
|
|
22
|
-
// ── Test fixtures ────────────────────────────────────────────────────────
|
|
23
|
-
|
|
24
|
-
let tmpDir;
|
|
25
|
-
let unitDir;
|
|
26
|
-
let specPath;
|
|
27
|
-
|
|
28
|
-
before(() => {
|
|
29
|
-
tmpDir = mkdtempSync(join(tmpdir(), "agwo-edit-"));
|
|
30
|
-
unitDir = join(tmpDir, "docs", "features", "61-test-slug");
|
|
31
|
-
mkdirSync(unitDir, { recursive: true });
|
|
32
|
-
specPath = join(unitDir, "SPEC.md");
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
after(() => {
|
|
36
|
-
if (tmpDir && existsSync(tmpDir)) {
|
|
37
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// ── UnitDoc tests ────────────────────────────────────────────────────────
|
|
42
|
-
|
|
43
|
-
describe("UnitDoc", () => {
|
|
44
|
-
it("create produces 13 sections in order", () => {
|
|
45
|
-
const receipt = create(unitDir, "61-test-slug");
|
|
46
|
-
strictEqual(receipt.ok, true);
|
|
47
|
-
strictEqual(receipt.service, "unitDoc");
|
|
48
|
-
strictEqual(receipt.op, "create");
|
|
49
|
-
|
|
50
|
-
const content = readFileSync(specPath, "utf8");
|
|
51
|
-
const sections = [
|
|
52
|
-
"Objective", "Why", "User outcome", "Acceptance criteria",
|
|
53
|
-
"Non-goals", "Future cost", "Applicable tests",
|
|
54
|
-
"Known pre-existing issues", "Tasks", "Evidence",
|
|
55
|
-
"Progress log", "Next", "References",
|
|
56
|
-
];
|
|
57
|
-
|
|
58
|
-
// All 13 sections must exist in order
|
|
59
|
-
let lastIdx = -1;
|
|
60
|
-
for (const section of sections) {
|
|
61
|
-
const idx = content.indexOf(`## ${section}`);
|
|
62
|
-
ok(idx !== -1, `Section "${section}" not found`);
|
|
63
|
-
ok(idx > lastIdx, `Section "${section}" out of order`);
|
|
64
|
-
lastIdx = idx;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("setSection refuses an unknown section", () => {
|
|
69
|
-
throws(() => {
|
|
70
|
-
setSection(specPath, "UnknownSection", "body");
|
|
71
|
-
}, /Unknown section/);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("setSection updates an existing section", () => {
|
|
75
|
-
const receipt = setSection(specPath, "Objective", "New objective body");
|
|
76
|
-
strictEqual(receipt.ok, true);
|
|
77
|
-
|
|
78
|
-
const content = readFileSync(specPath, "utf8");
|
|
79
|
-
ok(content.includes("New objective body"));
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("evidence.addRow writes the exact column shape", () => {
|
|
83
|
-
const receipt = evidence_addRow(specPath, {
|
|
84
|
-
ac: "AC-14",
|
|
85
|
-
command: "bun test edit.test.mjs",
|
|
86
|
-
exitDigest: "sha256:abc123",
|
|
87
|
-
output: "2 tests passed",
|
|
88
|
-
verifiedBy: "test-agent",
|
|
89
|
-
});
|
|
90
|
-
strictEqual(receipt.ok, true);
|
|
91
|
-
|
|
92
|
-
const content = readFileSync(specPath, "utf8");
|
|
93
|
-
ok(content.includes("| AC-14"));
|
|
94
|
-
ok(content.includes("| bun test edit.test.mjs"));
|
|
95
|
-
ok(content.includes("| sha256:abc123"));
|
|
96
|
-
ok(content.includes("| 2 tests passed"));
|
|
97
|
-
ok(content.includes("| test-agent |"));
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("progress entry with a bad timestamp is refused", () => {
|
|
101
|
-
throws(() => {
|
|
102
|
-
progress_logEntry(specPath, {
|
|
103
|
-
ts: "not-a-timestamp",
|
|
104
|
-
what: "did something",
|
|
105
|
-
ref: "abc123",
|
|
106
|
-
next: "do more",
|
|
107
|
-
});
|
|
108
|
-
}, /Progress entry does not match/);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("progress entry with valid format succeeds", () => {
|
|
112
|
-
const receipt = progress_logEntry(specPath, {
|
|
113
|
-
ts: "2026-09-22 14:30",
|
|
114
|
-
what: "implemented agwo edit",
|
|
115
|
-
ref: "abc123def",
|
|
116
|
-
next: "write tests",
|
|
117
|
-
});
|
|
118
|
-
strictEqual(receipt.ok, true);
|
|
119
|
-
|
|
120
|
-
const content = readFileSync(specPath, "utf8");
|
|
121
|
-
ok(content.includes("2026-09-22 14:30 — implemented agwo edit → abc123def — next: write tests"));
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("validate returns violations for missing sections", () => {
|
|
125
|
-
const content = "# Test\n\n## Objective\n\nOnly one section";
|
|
126
|
-
const result = validate(content);
|
|
127
|
-
strictEqual(result.ok, false);
|
|
128
|
-
ok(result.violations.length > 0);
|
|
129
|
-
ok(result.violations.some((v) => v.includes("Why")));
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// ── Roadmap tests ────────────────────────────────────────────────────────
|
|
134
|
-
|
|
135
|
-
describe("Roadmap", () => {
|
|
136
|
-
let roadmapPath;
|
|
137
|
-
|
|
138
|
-
before(() => {
|
|
139
|
-
roadmapPath = join(tmpDir, "ROADMAP.md");
|
|
140
|
-
const content = `# Roadmap
|
|
141
|
-
|
|
142
|
-
| NN | slug | status | depends-on | description |
|
|
143
|
-
|---|---|---|---|---|
|
|
144
|
-
`;
|
|
145
|
-
writeFileSync(roadmapPath, content, "utf8");
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("rowUpsert inserts a new row", () => {
|
|
149
|
-
const receipt = rowUpsert(roadmapPath, {
|
|
150
|
-
nn: "61",
|
|
151
|
-
slug: "adaptive-unit-lane",
|
|
152
|
-
status: "active",
|
|
153
|
-
dependsOn: "",
|
|
154
|
-
description: "Adaptive unit lane implementation",
|
|
155
|
-
});
|
|
156
|
-
strictEqual(receipt.ok, true);
|
|
157
|
-
|
|
158
|
-
const updated = readFileSync(roadmapPath, "utf8");
|
|
159
|
-
ok(updated.includes("| 61 | adaptive-unit-lane |"));
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("rowUpsert updates the same NN without duplicating", () => {
|
|
163
|
-
const receipt = rowUpsert(roadmapPath, {
|
|
164
|
-
nn: "61",
|
|
165
|
-
slug: "adaptive-unit-lane-v2",
|
|
166
|
-
status: "completed",
|
|
167
|
-
dependsOn: "",
|
|
168
|
-
description: "Updated description",
|
|
169
|
-
});
|
|
170
|
-
strictEqual(receipt.ok, true);
|
|
171
|
-
|
|
172
|
-
const content = readFileSync(roadmapPath, "utf8");
|
|
173
|
-
const count = content.split("| 61 |").length - 1;
|
|
174
|
-
strictEqual(count, 1);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("annotate appends to the description", () => {
|
|
178
|
-
annotate(roadmapPath, "61", "Added annotation note");
|
|
179
|
-
const content = readFileSync(roadmapPath, "utf8");
|
|
180
|
-
ok(content.includes("— Added annotation note"));
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// ── Changelog tests ──────────────────────────────────────────────────────
|
|
185
|
-
|
|
186
|
-
describe("Changelog", () => {
|
|
187
|
-
it("changelog row lands inside the named section's table", () => {
|
|
188
|
-
const changelogPath = join(tmpDir, "CHANGELOG.md");
|
|
189
|
-
const content = `# Changelog
|
|
190
|
-
|
|
191
|
-
#### \`unit-doc\`
|
|
192
|
-
|
|
193
|
-
| Version | Date | Type | What changed |
|
|
194
|
-
|---|---|---|---|
|
|
195
|
-
|
|
196
|
-
#### \`roadmap\`
|
|
197
|
-
|
|
198
|
-
| Version | Date | Type | What changed |
|
|
199
|
-
|---|---|---|---|
|
|
200
|
-
`;
|
|
201
|
-
writeFileSync(changelogPath, content, "utf8");
|
|
202
|
-
|
|
203
|
-
const receipt = rowAdd(changelogPath, "unit-doc", {
|
|
204
|
-
version: "0.1.0",
|
|
205
|
-
date: "2026-09-22",
|
|
206
|
-
type: "feature",
|
|
207
|
-
what: "Added agwo edit typed file services",
|
|
208
|
-
});
|
|
209
|
-
strictEqual(receipt.ok, true);
|
|
210
|
-
|
|
211
|
-
const updated = readFileSync(changelogPath, "utf8");
|
|
212
|
-
// The row should appear under unit-doc section, not roadmap
|
|
213
|
-
const parts = updated.split("#### `unit-doc`");
|
|
214
|
-
ok(parts.length >= 2);
|
|
215
|
-
const unitDocContent = parts[1];
|
|
216
|
-
const roadmapIdx = unitDocContent.indexOf("#### `roadmap`");
|
|
217
|
-
const unitDocOnly = roadmapIdx === -1 ? unitDocContent : unitDocContent.slice(0, roadmapIdx);
|
|
218
|
-
ok(unitDocOnly.includes("| 0.1.0 | 2026-09-22 | feature | Added agwo edit"));
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
// ── Budgets tests ────────────────────────────────────────────────────────
|
|
223
|
-
|
|
224
|
-
describe("Budgets", () => {
|
|
225
|
-
let budgetPath;
|
|
226
|
-
|
|
227
|
-
before(() => {
|
|
228
|
-
budgetPath = join(tmpDir, "budgets.json");
|
|
229
|
-
const content = JSON.stringify({
|
|
230
|
-
routes: {
|
|
231
|
-
"execute-phase": { estimateMax: 1000, linesMax: 500, sources: {} },
|
|
232
|
-
},
|
|
233
|
-
}, null, 2);
|
|
234
|
-
writeFileSync(budgetPath, content, "utf8");
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it("budgets shrink without growth source is refused", () => {
|
|
238
|
-
const receipt = ceilingRebase(budgetPath, "execute-phase", 500, 250, "");
|
|
239
|
-
strictEqual(receipt.ok, false);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it("budgets shrink WITH growth source succeeds", () => {
|
|
243
|
-
const receipt = ceilingRebase(budgetPath, "execute-phase", 500, 250, "Optimization: reduced scope");
|
|
244
|
-
strictEqual(receipt.ok, true);
|
|
245
|
-
|
|
246
|
-
const content = readFileSync(budgetPath, "utf8");
|
|
247
|
-
const data = JSON.parse(content);
|
|
248
|
-
strictEqual(data.routes["execute-phase"].estimateMax, 500);
|
|
249
|
-
strictEqual(data.routes["execute-phase"].linesMax, 250);
|
|
250
|
-
strictEqual(data.routes["execute-phase"].sources.ceilingRebase, "Optimization: reduced scope");
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// ── Manifest tests ───────────────────────────────────────────────────────
|
|
255
|
-
|
|
256
|
-
describe("Manifest", () => {
|
|
257
|
-
let pluginJsonPath;
|
|
258
|
-
|
|
259
|
-
before(() => {
|
|
260
|
-
pluginJsonPath = join(tmpDir, ".claude-plugin", "plugin.json");
|
|
261
|
-
mkdirSync(join(pluginJsonPath, ".."), { recursive: true });
|
|
262
|
-
const data = { skills: [] };
|
|
263
|
-
writeFileSync(pluginJsonPath, JSON.stringify(data, null, 2), "utf8");
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it("manifest add keeps alphabetical order", () => {
|
|
267
|
-
skillAdd(pluginJsonPath, "zebra-skill", { description: "Z" });
|
|
268
|
-
skillAdd(pluginJsonPath, "alpha-skill", { description: "A" });
|
|
269
|
-
skillAdd(pluginJsonPath, "middle-skill", { description: "M" });
|
|
270
|
-
|
|
271
|
-
const content = readFileSync(pluginJsonPath, "utf8");
|
|
272
|
-
const parsed = JSON.parse(content);
|
|
273
|
-
const names = parsed.skills.map((s) => s.name);
|
|
274
|
-
strictEqual(names.length, 3);
|
|
275
|
-
strictEqual(names[0], "alpha-skill");
|
|
276
|
-
strictEqual(names[1], "middle-skill");
|
|
277
|
-
strictEqual(names[2], "zebra-skill");
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it("manifest add refuses duplicate", () => {
|
|
281
|
-
throws(() => {
|
|
282
|
-
skillAdd(pluginJsonPath, "alpha-skill", { description: "duplicate" });
|
|
283
|
-
}, /already exists/);
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it("manifest remove keeps alphabetical order", () => {
|
|
287
|
-
skillRemove(pluginJsonPath, "middle-skill");
|
|
288
|
-
|
|
289
|
-
const content = readFileSync(pluginJsonPath, "utf8");
|
|
290
|
-
const parsed = JSON.parse(content);
|
|
291
|
-
const names = parsed.skills.map((s) => s.name);
|
|
292
|
-
strictEqual(names.length, 2);
|
|
293
|
-
strictEqual(names[0], "alpha-skill");
|
|
294
|
-
strictEqual(names[1], "zebra-skill");
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
// ── Receipt tests ────────────────────────────────────────────────────────
|
|
299
|
-
|
|
300
|
-
describe("Receipts", () => {
|
|
301
|
-
it("receipts carry matching sha256 digests", () => {
|
|
302
|
-
const receipt = setSection(specPath, "Why", "New reason");
|
|
303
|
-
strictEqual(typeof receipt.before, "string");
|
|
304
|
-
strictEqual(typeof receipt.after, "string");
|
|
305
|
-
strictEqual(receipt.before.length, 8); // sha256 prefix is 8 chars
|
|
306
|
-
strictEqual(receipt.after.length, 8);
|
|
307
|
-
// Content changed so digests differ
|
|
308
|
-
strictNotEqual(receipt.before, receipt.after);
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
// ── CLI smoke test ───────────────────────────────────────────────────────
|
|
313
|
-
|
|
314
|
-
describe("CLI smoke", () => {
|
|
315
|
-
it("spawn bin/agwo.mjs unit-doc create --json parses", (t, done) => {
|
|
316
|
-
const testDir = mkdtempSync(join(tmpdir(), "agwo-cli-"));
|
|
317
|
-
const testUnitDir = join(testDir, "docs", "features", "cli-test");
|
|
318
|
-
mkdirSync(testUnitDir, { recursive: true });
|
|
319
|
-
|
|
320
|
-
const agwoPath = join(process.cwd(), "bin", "agwo.mjs");
|
|
321
|
-
|
|
322
|
-
const proc = spawn("node", [agwoPath, "unit-doc", "cli-test", "create", "--json"], {
|
|
323
|
-
cwd: testDir,
|
|
324
|
-
timeout: 10000,
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
let stdout = "";
|
|
328
|
-
let stderr = "";
|
|
329
|
-
|
|
330
|
-
proc.stdout.on("data", (data) => { stdout += data.toString(); });
|
|
331
|
-
proc.stderr.on("data", (data) => { stderr += data.toString(); });
|
|
332
|
-
|
|
333
|
-
proc.on("close", (code) => {
|
|
334
|
-
try {
|
|
335
|
-
strictEqual(code, 0);
|
|
336
|
-
const parsed = JSON.parse(stdout);
|
|
337
|
-
strictEqual(parsed.ok, true);
|
|
338
|
-
strictEqual(parsed.service, "unitDoc");
|
|
339
|
-
strictEqual(parsed.op, "create");
|
|
340
|
-
// Cleanup
|
|
341
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
342
|
-
done();
|
|
343
|
-
} catch (e) {
|
|
344
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
345
|
-
done(e);
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
proc.on("error", (e) => {
|
|
350
|
-
rmSync(testDir, { recursive: true, force: true });
|
|
351
|
-
done(e);
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
function strictNotEqual(a, b) {
|
|
357
|
-
if (a === b) throw new Error(`Expected ${a} !== ${b}`);
|
|
358
|
-
}
|
package/test/fixtures.mjs
DELETED
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
// Shared throwaway-repo fixture matrix for the turn-contract suites.
|
|
2
|
-
//
|
|
3
|
-
// The engine suite, the two-engine parity suite, and the grammar conformance
|
|
4
|
-
// test all drive the SAME matrix so a per-box outcome and the receipt grammar
|
|
5
|
-
// are asserted once and reused (D-52-9 proportionality, no combinatorial
|
|
6
|
-
// flag x state sweep). Everything lives in one temp directory; `gh` is a
|
|
7
|
-
// PATH-stub because no suite contacts a forge.
|
|
8
|
-
|
|
9
|
-
import { spawnSync } from "node:child_process";
|
|
10
|
-
import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
11
|
-
import os from "node:os";
|
|
12
|
-
import path from "node:path";
|
|
13
|
-
import { fileURLToPath } from "node:url";
|
|
14
|
-
|
|
15
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
-
export const REPO_ROOT = path.resolve(here, "..", "..", "..");
|
|
17
|
-
export const ENGINE = path.join(REPO_ROOT, "packages/agentic-workflow/bin/turn-contract.mjs");
|
|
18
|
-
export const SHIM = path.join(REPO_ROOT, "template/.agentic-workflow/hooks/turn-contract.sh");
|
|
19
|
-
|
|
20
|
-
const GIT_CONFIG = ["-c", "user.email=t@example.com", "-c", "user.name=test", "-c", "commit.gpgsign=false"];
|
|
21
|
-
|
|
22
|
-
export function git(cwd, ...args) {
|
|
23
|
-
const r = spawnSync("git", [...GIT_CONFIG, "-C", cwd, ...args], { encoding: "utf8" });
|
|
24
|
-
if (r.status !== 0) throw new Error(`git ${args.join(" ")} in ${cwd} failed: ${r.stderr}`);
|
|
25
|
-
return r.stdout.trimEnd();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function gitInit(dir, branch) {
|
|
29
|
-
const r = spawnSync("git", ["init", "-q", "-b", branch, dir], { encoding: "utf8" });
|
|
30
|
-
if (r.status !== 0) throw new Error(`git init ${dir} failed: ${r.stderr}`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function newRepo(root, name, branch) {
|
|
34
|
-
const dir = path.join(root, name);
|
|
35
|
-
gitInit(dir, branch);
|
|
36
|
-
writeFileSync(path.join(dir, "README.md"), "base\n");
|
|
37
|
-
git(dir, "add", "README.md");
|
|
38
|
-
git(dir, "commit", "-qm", "base");
|
|
39
|
-
return dir;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { newRepo, commitFile };
|
|
43
|
-
|
|
44
|
-
function commitFile(dir, rel, content) {
|
|
45
|
-
const target = path.join(dir, rel);
|
|
46
|
-
mkdirSync(path.dirname(target), { recursive: true });
|
|
47
|
-
writeFileSync(target, content);
|
|
48
|
-
git(dir, "add", rel);
|
|
49
|
-
git(dir, "commit", "-qm", `add ${rel}`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function bareRemote(root, dir, branch) {
|
|
53
|
-
const bare = path.join(root, `${path.basename(dir)}-remote.git`);
|
|
54
|
-
const r = spawnSync("git", ["init", "-q", "--bare", bare], { encoding: "utf8" });
|
|
55
|
-
if (r.status !== 0) throw new Error(`git init --bare failed: ${r.stderr}`);
|
|
56
|
-
git(dir, "remote", "add", "origin", bare);
|
|
57
|
-
git(dir, "push", "-qu", "origin", branch);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function unitBranch(root, name, branch, acceptance = "frozen") {
|
|
61
|
-
const dir = newRepo(root, name, "main");
|
|
62
|
-
git(dir, "checkout", "-q", "-b", branch);
|
|
63
|
-
// Feature 61: the unit document is the frozen surface at HEAD.
|
|
64
|
-
commitFile(dir, `docs/features/${branch.split("/")[1]}/SPEC.md`, `unit doc\n`);
|
|
65
|
-
return dir;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function ghStub(root) {
|
|
69
|
-
const dir = path.join(root, "bin");
|
|
70
|
-
mkdirSync(dir, { recursive: true });
|
|
71
|
-
const file = path.join(dir, "gh");
|
|
72
|
-
writeFileSync(
|
|
73
|
-
file,
|
|
74
|
-
[
|
|
75
|
-
"#!/usr/bin/env bash",
|
|
76
|
-
"# PATH-stub for gh. `pr list --head <branch>` answers with $GH_STUB_JSON (the",
|
|
77
|
-
"# pull requests of that branch); `pr view <arg>` answers with",
|
|
78
|
-
"# $GH_STUB_VIEW_JSON — real gh reads an all-numeric argument as a PR NUMBER",
|
|
79
|
-
"# and exits nonzero when no pull request matches the branch.",
|
|
80
|
-
"# $GH_STUB_EXIT forces a failure exit from either invocation;",
|
|
81
|
-
"# $GH_STUB_VIEW_EXIT forces one from `pr view` only (the real 'no PR for",
|
|
82
|
-
"# this branch' answer, which is what makes a missing PR",
|
|
83
|
-
"# indistinguishable from an unreachable gh in the pre-F9 query).",
|
|
84
|
-
'case "$1 $2" in',
|
|
85
|
-
' "pr list")\n printf \'%s\\n\' "${GH_STUB_JSON:-[]}"\n exit_code="${GH_STUB_EXIT:-0}"\n ;;',
|
|
86
|
-
' "pr view")\n printf \'%s\\n\' "${GH_STUB_VIEW_JSON:-}"\n exit_code="${GH_STUB_VIEW_EXIT:-${GH_STUB_EXIT:-0}}"\n ;;',
|
|
87
|
-
" *) exit 3 ;;",
|
|
88
|
-
"esac",
|
|
89
|
-
'[ "$exit_code" -eq 0 ] || exit "$exit_code"',
|
|
90
|
-
"",
|
|
91
|
-
].join("\n"),
|
|
92
|
-
);
|
|
93
|
-
chmodSync(file, 0o755);
|
|
94
|
-
return dir;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function buildFixtures(root) {
|
|
98
|
-
const fx = {};
|
|
99
|
-
|
|
100
|
-
// Unit-shaped, clean, no upstream -> the ok path.
|
|
101
|
-
fx.ok = unitBranch(root, "ok", "feat/ok");
|
|
102
|
-
|
|
103
|
-
// On the default branch.
|
|
104
|
-
fx.default = newRepo(root, "default", "main");
|
|
105
|
-
|
|
106
|
-
// Not a repository at all.
|
|
107
|
-
fx.notrepo = path.join(root, "notrepo");
|
|
108
|
-
mkdirSync(fx.notrepo, { recursive: true });
|
|
109
|
-
|
|
110
|
-
// Branch with no own commit.
|
|
111
|
-
fx.nocommits = newRepo(root, "nocommits", "main");
|
|
112
|
-
git(fx.nocommits, "checkout", "-q", "-b", "feat/none");
|
|
113
|
-
|
|
114
|
-
// Unborn branch, zero commits anywhere (dev scenario verifier:empty-repo).
|
|
115
|
-
fx.empty = path.join(root, "empty");
|
|
116
|
-
gitInit(fx.empty, "feature/x");
|
|
117
|
-
|
|
118
|
-
// Unit branch exists but the unit doc is absent at HEAD.
|
|
119
|
-
fx.missing = newRepo(root, "missing", "main");
|
|
120
|
-
git(fx.missing, "checkout", "-q", "-b", "feat/missing");
|
|
121
|
-
commitFile(fx.missing, "docs/features/missing/.gitkeep", "");
|
|
122
|
-
|
|
123
|
-
// Not unit-shaped -> box2 not applicable.
|
|
124
|
-
fx.plain = newRepo(root, "plain", "main");
|
|
125
|
-
git(fx.plain, "checkout", "-q", "-b", "chore/plain");
|
|
126
|
-
commitFile(fx.plain, "note.txt", "x\n");
|
|
127
|
-
|
|
128
|
-
// Unit path exists as a regular FILE, not a directory -> the unit directory
|
|
129
|
-
// does not exist, so box2 is not-applicable (ED-52-2) in BOTH engines
|
|
130
|
-
// (F5, review cycle 2).
|
|
131
|
-
fx.unitfile = newRepo(root, "unitfile", "main");
|
|
132
|
-
git(fx.unitfile, "checkout", "-q", "-b", "feat/unitfile");
|
|
133
|
-
commitFile(fx.unitfile, "docs/features/unitfile", "not a directory\n");
|
|
134
|
-
|
|
135
|
-
// Dirty tree.
|
|
136
|
-
fx.dirty = unitBranch(root, "dirty", "feat/dirty");
|
|
137
|
-
writeFileSync(path.join(fx.dirty, "README.md"), "base\ndirty\n");
|
|
138
|
-
|
|
139
|
-
// Pushed branch plus one local commit -> ahead of remote.
|
|
140
|
-
fx.ahead = unitBranch(root, "ahead", "feat/ahead");
|
|
141
|
-
bareRemote(root, fx.ahead, "feat/ahead");
|
|
142
|
-
commitFile(fx.ahead, "extra.txt", "local only\n");
|
|
143
|
-
|
|
144
|
-
// Dirty AND ahead simultaneously -> dirty wins inside box5.
|
|
145
|
-
fx.dirtyahead = unitBranch(root, "dirtyahead", "feat/dirtyahead");
|
|
146
|
-
bareRemote(root, fx.dirtyahead, "feat/dirtyahead");
|
|
147
|
-
commitFile(fx.dirtyahead, "extra.txt", "local only\n");
|
|
148
|
-
writeFileSync(path.join(fx.dirtyahead, "README.md"), "base\ndirty\n");
|
|
149
|
-
|
|
150
|
-
// Dirty tree with spaces / unicode filenames (dev scenario).
|
|
151
|
-
fx.unicode = unitBranch(root, "unicode", "feat/unicode");
|
|
152
|
-
writeFileSync(path.join(fx.unicode, "a b.txt"), "x\n");
|
|
153
|
-
writeFileSync(path.join(fx.unicode, "café.txt"), "x\n");
|
|
154
|
-
|
|
155
|
-
// Pushed branch with an upstream -> box4 exercises the gh stub.
|
|
156
|
-
fx.b4 = unitBranch(root, "b4", "feat/b4");
|
|
157
|
-
bareRemote(root, fx.b4, "feat/b4");
|
|
158
|
-
|
|
159
|
-
// Corrupt index: `git status` itself errors while branch/rev-list still
|
|
160
|
-
// answer -> box5 must fail closed, never print a fake ok (F1, review cycle 1).
|
|
161
|
-
fx.corrupt = unitBranch(root, "corrupt", "feat/corrupt");
|
|
162
|
-
writeFileSync(path.join(fx.corrupt, ".git/index"), "not a git index\n");
|
|
163
|
-
|
|
164
|
-
// Listing past the engine's 1 MiB read cap and past the shim's pipe buffer:
|
|
165
|
-
// both truncate, and both must still fail closed (F6, fold cycle 2). Long
|
|
166
|
-
// path segments keep the fixture cheap — 320 files ≈ 1.2 MB of porcelain.
|
|
167
|
-
fx.bigstatus = unitBranch(root, "bigstatus", "feat/bigstatus");
|
|
168
|
-
const longDir = Array.from({ length: 19 }, () => "d".repeat(200)).join("/");
|
|
169
|
-
commitFile(fx.bigstatus, `${longDir}/tracked.txt`, "x\n");
|
|
170
|
-
for (let i = 0; i < 320; i += 1) writeFileSync(path.join(fx.bigstatus, longDir, `f${i}`), "x\n");
|
|
171
|
-
|
|
172
|
-
// Repo-local `status.showUntrackedFiles=no` must not hide an untracked file
|
|
173
|
-
// from box5 (F8, fold cycle 3).
|
|
174
|
-
fx.hidden = unitBranch(root, "hidden", "feat/hidden");
|
|
175
|
-
git(fx.hidden, "config", "status.showUntrackedFiles", "no");
|
|
176
|
-
writeFileSync(path.join(fx.hidden, "untracked.txt"), "x\n");
|
|
177
|
-
|
|
178
|
-
// All-numeric branch name: a bare `gh pr view <branch>` argument is read by
|
|
179
|
-
// gh as a PR NUMBER, so box4 would judge the unrelated PR that shares the
|
|
180
|
-
// name instead of this branch (F11, fold cycle 3).
|
|
181
|
-
fx.numeric = newRepo(root, "numeric", "main");
|
|
182
|
-
git(fx.numeric, "checkout", "-q", "-b", "123");
|
|
183
|
-
commitFile(fx.numeric, "note.txt", "x\n");
|
|
184
|
-
bareRemote(root, fx.numeric, "123");
|
|
185
|
-
|
|
186
|
-
// Engine-only: the phase-lint clause of box2 (the shim cannot run it).
|
|
187
|
-
fx.lintfail = unitBranch(root, "lintfail", "feat/lintfail");
|
|
188
|
-
commitFile(fx.lintfail, "docs/features/lintfail/TASKS.md", "# TASKS\n");
|
|
189
|
-
commitFile(fx.lintfail, "scripts/phase-lint.mjs", "process.exit(1);\n");
|
|
190
|
-
fx.lintpass = unitBranch(root, "lintpass", "feat/lintpass");
|
|
191
|
-
commitFile(fx.lintpass, "docs/features/lintpass/TASKS.md", "# TASKS\n");
|
|
192
|
-
commitFile(fx.lintpass, "scripts/phase-lint.mjs", "process.exit(0);\n");
|
|
193
|
-
|
|
194
|
-
return fx;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function baseEnv(ghDir) {
|
|
198
|
-
return {
|
|
199
|
-
...process.env,
|
|
200
|
-
PATH: `${ghDir}:${process.env.PATH}`,
|
|
201
|
-
AGENTIC_WORKFLOW_RUNTIME: "node",
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export function makeContext() {
|
|
206
|
-
const root = mkdtempSync(path.join(os.tmpdir(), "tc-fixtures-"));
|
|
207
|
-
const ghDir = ghStub(root);
|
|
208
|
-
const fx = buildFixtures(root);
|
|
209
|
-
return {
|
|
210
|
-
root,
|
|
211
|
-
ghDir,
|
|
212
|
-
fx,
|
|
213
|
-
cleanup: () => rmSync(root, { recursive: true, force: true }),
|
|
214
|
-
runEngine(cwd, args = [], env = {}) {
|
|
215
|
-
const r = spawnSync(process.execPath, [ENGINE, ...args], {
|
|
216
|
-
cwd,
|
|
217
|
-
encoding: "utf8",
|
|
218
|
-
env: { ...baseEnv(ghDir), ...env },
|
|
219
|
-
});
|
|
220
|
-
return { code: r.status, stdout: r.stdout, stderr: r.stderr };
|
|
221
|
-
},
|
|
222
|
-
runShim(cwd, args = [], env = {}) {
|
|
223
|
-
const r = spawnSync("bash", [SHIM, ...args], {
|
|
224
|
-
cwd,
|
|
225
|
-
encoding: "utf8",
|
|
226
|
-
env: { ...baseEnv(ghDir), ...env },
|
|
227
|
-
});
|
|
228
|
-
return { code: r.status, stdout: r.stdout, stderr: r.stderr };
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// The shared matrix for BOTH engines (no phase-lint fixture: that clause is
|
|
234
|
-
// engine-only, ED-52-3).
|
|
235
|
-
export function receiptCases(ctx) {
|
|
236
|
-
const head = git(ctx.fx.b4, "rev-parse", "HEAD");
|
|
237
|
-
return [
|
|
238
|
-
{ name: "box1 default branch", dir: ctx.fx.default, code: 1, line: "TURN-CONTRACT fail box1: branch-default" },
|
|
239
|
-
{ name: "box1 not a repo", dir: ctx.fx.notrepo, code: 1, line: "TURN-CONTRACT fail box1: not-a-repo" },
|
|
240
|
-
{ name: "box2 unit-doc missing", dir: ctx.fx.missing, code: 1, line: "TURN-CONTRACT fail box2: unit-doc-missing" },
|
|
241
|
-
{ name: "box2 not applicable", dir: ctx.fx.plain, code: 0, line: "TURN-CONTRACT ok" },
|
|
242
|
-
{ name: "box2 unit path is a file", dir: ctx.fx.unitfile, code: 0, line: "TURN-CONTRACT ok" },
|
|
243
|
-
{ name: "box3 no commits", dir: ctx.fx.nocommits, code: 1, line: "TURN-CONTRACT fail box3: no-commits" },
|
|
244
|
-
{ name: "box3 empty repo", dir: ctx.fx.empty, code: 1, line: "TURN-CONTRACT fail box3: no-commits" },
|
|
245
|
-
{ name: "box4 not applicable", dir: ctx.fx.ok, code: 0, line: "TURN-CONTRACT ok" },
|
|
246
|
-
{ name: "box4 no upstream", dir: ctx.fx.ok, args: ["--finished"], code: 1, line: "TURN-CONTRACT fail box4: pr-not-open" },
|
|
247
|
-
{
|
|
248
|
-
name: "box4 gh unreachable",
|
|
249
|
-
dir: ctx.fx.b4,
|
|
250
|
-
args: ["--finished"],
|
|
251
|
-
env: { GH_STUB_EXIT: "1" },
|
|
252
|
-
code: 1,
|
|
253
|
-
line: "TURN-CONTRACT fail box4: pr-unreachable",
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
name: "box4 no PR for the branch",
|
|
257
|
-
dir: ctx.fx.b4,
|
|
258
|
-
args: ["--finished"],
|
|
259
|
-
// The branch is pushed and has no PR: `pr list` answers that with exit 0
|
|
260
|
-
// and an empty result; the pre-F9 query (`pr view`) exits nonzero for the
|
|
261
|
-
// same state, which is why it reports a missing PR as pr-unreachable.
|
|
262
|
-
env: { GH_STUB_JSON: "[]", GH_STUB_VIEW_EXIT: "1" },
|
|
263
|
-
code: 1,
|
|
264
|
-
line: "TURN-CONTRACT fail box4: pr-not-open",
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
name: "box4 merged PR is not an open PR",
|
|
268
|
-
dir: ctx.fx.b4,
|
|
269
|
-
args: ["--finished"],
|
|
270
|
-
env: {
|
|
271
|
-
GH_STUB_JSON: JSON.stringify([{ headRefOid: head, state: "MERGED" }]),
|
|
272
|
-
GH_STUB_VIEW_JSON: JSON.stringify({ headRefOid: head, state: "MERGED" }),
|
|
273
|
-
},
|
|
274
|
-
code: 1,
|
|
275
|
-
line: "TURN-CONTRACT fail box4: pr-not-open",
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
name: "box4 head mismatch",
|
|
279
|
-
dir: ctx.fx.b4,
|
|
280
|
-
args: ["--finished"],
|
|
281
|
-
env: { GH_STUB_JSON: JSON.stringify([{ headRefOid: "0".repeat(40), state: "OPEN" }]) },
|
|
282
|
-
code: 1,
|
|
283
|
-
line: "TURN-CONTRACT fail box4: pr-head-mismatch",
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
name: "box4 open PR at HEAD",
|
|
287
|
-
dir: ctx.fx.b4,
|
|
288
|
-
args: ["--finished"],
|
|
289
|
-
env: { GH_STUB_JSON: JSON.stringify([{ headRefOid: head, state: "OPEN" }]) },
|
|
290
|
-
code: 0,
|
|
291
|
-
line: "TURN-CONTRACT ok",
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
name: "box4 numeric branch is not a PR number",
|
|
295
|
-
dir: ctx.fx.numeric,
|
|
296
|
-
args: ["--finished"],
|
|
297
|
-
env: {
|
|
298
|
-
GH_STUB_JSON: "[]",
|
|
299
|
-
GH_STUB_VIEW_JSON: JSON.stringify({ headRefOid: "0".repeat(40), state: "OPEN" }),
|
|
300
|
-
},
|
|
301
|
-
code: 1,
|
|
302
|
-
line: "TURN-CONTRACT fail box4: pr-not-open",
|
|
303
|
-
},
|
|
304
|
-
{ name: "box5 dirty tree", dir: ctx.fx.dirty, code: 1, line: "TURN-CONTRACT fail box5: dirty-tree" },
|
|
305
|
-
{ name: "box5 ahead of remote", dir: ctx.fx.ahead, code: 1, line: "TURN-CONTRACT fail box5: ahead-of-remote" },
|
|
306
|
-
{ name: "box5 dirty precedes ahead", dir: ctx.fx.dirtyahead, code: 1, line: "TURN-CONTRACT fail box5: dirty-tree" },
|
|
307
|
-
{ name: "box5 unicode/space names", dir: ctx.fx.unicode, code: 1, line: "TURN-CONTRACT fail box5: dirty-tree" },
|
|
308
|
-
{
|
|
309
|
-
name: "box5 ignores status.showUntrackedFiles=no",
|
|
310
|
-
dir: ctx.fx.hidden,
|
|
311
|
-
code: 1,
|
|
312
|
-
line: "TURN-CONTRACT fail box5: dirty-tree",
|
|
313
|
-
},
|
|
314
|
-
{ name: "box5 unreadable status fails closed", dir: ctx.fx.corrupt, code: 1, line: "TURN-CONTRACT fail box5: dirty-tree" },
|
|
315
|
-
{ name: "box5 huge listing fails closed", dir: ctx.fx.bigstatus, code: 1, line: "TURN-CONTRACT fail box5: dirty-tree" },
|
|
316
|
-
{ name: "clean feature branch", dir: ctx.fx.ok, code: 0, line: "TURN-CONTRACT ok" },
|
|
317
|
-
];
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// Engine-only cases: the phase-lint clause of box2.
|
|
321
|
-
export function engineOnlyCases(ctx) {
|
|
322
|
-
return [
|
|
323
|
-
{ name: "box2 phase-lint failed", dir: ctx.fx.lintfail, code: 1, line: "TURN-CONTRACT fail box2: phase-lint-failed" },
|
|
324
|
-
{ name: "box2 phase-lint green", dir: ctx.fx.lintpass, code: 0, line: "TURN-CONTRACT ok" },
|
|
325
|
-
];
|
|
326
|
-
}
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
// Engine suite for packages/agentic-workflow/src/path-policy.mjs.
|
|
2
|
-
//
|
|
3
|
-
// The freeze × class × operation matrix, creation-vs-modification, the
|
|
4
|
-
// justification / approval / unmatched-record / malformed-declaration cases,
|
|
5
|
-
// the shipped-default fallback and degradation cases, and the
|
|
6
|
-
// `path-guard:empty-diff` pin (AC1, AC3, AC5, AC6).
|
|
7
|
-
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
10
|
-
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
11
|
-
import os from "node:os";
|
|
12
|
-
import path from "node:path";
|
|
13
|
-
import { fileURLToPath } from "node:url";
|
|
14
|
-
import test from "node:test";
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
CHANGED_PATH_LIMIT,
|
|
18
|
-
DEGRADATION_CODES,
|
|
19
|
-
PATH_GUARD_REASONS,
|
|
20
|
-
REQUIREMENTS,
|
|
21
|
-
SHIPPED_PATH_POLICY,
|
|
22
|
-
evaluatePathGuard,
|
|
23
|
-
freezeStateFor,
|
|
24
|
-
globToRegExp,
|
|
25
|
-
parsePlanDeclaration,
|
|
26
|
-
parsePathPolicy,
|
|
27
|
-
parseRecords,
|
|
28
|
-
pathMatchesGlob,
|
|
29
|
-
resolvePathPolicy,
|
|
30
|
-
serializeShippedPolicy,
|
|
31
|
-
} from "../src/path-policy.mjs";
|
|
32
|
-
|
|
33
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
34
|
-
const CLI = path.join(here, "..", "bin", "path-guard.mjs");
|
|
35
|
-
const GIT_CONFIG = ["-c", "user.email=t@example.com", "-c", "user.name=test", "-c", "commit.gpgsign=false"];
|
|
36
|
-
const TMP = [];
|
|
37
|
-
|
|
38
|
-
function repo(name) {
|
|
39
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), `path-guard-${name}-`));
|
|
40
|
-
TMP.push(dir);
|
|
41
|
-
execFileSync("git", ["init", "-q", "-b", "feat/unit", dir]);
|
|
42
|
-
execFileSync("git", [...GIT_CONFIG, "-C", dir, "commit", "-q", "--allow-empty", "-m", "base"]);
|
|
43
|
-
return dir;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function commitFile(dir, rel, content = "x\n") {
|
|
47
|
-
const target = path.join(dir, rel);
|
|
48
|
-
mkdirSync(path.dirname(target), { recursive: true });
|
|
49
|
-
writeFileSync(target, content);
|
|
50
|
-
execFileSync("git", [...GIT_CONFIG, "-C", dir, "add", rel]);
|
|
51
|
-
execFileSync("git", [...GIT_CONFIG, "-C", dir, "commit", "-q", "-m", `add ${rel}`]);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function runCli(dir, args) {
|
|
55
|
-
const result = spawnSync(process.execPath, [CLI, ...args], { cwd: dir, encoding: "utf8" });
|
|
56
|
-
return { code: result.status, stdout: result.stdout, stderr: result.stderr };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
test.after(() => {
|
|
60
|
-
for (const dir of TMP) rmSync(dir, { recursive: true, force: true });
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const DECLARED = `path-protection-plan@1
|
|
64
|
-
freeze-after: P4
|
|
65
|
-
kind | path | justification
|
|
66
|
-
created | ** | all paths declared for the matrix`;
|
|
67
|
-
|
|
68
|
-
const DECLARATION = parsePlanDeclaration(DECLARED).declaration;
|
|
69
|
-
const POLICY = resolvePathPolicy(SHIPPED_PATH_POLICY, null);
|
|
70
|
-
|
|
71
|
-
function evaluate(changes, { phase = "P1", records = [], declaration = DECLARATION, policy = POLICY } = {}) {
|
|
72
|
-
return evaluatePathGuard({ changes, policy, declaration, records, phase });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function justification(paths, phase = "P1") {
|
|
76
|
-
return { kind: "justification", paths: [paths].flat(), phase, date: "2026-09-18", authority: "execute-phase", justification: "why" };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function approval(paths, phase = "P5") {
|
|
80
|
-
return { kind: "approval", paths: [paths].flat(), phase, date: "2026-09-18", authority: "human-owner", justification: "owner said yes" };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/* ------------------------------------------------------------- vocabularies */
|
|
84
|
-
|
|
85
|
-
test("the shipped defaults are frozen and carry the five classes", () => {
|
|
86
|
-
assert.deepEqual(Object.keys(SHIPPED_PATH_POLICY.classes), ["tests", "e2e", "test-file", "fixtures", "policy-config"]);
|
|
87
|
-
assert.equal(SHIPPED_PATH_POLICY.classes["policy-config"].freeze, false);
|
|
88
|
-
assert.equal(Object.isFrozen(SHIPPED_PATH_POLICY.classes.tests.globs), true);
|
|
89
|
-
assert.equal(serializeShippedPolicy().endsWith("\n"), true);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("the closed reason set is exactly the ten declared reasons", () => {
|
|
93
|
-
assert.deepEqual([...PATH_GUARD_REASONS].sort(), [
|
|
94
|
-
"approval-required",
|
|
95
|
-
"approved",
|
|
96
|
-
"clean",
|
|
97
|
-
"justified",
|
|
98
|
-
"malformed-config",
|
|
99
|
-
"malformed-declaration",
|
|
100
|
-
"missing-config",
|
|
101
|
-
"protected-modification",
|
|
102
|
-
"undeclared-test",
|
|
103
|
-
"unmatched-record",
|
|
104
|
-
]);
|
|
105
|
-
assert.equal(Object.isFrozen(PATH_GUARD_REASONS), true);
|
|
106
|
-
assert.equal(DEGRADATION_CODES.includes("ignored-removal"), true);
|
|
107
|
-
assert.equal(CHANGED_PATH_LIMIT, 10000);
|
|
108
|
-
assert.deepEqual(REQUIREMENTS, ["none", "justification", "approval"]);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
/* ------------------------------------------------------- freeze-state logic */
|
|
112
|
-
|
|
113
|
-
test("freeze state flips at the declared boundary", () => {
|
|
114
|
-
assert.equal(freezeStateFor("P4", "P4"), "pre-freeze");
|
|
115
|
-
assert.equal(freezeStateFor("P5", "P4"), "post-freeze");
|
|
116
|
-
assert.equal(freezeStateFor("P1", null), "pre-freeze");
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
/* --------------------------------------------------------------- glob match */
|
|
120
|
-
|
|
121
|
-
test("glob matching crosses directories for ** and stays inside for *", () => {
|
|
122
|
-
assert.equal(pathMatchesGlob("tests/a/b.mjs", "tests/**"), true);
|
|
123
|
-
assert.equal(pathMatchesGlob("a/b/foo.test.mjs", "**/*.test.*"), true);
|
|
124
|
-
assert.equal(pathMatchesGlob("foo.test.mjs", "**/*.test.*"), true);
|
|
125
|
-
assert.equal(pathMatchesGlob("a/foo.spec.mjs", "**/*.test.*"), false);
|
|
126
|
-
assert.equal(globToRegExp("a?c").test("abc"), true);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
/* ------------------------------------------------------- policy validation */
|
|
130
|
-
|
|
131
|
-
test("parsePathPolicy fails closed on a wrong schema, unknown key, or bad requirement", () => {
|
|
132
|
-
assert.equal(parsePathPolicy("not json").ok, false);
|
|
133
|
-
assert.equal(parsePathPolicy("{}").ok, false);
|
|
134
|
-
const good = JSON.parse(serializeShippedPolicy());
|
|
135
|
-
assert.equal(parsePathPolicy(JSON.stringify(good)).ok, true);
|
|
136
|
-
assert.equal(parsePathPolicy(JSON.stringify({ ...good, extra: 1 })).ok, false);
|
|
137
|
-
good.matrix["pre-freeze"].modify = "sometimes";
|
|
138
|
-
assert.equal(parsePathPolicy(JSON.stringify(good)).ok, false);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
/* ------------------------------------------------------- resolution / fallback */
|
|
142
|
-
|
|
143
|
-
test("a missing override resolves to the shipped defaults with no degradation", () => {
|
|
144
|
-
const resolved = resolvePathPolicy(SHIPPED_PATH_POLICY, null);
|
|
145
|
-
assert.deepEqual(resolved.degradations, []);
|
|
146
|
-
assert.deepEqual(resolved.classes.tests.globs, ["tests/**"]);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test("an override may only add globs and raise requirements", () => {
|
|
150
|
-
const override = JSON.parse(serializeShippedPolicy());
|
|
151
|
-
override.classes.tests.globs.push("spec/**");
|
|
152
|
-
override.matrix["pre-freeze"].modify = "approval";
|
|
153
|
-
const resolved = resolvePathPolicy(SHIPPED_PATH_POLICY, override);
|
|
154
|
-
assert.equal(resolved.classes.tests.globs.includes("spec/**"), true);
|
|
155
|
-
assert.equal(resolved.matrix["pre-freeze"].modify, "approval");
|
|
156
|
-
assert.deepEqual(resolved.degradations, []);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test("a removal or lowering is ignored and reported", () => {
|
|
160
|
-
const override = JSON.parse(serializeShippedPolicy());
|
|
161
|
-
override.classes.tests.globs = [];
|
|
162
|
-
override.matrix["post-freeze"].modify = "justification";
|
|
163
|
-
const resolved = resolvePathPolicy(SHIPPED_PATH_POLICY, override);
|
|
164
|
-
assert.equal(resolved.classes.tests.globs.includes("tests/**"), true, "the shipped glob stays in force");
|
|
165
|
-
assert.equal(resolved.matrix["post-freeze"].modify, "approval", "the shipped requirement stays in force");
|
|
166
|
-
const codes = resolved.degradations.map((entry) => entry.code);
|
|
167
|
-
assert.equal(codes.includes("ignored-removal"), true);
|
|
168
|
-
assert.equal(codes.includes("ignored-lowering"), true);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
/* ---------------------------------------------------- matrix: freeze × class */
|
|
172
|
-
|
|
173
|
-
const CLASS_PATHS = {
|
|
174
|
-
tests: "tests/a.mjs",
|
|
175
|
-
e2e: "e2e/a.mjs",
|
|
176
|
-
"test-file": "src/a.test.mjs",
|
|
177
|
-
fixtures: "fixtures/a.json",
|
|
178
|
-
"policy-config": ".agentic-workflow/path-policy.json",
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
test("pre-freeze freeze-class matrix: create passes, modify/delete/rename need a justification", () => {
|
|
182
|
-
for (const name of ["tests", "e2e", "test-file", "fixtures"]) {
|
|
183
|
-
const path0 = CLASS_PATHS[name];
|
|
184
|
-
assert.equal(evaluate([{ path: path0, operation: "create" }]).reason, "clean", `${name} create`);
|
|
185
|
-
for (const operation of ["modify", "delete", "rename"]) {
|
|
186
|
-
const fail = evaluate([{ path: path0, operation }]);
|
|
187
|
-
assert.equal(fail.verdict, "fail", `${name} ${operation} without record`);
|
|
188
|
-
assert.equal(fail.reason, "protected-modification", `${name} ${operation} reason`);
|
|
189
|
-
const pass = evaluate([{ path: path0, operation }], { records: [justification(path0)] });
|
|
190
|
-
assert.equal(pass.verdict, "pass", `${name} ${operation} with justification`);
|
|
191
|
-
assert.equal(pass.reason, "justified");
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
test("post-freeze freeze-class matrix: modify/delete/rename need a justification plus an approval", () => {
|
|
197
|
-
for (const name of ["tests", "e2e", "test-file", "fixtures"]) {
|
|
198
|
-
const path0 = CLASS_PATHS[name];
|
|
199
|
-
for (const operation of ["modify", "delete", "rename"]) {
|
|
200
|
-
assert.equal(
|
|
201
|
-
evaluate([{ path: path0, operation }], { phase: "P5" }).reason,
|
|
202
|
-
"protected-modification",
|
|
203
|
-
`${name} ${operation} without record`,
|
|
204
|
-
);
|
|
205
|
-
assert.equal(
|
|
206
|
-
evaluate([{ path: path0, operation }], { phase: "P5", records: [justification(path0, "P5")] }).reason,
|
|
207
|
-
"approval-required",
|
|
208
|
-
`${name} ${operation} with justification only`,
|
|
209
|
-
);
|
|
210
|
-
const approved = evaluate([{ path: path0, operation }], {
|
|
211
|
-
phase: "P5",
|
|
212
|
-
records: [justification(path0, "P5"), approval(path0, "P5")],
|
|
213
|
-
});
|
|
214
|
-
assert.equal(approved.verdict, "pass", `${name} ${operation} approved`);
|
|
215
|
-
assert.equal(approved.reason, "approved");
|
|
216
|
-
}
|
|
217
|
-
const create = evaluate([{ path: path0, operation: "create" }], { phase: "P5", records: [justification(path0, "P5")] });
|
|
218
|
-
assert.equal(create.verdict, "pass", `${name} create post-freeze needs only a justification`);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test("the policy config is protected at all times", () => {
|
|
223
|
-
const path0 = CLASS_PATHS["policy-config"];
|
|
224
|
-
for (const phase of ["P1", "P5"]) {
|
|
225
|
-
assert.equal(evaluate([{ path: path0, operation: "modify" }], { phase }).reason, "protected-modification");
|
|
226
|
-
const pass = evaluate([{ path: path0, operation: "modify" }], {
|
|
227
|
-
phase,
|
|
228
|
-
records: [justification(path0, phase), approval(path0, phase)],
|
|
229
|
-
});
|
|
230
|
-
assert.equal(pass.verdict, "pass");
|
|
231
|
-
assert.equal(pass.reason, "approved");
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
/* ----------------------------------------------- creation ≠ modification */
|
|
236
|
-
|
|
237
|
-
test("a declared create passes pre-freeze; an undeclared create is undeclared-test", () => {
|
|
238
|
-
const declared = evaluate([{ path: "tests/a.mjs", operation: "create" }]);
|
|
239
|
-
assert.equal(declared.verdict, "pass");
|
|
240
|
-
|
|
241
|
-
const narrow = parsePlanDeclaration(`path-protection-plan@1
|
|
242
|
-
freeze-after: P4
|
|
243
|
-
kind | path | justification
|
|
244
|
-
created | tests/declared.mjs | only this one`).declaration;
|
|
245
|
-
const undeclared = evaluate([{ path: "tests/other.mjs", operation: "create" }], { declaration: narrow });
|
|
246
|
-
assert.equal(undeclared.verdict, "fail");
|
|
247
|
-
assert.equal(undeclared.reason, "undeclared-test");
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
/* ---------------------------------------------------- records and closure */
|
|
251
|
-
|
|
252
|
-
test("an unmatched record fails the gate", () => {
|
|
253
|
-
const result = evaluate([], { records: [justification("tests/void.mjs")] });
|
|
254
|
-
assert.equal(result.verdict, "fail");
|
|
255
|
-
assert.equal(result.reason, "unmatched-record");
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test("a record from another phase never satisfies this phase", () => {
|
|
259
|
-
const result = evaluate([{ path: "tests/a.mjs", operation: "modify" }], {
|
|
260
|
-
phase: "P2",
|
|
261
|
-
records: [justification("tests/a.mjs", "P1")],
|
|
262
|
-
});
|
|
263
|
-
assert.equal(result.reason, "protected-modification");
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
test("a malformed declaration fails closed", () => {
|
|
267
|
-
assert.equal(evaluate([], { declaration: null }).reason, "malformed-declaration");
|
|
268
|
-
assert.equal(parsePlanDeclaration("no block here").ok, false);
|
|
269
|
-
assert.equal(parsePlanDeclaration("path-protection-plan@1\nkind | path | justification\ncreated | x | y").ok, false);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
test("records require the sanctioned authority per kind", () => {
|
|
273
|
-
assert.equal(parseRecords("").ok, true);
|
|
274
|
-
assert.equal(parseRecords("").records.length, 0);
|
|
275
|
-
const bad = `path-protection-records@1
|
|
276
|
-
kind | paths | phase | date | authority | justification
|
|
277
|
-
approval | tests/a.mjs | P5 | 2026-09-18 | execute-phase | auto`;
|
|
278
|
-
assert.equal(parseRecords(bad).ok, false);
|
|
279
|
-
const good = `path-protection-records@1
|
|
280
|
-
kind | paths | phase | date | authority | justification
|
|
281
|
-
approval | tests/a.mjs | P5 | 2026-09-18 | human-owner | owner`;
|
|
282
|
-
assert.equal(parseRecords(good).ok, true);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
/* ------------------------------------------------------- empty-diff pin (CLI) */
|
|
286
|
-
|
|
287
|
-
test("path-guard:empty-diff — a clean tree yields pass — clean, exit 0", () => {
|
|
288
|
-
const dir = repo("empty");
|
|
289
|
-
const unit = "docs/features/60-demo";
|
|
290
|
-
commitFile(dir, `${unit}/PLAN.md`, `\`\`\`text\n${DECLARED}\n\`\`\`\n`);
|
|
291
|
-
const result = runCli(dir, ["--unit", unit, "--phase", "P1"]);
|
|
292
|
-
assert.equal(result.code, 0, result.stderr);
|
|
293
|
-
assert.match(result.stdout, /^PATH-GUARD pass — clean\n/);
|
|
294
|
-
assert.match(result.stdout, /offenders: none\n/);
|
|
295
|
-
assert.match(result.stdout, /checked: 0\n/);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test("unknown arguments are a usage error on stderr, exit 2", () => {
|
|
299
|
-
const dir = repo("usage");
|
|
300
|
-
const result = runCli(dir, ["--unit", "u", "--phase", "P1", "--bogus"]);
|
|
301
|
-
assert.equal(result.code, 2);
|
|
302
|
-
assert.match(result.stderr, /unknown argument: --bogus/);
|
|
303
|
-
assert.equal(result.stdout, "");
|
|
304
|
-
});
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// Engine suite for packages/agentic-workflow/bin/turn-contract.mjs.
|
|
2
|
-
//
|
|
3
|
-
// Per-box pass/fail/n-a over the shared throwaway-repo matrix (fixtures.mjs),
|
|
4
|
-
// plus the CLI contract, subdirectory invocation, the read-only assertion, and
|
|
5
|
-
// the engine-only phase-lint clause of box2 (ED-52-3).
|
|
6
|
-
|
|
7
|
-
import test from "node:test";
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { chmodSync, mkdirSync, readFileSync, utimesSync, writeFileSync } from "node:fs";
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
|
|
12
|
-
import { makeContext, receiptCases, engineOnlyCases, git, newRepo, commitFile } from "./fixtures.mjs";
|
|
13
|
-
|
|
14
|
-
const ctx = makeContext();
|
|
15
|
-
test.after(() => ctx.cleanup());
|
|
16
|
-
|
|
17
|
-
for (const c of [...receiptCases(ctx), ...engineOnlyCases(ctx)]) {
|
|
18
|
-
test(c.name, () => {
|
|
19
|
-
const r = ctx.runEngine(c.dir, c.args ?? [], c.env ?? {});
|
|
20
|
-
assert.equal(r.stdout, `${c.line}\n`, `stdout for "${c.name}"`);
|
|
21
|
-
assert.equal(r.code, c.code, `exit code for "${c.name}"`);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
test("empty repo fails without a stack trace", () => {
|
|
26
|
-
const r = ctx.runEngine(ctx.fx.empty);
|
|
27
|
-
assert.equal(r.code, 1);
|
|
28
|
-
assert.equal(r.stderr, "", "no diagnostics on a fail path");
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("--help names both flags and exits 0", () => {
|
|
32
|
-
for (const args of [["--help"], ["--finished", "--help"]]) {
|
|
33
|
-
const r = ctx.runEngine(ctx.fx.ok, args);
|
|
34
|
-
assert.equal(r.code, 0, `exit for ${args.join(" ")}`);
|
|
35
|
-
assert.match(r.stdout, /--finished/);
|
|
36
|
-
assert.match(r.stdout, /--help/);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test("unknown flag prints usage on stderr and exits 2", () => {
|
|
41
|
-
const r = ctx.runEngine(ctx.fx.ok, ["--nope"]);
|
|
42
|
-
assert.equal(r.code, 2);
|
|
43
|
-
assert.equal(r.stdout, "", "usage errors never print a receipt on stdout");
|
|
44
|
-
assert.match(r.stderr, /unknown argument: --nope/);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("works from a subdirectory of the repository", () => {
|
|
48
|
-
const sub = path.join(ctx.fx.ok, "subdir");
|
|
49
|
-
mkdirSync(sub, { recursive: true });
|
|
50
|
-
const r = ctx.runEngine(sub);
|
|
51
|
-
assert.equal(r.code, 0);
|
|
52
|
-
assert.equal(r.stdout, "TURN-CONTRACT ok\n");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("the verifier is read-only", () => {
|
|
56
|
-
const before = git(ctx.fx.ok, "status", "--porcelain", "--untracked-files=all");
|
|
57
|
-
const r = ctx.runEngine(ctx.fx.ok);
|
|
58
|
-
const after = git(ctx.fx.ok, "status", "--porcelain", "--untracked-files=all");
|
|
59
|
-
assert.equal(r.stdout, "TURN-CONTRACT ok\n");
|
|
60
|
-
assert.equal(after, before, "the verifier must not mutate tree or index");
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("the status read does not rewrite .git/index", () => {
|
|
64
|
-
const dir = newRepo(ctx.root, "readonlyindex", "feat/readonlyindex");
|
|
65
|
-
commitFile(dir, "docs/features/readonlyindex/SPEC.md", "unit doc\n");
|
|
66
|
-
// A stale mtime on a tracked file makes `git status` want to refresh the
|
|
67
|
-
// index; the read must not write it (F10, fold cycle 3 — a porcelain-only
|
|
68
|
-
// before/after comparison cannot observe that write).
|
|
69
|
-
const stale = new Date("2020-01-01T00:00:00.000Z");
|
|
70
|
-
utimesSync(path.join(dir, "README.md"), stale, stale);
|
|
71
|
-
const index = path.join(dir, ".git", "index");
|
|
72
|
-
const before = readFileSync(index);
|
|
73
|
-
const r = ctx.runEngine(dir);
|
|
74
|
-
assert.equal(r.stdout, "TURN-CONTRACT ok\n");
|
|
75
|
-
assert.equal(r.code, 0);
|
|
76
|
-
assert.deepEqual(readFileSync(index), before, "git status must not refresh (rewrite) .git/index");
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("the box2 phase-lint clause is read-only", () => {
|
|
80
|
-
const before = git(ctx.fx.lintpass, "status", "--porcelain", "--untracked-files=all");
|
|
81
|
-
const r = ctx.runEngine(ctx.fx.lintpass);
|
|
82
|
-
const after = git(ctx.fx.lintpass, "status", "--porcelain", "--untracked-files=all");
|
|
83
|
-
assert.equal(r.stdout, "TURN-CONTRACT ok\n");
|
|
84
|
-
assert.equal(after, before, "the phase-lint spawn must not mutate tree or index");
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("unreadable .git fails closed with a fail line", (t) => {
|
|
88
|
-
if (typeof process.getuid === "function" && process.getuid() === 0) {
|
|
89
|
-
t.skip("running as root: permission bits are not enforced");
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const dir = newRepo(ctx.root, "plumbing", "feat/plumbing");
|
|
93
|
-
commitFile(dir, "docs/features/plumbing/ACCEPTANCE.md", "frozen\n");
|
|
94
|
-
const dotgit = path.join(dir, ".git");
|
|
95
|
-
chmodSync(dotgit, 0o000);
|
|
96
|
-
try {
|
|
97
|
-
const r = ctx.runEngine(dir);
|
|
98
|
-
assert.equal(r.code, 1, "never a fake ok when plumbing is denied");
|
|
99
|
-
assert.equal(r.stdout, "TURN-CONTRACT fail box1: not-a-repo\n");
|
|
100
|
-
} finally {
|
|
101
|
-
chmodSync(dotgit, 0o755);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Two-engine parity suite: the same fixture-repo matrix through the crate
|
|
2
|
-
// engine and the scaffold shim must produce byte-identical stdout and exit
|
|
3
|
-
// codes (AC7). This is the drift gate between the two implementations.
|
|
4
|
-
|
|
5
|
-
import test from "node:test";
|
|
6
|
-
import assert from "node:assert/strict";
|
|
7
|
-
|
|
8
|
-
import { makeContext, receiptCases } from "./fixtures.mjs";
|
|
9
|
-
|
|
10
|
-
const ctx = makeContext();
|
|
11
|
-
test.after(() => ctx.cleanup());
|
|
12
|
-
|
|
13
|
-
for (const c of receiptCases(ctx)) {
|
|
14
|
-
test(`parity: ${c.name}`, () => {
|
|
15
|
-
const engine = ctx.runEngine(c.dir, c.args ?? [], c.env ?? {});
|
|
16
|
-
const shim = ctx.runShim(c.dir, c.args ?? [], c.env ?? {});
|
|
17
|
-
assert.equal(engine.code, shim.code, `exit parity for "${c.name}"`);
|
|
18
|
-
assert.equal(engine.stdout, shim.stdout, `stdout parity for "${c.name}"`);
|
|
19
|
-
});
|
|
20
|
-
}
|