@skathio/somi 4.0.0 → 4.1.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 +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.copilot-extension/extension.json +1 -1
- package/.copilot-extension/marketplace.json +1 -1
- package/README.md +11 -5
- package/VERSION +1 -1
- package/agents/somi-coder.md +4 -228
- package/agents/somi-designer.md +4 -160
- package/agents/somi-discovery-analyst.md +4 -276
- package/agents/somi-flow.md +47 -0
- package/agents/somi-general.md +36 -0
- package/agents/somi-planner.md +4 -341
- package/agents/somi-reviewer.md +4 -199
- package/agents/somi.md +81 -253
- package/commands/adopt.md +6 -84
- package/commands/architecture-review.md +11 -86
- package/commands/atlas.md +10 -25
- package/commands/code-loop.md +10 -221
- package/commands/code-parallel.md +10 -151
- package/commands/code.md +9 -157
- package/commands/debug.md +9 -131
- package/commands/design.md +9 -160
- package/commands/discover.md +9 -194
- package/commands/impact.md +9 -25
- package/commands/incident.md +9 -39
- package/commands/plan-loop.md +9 -181
- package/commands/plan.md +9 -244
- package/commands/pr.md +10 -25
- package/commands/refactor-design.md +11 -89
- package/commands/refactor.md +11 -50
- package/commands/release-readiness.md +11 -70
- package/commands/review-panel.md +10 -141
- package/commands/review.md +11 -181
- package/commands/security-review.md +11 -75
- package/commands/ship-loop.md +9 -260
- package/commands/ship.md +9 -115
- package/commands/somi-config.md +12 -124
- package/commands/test-strategy.md +11 -75
- package/commands/upgrade.md +9 -72
- package/hooks/hooks.json +1 -1
- package/hooks/lib/common.mjs +15 -13
- package/hooks/pre-tool/block-dangerous-bash.mjs +1 -1
- package/hooks/pre-tool/block-secret-writes.mjs +5 -7
- package/hooks/pre-tool/guard-cost-lowering.mjs +26 -11
- package/hooks/pre-tool/guard-protected-paths.mjs +54 -34
- package/hooks/session-start/ensure-default-config.mjs +34 -42
- package/package.json +1 -1
- package/scripts/lib/config-files.mjs +145 -0
- package/scripts/lib/cost-ceiling.mjs +29 -22
- package/scripts/lib/cost-defaults.mjs +2 -0
- package/scripts/lib/escalation-facts.mjs +146 -0
- package/scripts/lib/escalation.mjs +129 -0
- package/scripts/lib/findings-ledger.mjs +241 -0
- package/scripts/lib/install-text.mjs +97 -0
- package/scripts/lib/loop-caps.mjs +140 -0
- package/scripts/lib/loop-diff.mjs +12 -70
- package/scripts/lib/loop-engine.mjs +226 -0
- package/scripts/lib/loop-escalate.mjs +49 -0
- package/scripts/lib/loop-exit.mjs +47 -0
- package/scripts/lib/loop-notes-compact.mjs +72 -0
- package/scripts/lib/loop-notes.mjs +278 -0
- package/scripts/lib/loop-review.mjs +355 -12
- package/scripts/lib/loop-state.mjs +44 -0
- package/scripts/lib/loop-step-close.mjs +75 -0
- package/scripts/lib/loop-step-kit.mjs +179 -0
- package/scripts/lib/loop-step-review.mjs +140 -0
- package/scripts/lib/loop-step-tool.mjs +89 -0
- package/scripts/lib/loop-step.mjs +301 -0
- package/scripts/lib/mcp-project-root.mjs +18 -7
- package/scripts/lib/path-facts.mjs +187 -0
- package/scripts/lib/path-safety.mjs +171 -0
- package/scripts/lib/run-card.mjs +73 -0
- package/scripts/size-budget-overrides.json +5 -13
- package/scripts/somi-card.mjs +39 -0
- package/scripts/somi-check.mjs +4 -3
- package/scripts/somi-config.mjs +113 -50
- package/scripts/somi-findings.mjs +56 -271
- package/scripts/somi-loop.mjs +77 -446
- package/scripts/somi-mcp.mjs +27 -96
- package/scripts/validate.sh +92 -54
- package/skills/flow-adopt/SKILL.md +92 -0
- package/skills/flow-architecture-review/SKILL.md +94 -0
- package/skills/flow-atlas/SKILL.md +34 -0
- package/skills/flow-code/SKILL.md +167 -0
- package/skills/flow-code-loop/SKILL.md +263 -0
- package/skills/flow-code-parallel/SKILL.md +160 -0
- package/skills/flow-debug/SKILL.md +141 -0
- package/skills/flow-design/SKILL.md +170 -0
- package/skills/flow-discover/SKILL.md +204 -0
- package/skills/flow-impact/SKILL.md +35 -0
- package/skills/flow-incident/SKILL.md +49 -0
- package/skills/flow-plan/SKILL.md +254 -0
- package/skills/flow-plan-loop/SKILL.md +254 -0
- package/skills/flow-pr/SKILL.md +34 -0
- package/skills/flow-refactor/SKILL.md +58 -0
- package/skills/flow-refactor-design/SKILL.md +97 -0
- package/skills/flow-release-readiness/SKILL.md +82 -0
- package/skills/flow-review/SKILL.md +193 -0
- package/skills/flow-review-panel/SKILL.md +154 -0
- package/skills/flow-security-review/SKILL.md +83 -0
- package/skills/flow-ship/SKILL.md +125 -0
- package/skills/flow-ship-loop/SKILL.md +274 -0
- package/skills/flow-somi-config/SKILL.md +142 -0
- package/skills/flow-status/SKILL.md +43 -0
- package/skills/flow-test-strategy/SKILL.md +83 -0
- package/skills/flow-upgrade/SKILL.md +82 -0
- package/skills/role-coder/SKILL.md +247 -0
- package/skills/role-designer/SKILL.md +172 -0
- package/skills/role-discovery-analyst/SKILL.md +288 -0
- package/skills/role-planner/SKILL.md +353 -0
- package/skills/role-reviewer/SKILL.md +218 -0
- package/skills/somi-checkpoint/SKILL.md +95 -0
- package/skills/somi-dispatch/SKILL.md +14 -14
- package/skills/somi-routing/SKILL.md +6 -2
- package/tests/hooks/cases/block-secret-writes.json +6 -1
- package/tests/hooks/cases/guard-protected-paths.json +44 -2
- package/tests/hooks/run.sh +21 -0
- package/tests/scripts/checkpoint-gate.sh +2 -2
- package/tests/scripts/cost-defaults.sh +2 -0
- package/tests/scripts/cost-hardcap.sh +26 -17
- package/tests/scripts/dispatch-line-gate.sh +4 -4
- package/tests/scripts/dispatch-reference-gate.sh +14 -14
- package/tests/scripts/ensure-default-config.sh +4 -4
- package/tests/scripts/escalation.sh +409 -0
- package/tests/scripts/eval-runner.sh +8 -7
- package/tests/scripts/fact-sheet.sh +296 -0
- package/tests/scripts/global-config.sh +167 -0
- package/tests/scripts/goldens/somi-loop.json +2 -2
- package/tests/scripts/lib/dispatch-reference-gate.mjs +14 -5
- package/tests/scripts/lib/escalation-facts-tests.mjs +140 -0
- package/tests/scripts/lib/escalation-tests.mjs +154 -0
- package/tests/scripts/lib/findings-ledger-tests.mjs +118 -0
- package/tests/scripts/lib/loop-engine-tests.mjs +287 -0
- package/tests/scripts/lib/loop-escalate-tests.mjs +356 -0
- package/tests/scripts/lib/loop-flow-gate.mjs +173 -0
- package/tests/scripts/lib/loop-notes-tests.mjs +371 -0
- package/tests/scripts/lib/loop-step-cli-tests.mjs +141 -0
- package/tests/scripts/lib/loop-step-close-tests.mjs +351 -0
- package/tests/scripts/lib/loop-step-lenient-tests.mjs +114 -0
- package/tests/scripts/lib/loop-step-state-tests.mjs +127 -0
- package/tests/scripts/lib/loop-step-tests.mjs +499 -0
- package/tests/scripts/lib/loop-step-unwritten-tests.mjs +55 -0
- package/tests/scripts/lib/path-facts-tests.mjs +198 -0
- package/tests/scripts/lib/path-safety-tests.mjs +201 -0
- package/tests/scripts/lib/run-suites.mjs +139 -0
- package/tests/scripts/lib/site-roadmap-gate.mjs +64 -0
- package/tests/scripts/lib/sizing-score-tests.mjs +210 -0
- package/tests/scripts/lib/sizing-set-tests.mjs +131 -0
- package/tests/scripts/lib/somi-mcp-loop-tests.mjs +226 -0
- package/tests/scripts/lib/somi-mcp-tests.mjs +21 -1
- package/tests/scripts/loop-engine.sh +22 -0
- package/tests/scripts/loop-flow-gate.sh +11 -0
- package/tests/scripts/review-panel-seats.sh +4 -4
- package/tests/scripts/run-card.sh +57 -0
- package/tests/scripts/run-suites.sh +74 -0
- package/tests/scripts/run.sh +11 -0
- package/tests/scripts/site-roadmap-gate.sh +76 -0
- package/tests/scripts/size-tier.sh +3 -3
- package/tests/scripts/somi-agent-dispatch-contract.sh +23 -3
- package/tests/scripts/somi-config.sh +9 -4
- package/tests/scripts/somi-mcp.sh +1 -0
- package/tests/scripts/suite-plan.json +20 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Guards the fact-sheet library modules under scripts/lib. Each section runs a module's test lib, then proves
|
|
3
|
+
# the suite has teeth: every mutation of the module, applied to a scratch copy, must turn the test NAMED for it red
|
|
4
|
+
# (a mutant that fails some other way, or not at all, is a failure). Hermetic: temp tree only, no network, no model.
|
|
5
|
+
set -uo pipefail
|
|
6
|
+
umask 022
|
|
7
|
+
|
|
8
|
+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
9
|
+
TMP="$(mktemp -d)"
|
|
10
|
+
trap 'chmod -R u+rwx "$TMP" 2>/dev/null; rm -rf "$TMP"' EXIT
|
|
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
|
+
|
|
15
|
+
# run_suite <test lib> <module>: prints the suite's lines, folds its SUMMARY into the totals.
|
|
16
|
+
run_suite() {
|
|
17
|
+
local out rc total failed
|
|
18
|
+
out="$(node "$1" "$2" 2>&1)"; rc=$?
|
|
19
|
+
printf '%s\n' "$out" | grep -v '^SUMMARY'
|
|
20
|
+
total="$(printf '%s\n' "$out" | awk '/^SUMMARY/{print $2}')"; failed="$(printf '%s\n' "$out" | awk '/^SUMMARY/{print $3}')"
|
|
21
|
+
pass=$((pass + ${total:-0} - ${failed:-0})); fail=$((fail + ${failed:-1}))
|
|
22
|
+
[ "$rc" = 0 ] || [ "${failed:-1}" -gt 0 ] || fail=$((fail+1))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# mutate <test lib> <module> <label> <test it must break> <from> <to>: the first <from> in the module becomes <to>.
|
|
26
|
+
mutate() {
|
|
27
|
+
local lib="$1" mod="$2" label="$3" named="$4" mut="$TMP/mutant-$(basename "$2")"
|
|
28
|
+
node -e "const fs=require('fs');const s=fs.readFileSync(process.argv[1],'utf8');const t=s.replace(process.argv[2],()=>process.argv[3]);if(t===s)process.exit(3);fs.writeFileSync(process.argv[4],t)" "$mod" "$5" "$6" "$mut"
|
|
29
|
+
if [ $? != 0 ]; then bad "mutation '$label' did not change the module (stale pattern)"; return; fi
|
|
30
|
+
local out; out="$(node "$lib" "$mut" 2>&1)"
|
|
31
|
+
if grep -qF -- " FAIL $named" <<<"$out"; then ok "mutation '$label' turns '$named' red"; else bad "mutation '$label' did not turn '$named' red"; fi
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# ---- scripts/lib/path-safety.mjs ----
|
|
35
|
+
echo "== fact sheet: path safety =="
|
|
36
|
+
PS="$ROOT/scripts/lib/path-safety.mjs"; PST="$ROOT/tests/scripts/lib/path-safety-tests.mjs"
|
|
37
|
+
run_suite "$PST" "$PS"
|
|
38
|
+
ps() { mutate "$PST" "$PS" "$@"; }
|
|
39
|
+
T_STAT='a deny-listed name is decided without any filesystem call'
|
|
40
|
+
ps 'deny-list stats the file' "$T_STAT" "if (denied) return { kind: 'denied' };" "if (denied) { try { fs.lstatSync(root); } catch { /* the probe is the call itself */ } return { kind: 'denied' }; }"
|
|
41
|
+
ps 'refusal drops the denied fact' 'a malformed deny-listed name returns the refusal id' 'if (bad) return refused(bad, denied);' 'if (bad) return refused(bad);'
|
|
42
|
+
ps 'case folding removed' 'denies case variants' ".normalize('NFKC').toUpperCase().toLowerCase()" ".normalize('NFKC')"
|
|
43
|
+
ps 'compatibility normalisation removed' 'denies a name written with another separator' ".normalize('NFKC').toUpperCase().toLowerCase()" '.toUpperCase().toLowerCase()'
|
|
44
|
+
ps 'full case folding reduced to lower-casing' 'denies a name that only full case folding' '.toUpperCase().toLowerCase()' '.toLowerCase()'
|
|
45
|
+
ps 'backslash not a separator in the deny test' 'denies a name written with another separator' 'const SEPARATORS = /[\\/]+/;' 'const SEPARATORS = /[/]+/;'
|
|
46
|
+
ps 'trailing dot and space not stripped' 'denies a name written with another separator' 'trimDots(piece)' 'piece'
|
|
47
|
+
T_SEP='denies a name whose compatibility fold writes a separator'
|
|
48
|
+
ps 'fold, then split, restored' "$T_SEP" 'return raw.split(SEPARATORS).some((segment) => {' "return raw.normalize('NFKC').toUpperCase().toLowerCase().split(SEPARATORS).some((segment) => {"
|
|
49
|
+
ps 'the folded segment tested only as its pieces' "$T_SEP" 'new Set([folded, ...folded.split(SEPARATORS)])' 'new Set(folded.split(SEPARATORS))'
|
|
50
|
+
ps 'the folded segment tested only whole' "$T_SEP" 'new Set([folded, ...folded.split(SEPARATORS)])' 'new Set([folded])'
|
|
51
|
+
T_BIG='a huge name is refused as path_length'
|
|
52
|
+
ps 'the raw-length bound removed' "$T_BIG" 'if (raw.length > MAX_PATH_CHARS) return true;' ''
|
|
53
|
+
ps 'the regex trim restored without the bound' "$T_BIG" "if (raw.length > MAX_PATH_CHARS) return true;
|
|
54
|
+
return raw.split(SEPARATORS).some((segment) => {
|
|
55
|
+
const folded = foldName(segment);
|
|
56
|
+
return [...new Set([folded, ...folded.split(SEPARATORS)])].some((piece) => {
|
|
57
|
+
const name = trimDots(piece);" "return raw.split(SEPARATORS).some((segment) => {
|
|
58
|
+
const folded = foldName(segment);
|
|
59
|
+
return [...new Set([folded, ...folded.split(SEPARATORS)])].some((piece) => {
|
|
60
|
+
const name = piece.replace(/[. ]+\$/, '');"
|
|
61
|
+
ps 'the short-name rule removed' 'denies Windows short names' '/~\d/.test(name) || ' ''
|
|
62
|
+
ps 'the stream-suffix rule removed' 'denies Windows short names' "name.includes(':') || " ''
|
|
63
|
+
ps 'the short-name rule over-matches a bare tilde' 'does not deny look-alikes' '/~\d/' '/~/'
|
|
64
|
+
ps 'the short-name rule narrowed to a bare stem' 'floors drive-letter paths and ~<digit> names' '/~\d/.test(name)' '/^[a-z]+~\d$/.test(name)'
|
|
65
|
+
ps 'the drive-letter floor removed' 'floors drive-letter paths and ~<digit> names' "name.includes(':') || " ''
|
|
66
|
+
ps 'the .ssh segment not matched' 'denies .env, key and certificate' "'.ssh', " ''
|
|
67
|
+
ps 'the .tfvars suffix not matched' 'denies .env, key and certificate' "'.tfvars', " ''
|
|
68
|
+
ps 'the .npmrc name not matched' 'denies .env, key and certificate' "'.npmrc', " ''
|
|
69
|
+
T_HOOK='denies the secret names the repository secret-write hook denies'
|
|
70
|
+
T_LIST='the hook secret-name patterns and the representative table list the same literals'
|
|
71
|
+
T_MATCH='each hook pattern, built with its own flags, matches the basename of its representative'
|
|
72
|
+
T_REP='every representative of a hook pattern is denied here'
|
|
73
|
+
T_ADDED='denies .env, key and certificate'
|
|
74
|
+
T_LOOK='does not deny the look-alikes of the added names'
|
|
75
|
+
ps 'the -key.json suffix not matched' "$T_HOOK" "'-key.json', " ''
|
|
76
|
+
ps 'the -key.json suffix over-matches key.json' 'does not deny look-alikes of those names' "'-key.json'" "'key.json'"
|
|
77
|
+
ps 'the credentials.json suffix not matched' "$T_REP" ", 'credentials.json'" ''
|
|
78
|
+
ps 'the credentials.json suffix not matched (file in the name table)' "$T_ADDED" ", 'credentials.json'" ''
|
|
79
|
+
ps 'the credentials.json suffix over-matches any json' 'does not deny look-alikes of those names' ", 'credentials.json'" ", '.json'"
|
|
80
|
+
ps 'the service-account rule not matched' "$T_HOOK" 'service[-_]?account[^]*\.json$|' ''
|
|
81
|
+
ps 'the service-account rule loses its extension' 'does not deny look-alikes of those names' 'service[-_]?account[^]*\.json$' 'service[-_]?account'
|
|
82
|
+
ps 'the service-account rule loses its underscore form' "$T_ADDED" 'service[-_]?account' 'service-?account'
|
|
83
|
+
ps 'the service-account rule loses its optional separator' "$T_ADDED" 'service[-_]?account' 'service[-_]account'
|
|
84
|
+
ps 'the service-account rule matches a bare account.json' "$T_LOOK" 'service[-_]?account' 'account'
|
|
85
|
+
ps 'the client_secret rule not matched' "$T_ADDED" '|client_secret[^]*\.json$' ''
|
|
86
|
+
ps 'the client_secret rule loses its extension' "$T_LOOK" 'client_secret[^]*\.json$' 'client_secret'
|
|
87
|
+
ps 'the .netrc suffix not matched' "$T_REP" " '.netrc', '.pgpass', '-key.json'" " '.pgpass', '-key.json'"
|
|
88
|
+
ps 'the .netrc suffix not matched (name table)' "$T_ADDED" " '.netrc', '.pgpass', '-key.json'" " '.pgpass', '-key.json'"
|
|
89
|
+
ps 'the .pgpass suffix not matched' "$T_REP" " '.pgpass', '-key.json'" " '-key.json'"
|
|
90
|
+
ps 'the .pgpass suffix not matched (name table)' "$T_ADDED" " '.pgpass', '-key.json'" " '-key.json'"
|
|
91
|
+
ps 'the .tfstate.backup suffix not matched' "$T_ADDED" " '.tfstate.backup'," ''
|
|
92
|
+
ps 'the .tfstate.backup suffix over-matches any .backup' "$T_LOOK" "'.tfstate.backup'" "'.backup'"
|
|
93
|
+
ps 'the exact key.json rule removed' "$T_ADDED" '|^key\.json$' ''
|
|
94
|
+
ps 'the key.json rule unanchored' 'does not deny look-alikes of those names' '^key\.json$' 'key\.json$'
|
|
95
|
+
ps 'the tfstate backup-copy rule removed' "$T_ADDED" '|\.tfstate\.[^]*\.backup$' ''
|
|
96
|
+
ps 'the tfstate backup-copy rule over-matches' "$T_LOOK" '\.tfstate\.[^]*\.backup$' '\.tfstate\.[^]*'
|
|
97
|
+
T_TERM='denies a name with a line terminator inside the matched span'
|
|
98
|
+
ps 'the service-account rule stops at a line terminator' "$T_TERM" 'service[-_]?account[^]*\.json$' 'service[-_]?account.*\.json$'
|
|
99
|
+
ps 'the client_secret rule stops at a line terminator' "$T_TERM" 'client_secret[^]*\.json$' 'client_secret.*\.json$'
|
|
100
|
+
ps 'the tfstate backup-copy rule stops at a line terminator' "$T_TERM" '\.tfstate\.[^]*\.backup$' '\.tfstate\..*\.backup$'
|
|
101
|
+
ps 'a bare config denied' 'a bare config stays allowed on purpose' "'.docker', 'credentials'];" "'.docker', 'credentials', 'config'];"
|
|
102
|
+
ps 'credentials denied only as a file, not as a directory' 'credentials/ is denied as a directory' "return raw.split(SEPARATORS).some((segment) => {
|
|
103
|
+
const folded = foldName(segment);
|
|
104
|
+
return [...new Set([folded, ...folded.split(SEPARATORS)])].some((piece) => {
|
|
105
|
+
const name = trimDots(piece);
|
|
106
|
+
return NAME_EXACT.includes(name) ||" "return raw.split(SEPARATORS).some((segment, _, all) => {
|
|
107
|
+
const folded = foldName(segment);
|
|
108
|
+
return [...new Set([folded, ...folded.split(SEPARATORS)])].some((piece) => {
|
|
109
|
+
const name = trimDots(piece);
|
|
110
|
+
return (NAME_EXACT.includes(name) && (name !== 'credentials' || segment === all.at(-1))) ||"
|
|
111
|
+
ps 'the secrets rule not matched' "$T_HOOK" '|secrets?\.(?:ya?ml|json)$' ''
|
|
112
|
+
ps 'the secrets rule loses its extension' 'does not deny look-alikes of those names' 'secrets?\.(?:ya?ml|json)$' 'secrets?\.'
|
|
113
|
+
ps 'the credentials name not matched' "$T_HOOK" ", 'credentials'];" '];'
|
|
114
|
+
ps 'the .tfstate suffix not matched' "$T_HOOK" "'.tfstate', " ''
|
|
115
|
+
ps 'the _netrc name not matched' "$T_HOOK" "'_netrc', " ''
|
|
116
|
+
ps 'the _pgpass name not matched' "$T_HOOK" "'_pgpass', " ''
|
|
117
|
+
ps 'the .htpasswd name not matched' "$T_HOOK" "'.htpasswd', " ''
|
|
118
|
+
ps 'the .p8 suffix not matched' "$T_HOOK" "'.p8', " ''
|
|
119
|
+
ps 'the .vault-token name not matched' "$T_HOOK" ", '.vault-token'" ''
|
|
120
|
+
ps 'the .kube segment not matched' "$T_HOOK" "'.kube', " ''
|
|
121
|
+
ps 'the .docker segment not matched' "$T_HOOK" "'.docker', " ''
|
|
122
|
+
ps 'the hook parity: -key.json dropped from the deny list' "$T_REP" "'-key.json', " ''
|
|
123
|
+
ps 'the hook parity: .kdbx dropped from the deny list (a representative no longer denied)' "$T_REP" "'.kdbx', " ''
|
|
124
|
+
# The hook's own source, copied with one edit and read by the test through SECRET_HOOK_SOURCE.
|
|
125
|
+
HOOK="$ROOT/hooks/pre-tool/block-secret-writes.mjs"
|
|
126
|
+
hk() {
|
|
127
|
+
local label="$1" named="$2" mut="$TMP/hook-mutant.mjs" out
|
|
128
|
+
node -e "const fs=require('fs');const s=fs.readFileSync(process.argv[1],'utf8');const t=s.replace(process.argv[2],()=>process.argv[3]);if(t===s)process.exit(3);fs.writeFileSync(process.argv[4],t)" "$HOOK" "$3" "$4" "$mut"
|
|
129
|
+
if [ $? != 0 ]; then bad "hook mutation '$label' did not change the hook (stale pattern)"; return; fi
|
|
130
|
+
out="$(SECRET_HOOK_SOURCE="$mut" node "$PST" "$PS" 2>&1)"
|
|
131
|
+
if grep -qF -- " FAIL $named" <<<"$out"; then ok "hook mutation '$label' turns '$named' red"; else bad "hook mutation '$label' did not turn '$named' red"; fi
|
|
132
|
+
}
|
|
133
|
+
hk 'a hook pattern gains a flag' "$T_LIST" ' /\.pem$/,' ' /\.pem$/i,'
|
|
134
|
+
hk 'a hook pattern gains a flag the test must build with' "$T_MATCH" ' /\.pem$/,' ' /\.pem$/y,'
|
|
135
|
+
hk 'a hook pattern is added with no representative' "$T_LIST" ' /\.kdbx$/,' ' /\.kdbx$/,
|
|
136
|
+
/\.tfplan$/,'
|
|
137
|
+
hk 'a hook pattern with a character class is added with no representative' "$T_LIST" ' /\.kdbx$/,' ' /\.kdbx$/,
|
|
138
|
+
/[a-z]\.tfplan$/,'
|
|
139
|
+
hk 'a hook entry that is not a plain literal is added' "$T_LIST" ' /\.kdbx$/,' ' /\.kdbx$/,
|
|
140
|
+
new RegExp("x"),'
|
|
141
|
+
hk 'a hook pattern is altered' "$T_LIST" '/-key\.json$/,' '/-key\.jsonl$/,'
|
|
142
|
+
hk 'a hook pattern is removed and its representative goes stale' "$T_LIST" ' /\.pgpass$/,
|
|
143
|
+
' ''
|
|
144
|
+
ps 'the realpath re-check removed' 'a path whose canonical on-disk spelling is a denied name' "if (denyListed(rel)) return { kind: 'denied' };" ''
|
|
145
|
+
ps 'the .git segment not matched' 'denies .env, key and certificate' "NAME_EXACT.includes(name) || " ''
|
|
146
|
+
ps 'the .env prefix not matched' 'denies .env, key and certificate' "'.env', " ''
|
|
147
|
+
ps 'id_rsa not matched' 'denies .env, key and certificate' "'id_rsa', " ''
|
|
148
|
+
ps 'the .pfx suffix not matched' 'denies .env, key and certificate' "'.pfx', " ''
|
|
149
|
+
ps 'the deny list over-matches .gitignore' 'does not deny look-alikes' "NAME_EXACT.includes(name)" "name.startsWith('.git')"
|
|
150
|
+
ps 'the backslash dropped from the absolute check' 'refuses an absolute path' '^(?:[\\/]|[a-z]:)' '^(?:[/]|[a-z]:)'
|
|
151
|
+
ps 'the absolute check removed' 'refuses an absolute path' "if (ABSOLUTE.test(raw)) return 'absolute';" ''
|
|
152
|
+
ps 'the parent-segment check removed' 'refuses a parent segment' "if (segments.some((s) => PARENT_SEGMENT.test(s))) return 'traversal';" ''
|
|
153
|
+
ps 'control characters allowed' 'refuses NUL and control' '[\p{Cc}\p{Cf}' '[\p{Cf}'
|
|
154
|
+
ps 'bidi characters allowed' 'refuses bidi' '[\p{Cc}\p{Cf}' '[\p{Cc}'
|
|
155
|
+
ps 'lone surrogates allowed' 'refuses lone surrogates' '\p{Cs}' ''
|
|
156
|
+
ps 'a non-string name read as text' 'refuses an empty' "if (typeof raw !== 'string') return 'malformed';" ''
|
|
157
|
+
ps 'the length cap off by one' 'refuses a name over the length cap' 'raw.length > MAX_PATH_CHARS' 'raw.length >= MAX_PATH_CHARS'
|
|
158
|
+
ps 'the count cap off by one' 'refuses a list over the count cap' 'paths.length <= MAX_PATHS' 'paths.length < MAX_PATHS'
|
|
159
|
+
ps 'the list refusal drops the denied fact' 'a list over the cap keeps the denied fact' 'paths.some(denyListed)' 'false'
|
|
160
|
+
ps 'a far-over-cap list is scanned' 'a list far over the cap is refused as denied' "if (paths.length > 4 * MAX_PATHS) return refused('path_count', true);" ''
|
|
161
|
+
ps 'the scan bound off by one' 'a list far over the cap is refused as denied' 'paths.length > 4 * MAX_PATHS' 'paths.length >= 4 * MAX_PATHS'
|
|
162
|
+
ps 'a symlink component allowed' 'refuses a symlinked file' "if (stat.isSymbolicLink()) return { result: refused('symlink') };" ''
|
|
163
|
+
ps 'an escape outside the root allowed' 'refuses a path whose canonical form leaves the root' 'rel.startsWith(`..${path.sep}`) ||' ''
|
|
164
|
+
ps 'the root itself allowed' 'refuses a path whose canonical form leaves the root' "rel === '' ||" ''
|
|
165
|
+
ps 'the parent of the root allowed' 'refuses a path whose canonical form leaves the root' "rel === '..' ||" ''
|
|
166
|
+
ps 'a name starting with two dots read as an escape' 'a file whose name begins with two dots' 'rel.startsWith(`..${path.sep}`)' "rel.startsWith('..')"
|
|
167
|
+
if [ "$(uname -s)" = Linux ]; then ps 'a non-ENOENT lstat error read as a missing file' 'a name the filesystem cannot look up' "if (e.code !== 'ENOENT') return { result: refused('unreadable') };" ''
|
|
168
|
+
else echo " skip mutation 'a non-ENOENT lstat error read as a missing file' on the long-name test (not Linux: the name limit counts bytes only there)"; fi
|
|
169
|
+
if [ "$(id -u)" = 0 ]; then echo " skip mutation 'a non-ENOENT lstat error read as a missing file' on the unreadable-directory test (running as root, which reads it)"
|
|
170
|
+
else ps 'a non-ENOENT lstat error read as a missing file (directory case)' 'a file in an unreadable directory' "if (e.code !== 'ENOENT') return { result: refused('unreadable') };" ''; fi
|
|
171
|
+
ps 'the walk splits on slashes only' 'refuses a parent segment' 'raw.split(SEPARATORS).filter' "raw.split('/').filter"
|
|
172
|
+
ps 'a final non-file is opened' 'a path that does not exist, a directory or a FIFO opens nothing' "if (i === segments.length - 1 && !stat.isFile()) return { result: refused('not_file') };" ''
|
|
173
|
+
ps 'a probe error is rethrown' 'an error from the probe is a refusal' "result = refused('probe');" "throw new Error('PROBEMSG');"
|
|
174
|
+
ps 'a missing parent allowed' 'refuses a directory, a path through a file' "if (i < segments.length - 1) return { result: refused('no_parent') };" ''
|
|
175
|
+
ps 'a file read as a directory' 'refuses a directory, a path through a file' 'i < segments.length - 1 && !stat.isDirectory()' 'false'
|
|
176
|
+
ps 'a directory or device read as a file' 'refuses a directory, a path through a file' "if (!stat.isFile()) throw Object.assign(new Error(), { refusal: 'not_file' });" ''
|
|
177
|
+
ps 'the size cap not applied' 'refuses a file over the size cap' 'stat.size > MAX_FILE_BYTES' 'false'
|
|
178
|
+
ps 'the size cap off by one' 'refuses a file over the size cap' 'stat.size > MAX_FILE_BYTES' 'stat.size >= MAX_FILE_BYTES'
|
|
179
|
+
ps 'the open can block on a FIFO' 'a FIFO is refused and the call returns' ' | constants.O_NONBLOCK' ''
|
|
180
|
+
ps 'the open can take a controlling terminal' 'the open follows no link, cannot block' ' | (constants.O_NOCTTY ?? 0)' ''
|
|
181
|
+
ps 'the open follows a link' 'refuses a link swapped in after the check' ' | constants.O_NOFOLLOW' ''
|
|
182
|
+
ps 'no platform check' 'fails closed with `platform`' "if (!(constants.O_NOFOLLOW > 0 && constants.O_NONBLOCK > 0)) return refused('platform');" ''
|
|
183
|
+
ps 'the platform check ignores O_NONBLOCK' 'fails closed with `platform`' ' && constants.O_NONBLOCK > 0' ''
|
|
184
|
+
ps 'the descriptor is leaked after a probe' 'the descriptor is closed after a probe' 'fs.closeSync(opened.fd);' ''
|
|
185
|
+
ps 'a failed close of the descriptor is rethrown' 'a probe that closes the descriptor is a refusal' "try {
|
|
186
|
+
fs.closeSync(opened.fd);
|
|
187
|
+
} catch {
|
|
188
|
+
return refused(probe ? 'probe' : 'unreadable'); // with a probe, the likely cause is the probe closing the descriptor
|
|
189
|
+
}" 'fs.closeSync(opened.fd);'
|
|
190
|
+
T_CLOSE='a close that fails is unreadable with no probe'
|
|
191
|
+
ps 'a failed close with no probe labelled probe' "$T_CLOSE" "refused(probe ? 'probe' : 'unreadable')" "refused('probe')"
|
|
192
|
+
ps 'a failed close with a probe labelled unreadable' "$T_CLOSE" "refused(probe ? 'probe' : 'unreadable')" "refused('unreadable')"
|
|
193
|
+
ps 'the descriptor is leaked on a refusal' 'the descriptor is closed after a probe' 'fs.closeSync(fd);' ''
|
|
194
|
+
ps 'the probe answer is passed through' 'the probe gets an open descriptor and the size and its answer is a boolean' 'probe(opened.fd, opened.size) === true' 'probe(opened.fd, opened.size)'
|
|
195
|
+
ps 'an unreadable root is read through' 'an unreadable root is refused' "} catch {
|
|
196
|
+
return refused('unreadable');
|
|
197
|
+
}
|
|
198
|
+
if (found.result)" "} catch {
|
|
199
|
+
return { kind: 'contained', exists: false, rel: '' };
|
|
200
|
+
}
|
|
201
|
+
if (found.result)"
|
|
202
|
+
|
|
203
|
+
# ---- scripts/lib/path-facts.mjs ----
|
|
204
|
+
echo "== fact sheet: path facts =="
|
|
205
|
+
PF="$ROOT/scripts/lib/path-facts.mjs"; PFT="$ROOT/tests/scripts/lib/path-facts-tests.mjs"
|
|
206
|
+
ln -s "$PS" "$TMP/path-safety.mjs" # a scratch copy of the module imports its sibling
|
|
207
|
+
run_suite "$PFT" "$PF"
|
|
208
|
+
# The timed cost check costs about a second a run, so only the mutants that name it run it.
|
|
209
|
+
# SKIP_TIMED is honoured only as the value mutant-run (see the stray-seam check at the end).
|
|
210
|
+
pf() { local skip_timed=mutant-run; case "$2" in *nested-quantifier*|*adjacent*) skip_timed= ;; esac; SKIP_TIMED=$skip_timed mutate "$PFT" "$PF" "$@"; }
|
|
211
|
+
T_FLAG='an unconfigured repo flags .env, a migrations directory, a lockfile and a route file'
|
|
212
|
+
T_ADD='config globs are added to the built-ins, not instead of them'
|
|
213
|
+
T_CONT='still two with an empty container list'
|
|
214
|
+
T_HOSTILE='a hostile section reads as the defaults'
|
|
215
|
+
T_DIR='a directory glob with a slash is anchored'
|
|
216
|
+
T_LIT='a config glob is literal text except star'
|
|
217
|
+
T_UNUSABLE='an unusable entry floors instead of vanishing'
|
|
218
|
+
T_KEY='module key under a built-in container'
|
|
219
|
+
T_DENY='a denied name reports a deny_list hit'
|
|
220
|
+
pf 'a default glob dropped: migrations' "$T_FLAG" "migrations: ['migrations', 'migration*', 'migrate']," 'migrations: [],'
|
|
221
|
+
pf 'a default glob dropped: routes' "$T_FLAG" "routes: ['routes', " "routes: ["
|
|
222
|
+
pf 'a default glob dropped: the lockfile name' "$T_FLAG" "'package-lock.json', " ''
|
|
223
|
+
pf 'config replaces the sensitive globs' "$T_ADD" "const sensitive = [...SENSITIVE, ['config', extra.sensitive]];" "const sensitive = extra.sensitive.length ? [['config', extra.sensitive]] : SENSITIVE;"
|
|
224
|
+
pf 'config replaces the built-in containers' "$T_CONT" 'new Set([...BUILTIN_CONTAINERS, ...extra.containers])' 'new Set(extra.containers.length ? extra.containers : BUILTIN_CONTAINERS)'
|
|
225
|
+
T_CSPLIT='a configured container splits its children'
|
|
226
|
+
pf 'config containers are ignored' "$T_CSPLIT" 'out.containers.push(...names.map(containerName))' 'names.map(containerName)'
|
|
227
|
+
pf 'a container name is not reduced to one segment' "$T_CSPLIT" 'const s = globParts(g);' 'const s = [fold(g)];'
|
|
228
|
+
pf 'a container with a slash or wildcard accepted' "$T_HOSTILE" 's.length === 1 && !/[*?]/.test(s[0])' 's.length > 0'
|
|
229
|
+
pf 'a test file counted as production' 'a test file is not a production file' 'production: !isTest(segs)' 'production: true'
|
|
230
|
+
pf 'a test directory not recognised' 'a test file is not a production file' 'TEST_DIRS.has(s)' 'false'
|
|
231
|
+
pf 'a test file name not recognised' 'a test file is not a production file' " || TEST_FILES.some((g) => segMatch(g, segs.at(-1) ?? ''))" ''
|
|
232
|
+
pf 'the deny floor left out of the aggregates' "$T_DENY" 'const floor = denied ? [DENY_LIST] : [];' 'const floor = [];'
|
|
233
|
+
pf 'a hostile entry not floored' "$T_UNUSABLE" 'const denied = !usable || denyListed(raw);' 'const denied = usable && denyListed(raw);'
|
|
234
|
+
pf 'a list over the count cap classified' "$T_UNUSABLE" 'Array.isArray(paths) && paths.length <= MAX_PATHS && ' 'Array.isArray(paths) && '
|
|
235
|
+
pf 'a long path echoed' "$T_UNUSABLE" "path: usable ? raw : ''," 'path: raw,'
|
|
236
|
+
pf 'the module key loses its container' 'one name under two containers' '`${segs[0]}/${segs[1]}`' 'segs[1]'
|
|
237
|
+
pf 'the module count counts files' 'one name under two containers' 'modules: new Set(files.map((f) => f.module)).size' 'modules: files.length'
|
|
238
|
+
pf 'a root file keyed by its name' 'module key: first segment' "if (segs.length < 2) return '';" ''
|
|
239
|
+
pf 'a file in a container keyed by its name' "$T_KEY" 'containers.has(head) && segs.length > 2' 'containers.has(head)'
|
|
240
|
+
pf 'case folding removed' 'matching is case-folded' "denyListed, foldName as fold, trimDots as trim } from './path-safety.mjs';" "denyListed, trimDots as trim } from './path-safety.mjs'; const fold = (s) => s;"
|
|
241
|
+
pf 'the module key is folded' 'the module key keeps the case' '`${segs[0]}/${segs[1]}` : segs[0]' '`${segs[0]}/${segs[1]}`.toLowerCase() : segs[0].toLowerCase()'
|
|
242
|
+
pf 'the container match is not folded' 'the module key keeps the case' 'const head = trim(fold(segs[0]));' 'const head = trim(segs[0]);'
|
|
243
|
+
T_TRIM='the trim is an extra reading'
|
|
244
|
+
pf 'the trimmed readings dropped' 'a trailing dot or space on a segment' '[p, trimmed(p), r, trimmed(r)]' '[p, r]'
|
|
245
|
+
pf 'the untrimmed readings dropped' "$T_TRIM" '[p, trimmed(p), r, trimmed(r)]' '[trimmed(p), trimmed(r)]'
|
|
246
|
+
T_FOLDSEP='a code point that folds to a separator'
|
|
247
|
+
pf 'the re-split readings dropped' "$T_FOLDSEP: the primary" '[p, trimmed(p), r, trimmed(r)]' '[p, trimmed(p)]'
|
|
248
|
+
pf 'the primary reading is the re-split one' "$T_FOLDSEP stays inside" 'const split = (s) => parts(s).map(fold);' 'const split = (s) => parts(fold(s));'
|
|
249
|
+
pf 'the test judgement reads the trimmed segments' 'a name that trims to a test directory' 'production: !isTest(segs)' 'production: !isTest(trimmed(segs))'
|
|
250
|
+
T_GTRIM='a glob or a container written with a trailing dot or space'
|
|
251
|
+
pf 'a container lookup reads the first segment as written' "$T_GTRIM" 'const head = trim(fold(segs[0]));' 'const head = fold(segs[0]);'
|
|
252
|
+
pf 'a container name keeps its trailing dot' "$T_GTRIM" 'const s = globParts(g); return s.length === 1' 'const s = split(g); return s.length === 1'
|
|
253
|
+
pf 'a glob keeps its trailing dot' "$T_GTRIM" "? globParts(glob) : ['**', ...globParts(glob)]" "? split(glob) : ['**', ...split(glob)]"
|
|
254
|
+
pf 'a glob that trims to nothing accepted' "$T_HOSTILE" ' && globParts(g).length > 0' ''
|
|
255
|
+
pf 'a glob whose trim leaves only wildcards accepted' "$T_HOSTILE" ' && !widened(g)' ''
|
|
256
|
+
pf 'a glob that trims to nothing is judged untrimmed' "$T_HOSTILE" 'globParts(g).length > 0' 'split(g).length > 0'
|
|
257
|
+
pf 'the unusable-entry module key can collide with a real segment' 'an unusable entry has a module key no real path can have' '`/?${i}`' '`?${i}`'
|
|
258
|
+
pf 'a glob with a slash not anchored' "$T_DIR" "/[\\\\/]/.test(glob) ? globParts(glob) : ['**', ...globParts(glob)]" "['**', ...globParts(glob)]"
|
|
259
|
+
pf 'a ** segment read as one segment' "$T_DIR" "part === '**'" 'part === "\0"'
|
|
260
|
+
pf 'a ** step restarts from every position' 'nested-quantifier shapes' 'for (let k = Math.min(...at); k <= segs.length; k++) next.add(k);' 'for (const pos of at) for (let k = pos; k <= segs.length; k++) next.add(k);'
|
|
261
|
+
pf 'a test directory named fixtures' 'a test file is not a production file' "'e2e', '__mocks__'" "'e2e', 'fixtures', '__mocks__'"
|
|
262
|
+
pf 'layers read as the last one only' 'a later layer, valid, empty' 'Array.isArray(l) ? l : [l]' 'Array.isArray(l) ? l.slice(-1) : [l]'
|
|
263
|
+
pf 'one invalid key drops the whole layer' 'one invalid key drops only itself' 'if (bounded(globs, validGlob)) out' 'if (bounded(globs, validGlob) && bounded(names, validGlob)) out'
|
|
264
|
+
pf 'an unusable list reported as one entry' 'an unusable list reports the counts' 'Array(MAX_PATHS).fill(null)' '[null]'
|
|
265
|
+
pf 'a glob no longer matches what is under its directory' "$T_DIR" 'return at.size > 0;' 'return at.has(segs.length);'
|
|
266
|
+
pf 'a star cannot backtrack' "$T_LIT" 'else if (star >= 0) { i = star + 1; j = ++mark; }' ''
|
|
267
|
+
pf 'the matcher builds a regex from config text' "$T_LIT" 'function segMatch(p, s) {' 'function segMatch(p, s) { return new RegExp(`^${p.replace(/\*/g, ".*").replace(/\?/g, ".")}$`).test(s); }
|
|
268
|
+
function segMatchUnused(p, s) {'
|
|
269
|
+
pf 'the glob length cap removed' 'a glob whose fold exceeds the glob cap' ' && g.length <= MAX_GLOB_CHARS' ''
|
|
270
|
+
pf 'the glob count cap off by one' "$T_HOSTILE" 'v.length <= MAX_GLOBS' 'v.length <= MAX_GLOBS + 1'
|
|
271
|
+
pf 'a glob with .. accepted' "$T_HOSTILE" " && !g.includes('..')" ''
|
|
272
|
+
pf 'an absolute glob accepted' "$T_HOSTILE" ' && !/^(?:[\\/]|[a-z]:)/i.test(g)' ''
|
|
273
|
+
pf 'a glob with control characters accepted' "$T_HOSTILE" '!/[\p{C}\p{Zl}\p{Zp}]/u.test(g) && ' ''
|
|
274
|
+
pf 'a non-array section accepted' "$T_HOSTILE" 'Array.isArray(v) && ' ''
|
|
275
|
+
# the ci class, the layer cap and the folded caps
|
|
276
|
+
T_CI='every CI system is a ci hit'
|
|
277
|
+
pf 'the ci list emptied' "$T_CI" "ci: ['.github'," "cx: ['.github',"
|
|
278
|
+
pf 'a CI system dropped from the ci list' "$T_CI" "'.circleci', " ''
|
|
279
|
+
pf 'config removes the ci class' 'a config cannot remove the ci class' "const sensitive = [...SENSITIVE, ['config', extra.sensitive]];" "const sensitive = [...SENSITIVE.filter(([n]) => n !== 'ci' || extra.sensitive.length === 0), ['config', extra.sensitive]];"
|
|
280
|
+
pf 'the loadConfig result read as one layer' "loadConfig's {global, project} result is the layers" '[l.global.config, l.project.config]' '[l.config]'
|
|
281
|
+
pf 'the loadConfig result read as the global layer only' "loadConfig's {global, project} result is the layers" '[l.global.config, l.project.config]' '[l.global.config]'
|
|
282
|
+
pf 'the path cap counts the raw text only' 'a path whose fold exceeds the path cap' ' && fold(raw).length <= MAX_PATH_CHARS' ''
|
|
283
|
+
pf 'the glob cap counts the raw text only' 'a glob whose fold exceeds the glob cap' ' && fold(g).length <= MAX_GLOB_CHARS' ''
|
|
284
|
+
pf 'the layer cap removed' 'more layers than loadConfig supplies' ' && layerList.length <= MAX_LAYERS' ''
|
|
285
|
+
pf 'a refused key is not reported' 'a refused key is named in refused' "; else out.refused.push('sensitive_paths');" ';'
|
|
286
|
+
pf 'a wildcard then a dot segment still widens nothing' "$T_HOSTILE" "(t === '' && wild(r[i - 1] ?? ''))" 'false'
|
|
287
|
+
pf 'adjacent ** segments not collapsed' 'adjacent ** segments in a glob are one step' 'const compile = (glob) => collapse(' 'const compile = (glob) => ((x) => x)('
|
|
288
|
+
|
|
289
|
+
# A stray exported seam must change nothing: the timed cost check and the real-hook parity check still run.
|
|
290
|
+
# Stated residual: this runs the real module with a stray value, not a stale copy that is named like a sentinel; the guard under test is the exact comparison.
|
|
291
|
+
stray="$(env SKIP_TIMED=1 SECRET_HOOK_SOURCE=/dev/null node "$PFT" "$PF" 2>&1; env SKIP_TIMED=1 SECRET_HOOK_SOURCE=/dev/null node "$PST" "$PS" 2>&1)"
|
|
292
|
+
if grep -qF ' ok nested-quantifier shapes' <<<"$stray" && grep -qF ' ok the hook secret-name patterns and the representative table' <<<"$stray" && ! grep -qF ' skip nested-quantifier' <<<"$stray" && ! grep -qF ' skip adjacent' <<<"$stray"; then ok 'a stray exported SKIP_TIMED and SECRET_HOOK_SOURCE skip and repoint nothing'; else bad 'a stray exported SKIP_TIMED or SECRET_HOOK_SOURCE changed a check'; fi
|
|
293
|
+
|
|
294
|
+
total=$((pass + fail))
|
|
295
|
+
echo "SUMMARY $total checks, $fail failed"
|
|
296
|
+
[ "$fail" = 0 ]
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Guard for the global config and the merge (scripts/lib/config-files.mjs) and for reads through links:
|
|
3
|
+
# the loader on its own, then every consumer that must see the merged config -- the resolver, the
|
|
4
|
+
# somi-config CLI, the SessionStart default-config hook, the cost-lowering hook and the hooks' config().
|
|
5
|
+
# Every case sets SOMI_GLOBAL_CONFIG itself, so a real global config on the machine never leaks in.
|
|
6
|
+
set -uo pipefail
|
|
7
|
+
|
|
8
|
+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
9
|
+
LIB="$ROOT/scripts/lib/config-files.mjs"
|
|
10
|
+
CLI="$ROOT/scripts/somi-config.mjs"
|
|
11
|
+
DISPATCH="$ROOT/scripts/somi-dispatch.mjs"
|
|
12
|
+
ENSURE="$ROOT/hooks/session-start/ensure-default-config.mjs"
|
|
13
|
+
GUARD="$ROOT/hooks/pre-tool/guard-cost-lowering.mjs"
|
|
14
|
+
|
|
15
|
+
pass=0; fail=0
|
|
16
|
+
ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
|
|
17
|
+
bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
|
|
18
|
+
check() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi; }
|
|
19
|
+
|
|
20
|
+
TMP="$(mktemp -d)"
|
|
21
|
+
trap 'rm -rf "$TMP"' EXIT
|
|
22
|
+
proj() { mktemp -d -p "$TMP"; }
|
|
23
|
+
node_lib() { SOMI_GLOBAL_CONFIG="${G:-}" node --input-type=module -e "import * as L from '$LIB'; $1"; }
|
|
24
|
+
|
|
25
|
+
echo "== global config: the loader =="
|
|
26
|
+
|
|
27
|
+
check "SOMI_GLOBAL_CONFIG names the file" "$(SOMI_GLOBAL_CONFIG=/x/y.json node --input-type=module -e "import {globalConfigPath} from '$LIB'; process.stdout.write(String(globalConfigPath()))")" "/x/y.json"
|
|
28
|
+
check "an empty SOMI_GLOBAL_CONFIG means no global config" "$(SOMI_GLOBAL_CONFIG= node --input-type=module -e "import {globalConfigPath} from '$LIB'; process.stdout.write(String(globalConfigPath()))")" "null"
|
|
29
|
+
check "platform defaults: XDG, ~/.config, %APPDATA%" "$(node --input-type=module -e "
|
|
30
|
+
import {globalConfigPath as g} from '$LIB';
|
|
31
|
+
process.stdout.write([g({XDG_CONFIG_HOME:'/xdg'},'linux','/h'), g({XDG_CONFIG_HOME:'rel'},'linux','/h'), g({},'darwin','/h'), g({APPDATA:'C:/A'},'win32','C:/h')].join('|'))")" \
|
|
32
|
+
"/xdg/somi/config.json|/h/.config/somi/config.json|/h/.config/somi/config.json|C:/A/somi/config.json"
|
|
33
|
+
|
|
34
|
+
check "merge: the user's example (project changes only somi-coder and the medium mapping)" "$(node_lib "
|
|
35
|
+
const g = {cost:{ceiling:'medium',agents:{'somi-coder':'medium','somi-reviewer':'high'},mapping:{'copilot-cli':{low:['a'],medium:['b','c'],high:['d']}}},dep_install:{allow:['x']}};
|
|
36
|
+
const p = {cost:{agents:{'somi-coder':'high'},mapping:{'copilot-cli':{medium:['z']}}}};
|
|
37
|
+
const m = L.mergeConfig(g, p);
|
|
38
|
+
process.stdout.write(JSON.stringify(m) + '|' + g.cost.agents['somi-coder'] + '|' + JSON.stringify(p))")" \
|
|
39
|
+
'{"cost":{"ceiling":"medium","agents":{"somi-coder":"high","somi-reviewer":"high"},"mapping":{"copilot-cli":{"low":["a"],"medium":["z"],"high":["d"]}}},"dep_install":{"allow":["x"]}}|medium|{"cost":{"agents":{"somi-coder":"high"},"mapping":{"copilot-cli":{"medium":["z"]}}}}'
|
|
40
|
+
check "merge: arrays, scalars and null replace; objects merge" "$(node_lib "
|
|
41
|
+
process.stdout.write(JSON.stringify(L.mergeConfig({a:[1,2],b:{c:1,d:2},e:'x',f:{g:1}}, {a:[3],b:{d:3},e:null,f:5})))")" \
|
|
42
|
+
'{"a":[3],"b":{"c":1,"d":3},"e":null,"f":5}'
|
|
43
|
+
check "merge: a __proto__ key stays data and pollutes nothing" "$(node_lib "
|
|
44
|
+
const m = L.mergeConfig({}, JSON.parse('{\"__proto__\":{\"polluted\":1},\"cost\":{\"__proto__\":{\"x\":1}}}'));
|
|
45
|
+
process.stdout.write([String(({}).polluted), Object.getPrototypeOf(m) === Object.prototype, Object.hasOwn(m, '__proto__'), Object.getPrototypeOf(m.cost) === Object.prototype].join(','))")" \
|
|
46
|
+
"undefined,true,true,true"
|
|
47
|
+
|
|
48
|
+
P="$(proj)"; mkdir "$P/.somi"
|
|
49
|
+
check "absent files read as unconfigured" "$(G="$TMP/none.json" node_lib "const r = L.loadConfig('$P'); process.stdout.write(JSON.stringify([r.config, r.global.present, r.project.present]))")" '[{},false,false]'
|
|
50
|
+
printf '{"cost":{"ceiling":"high"}}' > "$TMP/g1.json"; printf '{"cost":{"agents":{"somi-coder":"low"}}}' > "$P/.somi/config.json"
|
|
51
|
+
check "global and project merge, each file reported" "$(G="$TMP/g1.json" node_lib "const r = L.loadConfig('$P'); process.stdout.write(JSON.stringify([r.config, r.global.present, r.project.present]))")" \
|
|
52
|
+
'[{"cost":{"ceiling":"high","agents":{"somi-coder":"low"}}},true,true]'
|
|
53
|
+
P="$(proj)"; SHARED="$(mktemp -d -p "$TMP")"; printf '{"cost":{"ceiling":"low"}}' > "$SHARED/config.json"; ln -s "$SHARED" "$P/.somi"
|
|
54
|
+
check "a symlinked .somi (a junction on Windows) is read through" "$(G= node_lib "process.stdout.write(L.loadConfig('$P').config.cost.ceiling)")" "low"
|
|
55
|
+
ln -s "$SHARED/config.json" "$TMP/linked.json"
|
|
56
|
+
check "a symlinked global config is read through" "$(G="$TMP/linked.json" node_lib "process.stdout.write(L.loadConfig('$(proj)').config.cost.ceiling)")" "low"
|
|
57
|
+
ln -s "$TMP/gone.json" "$TMP/dangling.json"
|
|
58
|
+
check "a dangling link is an error, not 'no config'" "$(G="$TMP/dangling.json" node_lib "try { L.loadConfig('$(proj)'); console.log('read'); } catch (e) { console.log(e instanceof L.ConfigFileError && /link to a missing file/.test(e.message) ? 'refused' : e.message); }")" "refused"
|
|
59
|
+
mkdir "$TMP/dir.json"
|
|
60
|
+
check "a directory is not a config" "$(G="$TMP/dir.json" node_lib "try { L.loadConfig('$(proj)'); console.log('read'); } catch (e) { console.log(/not a regular file/.test(e.message) ? 'refused' : e.message); }")" "refused"
|
|
61
|
+
mkfifo "$TMP/fifo.json"; rc=0
|
|
62
|
+
out="$(G="$TMP/fifo.json" timeout 5 node --input-type=module -e "import * as L from '$LIB'; process.env.SOMI_GLOBAL_CONFIG='$TMP/fifo.json'; try { L.loadConfig('$(proj)'); console.log('read'); } catch (e) { console.log(/not a regular file/.test(e.message) ? 'refused' : e.message); }")" || rc=$?
|
|
63
|
+
check "a FIFO is refused without blocking" "$rc|$out" "0|refused"
|
|
64
|
+
{ printf '{"pad":"'; head -c 70000 /dev/zero | tr '\0' x; printf '"}'; } > "$TMP/big.json"
|
|
65
|
+
check "an oversize global config is refused" "$(G="$TMP/big.json" node_lib "try { L.loadConfig('$(proj)'); console.log('read'); } catch (e) { console.log(/byte limit/.test(e.message) ? 'refused' : e.message); }")" "refused"
|
|
66
|
+
printf '\x1b[31mSECRET {nope' > "$TMP/bad.json"
|
|
67
|
+
msg="$(G="$TMP/bad.json" node_lib "try { L.loadConfig('$(proj)'); } catch (e) { console.log(e.message); }")"
|
|
68
|
+
case "$msg" in *SECRET*|*$'\x1b'*) bad "a parse error leaks file text: $msg" ;; *"not valid JSON"*) ok "a parse error names the file and leaks no text" ;; *) bad "unexpected parse error: $msg" ;; esac
|
|
69
|
+
|
|
70
|
+
node -e "const n=20000; require('fs').writeFileSync('$TMP/deep.json', '{\"deep\":'+'['.repeat(n)+']'.repeat(n)+'}')"
|
|
71
|
+
out="$(SOMI_GLOBAL_CONFIG="$TMP/deep.json" node --stack-size=200 --input-type=module -e "import * as L from '$LIB'; try { L.loadConfig('$(proj)'); console.log('read'); } catch (e) { console.log(e instanceof L.ConfigFileError && /nested deeper/.test(e.message) ? 'refused' : 'crash'); }" 2>&1)"
|
|
72
|
+
check "a config nested 20000 deep is refused cleanly, even on a small stack (CI's Node)" "$out" "refused"
|
|
73
|
+
|
|
74
|
+
echo "== global config: the resolver =="
|
|
75
|
+
resolve() { # $1 = global file, $2 = project, $3.. = resolve args -> stdout JSON
|
|
76
|
+
local g="$1" p="$2"; shift 2
|
|
77
|
+
(cd "$p" && SOMI_GLOBAL_CONFIG="$g" CLAUDE_PROJECT_DIR="$p" env -u SOMI_COST_CEILING node "$DISPATCH" resolve "$@" 2>&1)
|
|
78
|
+
}
|
|
79
|
+
jget() { node -e "const o = JSON.parse(require('fs').readFileSync(0,'utf8')); process.stdout.write(String($1))"; }
|
|
80
|
+
GF="$TMP/global.json"
|
|
81
|
+
printf '%s' '{"cost":{"ceiling":"medium","agents":{"somi-coder":"medium","somi-planner":"high"},"mapping":{"copilot-cli":{"low":["g-low"],"medium":["g-med"],"high":["g-high"]}}}}' > "$GF"
|
|
82
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '%s' '{"cost":{"agents":{"somi-coder":"high"},"mapping":{"copilot-cli":{"medium":["p-med"]}}}}' > "$P/.somi/config.json"
|
|
83
|
+
check "the project overrides somi-coder" "$(resolve "$GF" "$P" --agent somi-coder --host copilot-cli | jget 'o.tier + "," + o.tier_source + "," + o.model')" "high,override,g-high"
|
|
84
|
+
check "an agent the project does not name keeps the global pin" "$(resolve "$GF" "$P" --agent somi-planner --host copilot-cli | jget 'o.tier + "," + o.model')" "high,g-high"
|
|
85
|
+
check "the project's medium mapping replaces the global one; other tiers stay" "$(resolve "$GF" "$P" --agent somi-impact --host copilot-cli | jget 'o.tier + "," + o.model')" "medium,p-med"
|
|
86
|
+
check "the ceiling comes from the global file" "$(resolve "$GF" "$P" --agent somi-impact --host copilot-cli | jget 'o.ceiling + "," + o.ceiling_source')" "medium,config"
|
|
87
|
+
printf '%s' '{"cost":{"celing":"low"}}' > "$TMP/typo.json"; rc=0
|
|
88
|
+
resolve "$TMP/typo.json" "$(proj)" --agent somi-coder > "$TMP/typo.out" || rc=$?
|
|
89
|
+
check "a typo in the global file exits 67 and names that file" "$rc|$(grep -c 'typo.json' "$TMP/typo.out")" "67|1"
|
|
90
|
+
|
|
91
|
+
echo "== global config: somi-config =="
|
|
92
|
+
cfg() { # $1 = global file, $2 = project, $3.. = args -> exit code; stdout in $TMP/out
|
|
93
|
+
local g="$1" p="$2"; shift 2
|
|
94
|
+
SOMI_GLOBAL_CONFIG="$g" env -u SOMI_COST_CEILING node "$CLI" "$@" --project-dir "$p" > "$TMP/out" 2> "$TMP/err"; echo $?
|
|
95
|
+
}
|
|
96
|
+
jf() { node -e "const o = JSON.parse(require('fs').readFileSync('$TMP/out','utf8')); process.stdout.write(typeof ($1) === 'string' ? ($1) : JSON.stringify($1))"; }
|
|
97
|
+
check "show merges both files and says where each value came from" \
|
|
98
|
+
"$(cfg "$GF" "$P" show)|$(jf 'o.global.exists')|$(jf 'o.ceiling.from')|$(jf 'o.agents.find((a) => a.name === "somi-coder").from')|$(jf 'o.agents.find((a) => a.name === "somi-planner").from')" \
|
|
99
|
+
"0|true|global|project|global"
|
|
100
|
+
check "get reads the merged value" "$(cfg "$GF" "$P" get cost.mapping.copilot-cli.medium)|$(jf 'o.value')" '0|["p-med"]'
|
|
101
|
+
|
|
102
|
+
H="$TMP/home"; NG="$H/.config/somi/config.json"
|
|
103
|
+
check "init --global creates the default global file, parents included" "$(cfg "$NG" "$(proj)" init --global)|$(jf 'o.created')|$([ -f "$NG" ] && echo file)" "0|true|file"
|
|
104
|
+
P="$(proj)"
|
|
105
|
+
check "init in a project is a no-op while a global config exists" "$(cfg "$NG" "$P" init)|$(jf 'o.created')|$([ -e "$P/.somi/config.json" ] && echo made || echo none)" "0|false|none"
|
|
106
|
+
check "set --global changes the global file" "$(cfg "$NG" "$P" set cost.agents.somi-coder high --global)|$(node -e "process.stdout.write(JSON.parse(require('fs').readFileSync('$NG','utf8')).cost.agents['somi-coder'])")" "0|high"
|
|
107
|
+
check "a first project set over a global config writes only that key" "$(cfg "$NG" "$P" set cost.agents.somi-pr high)|$(cat "$P/.somi/config.json" | tr -d ' \n')" '0|{"cost":{"agents":{"somi-pr":"high"}}}'
|
|
108
|
+
check "unset of a value only the global file sets changes nothing and says where it lives" "$(cfg "$NG" "$P" unset cost.agents.somi-coder)|$(jf 'o.changed')|$(jf 'String(o.warnings[0].startsWith("that value is set in your global config"))')" "0|false|true"
|
|
109
|
+
check "--global is refused on show" "$(cfg "$NG" "$P" show --global)" "64"
|
|
110
|
+
check "--refuse-lowering judges a project change merged over the global file" "$(cfg "$NG" "$P" set cost.agents.somi-coder low --refuse-lowering)|$(cat "$P/.somi/config.json" | tr -d ' \n')" '64|{"cost":{"agents":{"somi-pr":"high"}}}'
|
|
111
|
+
DOT="$TMP/dotfiles"; mkdir -p "$DOT" "$H/.config/linked"; printf '{"cost":{"ceiling":"medium"}}' > "$DOT/somi.json"; ln -s "$DOT/somi.json" "$H/.config/linked/config.json"
|
|
112
|
+
check "set --global through a dotfiles link writes the real file and keeps the link" \
|
|
113
|
+
"$(cfg "$H/.config/linked/config.json" "$P" set cost.ceiling high --global)|$([ -L "$H/.config/linked/config.json" ] && echo link)|$(node -e "process.stdout.write(JSON.parse(require('fs').readFileSync('$DOT/somi.json','utf8')).cost.ceiling)")" \
|
|
114
|
+
"0|link|high"
|
|
115
|
+
check "with SOMI_GLOBAL_CONFIG empty, --global is a usage error" "$(cfg "" "$P" set cost.ceiling high --global)" "64"
|
|
116
|
+
|
|
117
|
+
echo "== global config: hooks =="
|
|
118
|
+
runhook() { # $1 = hook, $2 = global file, $3 = project; payload on stdin -> stdout
|
|
119
|
+
(cd "$3" && SOMI_GLOBAL_CONFIG="$2" CLAUDE_PROJECT_DIR="$3" node "$1")
|
|
120
|
+
}
|
|
121
|
+
P="$(proj)"
|
|
122
|
+
out="$(printf '{}' | runhook "$ENSURE" "$NG" "$P")"
|
|
123
|
+
check "SessionStart writes no project default while a global config exists" "$([ -e "$P/.somi/config.json" ] && echo made || echo none)" "none"
|
|
124
|
+
printf '{"cost":{"ceiling":"medium","agents":{}}}' > "$TMP/nopin.json"
|
|
125
|
+
out="$(printf '{}' | runhook "$ENSURE" "$TMP/nopin.json" "$(proj)")"
|
|
126
|
+
case "$out" in *"your global config"*"no cost.agents pin for somi-security-reviewer"*) ok "the pin notice reads the merged config and names the global file" ;; *) bad "the pin notice reads the merged config and names the global file ($out)" ;; esac
|
|
127
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"agents":{"somi-security-reviewer":"high"}}}' > "$P/.somi/config.json"
|
|
128
|
+
check "... and a project pin satisfies it" "$(printf '{}' | runhook "$ENSURE" "$TMP/nopin.json" "$P")" ""
|
|
129
|
+
|
|
130
|
+
verdict() { # $1 = global file, $2 = project, $3 = payload -> ask | allow
|
|
131
|
+
local out; out="$(printf '%s' "$3" | runhook "$GUARD" "$1" "$2")"
|
|
132
|
+
case "$out" in *'"permissionDecision":"ask"'*) echo ask ;; *) echo allow ;; esac
|
|
133
|
+
}
|
|
134
|
+
wr() { node -e "process.stdout.write(JSON.stringify({tool_name:'Write',tool_input:{file_path:process.argv[1],content:process.argv[2]}}))" "$1" "$2"; }
|
|
135
|
+
GP="$TMP/gp.json"; printf '{"cost":{"ceiling":"medium","agents":{"somi-security-reviewer":"high","somi-coder":"high"}}}' > "$GP"
|
|
136
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '{}' > "$P/.somi/config.json"
|
|
137
|
+
check "a tool write to the global config always asks" "$(verdict "$GP" "$P" "$(wr "$GP" '{"cost":{"ceiling":"high"}}')")" "ask"
|
|
138
|
+
check "... also when the global file does not exist yet" "$(verdict "$TMP/new/somi/config.json" "$P" "$(wr "$TMP/new/somi/config.json" '{}')")" "ask"
|
|
139
|
+
check "a project write that drops below a global pin asks" "$(verdict "$GP" "$P" "$(wr "$P/.somi/config.json" '{"cost":{"agents":{"somi-coder":"low"}}}')")" "ask"
|
|
140
|
+
check "a project write that raises over the global file passes" "$(verdict "$GP" "$P" "$(wr "$P/.somi/config.json" '{"cost":{"ceiling":"high"}}')")" "allow"
|
|
141
|
+
check "an unrelated write passes" "$(verdict "$GP" "$P" "$(wr "$P/notes.txt" 'hi')")" "allow"
|
|
142
|
+
|
|
143
|
+
printf '{"dep_install":{"allow":["left-pad"]},"lockfiles":{"allow_edit":true}}' > "$TMP/policy.json"
|
|
144
|
+
P="$(proj)"; mkdir "$P/.somi"; printf '{"dep_install":{"allow":["is-odd"]}}' > "$P/.somi/config.json"
|
|
145
|
+
check "the hooks' config() sees the merge (project array replaces, global key stays)" "$(cd "$P" && SOMI_GLOBAL_CONFIG="$TMP/policy.json" CLAUDE_PROJECT_DIR="$P" node --input-type=module -e "
|
|
146
|
+
import { config } from '$ROOT/hooks/lib/common.mjs';
|
|
147
|
+
process.stdout.write(JSON.stringify([config('.dep_install.allow[]?'), config('.lockfiles.allow_edit')]))")" '[["is-odd"],"true"]'
|
|
148
|
+
|
|
149
|
+
echo "== global config: red proofs =="
|
|
150
|
+
# Each mutant removes one rule from a copy of the plugin's scripts/ and hooks/; the case it guards must flip.
|
|
151
|
+
mutant() { # $1 = name, $2 = file below the copy, $3 = sed expression
|
|
152
|
+
local d="$TMP/mut-$1"; mkdir -p "$d"; cp -r "$ROOT/scripts" "$ROOT/hooks" "$d/"
|
|
153
|
+
sed -i "$3" "$d/$2"
|
|
154
|
+
cmp -s "$ROOT/$2" "$d/$2" && bad "mutant $1 did not change $2"
|
|
155
|
+
}
|
|
156
|
+
mutant shallow scripts/lib/config-files.mjs 's/isObj(v) \&\& isObj(prev) ? mergeConfig(prev, v) : copy(v)/copy(v)/'
|
|
157
|
+
check "red proof: a shallow merge loses the global pins the project does not name" "$(node --input-type=module -e "
|
|
158
|
+
import * as L from '$TMP/mut-shallow/scripts/lib/config-files.mjs';
|
|
159
|
+
process.stdout.write(String(L.mergeConfig({cost:{agents:{a:'high',b:'high'}}}, {cost:{agents:{a:'low'}}}).cost.agents.b))")" "undefined"
|
|
160
|
+
mutant no-global-ask hooks/pre-tool/guard-cost-lowering.mjs 's/askPretool(payload, GLOBAL_WRITE)/void 0/'
|
|
161
|
+
check "red proof: without its rule a global write is not asked about" "$(out="$(wr "$GP" '{"cost":{"ceiling":"high"}}' | (cd "$P" && SOMI_GLOBAL_CONFIG="$GP" CLAUDE_PROJECT_DIR="$P" node "$TMP/mut-no-global-ask/hooks/pre-tool/guard-cost-lowering.mjs"))"; case "$out" in *ask*) echo ask ;; *) echo allow ;; esac)" "allow"
|
|
162
|
+
mutant no-global-skip hooks/session-start/ensure-default-config.mjs 's/if (existing || hasGlobal) {/if (existing) {/'
|
|
163
|
+
P="$(proj)"; printf '{}' | runhook "$TMP/mut-no-global-skip/hooks/session-start/ensure-default-config.mjs" "$NG" "$P" > /dev/null
|
|
164
|
+
check "red proof: without the global check SessionStart writes a project default that masks it" "$([ -e "$P/.somi/config.json" ] && echo made || echo none)" "made"
|
|
165
|
+
|
|
166
|
+
echo " $pass passed, $fail failed"
|
|
167
|
+
[ "$fail" -eq 0 ]
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
"1.1"
|
|
133
133
|
],
|
|
134
134
|
"exit": 0,
|
|
135
|
-
"stdout": "{\"slug\":\"g\",\"loop\":\"code\",\"iteration\":\"1.1\",\"baseline_sha\":\"<SHA>\",\"started\":\"<TS>\",\"status\":\"running\",\"caps\":{\"max_passes\":2,\"diff_cap_lines\":10,\"severity_floor\":\"Major\"},\"iteration_files\":[\"src/a.txt\"],\"pass\":2,\"history\":[{\"pass\":2,\"verdict\":\"request-changes\",\"blockers\":0,\"majors\":2,\"diff_lines\":7,\"tree\":\"<SHA>\",\"at\":\"<TS>\"}]}",
|
|
135
|
+
"stdout": "{\"slug\":\"g\",\"loop\":\"code\",\"iteration\":\"1.1\",\"baseline_sha\":\"<SHA>\",\"started\":\"<TS>\",\"status\":\"running\",\"caps\":{\"max_passes\":2,\"diff_cap_lines\":10,\"severity_floor\":\"Major\"},\"iteration_files\":[\"src/a.txt\"],\"pass\":2,\"history\":[{\"pass\":2,\"verdict\":\"request-changes\",\"blockers\":0,\"majors\":2,\"diff_lines\":7,\"tree\":\"<SHA>\",\"at\":\"<TS>\"}],\"ignored_guarded\":{\"over\":false,\"files\":{}}}",
|
|
136
136
|
"stderr": ""
|
|
137
137
|
},
|
|
138
138
|
{
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
"1.1"
|
|
163
163
|
],
|
|
164
164
|
"exit": 0,
|
|
165
|
-
"stdout": "{\n \"slug\": \"g\",\n \"loop\": \"code\",\n \"iteration\": \"1.1\",\n \"baseline_sha\": \"<SHA>\",\n \"started\": \"<TS>\",\n \"status\": \"stopped-diff-cap\",\n \"caps\": {\n \"max_passes\": 2,\n \"diff_cap_lines\": 10,\n \"severity_floor\": \"Major\"\n },\n \"iteration_files\": [\n \"src/a.txt\"\n ],\n \"pass\": 2,\n \"history\": [\n {\n \"pass\": 2,\n \"verdict\": \"request-changes\",\n \"blockers\": 0,\n \"majors\": 2,\n \"diff_lines\": 7,\n \"tree\": \"<SHA>\",\n \"at\": \"<TS>\"\n }\n ],\n \"finished\": \"<TS>\"\n}",
|
|
165
|
+
"stdout": "{\n \"slug\": \"g\",\n \"loop\": \"code\",\n \"iteration\": \"1.1\",\n \"baseline_sha\": \"<SHA>\",\n \"started\": \"<TS>\",\n \"status\": \"stopped-diff-cap\",\n \"caps\": {\n \"max_passes\": 2,\n \"diff_cap_lines\": 10,\n \"severity_floor\": \"Major\"\n },\n \"iteration_files\": [\n \"src/a.txt\"\n ],\n \"pass\": 2,\n \"history\": [\n {\n \"pass\": 2,\n \"verdict\": \"request-changes\",\n \"blockers\": 0,\n \"majors\": 2,\n \"diff_lines\": 7,\n \"tree\": \"<SHA>\",\n \"at\": \"<TS>\"\n }\n ],\n \"ignored_guarded\": {\n \"over\": false,\n \"files\": {}\n },\n \"finished\": \"<TS>\"\n}",
|
|
166
166
|
"stderr": ""
|
|
167
167
|
}
|
|
168
168
|
]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// dispatch-reference-gate.mjs — asserts that every
|
|
2
|
+
// dispatch-reference-gate.mjs — asserts that every workflow procedure (skills/flow-*/SKILL.md) that starts a real agent
|
|
3
3
|
// (a `Task` call naming one of the files under agents/) references skills/somi-dispatch/SKILL.md
|
|
4
4
|
// somewhere in its own text -- every entry path that starts an agent resolves it through the same
|
|
5
5
|
// dispatch procedure, not just the front door. "Starts an agent" is DERIVED from the real
|
|
@@ -64,12 +64,21 @@ export function agentNamesFrom(agentsDir) {
|
|
|
64
64
|
.filter((n) => n !== 'somi');
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
// The procedures that start agents: `flow-<name>/SKILL.md` under a skills/ directory (where every
|
|
68
|
+
// workflow's procedure lives), plus any plain `*.md` directly in the directory (a commands/-shaped
|
|
69
|
+
// tree, which the fixtures use).
|
|
70
|
+
export function procedureFiles(dir) {
|
|
71
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
72
|
+
const flat = entries.filter((e) => e.isFile() && e.name.endsWith('.md')).map((e) => e.name);
|
|
73
|
+
const flows = entries
|
|
74
|
+
.filter((e) => e.isDirectory() && e.name.startsWith('flow-') && fs.existsSync(path.join(dir, e.name, 'SKILL.md')))
|
|
75
|
+
.map((e) => path.join(e.name, 'SKILL.md'));
|
|
76
|
+
return [...flat, ...flows].sort();
|
|
77
|
+
}
|
|
78
|
+
|
|
67
79
|
export function scan(commandsDir, agentsDir) {
|
|
68
80
|
const agentNames = agentNamesFrom(agentsDir);
|
|
69
|
-
const files =
|
|
70
|
-
.readdirSync(commandsDir)
|
|
71
|
-
.filter((f) => f.endsWith('.md'))
|
|
72
|
-
.sort();
|
|
81
|
+
const files = procedureFiles(commandsDir);
|
|
73
82
|
|
|
74
83
|
const checked = [];
|
|
75
84
|
const missing = [];
|