@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,195 @@
1
+ #!/usr/bin/env bash
2
+ # Cross-checks agents/somi.md's dispatch instructions against both dispatch surfaces' real
3
+ # behavior. A prompt cannot be exercised without a model, but what it tells the model to RUN can
4
+ # be: the primary path is the bundled somi_resolve/somi_command MCP tools (checked against the
5
+ # real server below, driven rather than hand-typed), and the CLI fallback invocation shape plus the
6
+ # exit codes Step 4 maps must still be real and current against scripts/somi-dispatch.mjs, not
7
+ # prose that quietly drifted from either surface it describes.
8
+ set -uo pipefail
9
+
10
+ ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
11
+ AGENT_MD="$ROOT_REPO/agents/somi.md"
12
+ SKILL_MD="$ROOT_REPO/skills/somi-dispatch/SKILL.md"
13
+ CLI="$ROOT_REPO/scripts/somi-dispatch.mjs"
14
+ COMMAND_MDS="$ROOT_REPO"/commands/*.md
15
+
16
+ pass=0; fail=0
17
+ ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
18
+ bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
19
+
20
+ echo "== somi agent <-> somi-dispatch.mjs dispatch contract =="
21
+
22
+ TMP="$(mktemp -d)"
23
+ trap 'rm -rf "$TMP"' EXIT
24
+ fresh() { mktemp -d -p "$TMP"; }
25
+ reach() { # $1=name $2=want-exit-code, remaining = CLI args after 'resolve'
26
+ local name="$1" want="$2" rc=0
27
+ shift 2
28
+ CLAUDE_PROJECT_DIR="$(fresh)" node "$CLI" resolve "$@" >/dev/null 2>&1 || rc=$?
29
+ if [ "$rc" = "$want" ]; then ok "$name"; else bad "$name (expected exit $want, got $rc)"; fi
30
+ }
31
+
32
+ # --- the CLI-fallback invocation shape is named in skills/somi-dispatch/SKILL.md (the resolve
33
+ # procedure lives there so every command that Tasks an agent shares it, not just the front door) --
34
+ # checked against the skill and, for belt-and-braces, agents/somi.md too, since either file could
35
+ # carry the wording after a future edit.
36
+ if grep -qF 'resolve --agent <agent name> --host <host>' "$AGENT_MD" "$SKILL_MD"; then
37
+ ok "skills/somi-dispatch/SKILL.md names the 'resolve --agent ... --host ...' invocation shape"
38
+ else
39
+ bad "neither agents/somi.md nor skills/somi-dispatch/SKILL.md names the resolve --agent/--host CLI fallback shape -- if the wording changed intentionally, update this test to match it"
40
+ fi
41
+
42
+ out="$(CLAUDE_PROJECT_DIR="$(fresh)" node "$CLI" resolve --agent coder --host claude-code)"; rc=$?
43
+ if [ "$rc" -eq 0 ] && node -e 'JSON.parse(process.argv[1])' "$out" >/dev/null 2>&1; then
44
+ ok "the literal CLI-fallback invocation Step 4 names succeeds against the real CLI and prints valid JSON"
45
+ else
46
+ bad "Step 4's CLI-fallback invocation does not succeed against the real CLI (rc=$rc, out=$out)"
47
+ fi
48
+
49
+ # --- the two host values the dispatch skill names are the CLI's own recognized host strings -------
50
+ if grep -q '`claude-code` if this turn is running in Claude Code' "$AGENT_MD" "$SKILL_MD" \
51
+ && grep -q '`copilot` if.*running in GitHub Copilot' "$AGENT_MD" "$SKILL_MD"; then
52
+ ok "skills/somi-dispatch/SKILL.md names claude-code and copilot precisely as the two --host values"
53
+ else
54
+ bad "neither agents/somi.md nor skills/somi-dispatch/SKILL.md clearly names both claude-code and copilot as --host values"
55
+ fi
56
+ for h in claude-code copilot; do
57
+ hrc=0
58
+ CLAUDE_PROJECT_DIR="$(fresh)" node "$CLI" resolve --agent coder --host "$h" >/dev/null 2>&1 || hrc=$?
59
+ if [ "$hrc" = "0" ]; then ok "--host $h is accepted by the real CLI"; else bad "--host $h was rejected (rc=$hrc)"; fi
60
+ done
61
+
62
+ # --- the exit codes the dispatch skill maps are EXACTLY the CLI's real EXIT_* constants -----------
63
+ PROMPT_CODES="$(grep -ohE '^- `[0-9]+`' "$AGENT_MD" "$SKILL_MD" | grep -oE '[0-9]+' | sort -un | tr '\n' ' ')"
64
+ CLI_CODES="$(grep -oE '^const EXIT_[A-Z_]+ = [0-9]+;' "$CLI" | grep -oE '[0-9]+' | sort -un | tr '\n' ' ')"
65
+ if [ -n "$PROMPT_CODES" ] && [ "$PROMPT_CODES" = "$CLI_CODES" ]; then
66
+ ok "the exit codes skills/somi-dispatch/SKILL.md maps ($PROMPT_CODES) exactly match the CLI's real EXIT_* constants ($CLI_CODES)"
67
+ else
68
+ bad "the mapped exit codes ($PROMPT_CODES) do not match the CLI's real EXIT_* constants ($CLI_CODES)"
69
+ fi
70
+
71
+ # --- each code Step 4 maps is genuinely reachable against the real CLI, not merely documented -----
72
+ reach "64 (usage) is reachable: missing --agent" 64
73
+ reach "65 (unknown agent) is reachable" 65 --agent totally-not-a-real-agent
74
+ reach "66 (malformed declaration) is reachable: somi is exempt from cost:" 66 --agent somi
75
+
76
+ R67="$(fresh)"; mkdir -p "$R67/.somi"
77
+ printf '{"cost": {"ceiling": "low"}\n' > "$R67/.somi/config.json" # missing closing brace
78
+ r67rc=0
79
+ CLAUDE_PROJECT_DIR="$R67" node "$CLI" resolve --agent coder >/dev/null 2>&1 || r67rc=$?
80
+ if [ "$r67rc" = "67" ]; then
81
+ ok "67 (project environment/config failure) is reachable: unparsable .somi/config.json"
82
+ else
83
+ bad "67 was not reachable via an unparsable config.json (got $r67rc)"
84
+ fi
85
+
86
+ # 67 is also reachable AFTER a session already bootstrapped successfully (M1: a config error must
87
+ # never surface as 66, blamed on the agent's own cost: declaration, just because it happened on a
88
+ # LATER call than the one that wrote .somi/somi-state/ceiling.json).
89
+ R67_POST="$(fresh)"; mkdir -p "$R67_POST/.somi"
90
+ printf '{"cost": {"ceiling": "high"}}\n' > "$R67_POST/.somi/config.json"
91
+ CLAUDE_PROJECT_DIR="$R67_POST" node "$CLI" resolve --agent coder >/dev/null 2>&1 # bootstrap
92
+ printf '{"cost": {"ceiling": "high"}\n' > "$R67_POST/.somi/config.json" # now corrupt
93
+ r67postrc=0
94
+ CLAUDE_PROJECT_DIR="$R67_POST" node "$CLI" resolve --agent coder >/dev/null 2>&1 || r67postrc=$?
95
+ if [ "$r67postrc" = "67" ]; then
96
+ ok "67 is reachable even AFTER a successful bootstrap, not just on a fresh project"
97
+ else
98
+ bad "config corrupted after bootstrap did not reach 67 (got $r67postrc) -- may be misattributed to 66"
99
+ fi
100
+
101
+
102
+ # --- agents/somi.md + skills/somi-dispatch/SKILL.md's tool/argument names match the REAL
103
+ # somi-mcp.mjs tools/list --------------------------------------------------------------------------
104
+ # Step 4/5 now call the bundled MCP tools as their primary path (the CLI above is the fallback, only
105
+ # where SoMi's own install path is already known); the RESOLVE side of that (somi_resolve's
106
+ # arguments, fallback order, exit-code mapping) moved out of agents/somi.md into
107
+ # skills/somi-dispatch/SKILL.md so every command that Tasks an agent directly shares it too --
108
+ # agents/somi.md keeps only what's specific to the front door (somi_command, the classify/recursion
109
+ # steps). So this section checks the UNION of both files: wherever a given rule now lives, it must
110
+ # still be there, and it must still be derived from the REAL server, never a hand-typed second copy
111
+ # of scripts/somi-mcp.mjs's TOOLS table, which is exactly the kind of copy that quietly drifts.
112
+ echo "== agents/somi.md + skills/somi-dispatch/SKILL.md <-> somi-mcp.mjs tool/argument contract =="
113
+
114
+ SCHEMA_JSON="$(node "$ROOT_REPO/tests/scripts/lib/somi-mcp-tool-schema.mjs" 2>/dev/null || true)"
115
+ if [ -z "$SCHEMA_JSON" ] || ! node -e 'JSON.parse(process.argv[1])' "$SCHEMA_JSON" >/dev/null 2>&1; then
116
+ bad "could not drive scripts/somi-mcp.mjs's real tools/list to derive its schema"
117
+ else
118
+ ok "drove the real MCP server to derive its tools/list schema"
119
+
120
+ schema_field() { node -e '
121
+ const s = JSON.parse(process.argv[1])[process.argv[2]] || {};
122
+ console.log((s[process.argv[3]] || []).join(" "));
123
+ ' "$SCHEMA_JSON" "$1" "$2"; }
124
+
125
+ # The UNION of the front door, the skill, AND every commands/*.md file -- a command's own
126
+ # dispatch-reference line now names `somi_resolve`/`somi_skill` directly (not just a link to the
127
+ # skill), so a stale or invented tool name there would otherwise go unchecked: the skill/front-door
128
+ # pair alone can't see a typo that only ever appears in a command file.
129
+ REAL_TOOLS="$(node -e 'console.log(Object.keys(JSON.parse(process.argv[1])).sort().join(" "))' "$SCHEMA_JSON")"
130
+ PROMPT_TOOLS="$(grep -ohE '`somi_[a-z_]+`' "$AGENT_MD" "$SKILL_MD" $COMMAND_MDS | tr -d '`' | sort -u | tr '\n' ' ' | sed 's/ *$//')"
131
+ if [ "$REAL_TOOLS" = "$PROMPT_TOOLS" ]; then
132
+ ok "agents/somi.md + skills/somi-dispatch/SKILL.md + commands/*.md together name exactly the server's real tools ($REAL_TOOLS)"
133
+ else
134
+ bad "tool-name mismatch -- server: [$REAL_TOOLS] vs agents/somi.md + skills/somi-dispatch/SKILL.md + commands/*.md: [$PROMPT_TOOLS]"
135
+ fi
136
+
137
+ # somi_resolve: every REAL property must be named somewhere across the two files (nothing silently
138
+ # dropped) -- and every key the skill's own canonical invocation example passes must be a REAL
139
+ # property (nothing invented, nothing stale).
140
+ REAL_RESOLVE_PROPS="$(schema_field somi_resolve properties)"
141
+ for prop in $REAL_RESOLVE_PROPS; do
142
+ if grep -qE "\b${prop}\b" "$AGENT_MD" "$SKILL_MD"; then
143
+ ok "somi_resolve's real argument '$prop' is named in agents/somi.md or skills/somi-dispatch/SKILL.md"
144
+ else
145
+ bad "somi_resolve's real argument '$prop' is never mentioned in agents/somi.md or skills/somi-dispatch/SKILL.md"
146
+ fi
147
+ done
148
+
149
+ SNIPPET="$(cat "$AGENT_MD" "$SKILL_MD" | sed -n '/somi_resolve({ agent:/,/})/p')"
150
+ if [ -z "$SNIPPET" ]; then
151
+ bad "neither agents/somi.md nor skills/somi-dispatch/SKILL.md has a somi_resolve({ agent: ...}) canonical invocation example -- if the wording changed intentionally, update this test to match it"
152
+ else
153
+ ok "found the canonical somi_resolve invocation example (skills/somi-dispatch/SKILL.md)"
154
+ SNIPPET_KEYS="$(printf '%s' "$SNIPPET" | grep -oE '[a-zA-Z_]+:' | tr -d ':' | sort -u | tr '\n' ' ' | sed 's/ *$//')"
155
+ for key in $SNIPPET_KEYS; do
156
+ case " $REAL_RESOLVE_PROPS " in
157
+ *" $key "*) ok "the example's argument '$key' is a real somi_resolve property" ;;
158
+ *) bad "the example passes '$key', which is not a real somi_resolve property" ;;
159
+ esac
160
+ done
161
+ REAL_RESOLVE_REQUIRED="$(schema_field somi_resolve required)"
162
+ for req in $REAL_RESOLVE_REQUIRED; do
163
+ case " $SNIPPET_KEYS " in
164
+ *" $req "*) ok "the example passes somi_resolve's required argument '$req'" ;;
165
+ *) bad "somi_resolve's required argument '$req' is missing from the example" ;;
166
+ esac
167
+ done
168
+ fi
169
+
170
+ # somi_command: same shape, one required "name" argument -- stays specific to agents/somi.md
171
+ # (only the front door reads a command's procedure text this way), but check both files anyway
172
+ # so a future move doesn't silently drop the check.
173
+ REAL_COMMAND_PROPS="$(schema_field somi_command properties)"
174
+ for prop in $REAL_COMMAND_PROPS; do
175
+ if grep -qE "\b${prop}\b" "$AGENT_MD" "$SKILL_MD"; then
176
+ ok "somi_command's real argument '$prop' is named in agents/somi.md or skills/somi-dispatch/SKILL.md"
177
+ else
178
+ bad "somi_command's real argument '$prop' is never mentioned in agents/somi.md or skills/somi-dispatch/SKILL.md"
179
+ fi
180
+ done
181
+
182
+ # somi_skill: same shape again, one required "name" argument -- checked against the UNION that
183
+ # actually names it (agents/somi.md today; any commands/*.md file would also count).
184
+ REAL_SKILL_PROPS="$(schema_field somi_skill properties)"
185
+ for prop in $REAL_SKILL_PROPS; do
186
+ if grep -qE "\b${prop}\b" "$AGENT_MD" "$SKILL_MD" $COMMAND_MDS; then
187
+ ok "somi_skill's real argument '$prop' is named in agents/somi.md, skills/somi-dispatch/SKILL.md, or a command"
188
+ else
189
+ bad "somi_skill's real argument '$prop' is never mentioned in agents/somi.md, skills/somi-dispatch/SKILL.md, or any command"
190
+ fi
191
+ done
192
+ fi
193
+
194
+ echo "somi agent <-> somi-dispatch.mjs dispatch contract tests: $pass ok, $fail failed"
195
+ [ "$fail" -eq 0 ] || exit 1
@@ -0,0 +1,354 @@
1
+ #!/usr/bin/env bash
2
+ # Unit guard for scripts/somi-dispatch.mjs: the deterministic dispatch resolver a prompt shells out
3
+ # to for "which tier and model should this agent run at, right now" -- the first real call site for
4
+ # decideDispatch/modelForDispatch (nothing before this composed them together outside a test).
5
+ #
6
+ # Exercises: resolution against real shipped agents at every representative declared shape
7
+ # (high-only, medium+high, low+medium) across all three ceilings; ceiling_source surfacing each of
8
+ # cli/env/config/state/default; an unmapped host resolving to model: null rather than a guess; the
9
+ # project's `.somi/config.json` `cost.mapping` override (an unmapped host gaining a mapped model, a
10
+ # single claude-code tier overridden, a __proto__ key rejected, a malformed mapping -- missing tier
11
+ # or non-string model -- failing loudly with no JSON on stdout); a path-traversal attempt in
12
+ # --agent rejected before any file is read, in either direction (`../` and a bare `/`); the somi
13
+ # exemption and an unknown agent each failing with their own distinct, clear, non-zero exit code;
14
+ # an empty or missing value for --host/--ceiling/--agent rejected outright rather than falling
15
+ # through to a silent default; and the three exit codes (usage / unknown agent / malformed
16
+ # declaration) staying distinct from each other and from success.
17
+ #
18
+ # Every invocation is scoped to its OWN throwaway CLAUDE_PROJECT_DIR, so the real repo's
19
+ # .somi/somi-state/ceiling.json is never read or written by this suite -- agent frontmatter itself
20
+ # is still read from the REAL agents/ directory (the resolver's install root, not the project
21
+ # root), which is the behavior under test, not something to fake.
22
+ set -uo pipefail
23
+
24
+ ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
25
+ CLI="$ROOT_REPO/scripts/somi-dispatch.mjs"
26
+
27
+ pass=0; fail=0
28
+ ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
29
+ bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
30
+ check() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi; }
31
+
32
+ echo "== somi-dispatch resolve =="
33
+
34
+ TMP="$(mktemp -d)"
35
+ trap 'rm -rf "$TMP"' EXIT
36
+ fresh() { mktemp -d -p "$TMP"; }
37
+
38
+ # $1 = project root, remaining = full CLI args (including the subcommand).
39
+ run() {
40
+ local proj="$1"; shift
41
+ CLAUDE_PROJECT_DIR="$proj" node "$CLI" "$@"
42
+ }
43
+ # $1 = a captured JSON string, $2 = key to extract.
44
+ field() {
45
+ node -e 'const o = JSON.parse(process.argv[1]); process.stdout.write(String(o[process.argv[2]]))' "$1" "$2"
46
+ }
47
+ expect_exit() { # $1 = name, $2 = expected exit code, $3 = project root, remaining = CLI args
48
+ local name="$1" want="$2" proj="$3" got=0
49
+ shift 3
50
+ run "$proj" "$@" >/dev/null 2>&1 || got=$?
51
+ if [ "$got" = "$want" ]; then ok "$name"; else bad "$name (expected exit $want, got $got)"; fi
52
+ }
53
+
54
+ # --- high-only (`designer`, cost: high): no cheaper mode exists, so every ceiling still runs high -
55
+ for c in low medium high; do
56
+ out="$(run "$(fresh)" resolve --agent designer --ceiling "$c")"
57
+ check "designer (high-only) under ceiling=$c: tier is high -- no cheaper mode to select" \
58
+ "$(field "$out" tier)" "high"
59
+ check "designer under ceiling=$c: model is opus" "$(field "$out" model)" "opus"
60
+ done
61
+
62
+ # --- graded medium/high (`reviewer`): ceiling picks the highest permitted member -----------------
63
+ out="$(run "$(fresh)" resolve --agent reviewer --ceiling low)"
64
+ check "reviewer (medium,high) under ceiling=low: no member fits, selects cheapest (medium)" \
65
+ "$(field "$out" tier)" "medium"
66
+ out="$(run "$(fresh)" resolve --agent reviewer --ceiling medium)"
67
+ check "reviewer under ceiling=medium: selects medium" "$(field "$out" tier)" "medium"
68
+ out="$(run "$(fresh)" resolve --agent reviewer --ceiling high)"
69
+ check "reviewer under ceiling=high: selects high" "$(field "$out" tier)" "high"
70
+
71
+ # --- graded low/medium (`coder`): the opt-in `low` bar's shipped example ------------------------
72
+ out="$(run "$(fresh)" resolve --agent coder --ceiling low)"
73
+ check "coder (low,medium) under ceiling=low: selects low" "$(field "$out" tier)" "low"
74
+ check "coder under ceiling=low: model is haiku" "$(field "$out" model)" "haiku"
75
+ out="$(run "$(fresh)" resolve --agent coder --ceiling medium)"
76
+ check "coder under ceiling=medium: selects medium" "$(field "$out" tier)" "medium"
77
+ out="$(run "$(fresh)" resolve --agent coder --ceiling high)"
78
+ check "coder under ceiling=high: selects its own top member (medium), never invents high" \
79
+ "$(field "$out" tier)" "medium"
80
+ check "coder under ceiling=high: model is sonnet, not opus" "$(field "$out" model)" "sonnet"
81
+
82
+ # --- ceiling_source covers all five origins -- this is what lets a dispatcher announce a `low`
83
+ # ceiling honestly, by its real source, not just its bare value. -----------------------------------
84
+ out="$(run "$(fresh)" resolve --agent coder)"
85
+ check "no config, no env, no --ceiling: ceiling_source is default" "$(field "$out" ceiling_source)" "default"
86
+
87
+ out="$(run "$(fresh)" resolve --agent coder --ceiling medium)"
88
+ check "explicit --ceiling: ceiling_source is cli" "$(field "$out" ceiling_source)" "cli"
89
+
90
+ R_ENV="$(fresh)"
91
+ out="$(CLAUDE_PROJECT_DIR="$R_ENV" SOMI_COST_CEILING=medium node "$CLI" resolve --agent coder)"
92
+ check "SOMI_COST_CEILING set, no --ceiling: ceiling_source is env" "$(field "$out" ceiling_source)" "env"
93
+
94
+ R_CFG="$(fresh)"; mkdir -p "$R_CFG/.somi"
95
+ printf '{"cost": {"ceiling": "low"}}\n' > "$R_CFG/.somi/config.json"
96
+ out="$(run "$R_CFG" resolve --agent coder)"
97
+ check "bootstrap from .somi/config.json's cost.ceiling: ceiling_source is config" \
98
+ "$(field "$out" ceiling_source)" "config"
99
+ out2="$(run "$R_CFG" resolve --agent coder)"
100
+ check "a second call against the same project root: ceiling_source is state, not config again" \
101
+ "$(field "$out2" ceiling_source)" "state"
102
+
103
+ # --- unmapped host: model is null (let the host choose), never a guessed name -------------------
104
+ out="$(run "$(fresh)" resolve --agent coder --host some-future-host)"
105
+ check "unmapped host: model is null" "$(field "$out" model)" "null"
106
+ check "unmapped host: tier still resolves normally" "$(field "$out" tier)" "medium"
107
+
108
+ # --- .somi/config.json's cost.mapping override: how a host SoMi doesn't map (e.g. Copilot) is told
109
+ # which of ITS OWN models is low/medium/high -- reused via readCostConfig, merged via
110
+ # mergeHostMapping, never a second config reader. A malformed one fails loudly, no stdout -- exit 67
111
+ # whenever the project's own cost.mapping is the cause: either the mapping's own SHAPE is invalid
112
+ # (mergeHostMapping's own checks: a disallowed host key, a non-object per-host value), or the shape
113
+ # is fine but the resolved data is incomplete or wrong for the tier actually selected (resolveModel's
114
+ # checks, via modelForDispatch) for a host the project's OWN mapping named -- a partial override of a
115
+ # shipped host replaces that host's whole tier map rather than merging it tier-by-tier, so overriding
116
+ # just one tier drops the others, and the resulting error names ".somi/config.json cost.mapping"
117
+ # explicitly rather than reading like agent coder's own broken cost: declaration. Exit 66 stays
118
+ # reserved for a resolution failure on a host the project's mapping never mentioned at all -- which
119
+ # would mean a bug in the shipped HOST_MODELS table itself (see scripts/somi-dispatch.mjs's own
120
+ # split). ------------------------------------------------------------------------------------------
121
+ expect_malformed() { # $1=name $2=want-exit-code $3=proj, remaining = CLI args
122
+ local name="$1" want="$2" proj="$3" out rc=0; shift 3
123
+ out="$(run "$proj" "$@" 2>/dev/null)" || rc=$?
124
+ check "$name: exit $want" "$rc" "$want"
125
+ check "$name: no JSON on stdout" "$out" ""
126
+ }
127
+
128
+ # Otherwise-unmapped host, mapped by the project: resolves to it for the tier actually selected
129
+ # (coder is low,medium; default ceiling high -> its own top member, medium). Without the mapping,
130
+ # same as any unmapped host: null.
131
+ R_MAP="$(fresh)"; mkdir -p "$R_MAP/.somi"
132
+ printf '{"cost": {"mapping": {"copilot": {"low": "gpt-5-mini", "medium": "gpt-5", "high": "gpt-5-pro"}}}}\n' \
133
+ > "$R_MAP/.somi/config.json"
134
+ out="$(run "$R_MAP" resolve --agent coder --host copilot)"
135
+ check "copilot mapped via project config: model is the mapped medium entry" "$(field "$out" model)" "gpt-5"
136
+ out="$(run "$(fresh)" resolve --agent coder --host copilot)"
137
+ check "copilot with no project mapping: model is null" "$(field "$out" model)" "null"
138
+
139
+ # A project mapping can override a single claude-code tier; designer (cost: high, no cheaper mode)
140
+ # always selects high, isolating the override to exactly the tier it names.
141
+ R_OVERRIDE="$(fresh)"; mkdir -p "$R_OVERRIDE/.somi"
142
+ printf '{"cost": {"mapping": {"claude-code": {"low": "haiku", "medium": "sonnet", "high": "custom-opus"}}}}\n' \
143
+ > "$R_OVERRIDE/.somi/config.json"
144
+ out="$(run "$R_OVERRIDE" resolve --agent designer)"
145
+ check "project mapping overrides claude-code's high tier" "$(field "$out" model)" "custom-opus"
146
+
147
+ # A __proto__ key is rejected outright (mergeHostMapping's denylist) -- this is the PROJECT's own
148
+ # config.json being malformed, exit 67, never merged.
149
+ R_PROTO="$(fresh)"; mkdir -p "$R_PROTO/.somi"
150
+ printf '{"cost": {"mapping": {"__proto__": {"low": "x"}}}}\n' > "$R_PROTO/.somi/config.json"
151
+ expect_malformed "a __proto__ key in cost.mapping" 67 "$R_PROTO" resolve --agent coder
152
+ proto_err="$(run "$R_PROTO" resolve --agent coder 2>&1 >/dev/null)"
153
+ case "$proto_err" in
154
+ *"__proto__"*) ok "the __proto__ rejection names the disallowed key" ;;
155
+ *) bad "the __proto__ rejection does not name the key (got: $proto_err)" ;;
156
+ esac
157
+
158
+ # A mapped host missing the tier actually selected (coder's default selection is medium; this
159
+ # mapping supplies only low), and a non-string model value, are shape-valid but data-incomplete for
160
+ # THIS dispatch -- resolveModel's own checks, via modelForDispatch. Both name "copilot", which the
161
+ # project's OWN mapping named, so both are the project's fault: exit 67, message names
162
+ # ".somi/config.json cost.mapping" (not every mapping problem is the project's own file being
163
+ # broken in the STRUCTURAL sense mergeHostMapping checks, but these two are still its own data).
164
+ R_PARTIAL="$(fresh)"; mkdir -p "$R_PARTIAL/.somi"
165
+ printf '{"cost": {"mapping": {"copilot": {"low": "gpt-5-mini"}}}}\n' > "$R_PARTIAL/.somi/config.json"
166
+ expect_malformed "a mapped host missing the selected tier" 67 "$R_PARTIAL" resolve --agent coder --host copilot
167
+ partial_msg="$(run "$R_PARTIAL" resolve --agent coder --host copilot 2>&1 >/dev/null || true)"
168
+ case "$partial_msg" in
169
+ *".somi/config.json cost.mapping"*) ok "the missing-tier error names .somi/config.json cost.mapping" ;;
170
+ *) bad "the missing-tier error does not name .somi/config.json cost.mapping (got: $partial_msg)" ;;
171
+ esac
172
+
173
+ R_NONSTRING="$(fresh)"; mkdir -p "$R_NONSTRING/.somi"
174
+ printf '{"cost": {"mapping": {"copilot": {"low": "gpt-5-mini", "medium": 5, "high": "gpt-5-pro"}}}}\n' \
175
+ > "$R_NONSTRING/.somi/config.json"
176
+ expect_malformed "a non-string mapped model" 67 "$R_NONSTRING" resolve --agent coder --host copilot
177
+ nonstring_msg="$(run "$R_NONSTRING" resolve --agent coder --host copilot 2>&1 >/dev/null || true)"
178
+ case "$nonstring_msg" in
179
+ *".somi/config.json cost.mapping"*) ok "the non-string-model error names .somi/config.json cost.mapping" ;;
180
+ *) bad "the non-string-model error does not name .somi/config.json cost.mapping (got: $nonstring_msg)" ;;
181
+ esac
182
+
183
+ # The reported bug: a partial override of a SHIPPED host (claude-code) that names only one tier
184
+ # replaces that host's whole tier map (mergeHostMapping never merges tier-by-tier), so every OTHER
185
+ # tier for that host now fails too -- and the failure must name .somi/config.json cost.mapping, not
186
+ # read like coder's own cost: declaration is broken.
187
+ R_SHIPPED_PARTIAL="$(fresh)"; mkdir -p "$R_SHIPPED_PARTIAL/.somi"
188
+ printf '{"cost": {"mapping": {"claude-code": {"high": "custom-opus"}}}}\n' > "$R_SHIPPED_PARTIAL/.somi/config.json"
189
+ expect_malformed "a partial override of the shipped claude-code host drops its other tiers" 67 \
190
+ "$R_SHIPPED_PARTIAL" resolve --agent coder
191
+ shipped_partial_msg="$(run "$R_SHIPPED_PARTIAL" resolve --agent coder 2>&1 >/dev/null || true)"
192
+ case "$shipped_partial_msg" in
193
+ *".somi/config.json cost.mapping"*) ok "the shipped-host partial-override error names .somi/config.json cost.mapping" ;;
194
+ *) bad "the shipped-host partial-override error does not name .somi/config.json cost.mapping (got: $shipped_partial_msg)" ;;
195
+ esac
196
+
197
+ # A tier key outside low|medium|high in cost.mapping is ALSO the project's own file being malformed
198
+ # (mergeHostMapping's own check, same as __proto__ above) -- exit 67, not 66.
199
+ R_BADTIER="$(fresh)"; mkdir -p "$R_BADTIER/.somi"
200
+ printf '{"cost": {"mapping": {"copilot": {"lo": "gpt-5-mini"}}}}\n' > "$R_BADTIER/.somi/config.json"
201
+ expect_malformed "a tier key outside low|medium|high in cost.mapping" 67 "$R_BADTIER" resolve --agent coder --host copilot
202
+
203
+ # A named regression test: bootstrap normally (valid config, ceiling state written), THEN corrupt
204
+ # config.json -- the ceiling itself doesn't re-read config after bootstrap, but the mapping
205
+ # (read fresh every call) does, and its failure must be reported as the PROJECT's file breaking
206
+ # (67), never as agent coder's own cost: declaration being malformed (66).
207
+ R_POSTBOOT="$(fresh)"; mkdir -p "$R_POSTBOOT/.somi"
208
+ printf '{"cost": {"ceiling": "high"}}\n' > "$R_POSTBOOT/.somi/config.json"
209
+ run "$R_POSTBOOT" resolve --agent coder >/dev/null # bootstrap: writes .somi/somi-state/ceiling.json
210
+ printf '{"cost": {"ceiling": "high"}\n' > "$R_POSTBOOT/.somi/config.json" # now corrupt (missing brace)
211
+ postboot_rc=0
212
+ run "$R_POSTBOOT" resolve --agent coder >/dev/null 2>&1 || postboot_rc=$?
213
+ check "config corrupted AFTER a successful bootstrap: exit 67, not 66" "$postboot_rc" "67"
214
+
215
+ # --- path traversal in --agent: rejected before any file is read, in either direction ------------
216
+ expect_exit "path traversal in --agent (../etc/passwd) rejected as a usage error" 64 \
217
+ "$(fresh)" resolve --agent ../etc/passwd
218
+ expect_exit "a slash in --agent (a/b) rejected as a usage error" 64 \
219
+ "$(fresh)" resolve --agent a/b
220
+
221
+ R_TRAV="$(fresh)"
222
+ run "$R_TRAV" resolve --agent ../etc/passwd >/dev/null 2>&1
223
+ if [ -e "$R_TRAV/.somi" ]; then
224
+ bad "a rejected --agent must be caught before the ceiling is ever touched (found .somi/ in the project root)"
225
+ else
226
+ ok "a rejected --agent (../etc/passwd) leaves the project root untouched -- rejected before any read"
227
+ fi
228
+
229
+ # --- somi is exempt: a clear, distinct, non-zero error, never a guessed model --------------------
230
+ expect_exit "agent somi (exempt from cost:) fails with its own distinct exit code" 66 \
231
+ "$(fresh)" resolve --agent somi
232
+ msg="$(run "$(fresh)" resolve --agent somi 2>&1 >/dev/null || true)"
233
+ case "$msg" in
234
+ *exempt*) ok "somi's error message names the exemption, not a generic failure" ;;
235
+ *) bad "somi's error message does not mention the exemption (got: $msg)" ;;
236
+ esac
237
+
238
+ # --- unknown agent: a clear, distinct, non-zero error --------------------------------------------
239
+ expect_exit "unknown agent fails with its own distinct exit code" 65 \
240
+ "$(fresh)" resolve --agent totally-not-a-real-agent
241
+ msg="$(run "$(fresh)" resolve --agent totally-not-a-real-agent 2>&1 >/dev/null || true)"
242
+ case "$msg" in
243
+ *"unknown agent"*) ok "unknown-agent error message says so" ;;
244
+ *) bad "unknown-agent error message is unclear (got: $msg)" ;;
245
+ esac
246
+
247
+ # --- the four failure exit codes, DERIVED from the CLI's own EXIT_* constants (not re-typed here),
248
+ # are pairwise distinct, and distinct from success (0) -------------------------------------------
249
+ cli_codes="$(grep -oE '^const EXIT_[A-Z_]+ = [0-9]+;' "$CLI" | grep -oE '[0-9]+')"
250
+ check "the CLI declares exactly four EXIT_* constants" "$(printf '%s\n' "$cli_codes" | wc -l | tr -d ' ')" "4"
251
+ check "the CLI's own EXIT_* constants are pairwise distinct, and none is 0 (success)" \
252
+ "$(printf '%s\n0\n' "$cli_codes" | sort -u | wc -l | tr -d ' ')" "5"
253
+
254
+ # --- bad args: missing --agent, unknown subcommand, unknown flag --------------------------------
255
+ expect_exit "missing --agent is a usage error" 64 "$(fresh)" resolve
256
+ expect_exit "unknown subcommand is a usage error" 64 "$(fresh)" bogus-subcommand --agent coder
257
+ expect_exit "unknown flag is a usage error" 64 "$(fresh)" resolve --agent coder --bogus-flag x
258
+ expect_exit "no subcommand at all is a usage error" 64 "$(fresh)"
259
+
260
+ # --- an empty or missing flag value is rejected outright, never silently defaulted --------------
261
+ expect_exit "--host with an explicitly empty value is a usage error, not a silent default" 64 \
262
+ "$(fresh)" resolve --agent coder --host ""
263
+ expect_exit "a trailing --host with no value at all is a usage error" 64 \
264
+ "$(fresh)" resolve --agent coder --host
265
+ expect_exit "--ceiling with an explicitly empty value is a usage error" 64 \
266
+ "$(fresh)" resolve --agent coder --ceiling ""
267
+ expect_exit "a trailing --ceiling with no value at all is a usage error" 64 \
268
+ "$(fresh)" resolve --agent coder --ceiling
269
+ expect_exit "--agent with an explicitly empty value is a usage error" 64 \
270
+ "$(fresh)" resolve --agent ""
271
+
272
+ # --- a syntactically-present but invalid --ceiling VALUE (not empty/missing, an unrecognized tier)
273
+ # is a usage error, and -- the actual point of this guard -- it must be rejected BEFORE
274
+ # resolveCeiling() ever touches disk, so a rejected value leaves no .somi/ state behind. -----------
275
+ R_BADCEIL="$(fresh)"
276
+ expect_exit "an invalid --ceiling VALUE ('critical') is a usage error, not a project-env failure" 64 \
277
+ "$R_BADCEIL" resolve --agent coder --ceiling critical
278
+ badceil_msg="$(run "$R_BADCEIL" resolve --agent coder --ceiling critical 2>&1 >/dev/null || true)"
279
+ case "$badceil_msg" in
280
+ *"--ceiling"*"critical"*) ok "the bad --ceiling error names the flag and the rejected value" ;;
281
+ *) bad "the bad --ceiling error is unclear (got: $badceil_msg)" ;;
282
+ esac
283
+ if [ -e "$R_BADCEIL/.somi" ]; then
284
+ bad "a rejected --ceiling value must be caught before the ceiling state is ever touched (found .somi/ in the project root)"
285
+ else
286
+ ok "a rejected --ceiling value ('critical') leaves the project root untouched -- validated before resolveCeiling touches disk"
287
+ fi
288
+
289
+ # --- project environment/config failures: exit 67, distinct from 64 (usage) and 66 (declaration),
290
+ # and the message names the offending file -- these are the caller's PROJECT state being broken,
291
+ # not a bad argument to this command and not a bad agent declaration. ------------------------------
292
+ R_CFG_BROKEN="$(fresh)"; mkdir -p "$R_CFG_BROKEN/.somi"
293
+ printf '{"cost": {"ceiling": "low"}\n' > "$R_CFG_BROKEN/.somi/config.json" # missing closing brace
294
+ expect_exit "an unparsable .somi/config.json is a project-env failure (67), not usage or malformed" 67 \
295
+ "$R_CFG_BROKEN" resolve --agent coder
296
+ cfg_broken_msg="$(run "$R_CFG_BROKEN" resolve --agent coder 2>&1 >/dev/null || true)"
297
+ case "$cfg_broken_msg" in
298
+ *"config.json"*) ok "the unparsable-config error names config.json" ;;
299
+ *) bad "the unparsable-config error does not name config.json (got: $cfg_broken_msg)" ;;
300
+ esac
301
+
302
+ R_STATE_BROKEN="$(fresh)"; mkdir -p "$R_STATE_BROKEN/.somi/somi-state"
303
+ printf '{"ceiling": "low"\n' > "$R_STATE_BROKEN/.somi/somi-state/ceiling.json" # missing closing brace
304
+ expect_exit "an unparsable .somi/somi-state/ceiling.json is a project-env failure (67)" 67 \
305
+ "$R_STATE_BROKEN" resolve --agent coder
306
+ state_broken_msg="$(run "$R_STATE_BROKEN" resolve --agent coder 2>&1 >/dev/null || true)"
307
+ case "$state_broken_msg" in
308
+ *"ceiling.json"*) ok "the unparsable-state error names ceiling.json" ;;
309
+ *) bad "the unparsable-state error does not name ceiling.json (got: $state_broken_msg)" ;;
310
+ esac
311
+
312
+ # A malformed SOMI_COST_CEILING is the CALLER's input (same channel as --ceiling, just an env var
313
+ # instead of a flag), not the project's own persisted state -- classified 64 (usage), not 67, and
314
+ # -- the actual point of this guard -- rejected before resolveCeiling() ever touches disk, same as
315
+ # a bad --ceiling value above.
316
+ R_ENV_BAD="$(fresh)"
317
+ env_bad_rc=0
318
+ CLAUDE_PROJECT_DIR="$R_ENV_BAD" SOMI_COST_CEILING=critical node "$CLI" resolve --agent coder >/dev/null 2>&1 || env_bad_rc=$?
319
+ check "a malformed SOMI_COST_CEILING is a usage error (64), not a project-env failure" "$env_bad_rc" "64"
320
+ if [ -e "$R_ENV_BAD/.somi" ]; then
321
+ bad "a rejected SOMI_COST_CEILING must be caught before the ceiling state is ever touched (found .somi/ in the project root)"
322
+ else
323
+ ok "a rejected SOMI_COST_CEILING ('critical') leaves the project root untouched -- validated before resolveCeiling touches disk"
324
+ fi
325
+ envbad_msg="$(CLAUDE_PROJECT_DIR="$(fresh)" SOMI_COST_CEILING=critical node "$CLI" resolve --agent coder 2>&1 >/dev/null || true)"
326
+ case "$envbad_msg" in
327
+ *"SOMI_COST_CEILING"*"critical"*) ok "the bad SOMI_COST_CEILING error names the variable and the rejected value" ;;
328
+ *) bad "the bad SOMI_COST_CEILING error is unclear (got: $envbad_msg)" ;;
329
+ esac
330
+
331
+ # --- output shape: exactly the seven documented fields, and a real JSON array for `supported` -----
332
+ out="$(run "$(fresh)" resolve --agent coder --ceiling medium)"
333
+ check "JSON output carries exactly agent/ceiling/ceiling_origin/ceiling_source/model/supported/tier" \
334
+ "$(node -e 'process.stdout.write(Object.keys(JSON.parse(process.argv[1])).sort().join("|"))' "$out")" \
335
+ "agent|ceiling|ceiling_origin|ceiling_source|model|supported|tier"
336
+ check "coder's supported set is exactly [low, medium], echoing its declared frontmatter" \
337
+ "$(node -e 'process.stdout.write(JSON.parse(process.argv[1]).supported.join(","))' "$out")" \
338
+ "low,medium"
339
+
340
+ # --- ceiling_origin surfaces through the CLI, not just the library: the source/origin distinction
341
+ # that makes "ceiling_source: state" actionable round-trips through the JSON. ---------------------
342
+ out="$(run "$(fresh)" resolve --agent coder)"
343
+ check "fresh project, no override: ceiling_origin matches ceiling_source ('default')" \
344
+ "$(field "$out" ceiling_origin)" "default"
345
+
346
+ R_ORIGIN="$(fresh)"; mkdir -p "$R_ORIGIN/.somi"
347
+ printf '{"cost": {"ceiling": "low"}}\n' > "$R_ORIGIN/.somi/config.json"
348
+ run "$R_ORIGIN" resolve --agent coder >/dev/null # bootstrap from config
349
+ out="$(run "$R_ORIGIN" resolve --agent coder)" # a later bare call: state now on disk
350
+ check "a later call: ceiling_source is 'state' but ceiling_origin still says 'config' -- actionable" \
351
+ "$(field "$out" ceiling_source),$(field "$out" ceiling_origin)" "state,config"
352
+
353
+ echo "somi-dispatch tests: $pass ok, $fail failed"
354
+ [ "$fail" -eq 0 ] || exit 1
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+ # Guards scripts/somi-mcp.mjs: the bundled, zero-dependency stdio MCP server wrapping the same
3
+ # scripts/lib/dispatch-resolver.mjs the CLI (scripts/somi-dispatch.mjs) uses. A JSON-RPC stdio
4
+ # conversation needs request/response correlation and (for the roots/list rung) a SERVER-initiated
5
+ # request answered by the test acting as the client -- awkward in bash alone, so the actual
6
+ # protocol driving lives in tests/scripts/lib/somi-mcp-tests.mjs; this file is the thin wrapper
7
+ # scripts/validate.sh calls, matching how other heavier checks in this suite pair a .sh entry
8
+ # point with a .mjs implementation (e.g. tests/scripts/lib/digest-marker-coupling.mjs).
9
+ set -euo pipefail
10
+
11
+ ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
12
+ node "$ROOT_REPO/tests/scripts/lib/somi-mcp-tests.mjs"