@skathio/somi 4.0.1 → 4.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/.claude/settings.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.copilot-extension/extension.json +1 -1
- package/.copilot-extension/marketplace.json +1 -1
- package/README.md +5 -4
- package/VERSION +1 -1
- package/agents/somi-coder.md +4 -228
- package/agents/somi-designer.md +4 -160
- package/agents/somi-discovery-analyst.md +4 -276
- package/agents/somi-flow.md +47 -0
- package/agents/somi-general.md +36 -0
- package/agents/somi-planner.md +4 -341
- package/agents/somi-reviewer.md +4 -199
- package/agents/somi.md +81 -253
- package/commands/adopt.md +6 -84
- package/commands/architecture-review.md +11 -86
- package/commands/atlas.md +10 -25
- package/commands/code-loop.md +10 -221
- package/commands/code-parallel.md +10 -151
- package/commands/code.md +9 -157
- package/commands/debug.md +9 -131
- package/commands/design.md +9 -160
- package/commands/discover.md +9 -194
- package/commands/impact.md +9 -25
- package/commands/incident.md +9 -39
- package/commands/plan-loop.md +9 -181
- package/commands/plan.md +9 -244
- package/commands/pr.md +10 -25
- package/commands/refactor-design.md +11 -89
- package/commands/refactor.md +11 -50
- package/commands/release-readiness.md +11 -70
- package/commands/review-panel.md +10 -141
- package/commands/review.md +11 -181
- package/commands/security-review.md +11 -75
- package/commands/ship-loop.md +9 -260
- package/commands/ship.md +9 -115
- package/commands/somi-config.md +11 -130
- package/commands/test-strategy.md +11 -75
- package/commands/upgrade.md +9 -72
- package/hooks/hooks.json +1 -1
- package/hooks/lib/common.mjs +8 -5
- package/hooks/pre-tool/block-dangerous-bash.mjs +1 -1
- package/hooks/pre-tool/block-secret-writes.mjs +5 -7
- package/hooks/pre-tool/guard-protected-paths.mjs +54 -34
- package/package.json +1 -1
- package/scripts/lib/cost-defaults.mjs +2 -0
- package/scripts/lib/escalation-facts.mjs +146 -0
- package/scripts/lib/escalation.mjs +129 -0
- package/scripts/lib/findings-ledger.mjs +241 -0
- package/scripts/lib/install-text.mjs +97 -0
- package/scripts/lib/loop-caps.mjs +140 -0
- package/scripts/lib/loop-diff.mjs +12 -70
- package/scripts/lib/loop-engine.mjs +227 -0
- package/scripts/lib/loop-escalate.mjs +49 -0
- package/scripts/lib/loop-exit.mjs +47 -0
- package/scripts/lib/loop-notes-compact.mjs +72 -0
- package/scripts/lib/loop-notes.mjs +282 -0
- package/scripts/lib/loop-review.mjs +355 -12
- package/scripts/lib/loop-state.mjs +44 -0
- package/scripts/lib/loop-step-close.mjs +75 -0
- package/scripts/lib/loop-step-kit.mjs +179 -0
- package/scripts/lib/loop-step-review.mjs +140 -0
- package/scripts/lib/loop-step-tool.mjs +89 -0
- package/scripts/lib/loop-step.mjs +303 -0
- package/scripts/lib/mcp-project-root.mjs +18 -7
- package/scripts/lib/path-facts.mjs +187 -0
- package/scripts/lib/path-safety.mjs +171 -0
- package/scripts/lib/run-card.mjs +73 -0
- package/scripts/size-budget-overrides.json +5 -13
- package/scripts/somi-card.mjs +39 -0
- package/scripts/somi-findings.mjs +56 -271
- package/scripts/somi-loop.mjs +84 -443
- package/scripts/somi-mcp.mjs +26 -95
- package/scripts/validate.sh +75 -57
- package/skills/flow-adopt/SKILL.md +92 -0
- package/skills/flow-architecture-review/SKILL.md +94 -0
- package/skills/flow-atlas/SKILL.md +34 -0
- package/skills/flow-code/SKILL.md +167 -0
- package/skills/flow-code-loop/SKILL.md +263 -0
- package/skills/flow-code-parallel/SKILL.md +160 -0
- package/skills/flow-debug/SKILL.md +141 -0
- package/skills/flow-design/SKILL.md +170 -0
- package/skills/flow-discover/SKILL.md +204 -0
- package/skills/flow-impact/SKILL.md +35 -0
- package/skills/flow-incident/SKILL.md +49 -0
- package/skills/flow-plan/SKILL.md +254 -0
- package/skills/flow-plan-loop/SKILL.md +254 -0
- package/skills/flow-pr/SKILL.md +34 -0
- package/skills/flow-refactor/SKILL.md +58 -0
- package/skills/flow-refactor-design/SKILL.md +97 -0
- package/skills/flow-release-readiness/SKILL.md +82 -0
- package/skills/flow-review/SKILL.md +193 -0
- package/skills/flow-review-panel/SKILL.md +154 -0
- package/skills/flow-security-review/SKILL.md +83 -0
- package/skills/flow-ship/SKILL.md +125 -0
- package/skills/flow-ship-loop/SKILL.md +274 -0
- package/skills/flow-somi-config/SKILL.md +142 -0
- package/skills/flow-status/SKILL.md +43 -0
- package/skills/flow-test-strategy/SKILL.md +83 -0
- package/skills/flow-upgrade/SKILL.md +82 -0
- package/skills/role-coder/SKILL.md +247 -0
- package/skills/role-designer/SKILL.md +172 -0
- package/skills/role-discovery-analyst/SKILL.md +288 -0
- package/skills/role-planner/SKILL.md +353 -0
- package/skills/role-reviewer/SKILL.md +218 -0
- package/skills/somi-checkpoint/SKILL.md +95 -0
- package/skills/somi-dispatch/SKILL.md +14 -14
- package/skills/somi-routing/SKILL.md +6 -2
- package/tests/hooks/cases/block-secret-writes.json +6 -1
- package/tests/hooks/cases/guard-protected-paths.json +44 -2
- package/tests/hooks/run.sh +21 -0
- package/tests/scripts/checkpoint-gate.sh +2 -2
- package/tests/scripts/cost-defaults.sh +2 -0
- package/tests/scripts/dispatch-line-gate.sh +4 -4
- package/tests/scripts/dispatch-reference-gate.sh +14 -14
- package/tests/scripts/escalation.sh +409 -0
- package/tests/scripts/eval-runner.sh +8 -7
- package/tests/scripts/fact-sheet.sh +296 -0
- package/tests/scripts/goldens/somi-loop.json +2 -2
- package/tests/scripts/lib/dispatch-reference-gate.mjs +14 -5
- package/tests/scripts/lib/escalation-facts-tests.mjs +140 -0
- package/tests/scripts/lib/escalation-tests.mjs +154 -0
- package/tests/scripts/lib/findings-ledger-tests.mjs +118 -0
- package/tests/scripts/lib/loop-engine-tests.mjs +287 -0
- package/tests/scripts/lib/loop-escalate-tests.mjs +356 -0
- package/tests/scripts/lib/loop-flow-gate.mjs +173 -0
- package/tests/scripts/lib/loop-notes-tests.mjs +384 -0
- package/tests/scripts/lib/loop-step-cli-tests.mjs +156 -0
- package/tests/scripts/lib/loop-step-close-tests.mjs +351 -0
- package/tests/scripts/lib/loop-step-lenient-tests.mjs +114 -0
- package/tests/scripts/lib/loop-step-state-tests.mjs +127 -0
- package/tests/scripts/lib/loop-step-tests.mjs +499 -0
- package/tests/scripts/lib/loop-step-unwritten-tests.mjs +55 -0
- package/tests/scripts/lib/path-facts-tests.mjs +198 -0
- package/tests/scripts/lib/path-safety-tests.mjs +201 -0
- package/tests/scripts/lib/run-suites.mjs +139 -0
- package/tests/scripts/lib/sizing-score-tests.mjs +210 -0
- package/tests/scripts/lib/sizing-set-tests.mjs +131 -0
- package/tests/scripts/lib/somi-mcp-loop-tests.mjs +226 -0
- package/tests/scripts/lib/somi-mcp-tests.mjs +21 -1
- package/tests/scripts/loop-engine.sh +22 -0
- package/tests/scripts/loop-flow-gate.sh +11 -0
- package/tests/scripts/review-panel-seats.sh +4 -4
- package/tests/scripts/run-card.sh +57 -0
- package/tests/scripts/run-suites.sh +74 -0
- package/tests/scripts/run.sh +11 -0
- package/tests/scripts/size-tier.sh +3 -3
- package/tests/scripts/somi-agent-dispatch-contract.sh +23 -3
- package/tests/scripts/somi-mcp.sh +1 -0
- package/tests/scripts/suite-plan.json +20 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Tests of the composite loop steps open, after-code and status (scripts/lib/loop-step.mjs), in throwaway git repos:
|
|
3
|
+
// validation, parity with the primitive subcommands, replay and kill-and-replay, tighten-only caps, write confinement, the size budget.
|
|
4
|
+
// Run by tests/scripts/loop-engine.sh.
|
|
5
|
+
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { execFileSync } from 'node:child_process';
|
|
8
|
+
import { chmodSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
13
|
+
import { BUDGET, runStep } from '../../../scripts/lib/loop-step.mjs';
|
|
14
|
+
import { checkDiff, init, pass as passPrim, recordPass, reviewScope } from '../../../scripts/lib/loop-engine.mjs';
|
|
15
|
+
import { recordFindings } from '../../../scripts/lib/findings-ledger.mjs';
|
|
16
|
+
import { stateFile } from '../../../scripts/lib/loop-state.mjs';
|
|
17
|
+
import { markIteration, STATUSES } from '../../../scripts/lib/loop-notes.mjs';
|
|
18
|
+
|
|
19
|
+
const SOMI = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
|
|
20
|
+
let pass = 0; let fail = 0;
|
|
21
|
+
const check = (name, got, want) => {
|
|
22
|
+
if (isDeepStrictEqual(got, want)) { pass++; console.log(` ok ${name}`); } else { fail++; console.log(` FAIL ${name} (want ${JSON.stringify(want)}, got ${JSON.stringify(got)})`); }
|
|
23
|
+
};
|
|
24
|
+
const tmp = mkdtempSync(path.join(tmpdir(), 'loop-step-'));
|
|
25
|
+
process.on('exit', () => rmSync(tmp, { recursive: true, force: true }));
|
|
26
|
+
|
|
27
|
+
const NOW = '2026-10-29T09:30:00Z';
|
|
28
|
+
const ROWS = '# Progress — p1\n\n## Iteration progress\n\n| Iteration | Title | Status | Reviewed | Last activity |\n|---|---|---|---|---|\n| 1.1 | one | not-started | — | — |\n| 2.2 | two | not-started | — | — |\n';
|
|
29
|
+
const DIARY = '# Diary — p1\n\n> Spec: x\n\n---\n\n## 2026-10-28 10:00 — Plan\n\n**Category**: `note`\n**Phase**: 1\n\nbody\n\n---\n\n';
|
|
30
|
+
let n = 0;
|
|
31
|
+
// A repo with a.js and b.js committed and two plan directories (p1 for code loops, pl for plan loops).
|
|
32
|
+
function repo() {
|
|
33
|
+
const root = path.join(tmp, `r${n++}`); mkdirSync(root);
|
|
34
|
+
const git = (...a) => execFileSync('git', ['-C', root, '-c', 'user.name=t', '-c', 'user.email=t@t', ...a], { encoding: 'utf8' });
|
|
35
|
+
git('init', '-q'); writeFileSync(path.join(root, 'a.js'), '1\n'); writeFileSync(path.join(root, 'b.js'), '1\n'); git('add', 'a.js', 'b.js'); git('commit', '-q', '-m', 'base');
|
|
36
|
+
for (const slug of ['p1', 'pl']) { mkdirSync(path.join(root, '.somi', 'plans', slug, 'phases'), { recursive: true }); writeFileSync(path.join(root, '.somi', 'plans', slug, 'diary.md'), DIARY); writeFileSync(path.join(root, '.somi', 'plans', slug, 'progress.md'), ROWS); }
|
|
37
|
+
const ctx = (env = {}, o = {}) => ({ root, env: { SOMI_GLOBAL_CONFIG: '', ...env }, stateDir: path.join(root, '.somi', 'somi-state', 'loop'), installRoot: SOMI, now: () => NOW, via: 'mcp', ...o });
|
|
38
|
+
return { root, ctx, diary: () => readFileSync(path.join(root, '.somi', 'plans', 'p1', 'diary.md'), 'utf8'), state: (slug = 'p1', it = '1.1') => JSON.parse(readFileSync(stateFile(ctx().stateDir, slug, it), 'utf8')), file: (f, text) => writeFileSync(path.join(root, f), text) };
|
|
39
|
+
}
|
|
40
|
+
const run = (r, args, env, o) => runStep(r.ctx(env, o), { slug: 'p1', iteration: '1.1', ...args });
|
|
41
|
+
const open = (r, args = {}, env, o) => run(r, { step: 'open', files: 'a.js', ...args }, env, o);
|
|
42
|
+
const after = (r, args = {}, env, o) => run(r, { step: 'after-code', agent: 'somi-coder', ...args }, env, o);
|
|
43
|
+
const status = (r, args = {}) => runStep(r.ctx(), { step: 'status', slug: 'p1', iteration: '1.1', ...args });
|
|
44
|
+
const entries = (r) => r.diary().split('\n').filter((l) => l.startsWith('## ')).length;
|
|
45
|
+
// Every file under the repo (the .git directory aside) with its hash: the "nothing was written" oracle.
|
|
46
|
+
const tree = (root) => Object.fromEntries(readdirSync(root, { recursive: true }).filter((f) => !f.startsWith('.git')).sort().map((f) => [f, lstatSync(path.join(root, f)).isFile() ? createHash('sha256').update(readFileSync(path.join(root, f))).digest('hex') : 'dir']));
|
|
47
|
+
const prim = { slug: 'p1', loop: 'code', iteration: '1.1', files: 'a.js', force: false, status: '', maxPasses: '', diffCap: '', severity: '', maxMinutes: '', verdict: '', blockers: '0', majors: '0', agent: '' };
|
|
48
|
+
const dies = (fn) => { try { fn(); } catch (e) { return e.message; } return 'no throw'; };
|
|
49
|
+
const bytes = (r) => Buffer.byteLength(JSON.stringify(r));
|
|
50
|
+
|
|
51
|
+
console.log('== the engine reads no environment and no clock ==');
|
|
52
|
+
{
|
|
53
|
+
const code = readFileSync(path.join(SOMI, 'scripts', 'lib', 'loop-step.mjs'), 'utf8').split('\n').filter((l) => !l.trimStart().startsWith('//')).join('\n');
|
|
54
|
+
check('loop-step.mjs names neither process, globalThis, Date.now nor new Date outside comments', /\b(process|globalThis)\b|Date\.now|new Date/.test(code), false);
|
|
55
|
+
process.env.SOMI_CODE_LOOP_MAX_PASSES = '9';
|
|
56
|
+
const r = repo(); const o = open(r);
|
|
57
|
+
delete process.env.SOMI_CODE_LOOP_MAX_PASSES;
|
|
58
|
+
check('a sentinel in process.env is ignored; the env handed in counts (cap 5 from ctx.env)', [o.caps.max_passes, open(repo(), {}, { SOMI_CODE_LOOP_MAX_PASSES: '5' }).caps.max_passes], [3, 5]);
|
|
59
|
+
}
|
|
60
|
+
console.log('== validation: refused with 64 naming the field, before any path or write ==');
|
|
61
|
+
{
|
|
62
|
+
const r = repo(); const before = tree(r.root);
|
|
63
|
+
const cases = [
|
|
64
|
+
['slug', { step: 'open', slug: '../x' }], ['slug', { step: 'open', slug: 'a/b' }], ['iteration', { step: 'open', iteration: '../1.1' }], ['iteration', { step: 'open', iteration: '1.1/../x' }],
|
|
65
|
+
['iteration', { step: 'open', iteration: '1.1.1' }], ['iteration', { step: 'open', iteration: `1.${'9'.repeat(300)}` }], ...['/etc/x', '-rf', '~/x', 'a/../b', 'a\\b', '..', 'a.js,b.js'].map((f) => ['files', { step: 'open', files: [f] }]), ['iteration', { step: 'open', iteration: undefined }], ['iteration', { step: 'open', loop: 'plan', slug: 'pl' }],
|
|
66
|
+
['verdict', { step: 'open', verdict: 'approve' }], ['agent', { step: 'open', agent: 'somi-coder' }], ['review_mode', { step: 'open', review_mode: 'panel' }],
|
|
67
|
+
['diff_cap', { step: 'open', loop: 'plan', slug: 'pl', iteration: undefined, diff_cap: 5 }], ['loop', { step: 'open', loop: 'x' }],
|
|
68
|
+
['max_passes', { step: 'open', max_passes: '1,0' }], ['max_passes', { step: 'open', max_passes: -1 }], ['diff_cap', { step: 'open', diff_cap: 1.5 }], ['files', { step: 'open', files: ['a\n.js'] }],
|
|
69
|
+
['review_scope', { step: 'open', review_scope: 'x' }], ['host', { step: 'open', host: 'vim' }], ['step', { step: 'nope' }], ['status', { step: 'close' }], ['reviewers', { step: 'after-review' }],
|
|
70
|
+
['agent', { step: 'after-code' }], ['agent', { step: 'after-code', agent: '../evil' }], ['review_scope', { step: 'after-code', agent: 'somi-coder', review_scope: 'x' }], ['review_mode', { step: 'after-code', agent: 'somi-coder', review_mode: 'loud' }],
|
|
71
|
+
['review_mode', { step: 'after-code', loop: 'plan', slug: 'pl', iteration: undefined, agent: 'somi-planner', review_mode: 'panel' }], ['diff_cap', { step: 'after-code', loop: 'plan', slug: 'pl', iteration: undefined, agent: 'somi-planner', diff_cap: 5 }],
|
|
72
|
+
['iteration', { step: 'after-code', agent: 'somi-coder', iteration: '1.1/../x' }], ['slug', { step: 'status', slug: 'a/b' }], ['iteration', { step: 'status', iteration: '1.1.1' }], ['files', { step: 'status', files: 'a.js' }], ['agent', { step: 'status', agent: 'somi-coder' }],
|
|
73
|
+
];
|
|
74
|
+
const got = cases.map(([f, a]) => { const x = runStep(r.ctx(), { slug: 'p1', iteration: '1.1', ...a }); return [x.exit, x.error.startsWith(`${f}:`)]; });
|
|
75
|
+
check('every bad slug, iteration, foreign field, enum and cap shape exits 64 and names its field', got, cases.map(() => [64, true]));
|
|
76
|
+
check('none of them wrote anything: the repo tree is byte-identical', tree(r.root), before);
|
|
77
|
+
check('a missing files list is refused when a code loop starts, and open then creates no state file', [open(r, { files: undefined }).error, existsSync(path.join(r.root, '.somi', 'somi-state'))], ['files: required to start a code loop', false]);
|
|
78
|
+
const bo = repo(); mkdirSync(path.join(bo.root, '.somi', 'plans', 'bo')); bo.file('.somi/plans/bo/progress.md', ROWS);
|
|
79
|
+
const briefOnly = runStep(bo.ctx(), { step: 'open', slug: 'bo', iteration: '1.1', files: 'a.js' });
|
|
80
|
+
check('a brief-only slug without the tier record is refused 64 and no state file appears', [briefOnly.exit, briefOnly.error.includes('brief-only'), existsSync(path.join(bo.root, '.somi', 'somi-state', 'loop', 'bo.1.1.json'))], [64, true, false]);
|
|
81
|
+
}
|
|
82
|
+
console.log('== open ==');
|
|
83
|
+
{
|
|
84
|
+
const r = repo();
|
|
85
|
+
const o = open(r);
|
|
86
|
+
const s = r.state();
|
|
87
|
+
check('open on a fresh slug starts the loop at pass 1 and asks for the coder; the brief is the card verbatim', [o.ok, o.exit, o.pass, o.next, o.stop_reason, o.replayed, o.brief.startsWith('```somi-card\n'), o.brief.includes('files in scope: a.js')], [true, 0, 1, 'task-coder', null, false, true, true]);
|
|
88
|
+
check('the state holds pass 1, no history, and the cursor with its via, stored time and sub-steps', [s.pass, s.history, s.steps['1:open'].via, s.steps['1:open'].at, s.steps['1:open'].done], [1, [], 'mcp', NOW, ['pass', 'diary', 'row']]);
|
|
89
|
+
check('the diary gained exactly one started entry, built from stored state, and the response lists the write', [entries(r), r.diary().includes('— code-loop started for iteration 1.1\n'), r.diary().includes('max_passes 3, diff_cap_lines 400, severity_floor Major; files in scope: 1'), o.wrote], [2, true, true, ['.somi/plans/p1/diary.md', '.somi/plans/p1/progress.md']]);
|
|
90
|
+
const again = open(r);
|
|
91
|
+
check('open twice returns the same pass with replayed: true, history unchanged, still one diary entry', [again.pass, again.replayed, again.brief, r.state().history, entries(r)], [1, true, o.brief, [], 2]);
|
|
92
|
+
const lost = r.state(); delete lost.steps['1:open'].response; lost.steps['1:open'].done = ['pass'];
|
|
93
|
+
writeFileSync(stateFile(r.ctx().stateDir, 'p1', '1.1'), JSON.stringify(lost));
|
|
94
|
+
const redo = open(r);
|
|
95
|
+
check('a retry that lost its marker after the writer ran re-sends a byte-identical entry and the writer drops it: one entry', [redo.replayed, redo.pass, entries(r)], [false, 1, 2]);
|
|
96
|
+
const dc = repo(); init(dc.ctx(), prim); const sfd = stateFile(dc.ctx().stateDir, 'p1', '1.1');
|
|
97
|
+
const hold = (text) => { rmSync(sfd, { force: true }); if (text) writeFileSync(sfd, text); else symlinkSync('gone', sfd);
|
|
98
|
+
const t = tree(dc.root); const x = open(dc); return [x.exit, x.stop_reason, x.next, isDeepStrictEqual(tree(dc.root), t), /CLI/.test(x.error) && !/node |scripts\/|--/.test(x.error)]; };
|
|
99
|
+
check('open refuses a finished or a corrupt state (64, ask-user, no command line in the text) or a dangling link and the tree, state file included, is byte-identical', [hold(JSON.stringify({ ...dc.state(), status: 'approved' })), hold('{ not json'), hold()], [[64, 'no-running-loop', 'ask-user', true, true], [64, 'no-running-loop', 'ask-user', true, true], [64, 'no-running-loop', 'ask-user', true, true]]);
|
|
100
|
+
const gr = repo(); open(gr, { iteration: '2.2', max_passes: 1 }); recordPass(gr.ctx(), { ...prim, iteration: '2.2', verdict: 'needs-changes', blockers: '0', majors: '1' }); const gb = tree(gr.root); const nope = (a) => { const x = runStep(gr.ctx(), { step: 'open', slug: 'p1', iteration: '2.2', files: 'a.js', ...a }); return [x.exit, x.stop_reason]; };
|
|
101
|
+
check('after 2.2 hit its cap, open for an undeclared 2.2c, a non-canonical 2.02 or 02.2, and an unplanned slug each refuse and the tree is byte-identical', [[nope({ iteration: '2.2c' }), nope({ iteration: '2.02' }), nope({ iteration: '02.2' }), nope({ slug: 'zz' })], tree(gr.root)], [[[64, 'not-declared'], [64, null], [64, null], [64, 'not-declared']], gb]);
|
|
102
|
+
gr.file('.somi/plans/p1/progress.md', `${ROWS}| 2.2c | split | not-started | — | — |\n`);
|
|
103
|
+
check('a declared 2.2c row lets the split start a fresh state (the legitimate path)', [nope({ iteration: '2.2c' })[0], existsSync(stateFile(gr.ctx().stateDir, 'p1', '2.2c'))], [0, true]);
|
|
104
|
+
const big = repo(); const huge = Array.from({ length: 20 }, (_, i) => `${i}${'x'.repeat(150)}.js`); const hg = open(big, { files: huge });
|
|
105
|
+
check('an oversized files list is clipped, not refused: open starts, the brief says how many are not listed, and the state keeps all twenty', [hg.ok, /\(\d+ more files in scope/.test(hg.brief), bytes(hg) <= BUDGET, big.state().iteration_files.length], [true, true, true, 20]);
|
|
106
|
+
const planOpen = runStep(r.ctx(), { step: 'open', slug: 'pl', loop: 'plan' });
|
|
107
|
+
check('a plan loop has no card and no diff cap and asks for the planner', [planOpen.next, planOpen.brief, planOpen.caps.diff_cap_lines, planOpen.pass], ['task-planner', '', 0, 1]);
|
|
108
|
+
}
|
|
109
|
+
{
|
|
110
|
+
const r = repo();
|
|
111
|
+
init(r.ctx(), prim); passPrim(r.ctx(), prim);
|
|
112
|
+
check('open on a state the CLI pass primitive left at pass 1 returns pass 1, not 2', [open(r).pass, r.state().pass], [1, 1]);
|
|
113
|
+
recordPass(r.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
114
|
+
check('once the pass is recorded the next open counts pass 2 (and resumes: no after-review cursor, so a resumed entry)', [open(r).pass, r.diary().includes('— code-loop resumed from pass 1\n')], [2, true]);
|
|
115
|
+
}
|
|
116
|
+
{
|
|
117
|
+
const r = repo(); open(r, { max_passes: 1 });
|
|
118
|
+
recordPass(r.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
119
|
+
const s = r.state();
|
|
120
|
+
const x = open(r);
|
|
121
|
+
check('max_passes 1 at start is accepted and recorded as a tool override; pass 2 is then max-passes-exceeded (exit 2) with the CLI command to re-run', [s.caps.max_passes, s.cap_overrides.map((c) => [c.field, c.from, c.to, c.source]), x.ok, x.exit, x.stop_reason, x.next, x.cli, r.state().pass], [1, [['max_passes', 3, 1, 'tool']], false, 2, 'max-passes-exceeded', 'close', 'node scripts/somi-loop.mjs pass --slug p1 --iteration 1.1 --max-passes <N>', 1]);
|
|
122
|
+
const t = repo(); open(t);
|
|
123
|
+
mkdirSync(path.join(t.root, '.somi', 'somi-state', 'run'), { recursive: true });
|
|
124
|
+
writeFileSync(path.join(t.root, '.somi', 'somi-state', 'run', 'p1.json'), JSON.stringify({ started: '2026-10-29T08:00:00Z', max_minutes: 5 }));
|
|
125
|
+
recordPass(t.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
126
|
+
const late = open(t);
|
|
127
|
+
check('a spent run budget stops at open with exit 4, judged on the injected clock, and counts no pass', [late.exit, late.stop_reason, late.next, late.pass, t.state().pass], [4, 'time-budget', 'close', 1, 1]);
|
|
128
|
+
}
|
|
129
|
+
console.log('== tighten-only caps ==');
|
|
130
|
+
{
|
|
131
|
+
const r = repo(); open(r);
|
|
132
|
+
const before = [readFileSync(stateFile(r.ctx().stateDir, 'p1', '1.1'), 'utf8'), tree(r.root)];
|
|
133
|
+
const up = [open(r, { max_passes: 9 }), open(r, { diff_cap: 999 }), open(r, { diff_cap: 0 })];
|
|
134
|
+
check('max_passes 9 against a stored 3, diff_cap 999 against 400 and diff_cap 0 (off) against 400 are refused 64 and the state file and tree are byte-identical', [up.map((x) => [x.exit, x.error.split(':')[0]]), [readFileSync(stateFile(r.ctx().stateDir, 'p1', '1.1'), 'utf8'), tree(r.root)]], [[[64, 'max_passes'], [64, 'diff_cap'], [64, 'diff_cap']], before]);
|
|
135
|
+
const fresh = repo(); const fb = tree(fresh.root);
|
|
136
|
+
check('a cap argument above what init would resolve is refused before init writes a state file', [open(fresh, { max_passes: 4 }).exit, tree(fresh.root)], [64, fb]);
|
|
137
|
+
const low = repo(); const l = open(low, { diff_cap: 1 });
|
|
138
|
+
check('diff_cap below the cap in force is applied at start and recorded with source tool', [l.exit, low.state().caps.diff_cap_lines, low.state().cap_overrides.map((c) => [c.field, c.from, c.to, c.source, c.after_pass])], [0, 1, [['diff_cap_lines', 400, 1, 'tool', 0]]]);
|
|
139
|
+
check('a later call that tries to loosen it again is refused', open(low, { diff_cap: 2 }).exit, 64);
|
|
140
|
+
}
|
|
141
|
+
console.log('== kill and replay ==');
|
|
142
|
+
{
|
|
143
|
+
const o = repo();
|
|
144
|
+
const k1 = dies(() => open(o, {}, {}, { failAfter: 'pass' })); const k2 = dies(() => open(o, {}, {}, { failAfter: 'diary' }));
|
|
145
|
+
const done = open(o);
|
|
146
|
+
const w = repo(); rmSync(path.join(w.root, '.somi', 'plans', 'p1', 'diary.md')); dies(() => open(w, {}, {}, { failAfter: 'diary' }));
|
|
147
|
+
check('a step killed after a diary that could not be written reports the unwritten item when retried', open(w).unwritten.map((u) => [u.file, u.reason]), [['diary.md', 'missing']]);
|
|
148
|
+
check('open killed after pass, then after diary, then replayed: pass 1, no history, one diary entry', [k1, k2, done.pass, done.ok, o.state().history, entries(o)], ['failAfter pass', 'failAfter diary', 1, true, [], 2]);
|
|
149
|
+
}
|
|
150
|
+
console.log('== writers: their unwritten lines surface and never crash a step ==');
|
|
151
|
+
{
|
|
152
|
+
const r = repo(); rmSync(path.join(r.root, '.somi', 'plans', 'p1', 'diary.md'));
|
|
153
|
+
const o = open(r);
|
|
154
|
+
check('a diary that is missing leaves the step complete with the entry text in unwritten', [o.ok, o.pass, o.wrote, o.unwritten.map((u) => [u.file, u.reason, u.line.includes('code-loop started')])], [true, 1, ['.somi/plans/p1/progress.md'], [['diary.md', 'missing', true]]]);
|
|
155
|
+
if (typeof process.getuid === 'function' && process.getuid() !== 0) {
|
|
156
|
+
const w = repo(); chmodSync(path.join(w.root, '.somi', 'plans', 'p1'), 0o555);
|
|
157
|
+
const x = open(w); chmodSync(path.join(w.root, '.somi', 'plans', 'p1'), 0o755);
|
|
158
|
+
check('an unwritable plan directory: write-failed in unwritten, the step still returns', [x.ok, x.unwritten.map((u) => [u.file, u.reason])], [true, [['diary.md', 'write-failed'], ['progress.md', 'write-failed']]]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
console.log('== after-code ==');
|
|
162
|
+
{
|
|
163
|
+
const a = repo(); const b = repo();
|
|
164
|
+
open(a); init(b.ctx(), prim); passPrim(b.ctx(), prim);
|
|
165
|
+
for (const x of [a, b]) { x.file('a.js', '1\n2\n3\n'); x.file('c.js', '1\n'); }
|
|
166
|
+
const s = after(a, {}, {});
|
|
167
|
+
const p = checkDiff(b.ctx(), prim).out; const sc = reviewScope(b.ctx(), prim).out;
|
|
168
|
+
check('open then after-code gives the same pass, diff_lines, weighted_lines, out_of_scope and scope as pass, check-diff, review-scope on a copy', [s.pass, s.diff, s.scope], [1, { diff_lines: p.diff_lines, weighted_lines: p.weighted_lines, cap: 400, out_of_scope: p.out_of_scope }, sc]);
|
|
169
|
+
check('it asks for the single reviewer, repeats the full scope in a brief, and records the dispatch of the agent that ran', [s.next, s.review_mode, s.review_brief.startsWith("Review this iteration's whole diff"), a.state().dispatches.map((d) => [d.agent, d.pass])], ['task-reviewer', 'single', true, [['somi-coder', 1]]]);
|
|
170
|
+
const rp = [after(a, { review_mode: 'panel' }), after(a, { review_scope: 'full' })].map((x) => [x.exit, x.next]);
|
|
171
|
+
check('a repeated after-code that asks for a stronger review_mode or review_scope than the first call is honoured, never refused (weak then panel is task-panel); the same call again is measured afresh, not replayed; one dispatch', [rp, after(a).replayed, a.state().dispatches.length], [[[0, 'task-panel'], [0, 'task-panel']], false, 1]);
|
|
172
|
+
check('an after-code that is not preceded by an open (no state, or a pass already recorded) is refused 64', [after(repo()).exit, (() => { recordPass(a.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' }); return after(a, { agent: 'somi-planner' }).exit; })()], [64, 64]);
|
|
173
|
+
}
|
|
174
|
+
{
|
|
175
|
+
const r = repo(); open(r, {}, { SOMI_CODE_LOOP_DIFF_CAP: '3' });
|
|
176
|
+
r.file('a.js', '1\n2\n'); r.file('c.js', '1\n2\n');
|
|
177
|
+
const x = after(r);
|
|
178
|
+
check('an out-of-scope file doubles (weighted 5 > cap 3 while total is 3) and stops with scope-expansion naming it, exit 3, and the CLI command', [x.ok, x.exit, x.stop_reason, x.next, x.diff, x.cli], [false, 3, 'scope-expansion', 'close', { diff_lines: 3, weighted_lines: 5, cap: 3, out_of_scope: ['c.js'] }, 'node scripts/somi-loop.mjs check-diff --slug p1 --iteration 1.1 --diff-cap <N>']);
|
|
179
|
+
rmSync(path.join(r.root, 'c.js')); r.file('a.js', '1\n2\n3\n4\n5\n');
|
|
180
|
+
const y = after(r);
|
|
181
|
+
check('in-scope lines over the cap are diff-cap-exceeded; repeated stops record the dispatch once and store no response', [y.exit, y.stop_reason, after(r).exit, r.state().dispatches.length, 'response' in r.state().steps['1:after-code']], [3, 'diff-cap-exceeded', 3, 1, false]);
|
|
182
|
+
const z = after(r, {}, { SOMI_CODE_LOOP_DIFF_CAP: '100' });
|
|
183
|
+
check('a cap raised through the env afterwards lets the same step through (the stop was not cached) and is recorded with source env', [z.exit, r.state().cap_overrides.map((c) => c.source)], [0, ['env']]);
|
|
184
|
+
const c = repo(); open(c, {}, { SOMI_CODE_LOOP_DIFF_CAP: '3' }); c.file('a.js', '1\n2\n3\n4\n5\n'); after(c);
|
|
185
|
+
checkDiff(c.ctx(), { ...prim, diffCap: '100' });
|
|
186
|
+
check('a cap raised through the CLI after a gate stop takes effect on the next after-code', [after(c).exit, c.state().cap_overrides.map((o) => o.source), c.state().dispatches.length], [0, ['cli'], 1]);
|
|
187
|
+
const g = repo(); open(g, { max_passes: 1 }); recordPass(g.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
188
|
+
const stopped = open(g); passPrim(g.ctx(), { ...prim, maxPasses: '5' }); const next = open(g);
|
|
189
|
+
check('a pass cap raised through the CLI after max-passes-exceeded takes effect on the next open (pass 2, not replayed)', [stopped.exit, next.ok, next.pass, next.replayed, next.caps.max_passes], [2, true, 2, false, 5]);
|
|
190
|
+
}
|
|
191
|
+
{
|
|
192
|
+
const o = repo(); const z = repo(); const big = '1\n'.repeat(10);
|
|
193
|
+
open(o, {}, { SOMI_CODE_LOOP_DIFF_CAP: '0' }); o.file('a.js', big);
|
|
194
|
+
open(z, {}, { SOMI_CODE_LOOP_DIFF_CAP: '0' }); z.file('a.js', big);
|
|
195
|
+
const off = after(o); const tight = after(z, { diff_cap: 5 });
|
|
196
|
+
check('a stored diff_cap 0 is the gate off (a 10-line diff passes, cap 0 shown); a diff_cap argument tightens it, is recorded as a tool override from 0, and then gates', [off.exit, off.diff.cap, tight.exit, tight.stop_reason, z.state().caps.diff_cap_lines, z.state().cap_overrides.map((c) => [c.from, c.to, c.source])], [0, 0, 3, 'diff-cap-exceeded', 5, [[0, 5, 'tool']]]);
|
|
197
|
+
}
|
|
198
|
+
{
|
|
199
|
+
const r = repo(); open(r);
|
|
200
|
+
const un = after(r, { agent: 'no-such-agent' });
|
|
201
|
+
check('an agent the resolver refuses exits 65 and records no dispatch and no cursor', [un.exit, r.state().dispatches, Object.keys(r.state().steps)], [65, undefined, ['1:open']]);
|
|
202
|
+
const sec = after(r, { review_mode: 'panel' }, { SOMI_CODE_LOOP_REVIEW: 'security' });
|
|
203
|
+
const w = repo(); open(w); const weak = after(w, { review_mode: 'single' }, { SOMI_CODE_LOOP_REVIEW: 'security' });
|
|
204
|
+
const lens = repo(); open(lens); writeFileSync(stateFile(lens.ctx().stateDir, 'p1', '1.1'), JSON.stringify({ ...lens.state(), review_min: 'security' }));
|
|
205
|
+
check('review_mode: the argument strengthens (security -> panel), never weakens (single is ignored under security), and the sizing record\'s review_min is a floor too', [sec.review_mode, sec.next, weak.review_mode, weak.next, after(lens, { review_mode: 'single' }).review_mode], ['panel', 'task-panel', 'security', 'task-reviewers', 'security']);
|
|
206
|
+
const bad = repo(); open(bad);
|
|
207
|
+
check('a malformed review setting is refused 64 before the dispatch is recorded', [after(bad, {}, { SOMI_CODE_LOOP_REVIEW: 'loud' }).exit, after(bad, {}, { SOMI_CODE_LOOP_REVIEW_SCOPE: 'wide' }).exit, bad.state().dispatches], [64, 64, undefined]);
|
|
208
|
+
const p = runStep(r.ctx(), { step: 'open', slug: 'pl', loop: 'plan' });
|
|
209
|
+
const pa = runStep(r.ctx(), { step: 'after-code', slug: 'pl', loop: 'plan', agent: 'somi-planner' });
|
|
210
|
+
check('a plan loop records the planner and asks for the reviewer, with no diff or scope', [p.ok, pa.ok, pa.next, pa.diff, pa.scope, r.state('pl', '').dispatches.map((d) => d.agent)], [true, true, 'task-reviewer', undefined, undefined, ['somi-planner']]);
|
|
211
|
+
writeFileSync(stateFile(r.ctx().stateDir, 'p1', '1.1'), JSON.stringify({ ...r.state(), loop: 'plan' }));
|
|
212
|
+
check('a state whose loop disagrees with the one asked for is refused 64 naming loop, by after-code and by status', [after(r).error.split(':')[0], status(r).error.split(':')[0]], ['loop', 'loop']);
|
|
213
|
+
}
|
|
214
|
+
{
|
|
215
|
+
const r = repo(); open(r);
|
|
216
|
+
recordPass(r.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
217
|
+
open(r); r.file('a.js', '1\n2\n');
|
|
218
|
+
const d = after(r);
|
|
219
|
+
check('from pass 2 the scope is the delta since the reviewed tree and the brief names it; review_scope full makes it whole', [d.scope.scope, d.scope.since_pass, d.scope.files, d.review_brief.includes(`git --no-replace-objects diff --text ${d.scope.from} ${d.scope.to}`)], ['delta', 1, ['a.js'], true]);
|
|
220
|
+
const f = repo(); open(f); recordPass(f.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' }); open(f);
|
|
221
|
+
check('review_scope full on pass 2 is the whole iteration, why: setting', [after(f, { review_scope: 'full' }).scope], [{ scope: 'full', why: 'setting' }]);
|
|
222
|
+
}
|
|
223
|
+
{
|
|
224
|
+
const r = repo(); const P = { ...prim, slug: 'pl', loop: 'plan', iteration: '', files: '' }; const planStep = (step, extra = {}) => runStep(r.ctx(), { step, slug: 'pl', loop: 'plan', ...extra });
|
|
225
|
+
planStep('open'); planStep('after-code', { agent: 'somi-planner' });
|
|
226
|
+
recordPass(r.ctx(), { ...P, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
227
|
+
const two = planStep('open'); const twoAfter = planStep('after-code', { agent: 'somi-planner' });
|
|
228
|
+
check('a plan loop runs a second pass through the steps: open counts pass 2 (a resumed diary entry, no card), after-code records the planner for pass 2 and asks for the reviewer', [two.ok, two.pass, two.next, two.brief, twoAfter.ok, twoAfter.pass, twoAfter.next, r.state('pl', '').dispatches.map((d) => d.pass), readFileSync(path.join(r.root, '.somi', 'plans', 'pl', 'diary.md'), 'utf8').includes('— plan-loop resumed from pass 1\n')], [true, 2, 'task-planner', '', true, 2, 'task-reviewer', [1, 2], true]);
|
|
229
|
+
}
|
|
230
|
+
console.log('== after-code is measured afresh on every call ==');
|
|
231
|
+
{
|
|
232
|
+
const r = repo(); open(r); const early = after(r);
|
|
233
|
+
check('an after-code before any change outside .somi runs the gate and says changed: false', [early.exit, early.changed, early.note.includes('re-checks the open findings')], [0, false, true]);
|
|
234
|
+
r.file('a.js', '1\n2\n'); const small = after(r);
|
|
235
|
+
r.file('a.js', 'x\n'.repeat(5000)); r.file('evil.js', 'x\n'.repeat(5000)); const huge = after(r);
|
|
236
|
+
check('a passed after-code is not replayed: a later 5000-line out-of-scope change stops at exit 3, and the dispatch stays one', [small.exit, small.changed, huge.exit, huge.stop_reason, huge.replayed, r.state().dispatches.length], [0, true, 3, 'scope-expansion', false, 1]);
|
|
237
|
+
const p = repo(); open(p); p.file('a.js', '1\n2\n'); after(p); recordPass(p.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' }); open(p);
|
|
238
|
+
p.file('b.js', '2\n'); const one = after(p); p.file('late.js', '1\n'); const two = after(p);
|
|
239
|
+
check('a file that appears after a first after-code is in the delta scope of the next call', [one.scope.files, two.scope.files, two.replayed], [['b.js'], ['b.js', 'late.js'], false]);
|
|
240
|
+
const q = repo(); open(q); recordPass(q.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' }); open(q); q.file('.somi/plans/p1/notes.md', 'resolved\n');
|
|
241
|
+
const led = after(q);
|
|
242
|
+
check('a pass that changed only plan or ledger files passes with changed: false, an empty delta, and a brief that sends the reviewer to the open findings', [led.exit, led.changed, led.scope.files, led.review_brief.includes('re-check each open finding')], [0, false, [], true]);
|
|
243
|
+
const f = repo(); open(f); recordPass(f.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' }); open(f); f.file('a.js', '1\n2\n'); const strong = after(f, { review_mode: 'panel', review_scope: 'full' }); const bare = after(f);
|
|
244
|
+
check('a repeat of the same pass keeps the review lens and the full scope the pass already asked for', [strong.next, bare.next, bare.review_mode, bare.scope.scope], ['task-panel', 'task-panel', 'panel', 'full']);
|
|
245
|
+
}
|
|
246
|
+
console.log('== a repeated step: stored answer, and a cap argument that would still tighten is refused ==');
|
|
247
|
+
{
|
|
248
|
+
const r = repo(); open(r, { max_passes: 2 }); after(r);
|
|
249
|
+
const kept = [readFileSync(stateFile(r.ctx().stateDir, 'p1', '1.1'), 'utf8'), tree(r.root)];
|
|
250
|
+
const same = open(r, { max_passes: 2 });
|
|
251
|
+
const late = [open(r, { max_passes: 1 }), open(r, { diff_cap: 10 })];
|
|
252
|
+
check('the same open again, even a tightening one already applied, is a replay; a new tighter cap on a finished open is refused 64 naming it, and nothing is written', [same.replayed, late.map((x) => [x.exit, x.error?.split(':')[0]]), [readFileSync(stateFile(r.ctx().stateDir, 'p1', '1.1'), 'utf8'), tree(r.root)]], [true, [[64, 'max_passes'], [64, 'diff_cap']], kept]);
|
|
253
|
+
const lag = open(r, { files: 'zz.js', host: 'copilot' });
|
|
254
|
+
check('a replay with other files or host returns the stored answer (the arguments name a new loop only)', [lag.replayed, lag.brief.includes('files in scope: a.js'), lag.brief.includes('host: claude-code')], [true, true, true]);
|
|
255
|
+
}
|
|
256
|
+
console.log('== resuming after each recorded sub-step ==');
|
|
257
|
+
{
|
|
258
|
+
const cases = [['open', 'pass'], ['open', 'diary'], ['after-code', 'dispatch']];
|
|
259
|
+
const got = cases.map(([step, killAt]) => {
|
|
260
|
+
const r = repo(); const go = (o) => (step === 'open' ? open(r, {}, {}, o) : after(r, {}, {}, o));
|
|
261
|
+
if (step === 'after-code') open(r);
|
|
262
|
+
const killed = dies(() => go({ failAfter: killAt }));
|
|
263
|
+
const mid = r.state().steps[`1:${step}`].done;
|
|
264
|
+
const redo = go();
|
|
265
|
+
return [killed, mid.at(-1), redo.ok, redo.replayed, redo.exit, entries(r), (r.state().dispatches ?? []).length];
|
|
266
|
+
});
|
|
267
|
+
check('open killed after pass and after diary, and after-code killed after dispatch, each resume on retry (the cursor naming the sub-step is a usable state) with one diary entry and at most one dispatch', got, [[`failAfter pass`, 'pass', true, false, 0, 2, 0], ['failAfter diary', 'diary', true, false, 0, 2, 0], ['failAfter dispatch', 'dispatch', true, false, 0, 2, 1]]);
|
|
268
|
+
}
|
|
269
|
+
console.log('== the resumed diary entry follows the previous pass\'s cursor ==');
|
|
270
|
+
{
|
|
271
|
+
const viaSteps = repo(); open(viaSteps); after(viaSteps);
|
|
272
|
+
const half = repo(); open(half); after(half);
|
|
273
|
+
const lone = repo(); open(lone);
|
|
274
|
+
const withReview = (x) => { const st = x.state(); st.steps['1:after-review'] = { via: 'mcp', at: NOW, done: [], response: { ok: true, step: 'after-review' } }; writeFileSync(stateFile(x.ctx().stateDir, 'p1', '1.1'), JSON.stringify(st)); };
|
|
275
|
+
withReview(viaSteps); withReview(lone);
|
|
276
|
+
for (const x of [viaSteps, half, lone]) recordPass(x.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
277
|
+
const cli = repo(); init(cli.ctx(), prim); passPrim(cli.ctx(), prim); recordPass(cli.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
278
|
+
check('pass 2 is a "resumed" entry unless pass 1 has both a finished after-code and a finished after-review entry: both is silent; after-code alone, after-review alone and CLI-only each write one', [viaSteps, half, lone, cli].map((x) => [open(x).pass, entries(x), x.diary().includes('— code-loop resumed from pass 1\n')]), [[2, 2, false], [2, 3, true], [2, 3, true], [2, 2, true]]);
|
|
279
|
+
}
|
|
280
|
+
console.log('== status ==');
|
|
281
|
+
{
|
|
282
|
+
const r = repo(); open(r); after(r);
|
|
283
|
+
const b = tree(r.root);
|
|
284
|
+
const s = status(r);
|
|
285
|
+
check('status shows the state, the cursor and open findings, and changes nothing (no ledger seeded)', [s.ok, s.pass, s.state.status, s.cursor.map((c) => [c.key, c.complete]), s.open_findings, tree(r.root)], [true, 1, 'running', [['1:open', true], ['1:after-code', true]], [], b]);
|
|
286
|
+
check('status of a loop that does not exist, or of the other loop kind, is refused 64', [status(r, { iteration: '9.9' }).exit, status(r, { loop: 'plan', iteration: undefined }).exit], [64, 64]);
|
|
287
|
+
const fin = repo(); init(fin.ctx(), prim); writeFileSync(stateFile(fin.ctx().stateDir, 'p1', '1.1'), JSON.stringify({ ...fin.state(), status: 'approved' }));
|
|
288
|
+
const broken = repo(); init(broken.ctx(), prim); writeFileSync(stateFile(broken.ctx().stateDir, 'p1', '1.1'), JSON.stringify({ ...broken.state(), history: null }));
|
|
289
|
+
check('status reads a finished loop, and refuses a state of a broken shape with 64 instead of a TypeError', [status(fin).state?.status, status(broken).exit], ['approved', 64]);
|
|
290
|
+
const led = repo(); open(led);
|
|
291
|
+
recordFindings({ root: led.root, slug: 'p1', review: 'r1.md', run: 'x', pass: 1, input: [{ file: 'a.js', symbol: 's', title: 'minor one', severity: 'Nit', confidence: 'High' }] });
|
|
292
|
+
const file = path.join(led.root, '.somi', 'reviews', 'p1', 'findings.json'); renameSync(file, `${file}.real`); symlinkSync(`${file}.real`, file);
|
|
293
|
+
check('status lists every open finding (a Nit too) and flags a linked ledger as unreadable instead of following it', [status(led).open_findings], [['(the findings ledger is unreadable)']]);
|
|
294
|
+
}
|
|
295
|
+
console.log('== the response budget ==');
|
|
296
|
+
{
|
|
297
|
+
const o = open(repo());
|
|
298
|
+
const typ = repo(); open(typ);
|
|
299
|
+
check('typical open and after-code responses are under 2.5 KB', [bytes(o) <= BUDGET, bytes(after(typ)) <= BUDGET], [true, true]);
|
|
300
|
+
const big = repo(); open(big);
|
|
301
|
+
const input = Array.from({ length: 80 }, (_, i) => ({ file: `src/f${i}.js`, symbol: 's', title: `finding ${i} ${'long '.repeat(40)}`, severity: 'Major', confidence: 'High' }));
|
|
302
|
+
recordFindings({ root: big.root, slug: 'p1', review: 'r1.md', run: 'x', pass: 1, input });
|
|
303
|
+
recordPass(big.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '80' });
|
|
304
|
+
const ob = open(big);
|
|
305
|
+
check('80 open findings with long titles: the open brief is cut to the budget and says how many more', [bytes(ob) <= BUDGET, /\(\+\d+ more/.test(ob.brief), ob.brief.includes('F-1: finding 0 long')], [true, true, true]);
|
|
306
|
+
const st = status(big);
|
|
307
|
+
check('80 open findings: the status list is cut to the budget the same way and says how many more', [bytes(st) <= BUDGET, st.open_findings.at(-1).startsWith('(+')], [true, true]);
|
|
308
|
+
const files = Array.from({ length: 14 }, (_, i) => `src/module-${i}/${'d'.repeat(60)}.js`);
|
|
309
|
+
const wide = repo(); rmSync(path.join(wide.root, '.somi', 'plans', 'p1', 'diary.md'));
|
|
310
|
+
const lw = open(wide, { files }); const longest = Math.max(...lw.unwritten.map((u) => u.line.length));
|
|
311
|
+
check('a run card near its limit with a failed diary write (its entry is long) still fits: the whole response is under 2.5 KB and the unwritten line is cut to a pointer', [lw.ok, lw.brief.length > 1500, lw.unwritten.length, longest <= 120, bytes(lw) <= BUDGET], [true, true, 1, true, true]);
|
|
312
|
+
const cliWide = repo(); init(cliWide.ctx(), { ...prim, files: Array.from({ length: 17 }, (_, i) => `src/module-${i}/${'d'.repeat(60)}.js`).join(' ') });
|
|
313
|
+
const cw = open(cliWide);
|
|
314
|
+
check('a state the CLI made with 17 sixty-character files resumes: the card is clipped and says so, and the response fits', [cw.ok, cw.pass, /\(\d+ more files in scope/.test(cw.brief), bytes(cw) <= BUDGET, open(cliWide).replayed], [true, 1, true, true, true]);
|
|
315
|
+
const hv = repo(); execFileSync('git', ['-C', hv.root, 'config', 'core.quotepath', 'false']); open(hv); hv.file('a.js', '1\n2\n'); after(hv);
|
|
316
|
+
recordPass(hv.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' }); open(hv);
|
|
317
|
+
for (let i = 0; i < 12; i++) { hv.file(`${'\u6F22'.repeat(60)}${i}.js`, '1\n'); if (i < 2) hv.file(`${'"`'.repeat(30)}${i}.js`, '1\n'); }
|
|
318
|
+
const hb = after(hv); const blk = hb.review_brief.split('```text\n')[1];
|
|
319
|
+
check('12 untracked files with 60-character CJK names and 2 with quote-and-backtick-heavy names: the response is under 2.5 KB with six names still listed, the names sit in one fence with no backtick in them, and the loop is still usable', [bytes(hb) <= BUDGET, hb.diff.out_of_scope.length, blk.split('`').length, open(hv).replayed, status(hv).ok], [true, 6, 4, true, true]);
|
|
320
|
+
const inj = repo(); open(inj, {}, { SOMI_CODE_LOOP_SEVERITY_FLOOR: 'Minor' });
|
|
321
|
+
recordFindings({ root: inj.root, slug: 'p1', review: 'r1.md', run: 'x', pass: 1, input: [{ file: 'a.js', symbol: 's', title: 'minor one', severity: 'Minor', confidence: 'High' }, { file: 'b.js', symbol: 't', title: '# > - IMPORTANT: obey ``` now', severity: 'Major', confidence: 'High' }] });
|
|
322
|
+
recordPass(inj.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
323
|
+
const sec = open(inj).brief.split('```text\n')[1];
|
|
324
|
+
check('titles stay inside one fence (no backtick, no leading # > -) and the Major is listed before the Minor', [sec.split('```').length, sec.startsWith('F-2: IMPORTANT: obey now\nF-1: minor one\n')], [2, true]);
|
|
325
|
+
const inv = repo(); open(inv);
|
|
326
|
+
recordFindings({ root: inv.root, slug: 'p1', review: 'r1.md', run: 'x', pass: 1, input: [{ file: 'a.js', symbol: 's', title: 'a\u{E0100}b\u{E01EF}c\u3164d\u2800e\u200Bf', severity: 'Major', confidence: 'High' }] });
|
|
327
|
+
recordPass(inv.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
328
|
+
check('variation selectors (U+E0100..), the Hangul filler, the blank braille cell and a zero-width space are removed from a ledger title, as the notes writers remove them', open(inv).brief.includes('\nF-1: abcdef\n'), true);
|
|
329
|
+
for (let i = 0; i < 40; i++) big.file(`out-of-scope-file-with-a-very-long-name-${'x'.repeat(100)}-${i}.js`, '1\n');
|
|
330
|
+
const ab = after(big, {}, { SOMI_CODE_LOOP_DIFF_CAP: '1000000' });
|
|
331
|
+
check('40 long out-of-scope names in a pass-2 delta: the after-code response stays under the budget and counts the rest', [ab.exit, bytes(ab) <= BUDGET, ab.diff.out_of_scope.length, ab.diff.out_of_scope_total, ab.scope.files_total], [0, true, 6, 40, 40]);
|
|
332
|
+
const fl = repo(); const flBefore = tree(fl.root);
|
|
333
|
+
check('a severity floor outside Blocker|Major|Minor|Nit is refused 64 and a refused init leaves no state directory behind (tree byte-identical)', [open(fl, {}, { SOMI_CODE_LOOP_SEVERITY_FLOOR: 'x' }).exit, tree(fl.root)], [64, flBefore]);
|
|
334
|
+
}
|
|
335
|
+
console.log('== open hardening: declaration table, state shape, floor, ledger confinement ==');
|
|
336
|
+
{
|
|
337
|
+
const P = (r, ...s) => path.join(r.root, '.somi', 'plans', ...s);
|
|
338
|
+
const CLI = '; the user starts a new loop through the CLI';
|
|
339
|
+
const tbl = (...rows) => `# Progress — p1\n\n## Iteration progress\n\n| Iteration | Title | Status | Reviewed | Last activity |\n|---|---|---|---|---|\n${rows.join('\n')}\n`;
|
|
340
|
+
const row = (st) => `| 1.1 | one | ${st} | — | — |`;
|
|
341
|
+
const cases = [ // [name, setup, args, the refusal text]
|
|
342
|
+
['plan dir missing', (r) => rmSync(P(r, 'p1'), { recursive: true }), {}, '.somi/plans/p1 is missing'],
|
|
343
|
+
['plan dir is a link', (r) => { rmSync(P(r, 'p1'), { recursive: true }); symlinkSync(P(r, 'pl'), P(r, 'p1')); }, {}, '.somi/plans/p1 is not a plain directory'],
|
|
344
|
+
['progress.md missing', (r) => rmSync(P(r, 'p1', 'progress.md')), {}, 'progress.md is missing'],
|
|
345
|
+
['progress.md is a link', (r) => { renameSync(P(r, 'p1', 'progress.md'), P(r, 'p1', 'real.md')); symlinkSync('real.md', P(r, 'p1', 'progress.md')); }, {}, 'progress.md is symlink'],
|
|
346
|
+
['progress.md is a directory', (r) => { rmSync(P(r, 'p1', 'progress.md')); mkdirSync(P(r, 'p1', 'progress.md')); }, {}, 'progress.md is not-a-regular-file'],
|
|
347
|
+
['progress.md over 4 MiB', (r) => r.file('.somi/plans/p1/progress.md', `${tbl(row('not-started'))}${' '.repeat((1 << 22) + 1)}`), {}, 'progress.md is too-large'],
|
|
348
|
+
['row outside any table', (r) => r.file('.somi/plans/p1/progress.md', `# Progress — p1\n\n## Notes\n\n${row('not-started')}\n`), {}, 'the Iteration progress table of progress.md is not in the template shape: the "## Iteration progress" heading appears 0 times, not once'],
|
|
349
|
+
['row under another heading', (r) => r.file('.somi/plans/p1/progress.md', `${tbl('| 2.2 | two | not-started | — | — |')}\n## Other\n\n${row('not-started')}\n`), {}, 'iteration 1.1 has no row in the Iteration progress table of progress.md'],
|
|
350
|
+
['row with four cells', (r) => r.file('.somi/plans/p1/progress.md', tbl('| 1.1 | one | not-started | — |')), {}, 'the row of iteration 1.1 in progress.md is not in the template shape'],
|
|
351
|
+
['duplicate rows', (r) => r.file('.somi/plans/p1/progress.md', tbl(row('not-started'), row('not-started'))), {}, 'iteration 1.1 has more than one row in the Iteration progress table of progress.md'],
|
|
352
|
+
['table without the template header', (r) => r.file('.somi/plans/p1/progress.md', `# Progress — p1\n\n## Iteration progress\n\n${row('not-started')}\n`), {}, 'the Iteration progress table of progress.md is not in the template shape: the table header or its separator row is not the template\'s'],
|
|
353
|
+
['empty progress.md', (r) => r.file('.somi/plans/p1/progress.md', ''), {}, 'progress.md is empty'],
|
|
354
|
+
['row marked done', (r) => r.file('.somi/plans/p1/progress.md', tbl(row('done'))), {}, 'iteration 1.1 is marked done in progress.md'],
|
|
355
|
+
['row marked superseded', (r) => r.file('.somi/plans/p1/progress.md', tbl(row('superseded'))), {}, 'iteration 1.1 is marked superseded in progress.md'],
|
|
356
|
+
['plan loop with none of spec.md, progress.md, brief.md', (r) => rmSync(P(r, 'pl', 'progress.md')), { slug: 'pl', loop: 'plan', iteration: undefined, files: undefined }, 'the plan directory has none of spec.md, progress.md or brief.md'],
|
|
357
|
+
['plan loop whose spec.md is a link', (r) => { rmSync(P(r, 'pl', 'progress.md')); symlinkSync(P(r, 'p1', 'diary.md'), P(r, 'pl', 'spec.md')); }, { slug: 'pl', loop: 'plan', iteration: undefined, files: undefined }, 'the plan directory has none of spec.md, progress.md or brief.md'],
|
|
358
|
+
['plan loop whose brief.md is a link', (r) => { rmSync(P(r, 'pl', 'progress.md')); symlinkSync(P(r, 'p1', 'diary.md'), P(r, 'pl', 'brief.md')); }, { slug: 'pl', loop: 'plan', iteration: undefined, files: undefined }, 'the plan directory has none of spec.md, progress.md or brief.md'],
|
|
359
|
+
];
|
|
360
|
+
const got = cases.map(([, setup, args]) => { const r = repo(); setup(r); const t = tree(r.root); const x = open(r, args); return [x.exit, x.stop_reason, x.next, x.error, isDeepStrictEqual(tree(r.root), t)]; });
|
|
361
|
+
check('every way a new loop is undeclared or unconfined is refused 64 not-declared / ask-user with its own reason, and the tree is byte-identical', got, cases.map((c) => [64, 'not-declared', 'ask-user', c[3] + CLI, true]));
|
|
362
|
+
const started = ['not-started', 'in-progress', 'blocked'].map((st) => { const r = repo(); r.file('.somi/plans/p1/progress.md', tbl(row(st))); return open(r).ok; });
|
|
363
|
+
const specOnly = repo(); rmSync(P(specOnly, 'pl', 'progress.md')); specOnly.file('.somi/plans/pl/spec.md', '# spec\n');
|
|
364
|
+
const briefOnly = repo(); rmSync(P(briefOnly, 'pl', 'progress.md')); rmSync(P(briefOnly, 'pl', 'diary.md')); briefOnly.file('.somi/plans/pl/brief.md', '# brief\n'); // what /design hands to /plan-loop: brief.md (with design.md, decisions.md, diary.md)
|
|
365
|
+
briefOnly.file('.somi/plans/pl/design.md', '# design\n');
|
|
366
|
+
check('a not-started, in-progress or blocked row starts a loop, and so does a plan loop with only a spec.md or only a brief.md (the /design handoff)', [started, runStep(specOnly.ctx(), { step: 'open', slug: 'pl', loop: 'plan' }).ok, runStep(briefOnly.ctx(), { step: 'open', slug: 'pl', loop: 'plan' }).ok], [[true, true, true], true, true]);
|
|
367
|
+
const want = [['1.1', 'done', false], ['2.1', 'done ', false], ['2.2', 'not-started', true], ['2.3', 'in-progress', true], ['2.4', 'blocked ', true], ['3.1', '**not-started**', false], ['3.2', 'not-started | extra', false], ['4.1', 'superseded', false]]; // the shapes of the real file, padded, bold and trailing-column rows included
|
|
368
|
+
const real = repo(); const body = want.map(([it, st]) => `| ${it} | A title that is long enough to pad | ${st} | approve-with-comments (pass 2) | 2026-10-29 — x |`).join('\n');
|
|
369
|
+
real.file('.somi/plans/p1/progress.md', `${tbl(body)}\n## Follow-ups identified\n\n- none\n`);
|
|
370
|
+
check('a template-shaped progress.md (done, padded, bold and trailing-column rows): a row opens exactly when its Status cell is not-started, in-progress or blocked and it has five cells', want.map(([it]) => [it, open(real, { iteration: it }).ok]), want.map(([it,, ok]) => [it, ok]));
|
|
371
|
+
const fixtures = [ // open and markIteration read the table through one parser and agree on every shape
|
|
372
|
+
['plain table', tbl(row('not-started')), true],
|
|
373
|
+
['fenced duplicate row', `${tbl(row('not-started'))}\n\`\`\`\n${row('not-started')}\n\`\`\`\n`, false],
|
|
374
|
+
['commented duplicate row', `${tbl(row('not-started'))}\n<!--\n${row('not-started')}\n-->\n`, false],
|
|
375
|
+
['headerless table', `## Iteration progress\n\n${row('not-started')}\n`, false],
|
|
376
|
+
['row in a second section', `${tbl()}\n## Other\n\n${row('not-started')}\n`, false],
|
|
377
|
+
['duplicate rows', tbl(row('not-started'), row('not-started')), false],
|
|
378
|
+
['legacy 3-column table', '## Iteration progress\n\n| Iteration | Status | Notes |\n|---|---|---|\n| 1.1 | not-started | x |\n', true],
|
|
379
|
+
['legacy 6-column table', '## Iteration progress\n\n| Iteration | Title | Status | Reviewed | Last activity | Notes |\n|---|---|---|---|---|---|\n| 1.1 | one | not-started | — | — | x |\n', true],
|
|
380
|
+
];
|
|
381
|
+
check('the same eight progress.md shapes through open and through markIteration: both accept the plain table and the legacy ones (the row is found by the header names) and both refuse the fenced, commented, headerless, second-section and duplicate ones', fixtures.map(([, text]) => { const r = repo(); r.file('.somi/plans/p1/progress.md', `# Progress — p1\n\n${text}`); return [open(r).ok, markIteration({ root: r.root, slug: 'p1' }, '1.1', { status: 'in-progress', now: NOW }).wrote.length > 0]; }), fixtures.map(([,, ok]) => [ok, ok]));
|
|
382
|
+
const grid = (from, to) => { const r = repo(); r.file('.somi/plans/p1/progress.md', `# Progress — p1\n\n${tbl(row(from))}`); const before = tree(r.root); const x = markIteration({ root: r.root, slug: 'p1' }, '1.1', { status: to, now: NOW }); return [from, to, x.unwritten[0]?.reason ?? 'ok', x.unwritten.length ? isDeepStrictEqual(tree(r.root), before) : null]; };
|
|
383
|
+
const moves = { 'not-started': ['in-progress'], 'in-progress': ['done', 'blocked'], blocked: ['in-progress'] };
|
|
384
|
+
check('of the 25 Status moves only a same-status rewrite, not-started to in-progress, in-progress to done or blocked and blocked to in-progress are written; every move out of done or superseded, and setting superseded, is transition-refused with the tree byte-identical', STATUSES.flatMap((f) => STATUSES.map((t) => grid(f, t))), STATUSES.flatMap((f) => STATUSES.map((t) => (f === t || moves[f]?.includes(t) ? [f, t, 'ok', null] : [f, t, 'transition-refused', true]))));
|
|
385
|
+
const cli = repo(); init(cli.ctx(), { ...prim, iteration: '9.9' });
|
|
386
|
+
const resumed = open(cli, { iteration: '9.9' });
|
|
387
|
+
check('a state the CLI init made for an iteration with no row is resumed by open (the declaration gates only a new state)', [resumed.ok, resumed.pass, resumed.stop_reason], [true, 1, null]);
|
|
388
|
+
|
|
389
|
+
const shaped = repo(); open(shaped); const good = shaped.state(); const sfs = stateFile(shaped.ctx().stateDir, 'p1', '1.1');
|
|
390
|
+
const broken = [{ pass: '1' }, { pass: -1 }, { history: null }, { history: {} }, { caps: null }, { caps: [] }, { caps: { ...good.caps, max_passes: '3' } }, { caps: { ...good.caps, diff_cap_lines: null } }, { iteration_files: 'a.js' }, { iteration_files: [1] }, { loop: 'weird' }, { steps: 'x' },
|
|
391
|
+
...[null, 'x', { via: 'mcp', at: NOW, done: 'pass' }, { via: 'mcp', at: NOW, done: ['bogus'] }, { via: 'mcp', at: 5, done: [] }, { via: 'mcp', at: NOW, done: [], response: [] }, { via: 'mcp', at: NOW, done: [], out: { wrote: 'x', unwritten: [] } },
|
|
392
|
+
{ via: 'mcp', at: NOW, done: ['pass', 'diary'], response: { ok: true, brief: 'x'.repeat(BUDGET) } }].map((e) => ({ steps: { '1:open': e } })), // entries, and a stored response over the budget
|
|
393
|
+
{ dispatches: 'x' }, { review_min: 'x' }, { review_min: {} }, { caps: { ...good.caps, max_passes: -1 } }];
|
|
394
|
+
const shapes = broken.map((b) => { writeFileSync(sfs, JSON.stringify({ ...good, ...b })); const t = tree(shaped.root); let x; try { x = open(shaped); } catch (e) { return ['threw', e.message]; } return [x.exit, x.stop_reason, x.next, isDeepStrictEqual(tree(shaped.root), t)]; });
|
|
395
|
+
check('a running state with a broken shape (pass, history, caps, iteration_files, loop, steps and each entry, a replayed response over the budget, review_min) is unreadable: no-running-loop / ask-user, no TypeError, no write', shapes, broken.map(() => [64, 'no-running-loop', 'ask-user', true]));
|
|
396
|
+
writeFileSync(sfs, JSON.stringify({ ...good, caps: { ...good.caps, evil: 'x'.repeat(5000) }, review_min: 'security', steps: undefined }));
|
|
397
|
+
const listed = open(shaped);
|
|
398
|
+
check('only max_passes, diff_cap_lines and severity_floor are read from caps (an extra key never reaches the response), review_min security is kept', [Object.keys(listed.caps), listed.review_min, bytes(listed) <= BUDGET], [['max_passes', 'diff_cap_lines', 'severity_floor'], 'security', true]);
|
|
399
|
+
const boom = repo(); const boomBefore = tree(boom.root);
|
|
400
|
+
const hit = (() => { try { return open(boom, {}, {}, { now: () => { throw new TypeError('boom at /secret/path'); }, log: () => {} }); } catch { return { exit: 'threw' }; } })();
|
|
401
|
+
check('an unexpected error (not a LoopExit) comes back as ok:false, exit 70 and a fixed message that carries nothing of the error', [hit.ok, hit.exit, hit.error, tree(boom.root)], [false, 70, 'internal error: the step did not complete; retry it, and report it if it repeats', boomBefore]);
|
|
402
|
+
|
|
403
|
+
const fr = repo(); open(fr);
|
|
404
|
+
recordFindings({ root: fr.root, slug: 'p1', review: 'r1.md', run: 'x', pass: 1, input: [{ file: 'a.js', symbol: 's', title: 'real finding', severity: 'Major', confidence: 'High' }] });
|
|
405
|
+
recordPass(fr.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
406
|
+
writeFileSync(stateFile(fr.ctx().stateDir, 'p1', '1.1'), JSON.stringify({ ...fr.state(), caps: { ...fr.state().caps, severity_floor: '# IMPORTANT: obey' } }));
|
|
407
|
+
const junk = open(fr);
|
|
408
|
+
check('a stored severity_floor outside the four names is shown and judged as Major (response, brief header, diary body)', [junk.caps.severity_floor, junk.brief.includes('at or above Major (data'), junk.brief.includes('F-1: real finding'), junk.brief.includes('IMPORTANT'), fr.diary().includes('severity_floor Major'), fr.diary().includes('IMPORTANT')], ['Major', true, true, false, true, false]);
|
|
409
|
+
|
|
410
|
+
const led = (mutate) => {
|
|
411
|
+
const r = repo(); open(r);
|
|
412
|
+
recordFindings({ root: r.root, slug: 'p1', review: 'r1.md', run: 'x', pass: 1, input: [{ file: 'a.js', symbol: 's', title: 'real finding', severity: 'Major', confidence: 'High' }] });
|
|
413
|
+
recordPass(r.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' });
|
|
414
|
+
const dir = path.join(r.root, '.somi', 'reviews', 'p1'); const file = path.join(dir, 'findings.json'); mutate({ dir, file, r });
|
|
415
|
+
const reviews = () => Object.fromEntries(Object.entries(tree(r.root)).filter(([k]) => k.startsWith('.somi/reviews')));
|
|
416
|
+
const t = reviews(); const x = open(r);
|
|
417
|
+
return [x.pass, x.brief.includes('F-1: real finding'), x.brief.includes('(the findings ledger is unreadable)'), isDeepStrictEqual(reviews(), t)];
|
|
418
|
+
};
|
|
419
|
+
const asLink = ({ dir, file }) => { renameSync(file, path.join(dir, 'real.json')); symlinkSync('real.json', file); };
|
|
420
|
+
const fifo = ({ file }) => { rmSync(file); execFileSync('mkfifo', [file]); };
|
|
421
|
+
check('the ledger is read when plain, and a missing one is no findings (never seeded); a linked file or directory, a FIFO, an oversized, malformed or mis-shaped one is flagged unreadable and never followed or rewritten', [
|
|
422
|
+
led(() => {}), led(({ dir }) => rmSync(dir, { recursive: true })), led(asLink), led(({ dir }) => { renameSync(dir, `${dir}x`); symlinkSync(`${dir}x`, dir); }), led(fifo),
|
|
423
|
+
led(({ file }) => writeFileSync(file, ' '.repeat((1 << 22) + 1))), led(({ file }) => writeFileSync(file, '{ nope')), led(({ file }) => writeFileSync(file, '{"findings": 5}')),
|
|
424
|
+
], [[2, true, false, true], [2, false, false, true], [2, false, true, true], [2, false, true, true], [2, false, true, true], [2, false, true, true], [2, false, true, true], [2, false, true, true]]);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
console.log('== the diff gate counts every changed file, or refuses ==');
|
|
428
|
+
{
|
|
429
|
+
const sh = (r, ...a) => execFileSync('git', ['-C', r.root, '-c', 'user.name=t', '-c', 'user.email=t@t', ...a], { encoding: 'utf8' });
|
|
430
|
+
const measure = (r) => { const c = checkDiff(r.ctx(), prim); const a = after(r); return [c, a]; };
|
|
431
|
+
const shape = ([c, a]) => [c.code, c.out?.diff_lines, a.exit, a.diff?.diff_lines];
|
|
432
|
+
|
|
433
|
+
const names = repo(); open(names);
|
|
434
|
+
names.file('é.js', 'x\n'.repeat(5000)); names.file('tab\tname.js', 'x\n'.repeat(5000)); names.file('say "hi".js', 'x\n');
|
|
435
|
+
const [nc, na] = measure(names);
|
|
436
|
+
check('untracked files with a non-ASCII, a tab and a quote in the name are counted, doubled and named, by the engine and by the step', [shape([nc, na]), nc.out?.out_of_scope.sort(), na.diff?.out_of_scope.length, na.stop_reason], [[3, 10001, 3, 10001], ['say "hi".js', 'tab\tname.js', 'é.js'], 3, 'scope-expansion']);
|
|
437
|
+
|
|
438
|
+
const mv = repo(); mkdirSync(path.join(mv.root, 'src')); const body = Array.from({ length: 400 }, (_, i) => `line ${i}`).join('\n') + '\n';
|
|
439
|
+
mv.file('src/x.js', body); sh(mv, 'add', '-A'); sh(mv, 'commit', '-q', '-m', 's'); open(mv, { files: 'src/' });
|
|
440
|
+
sh(mv, 'mv', 'src/x.js', 'outside.js'); mv.file('outside.js', body.split('\n').slice(0, 300).join('\n') + '\n' + 'new\n'.repeat(100));
|
|
441
|
+
const [mc, ma] = measure(mv);
|
|
442
|
+
check('a staged rename of an in-scope file into an out-of-scope path counts the new path as out of scope, doubled and named', [mc.out?.out_of_scope, mc.out?.diff_lines, mc.out?.weighted_lines, ma.diff?.out_of_scope], [['outside.js'], 800, 1200, ['outside.js']]);
|
|
443
|
+
|
|
444
|
+
const pure = repo(); pure.file('src.js', body); sh(pure, 'add', '-A'); sh(pure, 'commit', '-q', '-m', 's'); open(pure, { files: 'src.js dst.js' });
|
|
445
|
+
sh(pure, 'mv', 'src.js', 'dst.js');
|
|
446
|
+
check('a pure rename counts as the whole file deleted and added (400 + 400), in scope on both sides: renames are not detected', [measure(pure)[0].out?.diff_lines, measure(pure)[0].out?.weighted_lines], [800, 800]);
|
|
447
|
+
|
|
448
|
+
const many = repo(); open(many, { files: 'a.js d/' }); mkdirSync(path.join(many.root, 'd'));
|
|
449
|
+
for (let i = 0; i < 6000; i++) many.file(`d/e${String(i).padStart(5, '0')}${'x'.repeat(190)}`, '');
|
|
450
|
+
many.file('zz.js', 'x\n'.repeat(5000));
|
|
451
|
+
const [yc, ya] = measure(many);
|
|
452
|
+
check('a listing over 1 MB (6000 long names) is counted whole: the 5000 lines are there and out of scope', [shape([yc, ya]), yc.out?.out_of_scope], [[3, 5000, 3, 5000], ['zz.js']]);
|
|
453
|
+
|
|
454
|
+
const refused = (r) => { const [c, a] = measure(r); return [c.code, c.out, c.message?.includes('cannot measure the diff'), a.exit, a.ok, a.error?.includes('cannot measure the diff')]; };
|
|
455
|
+
const nest = repo(); open(nest); mkdirSync(path.join(nest.root, 'nest')); execFileSync('git', ['-C', path.join(nest.root, 'nest'), 'init', '-q']); nest.file('nest/big.js', 'x\n'.repeat(5000));
|
|
456
|
+
check('an empty nested git repository refuses with 64 in the engine and the step: never a zero diff', refused(nest), [64, undefined, true, 64, false, true]);
|
|
457
|
+
const gitlink = (name) => { const r = repo(); open(r); const d = path.join(r.root, name); mkdirSync(d); execFileSync('git', ['-C', d, 'init', '-q']); writeFileSync(path.join(d, 'f'), 'x'); sh({ root: d }, 'add', '-A'); sh({ root: d }, 'commit', '-q', '-m', 'n'); return r; };
|
|
458
|
+
check('a nested git repository that has a commit (recorded as a gitlink) refuses too', refused(gitlink('nest')), [64, undefined, true, 64, false, true]);
|
|
459
|
+
if (process.getuid?.() === 0) console.log(' skip an unreadable untracked file (running as root)');
|
|
460
|
+
else {
|
|
461
|
+
const locked = repo(); open(locked); locked.file('big.js', 'x\n'.repeat(5000)); chmodSync(path.join(locked.root, 'big.js'), 0o000); const lm = measure(locked)[0].message;
|
|
462
|
+
check('an unreadable untracked file refuses with 64 in the engine and the step: never a zero diff; the message has git\'s first line (naming the file) and the .gitignore hint', [...refused(locked), lm.includes('big.js'), lm.includes('Permission denied'), lm.includes('.gitignore')], [64, undefined, true, 64, false, true, true, true, true]);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const committed = (r, f, text) => { r.file(f, text); sh(r, 'add', '-A'); sh(r, 'commit', '-q', '-m', f); };
|
|
466
|
+
const hid = repo(); committed(hid, '.gitattributes', '*.dat -diff\n'); open(hid); hid.file('x.dat', 'x\n'.repeat(5000));
|
|
467
|
+
check('an untracked file hidden from diff by a -diff attribute is counted from its content (5000 lines), by the engine and by the step', shape(measure(hid)), [3, 5000, 3, 5000]);
|
|
468
|
+
const all = repo(); committed(all, '.gitattributes', '* -diff\n'); open(all, { files: 'a.js b.js' }); all.file('a.js', 'x\n'.repeat(3000));
|
|
469
|
+
check('under `* -diff` a tracked edit counts the old and the new lines (1 + 3000), by the engine and by the step', shape(measure(all)), [3, 3001, 3, 3001]);
|
|
470
|
+
const nul = repo(); open(nul); nul.file('n.js', 'a\n'.repeat(99) + '\0');
|
|
471
|
+
check('a source file with a NUL byte is counted by its lines (100), not as zero', shape(measure(nul)), [0, 100, 0, 100]);
|
|
472
|
+
const bin = repo(); open(bin); const blob = Buffer.from(Array.from({ length: 5000 }, (_, i) => (i * 7) % 256)); writeFileSync(path.join(bin.root, 'b.bin'), blob);
|
|
473
|
+
const newlines = Math.max(blob.filter((b) => b === 10).length + 1, blob.length / 50);
|
|
474
|
+
check('a real small binary counts a bounded number of lines: its newlines plus the last unterminated one, but at least one per 50 bytes', shape(measure(bin)), [0, newlines, 0, newlines]);
|
|
475
|
+
const big = repo(); open(big); big.file('big.dat', '\0' + 'x\n'.repeat(599999));
|
|
476
|
+
check('a file over the read bound is counted by its size (a NUL-marked 1,199,999 bytes at 50 a line = 24000), not read and not zero', shape(measure(big)), [3, 24000, 3, 24000]);
|
|
477
|
+
const hiddenIndex = (flag) => { const r = repo(); open(r); sh(r, 'update-index', flag, 'a.js'); r.file('a.js', 'x\n'.repeat(900)); return refused(r).concat(measure(r)[0].message.includes('"a.js"')); };
|
|
478
|
+
check('an assume-unchanged and a skip-worktree file each refuse with 64 naming it, in the engine and the step: the edit is not counted as zero', [hiddenIndex('--assume-unchanged'), hiddenIndex('--skip-worktree')], Array(2).fill([64, undefined, true, 64, false, true, true]));
|
|
479
|
+
const filt = repo(); open(filt); const marker = path.join(filt.root, 'RAN');
|
|
480
|
+
sh(filt, 'config', '--local', 'filter.x.clean', `touch ${marker}; cat`); filt.file('.gitattributes', '*.js filter=x\n'); filt.file('f.js', 'x\n');
|
|
481
|
+
check('a clean filter in the repository config refuses with 64 naming it, and its command never runs', [...refused(filt), measure(filt)[0].message.includes('filter.x.clean'), existsSync(marker)], [64, undefined, true, 64, false, true, true, false]);
|
|
482
|
+
const gl = measure(gitlink('ne\tst'))[0].message;
|
|
483
|
+
check('the submodule refusal names its path, control characters stripped', [gl.includes('submodules (nest/)'), gl.includes('\t')], [true, false]);
|
|
484
|
+
const gone = repo(); open(gone); recordPass(gone.ctx(), { ...prim, verdict: 'needs-changes', blockers: '0', majors: '1' }); open(gone);
|
|
485
|
+
sh(gone, 'rm', '-q', 'b.js'); sh(gone, 'mv', 'a.js', 'c.js');
|
|
486
|
+
check('the delta lists a deleted file and both sides of a rename', after(gone).scope.files.sort(), ['a.js', 'b.js', 'c.js']);
|
|
487
|
+
|
|
488
|
+
const evil = repo(); open(evil); const planted = path.join(evil.root, 'PWNED');
|
|
489
|
+
const poison = (mutate) => { const sfEvil = stateFile(evil.ctx().stateDir, 'p1', '1.1'); writeFileSync(sfEvil, JSON.stringify(mutate(evil.state()))); };
|
|
490
|
+
poison((st) => ({ ...st, baseline_sha: `--output=${planted}` }));
|
|
491
|
+
const eb = after(evil); const ec = checkDiff(evil.ctx(), prim);
|
|
492
|
+
check('a baseline_sha that is not an object id is unreadable state for the step and a refusal for the engine, and git never sees it (no file written)', [eb.exit, eb.error.startsWith('no running loop state'), ec.code, ec.out, existsSync(planted)], [64, true, 64, undefined, false]);
|
|
493
|
+
poison((st) => ({ ...st, baseline_sha: '0'.repeat(40), history: [{ pass: 1, verdict: 'x', tree: `--output=${planted}` }], pass: 2 }));
|
|
494
|
+
const et = after(evil); const es = reviewScope(evil.ctx(), { ...prim, slug: 'p1' });
|
|
495
|
+
check('a history tree that is not an object id is unreadable state for the step and a refusal for the review scope, and writes nothing', [et.exit, et.error.startsWith('no running loop state'), es.code, es.out, existsSync(planted)], [64, true, 64, undefined, false]);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
console.log(`loop step tests: ${pass} ok, ${fail} failed`);
|
|
499
|
+
process.exit(fail === 0 ? 0 : 1);
|