@skathio/somi 3.1.0 → 4.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.
- package/.claude/settings.json +13 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.copilot-extension/extension.json +1 -1
- package/.copilot-extension/marketplace.json +2 -2
- package/README.md +28 -23
- package/VERSION +1 -1
- package/agents/{architecture-reviewer.md → somi-architecture-reviewer.md} +10 -11
- package/agents/{atlas.md → somi-atlas.md} +3 -5
- package/agents/{coder.md → somi-coder.md} +29 -26
- package/agents/{designer.md → somi-designer.md} +9 -11
- package/agents/{discovery-analyst.md → somi-discovery-analyst.md} +7 -9
- package/agents/{impact.md → somi-impact.md} +6 -8
- package/agents/{incident.md → somi-incident.md} +2 -4
- package/agents/{plan-reviewer.md → somi-plan-reviewer.md} +9 -11
- package/agents/{planner.md → somi-planner.md} +19 -27
- package/agents/{pr.md → somi-pr.md} +2 -4
- package/agents/{refactor-designer.md → somi-refactor-designer.md} +14 -15
- package/agents/{refactorer.md → somi-refactorer.md} +14 -15
- package/agents/{reviewer.md → somi-reviewer.md} +8 -7
- package/agents/{sdlc-reviewer.md → somi-sdlc-reviewer.md} +8 -10
- package/agents/{security-reviewer.md → somi-security-reviewer.md} +8 -8
- package/agents/{test-strategist.md → somi-test-strategist.md} +4 -6
- package/agents/somi.md +27 -14
- package/commands/adopt.md +9 -10
- package/commands/architecture-review.md +4 -5
- package/commands/atlas.md +3 -4
- package/commands/code-loop.md +38 -14
- package/commands/code-parallel.md +4 -4
- package/commands/code.md +24 -15
- package/commands/debug.md +8 -9
- package/commands/design.md +14 -15
- package/commands/discover.md +11 -12
- package/commands/impact.md +2 -3
- package/commands/incident.md +3 -4
- package/commands/plan-loop.md +16 -12
- package/commands/plan.md +15 -16
- package/commands/pr.md +2 -3
- package/commands/refactor-design.md +10 -11
- package/commands/refactor.md +7 -8
- package/commands/release-readiness.md +6 -7
- package/commands/review-panel.md +24 -23
- package/commands/review.md +14 -14
- package/commands/security-review.md +8 -7
- package/commands/ship-loop.md +107 -28
- package/commands/ship.md +6 -6
- package/commands/somi-config.md +131 -0
- package/commands/test-strategy.md +3 -4
- package/commands/upgrade.md +4 -5
- package/examples/code-review-example.md +1 -1
- package/examples/discovery-example.md +1 -1
- package/examples/feature-plan-example.md +2 -2
- package/hooks/hooks.json +14 -1
- package/hooks/lib/common.mjs +64 -1
- package/hooks/post-tool/audit-log.mjs +3 -2
- package/hooks/pre-tool/block-secret-writes.mjs +12 -11
- package/hooks/pre-tool/guard-cost-lowering.mjs +177 -0
- package/hooks/pre-tool/guard-protected-paths.mjs +13 -3
- package/hooks/session-start/detect-repo-instructions.mjs +27 -2
- package/hooks/session-start/ensure-default-config.mjs +121 -0
- package/package.json +1 -1
- package/rules/00-priorities.md +1 -1
- package/rules/30-security-owasp.md +1 -1
- package/rules/50-collaboration.md +9 -6
- package/rules/CLAUDE.md +11 -10
- package/scripts/lib/agent-info.mjs +85 -0
- package/scripts/lib/agent-registry.mjs +92 -0
- package/scripts/lib/cost-ceiling.mjs +175 -171
- package/scripts/lib/cost-config-edit.mjs +102 -0
- package/scripts/lib/cost-config.mjs +64 -0
- package/scripts/lib/cost-defaults.mjs +51 -0
- package/scripts/lib/cost-lowering.mjs +89 -0
- package/scripts/lib/cost-model.mjs +37 -22
- package/scripts/lib/dispatch-resolver.mjs +68 -50
- package/scripts/lib/loop-diff.mjs +96 -0
- package/scripts/lib/loop-dispatch.mjs +19 -0
- package/scripts/lib/loop-review.mjs +52 -0
- package/scripts/lib/run-budget.mjs +28 -0
- package/scripts/lib/size-tier.mjs +184 -0
- package/scripts/lib/tier-record.mjs +82 -0
- package/scripts/size-budget-overrides.json +7 -15
- package/scripts/somi-config.mjs +358 -0
- package/scripts/somi-dispatch.mjs +1 -1
- package/scripts/somi-loop.mjs +71 -96
- package/scripts/somi-mcp.mjs +135 -14
- package/scripts/somi-tier.mjs +393 -0
- package/scripts/validate.sh +37 -215
- package/skills/api-design/SKILL.md +1 -1
- package/skills/clean-code/SKILL.md +1 -1
- package/skills/market-research/SKILL.md +2 -2
- package/skills/owasp-defense/SKILL.md +2 -2
- package/skills/plan-review/SKILL.md +5 -1
- package/skills/reasoning-craft/SKILL.md +1 -1
- package/skills/requirements-engineering/SKILL.md +3 -3
- package/skills/solid-principles/SKILL.md +1 -1
- package/skills/somi-dispatch/SKILL.md +116 -87
- package/skills/somi-routing/SKILL.md +88 -1
- package/skills/testing-playbook/SKILL.md +2 -2
- package/skills/threat-modeling/SKILL.md +3 -3
- package/templates/BRIEF.md.tmpl +2 -2
- package/templates/DESIGN.md.tmpl +1 -1
- package/templates/DOD.md.tmpl +2 -2
- package/templates/PHASE.md.tmpl +2 -2
- package/templates/RCA.md.tmpl +1 -1
- package/templates/REVIEW.md.tmpl +3 -2
- package/templates/SDD.md.tmpl +1 -1
- package/templates/SPEC.md.tmpl +1 -1
- package/templates/TDD.md.tmpl +1 -1
- package/tests/hooks/cases/block-secret-writes.json +130 -17
- package/tests/hooks/cases/detect-repo-instructions.json +22 -1
- package/tests/hooks/cases/guard-protected-paths.json +175 -25
- package/tests/scripts/agent-model-frontmatter.sh +38 -0
- package/tests/scripts/agent-names.sh +77 -0
- package/tests/scripts/check-frontmatter.sh +1 -1
- package/tests/scripts/checkpoint-gate.sh +44 -3
- package/tests/scripts/convergence-runner.sh +10 -6
- package/tests/scripts/cost-ceiling.sh +127 -215
- package/tests/scripts/cost-defaults.sh +128 -0
- package/tests/scripts/cost-hardcap.sh +329 -0
- package/tests/scripts/cost-lowering.sh +261 -0
- package/tests/scripts/cost-model.sh +18 -14
- package/tests/scripts/dispatch-guard.sh +7 -7
- package/tests/scripts/dispatch-line-gate.sh +61 -0
- package/tests/scripts/dispatch-reference-gate.sh +13 -13
- package/tests/scripts/ensure-default-config.sh +162 -0
- package/tests/scripts/eval-runner.sh +9 -9
- package/tests/scripts/evals-packaging.sh +127 -20
- package/tests/scripts/fixtures/size-tier-cases.json +87 -0
- package/tests/scripts/goldens/loop-state-done.json +1 -1
- package/tests/scripts/goldens/somi-loop.json +3 -3
- package/tests/scripts/lib/agent-registry-tests.mjs +95 -0
- package/tests/scripts/lib/brief-only-guard.mjs +27 -0
- package/tests/scripts/lib/checkpoint-gate.mjs +40 -3
- package/tests/scripts/lib/dispatch-reference-gate.mjs +5 -5
- package/tests/scripts/lib/retirement-gate.mjs +7 -2
- package/tests/scripts/lib/ship-loop-sizing-guard.mjs +52 -0
- package/tests/scripts/lib/size-tier-drift.mjs +74 -0
- package/tests/scripts/lib/somi-mcp-config-tests.mjs +92 -0
- package/tests/scripts/lib/somi-mcp-tests.mjs +80 -25
- package/tests/scripts/lib/somi-mcp-tier-tests.mjs +64 -0
- package/tests/scripts/retirement-gate.sh +19 -0
- package/tests/scripts/review-panel-seats.sh +2 -2
- package/tests/scripts/run.sh +95 -0
- package/tests/scripts/size-tier.sh +562 -0
- package/tests/scripts/somi-agent-dispatch-contract.sh +20 -11
- package/tests/scripts/somi-config.sh +281 -0
- package/tests/scripts/somi-dispatch.sh +194 -95
- package/tests/scripts/somi-mcp.sh +2 -0
|
@@ -39,7 +39,7 @@ else
|
|
|
39
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
40
|
fi
|
|
41
41
|
|
|
42
|
-
out="$(CLAUDE_PROJECT_DIR="$(fresh)" node "$CLI" resolve --agent coder --host claude-code)"; rc=$?
|
|
42
|
+
out="$(CLAUDE_PROJECT_DIR="$(fresh)" node "$CLI" resolve --agent somi-coder --host claude-code)"; rc=$?
|
|
43
43
|
if [ "$rc" -eq 0 ] && node -e 'JSON.parse(process.argv[1])' "$out" >/dev/null 2>&1; then
|
|
44
44
|
ok "the literal CLI-fallback invocation Step 4 names succeeds against the real CLI and prints valid JSON"
|
|
45
45
|
else
|
|
@@ -55,7 +55,7 @@ else
|
|
|
55
55
|
fi
|
|
56
56
|
for h in claude-code copilot; do
|
|
57
57
|
hrc=0
|
|
58
|
-
CLAUDE_PROJECT_DIR="$(fresh)" node "$CLI" resolve --agent coder --host "$h" >/dev/null 2>&1 || hrc=$?
|
|
58
|
+
CLAUDE_PROJECT_DIR="$(fresh)" node "$CLI" resolve --agent somi-coder --host "$h" >/dev/null 2>&1 || hrc=$?
|
|
59
59
|
if [ "$hrc" = "0" ]; then ok "--host $h is accepted by the real CLI"; else bad "--host $h was rejected (rc=$hrc)"; fi
|
|
60
60
|
done
|
|
61
61
|
|
|
@@ -71,31 +71,33 @@ fi
|
|
|
71
71
|
# --- each code Step 4 maps is genuinely reachable against the real CLI, not merely documented -----
|
|
72
72
|
reach "64 (usage) is reachable: missing --agent" 64
|
|
73
73
|
reach "65 (unknown agent) is reachable" 65 --agent totally-not-a-real-agent
|
|
74
|
-
reach "66 (
|
|
74
|
+
reach "66 (no tier source) is reachable: somi is exempt from cost resolution" 66 --agent somi
|
|
75
75
|
|
|
76
76
|
R67="$(fresh)"; mkdir -p "$R67/.somi"
|
|
77
77
|
printf '{"cost": {"ceiling": "low"}\n' > "$R67/.somi/config.json" # missing closing brace
|
|
78
78
|
r67rc=0
|
|
79
|
-
CLAUDE_PROJECT_DIR="$R67" node "$CLI" resolve --agent coder >/dev/null 2>&1 || r67rc=$?
|
|
79
|
+
CLAUDE_PROJECT_DIR="$R67" node "$CLI" resolve --agent somi-coder >/dev/null 2>&1 || r67rc=$?
|
|
80
80
|
if [ "$r67rc" = "67" ]; then
|
|
81
81
|
ok "67 (project environment/config failure) is reachable: unparsable .somi/config.json"
|
|
82
82
|
else
|
|
83
83
|
bad "67 was not reachable via an unparsable config.json (got $r67rc)"
|
|
84
84
|
fi
|
|
85
85
|
|
|
86
|
-
# 67 is also reachable AFTER
|
|
86
|
+
# 67 is also reachable AFTER an earlier successful call persisted a ceiling (M1: a config error must
|
|
87
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).
|
|
88
|
+
# LATER call than the one that wrote .somi/somi-state/ceiling.json). The first call passes
|
|
89
|
+
# --ceiling so state really exists before the config is corrupted.
|
|
89
90
|
R67_POST="$(fresh)"; mkdir -p "$R67_POST/.somi"
|
|
90
91
|
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 #
|
|
92
|
+
CLAUDE_PROJECT_DIR="$R67_POST" node "$CLI" resolve --agent somi-coder --ceiling high >/dev/null 2>&1 # persists state
|
|
93
|
+
[ -f "$R67_POST/.somi/somi-state/ceiling.json" ] || bad "the first call did not persist a ceiling state file"
|
|
92
94
|
printf '{"cost": {"ceiling": "high"}\n' > "$R67_POST/.somi/config.json" # now corrupt
|
|
93
95
|
r67postrc=0
|
|
94
|
-
CLAUDE_PROJECT_DIR="$R67_POST" node "$CLI" resolve --agent coder >/dev/null 2>&1 || r67postrc=$?
|
|
96
|
+
CLAUDE_PROJECT_DIR="$R67_POST" node "$CLI" resolve --agent somi-coder >/dev/null 2>&1 || r67postrc=$?
|
|
95
97
|
if [ "$r67postrc" = "67" ]; then
|
|
96
|
-
ok "67 is reachable even AFTER
|
|
98
|
+
ok "67 is reachable even AFTER state was persisted, not just on a fresh project"
|
|
97
99
|
else
|
|
98
|
-
bad "config corrupted after
|
|
100
|
+
bad "config corrupted after state was persisted did not reach 67 (got $r67postrc) -- may be misattributed to 66"
|
|
99
101
|
fi
|
|
100
102
|
|
|
101
103
|
|
|
@@ -126,13 +128,20 @@ else
|
|
|
126
128
|
# dispatch-reference line now names `somi_resolve`/`somi_skill` directly (not just a link to the
|
|
127
129
|
# skill), so a stale or invented tool name there would otherwise go unchecked: the skill/front-door
|
|
128
130
|
# pair alone can't see a typo that only ever appears in a command file.
|
|
129
|
-
|
|
131
|
+
# somi_agent is a read-only text reader that dispatch must NOT use (an agent starts as its agent_type),
|
|
132
|
+
# so it is the one real tool the dispatch text is required to leave unnamed.
|
|
133
|
+
REAL_TOOLS="$(node -e 'console.log(Object.keys(JSON.parse(process.argv[1])).filter((t) => t !== "somi_agent").sort().join(" "))' "$SCHEMA_JSON")"
|
|
130
134
|
PROMPT_TOOLS="$(grep -ohE '`somi_[a-z_]+`' "$AGENT_MD" "$SKILL_MD" $COMMAND_MDS | tr -d '`' | sort -u | tr '\n' ' ' | sed 's/ *$//')"
|
|
131
135
|
if [ "$REAL_TOOLS" = "$PROMPT_TOOLS" ]; then
|
|
132
136
|
ok "agents/somi.md + skills/somi-dispatch/SKILL.md + commands/*.md together name exactly the server's real tools ($REAL_TOOLS)"
|
|
133
137
|
else
|
|
134
138
|
bad "tool-name mismatch -- server: [$REAL_TOOLS] vs agents/somi.md + skills/somi-dispatch/SKILL.md + commands/*.md: [$PROMPT_TOOLS]"
|
|
135
139
|
fi
|
|
140
|
+
if node -e 'process.exit(Object.keys(JSON.parse(process.argv[1])).includes("somi_agent") ? 0 : 1)' "$SCHEMA_JSON"; then
|
|
141
|
+
ok "somi_agent still exists as a reader, and the dispatch text above names it nowhere"
|
|
142
|
+
else
|
|
143
|
+
bad "somi_agent disappeared from the server -- its removal needs an audit of its consumers first"
|
|
144
|
+
fi
|
|
136
145
|
|
|
137
146
|
# somi_resolve: every REAL property must be named somewhere across the two files (nothing silently
|
|
138
147
|
# dropped) -- and every key the skill's own canonical invocation example passes must be a REAL
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Guard for scripts/somi-config.mjs: show/get/set/unset/init over a project's .somi/config.json.
|
|
3
|
+
# Checks every operation, byte-exact init, preservation of unrelated keys, the key allowlist, whole-block
|
|
4
|
+
# validation, exit codes (64 arguments / 67 the project's files), no-follow and atomic writes, and
|
|
5
|
+
# agreement with the resolver. The safety checks are also proven red on mutated copies of the script.
|
|
6
|
+
set -uo pipefail
|
|
7
|
+
|
|
8
|
+
ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
9
|
+
CLI="$ROOT_REPO/scripts/somi-config.mjs"
|
|
10
|
+
|
|
11
|
+
pass=0; fail=0
|
|
12
|
+
ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
|
|
13
|
+
bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
|
|
14
|
+
check() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi; }
|
|
15
|
+
|
|
16
|
+
echo "== somi-config =="
|
|
17
|
+
|
|
18
|
+
TMP="$(mktemp -d)"
|
|
19
|
+
trap 'chmod -R u+rwx "$TMP" 2>/dev/null; rm -rf "$TMP"' EXIT
|
|
20
|
+
|
|
21
|
+
proj() { mktemp -d -p "$TMP"; }
|
|
22
|
+
# $1 = cli, $2 = project, rest = args -> stdout in $TMP/out, stderr in $TMP/err, prints the exit code
|
|
23
|
+
cfg() { local cli=$1 p=$2; shift 2; node "$cli" "$@" --project-dir "$p" > "$TMP/out" 2> "$TMP/err"; echo $?; }
|
|
24
|
+
jf() { node -e "const o=JSON.parse(require('fs').readFileSync('$TMP/out','utf8')); const v=($1); process.stdout.write(typeof v==='string'?v:JSON.stringify(v))"; }
|
|
25
|
+
EXPECT="$TMP/expected.json"
|
|
26
|
+
node --input-type=module -e "const D = await import('$ROOT_REPO/scripts/lib/cost-defaults.mjs'); process.stdout.write(D.serializeDefaultConfig())" > "$EXPECT"
|
|
27
|
+
res() { CLAUDE_PROJECT_DIR="$1" env -u SOMI_COST_CEILING node "$ROOT_REPO/scripts/somi-dispatch.mjs" resolve --agent "$2"; }
|
|
28
|
+
fld() { node -e "process.stdout.write(String(JSON.parse(process.argv[1])[process.argv[2]]))" "$1" "$2"; }
|
|
29
|
+
ascii_only() { LC_ALL=C grep -q -P '[^\x09\x0a\x20-\x7e]' "$1" && echo no || echo yes; }
|
|
30
|
+
|
|
31
|
+
# --- init: byte-exact, no-op when present ---------------------------------------------------------
|
|
32
|
+
P="$(proj)"
|
|
33
|
+
check "init: exit 0" "$(cfg "$CLI" "$P" init)" "0"
|
|
34
|
+
check "init creates exactly the text the SessionStart hook writes" "$(cmp -s "$P/.somi/config.json" "$EXPECT" && echo same)" "same"
|
|
35
|
+
check "init output says created" "$(jf 'o.created')" "true"
|
|
36
|
+
check ".somi was created with mode 700" "$(stat -c %a "$P/.somi")" "700"
|
|
37
|
+
printf '{"mine":1}' > "$P/.somi/config.json"
|
|
38
|
+
check "init over an existing file: exit 0" "$(cfg "$CLI" "$P" init)" "0"
|
|
39
|
+
check "... a no-op, file untouched, reported created:false" "$(cat "$P/.somi/config.json")|$(jf 'o.created')" '{"mine":1}|false'
|
|
40
|
+
|
|
41
|
+
# --- show -----------------------------------------------------------------------------------------
|
|
42
|
+
P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
|
|
43
|
+
check "show: exit 0" "$(cfg "$CLI" "$P" show)" "0"
|
|
44
|
+
check "show on a fresh default config: ceiling medium from config" "$(jf 'o.ceiling')" '{"value":"medium","source":"config"}'
|
|
45
|
+
check "show: every shipped agent is listed with default, tier, source" "$(jf 'o.agents.length === Object.keys(JSON.parse(require("fs").readFileSync("'"$EXPECT"'","utf8")).cost.agents).length && o.agents.every((a) => a.tier === a.default && a.source === "override")')" "true"
|
|
46
|
+
check "show: no warnings for a fresh default config" "$(jf 'o.warnings')" "[]"
|
|
47
|
+
check "show output is one ASCII line" "$(wc -l < "$TMP/out" | tr -d ' ')|$(ascii_only "$TMP/out")" "1|yes"
|
|
48
|
+
P="$(proj)"
|
|
49
|
+
check "show with no config file: exists false, ceiling default medium" "$(cfg "$CLI" "$P" show)|$(jf 'o.exists')|$(jf 'o.ceiling')" '0|false|{"value":"medium","source":"default"}'
|
|
50
|
+
check "show with no config: agents follow the ceiling, security-reviewer warning present" "$(jf 'o.agents.find((a) => a.name === "somi-security-reviewer").tier + "/" + o.agents.find((a) => a.name === "somi-security-reviewer").source')|$(jf 'o.warnings.length')" "medium/ceiling|1"
|
|
51
|
+
check "show created nothing" "$([ -e "$P/.somi" ] && echo made || echo none)" "none"
|
|
52
|
+
|
|
53
|
+
# --- cost.mapping.<host>.<tier>: the writer behind the Copilot model picker (#34, #35) ---------------
|
|
54
|
+
P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
|
|
55
|
+
check "set cost.mapping.copilot.high to a preference list: stored as an array, parsed value echoed" \
|
|
56
|
+
"$(cfg "$CLI" "$P" set cost.mapping.copilot.high 'big-a, big-b')|$(jf 'JSON.stringify(o.value)')|$(node -e 'process.stdout.write(JSON.stringify(JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")).cost.mapping.copilot.high))' "$P/.somi/config.json")" \
|
|
57
|
+
'0|["big-a","big-b"]|["big-a","big-b"]'
|
|
58
|
+
check "... with a warning naming the tiers the host map still lacks" "$(jf 'o.warnings.some((w) => w.startsWith("cost.mapping.copilot has no low, medium entry yet"))')" "true"
|
|
59
|
+
cfg "$CLI" "$P" set cost.mapping.copilot.low mini-x > /dev/null; cfg "$CLI" "$P" set cost.mapping.copilot.medium mid-x > /dev/null
|
|
60
|
+
check "a single id is stored as a string; a complete host map has no incomplete-map warning" "$(cfg "$CLI" "$P" get cost.mapping.copilot.low)|$(jf 'o.value')|$(cfg "$CLI" "$P" show)|$(jf 'o.warnings.some((w) => w.includes("cost.mapping"))')" "0|mini-x|0|false"
|
|
61
|
+
check "the resolver now enforces copilot's high tier with the first candidate" "$(CLAUDE_PROJECT_DIR="$P" env -u SOMI_COST_CEILING node "$ROOT_REPO/scripts/somi-dispatch.mjs" resolve --agent somi-designer --host copilot | node -e 'const o=JSON.parse(require("fs").readFileSync(0,"utf8")); process.stdout.write(o.model+"/"+o.enforced)')" "big-a/true"
|
|
62
|
+
check "a remap with --refuse-lowering is refused (64) with its own message" "$(cfg "$CLI" "$P" set cost.mapping.copilot.high cheap-x --refuse-lowering)|$(grep -c 'remaps a tier to a different model' "$TMP/err")" "64|1"
|
|
63
|
+
for v in 'bad id' 'a,a' ',' "$(printf 'm%d,' 1 2 3 4 5 6 7 8 9 | sed 's/,$//')"; do
|
|
64
|
+
check "a bad model value is a usage error (64): $v" "$(cfg "$CLI" "$P" set cost.mapping.copilot.high "$v")" "64"
|
|
65
|
+
done
|
|
66
|
+
check "set on a whole host map (no tier) is a usage error (64)" "$(cfg "$CLI" "$P" set cost.mapping.copilot gpt-x)" "64"
|
|
67
|
+
check "unset cost.mapping.copilot removes the host map" "$(cfg "$CLI" "$P" unset cost.mapping.copilot)|$(node -e 'process.stdout.write(String(JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")).cost.mapping))' "$P/.somi/config.json")" "0|undefined"
|
|
68
|
+
|
|
69
|
+
# --- show --host: the unmapped-host warning (#36) --------------------------------------------------
|
|
70
|
+
P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
|
|
71
|
+
check "show --host copilot, default config (10 agents pinned high), no mapping: one unmapped warning naming the count" \
|
|
72
|
+
"$(cfg "$CLI" "$P" show --host copilot)|$(jf 'o.warnings.filter((w) => w.startsWith("copilot has no model mapping, so 10 high-tier agent(s)")).length')" "0|1"
|
|
73
|
+
check "show --host claude-code: shipped mapping, no unmapped warning" "$(cfg "$CLI" "$P" show --host claude-code)|$(jf 'o.warnings')" "0|[]"
|
|
74
|
+
check "show without --host: no unmapped warning (the host is unknown)" "$(cfg "$CLI" "$P" show)|$(jf 'o.warnings')" "0|[]"
|
|
75
|
+
node -e 'const f=process.argv[1];const c=JSON.parse(require("fs").readFileSync(f,"utf8"));c.cost.mapping={copilot:{low:"m-low",medium:"m-mid",high:"m-high"}};require("fs").writeFileSync(f,JSON.stringify(c,null,2)+"\n")' "$P/.somi/config.json"
|
|
76
|
+
check "show --host copilot with cost.mapping.copilot set: no unmapped warning" "$(cfg "$CLI" "$P" show --host copilot)|$(jf 'o.warnings')" "0|[]"
|
|
77
|
+
P="$(proj)"; mkdir -p "$P/.somi"
|
|
78
|
+
printf '{"cost":{"ceiling":"low"}}\n' > "$P/.somi/config.json"
|
|
79
|
+
check "show --host copilot where nothing resolves high: no unmapped warning" "$(cfg "$CLI" "$P" show --host copilot)|$(jf 'o.warnings.some((w) => w.includes("no model mapping"))')" "0|false"
|
|
80
|
+
check "--host on set is a usage error (64)" "$(cfg "$CLI" "$P" set cost.ceiling high --host copilot)" "64"
|
|
81
|
+
check "--host with a bad name is a usage error (64)" "$(cfg "$CLI" "$P" show --host 'Co pilot')" "64"
|
|
82
|
+
|
|
83
|
+
# --- get / set / unset ----------------------------------------------------------------------------
|
|
84
|
+
P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
|
|
85
|
+
check "get cost.ceiling" "$(cfg "$CLI" "$P" get cost.ceiling)|$(jf 'o.value + "/" + o.source')" "0|medium/config"
|
|
86
|
+
check "get cost.agents.somi-coder" "$(cfg "$CLI" "$P" get cost.agents.somi-coder)|$(jf 'o.value + "/" + o.source')" "0|medium/override"
|
|
87
|
+
check "get cost.agents.nobody -> null" "$(cfg "$CLI" "$P" get cost.agents.nobody)|$(jf 'o.value + "/" + o.source')" "0|null/none"
|
|
88
|
+
check "set cost.ceiling low" "$(cfg "$CLI" "$P" set cost.ceiling low)|$(jf 'o.changed')" "0|true"
|
|
89
|
+
out="$(res "$P" somi-coder)"
|
|
90
|
+
check "resolver agrees: the new ceiling is live, coder (pinned medium) stays medium" "$(fld "$out" ceiling)/$(fld "$out" tier)" "low/medium"
|
|
91
|
+
cfg "$CLI" "$P" set cost.agents.somi-designer low > /dev/null
|
|
92
|
+
out="$(res "$P" somi-designer)"
|
|
93
|
+
check "resolver agrees: set cost.agents.somi-designer low -> low/override" "$(fld "$out" tier)/$(fld "$out" tier_source)" "low/override"
|
|
94
|
+
cfg "$CLI" "$P" set cost.agents.somi-designer high > /dev/null
|
|
95
|
+
out="$(res "$P" somi-designer)"
|
|
96
|
+
check "resolver agrees: set cost.agents.somi-designer high -> high/override (above the low ceiling)" "$(fld "$out" tier)/$(fld "$out" tier_source)" "high/override"
|
|
97
|
+
check "set to the same value is a no-op (changed false)" "$(cfg "$CLI" "$P" set cost.agents.somi-designer high)|$(jf 'o.changed')" "0|false"
|
|
98
|
+
cfg "$CLI" "$P" unset cost.agents.somi-designer > /dev/null
|
|
99
|
+
out="$(res "$P" somi-designer)"
|
|
100
|
+
check "unset removes the pin: designer follows the ceiling" "$(fld "$out" tier)/$(fld "$out" tier_source)" "low/ceiling"
|
|
101
|
+
check "unset of an absent entry succeeds with changed:false" "$(cfg "$CLI" "$P" unset cost.agents.somi-designer)|$(jf 'o.changed')" "0|false"
|
|
102
|
+
check "no temp file is left behind" "$(ls -A "$P/.somi" | tr '\n' ' ')" "config.json "
|
|
103
|
+
P2="$(proj)"; cfg "$CLI" "$P2" set cost.ceiling high > /dev/null
|
|
104
|
+
check "set on an absent config starts from the default file (pins exist) with the change applied" "$(node -e "const a=JSON.parse(require('fs').readFileSync('$P2/.somi/config.json','utf8')), d=JSON.parse(require('fs').readFileSync('$EXPECT','utf8')); d.cost.ceiling='high'; process.stdout.write(String(JSON.stringify(a)===JSON.stringify(d)))")" "true"
|
|
105
|
+
P2="$(proj)"
|
|
106
|
+
check "unset on an absent config is a no-op: changed false, nothing created" "$(cfg "$CLI" "$P2" unset cost.agents.somi-coder)|$(jf 'o.changed')|$([ -e "$P2/.somi" ] && echo made || echo none)" "0|false|none"
|
|
107
|
+
P2="$(proj)"; cfg "$CLI" "$P2" init > /dev/null; sleep 1; before="$(stat -c '%i %Y' "$P2/.somi/config.json")"
|
|
108
|
+
check "unset of an absent entry writes nothing (inode and mtime unchanged)" "$(cfg "$CLI" "$P2" unset cost.agents.nobody)|$(jf 'o.changed')|$(stat -c '%i %Y' "$P2/.somi/config.json")" "0|false|$before"
|
|
109
|
+
|
|
110
|
+
# --- preservation and ordering --------------------------------------------------------------------
|
|
111
|
+
P="$(proj)"; mkdir "$P/.somi"
|
|
112
|
+
printf '%s' '{"zeta":{"keep":[1,2,{"a":null}]},"loop":{"max":3},"cost":{"mapping":{},"ceiling":"high","agents":{"somi-coder":"low"}},"alpha":"x"}' > "$P/.somi/config.json"
|
|
113
|
+
cfg "$CLI" "$P" set cost.agents.somi-planner medium > /dev/null
|
|
114
|
+
check "unrelated and unknown top-level keys are preserved, key order is stable, new entry appended" \
|
|
115
|
+
"$(node -e "const o=JSON.parse(require('fs').readFileSync('$P/.somi/config.json','utf8')); process.stdout.write(Object.keys(o).join()+'|'+Object.keys(o.cost).join()+'|'+Object.keys(o.cost.agents).join()+'|'+JSON.stringify(o.zeta)+o.alpha+o.loop.max)")" \
|
|
116
|
+
'zeta,loop,cost,alpha|mapping,ceiling,agents|somi-coder,somi-planner|{"keep":[1,2,{"a":null}]}x3'
|
|
117
|
+
check "file is 2-space JSON with a trailing newline" "$(head -c 3 "$P/.somi/config.json" | tr '\n' '$')|$(tail -c 2 "$P/.somi/config.json" | od -An -c | tr -d ' ')" '{$ |}\n'
|
|
118
|
+
printf '%s' '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"; chmod 600 "$P/.somi/config.json"
|
|
119
|
+
cfg "$CLI" "$P" set cost.ceiling low > /dev/null
|
|
120
|
+
check "an existing file's mode is kept" "$(stat -c %a "$P/.somi/config.json")" "600"
|
|
121
|
+
|
|
122
|
+
# --- warnings --------------------------------------------------------------------------------------
|
|
123
|
+
P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
|
|
124
|
+
check "set security-reviewer low: succeeds with the fixed warning" "$(cfg "$CLI" "$P" set cost.agents.somi-security-reviewer low)|$(jf 'o.warnings')" '0|["somi-security-reviewer runs below high; pin it with: set cost.agents.somi-security-reviewer high"]'
|
|
125
|
+
check "show carries the same warning" "$(cfg "$CLI" "$P" show)|$(jf 'o.warnings.length')" "0|1"
|
|
126
|
+
check "set security-reviewer back to high clears it" "$(cfg "$CLI" "$P" set cost.agents.somi-security-reviewer high)|$(jf 'o.warnings')" "0|[]"
|
|
127
|
+
check "set an agent not in the default table: accepted, unknown warning" "$(cfg "$CLI" "$P" set cost.agents.my-agent high)|$(jf 'o.warnings.length')" "0|1"
|
|
128
|
+
cfg "$CLI" "$P" show > /dev/null
|
|
129
|
+
check "show flags the extra name unknown:true with no default" "$(jf 'JSON.stringify(o.agents.find((a) => a.name === "my-agent"))')" '{"name":"my-agent","tier":"high","source":"override","default":null,"unknown":true}'
|
|
130
|
+
|
|
131
|
+
# --- 64: arguments ---------------------------------------------------------------------------------
|
|
132
|
+
P="$(proj)"; cfg "$CLI" "$P" init > /dev/null; cp "$P/.somi/config.json" "$TMP/before"
|
|
133
|
+
for args in "set cost.mapping.x low" "set cost.foo low" "set loop.max 3" "set cost.ceiling turbo" "set cost.agents.somi-coder turbo" "set cost.agents.Bad_Name low" "set cost.agents.constructor low" "set cost.agents.__proto__ low" "unset cost.ceiling" "unset loop" "get loop.max" "set cost.ceiling" "frobnicate" "show extra" "set cost.ceiling low --bogus x"; do
|
|
134
|
+
# shellcheck disable=SC2086
|
|
135
|
+
rc="$(cfg "$CLI" "$P" $args)"
|
|
136
|
+
check "bad input exits 64 and prints nothing on stdout: $args" "$rc|$(wc -c < "$TMP/out" | tr -d ' ')" "64|0"
|
|
137
|
+
done
|
|
138
|
+
check "none of those changed the file" "$(cmp -s "$P/.somi/config.json" "$TMP/before" && echo same)" "same"
|
|
139
|
+
check "a project dir that is not a directory exits 64" "$(node "$CLI" show --project-dir "$TMP/no-such-dir" > /dev/null 2>&1; echo $?)" "64"
|
|
140
|
+
check "error output is ASCII and does not echo a raw hostile key" "$(cfg "$CLI" "$P" set "$(printf 'cost.\xe2\x80\xaeevil\nx')" low)|$(ascii_only "$TMP/err")" "64|yes"
|
|
141
|
+
|
|
142
|
+
# --- 67: the project's files -----------------------------------------------------------------------
|
|
143
|
+
bad_cfg() { # $1 = label, $2 = body
|
|
144
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '%s' "$2" > "$P/.somi/config.json"
|
|
145
|
+
rc="$(cfg "$CLI" "$P" set cost.ceiling low)"
|
|
146
|
+
check "$1: set exits 67, file untouched" "$rc|$(cat "$P/.somi/config.json")" "67|$2"
|
|
147
|
+
check "$1: show exits 67 too" "$(cfg "$CLI" "$P" show)" "67"
|
|
148
|
+
}
|
|
149
|
+
bad_cfg "invalid JSON" '{ not json'
|
|
150
|
+
bad_cfg "a JSON array" '[1]'
|
|
151
|
+
bad_cfg "an unknown cost key" '{"cost":{"cieling":"low"}}'
|
|
152
|
+
bad_cfg "a bad tier in the existing file" '{"cost":{"agents":{"somi-coder":"turbo"}}}'
|
|
153
|
+
bad_cfg "a bad ceiling value in the existing file" '{"cost":{"ceiling":"turbo"}}'
|
|
154
|
+
bad_cfg "a top-level ceiling" '{"ceiling":"low"}'
|
|
155
|
+
P="$(proj)"; mkdir "$P/.somi"; head -c 70000 /dev/zero | tr '\0' ' ' > "$P/.somi/config.json"; printf '{}' >> "$P/.somi/config.json"; cp "$P/.somi/config.json" "$TMP/big.before"
|
|
156
|
+
check "an oversize config exits 67, untouched" "$(cfg "$CLI" "$P" set cost.ceiling low)|$(cmp -s "$P/.somi/config.json" "$TMP/big.before" && echo same)" "67|same"
|
|
157
|
+
check "error text does not echo file text" "$(P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"cieling":"SECRET-VALUE"}}' > "$P/.somi/config.json"; cfg "$CLI" "$P" show > /dev/null; grep -c SECRET-VALUE "$TMP/err" | tr -d ' ')" "0"
|
|
158
|
+
|
|
159
|
+
# --- no-follow ---------------------------------------------------------------------------------------
|
|
160
|
+
echo KEEP > "$TMP/victim.txt"; OUTSIDE="$(mktemp -d -p "$TMP")"
|
|
161
|
+
P="$(proj)"; ln -s "$OUTSIDE" "$P/.somi"
|
|
162
|
+
for op in "set cost.ceiling low" init show; do
|
|
163
|
+
# shellcheck disable=SC2086
|
|
164
|
+
check "a symlinked .somi: $op exits 67" "$(cfg "$CLI" "$P" $op)" "67"
|
|
165
|
+
done
|
|
166
|
+
check "... nothing was written outside" "$(ls -A "$OUTSIDE" | wc -l | tr -d ' ')" "0"
|
|
167
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"ceiling":"high"}}' > "$TMP/real.json"; ln -s "$TMP/real.json" "$P/.somi/config.json"
|
|
168
|
+
check "a symlinked config.json: set exits 67" "$(cfg "$CLI" "$P" set cost.ceiling low)" "67"
|
|
169
|
+
check "... the link target is untouched" "$(cat "$TMP/real.json")" '{"cost":{"ceiling":"high"}}'
|
|
170
|
+
check "init over a symlinked config.json is a no-op (it exists)" "$(cfg "$CLI" "$P" init)|$(jf 'o.created')" "0|false"
|
|
171
|
+
P="$(proj)"; mkdir "$P/.somi"; ln -s "$TMP/not-there.json" "$P/.somi/config.json"
|
|
172
|
+
check "init over a dangling symlink is a no-op, nothing created through it" "$(cfg "$CLI" "$P" init)|$([ -e "$TMP/not-there.json" ] && echo made || echo none)" "0|none"
|
|
173
|
+
P="$(proj)"; mkdir -p "$P/.somi/config.json"
|
|
174
|
+
check "config.json as a directory: set exits 67" "$(cfg "$CLI" "$P" set cost.ceiling low)" "67"
|
|
175
|
+
|
|
176
|
+
# --- atomic: a failing write leaves the original and no temp file -----------------------------------
|
|
177
|
+
if [ "$(id -u)" -eq 0 ]; then
|
|
178
|
+
echo " skip read-only .somi cases: running as root, chmod does not stop root"
|
|
179
|
+
else
|
|
180
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"; chmod 555 "$P/.somi"
|
|
181
|
+
check "an unwritable .somi: set exits 67" "$(cfg "$CLI" "$P" set cost.ceiling low)" "67"
|
|
182
|
+
check "... the original is intact and no temp file exists" "$(cat "$P/.somi/config.json")|$(ls -A "$P/.somi" | tr '\n' ' ')" '{"cost":{"ceiling":"high"}}|config.json '
|
|
183
|
+
chmod 755 "$P/.somi"
|
|
184
|
+
fi
|
|
185
|
+
|
|
186
|
+
# --- a rewrite must not lose data or exceed what the reader accepts ------------------------------------
|
|
187
|
+
exact() { # $1 = total bytes of a 2-space config {pad, cost.ceiling low}
|
|
188
|
+
node -e "const mk=(n)=>JSON.stringify({pad:'x'.repeat(n),cost:{ceiling:'low'}},null,2)+'\n'; const base=mk(0).length; process.stdout.write(mk($1-base))"
|
|
189
|
+
}
|
|
190
|
+
P="$(proj)"; mkdir "$P/.somi"; exact 65535 > "$P/.somi/config.json"
|
|
191
|
+
check "a rewrite that lands exactly on the 64 KiB limit succeeds and the result is readable" "$(cfg "$CLI" "$P" set cost.ceiling high)|$(stat -c %s "$P/.somi/config.json")|$(cfg "$CLI" "$P" show)" "0|65536|0"
|
|
192
|
+
P="$(proj)"; mkdir "$P/.somi"; exact 65536 > "$P/.somi/config.json"; cp "$P/.somi/config.json" "$TMP/lim.before"
|
|
193
|
+
check "a rewrite one byte over the limit is refused (67), file untouched" "$(cfg "$CLI" "$P" set cost.ceiling high)|$(cmp -s "$P/.somi/config.json" "$TMP/lim.before" && echo same)" "67|same"
|
|
194
|
+
P="$(proj)"; mkdir "$P/.somi"; node -e "const n=20000; require('fs').writeFileSync('$P/.somi/config.json', '{\"deep\":'+'['.repeat(n)+']'.repeat(n)+',\"cost\":{\"ceiling\":\"low\"}}')"; cp "$P/.somi/config.json" "$TMP/deep.before"
|
|
195
|
+
check "20000-deep unrelated nesting: set exits 67 with one line, no stack trace, file untouched" "$(cfg "$CLI" "$P" set cost.ceiling high)|$(wc -l < "$TMP/err" | tr -d ' ')|$(grep -c ' at ' "$TMP/err" | tr -d ' ')|$(cmp -s "$P/.somi/config.json" "$TMP/deep.before" && echo same)" "67|1|0|same"
|
|
196
|
+
for spec in 'big integer|{"big":12345678901234567890,"cost":{"ceiling":"low"}}' 'out-of-range number|{"f":1e400,"cost":{"ceiling":"low"}}' 'duplicate key|{"a":1,"a":2,"cost":{"ceiling":"low"}}' 'nested duplicate key|{"o":{"k":1,"k":2},"cost":{"ceiling":"low"}}' 'duplicate inside cost|{"cost":{"ceiling":"low","ceiling":"high"}}'; do
|
|
197
|
+
label="${spec%%|*}"; body="${spec#*|}"
|
|
198
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '%s' "$body" > "$P/.somi/config.json"
|
|
199
|
+
check "$label: set exits 67 and the file is untouched" "$(cfg "$CLI" "$P" set cost.ceiling high)|$(cat "$P/.somi/config.json")" "67|$body"
|
|
200
|
+
check "$label: show still works (read-only)" "$(cfg "$CLI" "$P" show)" "0"
|
|
201
|
+
done
|
|
202
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '%s' '{"s":"a,\"k\": 12345678901234567890 {","n":1.0,"safe":9007199254740991,"cost":{"ceiling":"low"}}' > "$P/.somi/config.json"
|
|
203
|
+
check "numbers and duplicates inside strings, safe integers and 1.0 do not trigger the refusal" "$(cfg "$CLI" "$P" set cost.ceiling high)|$(node -e "const o=JSON.parse(require('fs').readFileSync('$P/.somi/config.json','utf8')); process.stdout.write(o.s+'|'+o.safe+'|'+o.n+'|'+o.cost.ceiling)")" '0|a,"k": 12345678901234567890 {|9007199254740991|1|high'
|
|
204
|
+
|
|
205
|
+
# --- the ceiling the resolver would use ---------------------------------------------------------------------
|
|
206
|
+
envcfg() { local p=$1; shift; env SOMI_COST_CEILING="$ENVV" node "$CLI" "$@" --project-dir "$p" > "$TMP/out" 2> "$TMP/err"; echo $?; }
|
|
207
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '%s' '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"
|
|
208
|
+
ENVV=low
|
|
209
|
+
check "SOMI_COST_CEILING outranks the config: effective ceiling low from env, tiers follow it, warnings say why" "$(envcfg "$P" show)|$(jf 'JSON.stringify(o.effective_ceiling)')|$(jf 'o.agents.find((a) => a.name === "somi-coder").tier')|$(jf 'o.warnings.length')|$(jf 'o.ceiling.value')" '0|{"value":"low","source":"env"}|low|2|high'
|
|
210
|
+
check "set reports the effective ceiling too" "$(envcfg "$P" set cost.agents.somi-coder medium)|$(jf 'o.effective_ceiling.source')|$(jf 'o.warnings.length')" "0|env|2"
|
|
211
|
+
ENVV=turbo
|
|
212
|
+
check "an invalid SOMI_COST_CEILING is exit 64" "$(envcfg "$P" show)" "64"
|
|
213
|
+
P="$(proj)"; mkdir -p "$P/.somi/somi-state"; printf '%s' '{}' > "$P/.somi/config.json"; printf '%s' '{"ceiling":"low","ceiling_origin":"cli"}' > "$P/.somi/somi-state/ceiling.json"
|
|
214
|
+
check "a persisted cli ceiling is in force when the config sets none: source state, with its warning" "$(cfg "$CLI" "$P" show)|$(jf 'JSON.stringify(o.effective_ceiling)')|$(jf 'o.warnings.length')" '0|{"value":"low","source":"state"}|2'
|
|
215
|
+
printf '%s' '{"ceiling":"low","ceiling_origin":"config"}' > "$P/.somi/somi-state/ceiling.json"
|
|
216
|
+
check "a persisted ceiling that was not set by a flag or env is ignored: default medium" "$(cfg "$CLI" "$P" show)|$(jf 'JSON.stringify(o.effective_ceiling)')" '0|{"value":"medium","source":"default"}'
|
|
217
|
+
printf '%s' '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"; printf '%s' '{"ceiling":"low","ceiling_origin":"cli"}' > "$P/.somi/somi-state/ceiling.json"
|
|
218
|
+
check "the config outranks a persisted ceiling" "$(cfg "$CLI" "$P" show)|$(jf 'JSON.stringify(o.effective_ceiling)')" '0|{"value":"high","source":"config"}'
|
|
219
|
+
out="$(CLAUDE_PROJECT_DIR="$P" env -u SOMI_COST_CEILING node "$ROOT_REPO/scripts/somi-dispatch.mjs" resolve --agent somi-coder)"
|
|
220
|
+
check "and the resolver agrees with that" "$(fld "$out" ceiling)/$(fld "$out" ceiling_source)" "high/config"
|
|
221
|
+
P="$(proj)"; mkdir -p "$P/.somi/somi-state"; printf '%s' '{}' > "$P/.somi/config.json"; printf '{ bad' > "$P/.somi/somi-state/ceiling.json"
|
|
222
|
+
check "a corrupt state file is exit 67 for show" "$(cfg "$CLI" "$P" show)" "67"
|
|
223
|
+
|
|
224
|
+
# --- small behaviours ------------------------------------------------------------------------------------------
|
|
225
|
+
P="$(proj)"
|
|
226
|
+
check "a new file honours the umask (umask 077 -> mode 600)" "$( (umask 077; node "$CLI" init --project-dir "$P" > /dev/null 2>&1); stat -c %a "$P/.somi/config.json")" "600"
|
|
227
|
+
P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
|
|
228
|
+
check "the agent name somi is accepted without the not-a-shipped-agent warning" "$(cfg "$CLI" "$P" set cost.agents.somi low)|$(jf 'o.warnings.filter((w) => /not a shipped/.test(w)).length')" "0|0"
|
|
229
|
+
P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
|
|
230
|
+
check "no temp file is left behind after many writes" "$(for t in low medium high low; do cfg "$CLI" "$P" set cost.ceiling $t > /dev/null; done; ls -A "$P/.somi" | tr '\n' ' ')" "config.json "
|
|
231
|
+
|
|
232
|
+
# --- red proofs on mutated copies --------------------------------------------------------------------
|
|
233
|
+
mut() { # $1 = name, $2 = file (relative to scripts/), $3 = exact text, $4 = replacement
|
|
234
|
+
local d="$TMP/$1"; mkdir -p "$d/scripts"; [ -d "$d/scripts/lib" ] || cp -r "$ROOT_REPO/scripts/lib" "$d/scripts/lib"; cp "$CLI" "$d/scripts/"
|
|
235
|
+
M_FILE="$d/scripts/$2" M_FROM="$3" M_TO="$4" node -e "const f=process.env.M_FILE,fs=require('fs'),s=fs.readFileSync(f,'utf8');if(!s.includes(process.env.M_FROM))process.exit(3);fs.writeFileSync(f,s.replace(process.env.M_FROM,()=>process.env.M_TO))" || bad "mutant $1 did not apply"
|
|
236
|
+
}
|
|
237
|
+
mut_more() { M_FILE="$TMP/$1/scripts/$2" M_FROM="$3" M_TO="$4" node -e "const f=process.env.M_FILE,fs=require('fs'),s=fs.readFileSync(f,'utf8');if(!s.includes(process.env.M_FROM))process.exit(3);fs.writeFileSync(f,s.replace(process.env.M_FROM,()=>process.env.M_TO))" || bad "mutant $1 (second edit) did not apply"; }
|
|
238
|
+
mut allowlist lib/cost-config-edit.mjs "if (!m) throw new EditError(" "if (false) throw new EditError("
|
|
239
|
+
P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
|
|
240
|
+
rc="$(cfg "$TMP/allowlist/scripts/somi-config.mjs" "$P" set cost.bogus.x low)"
|
|
241
|
+
if [ "$rc" != 64 ]; then ok "red proof: without the key allowlist a bad key is no longer a clean 64 (rc $rc)"; else bad "red proof: allowlist mutant still gives 64"; fi
|
|
242
|
+
mut wholeblock somi-config.mjs "checkCost(next.cost, (m) => usage(m));" ""
|
|
243
|
+
P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
|
|
244
|
+
rc="$(cfg "$TMP/wholeblock/scripts/somi-config.mjs" "$P" set cost.agents.constructor low)"
|
|
245
|
+
if [ "$rc" = 0 ] && grep -q constructor "$P/.somi/config.json"; then ok "red proof: without whole-block validation a forbidden agent name is written"; else bad "red proof: whole-block mutant did not write (rc $rc)"; fi
|
|
246
|
+
mut nofollow-dir somi-config.mjs "if (d && !d.isDirectory()) project(" "if (false) project("
|
|
247
|
+
mut_more nofollow-dir somi-config.mjs "if (!loc.dirStat?.isDirectory()) project(" "if (false) project("
|
|
248
|
+
mut_more nofollow-dir somi-config.mjs "if (!now || !now.isDirectory() || now.dev !== loc.dirStat.dev || now.ino !== loc.dirStat.ino) project(" "if (false) project("
|
|
249
|
+
P="$(proj)"; OUTSIDE="$(mktemp -d -p "$TMP")"; ln -s "$OUTSIDE" "$P/.somi"
|
|
250
|
+
cfg "$TMP/nofollow-dir/scripts/somi-config.mjs" "$P" init > /dev/null
|
|
251
|
+
if [ -e "$OUTSIDE/config.json" ]; then ok "red proof: without the .somi link check init writes through the link"; else bad "red proof: no-follow (.somi) mutant wrote nothing"; fi
|
|
252
|
+
mut nofollow-cfg lib/cost-ceiling.mjs "| (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0)" "| (fs.constants.O_NONBLOCK ?? 0)"
|
|
253
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"ceiling":"high"}}' > "$TMP/real2.json"; ln -s "$TMP/real2.json" "$P/.somi/config.json"
|
|
254
|
+
rc="$(cfg "$TMP/nofollow-cfg/scripts/somi-config.mjs" "$P" set cost.ceiling low)"
|
|
255
|
+
if [ "$rc" = 0 ]; then ok "red proof: without O_NOFOLLOW a symlinked config.json is read through (set succeeds instead of exit 67)"; else bad "red proof: no-follow (config.json) mutant still refused"; fi
|
|
256
|
+
mut sizecap somi-config.mjs "if (Buffer.byteLength(text) > MAX_CONFIG_BYTES) project(" "if (false) project("
|
|
257
|
+
P="$(proj)"; mkdir "$P/.somi"; exact 65536 > "$P/.somi/config.json"
|
|
258
|
+
rc="$(cfg "$TMP/sizecap/scripts/somi-config.mjs" "$P" set cost.ceiling high)"
|
|
259
|
+
if [ "$rc" = 0 ] && [ "$(stat -c %s "$P/.somi/config.json")" -gt 65536 ]; then ok "red proof: without the size check a file its own reader rejects is written"; else bad "red proof: size-cap mutant (rc $rc)"; fi
|
|
260
|
+
mut hazard somi-config.mjs "if (why) project(" "if (false) project("
|
|
261
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '%s' '{"big":12345678901234567890,"cost":{"ceiling":"low"}}' > "$P/.somi/config.json"
|
|
262
|
+
rc="$(cfg "$TMP/hazard/scripts/somi-config.mjs" "$P" set cost.ceiling high)"
|
|
263
|
+
if [ "$rc" = 0 ] && ! grep -q 12345678901234567890 "$P/.somi/config.json"; then ok "red proof: without the hazard check a big integer is silently rewritten"; else bad "red proof: hazard mutant (rc $rc)"; fi
|
|
264
|
+
mut absent lib/cost-config-edit.mjs "const next = absent ? buildDefaultConfig() : cfg;" "const next = cfg ?? {};"
|
|
265
|
+
P="$(proj)"; rc="$(cfg "$TMP/absent/scripts/somi-config.mjs" "$P" set cost.ceiling high)"
|
|
266
|
+
if [ "$rc" = 0 ] && [ "$(node -e "console.log(JSON.parse(require('fs').readFileSync('$P/.somi/config.json','utf8')).cost.agents === undefined)")" = true ]; then ok "red proof: without starting from the defaults a set on an absent file loses the pins"; else bad "red proof: absent mutant (rc $rc)"; fi
|
|
267
|
+
mut envrank somi-config.mjs "if (env !== undefined && env !== '') {" "if (false) {"
|
|
268
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '%s' '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"
|
|
269
|
+
ENVV=low; env SOMI_COST_CEILING=low node "$TMP/envrank/scripts/somi-config.mjs" show --project-dir "$P" > "$TMP/out" 2>/dev/null
|
|
270
|
+
if [ "$(jf 'o.effective_ceiling.source')" = config ]; then ok "red proof: without reading SOMI_COST_CEILING the effective ceiling ignores it"; else bad "red proof: env mutant"; fi
|
|
271
|
+
if [ "$(id -u)" -ne 0 ]; then
|
|
272
|
+
mut atomic somi-config.mjs "fd = fs.openSync(tmp, WRITE_FLAGS, 0o644);" "fs.writeFileSync(loc.file, text); return true;"
|
|
273
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"; chmod 555 "$P/.somi"
|
|
274
|
+
rc="$(cfg "$TMP/atomic/scripts/somi-config.mjs" "$P" set cost.ceiling low)"
|
|
275
|
+
if [ "$rc" = 0 ]; then ok "red proof: a direct (non-temp-file) write succeeds where the atomic one refuses"; else bad "red proof: atomic mutant still failed (rc $rc)"; fi
|
|
276
|
+
chmod 755 "$P/.somi"
|
|
277
|
+
fi
|
|
278
|
+
|
|
279
|
+
echo "somi-config tests: $pass ok, $fail failed"
|
|
280
|
+
[ "$fail" -eq 0 ] || exit 1
|
|
281
|
+
node "$ROOT_REPO/tests/scripts/lib/somi-mcp-config-tests.mjs" || exit 1
|