@skathio/somi 2.2.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +8 -2
  3. package/.copilot-extension/extension.json +9 -8
  4. package/.copilot-extension/marketplace.json +2 -2
  5. package/README.md +45 -33
  6. package/VERSION +1 -1
  7. package/agents/architecture-reviewer.md +16 -0
  8. package/agents/atlas.md +102 -0
  9. package/agents/coder.md +66 -22
  10. package/agents/designer.md +20 -16
  11. package/agents/discovery-analyst.md +6 -5
  12. package/agents/impact.md +97 -0
  13. package/agents/incident.md +96 -0
  14. package/agents/plan-reviewer.md +70 -0
  15. package/agents/planner.md +77 -20
  16. package/agents/pr.md +101 -0
  17. package/agents/refactor-designer.md +82 -0
  18. package/agents/refactorer.md +30 -24
  19. package/agents/reviewer.md +28 -25
  20. package/agents/sdlc-reviewer.md +69 -0
  21. package/agents/security-reviewer.md +17 -0
  22. package/agents/somi.md +207 -209
  23. package/agents/test-strategist.md +16 -1
  24. package/commands/adopt.md +21 -7
  25. package/commands/architecture-review.md +8 -5
  26. package/commands/atlas.md +24 -72
  27. package/commands/code-loop.md +46 -15
  28. package/commands/code-parallel.md +6 -4
  29. package/commands/code.md +29 -21
  30. package/commands/debug.md +17 -11
  31. package/commands/design.md +48 -31
  32. package/commands/discover.md +26 -16
  33. package/commands/impact.md +16 -54
  34. package/commands/incident.md +22 -55
  35. package/commands/plan-loop.md +43 -17
  36. package/commands/plan.md +64 -26
  37. package/commands/pr.md +19 -66
  38. package/commands/refactor-design.md +98 -0
  39. package/commands/refactor.md +22 -23
  40. package/commands/release-readiness.md +16 -7
  41. package/commands/review-panel.md +31 -10
  42. package/commands/review.md +21 -14
  43. package/commands/security-review.md +12 -3
  44. package/commands/ship-loop.md +71 -54
  45. package/commands/ship.md +17 -13
  46. package/commands/test-strategy.md +6 -4
  47. package/commands/upgrade.md +10 -8
  48. package/examples/discovery-example.md +2 -2
  49. package/examples/sample-consumer/CLAUDE.md +41 -7
  50. package/examples/sample-consumer/README.md +36 -22
  51. package/hooks/lib/common.mjs +66 -20
  52. package/hooks/post-tool/audit-log.mjs +7 -11
  53. package/hooks/post-tool/lint-changed-files.mjs +8 -11
  54. package/hooks/pre-tool/block-dangerous-bash.mjs +32 -44
  55. package/hooks/pre-tool/block-secret-writes.mjs +6 -9
  56. package/hooks/pre-tool/gate-dep-install.mjs +18 -27
  57. package/hooks/pre-tool/guard-protected-paths.mjs +9 -11
  58. package/hooks/session-start/detect-repo-instructions.mjs +21 -23
  59. package/hooks/user-prompt-submit/inject-workflow-context.mjs +190 -42
  60. package/mcp.json +10 -0
  61. package/package.json +5 -2
  62. package/rules/CLAUDE.md +22 -19
  63. package/scripts/check-links.mjs +218 -0
  64. package/scripts/check-session-artefacts.mjs +149 -0
  65. package/scripts/check-size-budget.mjs +137 -0
  66. package/scripts/generate-digest.mjs +176 -0
  67. package/scripts/lib/cost-ceiling.mjs +317 -0
  68. package/scripts/lib/cost-model.mjs +95 -0
  69. package/scripts/lib/dispatch-resolver.mjs +224 -0
  70. package/scripts/lib/mcp-project-root.mjs +183 -0
  71. package/scripts/size-budget-overrides.json +74 -0
  72. package/scripts/somi-check.mjs +6 -13
  73. package/scripts/somi-dispatch.mjs +141 -0
  74. package/scripts/somi-findings.mjs +4 -5
  75. package/scripts/somi-loop.mjs +181 -13
  76. package/scripts/somi-mcp.mjs +357 -0
  77. package/scripts/validate.sh +690 -29
  78. package/skills/clean-code/SKILL.md +1 -1
  79. package/skills/plan-review/SKILL.md +79 -0
  80. package/skills/rules/SKILL.md +47 -0
  81. package/skills/sdlc-process/SKILL.md +74 -0
  82. package/skills/somi-dispatch/SKILL.md +220 -0
  83. package/skills/somi-routing/SKILL.md +33 -8
  84. package/skills/{test-strategy → testing-playbook}/SKILL.md +1 -1
  85. package/templates/ATLAS.md.tmpl +4 -4
  86. package/templates/BRIEF.md.tmpl +23 -22
  87. package/templates/DECISIONS.md.tmpl +1 -0
  88. package/templates/DESIGN.md.tmpl +5 -5
  89. package/templates/DIARY.md.tmpl +10 -5
  90. package/templates/DOD.md.tmpl +24 -0
  91. package/templates/PROGRESS.md.tmpl +3 -16
  92. package/templates/SOMI-README.md.tmpl +3 -3
  93. package/tests/hooks/cases/inject-workflow-context.json +120 -7
  94. package/tests/hooks/run.sh +20 -11
  95. package/tests/scripts/check-links.sh +105 -0
  96. package/tests/scripts/check-session-artefacts.sh +60 -0
  97. package/tests/scripts/check-size-budget.sh +71 -0
  98. package/tests/scripts/checkpoint-gate.sh +90 -0
  99. package/tests/scripts/convergence-runner.sh +1510 -0
  100. package/tests/scripts/cost-ceiling.sh +343 -0
  101. package/tests/scripts/cost-model.sh +192 -0
  102. package/tests/scripts/dispatch-guard.sh +108 -0
  103. package/tests/scripts/dispatch-reference-gate.sh +173 -0
  104. package/tests/scripts/eval-runner.sh +3691 -0
  105. package/tests/scripts/evals-packaging.sh +117 -0
  106. package/tests/scripts/fixtures/legacy-shard-no-schema.json +50 -0
  107. package/tests/scripts/generate-digest.sh +180 -0
  108. package/tests/scripts/goldens/loop-state-breach.json +1 -0
  109. package/tests/scripts/goldens/loop-state-done.json +1 -0
  110. package/tests/scripts/goldens/somi-loop.json +1 -1
  111. package/tests/scripts/lib/adr-shape.mjs +41 -0
  112. package/tests/scripts/lib/checkpoint-gate.mjs +54 -0
  113. package/tests/scripts/lib/digest-marker-coupling.mjs +52 -0
  114. package/tests/scripts/lib/dispatch-reference-gate.mjs +112 -0
  115. package/tests/scripts/lib/multipass-dependence.mjs +192 -0
  116. package/tests/scripts/lib/multipass-source-identity.mjs +243 -0
  117. package/tests/scripts/lib/reference-pair.mjs +61 -0
  118. package/tests/scripts/lib/retirement-gate.mjs +167 -0
  119. package/tests/scripts/lib/shell-embedded-js.mjs +47 -0
  120. package/tests/scripts/lib/somi-mcp-client.mjs +102 -0
  121. package/tests/scripts/lib/somi-mcp-tests.mjs +401 -0
  122. package/tests/scripts/lib/somi-mcp-tool-schema.mjs +38 -0
  123. package/tests/scripts/retirement-gate.sh +287 -0
  124. package/tests/scripts/review-panel-seats.sh +32 -0
  125. package/tests/scripts/run.sh +184 -2
  126. package/tests/scripts/somi-agent-dispatch-contract.sh +195 -0
  127. package/tests/scripts/somi-dispatch.sh +354 -0
  128. package/tests/scripts/somi-mcp.sh +12 -0
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env bash
2
+ # End-to-end tests for scripts/check-links.mjs.
3
+ #
4
+ # This work item has produced a fix-without-a-guard five separate times, so a new checker ships with
5
+ # its own regression suite. Fixtures are real `git init` repos, not bare directories, because the
6
+ # walker enumerates via `git ls-files` — and one case depends on `.gitignore` actually being
7
+ # honoured, which a bare directory cannot demonstrate.
8
+ #
9
+ # NEGATIVE cases are as load-bearing as positive ones here. The walker's pass-1 regex silently
10
+ # passed five dead-link forms, and every staged failure used the single form it was authored
11
+ # against — the same sample-selection defect. The forms below are
12
+ # chosen to be ones a naive implementation gets WRONG.
13
+
14
+ set -euo pipefail
15
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
16
+ CHECK="$ROOT/scripts/check-links.mjs"
17
+ TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
18
+ failures=0; total=0
19
+ expect_exit() { local name="$1" want="$2" got=0; shift 2; "$@" >/dev/null 2>&1 || got=$?
20
+ [[ "$got" == "$want" ]] || { echo "FAIL: $name — expected exit $want, got $got" >&2; failures=$((failures+1)); }
21
+ total=$((total+1)); }
22
+ check() { total=$((total+1)); [[ "$2" == "0" ]] || { echo "FAIL: $1" >&2; failures=$((failures+1)); }; }
23
+
24
+ mkrepo() { rm -rf "$TMP/r"; mkdir -p "$TMP/r/docs" "$TMP/r/examples" "$TMP/r/scripts"
25
+ cp "$CHECK" "$TMP/r/scripts/check-links.mjs"
26
+ printf '# t\n' > "$TMP/r/docs/real.md"
27
+ (cd "$TMP/r" && git init -q -b main && git config user.email t@t && git config user.name t); }
28
+ commit() { (cd "$TMP/r" && git add -A && git commit -qm x); }
29
+ run() { (cd "$TMP/r" && node scripts/check-links.mjs); }
30
+
31
+ # --- baseline -------------------------------------------------------------------
32
+ mkrepo; printf '[ok](./real.md)\n' > "$TMP/r/docs/a.md"; commit
33
+ expect_exit "resolving relative link passes" 0 run
34
+ printf '[dead](./nope.md)\n' >> "$TMP/r/docs/a.md"; commit
35
+ expect_exit "dead relative link fails" 1 run
36
+
37
+ # --- FENCED AND INLINE CODE ARE NOT LINKS ---------------------------------------
38
+ # The pass-1 walker had no fence awareness. Four fenced sample links in
39
+ # examples/feature-plan-example.md read as real, and "fixing" them wrote a CI token into the
40
+ # canonical example that ships to npm. This is the case that must never regress.
41
+ mkrepo
42
+ printf '# t\n\n```markdown\n[sample](./does-not-exist.md)\n```\n\nInline: `[x](./nope.md)`\n' > "$TMP/r/docs/a.md"
43
+ commit
44
+ expect_exit "links inside a fenced block are not checked" 0 run
45
+ printf '\n~~~md\n[t](./nope2.md)\n~~~\n' >> "$TMP/r/docs/a.md"; commit
46
+ expect_exit "tilde fences are honoured too" 0 run
47
+ printf '\n[after](./nope4.md)\n' >> "$TMP/r/docs/a.md"; commit
48
+ expect_exit "a dead link AFTER a fence is still caught" 1 run
49
+
50
+ # --- FENCE FORMS THE PASS-2 REWRITE MISSED ---------------------------------------
51
+ # Both reproduce the Blocker's outcome (displayed source flagged as a real link), and both shipped
52
+ # unguarded until code review measured them.
53
+ # (1) A fence indented 4+ spaces is legal inside a list item.
54
+ mkrepo
55
+ printf '# t\n\n1. Step:\n\n ```markdown\n [sample](./nope-listfence.md)\n ```\n' > "$TMP/r/docs/a.md"
56
+ commit
57
+ expect_exit "a list-indented fence (4+ spaces) is honoured" 0 run
58
+ # (2) CommonMark requires the closer be at least as long as the opener, so a ``` inside a ````
59
+ # block does not close it.
60
+ mkrepo
61
+ printf '# t\n\n````markdown\n```\n[inner](./nope-quad.md)\n```\n````\n' > "$TMP/r/docs/a.md"
62
+ commit
63
+ expect_exit "a shorter fence run does not close a longer one" 0 run
64
+
65
+ # --- FORMS THE PASS-1 REGEX SILENTLY PASSED -------------------------------------
66
+ mkrepo; printf '# t\n\nRef: [text][r]\n\n[r]: ./nope-ref.md\n' > "$TMP/r/docs/a.md"; commit
67
+ expect_exit "reference-style link with a dead target is caught" 1 run
68
+ mkrepo; printf '# t\n\n[link text that\nwraps](./nope-wrap.md)\n' > "$TMP/r/docs/a.md"; commit
69
+ expect_exit "line-wrapped link text is caught" 1 run
70
+ mkrepo; printf '# t\n\n[t](<./nope-angle.md>)\n' > "$TMP/r/docs/a.md"; commit
71
+ expect_exit "angle-bracket destination is caught" 1 run
72
+ mkrepo; printf '# t\n\nRef: [text][r]\n\n```\n[r]: ./real.md\n```\n' > "$TMP/r/docs/a.md"; commit
73
+ expect_exit "a reference definition inside a fence is not honoured" 0 run
74
+
75
+ # --- illustrative-path hatch: scoped, and self-invalidating ---------------------
76
+ mkrepo; printf '# t\n<!-- illustrative-path -->[dead](./nope.md)\n' > "$TMP/r/examples/e.md"; commit
77
+ expect_exit "same-line marker exempts, inside examples/" 0 run
78
+ check "the exemption is reported on success" \
79
+ "$( (cd "$TMP/r" && node scripts/check-links.mjs) | grep -q '1 illustrative-path exemption'; echo $?)"
80
+ # The success line is F5's whole remedy — the number that makes hatch growth visible. An earlier
81
+ # form incremented `checked` before the resolving branch, so it reported exempted (non-resolving)
82
+ # links as resolving: "2 relative link(s) resolve" when zero did. A false claim in the output of
83
+ # the tool built to remove false claims.
84
+ check "an exempted link is NOT counted as resolving" \
85
+ "$( (cd "$TMP/r" && node scripts/check-links.mjs) | grep -q '^check-links: 0 relative link(s) resolve; 1 illustrative-path exemption'; echo $?)"
86
+ mkrepo; printf '# t\n<!-- illustrative-path -->[dead](./nope.md)\n' > "$TMP/r/docs/a.md"; commit
87
+ expect_exit "a marker OUTSIDE examples/ fails rather than exempts" 1 run
88
+ mkrepo; printf '# t\n<!-- illustrative-path -->\n[dead](./nope.md)\n' > "$TMP/r/examples/e.md"; commit
89
+ expect_exit "preceding-line marker does NOT exempt (pinned placement)" 1 run
90
+ mkrepo; printf '# t\n<!-- illustrative-path -->[ok](../docs/real.md)\n' > "$TMP/r/examples/e.md"; commit
91
+ expect_exit "marker on a RESOLVING link fails as stale" 1 run
92
+
93
+ # --- exclusions and skipped link kinds ------------------------------------------
94
+ mkrepo
95
+ printf '.somi/\n' > "$TMP/r/.gitignore" # mirrors this repo: .somi is gitignored, so untracked
96
+ mkdir -p "$TMP/r/.somi"; printf '[x](./nope.md)\n' > "$TMP/r/.somi/plan.md"
97
+ printf '[x](./nope.md)\n' > "$TMP/r/CHANGELOG.md"
98
+ printf '[a](https://e.com/x.md)\n[b](#frag)\n[c](./real.md#frag)\n[d](mailto:a@b.c)\n[e](HTTPS://e.com/y.md)\n' > "$TMP/r/docs/a.md"
99
+ commit
100
+ expect_exit "gitignored .somi/ and CHANGELOG.md skipped; external/anchor/mailto ignored" 0 run
101
+ printf '[f](./nope.md#frag)\n' >> "$TMP/r/docs/a.md"; commit
102
+ expect_exit "a fragment on a DEAD target is still caught" 1 run
103
+
104
+ echo "check-links tests: $((total - failures)) of $total checks passed."
105
+ [[ "$failures" -eq 0 ]] || exit 1
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bash
2
+ # Tests for scripts/check-session-artefacts.mjs. Fixtures are plain directories (the checker walks
3
+ # the filesystem, not git). Each case plants one line in an otherwise clean tree and asserts the
4
+ # exit code.
5
+
6
+ set -euo pipefail
7
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
8
+ CHECK="$ROOT/scripts/check-session-artefacts.mjs"
9
+ TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
10
+ failures=0; total=0
11
+ expect_exit() { local name="$1" want="$2" got=0; shift 2; "$@" >/dev/null 2>&1 || got=$?
12
+ [[ "$got" == "$want" ]] || { echo "FAIL: $name -- expected exit $want, got $got" >&2; failures=$((failures+1)); }
13
+ total=$((total+1)); }
14
+
15
+ mktree() { rm -rf "$TMP/r"; mkdir -p "$TMP/r/hooks" "$TMP/r/scripts" "$TMP/r/agents" "$TMP/r/commands" "$TMP/r/skills/s" "$TMP/r/tests"
16
+ printf '// A clean comment explaining why.\nconst x = 1;\n' > "$TMP/r/hooks/h.mjs"
17
+ printf '# A clean comment.\necho ok\n' > "$TMP/r/scripts/s.sh"
18
+ printf -- '---\nname: a\n---\nPlan with `D1:` sample, phase 1, iteration 1, and F-3.\n' > "$TMP/r/agents/a.md"; }
19
+ run() { node "$CHECK" --root "$TMP/r"; }
20
+
21
+ mktree
22
+ expect_exit "clean tree passes" 0 run
23
+
24
+ mktree; printf '// guards F-29 from the plan\n' >> "$TMP/r/hooks/h.mjs"
25
+ expect_exit "finding id in a hook comment fails" 1 run
26
+
27
+ mktree; printf '# see decisions.md#d5\n' >> "$TMP/r/scripts/s.sh"
28
+ expect_exit "decision anchor in a shell comment fails" 1 run
29
+
30
+ mktree; printf 'const y = 2; // phase 2 iteration 2.1 port\n' >> "$TMP/r/hooks/h.mjs"
31
+ expect_exit "trailing comment with iteration number fails" 1 run
32
+
33
+ mktree; printf 'const msg = "D5 is a string, not a comment";\n' >> "$TMP/r/hooks/h.mjs"
34
+ expect_exit "tag inside a string literal (not a comment) passes" 0 run
35
+
36
+ mktree; printf '// Appends a dated entry to the diary and reads the phase file.\n' >> "$TMP/r/hooks/h.mjs"
37
+ expect_exit "product mention of the diary or a phase file in a comment passes" 0 run
38
+
39
+ mktree; printf '// see the diary for why this changed\n' >> "$TMP/r/hooks/h.mjs"
40
+ expect_exit "a 'see the diary' pointer in a comment fails" 1 run
41
+
42
+ mktree; printf 'Decided in (D3).\n' >> "$TMP/r/commands/c.md"
43
+ expect_exit "decision tag in command markdown fails" 1 run
44
+
45
+ mktree; printf 'Same fix as F-29.\n' >> "$TMP/r/skills/s/SKILL.md"
46
+ expect_exit "finding id in skill markdown fails" 1 run
47
+
48
+ mktree; printf 'The product has a work item and phases; see D1: sample.\n' >> "$TMP/r/commands/c.md"
49
+ expect_exit "product vocabulary and sample ids in markdown pass" 0 run
50
+
51
+ # --- exclusions hold -----------------------------------------------------------------
52
+ mktree; printf '// F-29 D5 iteration 2.1\n' >> "$TMP/r/tests/t.sh"; printf 'F-29\n' > "$TMP/r/CHANGELOG.md"
53
+ mkdir -p "$TMP/r/tests/evals/results"; printf '// F-29\n' > "$TMP/r/tests/evals/results/x.mjs"
54
+ expect_exit "tests/, CHANGELOG.md and eval results are not scanned" 0 run
55
+
56
+ mktree; cp "$CHECK" "$TMP/r/scripts/check-session-artefacts.mjs"
57
+ expect_exit "the checker's own pattern definition is excluded" 0 run
58
+
59
+ if (( failures > 0 )); then echo "$failures of $total check-session-artefacts case(s) FAILED" >&2; exit 1; fi
60
+ echo " ok: $total check-session-artefacts cases"
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env bash
2
+ # Tests for scripts/check-size-budget.mjs. Each case builds a throwaway git repo (the checker
3
+ # enumerates tracked files) and asserts the exit code, never touching the real tree.
4
+
5
+ set -euo pipefail
6
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
7
+ CHECK="$ROOT/scripts/check-size-budget.mjs"
8
+ TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
9
+ failures=0; total=0
10
+ expect_exit() { local name="$1" want="$2" got=0; shift 2; "$@" >/dev/null 2>&1 || got=$?
11
+ [[ "$got" == "$want" ]] || { echo "FAIL: $name -- expected exit $want, got $got" >&2; failures=$((failures+1)); }
12
+ total=$((total+1)); }
13
+
14
+ R="$TMP/r"
15
+ lines() { local n="$1" i; for ((i=0;i<n;i++)); do echo "line $i"; done; }
16
+ mktree() { rm -rf "$R"; mkdir -p "$R/agents" "$R/scripts" "$R/tests/evals/results"
17
+ git -C "$R" init -q; lines 10 > "$R/agents/small.md"; lines 10 > "$R/scripts/s.mjs"; }
18
+ ledger() { printf '[{"file":"%s","budget":%s,"current_size":%s,"source":"abc1234","at":"2026-10-01","reason":"test"}]\n' "$1" "$2" "$3" > "$R/scripts/size-budget-overrides.json"; }
19
+ run() { git -C "$R" add -A; node "$CHECK" --root "$R"; }
20
+
21
+ mktree
22
+ expect_exit "within-budget tree passes" 0 run
23
+
24
+ mktree; lines 301 > "$R/agents/big.md"
25
+ expect_exit "un-ledgered prompt file over 300 fails" 1 run
26
+
27
+ mktree; lines 501 > "$R/scripts/big.mjs"
28
+ expect_exit "un-ledgered .mjs over 500 fails" 1 run
29
+
30
+ mktree; lines 801 > "$R/scripts/big.sh"
31
+ expect_exit "un-ledgered .sh over 800 fails" 1 run
32
+
33
+ mktree; lines 500 > "$R/scripts/edge.mjs"; lines 300 > "$R/agents/edge.md"; lines 800 > "$R/scripts/edge.sh"
34
+ expect_exit "files exactly at budget pass" 0 run
35
+
36
+ mktree; lines 5000 > "$R/tests/evals/results/r.mjs"; lines 5000 > "$R/notes.md"
37
+ expect_exit "eval results and docs are not gated" 0 run
38
+
39
+ mktree; lines 600 > "$R/scripts/big.mjs"; ledger scripts/big.mjs 500 600
40
+ expect_exit "ledgered file at its recorded size passes" 0 run
41
+
42
+ mktree; lines 599 > "$R/scripts/big.mjs"; ledger scripts/big.mjs 500 600
43
+ expect_exit "ledgered file that shrank passes" 0 run
44
+
45
+ mktree; lines 601 > "$R/scripts/big.mjs"; ledger scripts/big.mjs 500 600
46
+ expect_exit "ledgered file grown by one line fails" 1 run
47
+
48
+ mktree; lines 100 > "$R/scripts/big.mjs"; ledger scripts/big.mjs 500 600
49
+ expect_exit "ledgered file now within budget passes" 0 run
50
+ warned="$(node "$CHECK" --root "$R" 2>&1)"
51
+ total=$((total+1))
52
+ [[ "$warned" == *"remove its ledger entry"* ]] || { echo "FAIL: within-budget ledgered file did not warn" >&2; failures=$((failures+1)); }
53
+
54
+ mktree; lines 600 > "$R/untracked.mjs"
55
+ expect_exit "untracked oversized file is ignored" 0 bash -c "git -C '$R' add -A; mv '$R/untracked.mjs' '$R/u.tmp'; mv '$R/u.tmp' '$R/untracked.mjs'; git -C '$R' reset -q untracked.mjs; node '$CHECK' --root '$R'"
56
+
57
+ mktree; printf '{not json' > "$R/scripts/size-budget-overrides.json"
58
+ expect_exit "ledger that is not JSON fails loudly" 2 run
59
+
60
+ mktree; printf '{"file":"x"}' > "$R/scripts/size-budget-overrides.json"
61
+ expect_exit "ledger that is not an array fails loudly" 2 run
62
+
63
+ mktree; printf '[{"file":"scripts/s.mjs","budget":500}]' > "$R/scripts/size-budget-overrides.json"
64
+ expect_exit "ledger entry missing fields fails loudly" 2 run
65
+
66
+ mktree; lines 600 > "$R/scripts/big.mjs"; ledger scripts/big.mjs 500 600
67
+ cat "$R/scripts/size-budget-overrides.json" "$R/scripts/size-budget-overrides.json" | tr -d '\n' | sed 's/\]\[/,/' > "$R/scripts/dup.json"; mv "$R/scripts/dup.json" "$R/scripts/size-budget-overrides.json"
68
+ expect_exit "duplicate ledger entry fails loudly" 2 run
69
+
70
+ if (( failures > 0 )); then echo "check-size-budget: $failures of $total cases failed" >&2; exit 1; fi
71
+ echo " ok: check-size-budget ($total cases)"
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env bash
2
+ # Unit guard for tests/scripts/lib/checkpoint-gate.mjs -- ship-loop's non-overridable checkpoint.
3
+ #
4
+ # commands/ship-loop.md's single mandatory human checkpoint moved from a cost-tier
5
+ # boundary (which stopped existing) to the brief handoff. Nothing else fails the build if a later
6
+ # edit quietly drops "non-overridable" or either of the two anchors it fires at (the brief handoff,
7
+ # and -- on a cold start -- after /plan-loop). Proves the gate both ways, the same discipline
8
+ # retirement-gate.sh and dispatch-reference-gate.sh already apply to their own gates: green against
9
+ # the real file, red against a `cp -a` copy with the wording deliberately weakened.
10
+ #
11
+ # Fixture mutations run through node, not sed -- this repo hard-wraps prose at ~100 chars, so at
12
+ # least one real anchor phrase ("brief\nhandoff") is split across a line break, and sed's per-line
13
+ # substitution silently leaves a split occurrence untouched while node's whole-file regex (the same
14
+ # shape the gate itself uses) does not.
15
+ set -uo pipefail
16
+
17
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
18
+ GATE="$ROOT/tests/scripts/lib/checkpoint-gate.mjs"
19
+ SHIP_LOOP="$ROOT/commands/ship-loop.md"
20
+
21
+ pass=0; fail=0
22
+ ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
23
+ bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
24
+
25
+ echo "== ship-loop checkpoint gate =="
26
+
27
+ TMP="$(mktemp -d)"
28
+ trap 'rm -rf "$TMP"' EXIT
29
+
30
+ strip() { # $1 = source file, $2 = dest file, $3 = whole-file regex (JS, case-insensitive), $4 = replacement
31
+ node -e '
32
+ const fs = require("fs");
33
+ const [, src, dest, pattern, replacement] = process.argv;
34
+ const re = new RegExp(pattern, "gi");
35
+ fs.writeFileSync(dest, fs.readFileSync(src, "utf8").replace(re, replacement));
36
+ ' "$1" "$2" "$3" "$4"
37
+ }
38
+
39
+ # --- GREEN: the real, unmodified file must pass ---------------------------------------------
40
+ if out_green="$(node "$GATE" "$SHIP_LOOP" 2>&1)"; then
41
+ ok "gate exits 0 against the real commands/ship-loop.md"
42
+ else
43
+ bad "gate exited non-zero against the real file (got: $out_green)"
44
+ fi
45
+ case "$out_green" in
46
+ ok*) ok "gate's report starts with 'ok' against the real file" ;;
47
+ *) bad "gate's report does not start with 'ok' against the real file (got: $out_green)" ;;
48
+ esac
49
+
50
+ # --- RED: drop "non-overridable" ---------------------------------------------------------------
51
+ strip "$SHIP_LOOP" "$TMP/ship-loop.md" 'non-overridable' ''
52
+ out_red1="$(node "$GATE" "$TMP/ship-loop.md" 2>&1)"; rc1=$?
53
+ if [ "$rc1" -eq 1 ]; then
54
+ ok "gate exits 1 once 'non-overridable' is stripped from the file"
55
+ else
56
+ bad "gate did not exit 1 after stripping 'non-overridable' (rc=$rc1, out=$out_red1)"
57
+ fi
58
+ case "$out_red1" in
59
+ *"non-overridable"*) ok "gate names the missing non-overridable language" ;;
60
+ *) bad "gate's output does not name the missing non-overridable language (got: $out_red1)" ;;
61
+ esac
62
+
63
+ # --- RED: drop the brief-handoff anchor ---------------------------------------------------------
64
+ strip "$SHIP_LOOP" "$TMP/ship-loop.md" 'brief[\s-]?hand[\s-]?off' 'the review point'
65
+ out_red2="$(node "$GATE" "$TMP/ship-loop.md" 2>&1)"; rc2=$?
66
+ if [ "$rc2" -eq 1 ]; then
67
+ ok "gate exits 1 once the brief-handoff anchor is renamed away"
68
+ else
69
+ bad "gate did not exit 1 after renaming the brief-handoff anchor (rc=$rc2, out=$out_red2)"
70
+ fi
71
+ case "$out_red2" in
72
+ *"brief-handoff anchor"*) ok "gate names the missing brief-handoff anchor" ;;
73
+ *) bad "gate's output does not name the missing brief-handoff anchor (got: $out_red2)" ;;
74
+ esac
75
+
76
+ # --- RED: drop the cold-start (after /plan-loop) anchor -----------------------------------------
77
+ strip "$SHIP_LOOP" "$TMP/ship-loop.md" 'after\s+`?/plan-loop`?' 'later'
78
+ out_red3="$(node "$GATE" "$TMP/ship-loop.md" 2>&1)"; rc3=$?
79
+ if [ "$rc3" -eq 1 ]; then
80
+ ok "gate exits 1 once every 'after /plan-loop' mention is reworded away"
81
+ else
82
+ bad "gate did not exit 1 after rewording every 'after /plan-loop' mention (rc=$rc3, out=$out_red3)"
83
+ fi
84
+ case "$out_red3" in
85
+ *"cold-start anchor"*) ok "gate names the missing cold-start anchor" ;;
86
+ *) bad "gate's output does not name the missing cold-start anchor (got: $out_red3)" ;;
87
+ esac
88
+
89
+ echo "checkpoint gate tests: $pass ok, $fail failed"
90
+ [ "$fail" -eq 0 ] || exit 1