@skathio/somi 2.2.2 → 3.0.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-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +8 -2
- package/.copilot-extension/extension.json +9 -8
- package/.copilot-extension/marketplace.json +2 -2
- package/README.md +45 -33
- package/VERSION +1 -1
- package/agents/architecture-reviewer.md +16 -0
- package/agents/atlas.md +102 -0
- package/agents/coder.md +66 -22
- package/agents/designer.md +20 -16
- package/agents/discovery-analyst.md +6 -5
- package/agents/impact.md +97 -0
- package/agents/incident.md +96 -0
- package/agents/plan-reviewer.md +70 -0
- package/agents/planner.md +77 -20
- package/agents/pr.md +101 -0
- package/agents/refactor-designer.md +82 -0
- package/agents/refactorer.md +30 -24
- package/agents/reviewer.md +28 -25
- package/agents/sdlc-reviewer.md +69 -0
- package/agents/security-reviewer.md +17 -0
- package/agents/somi.md +204 -153
- package/agents/test-strategist.md +16 -1
- package/commands/adopt.md +21 -7
- package/commands/architecture-review.md +8 -5
- package/commands/atlas.md +24 -72
- package/commands/code-loop.md +46 -15
- package/commands/code-parallel.md +6 -4
- package/commands/code.md +29 -21
- package/commands/debug.md +17 -11
- package/commands/design.md +48 -31
- package/commands/discover.md +26 -16
- package/commands/impact.md +16 -54
- package/commands/incident.md +22 -55
- package/commands/plan-loop.md +43 -17
- package/commands/plan.md +64 -26
- package/commands/pr.md +19 -66
- package/commands/refactor-design.md +98 -0
- package/commands/refactor.md +22 -23
- package/commands/release-readiness.md +16 -7
- package/commands/review-panel.md +31 -10
- package/commands/review.md +21 -14
- package/commands/security-review.md +12 -3
- package/commands/ship-loop.md +71 -54
- package/commands/ship.md +17 -13
- package/commands/test-strategy.md +6 -4
- package/commands/upgrade.md +10 -8
- package/examples/discovery-example.md +2 -2
- package/examples/sample-consumer/CLAUDE.md +41 -7
- package/examples/sample-consumer/README.md +36 -22
- package/hooks/lib/common.mjs +66 -20
- package/hooks/post-tool/audit-log.mjs +7 -11
- package/hooks/post-tool/lint-changed-files.mjs +8 -11
- package/hooks/pre-tool/block-dangerous-bash.mjs +32 -44
- package/hooks/pre-tool/block-secret-writes.mjs +6 -9
- package/hooks/pre-tool/gate-dep-install.mjs +18 -27
- package/hooks/pre-tool/guard-protected-paths.mjs +9 -11
- package/hooks/session-start/detect-repo-instructions.mjs +21 -23
- package/hooks/user-prompt-submit/inject-workflow-context.mjs +190 -42
- package/mcp.json +10 -0
- package/package.json +5 -2
- package/rules/CLAUDE.md +22 -19
- package/scripts/check-links.mjs +218 -0
- package/scripts/check-session-artefacts.mjs +149 -0
- package/scripts/check-size-budget.mjs +137 -0
- package/scripts/generate-digest.mjs +176 -0
- package/scripts/lib/cost-ceiling.mjs +317 -0
- package/scripts/lib/cost-model.mjs +95 -0
- package/scripts/lib/dispatch-resolver.mjs +225 -0
- package/scripts/lib/mcp-project-root.mjs +183 -0
- package/scripts/size-budget-overrides.json +74 -0
- package/scripts/somi-check.mjs +6 -13
- package/scripts/somi-dispatch.mjs +141 -0
- package/scripts/somi-findings.mjs +4 -5
- package/scripts/somi-loop.mjs +181 -13
- package/scripts/somi-mcp.mjs +357 -0
- package/scripts/validate.sh +691 -30
- package/skills/clean-code/SKILL.md +1 -1
- package/skills/plan-review/SKILL.md +79 -0
- package/skills/rules/SKILL.md +47 -0
- package/skills/sdlc-process/SKILL.md +74 -0
- package/skills/somi-dispatch/SKILL.md +220 -0
- package/skills/somi-routing/SKILL.md +31 -6
- package/skills/{test-strategy → testing-playbook}/SKILL.md +1 -1
- package/templates/ATLAS.md.tmpl +4 -4
- package/templates/BRIEF.md.tmpl +23 -22
- package/templates/DECISIONS.md.tmpl +1 -0
- package/templates/DESIGN.md.tmpl +5 -5
- package/templates/DIARY.md.tmpl +10 -5
- package/templates/DOD.md.tmpl +24 -0
- package/templates/PROGRESS.md.tmpl +3 -16
- package/templates/SOMI-README.md.tmpl +3 -3
- package/tests/hooks/cases/inject-workflow-context.json +120 -7
- package/tests/hooks/run.sh +20 -11
- package/tests/scripts/check-links.sh +105 -0
- package/tests/scripts/check-session-artefacts.sh +60 -0
- package/tests/scripts/check-size-budget.sh +71 -0
- package/tests/scripts/checkpoint-gate.sh +90 -0
- package/tests/scripts/convergence-runner.sh +1510 -0
- package/tests/scripts/cost-ceiling.sh +343 -0
- package/tests/scripts/cost-model.sh +192 -0
- package/tests/scripts/dispatch-guard.sh +108 -0
- package/tests/scripts/dispatch-reference-gate.sh +173 -0
- package/tests/scripts/eval-runner.sh +3691 -0
- package/tests/scripts/evals-packaging.sh +117 -0
- package/tests/scripts/fixtures/legacy-shard-no-schema.json +50 -0
- package/tests/scripts/generate-digest.sh +180 -0
- package/tests/scripts/goldens/loop-state-breach.json +1 -0
- package/tests/scripts/goldens/loop-state-done.json +1 -0
- package/tests/scripts/goldens/somi-loop.json +1 -1
- package/tests/scripts/lib/adr-shape.mjs +41 -0
- package/tests/scripts/lib/checkpoint-gate.mjs +54 -0
- package/tests/scripts/lib/digest-marker-coupling.mjs +52 -0
- package/tests/scripts/lib/dispatch-reference-gate.mjs +112 -0
- package/tests/scripts/lib/multipass-dependence.mjs +192 -0
- package/tests/scripts/lib/multipass-source-identity.mjs +243 -0
- package/tests/scripts/lib/reference-pair.mjs +61 -0
- package/tests/scripts/lib/retirement-gate.mjs +167 -0
- package/tests/scripts/lib/shell-embedded-js.mjs +47 -0
- package/tests/scripts/lib/somi-mcp-client.mjs +102 -0
- package/tests/scripts/lib/somi-mcp-tests.mjs +401 -0
- package/tests/scripts/lib/somi-mcp-tool-schema.mjs +38 -0
- package/tests/scripts/retirement-gate.sh +287 -0
- package/tests/scripts/review-panel-seats.sh +32 -0
- package/tests/scripts/run.sh +184 -2
- package/tests/scripts/somi-agent-dispatch-contract.sh +195 -0
- package/tests/scripts/somi-dispatch.sh +366 -0
- package/tests/scripts/somi-mcp.sh +12 -0
package/templates/DESIGN.md.tmpl
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Design — <feature / user-story name>
|
|
2
2
|
|
|
3
|
-
> Brief (the
|
|
3
|
+
> Brief (the execution handoff): [`brief.md`](./brief.md) • Decisions: [`decisions.md`](./decisions.md)
|
|
4
4
|
> Diary: [`diary.md`](./diary.md)
|
|
5
|
-
> Created: <YYYY-MM-DD> • Last updated: <YYYY-MM-DD> • Produced by: `/design` (
|
|
5
|
+
> Created: <YYYY-MM-DD> • Last updated: <YYYY-MM-DD> • Produced by: `/design` (`cost: high`)
|
|
6
6
|
|
|
7
7
|
The feature design against **this** codebase — **direction and the hard parts**, not the file-by-file
|
|
8
8
|
implementation. The planner sequences this into phases; the coder executes it. This is the deep doc
|
|
@@ -65,7 +65,7 @@ distills. Be specific — "the ordering dependency at `x.go:120`", not "concurre
|
|
|
65
65
|
|
|
66
66
|
The conventions distilled from the repo's own instruction files (`CLAUDE.md`, `AGENTS.md`,
|
|
67
67
|
`.github/copilot-instructions.md`, …) that bear on this feature. Source files: <paths, or "none
|
|
68
|
-
found">. (Also surfaced in the brief so
|
|
68
|
+
found">. (Also surfaced in the brief so execution inherits them without re-reading.)
|
|
69
69
|
|
|
70
70
|
- <convention 1>
|
|
71
71
|
- <convention 2>
|
|
@@ -74,8 +74,8 @@ found">. (Also surfaced in the brief so ECO inherits them without re-reading.)
|
|
|
74
74
|
|
|
75
75
|
- **Constraints**: <perf budgets, compat, deadlines, security/compliance rules>.
|
|
76
76
|
- **Non-goals**: <explicitly out of scope — keeps execution from gold-plating>.
|
|
77
|
-
- **Open risks** (could not be fully settled at design time): <list — each becomes an "Open risks
|
|
78
|
-
must watch" row in the brief, with a surfacing trigger>.
|
|
77
|
+
- **Open risks** (could not be fully settled at design time): <list — each becomes an "Open risks
|
|
78
|
+
execution must watch" row in the brief, with a surfacing trigger>.
|
|
79
79
|
|
|
80
80
|
## 9. Handoff
|
|
81
81
|
|
package/templates/DIARY.md.tmpl
CHANGED
|
@@ -12,11 +12,16 @@ not deleted or rewritten; if you're wrong about something, write a new entry cor
|
|
|
12
12
|
> they reach for older entries only when a specific finding needs the backstory. So keep each entry
|
|
13
13
|
> short (one paragraph) and self-contained, and capture the *why*, not a diff dump.
|
|
14
14
|
>
|
|
15
|
-
> **
|
|
16
|
-
>
|
|
17
|
-
>
|
|
18
|
-
> verbatim
|
|
19
|
-
>
|
|
15
|
+
> **Compaction (mandatory, done by the writer).** Whoever appends an entry counts the `## ` entry
|
|
16
|
+
> headings afterwards. If there are **more than 40**, compact in the same edit: move every entry
|
|
17
|
+
> *older than the newest 15* whose category is `note`, `discovery`, `unblock`, `blocker`, or
|
|
18
|
+
> `review-feedback` **verbatim** to the end of a sibling `diary-archive.md` (create it if absent;
|
|
19
|
+
> keep newest-first order), and leave **one** entry in `diary.md` titled
|
|
20
|
+
> `Compacted: <oldest date> .. <newest date>` (category `note`) saying how many entries moved and
|
|
21
|
+
> pointing at `diary-archive.md`. **Never move a `decision-change` or `plan-change` entry** — they
|
|
22
|
+
> stay in `diary.md`, where the recent slice is read. Nothing is deleted; history only leaves the
|
|
23
|
+
> default read path. 40 keeps the file to roughly a screenful-per-entry skim; 15 keeps a full
|
|
24
|
+
> review cycle of context.
|
|
20
25
|
|
|
21
26
|
**Always write a diary entry when**:
|
|
22
27
|
|
package/templates/DOD.md.tmpl
CHANGED
|
@@ -5,6 +5,30 @@ where you want a **standalone** DoD outside the SoMi `.somi/plans/<slug>/` artif
|
|
|
5
5
|
team-level "shipping standard" checklist). For most work items, fill out §12 of `spec.md`
|
|
6
6
|
directly and ignore this file.
|
|
7
7
|
|
|
8
|
+
## Minimum-evidence standard
|
|
9
|
+
|
|
10
|
+
A box may be ticked only against evidence of a **stated kind** and a **stated quantity**. Write both
|
|
11
|
+
next to the criterion before you start, not after the result is in.
|
|
12
|
+
|
|
13
|
+
- **Kind** — a named test, a command and its expected output, or a described manual exercise.
|
|
14
|
+
"Verify before ticking" is not a standard: it names no evidence, so any result satisfies it.
|
|
15
|
+
- **Quantity** — one run or N runs; one file or every file in a set; one host or each supported
|
|
16
|
+
host. State N, and say why N is enough to tell "works" from "fails some of the time".
|
|
17
|
+
- Evidence of the wrong kind, or too small a quantity, does **not** satisfy the criterion even when
|
|
18
|
+
it is green. A passing result that could not have failed proves nothing.
|
|
19
|
+
|
|
20
|
+
Worked example — a latency claim:
|
|
21
|
+
|
|
22
|
+
- Weak: `[ ] Checkout p95 latency is under 300 ms (verified).`
|
|
23
|
+
Ticked after two runs, both under 300 ms. If the real failure rate is around 40%, two runs
|
|
24
|
+
pass together about a third of the time, so the green result says almost nothing.
|
|
25
|
+
- Fixed: `[ ] Checkout p95 latency is under 300 ms. Evidence: load-test command <cmd>, 20 runs on
|
|
26
|
+
the staging host, p95 reported per run; all 20 under 300 ms. Fewer than 20 runs, or a run on a
|
|
27
|
+
developer machine, does not count.`
|
|
28
|
+
|
|
29
|
+
If the evidence you can produce is smaller than the criterion needs, leave the box unticked and
|
|
30
|
+
say what is missing.
|
|
31
|
+
|
|
8
32
|
## Functional
|
|
9
33
|
|
|
10
34
|
- [ ] All planned iterations landed (per `phases/`).
|
|
@@ -43,14 +43,9 @@ state is here.
|
|
|
43
43
|
|
|
44
44
|
`Status`: `not-started` | `in-progress` | `done` | `blocked` | `superseded`.
|
|
45
45
|
`Reviewed`: latest `/review` verdict or `—`.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<What's actively being worked on right now. One paragraph or bullet.>
|
|
50
|
-
|
|
51
|
-
- **Active iteration**: phase <N>.<M> — <title>
|
|
52
|
-
- **Owner / driver**: <name>
|
|
53
|
-
- **Blocker (if any)**: <description, with link to diary entry or open question>
|
|
46
|
+
The iteration with `Status: in-progress` *is* the active one; put a blocker's reason in `Last activity`
|
|
47
|
+
(with a pointer to its diary entry). There is no separate "in flight" or "recent activity" section —
|
|
48
|
+
the narrative lives in [`diary.md`](./diary.md) only.
|
|
54
49
|
|
|
55
50
|
## Decisions outstanding
|
|
56
51
|
|
|
@@ -60,14 +55,6 @@ in `spec.md` §<N> or to a `decisions.md` entry still in `proposed` status.
|
|
|
60
55
|
- [ ] <decision 1 needed> — context in [`spec.md`](./spec.md) / [`decisions.md`](./decisions.md)
|
|
61
56
|
- [ ] <decision 2 needed>
|
|
62
57
|
|
|
63
|
-
## Recent activity
|
|
64
|
-
|
|
65
|
-
The last few notable events. Full history is in [`diary.md`](./diary.md); this is the recent slice.
|
|
66
|
-
|
|
67
|
-
- **<YYYY-MM-DD>**: <one-line event>
|
|
68
|
-
- **<YYYY-MM-DD>**: <one-line event>
|
|
69
|
-
- **<YYYY-MM-DD>**: <one-line event>
|
|
70
|
-
|
|
71
58
|
## Follow-ups identified
|
|
72
59
|
|
|
73
60
|
Out-of-scope items discovered during this work item. Filed for the future, not blocking completion.
|
|
@@ -14,15 +14,15 @@ at the root:
|
|
|
14
14
|
.somi/
|
|
15
15
|
├── README.md ← this file
|
|
16
16
|
├── atlas.md ← the Repo Atlas (from /atlas): SHA-stamped repo map that
|
|
17
|
-
│
|
|
17
|
+
│ design actions consume instead of re-reading the codebase
|
|
18
18
|
├── config.json ← optional committed policy: loop caps, dep-install
|
|
19
19
|
│ allowlist, lockfile policy (env vars override per session)
|
|
20
20
|
├── rd/ ← discovery initiatives (from /discover, greenfield)
|
|
21
21
|
│ └── clinic-scheduler/ ← research report, BRD, SRS, FRD, SDD, TDD, decisions,
|
|
22
|
-
│ diary, brief.md (the
|
|
22
|
+
│ diary, brief.md (the design→execution handoff), README index
|
|
23
23
|
├── plans/
|
|
24
24
|
│ ├── rate-limiting-webhooks/ ← one work item (slug from the problem statement)
|
|
25
|
-
│ │ ├── brief.md ←
|
|
25
|
+
│ │ ├── brief.md ← design→execution handoff (when /design or /discover ran upstream)
|
|
26
26
|
│ │ ├── context.md ← background, surrounding code, constraints
|
|
27
27
|
│ │ ├── spec.md ← purpose, requirements, core decisions, user story, DoD
|
|
28
28
|
│ │ ├── decisions.md ← ADR-style log of architectural choices
|
|
@@ -5,21 +5,22 @@
|
|
|
5
5
|
{
|
|
6
6
|
"name": "emits-reminder-on-first-turn-absent-signature",
|
|
7
7
|
"_note": "No .somi/plans, .somi/reviews, .somi/rd, or git repo staged at all — a genuinely fresh project. No prior state file exists in this case's throwaway CLAUDE_PROJECT_DIR/.somi/somi-state/, so LAST_SIG is empty and EMIT_REMINDER is forced to \"yes\" regardless of content. This is the baseline 'signature absent -> emission happens' proof the phase spec asks for, and the pairing partner for the two signature-gate cases below (same empty staging, but those add \"prime\").",
|
|
8
|
-
"expect_context": "somi is active. Reminders:\n- Follow
|
|
8
|
+
"expect_context": "somi is active. Reminders:\n- Follow SoMi's priority order: security > correctness > maintainability > performance > convenience.",
|
|
9
9
|
"expect_context_excludes": "loose-end check",
|
|
10
10
|
"payload": {}
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
13
|
"name": "signature-gate-suppresses-unchanged-repeat",
|
|
14
|
-
"_note": "
|
|
15
|
-
"
|
|
14
|
+
"_note": "CHANGED at phase 1 iteration 1.2 (D5's Tier 1/Tier 2 split): previously asserted \"expect_no_context\": true. Under Tier 1 (today's REMINDER_BODY) now unconditional, the hook can never again emit nothing at all — the PROPERTY this case exists to prove (no re-emission of the GATED content when nothing changed since the last turn) survives, but the assertion pinning it does not. Same (empty) staging as the case above, plus \"prime\": true, so the second call's signature equals what priming just persisted -> EMIT_REMINDER=\"no\" -> Tier 2 (the full digest, gated) is omitted, while Tier 1 still fires unconditionally. Retargeted: assert the Tier 1 floor text is present (proving the always-on floor really is always-on) AND a Tier-2-only substring (\"Reasoning craft:\", unique to the full digest — see the positive companion assertion on full-digest-fires-on-first-turn below, which keeps this negative assertion from going silently vacuous per F15) is absent (proving the gate still suppresses Tier 2 on an unchanged repeat).",
|
|
15
|
+
"expect_context": "somi is active. Reminders:",
|
|
16
|
+
"expect_context_excludes": "Reasoning craft:",
|
|
16
17
|
"prime": true,
|
|
17
18
|
"payload": {}
|
|
18
19
|
},
|
|
19
20
|
{
|
|
20
21
|
"name": "signature-gate-reemits-when-state-changes",
|
|
21
|
-
"_note": "The required companion to the suppression case above, proving it is not vacuously green: identical empty baseline and identical \"prime\": true, but \"files_after_prime\" stages a brand-new .somi/reviews/probe/note.md between the priming call and the real one. The reviews_state segment of the hook's signature (find .somi/reviews -maxdepth 3 -name '*.md' | sort | sha256sum) now differs from what priming persisted, so the real call's LAST_SIG != CURRENT_SIG and
|
|
22
|
-
"expect_context": "
|
|
22
|
+
"_note": "The required companion to the suppression case above, proving it is not vacuously green: identical empty baseline and identical \"prime\": true, but \"files_after_prime\" stages a brand-new .somi/reviews/probe/note.md between the priming call and the real one. The reviews_state segment of the hook's signature (find .somi/reviews -maxdepth 3 -name '*.md' | sort | sha256sum) now differs from what priming persisted, so the real call's LAST_SIG != CURRENT_SIG and Tier 2 is emitted again.\n\nRETARGETED at iteration 1.2 pass 2 (F-30). This case previously asserted only \"somi is active. Reminders:\" — Tier 1 text, which D5 made UNCONDITIONAL, so the assertion could never fail and the case went silently vacuous. Measured: deleting the `|| lastSig !== currentSig` half of the gate (Tier 2 never re-fires on a state change) left the whole suite green on the 1.2 diff, while the identical mutation against a `git archive HEAD` copy turned this case red — i.e. this iteration REGRESSED a guarantee the suite previously held. Now asserts a Tier-2-only substring, so it fails closed if the state-change branch of the gate is ever broken. This is also scope point 7's required 'digest fires on a state-change turn' half (full-digest-fires-on-first-turn covers the first-turn half).",
|
|
23
|
+
"expect_context": "Reasoning craft:",
|
|
23
24
|
"prime": true,
|
|
24
25
|
"files_after_prime": {
|
|
25
26
|
".somi/reviews/probe/note.md": "throwaway review note used only to change the reviews_state hash\n"
|
|
@@ -112,15 +113,127 @@
|
|
|
112
113
|
},
|
|
113
114
|
{
|
|
114
115
|
"name": "nudge-fires-independent-of-suppressed-reminder",
|
|
115
|
-
"_note": "Combines the signature-gate mechanism with a nudge to pin a subtle, easy-to-regress interaction: NUDGES are computed unconditionally every call, while the
|
|
116
|
+
"_note": "CHANGED at phase 1 iteration 1.2 (D5's Tier 1/Tier 2 split): previously asserted \"expect_context_excludes\": \"somi is active. Reminders:\" to prove the reminder stayed suppressed while a nudge fired. That substring (Tier 1) is now always present, so the old assertion is unmeetable as worded — retargeted to the Tier-2-only substring instead, which keeps proving the same property this case exists for. Combines the signature-gate mechanism with a nudge to pin a subtle, easy-to-regress interaction: NUDGES are computed unconditionally every call, while Tier 2 (the full digest, with PLAN_HINT/RD_HINT inside it) is gated on EMIT_REMINDER alone, and Tier 1 (REMINDER_BODY) is unconditional — three independent branches in the same PARTS array, none gated by another. \"prime\" establishes a git repo with no loose ends yet (first call: absent signature, Tier 1 + Tier 2 both emit, discarded); \"files_after_prime\" then lands an untracked scratch file with the signature-relevant state (.somi/plans|reviews|rd) completely unchanged, so the real call's Tier 2 is suppressed exactly as in signature-gate-suppresses-unchanged-repeat (Tier 1 still fires, per D5), yet the loose-end nudge still fires — a naive port that nested the nudge check inside the same `if EMIT_REMINDER` branch as Tier 2 would silently drop end-of-turn nudges on every suppressed turn, a real regression this case is designed to catch.",
|
|
116
117
|
"expect_context": "Detected scratch / .bak files in working tree.",
|
|
117
|
-
"expect_context_excludes": "
|
|
118
|
+
"expect_context_excludes": "Reasoning craft:",
|
|
118
119
|
"setup_git": true,
|
|
119
120
|
"prime": true,
|
|
120
121
|
"files_after_prime": {
|
|
121
122
|
"scratch_debug.txt": "leftover debug output\n"
|
|
122
123
|
},
|
|
123
124
|
"payload": {}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"name": "full-digest-fires-on-first-turn",
|
|
128
|
+
"_note": "NEW at phase 1 iteration 1.2 (F15's positive companion assertion). The two retargeted cases above assert \"Reasoning craft:\" is ABSENT, which is true only by virtue of that bullet's current absence — vacuously satisfiable if a later phase (phase 4, most plausibly: longest and newest bullet, the likeliest trim target) ever trims or renames it. THIS case is the one that would actually go red if that happened: first turn, absent signature, no .somi/plans|reviews|rd staged, no CLAUDE_PLUGIN_ROOT/SOMI_VENDOR_ROOT set, so pluginRoot() falls to its import.meta.url fallback and reads THIS repo's own real, live rules/CLAUDE.md. Asserts the Reasoning craft bullet is present (Tier 2 genuinely fired via the real digest, not a stale/frozen copy). Sanity-checked per the phase's own mutation-check requirement: temporarily deleting the Reasoning craft bullet from rules/CLAUDE.md made this case fail loudly, then restoring it made the suite green again — recorded in diary.md, not just asserted here.\n\nNOTE CORRECTED at pass 2 (F-32): this note previously claimed 'and the trailing pointer line is present', which it did not assert — its only assertion was the Reasoning craft substring. Measured: deleting the pointer append left the whole suite green. The pointer is load-bearing (scope point 4 makes it the single replacement for the per-bullet paths that same point strips), so it now has its own dedicated case below — tier2-pointer-is-appended-and-trailing — rather than an unasserted claim in prose here.",
|
|
129
|
+
"expect_context": "Reasoning craft:",
|
|
130
|
+
"payload": {}
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"name": "citation-stripper-accepts-the-canonical-resolving-link-form",
|
|
134
|
+
"_note": "NEW at iteration 2.2 pass 3. Guards `stripDigestCitations()`'s ITEM_RE against a revert of the 2.2 widening, which is otherwise INVISIBLE. Measured by review: reverting ITEM_RE to the narrow pass-1 form (`rules/` segment REQUIRED) while keeping the corrected canonical left all 183 checks green -- 134 hook fixtures, 30 script checks, 19 generate-digest checks -- while a fresh-project probe injected 11 unresolvable markdown links into the gated turn. That is iteration 2.2's Blocker 2 reproduced exactly.\n\nWHY THE WIDENING IS NEEDED: rules/CLAUDE.md lives in rules/, so the citation form that actually RESOLVES from there is `./NN-name.md` with no `rules/` segment -- the form its own composition table already uses. The narrow regex accepted only `./rules/NN-name.md`, which resolves to rules/rules/ and is a dead link. The F14 round-trip appeared to pass in pass 1 precisely BECAUSE the canonical was broken; the bug and the test agreed with each other.\n\nWHY THIS CASE DISCRIMINATES: no `env` and no staged .somi/ dirs, so pluginRoot() falls through to the import.meta.url branch and reads THIS REPO's real rules/CLAUDE.md. The asserted substring is a bullet's rendered bare code, which appears only if ITEM_RE accepted the resolving form. Under the narrow regex the bullet is returned byte-identical with its markdown link intact, so the substring is absent and this case goes red. Confirmed both ways.\n\nNOTE the widened regex accepts BOTH forms, so a future edit that 'tidies' the canonical back to `./rules/NN-*.md` stays silently fine -- but an edit that tidies ITEM_RE is silently fatal. This case is the guard for the second, dangerous direction.",
|
|
135
|
+
"expect_context": "and say so. (`00`)",
|
|
136
|
+
"expect_context_excludes": "](./",
|
|
137
|
+
"payload": {}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"name": "tier2-pointer-is-appended-and-trailing",
|
|
141
|
+
"_note": "NEW at pass 2 (F-32 + F-33). Two properties, neither previously covered by any assertion.\n\n(1) F-32 — the rules-skill pointer exists at all. Measured before this case: deleting the append from buildTier2Digest() left all 130 fixtures green, while two other cases' _notes claimed the pointer was proven present. It is what replaces the per-bullet path assertions stripDigestCitations() removes, so without it Tier 2 strips citations to bare codes and offers no route to the full text.\n\n(2) F-33 — the pointer is genuinely LAST, after any plan/rd hint. The original code appended it inside buildTier2Digest(), then main() concatenated planHint/rdHint AFTER it, so a firing hint rendered as a dangling bullet hanging off a prose sentence — readable as an elaboration of 'load the rules skill' rather than as the work-item notice it is. Under HEAD that hint rendered as the fifth bullet of the Reminders list, so this was a real rendering regression, not merely cosmetic.\n\nStages an in-progress work item so planHint FIRES, then asserts the hint and the pointer appear in that order via a single contiguous expect_context spanning both — which fails if the pointer moves back ahead of the hint. First turn (absent signature) so Tier 2 is guaranteed to render.",
|
|
142
|
+
"expect_context": "update `progress.md` / `diary.md` as work proceeds.\n\nFor full detail on any of these, load the `rules` skill.",
|
|
143
|
+
"files": {
|
|
144
|
+
".somi/plans/demo-pointer/progress.md": "## Status\n\n`in-progress`\n"
|
|
145
|
+
},
|
|
146
|
+
"payload": {}
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"name": "prose-markdown-link-on-a-rejected-line-survives-untouched",
|
|
150
|
+
"_note": "NEW at pass 3 (F-37). Link flattening used to run on the WHOLE line before the recognizer, and both reject branches returned that flattened copy — so any line the recognizer DECLINED still had its markdown links destroyed. Measured: a bullet reading `read [the security file](./rules/30-security-owasp.md) before touching a sink` was injected as `read ./rules/30-security-owasp.md before touching a sink` — F19's exact output (a bare ENOENT path in a consuming project) reached through the opposite door, and via the `!citationMatch` branch, which has nothing to do with citations. The function's name and doc comment promised 'rewrites each line's trailing citation'; it in fact rewrote every markdown link on every line it touched, including lines it had explicitly decided not to handle.\n\nWIDENED at pass 4: the first version staged only a prose-link bullet with no trailing parenthetical, which exercises just ONE of the function's three flattening paths — the `!citationMatch` early return. Measured: restoring the flattened-copy leak on the OTHER reject branch, and separately splicing the SUCCESS path's prefix from a flattened copy, each left all 134 fixtures green. Both reproduce F19's exact output (bare `./rules/NN-*.md` injected into Tier 2) and neither would have turned the suite red.\n\nThree adjacent bullets now cover all three paths in one contiguous assertion: (1) prose link, NO parenthetical -> `!citationMatch` reject; (2) prose link + a REJECTED citation `(ISO 27001)` -> `!allItemsAreCitations` reject; (3) prose link + an ACCEPTED citation `` (`40`) `` -> success path, where the prefix must be spliced from the ORIGINAL line so the in-prose link survives while the citation rewrites. The assertion spans all three lines, so any of the three leaks turns this case red.\n\nNote on an earlier overstatement: per-line (rather than block-level all-or-nothing) rejection is pinned by `plugin-root-env-resolves-and-strips-links`, not by this case — an earlier version of this note credited it here. Bullet (3) now makes the claim true of this case as well, since it proves an accepted and a rejected bullet coexist correctly in one block.",
|
|
151
|
+
"expect_context": "- **Security:** read [the security file](./rules/30-security-owasp.md) before touching a sink\n- **Compliance:** read [the guide](./rules/00-priorities.md) then apply (ISO 27001)\n- **Testing:** see [the tests file](./rules/40-engineering-practices.md) for detail. (`40`)",
|
|
152
|
+
"env": {
|
|
153
|
+
"CLAUDE_PLUGIN_ROOT": "{{CASE_DIR}}/prose-link-root"
|
|
154
|
+
},
|
|
155
|
+
"files": {
|
|
156
|
+
"prose-link-root/rules/CLAUDE.md": "# Engineering OS — Global Rules\n\n## Always-on digest\n\nThis digest is always in force for this scratch fixture.\n\n<!-- digest:start -->\n- **Security:** read [the security file](./rules/30-security-owasp.md) before touching a sink\n- **Compliance:** read [the guide](./rules/00-priorities.md) then apply (ISO 27001)\n- **Testing:** see [the tests file](./rules/40-engineering-practices.md) for detail. (`40`)\n<!-- digest:end -->\n\n## rest\n"
|
|
157
|
+
},
|
|
158
|
+
"payload": {}
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"name": "non-citation-parenthetical-is-not-rewritten-as-a-rule-code",
|
|
162
|
+
"_note": "NEW at pass 2 (F-34). stripDigestCitations()'s recognizer previously scanned the line-final parenthetical UNANCHORED for any two-digit run, so any such parenthetical became a rule citation. Measured against a staged digest: a bullet ending `(ISO 27001)` was injected as `(`27`, `00`)` — a FABRICATED citation to two rule files, delivered into the model's context as fact. The function already had the right escape hatch (codes.length === 0 -> leave untouched); the recognizer was simply too loose to ever reach it.\n\nNot hypothetical for this work item: phase 4 iteration 4.2 rewraps and trims this exact block, which is precisely when a non-citation parenthetical most plausibly lands at end-of-line.\n\nThe recognizer is now anchored — the whole parenthetical body must BE a comma-separated citation list (`NN` / bare NN / (./)rules/NN-*.md) or the line is returned untouched. `ISO 27001` fails because `27001` is not a two-digit item. Asserts the bullet survives VERBATIM and that no fabricated backticked code appears.",
|
|
163
|
+
"expect_context": "follow the control set (ISO 27001)",
|
|
164
|
+
"expect_context_excludes": "(`27`",
|
|
165
|
+
"env": {
|
|
166
|
+
"CLAUDE_PLUGIN_ROOT": "{{CASE_DIR}}/iso-plugin-root"
|
|
167
|
+
},
|
|
168
|
+
"files": {
|
|
169
|
+
"iso-plugin-root/rules/CLAUDE.md": "# Engineering OS — Global Rules\n\n## Always-on digest\n\nThis digest is always in force for this scratch fixture.\n\n<!-- digest:start -->\n- **Compliance:** follow the control set (ISO 27001)\n- **Priorities:** security first. (`00`)\n<!-- digest:end -->\n\n## rest\n"
|
|
170
|
+
},
|
|
171
|
+
"payload": {}
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"name": "plan-hint-rides-tier2-and-is-suppressed-when-gated",
|
|
175
|
+
"_note": "NEW at pass 2 (F-36). Scope point 3 deliberately pins planHint/rdHint to Tier 2 — 'preserves their existing behavior unchanged rather than introducing a new, unrequested always-on behavior' — and D5's tier semantics turn on it. Measured before this case: moving both hints into Tier 1's part and removing them from Tier 2 left all 130 fixtures green, so nothing stopped a later refactor flipping the pin silently. The discriminating case did not exist because no fixture combined a SUPPRESSED turn with a staged active plan: the six existing hint cases all run on a first turn, where Tier 2 fires anyway and so cannot distinguish the tiers.\n\nStages the work item in \"files\" (present BEFORE priming, so the signature priming persists already accounts for it and the real call sees LAST_SIG == CURRENT_SIG -> Tier 2 suppressed), with \"prime\": true. Tier 1 must still fire; the hint must NOT appear. If the hints were moved to Tier 1, this case goes red.",
|
|
176
|
+
"expect_context": "somi is active. Reminders:",
|
|
177
|
+
"expect_context_excludes": "Active work item",
|
|
178
|
+
"prime": true,
|
|
179
|
+
"files": {
|
|
180
|
+
".somi/plans/demo-gated/progress.md": "## Status\n\n`in-progress`\n"
|
|
181
|
+
},
|
|
182
|
+
"payload": {}
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"name": "tier2-omitted-when-digest-markers-malformed",
|
|
186
|
+
"_note": "NEW at phase 1 iteration 1.2 — the fail-safe path the phase spec requires: 'a missing/malformed rules/CLAUDE.md fails safe (Tier 1 floor still fires, Tier 2 silently omitted, no crash)'. CLAUDE_PLUGIN_ROOT points at a scratch directory whose rules/CLAUDE.md EXISTS and IS readable (so pluginRoot()'s existence-validation accepts it as the resolved candidate and does not fall through to any later candidate) but carries no <!-- digest:start/end --> markers at all — the exact 'malformed' case distinct from the 'missing entirely' case covered by the pluginRoot()-branch cases below (existence-validation only guarantees the FILE is present and readable, never that its content parses; content-level failure is buildTier2Digest()'s own responsibility, checked here). Asserts Tier 1 still fires (the always-on floor is unaffected by Tier 2's source being broken) and Tier 2 is silently absent (no 'Reasoning craft:', which would only be present via a fallthrough to the real repo digest that must NOT happen here) — and, since the runner itself fails any case whose hook process exits non-zero, a passing case is also proof the malformed input did not crash the hook.",
|
|
187
|
+
"expect_context": "somi is active. Reminders:",
|
|
188
|
+
"expect_context_excludes": "Reasoning craft:",
|
|
189
|
+
"env": {
|
|
190
|
+
"CLAUDE_PLUGIN_ROOT": "{{CASE_DIR}}/broken-plugin-root"
|
|
191
|
+
},
|
|
192
|
+
"files": {
|
|
193
|
+
"broken-plugin-root/rules/CLAUDE.md": "# Engineering OS — Global Rules\n\nNo digest markers anywhere in this file — simulates a malformed rules/CLAUDE.md that pluginRoot() still accepts (the file exists and is readable) but that Tier 2 extraction cannot parse.\n"
|
|
194
|
+
},
|
|
195
|
+
"payload": {}
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"name": "plugin-root-env-resolves-and-strips-links",
|
|
199
|
+
"_note": "NEW at phase 1 iteration 1.2 — pluginRoot() branch (a): CLAUDE_PLUGIN_ROOT set and resolves (the plugin-install path). The staged scratch rules/CLAUDE.md's one bullet carries a FULL markdown-link citation (`([rules/00-priorities.md](./rules/00-priorities.md))`), matching the form phase 2 iteration 2.2 will normalize the canonical file to — proving stripDigestCitations() actually rewrites that form, not just today's already-bare one.\n\nASSERTION STRENGTHENED at pass 2 (F-31). The previous exclude — the exact unstripped-link fragment — was measured NON-DISCRIMINATING: mutating stripDigestCitations() to flatten the link to its target and stop injects `(./rules/00-priorities.md)`, six ENOENT path assertions in a consuming project (the plan's verbatim failure mode: 'still a path assertion, merely no longer clickable'), and the whole suite stayed GREEN. It was strictly weaker than the 'no [...](...) syntax' check the plan had already rejected as insufficient.\n\nIt now uses the plan's ORIGINAL F19 wording — a flat 'no rules/ substring anywhere' — which became satisfiable this pass once F-35 removed the `rules/CLAUDE.md` path from REMINDER_BODY. That was the real blocker: the acceptance line was never wrong, it was blocked by a second instance of the very defect it targets. The positive assertion is now the full rewritten tail including the bare-code citation, so a partial strip (which leaves a path where `(`00`)` belongs) fails on BOTH assertions.",
|
|
200
|
+
"expect_context": "proves the CLAUDE_PLUGIN_ROOT branch resolved. (`00`)",
|
|
201
|
+
"expect_context_excludes": "rules/",
|
|
202
|
+
"env": {
|
|
203
|
+
"CLAUDE_PLUGIN_ROOT": "{{CASE_DIR}}/plugin-install"
|
|
204
|
+
},
|
|
205
|
+
"files": {
|
|
206
|
+
"plugin-install/rules/CLAUDE.md": "# Engineering OS — Global Rules\n\n## Always-on digest\n\nThis digest is always in force for this scratch fixture.\n\n<!-- digest:start -->\n- **Plugin-root marker:** proves the CLAUDE_PLUGIN_ROOT branch resolved. ([rules/00-priorities.md](./rules/00-priorities.md))\n<!-- digest:end -->\n\n## rest\n"
|
|
207
|
+
},
|
|
208
|
+
"payload": {}
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"name": "vendor-root-env-resolves-when-plugin-root-absent",
|
|
212
|
+
"_note": "NEW at phase 1 iteration 1.2 — pluginRoot() branch (b): SOMI_VENDOR_ROOT set and resolves, with CLAUDE_PLUGIN_ROOT absent (the vendored-install path; run.sh unsets any ambient CLAUDE_PLUGIN_ROOT/SOMI_VENDOR_ROOT by default — see the runner's env sanitization — so this case's absence of CLAUDE_PLUGIN_ROOT is genuine, not accidental). Asserts the synthetic bullet fired and the real repo's 'Reasoning craft:' bullet did NOT (confirming this branch, not the import.meta.url fallback, supplied Tier 2's content).",
|
|
213
|
+
"expect_context": "Vendor-root marker",
|
|
214
|
+
"expect_context_excludes": "Reasoning craft:",
|
|
215
|
+
"env": {
|
|
216
|
+
"SOMI_VENDOR_ROOT": "{{CASE_DIR}}/vendor-install"
|
|
217
|
+
},
|
|
218
|
+
"files": {
|
|
219
|
+
"vendor-install/rules/CLAUDE.md": "# Engineering OS — Global Rules\n\n## Always-on digest\n\nThis digest is always in force for this scratch fixture.\n\n<!-- digest:start -->\n- **Vendor-root marker:** proves the SOMI_VENDOR_ROOT branch resolved when CLAUDE_PLUGIN_ROOT is absent. (`00`)\n<!-- digest:end -->\n\n## rest\n"
|
|
220
|
+
},
|
|
221
|
+
"payload": {}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"name": "plugin-root-env-set-but-unreadable-falls-through",
|
|
225
|
+
"_note": "NEW at phase 1 iteration 1.2 — the existence-validation case the whole correction (decisions.md#d5's F2 correction note) exists to prove: CLAUDE_PLUGIN_ROOT is SET but points at a path with no rules/CLAUDE.md underneath it at all (nothing staged there), and SOMI_VENDOR_ROOT is absent. A presence-only chain would accept CLAUDE_PLUGIN_ROOT's value, find nothing, and stop there — silently omitting Tier 2 exactly as this repo's own '.claude/settings.json' would trigger for SOMI_VENDOR_ROOT today. Asserts Tier 2 still fires (via the import.meta.url fallback, reading the real repo digest) — proving the bad candidate was skipped, not accepted.",
|
|
226
|
+
"expect_context": "Reasoning craft:",
|
|
227
|
+
"env": {
|
|
228
|
+
"CLAUDE_PLUGIN_ROOT": "{{CASE_DIR}}/nonexistent-plugin-root"
|
|
229
|
+
},
|
|
230
|
+
"payload": {}
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"name": "neither-plugin-root-nor-vendor-root-set-falls-back-to-import-meta-url",
|
|
234
|
+
"_note": "NEW at phase 1 iteration 1.2 — pluginRoot() branch (c), the final fallback: neither CLAUDE_PLUGIN_ROOT nor SOMI_VENDOR_ROOT is set at all (distinct from the previous case, which has CLAUDE_PLUGIN_ROOT set-but-broken; this one has no env override declared, and the runner's sanitized environment guarantees neither var leaks in ambiently — see run.sh's env sanitization). This is what this repo's own dev/test invocations (including this very test suite) actually exercise for every OTHER case in this file that doesn't declare CLAUDE_PLUGIN_ROOT/SOMI_VENDOR_ROOT. Asserts Tier 2 fires via the real repo digest.",
|
|
235
|
+
"expect_context": "Reasoning craft:",
|
|
236
|
+
"payload": {}
|
|
124
237
|
}
|
|
125
238
|
]
|
|
126
239
|
}
|
package/tests/hooks/run.sh
CHANGED
|
@@ -58,11 +58,13 @@
|
|
|
58
58
|
# mtimes changes deterministically, with no sleep/timing dependency,
|
|
59
59
|
# rather than relying on touching an existing file's mtime). Only
|
|
60
60
|
# meaningful alongside "prime".
|
|
61
|
-
# - A payload may reference the literal token
|
|
62
|
-
# with the case's absolute throwaway-dir path
|
|
63
|
-
# hooks that check real absolute paths (e.g.
|
|
64
|
-
# `[[ -f "$PATH_INPUT" ]]
|
|
65
|
-
#
|
|
61
|
+
# - A payload, or a value inside "env", may reference the literal token
|
|
62
|
+
# "{{CASE_DIR}}", substituted with the case's absolute throwaway-dir path
|
|
63
|
+
# before the hook runs — for hooks that check real absolute paths (e.g.
|
|
64
|
+
# lint-changed-files.sh's `[[ -f "$PATH_INPUT" ]]`, or
|
|
65
|
+
# inject-workflow-context.mjs's pluginRoot() reading CLAUDE_PLUGIN_ROOT /
|
|
66
|
+
# SOMI_VENDOR_ROOT), so a case can point at a file staged via "files"
|
|
67
|
+
# without hardcoding a path the hook's own CWD wouldn't resolve.
|
|
66
68
|
# - "expect_context": asserted as a substring of
|
|
67
69
|
# `.hookSpecificOutput.additionalContext` — for PostToolUse/UserPromptSubmit/
|
|
68
70
|
# SessionStart hooks that surface context instead of a permission decision.
|
|
@@ -99,10 +101,13 @@
|
|
|
99
101
|
# instead.
|
|
100
102
|
#
|
|
101
103
|
# The runner pipes each payload into the script under a sanitized environment
|
|
102
|
-
# (session opt-ins unset unless the case sets them;
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
104
|
+
# (session opt-ins unset unless the case sets them; CLAUDE_PLUGIN_ROOT and
|
|
105
|
+
# SOMI_VENDOR_ROOT are also unset unless the case sets them — otherwise
|
|
106
|
+
# whatever's ambient in the environment running `npm test` would leak into
|
|
107
|
+
# pluginRoot()'s fixture cases, phase 1 iteration 1.2; SOMI_AUDIT_LOG defaults
|
|
108
|
+
# to a per-case throwaway file, "$case_dir/audit.log", so audit writes never
|
|
109
|
+
# leak across cases; CLAUDE_PROJECT_DIR points at the same throwaway per-case
|
|
110
|
+
# dir, into which the optional `config` object is written as .somi/config.json)
|
|
106
111
|
# and asserts every expectation the case declares.
|
|
107
112
|
#
|
|
108
113
|
# Wired into scripts/validate.sh (npm test) — CI fails when a pattern change
|
|
@@ -248,6 +253,10 @@ for case_file in "$CASES_DIR"/*.json; do
|
|
|
248
253
|
env_args=("SOMI_AUDIT_LOG=$case_dir/audit.log" "CLAUDE_PROJECT_DIR=$case_dir")
|
|
249
254
|
while IFS= read -r kv; do
|
|
250
255
|
[[ -z "$kv" ]] && continue
|
|
256
|
+
# {{CASE_DIR}} in an env value resolves the same way it does in the payload (see header
|
|
257
|
+
# comment) — needed for a case to point CLAUDE_PLUGIN_ROOT / SOMI_VENDOR_ROOT at its own
|
|
258
|
+
# throwaway case directory (pluginRoot()'s fixture cases, phase 1 iteration 1.2).
|
|
259
|
+
kv="${kv//\{\{CASE_DIR\}\}/$case_dir}"
|
|
251
260
|
env_args+=("$kv")
|
|
252
261
|
done < <(jq -r ".cases[$i].env // {} | to_entries[] | \"\(.key)=\(.value)\"" "$case_file")
|
|
253
262
|
|
|
@@ -258,7 +267,7 @@ for case_file in "$CASES_DIR"/*.json; do
|
|
|
258
267
|
prime="$(jq -r ".cases[$i].prime // false" "$case_file")"
|
|
259
268
|
if [[ "$prime" == "true" ]]; then
|
|
260
269
|
if ! printf '%s' "$payload" \
|
|
261
|
-
| env -u SOMI_ALLOW_DEP_INSTALL -u SOMI_ALLOW_LOCKFILES "${env_args[@]}" "${cmd[@]}" >/dev/null; then
|
|
270
|
+
| env -u SOMI_ALLOW_DEP_INSTALL -u SOMI_ALLOW_LOCKFILES -u CLAUDE_PLUGIN_ROOT -u SOMI_VENDOR_ROOT "${env_args[@]}" "${cmd[@]}" >/dev/null; then
|
|
262
271
|
echo "FAIL: [$script_rel] $name — priming invocation exited non-zero" >&2
|
|
263
272
|
failures=$((failures + 1))
|
|
264
273
|
continue
|
|
@@ -270,7 +279,7 @@ for case_file in "$CASES_DIR"/*.json; do
|
|
|
270
279
|
fi
|
|
271
280
|
|
|
272
281
|
if ! out="$(printf '%s' "$payload" \
|
|
273
|
-
| env -u SOMI_ALLOW_DEP_INSTALL -u SOMI_ALLOW_LOCKFILES "${env_args[@]}" "${cmd[@]}")"; then
|
|
282
|
+
| env -u SOMI_ALLOW_DEP_INSTALL -u SOMI_ALLOW_LOCKFILES -u CLAUDE_PLUGIN_ROOT -u SOMI_VENDOR_ROOT "${env_args[@]}" "${cmd[@]}")"; then
|
|
274
283
|
echo "FAIL: [$script_rel] $name — hook exited non-zero" >&2
|
|
275
284
|
failures=$((failures + 1))
|
|
276
285
|
continue
|
|
@@ -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"
|