@windyroad/voice-tone 0.7.1 → 0.7.2

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.
@@ -123,5 +123,5 @@
123
123
  }
124
124
  },
125
125
  "name": "wr-voice-tone",
126
- "version": "0.7.1"
126
+ "version": "0.7.2"
127
127
  }
@@ -407,10 +407,15 @@ fi
407
407
  # Marker absent — deny + delegate.
408
408
  # P166: instruct the orchestrator to structure the agent prompt with a
409
409
  # leading `SURFACE: <name>` line and a `<draft>...</draft>` block so the
410
- # PostToolUse mark hook can derive the canonical marker key locally
410
+ # Claude PostToolUse mark hook can derive the canonical marker key locally
411
411
  # (sha256(DRAFT + '\n' + SURFACE)). Single fire per gate cycle.
412
412
  VERDICT_PREFIX="${EXTERNAL_COMMS_VERDICT_PREFIX:-EXTERNAL_COMMS_${EXTERNAL_COMMS_EVALUATOR_ID^^}}"
413
- REASON=$(printf 'BLOCKED (external-comms gate / %s evaluator): %s draft has not been reviewed by %s. Delegate to %s (subagent_type: '"'"'%s'"'"') with a prompt that starts with the line `SURFACE: %s` and wraps the draft body verbatim inside `<draft>...</draft>` markers (for the changeset-author surface the body is the changeset summary WITHOUT the leading `---` frontmatter block — the gate strips frontmatter before hashing the marker key). The PostToolUse hook derives the marker key from that structure and marks the draft reviewed when the subagent emits %s_VERDICT: PASS — single fire suffices. Dispatch the reviewer SYNCHRONOUSLY (run_in_background: false): a background-launched reviewer does not fire its PostToolUse mark hook, so the marker never persists and this gate re-blocks (P402). Use %s for an interactive walkthrough. There is no env override (P377/RFC-029 — BYPASS_RISK_GATE removed).' \
414
- "$EXTERNAL_COMMS_EVALUATOR_ID" "$SURFACE" "$EXTERNAL_COMMS_SUBAGENT_TYPE" "$EXTERNAL_COMMS_SUBAGENT_TYPE" "$EXTERNAL_COMMS_SUBAGENT_TYPE" "$SURFACE" "$VERDICT_PREFIX" "$EXTERNAL_COMMS_ASSESS_SKILL")
413
+ if [ -n "${CODEX_THREAD_ID:-}" ]; then
414
+ COMPLETION_GUIDANCE='On Codex, wait for the reviewer to finish, then close that completed agent once before retrying; the PostToolUse compatibility hook consumes the completed close response and persists its structured verdict, with no transcript parsing or nested codex exec.'
415
+ else
416
+ COMPLETION_GUIDANCE='On Claude Code, dispatch the reviewer SYNCHRONOUSLY (run_in_background: false): a background-launched reviewer does not fire its PostToolUse mark hook, so the marker never persists and this gate re-blocks (P402).'
417
+ fi
418
+ REASON=$(printf 'BLOCKED (external-comms gate / %s evaluator): %s draft has not been reviewed by %s. Delegate to %s (subagent_type: '"'"'%s'"'"') with a prompt that starts with the line `SURFACE: %s` and wraps the draft body verbatim inside `<draft>...</draft>` markers (for the changeset-author surface the body is the changeset summary WITHOUT the leading `---` frontmatter block — the gate strips frontmatter before hashing the marker key). The completion hook marks the draft reviewed when the subagent emits %s_VERDICT: PASS — single fire suffices. %s Use %s for an interactive walkthrough. There is no env override (P377/RFC-029 — BYPASS_RISK_GATE removed).' \
419
+ "$EXTERNAL_COMMS_EVALUATOR_ID" "$SURFACE" "$EXTERNAL_COMMS_SUBAGENT_TYPE" "$EXTERNAL_COMMS_SUBAGENT_TYPE" "$EXTERNAL_COMMS_SUBAGENT_TYPE" "$SURFACE" "$VERDICT_PREFIX" "$COMPLETION_GUIDANCE" "$EXTERNAL_COMMS_ASSESS_SKILL")
415
420
  deny_with_reason "$REASON"
416
421
  exit 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windyroad/voice-tone",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Voice and tone enforcement for user-facing copy",
5
5
  "bin": {
6
6
  "windyroad-voice-tone": "./bin/install.mjs"
@@ -24,6 +24,7 @@
24
24
  "hooks/",
25
25
  "skills/",
26
26
  ".claude-plugin/",
27
- "lib/"
27
+ "lib/",
28
+ "!hooks/test/"
28
29
  ]
29
30
  }
@@ -1,444 +0,0 @@
1
- #!/usr/bin/env bats
2
- # Tests for packages/voice-tone/hooks/external-comms-gate.sh
3
- # (P038 / ADR-028 amended 2026-05-14).
4
- #
5
- # Behavioural: the gate denies outbound prose tool calls until the
6
- # wr-voice-tone:external-comms subagent has reviewed the draft and the
7
- # per-evaluator marker `external-comms-voice-tone-reviewed-<KEY>` has been
8
- # written. Voice-tone evaluator does NOT run the leak-pattern pre-filter
9
- # (EXTERNAL_COMMS_LEAK_PREFILTER=no in external-comms-evaluator.conf).
10
- # Composition with the risk-scorer evaluator happens at firing level —
11
- # both gates fire on the same PreToolUse event when both plugins installed.
12
-
13
- setup() {
14
- HOOKS_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
15
- HOOK="$HOOKS_DIR/external-comms-gate.sh"
16
-
17
- TEST_SESSION="bats-vt-extcomms-gate-$$-${BATS_TEST_NUMBER}"
18
- RDIR="${TMPDIR:-/tmp}/claude-risk-${TEST_SESSION}"
19
- rm -rf "$RDIR"
20
- mkdir -p "$RDIR"
21
-
22
- # Voice-tone evaluator's policy file is docs/VOICE-AND-TONE.md per the .conf.
23
- TEST_PROJECT_DIR="$(mktemp -d)"
24
- mkdir -p "$TEST_PROJECT_DIR/docs"
25
- printf "## Voice principles\n- Direct\n- No hedging\n## Banned patterns\n- 'happy to help further'\n" \
26
- > "$TEST_PROJECT_DIR/docs/VOICE-AND-TONE.md"
27
-
28
- unset BYPASS_RISK_GATE
29
- }
30
-
31
- teardown() {
32
- rm -rf "$RDIR"
33
- rm -rf "$TEST_PROJECT_DIR"
34
- unset BYPASS_RISK_GATE
35
- }
36
-
37
- # ---------- Helpers ----------
38
-
39
- build_bash_input() {
40
- local cmd="$1"
41
- python3 -c "
42
- import json, sys
43
- print(json.dumps({
44
- 'session_id': '$TEST_SESSION',
45
- 'tool_name': 'Bash',
46
- 'tool_input': {'command': sys.argv[1]},
47
- }))
48
- " "$cmd"
49
- }
50
-
51
- build_write_input() {
52
- local file_path="$1"
53
- local content="$2"
54
- python3 -c "
55
- import json, sys
56
- print(json.dumps({
57
- 'session_id': '$TEST_SESSION',
58
- 'tool_name': 'Write',
59
- 'tool_input': {'file_path': sys.argv[1], 'content': sys.argv[2]},
60
- }))
61
- " "$file_path" "$content"
62
- }
63
-
64
- # Mock `gh repo view --json visibility` for the git-commit-message surface
65
- # repo-visibility precondition (P365). vis ∈ {PUBLIC,PRIVATE,INTERNAL}; pass the
66
- # literal "FAIL" to simulate gh absent / unauthenticated (non-zero exit).
67
- mock_gh_visibility() {
68
- local vis="$1"
69
- mkdir -p "$TEST_PROJECT_DIR/mockbin"
70
- if [ "$vis" = "FAIL" ]; then
71
- printf '#!/usr/bin/env bash\nexit 1\n' > "$TEST_PROJECT_DIR/mockbin/gh"
72
- else
73
- printf '#!/usr/bin/env bash\necho %s\n' "$vis" > "$TEST_PROJECT_DIR/mockbin/gh"
74
- fi
75
- chmod +x "$TEST_PROJECT_DIR/mockbin/gh"
76
- }
77
-
78
- run_hook() {
79
- local input="$1"
80
- run bash -c "cd '$TEST_PROJECT_DIR' && export PATH='$TEST_PROJECT_DIR/mockbin':\$PATH && printf '%s' \"\$1\" | '$HOOK'" _ "$input"
81
- }
82
-
83
- # ---------- Tests ----------
84
-
85
- @test "non-matching Bash command (ls) is allowed silently" {
86
- INPUT=$(build_bash_input "ls -la")
87
- run_hook "$INPUT"
88
- [ "$status" -eq 0 ]
89
- [ -z "$output" ]
90
- }
91
-
92
- @test "gh issue create with clean draft denies and prompts wr-voice-tone:external-comms delegation (no marker yet)" {
93
- INPUT=$(build_bash_input "gh issue create --title T --body 'we observed a build failure on Node 20'")
94
- run_hook "$INPUT"
95
- [ "$status" -eq 0 ]
96
- [[ "$output" == *"permissionDecision"* ]]
97
- [[ "$output" == *"deny"* ]]
98
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
99
- }
100
-
101
- # P377/RFC-029: the BYPASS_RISK_GATE env override was removed. The only
102
- # clearance path named in the deny is delegation to the external-comms subagent.
103
- @test "marker-absent deny names the reviewer and offers no env override (P377/RFC-029)" {
104
- INPUT=$(build_bash_input "gh issue create --title T --body 'we observed a build failure on Node 20'")
105
- run_hook "$INPUT"
106
- [ "$status" -eq 0 ]
107
- [[ "$output" == *"deny"* ]]
108
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
109
- [[ "$output" != *"BYPASS_RISK_GATE=1"* ]]
110
- }
111
-
112
- @test "voice-tone evaluator skips leak pre-filter (EXTERNAL_COMMS_LEAK_PREFILTER=no)" {
113
- # A draft with leak-shaped content (revenue figure with business context) would
114
- # hard-fail in the risk evaluator. The voice-tone gate must NOT hard-fail; leak
115
- # detection is the risk evaluator's concern. Voice-tone deny-and-delegates for
116
- # subagent review, same as any clean draft.
117
- INPUT=$(build_bash_input "gh issue comment 42 --body 'Acme Corp 2.4M ARR is a real concern'")
118
- run_hook "$INPUT"
119
- [ "$status" -eq 0 ]
120
- [[ "$output" == *"deny"* ]]
121
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
122
- # Must NOT name a leak class.
123
- [[ "$output" != *"credential"* ]]
124
- [[ "$output" != *"financial"* ]]
125
- }
126
-
127
- @test "BYPASS_RISK_GATE=1 does NOT bypass the gate (removed P377/RFC-029)" {
128
- INPUT=$(build_bash_input "gh issue create --title T --body 'we observed a build failure'")
129
- run bash -c "cd '$TEST_PROJECT_DIR' && BYPASS_RISK_GATE=1 printf '%s' \"\$1\" | BYPASS_RISK_GATE=1 '$HOOK'" _ "$INPUT"
130
- [ "$status" -eq 0 ]
131
- # The env override no longer short-circuits — the gate still denies the
132
- # unreviewed external-comms draft.
133
- [[ "$output" == *"deny"* ]]
134
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
135
- }
136
-
137
- @test "per-evaluator marker (external-comms-voice-tone-reviewed-<KEY>) allows the call" {
138
- DRAFT="we observed a build failure on Node 20"
139
- SURFACE="gh-issue-create"
140
- KEY=$(printf '%s\n%s' "$DRAFT" "$SURFACE" | shasum -a 256 | cut -d' ' -f1)
141
- touch "${RDIR}/external-comms-voice-tone-reviewed-${KEY}"
142
-
143
- INPUT=$(build_bash_input "gh issue create --title T --body '$DRAFT'")
144
- run_hook "$INPUT"
145
- [ "$status" -eq 0 ]
146
- [ -z "$output" ]
147
- }
148
-
149
- @test "risk-scorer marker (external-comms-risk-reviewed-<KEY>) does NOT satisfy the voice-tone gate" {
150
- # Independent per-evaluator markers: a risk-evaluator PASS marker does not
151
- # imply voice-tone has been reviewed.
152
- DRAFT="we observed a build failure on Node 20"
153
- SURFACE="gh-issue-create"
154
- KEY=$(printf '%s\n%s' "$DRAFT" "$SURFACE" | shasum -a 256 | cut -d' ' -f1)
155
- touch "${RDIR}/external-comms-risk-reviewed-${KEY}"
156
-
157
- INPUT=$(build_bash_input "gh issue create --title T --body '$DRAFT'")
158
- run_hook "$INPUT"
159
- [ "$status" -eq 0 ]
160
- [[ "$output" == *"deny"* ]]
161
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
162
- }
163
-
164
- @test "docs/VOICE-AND-TONE.md absent yields advisory-only mode (permits)" {
165
- rm -f "$TEST_PROJECT_DIR/docs/VOICE-AND-TONE.md"
166
- INPUT=$(build_bash_input "gh issue create --title T --body 'we observed a failure'")
167
- run_hook "$INPUT"
168
- [ "$status" -eq 0 ]
169
- # Must NOT deny when policy file is absent.
170
- [[ "$output" != *"\"permissionDecision\": \"deny\""* ]]
171
- [[ "$output" != *"\"permissionDecision\":\"deny\""* ]]
172
- # Must surface the advisory systemMessage.
173
- [[ "$output" == *"docs/VOICE-AND-TONE.md not found"* ]]
174
- }
175
-
176
- @test "PreToolUse:Write on .changeset/*.md triggers deny+delegate" {
177
- INPUT=$(build_write_input ".changeset/test.md" "Add some feature. Happy to help further with details.")
178
- run_hook "$INPUT"
179
- [ "$status" -eq 0 ]
180
- [[ "$output" == *"deny"* ]]
181
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
182
- }
183
-
184
- @test "PreToolUse:Write on a non-changeset path is ignored" {
185
- INPUT=$(build_write_input "src/foo.ts" "happy to help further")
186
- run_hook "$INPUT"
187
- [ "$status" -eq 0 ]
188
- [ -z "$output" ]
189
- }
190
-
191
- @test "gh api security-advisories triggers the gate" {
192
- INPUT=$(build_bash_input "gh api repos/foo/bar/security-advisories --method POST --field summary='vulnerability detail'")
193
- run_hook "$INPUT"
194
- [ "$status" -eq 0 ]
195
- [[ "$output" == *"deny"* ]]
196
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
197
- }
198
-
199
- # ---------------------------------------------------------------------------
200
- # P405 — read-only `gh api` polls must NOT trip the gate. `gh api` defaults to
201
- # GET; it only carries an outbound prose body (the thing this gate reviews)
202
- # when a request-body flag (-f/--field, -F/--raw-field, --input) is present.
203
- # The `/wr-itil:review-problems` Step 4.5c security-advisories discovery poll
204
- # is read-only (`--jq` filter, no body flag) and was being denied as if it
205
- # were an advisory draft, silently blacking out one discovery channel.
206
- # ---------------------------------------------------------------------------
207
-
208
- @test "P405: read-only gh api security-advisories poll (--jq, no body flag) is not gated" {
209
- INPUT=$(build_bash_input "gh api repos/foo/bar/security-advisories --jq '.[].ghsa_id'")
210
- run_hook "$INPUT"
211
- [ "$status" -eq 0 ]
212
- [ -z "$output" ]
213
- }
214
-
215
- @test "P405: bare gh api security-advisories read (no flags) is not gated" {
216
- INPUT=$(build_bash_input "gh api repos/foo/bar/security-advisories")
217
- run_hook "$INPUT"
218
- [ "$status" -eq 0 ]
219
- [ -z "$output" ]
220
- }
221
-
222
- @test "P405: read-only gh api comments poll (--jq, no body flag) is not gated" {
223
- INPUT=$(build_bash_input "gh api repos/foo/bar/issues/1/comments --jq '.[].body'")
224
- run_hook "$INPUT"
225
- [ "$status" -eq 0 ]
226
- [ -z "$output" ]
227
- }
228
-
229
- @test "P405: gh api security-advisories write with -f body flag still triggers the gate" {
230
- INPUT=$(build_bash_input "gh api repos/foo/bar/security-advisories -f summary='new advisory'")
231
- run_hook "$INPUT"
232
- [ "$status" -eq 0 ]
233
- [[ "$output" == *"deny"* ]]
234
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
235
- }
236
-
237
- @test "npm publish triggers the gate" {
238
- INPUT=$(build_bash_input "npm publish")
239
- run_hook "$INPUT"
240
- [ "$status" -eq 0 ]
241
- [[ "$output" == *"deny"* ]]
242
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
243
- }
244
-
245
- @test "deny message references the on-demand skill (/wr-voice-tone:assess-external-comms)" {
246
- INPUT=$(build_bash_input "gh issue comment 42 --body 'a draft'")
247
- run_hook "$INPUT"
248
- [ "$status" -eq 0 ]
249
- [[ "$output" == *"/wr-voice-tone:assess-external-comms"* ]]
250
- }
251
-
252
- @test "marker name uses evaluator id from external-comms-evaluator.conf (voice-tone, not risk)" {
253
- # Regression: the canonical hook sources the .conf and uses its EVALUATOR_ID
254
- # in the marker filename. The risk-scorer's marker name does NOT satisfy the
255
- # voice-tone gate even if the KEY matches.
256
- DRAFT="some draft body"
257
- SURFACE="gh-issue-create"
258
- KEY=$(printf '%s\n%s' "$DRAFT" "$SURFACE" | shasum -a 256 | cut -d' ' -f1)
259
- # Pre-amendment combined marker — should NOT satisfy the new voice-tone gate.
260
- touch "${RDIR}/external-comms-reviewed-${KEY}"
261
-
262
- INPUT=$(build_bash_input "gh issue create --title T --body '$DRAFT'")
263
- run_hook "$INPUT"
264
- [ "$status" -eq 0 ]
265
- [[ "$output" == *"deny"* ]]
266
- }
267
-
268
- # ---------------------------------------------------------------------------
269
- # P010 / ADR-028 amended 2026-05-25 — deny-after-PASS regression (voice-tone).
270
- # Mirror of the risk-scorer regression: the gate sees the FULL changeset
271
- # content (YAML frontmatter + body) but the mark hook keys the marker on the
272
- # <draft> body. After the fix the gate strips frontmatter before hashing, so
273
- # a body-keyed voice-tone PASS marker permits the changeset Write.
274
- # ---------------------------------------------------------------------------
275
-
276
- @test "P010: changeset Write permits when the voice-tone PASS marker is keyed on the <draft> body (frontmatter stripped before hash)" {
277
- BODY="external-comms gate strips changeset frontmatter before key hash"
278
- SURFACE="changeset-author"
279
- KEY=$(printf '%s\n%s' "$BODY" "$SURFACE" | shasum -a 256 | cut -d' ' -f1)
280
- touch "${RDIR}/external-comms-voice-tone-reviewed-${KEY}"
281
-
282
- CONTENT=$'---\n"@windyroad/voice-tone": patch\n---\n\n'"$BODY"
283
- INPUT=$(build_write_input ".changeset/p010-fix.md" "$CONTENT")
284
- run_hook "$INPUT"
285
- [ "$status" -eq 0 ]
286
- [ -z "$output" ]
287
- }
288
-
289
- # ---------------------------------------------------------------------------
290
- # P360 — voice-tone evaluator disclaims the git-commit-message surface.
291
- # docs/VOICE-AND-TONE.md § Scope explicitly excludes commit messages ("It does
292
- # NOT apply to: ... Commit messages (covered by ADR-014 + ADR-018)"), so a
293
- # voice-tone review of a commit-message body is a guaranteed-PASS no-op
294
- # (~19K tokens per round-trip). external-comms-evaluator.conf sets
295
- # EXTERNAL_COMMS_SKIP_SURFACES=git-commit-message, so the gate silent-passes the
296
- # prose-review delegation on this surface in EVERY repo — visibility-independent
297
- # (the P360 skip is placed ahead of the P365 visibility precondition). The
298
- # risk-scorer evaluator, whose .conf leaves the skip list empty, still gates
299
- # this surface (its leak check is meaningful) — covered by
300
- # packages/risk-scorer/hooks/test/external-comms-gate.bats.
301
- #
302
- # Supersedes the original P082 Phase 1 voice-tone commit-message tests, which
303
- # asserted DENY on PUBLIC — that gate fire was the no-op P360 removes.
304
- # ---------------------------------------------------------------------------
305
-
306
- @test "P360: git commit -m silent-passes (voice-tone disclaims commit messages)" {
307
- mock_gh_visibility PUBLIC
308
- INPUT=$(build_bash_input "git commit -m \"I've implemented the feature\"")
309
- run_hook "$INPUT"
310
- [ "$status" -eq 0 ]
311
- [ -z "$output" ]
312
- }
313
-
314
- @test "P360: git commit --message silent-passes with no marker round-trip" {
315
- mock_gh_visibility PUBLIC
316
- INPUT=$(build_bash_input "git commit --message \"happy to help further with this fix\"")
317
- run_hook "$INPUT"
318
- [ "$status" -eq 0 ]
319
- [ -z "$output" ]
320
- }
321
-
322
- @test "P360: git commit --amend -m silent-passes" {
323
- mock_gh_visibility PUBLIC
324
- INPUT=$(build_bash_input "git commit --amend -m \"rewritten subject\"")
325
- run_hook "$INPUT"
326
- [ "$status" -eq 0 ]
327
- [ -z "$output" ]
328
- }
329
-
330
- @test "P360: git commit HEREDOC body silent-passes without a marker" {
331
- mock_gh_visibility PUBLIC
332
- BODY=$'feat(foo): add bar\n\nWe observed a build failure on Node 20.'
333
- CMD=$'git commit -m "$(cat <<\'EOF\'\n'"$BODY"$'\nEOF\n)"'
334
- INPUT=$(build_bash_input "$CMD")
335
- run_hook "$INPUT"
336
- [ "$status" -eq 0 ]
337
- [ -z "$output" ]
338
- }
339
-
340
- @test "P360: commit-message skip is visibility-independent (PRIVATE silent-passes)" {
341
- mock_gh_visibility PRIVATE
342
- INPUT=$(build_bash_input "git commit -m \"I've implemented the feature\"")
343
- run_hook "$INPUT"
344
- [ "$status" -eq 0 ]
345
- [ -z "$output" ]
346
- }
347
-
348
- @test "P360: commit-message skip is visibility-independent (INTERNAL silent-passes)" {
349
- mock_gh_visibility INTERNAL
350
- INPUT=$(build_bash_input "git commit -m \"I've implemented the feature\"")
351
- run_hook "$INPUT"
352
- [ "$status" -eq 0 ]
353
- [ -z "$output" ]
354
- }
355
-
356
- @test "P360: commit-message skip is visibility-independent (indeterminate gh silent-passes)" {
357
- mock_gh_visibility FAIL
358
- INPUT=$(build_bash_input "git commit -m \"I've implemented the feature\"")
359
- run_hook "$INPUT"
360
- [ "$status" -eq 0 ]
361
- [ -z "$output" ]
362
- }
363
-
364
- @test "P082: bare git commit (editor flow) is silently allowed per SC1" {
365
- # No -m / --message → .git/COMMIT_EDITMSG doesn't exist at PreToolUse
366
- # time. Phase 1 skip is pragmatic; the editor flow has user-eyeballs.
367
- INPUT=$(build_bash_input "git commit")
368
- run_hook "$INPUT"
369
- [ "$status" -eq 0 ]
370
- [ -z "$output" ]
371
- }
372
-
373
- @test "P082: git merge is silently allowed (not a git commit verb)" {
374
- INPUT=$(build_bash_input "git merge --no-ff feature-branch")
375
- run_hook "$INPUT"
376
- [ "$status" -eq 0 ]
377
- [ -z "$output" ]
378
- }
379
-
380
- @test "P082→P377/RFC-029: BYPASS_RISK_GATE=1 is inert — does not short-circuit the gate" {
381
- # gh-issue is an unconditionally-gated external surface (no visibility
382
- # precondition). Setting BYPASS_RISK_GATE=1 has no effect: the unreviewed
383
- # draft still denies, identically to the no-env-var case.
384
- INPUT=$(build_bash_input "gh issue create --title T --body 'we observed a build failure on Node 20'")
385
- run bash -c "cd '$TEST_PROJECT_DIR' && BYPASS_RISK_GATE=1 printf '%s' \"\$1\" | BYPASS_RISK_GATE=1 '$HOOK'" _ "$INPUT"
386
- [ "$status" -eq 0 ]
387
- [[ "$output" == *"deny"* ]]
388
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
389
- }
390
-
391
- @test "P360: the skip is surface-scoped — gh-issue is NOT skipped (still denies+delegates)" {
392
- # EXTERNAL_COMMS_SKIP_SURFACES lists only git-commit-message; the inherently
393
- # external gh-issue surface stays gated. Guards against the skip list over-
394
- # matching (e.g. a substring or blanket-skip regression).
395
- mock_gh_visibility PUBLIC
396
- INPUT=$(build_bash_input "gh issue create --title x --body 'a clean issue body'")
397
- run_hook "$INPUT"
398
- [ "$status" -eq 0 ]
399
- [[ "$output" == *"deny"* ]]
400
- [[ "$output" == *"wr-voice-tone:external-comms"* ]]
401
- }
402
-
403
- @test "P365: PRIVATE visibility does NOT short-circuit the gh-issue surface (still denies+delegates)" {
404
- mock_gh_visibility PRIVATE
405
- INPUT=$(build_bash_input "gh issue create --title x --body 'a clean issue body'")
406
- run_hook "$INPUT"
407
- [ "$status" -eq 0 ]
408
- [[ "$output" == *"deny"* ]]
409
- [[ "$output" == *"gh-issue-create"* ]]
410
- }
411
-
412
- # ---------------------------------------------------------------------------
413
- # P364 — backtick-bearing double-quoted --body marker-key mismatch.
414
- # The voice-tone gate shares the byte-identical canonical external-comms-gate.sh
415
- # (ADR-017 sync), so the P364 shell-unescape fix applies here too: a body with
416
- # backslash-escaped backticks in --body "..." must unescape to the logical
417
- # <draft> body the PostToolUse mark hook hashes, or the PASS marker never
418
- # permits. DISTINCT from P276 / P010 (whitespace / frontmatter).
419
- # ---------------------------------------------------------------------------
420
-
421
- @test "P364: backtick-bearing double-quoted --body permits when marker keyed on the unescaped logical body" {
422
- LOGICAL='Tidied the wording in `external-comms-gate` for the patch.'
423
- SURFACE="gh-issue-comment"
424
- KEY=$(printf '%s\n%s' "$LOGICAL" "$SURFACE" | shasum -a 256 | cut -d' ' -f1)
425
- touch "${RDIR}/external-comms-voice-tone-reviewed-${KEY}"
426
-
427
- CMD='gh issue comment 42 --body "Tidied the wording in \`external-comms-gate\` for the patch."'
428
- INPUT=$(build_bash_input "$CMD")
429
- run_hook "$INPUT"
430
- [ "$status" -eq 0 ]
431
- [ -z "$output" ]
432
- }
433
-
434
- @test "P364: single-quoted --body with literal backticks stays literal (no unescaping applied)" {
435
- LOGICAL='Tidied the wording in `plain_span` here.'
436
- SURFACE="gh-issue-comment"
437
- KEY=$(printf '%s\n%s' "$LOGICAL" "$SURFACE" | shasum -a 256 | cut -d' ' -f1)
438
- touch "${RDIR}/external-comms-voice-tone-reviewed-${KEY}"
439
-
440
- INPUT=$(build_bash_input "gh issue comment 42 --body 'Tidied the wording in \`plain_span\` here.'")
441
- run_hook "$INPUT"
442
- [ "$status" -eq 0 ]
443
- [ -z "$output" ]
444
- }
@@ -1,117 +0,0 @@
1
- #!/usr/bin/env bats
2
- # Behavioural tests for packages/voice-tone/hooks/external-comms-mark-reviewed.sh
3
- # under P166 hook-side key derivation (ADR-028 amended 2026-05-16).
4
- #
5
- # Contract: the PostToolUse:Agent hook derives the marker key from
6
- # tool_input.prompt's `SURFACE: <name>` + `<draft>...</draft>` structure
7
- # instead of trusting an agent-emitted EXTERNAL_COMMS_VOICE_TONE_KEY line.
8
- # On PASS, writes external-comms-voice-tone-reviewed-<KEY> at the derived
9
- # key. Backward-compat: if the prompt lacks structure, falls back to the
10
- # agent-emitted KEY line (one release-cycle window per architect direction).
11
-
12
- setup() {
13
- SCRIPT_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
14
- HOOK="$SCRIPT_DIR/external-comms-mark-reviewed.sh"
15
- ORIG_DIR="$PWD"
16
- TEST_DIR=$(mktemp -d)
17
- cd "$TEST_DIR"
18
- TMPDIR="$TEST_DIR/tmp"
19
- export TMPDIR
20
- mkdir -p "$TMPDIR"
21
- SESSION_ID="test-vt-mark-prompt-$$-${BATS_TEST_NUMBER}"
22
- RDIR="$TMPDIR/claude-risk-${SESSION_ID}"
23
- }
24
-
25
- teardown() {
26
- cd "$ORIG_DIR"
27
- rm -rf "$TEST_DIR"
28
- }
29
-
30
- # Gate-side reference key — same computation as external-comms-gate.sh line 229.
31
- gate_key() {
32
- local draft="$1" surface="$2"
33
- printf '%s\n%s' "$draft" "$surface" | shasum -a 256 | cut -d' ' -f1
34
- }
35
-
36
- # Build the PostToolUse:Agent payload and pipe it to the hook.
37
- # - tool_input.prompt carries the structured prompt the orchestrator sent to the agent.
38
- # - tool_response.content[0].text carries the agent's stdout (verdict block).
39
- run_hook() {
40
- local prompt="$1"
41
- local agent_output="$2"
42
- python3 -c "
43
- import json, sys
44
- print(json.dumps({
45
- 'tool_name': 'Agent',
46
- 'session_id': '${SESSION_ID}',
47
- 'tool_input': {'subagent_type': 'wr-voice-tone:external-comms', 'prompt': sys.argv[1]},
48
- 'tool_response': {'content': [{'type': 'text', 'text': sys.argv[2]}]}
49
- }))" "$prompt" "$agent_output" | bash "$HOOK"
50
- }
51
-
52
- @test "PASS with structured prompt: marker lands at hook-derived key" {
53
- DRAFT="we noticed a build failure on Node 20"
54
- SURFACE="changeset-author"
55
- PROMPT=$'SURFACE: '"$SURFACE"$'\n<draft>\n'"$DRAFT"$'\n</draft>\nReview against docs/VOICE-AND-TONE.md.'
56
- AGENT_OUTPUT=$'no voice/tone violation matched\nEXTERNAL_COMMS_VOICE_TONE_VERDICT: PASS'
57
- run_hook "$PROMPT" "$AGENT_OUTPUT"
58
- KEY=$(gate_key "$DRAFT" "$SURFACE")
59
- [ -f "$RDIR/external-comms-voice-tone-reviewed-${KEY}" ]
60
- }
61
-
62
- @test "FAIL with structured prompt: no marker written" {
63
- DRAFT="happy to help further on this 2-year-old issue"
64
- SURFACE="gh-issue-comment"
65
- PROMPT=$'SURFACE: '"$SURFACE"$'\n<draft>\n'"$DRAFT"$'\n</draft>'
66
- AGENT_OUTPUT=$'EXTERNAL_COMMS_VOICE_TONE_VERDICT: FAIL\nEXTERNAL_COMMS_VOICE_TONE_REASON: banned closer'
67
- run_hook "$PROMPT" "$AGENT_OUTPUT"
68
- KEY=$(gate_key "$DRAFT" "$SURFACE")
69
- [ ! -f "$RDIR/external-comms-voice-tone-reviewed-${KEY}" ]
70
- }
71
-
72
- @test "PASS with structured prompt AND agent-emitted KEY: hook-derived key wins" {
73
- DRAFT="hook-derived path text"
74
- SURFACE="gh-pr-create"
75
- PROMPT=$'SURFACE: '"$SURFACE"$'\n<draft>\n'"$DRAFT"$'\n</draft>'
76
- # Agent emits a different (wrong) key — hook must ignore it in favour of derived key.
77
- BOGUS_KEY="0000000000000000000000000000000000000000000000000000000000000000"
78
- AGENT_OUTPUT=$'EXTERNAL_COMMS_VOICE_TONE_VERDICT: PASS\nEXTERNAL_COMMS_VOICE_TONE_KEY: '"$BOGUS_KEY"
79
- run_hook "$PROMPT" "$AGENT_OUTPUT"
80
- DERIVED_KEY=$(gate_key "$DRAFT" "$SURFACE")
81
- [ -f "$RDIR/external-comms-voice-tone-reviewed-${DERIVED_KEY}" ]
82
- [ ! -f "$RDIR/external-comms-voice-tone-reviewed-${BOGUS_KEY}" ]
83
- }
84
-
85
- @test "backward-compat: PASS with no structured prompt but agent-emitted KEY lands marker" {
86
- # Cached old SKILL.md still tells the agent to emit the KEY; hook honours it.
87
- LEGACY_KEY="abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
88
- PROMPT="please review this draft (legacy unstructured prompt)"
89
- AGENT_OUTPUT=$'EXTERNAL_COMMS_VOICE_TONE_VERDICT: PASS\nEXTERNAL_COMMS_VOICE_TONE_KEY: '"$LEGACY_KEY"
90
- run_hook "$PROMPT" "$AGENT_OUTPUT"
91
- [ -f "$RDIR/external-comms-voice-tone-reviewed-${LEGACY_KEY}" ]
92
- }
93
-
94
- @test "no structured prompt and no agent KEY: no marker written" {
95
- PROMPT="legacy prompt"
96
- AGENT_OUTPUT=$'EXTERNAL_COMMS_VOICE_TONE_VERDICT: PASS'
97
- run_hook "$PROMPT" "$AGENT_OUTPUT"
98
- # Nothing to key on — no marker at any path under RDIR.
99
- found=$(ls "$RDIR" 2>/dev/null | wc -l | tr -d ' ')
100
- [ "$found" -eq 0 ]
101
- }
102
-
103
- @test "ignores unrelated subagent types" {
104
- PROMPT=$'SURFACE: gh-issue-create\n<draft>\nbody\n</draft>'
105
- AGENT_OUTPUT=$'EXTERNAL_COMMS_VOICE_TONE_VERDICT: PASS'
106
- # Swap the subagent type in the input to an unrelated one.
107
- python3 -c "
108
- import json, sys
109
- print(json.dumps({
110
- 'tool_name': 'Agent',
111
- 'session_id': '${SESSION_ID}',
112
- 'tool_input': {'subagent_type': 'wr-architect:agent', 'prompt': sys.argv[1]},
113
- 'tool_response': {'content': [{'type': 'text', 'text': sys.argv[2]}]}
114
- }))" "$PROMPT" "$AGENT_OUTPUT" | bash "$HOOK"
115
- found=$(ls "$RDIR" 2>/dev/null | wc -l | tr -d ' ')
116
- [ "$found" -eq 0 ]
117
- }
@@ -1,81 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- # Tests for review-gate.sh (shared by voice-tone, style-guide, jtbd)
4
-
5
- setup() {
6
- SCRIPT_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
7
- source "$SCRIPT_DIR/lib/review-gate.sh"
8
- TEST_SESSION="test-$$-$BATS_TEST_NUMBER"
9
- TMPDIR_ORIG=$(mktemp -d)
10
- }
11
-
12
- teardown() {
13
- rm -f "/tmp/voice-tone-reviewed-${TEST_SESSION}"
14
- rm -f "/tmp/voice-tone-reviewed-${TEST_SESSION}.hash"
15
- rm -rf "$TMPDIR_ORIG"
16
- }
17
-
18
- @test "gate denies when no marker exists" {
19
- run check_review_gate "$TEST_SESSION" "voice-tone" "docs/VOICE-AND-TONE.md"
20
- [ "$status" -ne 0 ]
21
- }
22
-
23
- @test "gate allows when marker exists and is fresh" {
24
- touch "/tmp/voice-tone-reviewed-${TEST_SESSION}"
25
- run check_review_gate "$TEST_SESSION" "voice-tone" "docs/VOICE-AND-TONE.md"
26
- [ "$status" -eq 0 ]
27
- }
28
-
29
- @test "gate denies when marker is expired" {
30
- touch "/tmp/voice-tone-reviewed-${TEST_SESSION}"
31
- REVIEW_TTL=0 run check_review_gate "$TEST_SESSION" "voice-tone" "docs/VOICE-AND-TONE.md"
32
- [ "$status" -ne 0 ]
33
- }
34
-
35
- @test "store_review_hash creates hash file" {
36
- store_review_hash "$TEST_SESSION" "voice-tone" "docs/VOICE-AND-TONE.md"
37
- [ -f "/tmp/voice-tone-reviewed-${TEST_SESSION}.hash" ]
38
- }
39
-
40
- @test "_mtime returns a number" {
41
- touch "/tmp/voice-tone-reviewed-${TEST_SESSION}"
42
- result=$(_mtime "/tmp/voice-tone-reviewed-${TEST_SESSION}")
43
- [[ "$result" =~ ^[0-9]+$ ]]
44
- }
45
-
46
- @test "_hashcmd produces output" {
47
- result=$(echo "test" | _hashcmd)
48
- [ -n "$result" ]
49
- }
50
-
51
- # P215 / RFC-021 — REVIEW_GATE_REASON must carry an explicit recovery
52
- # directive naming the subagent_type and Agent tool, parallel to the
53
- # architect-gate ARCHITECT_GATE_REASON shape.
54
-
55
- @test "REVIEW_GATE_REASON names re-delegate directive when no marker" {
56
- REVIEW_GATE_REASON=""
57
- check_review_gate "$TEST_SESSION" "voice-tone" "docs/VOICE-AND-TONE.md" || true
58
- [[ "$REVIEW_GATE_REASON" == *"wr-voice-tone:agent"* ]]
59
- [[ "$REVIEW_GATE_REASON" == *"Agent tool"* ]]
60
- }
61
-
62
- @test "REVIEW_GATE_REASON names refresh-the-marker directive when TTL expired" {
63
- touch "/tmp/voice-tone-reviewed-${TEST_SESSION}"
64
- REVIEW_GATE_REASON=""
65
- REVIEW_TTL=0 check_review_gate "$TEST_SESSION" "voice-tone" "docs/VOICE-AND-TONE.md" || true
66
- [[ "$REVIEW_GATE_REASON" == *"expired"* ]]
67
- [[ "$REVIEW_GATE_REASON" == *"wr-voice-tone:agent"* ]]
68
- [[ "$REVIEW_GATE_REASON" == *"refresh the marker"* ]]
69
- }
70
-
71
- @test "REVIEW_GATE_REASON names drift directive when policy hash differs" {
72
- POLICY_FILE="$TMPDIR_ORIG/VOICE-AND-TONE.md"
73
- echo "# policy v1" > "$POLICY_FILE"
74
- touch "/tmp/voice-tone-reviewed-${TEST_SESSION}"
75
- echo "stale-hash" > "/tmp/voice-tone-reviewed-${TEST_SESSION}.hash"
76
- REVIEW_GATE_REASON=""
77
- check_review_gate "$TEST_SESSION" "voice-tone" "$POLICY_FILE" || true
78
- [[ "$REVIEW_GATE_REASON" == *"changed"* ]] || [[ "$REVIEW_GATE_REASON" == *"drift"* ]]
79
- [[ "$REVIEW_GATE_REASON" == *"wr-voice-tone:agent"* ]]
80
- [[ "$REVIEW_GATE_REASON" == *"refresh the marker"* ]]
81
- }
@@ -1,118 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- # Tests for slide_marker_on_subprocess_return helper (P111).
4
- #
5
- # Behavioural contract:
6
- # - Slides an existing marker forward (touch) on PostToolUse:Agent|Bash
7
- # completion, treating subprocess wall-clock as continuous parent-session
8
- # work for TTL purposes.
9
- # - Never CREATES a marker (creating requires a real gate review).
10
- # - Skips slide on subprocess error (tool_response.is_error=true) so a failed
11
- # subprocess does NOT extend the parent's trust window (ADR-009 amendment).
12
- # - No-op when no marker exists or session_id is empty (fail-safe).
13
-
14
- setup() {
15
- HOOKS_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
16
- source "$HOOKS_DIR/lib/gate-helpers.sh"
17
-
18
- TEST_SESSION="bats-slide-$$-${BATS_TEST_NUMBER}"
19
- MARKER="/tmp/architect-reviewed-${TEST_SESSION}"
20
- rm -f "$MARKER"
21
- }
22
-
23
- teardown() {
24
- rm -f "$MARKER"
25
- }
26
-
27
- # Helper: backdate file mtime by N seconds (portable between macOS and Linux)
28
- _backdate() {
29
- local file="$1" seconds="$2"
30
- local stamp
31
- stamp=$(date -v-${seconds}S +%Y%m%d%H%M.%S 2>/dev/null \
32
- || date -d "${seconds} seconds ago" +%Y%m%d%H%M.%S 2>/dev/null)
33
- touch -t "$stamp" "$file"
34
- }
35
-
36
- @test "slide: existing marker is touched on success response" {
37
- touch "$MARKER"
38
- _backdate "$MARKER" 60
39
- BEFORE=$(_mtime "$MARKER")
40
- _HOOK_INPUT='{"tool_response":{"content":[]}}'
41
- slide_marker_on_subprocess_return "$MARKER"
42
- AFTER=$(_mtime "$MARKER")
43
- [ "$AFTER" -gt "$BEFORE" ]
44
- }
45
-
46
- @test "slide: long-running subprocess does NOT cause parent marker expiry on return (P111 reproduction)" {
47
- # Simulate the P111 failure mode: parent's marker is set, then a long
48
- # subprocess runs (we backdate the marker to simulate elapsed wall-clock),
49
- # then PostToolUse fires with a successful tool_response. The marker mtime
50
- # must be refreshed so the parent's NEXT PreToolUse gate check (which
51
- # compares NOW - mtime against TTL) sees a fresh marker.
52
- touch "$MARKER"
53
- # Marker is 50 minutes old — under default 60-min TTL but close to expiry.
54
- # Without the slide on subprocess return, a subsequent 15-min subprocess
55
- # would push the mtime past TTL and the next PreToolUse would deny.
56
- _backdate "$MARKER" 3000
57
- BEFORE=$(_mtime "$MARKER")
58
- _HOOK_INPUT='{"tool_response":{"content":[{"type":"text","text":"OK"}]}}'
59
- slide_marker_on_subprocess_return "$MARKER"
60
- AFTER=$(_mtime "$MARKER")
61
- NOW=$(date +%s)
62
- [ "$AFTER" -gt "$BEFORE" ]
63
- # And the new mtime is approximately NOW (within 5 seconds of slide call)
64
- AGE=$((NOW - AFTER))
65
- [ "$AGE" -lt 5 ]
66
- }
67
-
68
- @test "slide: does NOT touch marker when tool_response.is_error=true" {
69
- touch "$MARKER"
70
- _backdate "$MARKER" 60
71
- BEFORE=$(_mtime "$MARKER")
72
- _HOOK_INPUT='{"tool_response":{"is_error":true,"content":[]}}'
73
- slide_marker_on_subprocess_return "$MARKER"
74
- AFTER=$(_mtime "$MARKER")
75
- [ "$BEFORE" = "$AFTER" ]
76
- }
77
-
78
- @test "slide: no-op when marker does not exist (never creates)" {
79
- [ ! -f "$MARKER" ]
80
- _HOOK_INPUT='{"tool_response":{"content":[]}}'
81
- slide_marker_on_subprocess_return "$MARKER"
82
- [ ! -f "$MARKER" ]
83
- }
84
-
85
- @test "slide: no-op when marker path argument is empty" {
86
- _HOOK_INPUT='{"tool_response":{"content":[]}}'
87
- run slide_marker_on_subprocess_return ""
88
- [ "$status" -eq 0 ]
89
- }
90
-
91
- @test "slide: malformed hook input is fail-safe (no slide)" {
92
- touch "$MARKER"
93
- _backdate "$MARKER" 60
94
- BEFORE=$(_mtime "$MARKER")
95
- _HOOK_INPUT='not valid json'
96
- slide_marker_on_subprocess_return "$MARKER"
97
- AFTER=$(_mtime "$MARKER")
98
- # Fail-safe: when the hook input cannot be parsed, treat as error and skip
99
- [ "$BEFORE" = "$AFTER" ]
100
- }
101
-
102
- @test "slide: triggers correctly on Skill tool_response shape (P213, ADR-009 2026-06-08 amendment)" {
103
- # hooks.json matcher expansion Agent|Bash → Agent|Bash|Skill (P213 Option D)
104
- # widens slide-marker coverage to PostToolUse:Skill completions (e.g. the
105
- # /wr-risk-scorer:assess-* sibling assessor SKILLs run as long subprocesses
106
- # by the AFK orchestrator). The Skill tool_response shape is identical to
107
- # Agent|Bash (Claude Code's uniform PostToolUse contract), so the matcher-
108
- # agnostic helper composes without code changes. This test documents that
109
- # contract explicitly so a future hook_input shape divergence regression
110
- # surfaces here rather than at the gate-denial site.
111
- touch "$MARKER"
112
- _backdate "$MARKER" 60
113
- BEFORE=$(_mtime "$MARKER")
114
- _HOOK_INPUT='{"tool_name":"Skill","tool_response":{"content":[{"type":"text","text":"OK"}]}}'
115
- slide_marker_on_subprocess_return "$MARKER"
116
- AFTER=$(_mtime "$MARKER")
117
- [ "$AFTER" -gt "$BEFORE" ]
118
- }
@@ -1,86 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- # Behavioural tests for ADR-009 amendment 2026-06-06: substance-aware drift +
4
- # atomic verdict-write — voice-tone gate. Sibling-coverage to architect /
5
- # jtbd / style-guide bats files of the same name.
6
-
7
- setup() {
8
- SCRIPT_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
9
- source "$SCRIPT_DIR/lib/review-gate.sh"
10
-
11
- TEST_SESSION="bats-vt-substance-$$-${BATS_TEST_NUMBER}"
12
- SYSTEM="voice-tone"
13
- TEST_DIR=$(mktemp -d -t substance-aware-drift-vt.XXXXXX)
14
- POLICY_FILE="$TEST_DIR/VOICE-AND-TONE.md"
15
-
16
- MARKER="/tmp/${SYSTEM}-reviewed-${TEST_SESSION}"
17
- HASH_FILE="${MARKER}.hash"
18
- rm -f "$MARKER" "$HASH_FILE"
19
- }
20
-
21
- teardown() {
22
- rm -f "$MARKER" "$HASH_FILE"
23
- rm -rf "$TEST_DIR"
24
- }
25
-
26
- _install_and_mark() {
27
- local body="$1"
28
- printf '%s' "$body" > "$POLICY_FILE"
29
- touch "$MARKER"
30
- store_review_hash "$TEST_SESSION" "$SYSTEM" "$POLICY_FILE"
31
- }
32
-
33
- @test "voice-tone substance-aware: trailing-whitespace edit does NOT re-trigger" {
34
- _install_and_mark "# Voice and Tone
35
-
36
- Plain. Direct. Concise.
37
- "
38
- printf '%s' "# Voice and Tone
39
-
40
- Plain. Direct. Concise.
41
- " > "$POLICY_FILE"
42
-
43
- run check_review_gate "$TEST_SESSION" "$SYSTEM" "$POLICY_FILE"
44
- [ "$status" -eq 0 ]
45
- }
46
-
47
- @test "voice-tone substance-aware: new-content edit DOES re-trigger" {
48
- _install_and_mark "# Voice and Tone
49
-
50
- Plain. Direct. Concise.
51
- "
52
- printf '%s' "# Voice and Tone
53
-
54
- Plain. Direct. Concise. Friendly.
55
- " > "$POLICY_FILE"
56
-
57
- run check_review_gate "$TEST_SESSION" "$SYSTEM" "$POLICY_FILE"
58
- [ "$status" -ne 0 ]
59
- [ ! -f "$MARKER" ]
60
- }
61
-
62
- @test "voice-tone atomic-write: store_review_hash lands marker + hash together" {
63
- printf '%s' "# Voice and Tone
64
-
65
- Body.
66
- " > "$POLICY_FILE"
67
- touch "$MARKER"
68
- run store_review_hash "$TEST_SESSION" "$SYSTEM" "$POLICY_FILE"
69
- [ "$status" -eq 0 ]
70
- [ -f "$MARKER" ]
71
- [ -f "$HASH_FILE" ]
72
- }
73
-
74
- @test "voice-tone conservative: single-numeral change DOES re-trigger" {
75
- _install_and_mark "# Voice and Tone
76
-
77
- Sentences should be at most 20 words.
78
- "
79
- printf '%s' "# Voice and Tone
80
-
81
- Sentences should be at most 25 words.
82
- " > "$POLICY_FILE"
83
-
84
- run check_review_gate "$TEST_SESSION" "$SYSTEM" "$POLICY_FILE"
85
- [ "$status" -ne 0 ]
86
- }
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- # Tests for voice-tone-enforce-edit.sh — verifies the path-based exemption
4
- # for governance-managed surfaces (docs/story-maps/, docs/stories/) per
5
- # ADR-060 § Phase 2 amendment 2026-05-12 lines 481-496 (P170 Phase 2 Slice 2.5).
6
- #
7
- # The voice-tone hook is opt-in (gates *.html|*.jsx|*.tsx|*.vue|*.svelte|
8
- # *.ejs|*.hbs) and blocks outright when docs/VOICE-AND-TONE.md is absent.
9
- # Story-map HTML files would otherwise be blocked even when no policy
10
- # exists — this is the empirical block P170 line 297 documented when the
11
- # STORY-MAP-001 bootstrap was attempted. The exemption short-circuits before
12
- # the extension check.
13
-
14
- setup() {
15
- SCRIPT_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
16
- HOOK="$SCRIPT_DIR/voice-tone-enforce-edit.sh"
17
- ORIG_DIR="$PWD"
18
- TEST_DIR=$(mktemp -d)
19
- cd "$TEST_DIR"
20
- }
21
-
22
- teardown() {
23
- cd "$ORIG_DIR"
24
- rm -rf "$TEST_DIR"
25
- }
26
-
27
- run_hook_with_file() {
28
- local file_path="$1"
29
- local json="{\"tool_input\":{\"file_path\":\"${file_path}\"},\"session_id\":\"test-session-$$\"}"
30
- echo "$json" | bash "$HOOK"
31
- }
32
-
33
- assert_path_allowed() {
34
- local file_path="$1"
35
- run run_hook_with_file "$file_path"
36
- [ "$status" -eq 0 ]
37
- [[ "$output" != *"BLOCKED"* ]]
38
- }
39
-
40
- assert_path_blocked() {
41
- local file_path="$1"
42
- run run_hook_with_file "$file_path"
43
- [ "$status" -eq 0 ]
44
- [[ "$output" == *"BLOCKED"* ]]
45
- }
46
-
47
- # --- Story maps + stories exemptions (P170 Phase 2 Slice 2.5 / ADR-060) ---
48
-
49
- @test "voice-tone: exempts docs/story-maps/ HTML in per-state subdir" {
50
- assert_path_allowed "$PWD/docs/story-maps/draft/STORY-MAP-001-foo.html"
51
- }
52
-
53
- @test "voice-tone: exempts docs/story-maps/ HTML in completed subdir" {
54
- assert_path_allowed "$PWD/docs/story-maps/completed/STORY-MAP-002-bar.html"
55
- }
56
-
57
- @test "voice-tone: exempts docs/story-maps/ even when no VOICE-AND-TONE.md exists" {
58
- # P170 line 297: STORY-MAP-001 bootstrap was blocked here exactly because
59
- # this exemption did not exist. Behavioural regression-guard.
60
- [ ! -f docs/VOICE-AND-TONE.md ]
61
- assert_path_allowed "$PWD/docs/story-maps/in-progress/STORY-MAP-001-rfc-framework.html"
62
- }
63
-
64
- @test "voice-tone: exempts docs/stories/ files even though .md isn't normally gated" {
65
- assert_path_allowed "$PWD/docs/stories/draft/STORY-001-foo.md"
66
- }
67
-
68
- # --- Regression: non-exempt HTML still gate ---
69
-
70
- @test "voice-tone: exempts VCS-internal .git/ files even with a gated extension (P458)" {
71
- assert_path_allowed "$PWD/.git/hooks/prepare-commit-msg.tsx"
72
- }
73
-
74
- @test "voice-tone: still blocks an unrelated .html file when no policy exists" {
75
- assert_path_blocked "$PWD/public/index.html"
76
- }
77
-
78
- @test "voice-tone: still blocks a .tsx component file when no policy exists" {
79
- assert_path_blocked "$PWD/src/Component.tsx"
80
- }
@@ -1,77 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- # P095 / ADR-038: voice-tone-eval.sh UserPromptSubmit hook must emit
4
- # the full MANDATORY block only on the first prompt of a session;
5
- # subsequent prompts emit a terse reminder.
6
-
7
- setup() {
8
- REPO_ROOT="$(cd "$(dirname "$BATS_TEST_FILENAME")/../../../.." && pwd)"
9
- HOOK="$REPO_ROOT/packages/voice-tone/hooks/voice-tone-eval.sh"
10
-
11
- WORKDIR="$(mktemp -d)"
12
- mkdir -p "$WORKDIR/docs"
13
- : > "$WORKDIR/docs/VOICE-AND-TONE.md"
14
-
15
- SID="vt-eval-test-$$-$RANDOM"
16
- }
17
-
18
- teardown() {
19
- rm -f "/tmp/voice-tone-announced-${SID}"
20
- rm -f "/tmp/voice-tone-announced-${SID}-alt"
21
- rm -rf "$WORKDIR"
22
- }
23
-
24
- run_hook() {
25
- local sid="$1"
26
- (cd "$WORKDIR" && echo "{\"session_id\":\"$sid\"}" | bash "$HOOK")
27
- }
28
-
29
- @test "voice-tone-eval: first invocation emits the full MANDATORY block" {
30
- run run_hook "$SID"
31
- [ "$status" -eq 0 ]
32
- [ "${#output}" -gt 400 ]
33
- [[ "$output" == *"MANDATORY VOICE & TONE CHECK"* ]]
34
- [[ "$output" == *"wr-voice-tone:agent"* ]]
35
- }
36
-
37
- @test "voice-tone-eval: first invocation writes the announcement marker" {
38
- run run_hook "$SID"
39
- [ -f "/tmp/voice-tone-announced-${SID}" ]
40
- }
41
-
42
- @test "voice-tone-eval: second invocation emits only a terse reminder" {
43
- run_hook "$SID" >/dev/null
44
- run run_hook "$SID"
45
- [ "${#output}" -lt 250 ]
46
- [[ "$output" == *"voice-and-tone"* ]] || [[ "$output" == *"VOICE"* ]] || [[ "$output" == *"voice"* ]]
47
- [[ "$output" == *"wr-voice-tone:agent"* ]]
48
- [[ "$output" != *"REQUIRED ACTIONS:"* ]]
49
- }
50
-
51
- @test "voice-tone-eval: terse reminder preserves the MANDATORY signal word" {
52
- run_hook "$SID" >/dev/null
53
- run run_hook "$SID"
54
- [[ "$output" == *"MANDATORY"* ]] || [[ "$output" == *"REQUIRED"* ]] || [[ "$output" == *"NON-OPTIONAL"* ]]
55
- }
56
-
57
- @test "voice-tone-eval: terse reminder names the trigger artifact" {
58
- run_hook "$SID" >/dev/null
59
- run run_hook "$SID"
60
- [[ "$output" == *"VOICE-AND-TONE.md"* ]]
61
- }
62
-
63
- @test "voice-tone-eval: different session_id re-emits the full block" {
64
- run_hook "$SID" >/dev/null
65
- local SID2="${SID}-alt"
66
- run run_hook "$SID2"
67
- [ "${#output}" -gt 400 ]
68
- [[ "$output" == *"MANDATORY VOICE & TONE CHECK"* ]]
69
- rm -f "/tmp/voice-tone-announced-${SID2}"
70
- }
71
-
72
- @test "voice-tone-eval: empty session_id emits the full block and writes no marker" {
73
- run run_hook ""
74
- [ "${#output}" -gt 400 ]
75
- [[ "$output" == *"MANDATORY VOICE & TONE CHECK"* ]]
76
- [ ! -f "/tmp/voice-tone-announced-" ]
77
- }
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- # P001 / ADR-009: Stop-hook marker reset removed.
4
-
5
- setup() {
6
- PLUGIN_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)"
7
- }
8
-
9
- @test "voice-tone: hooks.json has no Stop hook entry (ADR-009)" {
10
- ! grep -q '"Stop"' "$PLUGIN_DIR/hooks/hooks.json"
11
- }
12
-
13
- @test "voice-tone: voice-tone-reset-marker.sh has been removed" {
14
- [ ! -f "$PLUGIN_DIR/hooks/voice-tone-reset-marker.sh" ]
15
- }
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- # P004: voice-tone-enforce-edit.sh project-root check.
4
-
5
- setup() {
6
- SCRIPT_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
7
- HOOK="$SCRIPT_DIR/voice-tone-enforce-edit.sh"
8
- }
9
-
10
- run_hook_with_file() {
11
- local file_path="$1"
12
- local json="{\"tool_input\":{\"file_path\":\"${file_path}\"},\"session_id\":\"test-$$\"}"
13
- echo "$json" | bash "$HOOK"
14
- }
15
-
16
- @test "voice-tone project-root: absolute .tsx outside project exits 0" {
17
- run run_hook_with_file "/Users/other/project/src/foo.tsx"
18
- [ "$status" -eq 0 ]
19
- [[ "$output" != *"BLOCKED"* ]]
20
- }