@gtrabanco/agentic-workflow 0.1.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/README.md +19 -0
- package/bin/agwo.mjs +237 -0
- package/bin/path-guard.mjs +263 -0
- package/bin/turn-contract.mjs +174 -0
- package/package.json +20 -0
- package/src/edit/Budgets.mjs +103 -0
- package/src/edit/Changelog.mjs +92 -0
- package/src/edit/Manifest.mjs +167 -0
- package/src/edit/Roadmap.mjs +143 -0
- package/src/edit/UnitDoc.mjs +331 -0
- package/src/edit/schema.mjs +90 -0
- package/src/path-policy.mjs +570 -0
- package/test/edit.test.mjs +358 -0
- package/test/fixtures.mjs +326 -0
- package/test/path-guard.engine.test.mjs +304 -0
- package/test/turn-contract.engine.test.mjs +103 -0
- package/test/turn-contract.parity.test.mjs +20 -0
|
@@ -0,0 +1,304 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|