@skathio/somi 1.2.0 → 2.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 +8 -8
- 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 +5 -0
- package/VERSION +1 -1
- package/commands/code-loop.md +12 -12
- package/commands/plan-loop.md +9 -9
- package/commands/pr.md +1 -1
- package/commands/release-readiness.md +3 -3
- package/commands/review-panel.md +1 -1
- package/commands/review.md +3 -3
- package/commands/ship-loop.md +2 -2
- package/commands/somi.md +1 -1
- package/commands/upgrade.md +1 -1
- package/hooks/hooks.json +8 -8
- package/hooks/lib/common.mjs +328 -0
- package/hooks/post-tool/audit-log.mjs +93 -0
- package/hooks/post-tool/lint-changed-files.mjs +212 -0
- package/hooks/pre-tool/block-dangerous-bash.mjs +382 -0
- package/hooks/pre-tool/block-secret-writes.mjs +96 -0
- package/hooks/pre-tool/gate-dep-install.mjs +229 -0
- package/hooks/pre-tool/guard-protected-paths.mjs +157 -0
- package/hooks/session-start/detect-repo-instructions.mjs +264 -0
- package/hooks/user-prompt-submit/inject-workflow-context.mjs +432 -0
- package/package.json +2 -2
- package/scripts/somi-check.mjs +243 -0
- package/scripts/somi-findings.mjs +307 -0
- package/scripts/somi-loop.mjs +354 -0
- package/scripts/validate.sh +21 -16
- package/skills/clean-code/SKILL.md +1 -1
- package/tests/hooks/cases/audit-log.json +21 -0
- package/tests/hooks/cases/block-dangerous-bash.json +90 -2
- package/tests/hooks/cases/block-secret-writes.json +1 -1
- package/tests/hooks/cases/detect-repo-instructions.json +84 -0
- package/tests/hooks/cases/gate-dep-install.json +6 -1
- package/tests/hooks/cases/guard-protected-paths.json +1 -1
- package/tests/hooks/cases/inject-workflow-context.json +126 -0
- package/tests/hooks/cases/lint-changed-files.json +120 -0
- package/tests/hooks/run.sh +280 -15
- package/tests/scripts/goldens/somi-findings.json +336 -0
- package/tests/scripts/goldens/somi-loop.json +168 -0
- package/tests/scripts/run.sh +251 -30
- package/hooks/lib/common.sh +0 -133
- package/hooks/post-tool/audit-log.sh +0 -40
- package/hooks/post-tool/lint-changed-files.sh +0 -80
- package/hooks/pre-tool/block-dangerous-bash.sh +0 -171
- package/hooks/pre-tool/block-secret-writes.sh +0 -83
- package/hooks/pre-tool/gate-dep-install.sh +0 -113
- package/hooks/pre-tool/guard-protected-paths.sh +0 -89
- package/hooks/session-start/detect-repo-instructions.sh +0 -73
- package/hooks/user-prompt-submit/inject-workflow-context.sh +0 -143
- package/scripts/somi-check.sh +0 -135
- package/scripts/somi-findings.sh +0 -173
- package/scripts/somi-loop.sh +0 -225
package/tests/hooks/run.sh
CHANGED
|
@@ -8,21 +8,102 @@
|
|
|
8
8
|
# "script": "pre-tool/block-dangerous-bash.sh",
|
|
9
9
|
# "cases": [
|
|
10
10
|
# { "name": "rm-rf-root", "expect": "deny",
|
|
11
|
+
# "expect_reason": "rm -rf /",
|
|
11
12
|
# "payload": { "tool_name": "Bash", "tool_input": { "command": "rm -rf /" } } },
|
|
12
13
|
# { "name": "opted-in", "expect": "allow",
|
|
13
14
|
# "env": { "SOMI_ALLOW_DEP_INSTALL": "1" },
|
|
14
15
|
# "payload": { ... } },
|
|
15
16
|
# { "name": "config-allowlisted", "expect": "allow",
|
|
16
17
|
# "config": { "dep_install": { "allow": ["@types/"] } },
|
|
18
|
+
# "payload": { ... } },
|
|
19
|
+
# { "name": "surfaces-context", "expect_context": "somi repo-awareness",
|
|
20
|
+
# "files": { "AGENTS.md": "# repo instructions\n" },
|
|
17
21
|
# "payload": { ... } }
|
|
18
22
|
# ]
|
|
19
23
|
# }
|
|
20
24
|
#
|
|
25
|
+
# Case fields beyond "expect" (PreToolUse allow/deny):
|
|
26
|
+
# - "files": an object mapping a path (relative to the case's throwaway
|
|
27
|
+
# CLAUDE_PROJECT_DIR) to file content, written before the hook runs — for
|
|
28
|
+
# hooks that read repo-local files (e.g. detect-repo-instructions.sh's
|
|
29
|
+
# AGENTS.md/CLAUDE.md scan). Mirrors the "config" → .somi/config.json
|
|
30
|
+
# staging below, generalized to arbitrary relative paths. Keys are
|
|
31
|
+
# rejected (case FAILS loudly) if they contain a ".." path segment or a
|
|
32
|
+
# leading "/" — such a key would otherwise escape the case dir.
|
|
33
|
+
# - "setup_git": true — initializes a real git repo in the case dir (`git
|
|
34
|
+
# init -b main`, a throwaway commit identity, `git add -A` + an
|
|
35
|
+
# `--allow-empty` commit of whatever "files" staged) before the hook
|
|
36
|
+
# runs — for hooks that shell out to `git diff`/`git status` (e.g.
|
|
37
|
+
# inject-workflow-context.sh's loose-end nudges). The commit gives those
|
|
38
|
+
# hooks a real HEAD to diff against even when "files" staged nothing.
|
|
39
|
+
# - "dirty_files": like "files", but written *after* the "setup_git"
|
|
40
|
+
# baseline commit — so a new path lands untracked (visible in `git status
|
|
41
|
+
# --porcelain` as `??`) and an overwritten already-committed path lands
|
|
42
|
+
# modified-unstaged (visible in `git diff HEAD`). Same unsafe-key guard as
|
|
43
|
+
# "files". Meaningless without "setup_git" (no git repo to be dirty in).
|
|
44
|
+
# - "prime": true — runs the hook once beforehand (same sanitized env and
|
|
45
|
+
# payload as the real run below), discarding its output but still failing
|
|
46
|
+
# the case loudly if that priming invocation errors, so a hook whose
|
|
47
|
+
# behavior depends on its own prior invocation (e.g.
|
|
48
|
+
# inject-workflow-context.sh's signature-gated re-emission, which reads a
|
|
49
|
+
# state file the hook itself wrote last time) can be tested against its
|
|
50
|
+
# *second* call rather than its first. Note: this reuses the case's audit
|
|
51
|
+
# log path, so pairing "prime" with an audit-log assertion on a hook that
|
|
52
|
+
# writes audit lines would double-count; harmless for hooks (like
|
|
53
|
+
# inject-workflow-context.sh) that never call somi::audit.
|
|
54
|
+
# - "files_after_prime": like "files", but written after the priming
|
|
55
|
+
# invocation and before the real one — for perturbing whatever state the
|
|
56
|
+
# prior invocation just persisted (e.g. adding a new
|
|
57
|
+
# .somi/reviews/*/*.md so a signature computed from directory-listing
|
|
58
|
+
# mtimes changes deterministically, with no sleep/timing dependency,
|
|
59
|
+
# rather than relying on touching an existing file's mtime). Only
|
|
60
|
+
# meaningful alongside "prime".
|
|
61
|
+
# - A payload may reference the literal token "{{CASE_DIR}}", substituted
|
|
62
|
+
# with the case's absolute throwaway-dir path before the hook runs — for
|
|
63
|
+
# hooks that check real absolute paths (e.g. lint-changed-files.sh's
|
|
64
|
+
# `[[ -f "$PATH_INPUT" ]]`), so a case can point at a file staged via
|
|
65
|
+
# "files" without hardcoding a path the hook's own CWD wouldn't resolve.
|
|
66
|
+
# - "expect_context": asserted as a substring of
|
|
67
|
+
# `.hookSpecificOutput.additionalContext` — for PostToolUse/UserPromptSubmit/
|
|
68
|
+
# SessionStart hooks that surface context instead of a permission decision.
|
|
69
|
+
# Independent of "expect"; a case may declare either, both, or (paired with
|
|
70
|
+
# "expect": "deny") "expect_reason" as well. There is deliberately no
|
|
71
|
+
# Stop-event (`decision`-shape) assertion path — no Stop hooks are wired in
|
|
72
|
+
# hooks.json today, so that shape would be untested speculative scope.
|
|
73
|
+
# - "expect_no_context": true — asserts `.hookSpecificOutput.additionalContext`
|
|
74
|
+
# is absent/empty — for PostToolUse hooks whose current behavior is a
|
|
75
|
+
# documented no-op (e.g. lint-changed-files.sh with no configured linter).
|
|
76
|
+
# - "expect_context_excludes": asserted as a substring that must NOT appear
|
|
77
|
+
# in `.hookSpecificOutput.additionalContext` — the negative complement to
|
|
78
|
+
# "expect_context", for a hook that emits *some* context (so
|
|
79
|
+
# "expect_no_context" doesn't apply — a plain substring match on the part
|
|
80
|
+
# that IS present can't rule out something else silently being appended
|
|
81
|
+
# alongside it) but where one specific piece of content must be absent
|
|
82
|
+
# (e.g. inject-workflow-context.sh still prints its standing reminder
|
|
83
|
+
# block on an unrelated branch, but a particular work-item hint inside
|
|
84
|
+
# that block must not appear for this case's staged input).
|
|
85
|
+
# - "expect_reason": asserted as a substring of
|
|
86
|
+
# `.hookSpecificOutput.permissionDecisionReason` on deny cases — catches a
|
|
87
|
+
# hook that still denies (so `expect: deny` alone would pass) but whose
|
|
88
|
+
# matched/interpolated text drifted, e.g. an ERE→RegExp port that shifts
|
|
89
|
+
# *which* substring a pattern captures.
|
|
90
|
+
# - "expect_audit_log": asserted as a substring of the case's audit-log file
|
|
91
|
+
# (see below) — for hooks whose only observable effect is the audit-log
|
|
92
|
+
# side-effect (audit-log.sh emits no stdout decision at all).
|
|
93
|
+
# - "expect_no_audit_log": true — asserts the case's audit-log file was never
|
|
94
|
+
# created (e.g. audit-log.sh's no-tool_name early exit).
|
|
95
|
+
#
|
|
96
|
+
# A case that declares none of the seven recognized assertion fields above
|
|
97
|
+
# runs the hook and passes vacuously (a typo'd field name would silently
|
|
98
|
+
# produce a meaningless green case) — the runner fails such a case loudly
|
|
99
|
+
# instead.
|
|
100
|
+
#
|
|
21
101
|
# The runner pipes each payload into the script under a sanitized environment
|
|
22
|
-
# (session opt-ins unset unless the case sets them;
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
102
|
+
# (session opt-ins unset unless the case sets them; SOMI_AUDIT_LOG defaults to
|
|
103
|
+
# a per-case throwaway file, "$case_dir/audit.log", so audit writes never leak
|
|
104
|
+
# across cases; CLAUDE_PROJECT_DIR points at the same throwaway per-case dir,
|
|
105
|
+
# into which the optional `config` object is written as .somi/config.json)
|
|
106
|
+
# and asserts every expectation the case declares.
|
|
26
107
|
#
|
|
27
108
|
# Wired into scripts/validate.sh (npm test) — CI fails when a pattern change
|
|
28
109
|
# weakens a guarantee. If you change a hook pattern, add or update a fixture.
|
|
@@ -37,40 +118,159 @@ trap 'rm -rf "$TMP"' EXIT
|
|
|
37
118
|
total=0
|
|
38
119
|
failures=0
|
|
39
120
|
|
|
121
|
+
# Reject "files" staging keys that could escape the per-case throwaway dir: a
|
|
122
|
+
# ".." path segment (anywhere in the path, not just a bare prefix) or a
|
|
123
|
+
# leading "/". Fixture keys are maintainer-committed, not attacker-controlled,
|
|
124
|
+
# but a typo should fail the case loudly rather than silently write outside
|
|
125
|
+
# case_dir.
|
|
126
|
+
is_unsafe_staging_key() {
|
|
127
|
+
local key="$1"
|
|
128
|
+
[[ "$key" == /* ]] && return 0
|
|
129
|
+
local part
|
|
130
|
+
local IFS='/'
|
|
131
|
+
for part in $key; do
|
|
132
|
+
[[ "$part" == ".." ]] && return 0
|
|
133
|
+
done
|
|
134
|
+
return 1
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# Writes cases[$idx].$field (an object mapping relative path -> content) into
|
|
138
|
+
# $dir, one file per key, validating every key via is_unsafe_staging_key first
|
|
139
|
+
# (shared by "files", "dirty_files", and "files_after_prime" — same shape,
|
|
140
|
+
# different write timing). Prints a FAIL line and returns 1 on an unsafe key
|
|
141
|
+
# (caller must count a failure and skip the case); returns 0 otherwise,
|
|
142
|
+
# including when the field is absent/empty.
|
|
143
|
+
stage_case_files() {
|
|
144
|
+
local case_file="$1" idx="$2" dir="$3" field="$4" script_rel="$5" name="$6"
|
|
145
|
+
local rel_path
|
|
146
|
+
while IFS= read -r rel_path; do
|
|
147
|
+
[[ -z "$rel_path" ]] && continue
|
|
148
|
+
if is_unsafe_staging_key "$rel_path"; then
|
|
149
|
+
echo "FAIL: [$script_rel] $name — unsafe \"$field\" key escapes the case dir: $rel_path" >&2
|
|
150
|
+
return 1
|
|
151
|
+
fi
|
|
152
|
+
mkdir -p "$dir/$(dirname "$rel_path")"
|
|
153
|
+
jq -r --argjson idx "$idx" --arg key "$rel_path" ".cases[\$idx].$field[\$key]" "$case_file" \
|
|
154
|
+
> "$dir/$rel_path"
|
|
155
|
+
done < <(jq -r ".cases[$idx].$field // {} | keys[]" "$case_file")
|
|
156
|
+
return 0
|
|
157
|
+
}
|
|
158
|
+
|
|
40
159
|
for case_file in "$CASES_DIR"/*.json; do
|
|
41
160
|
script_rel="$(jq -r '.script' "$case_file")"
|
|
42
161
|
script="$ROOT/hooks/$script_rel"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
162
|
+
# Dispatch by extension (node-runtime-port phase 2, iteration 2.1): a
|
|
163
|
+
# ".mjs" hook is invoked via `node "$script"`; a ".sh" hook stays a direct
|
|
164
|
+
# exec, as before. This lets a single hook flip to its .mjs port (by
|
|
165
|
+
# changing the fixture's "script" field) without disturbing any other
|
|
166
|
+
# fixture still pointed at ".sh" — no hook is deleted until Phase 3.
|
|
167
|
+
#
|
|
168
|
+
# The executable-bit precondition is relaxed to the ".sh" branch only: a
|
|
169
|
+
# ".mjs" file invoked via `node "$script"` doesn't need an exec bit, and
|
|
170
|
+
# the exec bit doesn't exist on Windows — the exact host this work item
|
|
171
|
+
# targets. The ".mjs" branch checks readability instead.
|
|
172
|
+
case "$script_rel" in
|
|
173
|
+
*.mjs)
|
|
174
|
+
if [[ ! -r "$script" ]]; then
|
|
175
|
+
echo "FAIL: $(basename "$case_file") — hook script missing or not readable: hooks/$script_rel" >&2
|
|
176
|
+
failures=$((failures + 1))
|
|
177
|
+
continue
|
|
178
|
+
fi
|
|
179
|
+
cmd=(node "$script")
|
|
180
|
+
;;
|
|
181
|
+
*)
|
|
182
|
+
if [[ ! -x "$script" ]]; then
|
|
183
|
+
echo "FAIL: $(basename "$case_file") — hook script missing or not executable: hooks/$script_rel" >&2
|
|
184
|
+
failures=$((failures + 1))
|
|
185
|
+
continue
|
|
186
|
+
fi
|
|
187
|
+
cmd=("$script")
|
|
188
|
+
;;
|
|
189
|
+
esac
|
|
48
190
|
|
|
49
191
|
count="$(jq '.cases | length' "$case_file")"
|
|
50
192
|
for ((i = 0; i < count; i++)); do
|
|
51
193
|
total=$((total + 1))
|
|
52
194
|
name="$(jq -r ".cases[$i].name" "$case_file")"
|
|
53
|
-
expect="$(jq -r ".cases[$i].expect" "$case_file")"
|
|
195
|
+
expect="$(jq -r ".cases[$i].expect // empty" "$case_file")"
|
|
196
|
+
expect_context="$(jq -r ".cases[$i].expect_context // empty" "$case_file")"
|
|
197
|
+
expect_reason="$(jq -r ".cases[$i].expect_reason // empty" "$case_file")"
|
|
198
|
+
expect_no_context="$(jq -r ".cases[$i].expect_no_context // false" "$case_file")"
|
|
199
|
+
expect_context_excludes="$(jq -r ".cases[$i].expect_context_excludes // empty" "$case_file")"
|
|
200
|
+
expect_audit_log="$(jq -r ".cases[$i].expect_audit_log // empty" "$case_file")"
|
|
201
|
+
expect_no_audit_log="$(jq -r ".cases[$i].expect_no_audit_log // false" "$case_file")"
|
|
202
|
+
has_assertion="$(jq -r ".cases[$i] | (has(\"expect\") or has(\"expect_context\") or has(\"expect_reason\") or has(\"expect_no_context\") or has(\"expect_context_excludes\") or has(\"expect_audit_log\") or has(\"expect_no_audit_log\"))" "$case_file")"
|
|
54
203
|
payload="$(jq -c ".cases[$i].payload" "$case_file")"
|
|
55
204
|
|
|
56
205
|
# Sanitized environment: session opt-ins never leak in from the caller;
|
|
57
|
-
# audit-log writes land in a throwaway file, not the repo's
|
|
58
|
-
# project root is a per-case temp dir so .somi/config.json
|
|
206
|
+
# audit-log writes land in a per-case throwaway file, not the repo's
|
|
207
|
+
# .claude/; the project root is a per-case temp dir so .somi/config.json
|
|
208
|
+
# is case-controlled.
|
|
59
209
|
case_dir="$TMP/case-$total"
|
|
60
210
|
mkdir -p "$case_dir"
|
|
211
|
+
# {{CASE_DIR}} in the payload resolves to this case's absolute throwaway
|
|
212
|
+
# dir, for hooks that check real absolute paths (see header comment).
|
|
213
|
+
payload="${payload//\{\{CASE_DIR\}\}/$case_dir}"
|
|
61
214
|
config="$(jq -c ".cases[$i].config // empty" "$case_file")"
|
|
62
215
|
if [[ -n "$config" ]]; then
|
|
63
216
|
mkdir -p "$case_dir/.somi"
|
|
64
217
|
printf '%s' "$config" > "$case_dir/.somi/config.json"
|
|
65
218
|
fi
|
|
66
|
-
|
|
219
|
+
# Arbitrary file staging: a case may declare "files": { "rel/path": "content" }
|
|
220
|
+
# to be written into the case dir before the hook runs (e.g. AGENTS.md for
|
|
221
|
+
# detect-repo-instructions.sh). Generalizes the config staging above.
|
|
222
|
+
# Keys are validated (no ".." segment, no leading "/") before any write.
|
|
223
|
+
if ! stage_case_files "$case_file" "$i" "$case_dir" "files" "$script_rel" "$name"; then
|
|
224
|
+
failures=$((failures + 1))
|
|
225
|
+
continue
|
|
226
|
+
fi
|
|
227
|
+
|
|
228
|
+
# "setup_git": true — real git repo in the case dir, with whatever
|
|
229
|
+
# "files" staged committed as its baseline, so hooks that shell out to
|
|
230
|
+
# `git diff`/`git status` (e.g. inject-workflow-context.sh) have a real
|
|
231
|
+
# HEAD to compare against.
|
|
232
|
+
setup_git="$(jq -r ".cases[$i].setup_git // false" "$case_file")"
|
|
233
|
+
if [[ "$setup_git" == "true" ]]; then
|
|
234
|
+
git -C "$case_dir" init -q -b main
|
|
235
|
+
git -C "$case_dir" config user.email "somi-fixture@test.local"
|
|
236
|
+
git -C "$case_dir" config user.name "somi-fixture"
|
|
237
|
+
git -C "$case_dir" add -A
|
|
238
|
+
git -C "$case_dir" commit -q -m "fixture baseline" --allow-empty
|
|
239
|
+
fi
|
|
240
|
+
|
|
241
|
+
# "dirty_files": written after the baseline commit above, so a new path
|
|
242
|
+
# is untracked and an overwritten committed path is modified-unstaged.
|
|
243
|
+
if ! stage_case_files "$case_file" "$i" "$case_dir" "dirty_files" "$script_rel" "$name"; then
|
|
244
|
+
failures=$((failures + 1))
|
|
245
|
+
continue
|
|
246
|
+
fi
|
|
247
|
+
|
|
248
|
+
env_args=("SOMI_AUDIT_LOG=$case_dir/audit.log" "CLAUDE_PROJECT_DIR=$case_dir")
|
|
67
249
|
while IFS= read -r kv; do
|
|
68
250
|
[[ -z "$kv" ]] && continue
|
|
69
251
|
env_args+=("$kv")
|
|
70
252
|
done < <(jq -r ".cases[$i].env // {} | to_entries[] | \"\(.key)=\(.value)\"" "$case_file")
|
|
71
253
|
|
|
254
|
+
# "prime": true — run the hook once first, discarding output, so a
|
|
255
|
+
# signature/state file the hook itself writes is already in place before
|
|
256
|
+
# the real (assertable) invocation below. "files_after_prime" perturbs
|
|
257
|
+
# that state between the two invocations (see header comment).
|
|
258
|
+
prime="$(jq -r ".cases[$i].prime // false" "$case_file")"
|
|
259
|
+
if [[ "$prime" == "true" ]]; then
|
|
260
|
+
if ! printf '%s' "$payload" \
|
|
261
|
+
| env -u SOMI_ALLOW_DEP_INSTALL -u SOMI_ALLOW_LOCKFILES "${env_args[@]}" "${cmd[@]}" >/dev/null; then
|
|
262
|
+
echo "FAIL: [$script_rel] $name — priming invocation exited non-zero" >&2
|
|
263
|
+
failures=$((failures + 1))
|
|
264
|
+
continue
|
|
265
|
+
fi
|
|
266
|
+
if ! stage_case_files "$case_file" "$i" "$case_dir" "files_after_prime" "$script_rel" "$name"; then
|
|
267
|
+
failures=$((failures + 1))
|
|
268
|
+
continue
|
|
269
|
+
fi
|
|
270
|
+
fi
|
|
271
|
+
|
|
72
272
|
if ! out="$(printf '%s' "$payload" \
|
|
73
|
-
| env -u SOMI_ALLOW_DEP_INSTALL -u SOMI_ALLOW_LOCKFILES "${env_args[@]}" "$
|
|
273
|
+
| env -u SOMI_ALLOW_DEP_INSTALL -u SOMI_ALLOW_LOCKFILES "${env_args[@]}" "${cmd[@]}")"; then
|
|
74
274
|
echo "FAIL: [$script_rel] $name — hook exited non-zero" >&2
|
|
75
275
|
failures=$((failures + 1))
|
|
76
276
|
continue
|
|
@@ -82,11 +282,76 @@ for case_file in "$CASES_DIR"/*.json; do
|
|
|
82
282
|
decision="deny"
|
|
83
283
|
fi
|
|
84
284
|
|
|
85
|
-
if [[ "$decision" != "$expect" ]]; then
|
|
285
|
+
if [[ -n "$expect" ]] && [[ "$decision" != "$expect" ]]; then
|
|
86
286
|
echo "FAIL: [$script_rel] $name — expected $expect, got $decision" >&2
|
|
87
287
|
[[ -n "$out" ]] && echo " output: $out" >&2
|
|
88
288
|
failures=$((failures + 1))
|
|
89
289
|
fi
|
|
290
|
+
|
|
291
|
+
if [[ -n "$expect_reason" ]]; then
|
|
292
|
+
reason=""
|
|
293
|
+
[[ -n "$out" ]] && reason="$(jq -r '.hookSpecificOutput.permissionDecisionReason // empty' <<<"$out")"
|
|
294
|
+
if [[ "$reason" != *"$expect_reason"* ]]; then
|
|
295
|
+
echo "FAIL: [$script_rel] $name — permissionDecisionReason did not contain expected substring" >&2
|
|
296
|
+
echo " expected substring: $expect_reason" >&2
|
|
297
|
+
echo " actual reason: $reason" >&2
|
|
298
|
+
failures=$((failures + 1))
|
|
299
|
+
fi
|
|
300
|
+
fi
|
|
301
|
+
|
|
302
|
+
if [[ -n "$expect_context" ]]; then
|
|
303
|
+
context=""
|
|
304
|
+
[[ -n "$out" ]] && context="$(jq -r '.hookSpecificOutput.additionalContext // empty' <<<"$out")"
|
|
305
|
+
if [[ "$context" != *"$expect_context"* ]]; then
|
|
306
|
+
echo "FAIL: [$script_rel] $name — additionalContext did not contain expected substring" >&2
|
|
307
|
+
echo " expected substring: $expect_context" >&2
|
|
308
|
+
echo " actual context: $context" >&2
|
|
309
|
+
failures=$((failures + 1))
|
|
310
|
+
fi
|
|
311
|
+
fi
|
|
312
|
+
|
|
313
|
+
if [[ "$expect_no_context" == "true" ]]; then
|
|
314
|
+
context=""
|
|
315
|
+
[[ -n "$out" ]] && context="$(jq -r '.hookSpecificOutput.additionalContext // empty' <<<"$out")"
|
|
316
|
+
if [[ -n "$context" ]]; then
|
|
317
|
+
echo "FAIL: [$script_rel] $name — expected no additionalContext, got one" >&2
|
|
318
|
+
echo " actual context: $context" >&2
|
|
319
|
+
failures=$((failures + 1))
|
|
320
|
+
fi
|
|
321
|
+
fi
|
|
322
|
+
|
|
323
|
+
if [[ -n "$expect_context_excludes" ]]; then
|
|
324
|
+
context=""
|
|
325
|
+
[[ -n "$out" ]] && context="$(jq -r '.hookSpecificOutput.additionalContext // empty' <<<"$out")"
|
|
326
|
+
if [[ "$context" == *"$expect_context_excludes"* ]]; then
|
|
327
|
+
echo "FAIL: [$script_rel] $name — additionalContext contained a substring it must not" >&2
|
|
328
|
+
echo " excluded substring: $expect_context_excludes" >&2
|
|
329
|
+
echo " actual context: $context" >&2
|
|
330
|
+
failures=$((failures + 1))
|
|
331
|
+
fi
|
|
332
|
+
fi
|
|
333
|
+
|
|
334
|
+
if [[ -n "$expect_audit_log" ]]; then
|
|
335
|
+
audit_log_content=""
|
|
336
|
+
[[ -f "$case_dir/audit.log" ]] && audit_log_content="$(cat "$case_dir/audit.log")"
|
|
337
|
+
if [[ "$audit_log_content" != *"$expect_audit_log"* ]]; then
|
|
338
|
+
echo "FAIL: [$script_rel] $name — audit log did not contain expected substring" >&2
|
|
339
|
+
echo " expected substring: $expect_audit_log" >&2
|
|
340
|
+
echo " actual audit log: $audit_log_content" >&2
|
|
341
|
+
failures=$((failures + 1))
|
|
342
|
+
fi
|
|
343
|
+
fi
|
|
344
|
+
|
|
345
|
+
if [[ "$expect_no_audit_log" == "true" ]] && [[ -f "$case_dir/audit.log" ]]; then
|
|
346
|
+
echo "FAIL: [$script_rel] $name — expected no audit-log write, but one occurred" >&2
|
|
347
|
+
echo " actual audit log: $(cat "$case_dir/audit.log")" >&2
|
|
348
|
+
failures=$((failures + 1))
|
|
349
|
+
fi
|
|
350
|
+
|
|
351
|
+
if [[ "$has_assertion" != "true" ]]; then
|
|
352
|
+
echo "FAIL: [$script_rel] $name — case declares no recognized assertion field (expect/expect_context/expect_reason/expect_no_context/expect_audit_log/expect_no_audit_log); it would pass vacuously" >&2
|
|
353
|
+
failures=$((failures + 1))
|
|
354
|
+
fi
|
|
90
355
|
done
|
|
91
356
|
done
|
|
92
357
|
|