@tachikomagundam/abathur 0.2.5 → 0.2.7
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 +3 -3
- package/dist/cli.js +4 -0
- package/dist/commands/genome.js +2 -2
- package/dist/commands/graft.js +1 -1
- package/dist/commands/readjudicate.js +28 -0
- package/dist/commands/retract.js +53 -0
- package/dist/commands/run.js +1 -1
- package/dist/commands/self-eval.js +1 -1
- package/dist/commands/tombstone.js +30 -16
- package/dist/core/evolve/run-loop.js +14 -0
- package/dist/core/evolve/run-rows.js +14 -0
- package/dist/core/evolve/score-bank.js +214 -0
- package/dist/core/graft-rebench.js +3 -0
- package/dist/core/ledger.js +8 -1
- package/dist/core/promote.js +63 -47
- package/dist/core/readjudicate.js +247 -0
- package/dist/core/retract.js +166 -0
- package/dist/core/stats-math.js +39 -0
- package/dist/core/stats.js +93 -19
- package/dist/core/worktree.js +1 -1
- package/dist/genomes/toy-smoke/init.mjs +1 -1
- package/dist/test/bundle.test.js +1 -1
- package/dist/test/fixture-loop.test.js +1 -1
- package/dist/test/fixtures-self.js +1 -1
- package/dist/test/fixtures-wt.js +1 -1
- package/dist/test/friction.test.js +3 -3
- package/dist/test/graft.test.js +1 -1
- package/dist/test/historian-grader-integrity.test.js +509 -2
- package/dist/test/promote.test.js +222 -5
- package/dist/test/readjudicate.test.js +212 -0
- package/dist/test/reflect.test.js +1 -1
- package/dist/test/repopath-seams.test.js +55 -0
- package/dist/test/score-bank.test.js +235 -0
- package/dist/test/seam-gates.test.js +84 -0
- package/dist/test/self-snapshot.test.js +2 -2
- package/dist/test/stats-acceptance.test.js +329 -0
- package/graders/historian/grader-core.d.mts +27 -0
- package/graders/historian/grader-core.mjs +311 -19
- package/graders/historian/grader.mjs +5 -5
- package/graders/historian/judge-poststage-19.mjs +212 -0
- package/graders/historian/run-scenario-19.sh +43 -0
- package/graders/historian/run-scenario.sh +16 -0
- package/package.json +1 -1
- package/plugin/abathur-command.md +3 -3
- package/plugin/abathur.ts +6 -6
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Score-bank loader tests (acceptance-semantics redesign, 2026-09-24): the
|
|
2
|
+
// fail-closed activation law, exact shrinkage/quantum-floor arithmetic, row
|
|
3
|
+
// skipping with notices, corrupt-tail/backup exclusion and the gate-time
|
|
4
|
+
// candidate-tree exclusion hook the A9 backtest replays through.
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
7
|
+
import os from "node:os";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { describe, it } from "node:test";
|
|
10
|
+
import { BANK_QUANTUM, BANK_THIN_DF, loadScoreBank } from "../core/evolve/score-bank.js";
|
|
11
|
+
const STATE_DIR = path.join(".state", "abathur");
|
|
12
|
+
function generationLine(row) {
|
|
13
|
+
const data = {
|
|
14
|
+
source: row.source,
|
|
15
|
+
...(row.source === "candidate" ? { candidateId: `c-${row.tree}`, treeSha: row.tree, commitSha: row.tree ?? "c" } : {}),
|
|
16
|
+
headCommit: row.head,
|
|
17
|
+
complete: row.complete ?? true,
|
|
18
|
+
reps: 2,
|
|
19
|
+
units: row.units.map((u) => ({ ...u, runIds: u.scores.map((_, i) => `r${String(i)}`), failures: [] })),
|
|
20
|
+
counters: { candidates: row.source === "candidate" ? 1 : 0, modelCalls: 0, tokens: 1, wallS: 1 },
|
|
21
|
+
manifest: [],
|
|
22
|
+
benchProvenance: { benchType: "toy", versions: [] },
|
|
23
|
+
};
|
|
24
|
+
return `${JSON.stringify({ v: 1, ts: row.ts ?? "2026-09-24T00:00:00.000Z", kind: "generation_complete", genId: "g-1", runId: "a-1", data })}\n`;
|
|
25
|
+
}
|
|
26
|
+
function withRepo(write) {
|
|
27
|
+
const repo = mkdtempSync(path.join(os.tmpdir(), "abathur-bank-"));
|
|
28
|
+
try {
|
|
29
|
+
write(repo);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
rmSync(repo, { recursive: true, force: true });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function stateDir(repo) {
|
|
36
|
+
const dir = path.join(repo, STATE_DIR);
|
|
37
|
+
mkdirSync(dir, { recursive: true });
|
|
38
|
+
return dir;
|
|
39
|
+
}
|
|
40
|
+
describe("loadScoreBank fail-closed activation", () => {
|
|
41
|
+
it("no .state dir at all ⇒ null — and the loader never creates one (peekPlanState discipline)", () => {
|
|
42
|
+
withRepo((repo) => {
|
|
43
|
+
assert.equal(loadScoreBank(repo), null);
|
|
44
|
+
assert.equal(existsSync(path.join(repo, STATE_DIR)), false);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
it("live ledger only ⇒ null — rotation is the activation law", () => {
|
|
48
|
+
withRepo((repo) => {
|
|
49
|
+
const dir = stateDir(repo);
|
|
50
|
+
writeFileSync(path.join(dir, "ledger.jsonl"), generationLine({ source: "incumbent", head: "a".repeat(40), units: [{ unitId: "u", split: "train", scores: [0, 2, 1, 3] }] }));
|
|
51
|
+
assert.equal(loadScoreBank(repo), null);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
it("ledger.corrupt-* is NOT a rotated archive; an empty dir ⇒ null", () => {
|
|
55
|
+
withRepo((repo) => {
|
|
56
|
+
const dir = stateDir(repo);
|
|
57
|
+
writeFileSync(path.join(dir, "ledger.corrupt-20260924-9.jsonl"), generationLine({ source: "incumbent", head: "a".repeat(40), units: [{ unitId: "u", split: "train", scores: [0, 2, 1, 3] }] }));
|
|
58
|
+
assert.equal(loadScoreBank(repo), null);
|
|
59
|
+
rmSync(path.join(dir, "ledger.corrupt-20260924-9.jsonl"));
|
|
60
|
+
writeFileSync(path.join(dir, "notes.txt"), "unrelated");
|
|
61
|
+
assert.equal(loadScoreBank(repo), null);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
it("archive + live load; totalDf=0 (only single-rep groups ever) ⇒ null", () => {
|
|
65
|
+
withRepo((repo) => {
|
|
66
|
+
const dir = stateDir(repo);
|
|
67
|
+
writeFileSync(path.join(dir, "ledger.campaign1-x.jsonl"), generationLine({ source: "incumbent", head: "a".repeat(40), units: [{ unitId: "u", split: "train", scores: [1] }, { unitId: "v", split: "val", scores: [0.5] }] }));
|
|
68
|
+
writeFileSync(path.join(dir, "ledger.jsonl"), generationLine({ source: "incumbent", head: "b".repeat(40), units: [{ unitId: "u", split: "train", scores: [2] }] }));
|
|
69
|
+
assert.equal(loadScoreBank(repo), null);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe("loadScoreBank arithmetic", () => {
|
|
74
|
+
const scatterRow = (head, tree, source, scores) => generationLine({ source, head, ...(tree === undefined ? {} : { tree }), units: [{ unitId: "u", split: "train", scores }] });
|
|
75
|
+
it("pools within-group SS across lineages; thin df floors σ at the quantum; df≥6 keeps the shrunk σ", () => {
|
|
76
|
+
withRepo((repo) => {
|
|
77
|
+
const dir = stateDir(repo);
|
|
78
|
+
// group g1 (campaign1 archive): [0,2] → mean 1, SS 2, df 1 — the ONLY scatter in the bank.
|
|
79
|
+
writeFileSync(path.join(dir, "ledger.campaign1-x.jsonl"), `${scatterRow("a".repeat(40), undefined, "incumbent", [0, 2])}` +
|
|
80
|
+
// group g2 (live): same unit, different lineage head, zero scatter
|
|
81
|
+
scatterRow("b".repeat(40), undefined, "incumbent", [1, 1]));
|
|
82
|
+
writeFileSync(path.join(dir, "ledger.jsonl"), generationLine({ source: "candidate", head: "b".repeat(40), tree: "t1", units: [{ unitId: "q", split: "train", scores: [1, 1, 1, 1] }] }));
|
|
83
|
+
const bank = loadScoreBank(repo);
|
|
84
|
+
assert.ok(bank !== null);
|
|
85
|
+
// totals: u groups df 1+1 (SS 2+0), q group df 3 (SS 0) ⇒ total df 5, prior σ² = 2/5.
|
|
86
|
+
assert.equal(bank.totalDf, 5);
|
|
87
|
+
assert.ok(Math.abs(bank.priorSigma - Math.sqrt(0.4)) < 1e-12);
|
|
88
|
+
// unit u: σ̂² = 2/2 = 1; shrunk = (2·1 + 2·0.4)/4 = 0.7 ⇒ σ = √0.7 (floor 0.0884 does not bind).
|
|
89
|
+
const u = bank.units.get("u");
|
|
90
|
+
assert.ok(u !== undefined);
|
|
91
|
+
assert.equal(u.df, 2);
|
|
92
|
+
assert.ok(Math.abs(u.sigma - Math.sqrt(0.7)) < 1e-12, `sigma ${String(u.sigma)}`);
|
|
93
|
+
// unit q: df 3, zero SS ⇒ shrunk toward the prior: (3·0 + 2·0.4)/5 = 0.16 ⇒ σ = 0.4 > floor.
|
|
94
|
+
const q = bank.units.get("q");
|
|
95
|
+
assert.ok(q !== undefined);
|
|
96
|
+
assert.ok(Math.abs(q.sigma - 0.4) < 1e-12);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
it("zero-scatter bank: thin units sit exactly on BANK_QUANTUM, proven-quiet units (df≥6) on their shrunk σ", () => {
|
|
100
|
+
withRepo((repo) => {
|
|
101
|
+
const dir = stateDir(repo);
|
|
102
|
+
const thin = generationLine({ source: "incumbent", head: "a".repeat(40), units: [{ unitId: "thin", split: "train", scores: [0.5, 0.5] }] });
|
|
103
|
+
const wide = generationLine({ source: "incumbent", head: "b".repeat(40), units: [{ unitId: "wide", split: "train", scores: [1, 1, 1, 1, 1, 1] }] }) + generationLine({ source: "candidate", head: "b".repeat(40), tree: "x", units: [{ unitId: "wide", split: "train", scores: [1, 1, 1] }] });
|
|
104
|
+
writeFileSync(path.join(dir, "ledger.campaign1-x.jsonl"), thin + wide);
|
|
105
|
+
const bank = loadScoreBank(repo);
|
|
106
|
+
assert.ok(bank !== null);
|
|
107
|
+
assert.equal(bank.priorSigma, 0);
|
|
108
|
+
assert.equal(bank.units.get("thin")?.sigma, BANK_QUANTUM); // shrunk 0 → floored
|
|
109
|
+
assert.equal(bank.units.get("thin")?.df, 1);
|
|
110
|
+
assert.equal(bank.units.get("wide")?.sigma, 0); // df 4+1+… ≥ BANK_THIN_DF, zero prior ⇒ stays 0
|
|
111
|
+
assert.ok((bank.units.get("wide")?.df ?? 0) >= BANK_THIN_DF);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe("loadScoreBank row hygiene", () => {
|
|
116
|
+
it("corrupt JSON lines and schema-invalid rows are skipped with notices; valid rows still price", () => {
|
|
117
|
+
withRepo((repo) => {
|
|
118
|
+
const dir = stateDir(repo);
|
|
119
|
+
const good = generationLine({ source: "incumbent", head: "a".repeat(40), units: [{ unitId: "u", split: "train", scores: [0, 2, 2, 0] }] });
|
|
120
|
+
writeFileSync(path.join(dir, "ledger.campaign1-x.jsonl"), `${good}{"v":1,"ts":"x\n${generationLine({ source: "incumbent", head: "a".repeat(40), units: [{ unitId: "bad", split: "nope", scores: [1, 2] }] })}`);
|
|
121
|
+
const bank = loadScoreBank(repo);
|
|
122
|
+
assert.ok(bank !== null);
|
|
123
|
+
assert.ok(bank.units.has("u"));
|
|
124
|
+
assert.equal(bank.units.has("bad"), false);
|
|
125
|
+
assert.equal(bank.notices.length, 2);
|
|
126
|
+
assert.match(bank.notices.join("\n"), /not JSON/);
|
|
127
|
+
assert.match(bank.notices.join("\n"), /unreadable/);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
it("budget-truncated rows (complete:false) still contribute their real replicate scores", () => {
|
|
131
|
+
withRepo((repo) => {
|
|
132
|
+
const dir = stateDir(repo);
|
|
133
|
+
writeFileSync(path.join(dir, "ledger.campaign1-x.jsonl"), generationLine({ source: "candidate", head: "a".repeat(40), tree: "t", complete: false, units: [{ unitId: "u", split: "train", scores: [0, 2] }] }));
|
|
134
|
+
const bank = loadScoreBank(repo);
|
|
135
|
+
assert.equal(bank?.units.get("u")?.df, 1);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
it("excludeCandidateTrees replays the gate-time world (rows written after evaluate)", () => {
|
|
139
|
+
withRepo((repo) => {
|
|
140
|
+
const dir = stateDir(repo);
|
|
141
|
+
writeFileSync(path.join(dir, "ledger.campaign1-x.jsonl"), generationLine({ source: "incumbent", head: "a".repeat(40), units: [{ unitId: "u", split: "train", scores: [0, 2] }] }) +
|
|
142
|
+
generationLine({ source: "candidate", head: "a".repeat(40), tree: "to-exclude", units: [{ unitId: "u", split: "train", scores: [4, 0] }] }));
|
|
143
|
+
const withIt = loadScoreBank(repo);
|
|
144
|
+
const without = loadScoreBank(repo, { excludeCandidateTrees: ["to-exclude"] });
|
|
145
|
+
assert.equal(withIt?.units.get("u")?.df, 2);
|
|
146
|
+
assert.equal(without?.units.get("u")?.df, 1);
|
|
147
|
+
assert.equal(withIt?.totalDf, 2);
|
|
148
|
+
assert.equal(without?.totalDf, 1);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
it("excludeFiles hides a future campaign's ledger; null once no rotated archive remains", () => {
|
|
152
|
+
withRepo((repo) => {
|
|
153
|
+
const dir = stateDir(repo);
|
|
154
|
+
writeFileSync(path.join(dir, "ledger.campaign1-x.jsonl"), generationLine({ source: "incumbent", head: "a".repeat(40), units: [{ unitId: "u", split: "train", scores: [0, 2, 2, 0] }] }));
|
|
155
|
+
writeFileSync(path.join(dir, "ledger.campaign2-y.jsonl"), generationLine({ source: "incumbent", head: "b".repeat(40), units: [{ unitId: "u", split: "train", scores: [1, 5] }] }));
|
|
156
|
+
assert.equal(loadScoreBank(repo)?.units.get("u")?.df, 4);
|
|
157
|
+
const hidden = loadScoreBank(repo, { excludeFiles: ["ledger.campaign2-y.jsonl"] });
|
|
158
|
+
assert.equal(hidden?.units.get("u")?.df, 3);
|
|
159
|
+
assert.equal(hidden?.totalDf, 3);
|
|
160
|
+
assert.equal(loadScoreBank(repo, { excludeFiles: ["ledger.campaign1-x.jsonl", "ledger.campaign2-y.jsonl"] }), null);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
describe("loadScoreBank bank-epoch lineage quarantine", () => {
|
|
165
|
+
const quietNew = {
|
|
166
|
+
source: "incumbent",
|
|
167
|
+
head: "h1",
|
|
168
|
+
ts: "2026-09-25T00:00:00.000Z",
|
|
169
|
+
units: [{ unitId: "scenario-9", split: "val", scores: [1, 1] }],
|
|
170
|
+
};
|
|
171
|
+
const noisyOld = {
|
|
172
|
+
source: "incumbent",
|
|
173
|
+
head: "h1",
|
|
174
|
+
ts: "2026-09-20T00:00:00.000Z",
|
|
175
|
+
units: [{ unitId: "scenario-9", split: "val", scores: [0, 1, 0, 1] }],
|
|
176
|
+
};
|
|
177
|
+
it("groups with ts before the epoch are quarantined: df drops, notice names the count and why", () => {
|
|
178
|
+
withRepo((repo) => {
|
|
179
|
+
const dir = stateDir(repo);
|
|
180
|
+
writeFileSync(path.join(dir, "ledger.campaign1-2026-09-20.jsonl"), generationLine(noisyOld) + generationLine(quietNew));
|
|
181
|
+
writeFileSync(path.join(dir, "bank-epoch.json"), JSON.stringify({ "scenario-9": { sinceIso: "2026-09-24T00:00:00Z", why: "pin era voided" } }));
|
|
182
|
+
const bank = loadScoreBank(repo);
|
|
183
|
+
assert.ok(bank !== null);
|
|
184
|
+
const stat = bank.units.get("scenario-9");
|
|
185
|
+
assert.ok(stat !== undefined);
|
|
186
|
+
assert.equal(stat.df, 1); // only the quiet new group counts
|
|
187
|
+
assert.ok(stat.sigma >= BANK_QUANTUM - 1e-12); // thin history floor holds the prior
|
|
188
|
+
assert.ok(bank.notices.some((n) => n.includes("bank-epoch 'scenario-9' since") && n.includes("1 group(s) quarantined") && n.includes("pin era voided")));
|
|
189
|
+
assert.ok(bank.notices.some((n) => n.includes("since 2026-09-24T00:00:00Z") && !n.includes("undefined")), "notice must print the ISO epoch, never undefined");
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
it("quarantined-only units leave zero pooled df ⇒ bank null ⇒ caller runs the legacy gate", () => {
|
|
193
|
+
withRepo((repo) => {
|
|
194
|
+
const dir = stateDir(repo);
|
|
195
|
+
writeFileSync(path.join(dir, "ledger.campaign1-2026-09-20.jsonl"), generationLine(noisyOld));
|
|
196
|
+
writeFileSync(path.join(dir, "bank-epoch.json"), JSON.stringify({ "scenario-9": { sinceIso: "2026-09-24T00:00:00Z" } }));
|
|
197
|
+
assert.equal(loadScoreBank(repo), null);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
it("unreadable row ts fails closed for quarantined units but leaves unruled units untouched", () => {
|
|
201
|
+
withRepo((repo) => {
|
|
202
|
+
const dir = stateDir(repo);
|
|
203
|
+
const ruled = { ...noisyOld, ts: "not-a-date", units: [
|
|
204
|
+
{ unitId: "scenario-9", split: "val", scores: [0, 1] },
|
|
205
|
+
{ unitId: "scenario-8", split: "val", scores: [1, 0] },
|
|
206
|
+
] };
|
|
207
|
+
writeFileSync(path.join(dir, "ledger.campaign1-2026-09-20.jsonl"), generationLine(ruled));
|
|
208
|
+
writeFileSync(path.join(dir, "bank-epoch.json"), JSON.stringify({ "scenario-9": { sinceIso: "2026-09-24T00:00:00Z" } }));
|
|
209
|
+
const bank = loadScoreBank(repo);
|
|
210
|
+
assert.ok(bank !== null);
|
|
211
|
+
assert.equal(bank.units.has("scenario-9"), false); // provably-at-or-after failed ⇒ quarantined
|
|
212
|
+
assert.ok(bank.units.has("scenario-8")); // no rule ⇒ untouched
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
it("malformed quarantine sidecars disable the WHOLE bank (never a silently ignored quarantine)", () => {
|
|
216
|
+
const bad = ["{not json", JSON.stringify({ "scenario-9": { sinceIso: "not-a-date" } }), JSON.stringify({ "scenario-9": { sinceIso: "2026-09-24T00:00:00Z", extra: 1 } }), JSON.stringify(["scenario-9"])];
|
|
217
|
+
for (const body of bad) {
|
|
218
|
+
withRepo((repo) => {
|
|
219
|
+
const dir = stateDir(repo);
|
|
220
|
+
writeFileSync(path.join(dir, "ledger.campaign1-2026-09-20.jsonl"), generationLine(noisyOld) + generationLine(quietNew));
|
|
221
|
+
writeFileSync(path.join(dir, "bank-epoch.json"), body);
|
|
222
|
+
assert.equal(loadScoreBank(repo), null, `sidecar must disable bank: ${body.slice(0, 24)}`);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
it("absent sidecar = no quarantine, byte-identical legacy behavior", () => {
|
|
227
|
+
withRepo((repo) => {
|
|
228
|
+
const dir = stateDir(repo);
|
|
229
|
+
writeFileSync(path.join(dir, "ledger.campaign1-2026-09-20.jsonl"), generationLine(noisyOld) + generationLine(quietNew));
|
|
230
|
+
const bank = loadScoreBank(repo);
|
|
231
|
+
assert.ok(bank !== null);
|
|
232
|
+
assert.equal(bank.units.get("scenario-9")?.df, 4); // 3 df old + 1 df new — nothing skipped
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Seam test (postmortem 863e6c2): the human-gate commands `promote` and
|
|
2
|
+
// `tombstone` must resolve an env-literal repoPath exactly like status/run
|
|
3
|
+
// (4997618 pattern). Pre-fix, promote.ts opened the ledger under the STORED
|
|
4
|
+
// UNRESOLVED `${VAR}` literal, read an empty ledger, and reported the
|
|
5
|
+
// misleading "no generation_complete ledger row" with the literal still in
|
|
6
|
+
// the hint — the same fail-open seam class as the status spawn-ENOENT.
|
|
7
|
+
// Pins, for both gates:
|
|
8
|
+
// (1) env exported ⇒ gate reads the REAL ledger at the resolved path:
|
|
9
|
+
// the refusal names the resolved repo, never the `${VAR}` literal;
|
|
10
|
+
// (2) env unset ⇒ clean exit 2 NAMING the variable;
|
|
11
|
+
// (3) stderr never contains the unresolved literal or a spawn-ENOENT.
|
|
12
|
+
import assert from "node:assert/strict";
|
|
13
|
+
import { spawnSync } from "node:child_process";
|
|
14
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
16
|
+
import * as os from "node:os";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
import { test } from "node:test";
|
|
20
|
+
import { registerGenome } from "../core/genome.js";
|
|
21
|
+
import { prepareToyGenome } from "../bench/toy.js";
|
|
22
|
+
const CLI = fileURLToPath(new URL("../../dist/cli.js", import.meta.url));
|
|
23
|
+
const LIT_VAR = "ABATHUR_SEAM_GATES_REPO";
|
|
24
|
+
async function fixture(t, label) {
|
|
25
|
+
const root = mkdtempSync(path.join(os.tmpdir(), "seam-gates-"));
|
|
26
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
27
|
+
const configDir = path.join(root, "config");
|
|
28
|
+
mkdirSync(configDir, { recursive: true });
|
|
29
|
+
writeFileSync(path.join(configDir, "config.jsonc"), '{ "opencodeBin": null }\n', "utf8");
|
|
30
|
+
const repo = await prepareToyGenome(path.join(root, "genome"));
|
|
31
|
+
const doc = JSON.parse(readFileSync(path.join(repo, "genome.jsonc"), "utf8"));
|
|
32
|
+
doc["label"] = label;
|
|
33
|
+
doc["repoPath"] = `\${${LIT_VAR}}`;
|
|
34
|
+
const specFile = path.join(root, "private.jsonc");
|
|
35
|
+
writeFileSync(specFile, `${JSON.stringify(doc, null, 2)}\n`, "utf8");
|
|
36
|
+
process.env[LIT_VAR] = repo;
|
|
37
|
+
try {
|
|
38
|
+
registerGenome(configDir, specFile);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
delete process.env[LIT_VAR];
|
|
42
|
+
}
|
|
43
|
+
return { root, configDir, repo, label };
|
|
44
|
+
}
|
|
45
|
+
function cli(f, args, env) {
|
|
46
|
+
return spawnSync(process.execPath, [CLI, ...args], {
|
|
47
|
+
env: { ...process.env, ABATHUR_CONFIG: path.join(f.configDir, "config.jsonc"), ...env },
|
|
48
|
+
encoding: "utf8",
|
|
49
|
+
timeout: 60_000,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function assertNoLiteralOrEnoent(r) {
|
|
53
|
+
const blob = `${r.stdout}\n${r.stderr}`;
|
|
54
|
+
assert.ok(!blob.includes(`\${${LIT_VAR}}`), `unresolved literal leaked into output:\n${blob}`);
|
|
55
|
+
assert.ok(!blob.includes("ENOENT"), `misleading ENOENT leaked into output:\n${blob}`);
|
|
56
|
+
}
|
|
57
|
+
test("promote with env-literal repoPath: exported ⇒ blocked naming the RESOLVED repo path", async (t) => {
|
|
58
|
+
const f = await fixture(t, "seam-gate-promote");
|
|
59
|
+
const r = cli(f, ["promote", f.label, "g-nonexistent"], { [LIT_VAR]: f.repo });
|
|
60
|
+
assert.equal(r.status, 1, `stdout: ${r.stdout}\nstderr: ${r.stderr}`);
|
|
61
|
+
assertNoLiteralOrEnoent(r);
|
|
62
|
+
assert.ok(r.stderr.includes(f.repo), `refusal must name the resolved repo path so the operator can debug:\n${r.stderr}`);
|
|
63
|
+
});
|
|
64
|
+
test("tombstone with env-literal repoPath: exported ⇒ blocked, no literal leak", async (t) => {
|
|
65
|
+
const f = await fixture(t, "seam-gate-tombstone");
|
|
66
|
+
const r = cli(f, ["tombstone", f.label, "g-nonexistent", "--reason", "seam test"], { [LIT_VAR]: f.repo });
|
|
67
|
+
assert.equal(r.status, 1, `stdout: ${r.stdout}\nstderr: ${r.stderr}`);
|
|
68
|
+
assertNoLiteralOrEnoent(r);
|
|
69
|
+
});
|
|
70
|
+
test("retract with env-literal repoPath: exported ⇒ blocked naming the RESOLVED repo path", async (t) => {
|
|
71
|
+
const f = await fixture(t, "seam-gate-retract");
|
|
72
|
+
const r = cli(f, ["retract", f.label, "g-nonexistent", "--reason", "seam test"], { [LIT_VAR]: f.repo });
|
|
73
|
+
assert.equal(r.status, 1, `stdout: ${r.stdout}\nstderr: ${r.stderr}`);
|
|
74
|
+
assertNoLiteralOrEnoent(r);
|
|
75
|
+
});
|
|
76
|
+
test("promote with env-literal repoPath: unset ⇒ clean exit 2 naming the variable", async (t) => {
|
|
77
|
+
const f = await fixture(t, "seam-gate-promote-unset");
|
|
78
|
+
const env = {};
|
|
79
|
+
env[LIT_VAR] = undefined;
|
|
80
|
+
const r = cli(f, ["promote", f.label, "g-nonexistent"], env);
|
|
81
|
+
assert.equal(r.status, 2, `stdout: ${r.stdout}\nstderr: ${r.stderr}`);
|
|
82
|
+
assert.ok(r.stderr.includes(LIT_VAR), `exit-2 message must name the env var:\n${r.stderr}`);
|
|
83
|
+
assert.ok(!r.stderr.includes("ENOENT"), `misleading ENOENT leaked into output:\n${r.stderr}`);
|
|
84
|
+
});
|
|
@@ -283,8 +283,8 @@ function commitSurgery(fx, message, surgery) {
|
|
|
283
283
|
exec("git", ["-C", fx.harness.repo, "reset", "--hard", fx.head]);
|
|
284
284
|
surgery();
|
|
285
285
|
const repo = fx.harness.repo;
|
|
286
|
-
exec("git", ["-c", "user.name=abathur", "-c", "user.email=
|
|
287
|
-
exec("git", ["-c", "user.name=abathur", "-c", "user.email=
|
|
286
|
+
exec("git", ["-c", "user.name=abathur", "-c", "user.email=agent@host.example", "-C", repo, "add", "-A"]);
|
|
287
|
+
exec("git", ["-c", "user.name=abathur", "-c", "user.email=agent@host.example", "-C", repo, "commit", "-m", message]);
|
|
288
288
|
return headSha(repo);
|
|
289
289
|
}
|
|
290
290
|
function exec(bin, args) {
|