@bbcsoftwarefactory/skills 0.1.1 → 1.1.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.
Files changed (71) hide show
  1. package/dist/index.json +2 -3
  2. package/dist/skills/code-quality-gate/SKILL.md +4 -5
  3. package/dist/skills/code-quality-gate/references/gate-bigo.md +1 -1
  4. package/dist/skills/delivery-coordinator/SKILL.md +7 -8
  5. package/dist/skills/delivery-coordinator/references/hud-output.md +1 -1
  6. package/dist/skills/delivery-coordinator/references/issue-claim.md +5 -5
  7. package/dist/skills/delivery-coordinator/references/issue-dedup.md +1 -1
  8. package/dist/skills/delivery-coordinator/references/worktree-isolation.md +2 -2
  9. package/dist/skills/greptile-review-loop/SKILL.md +3 -4
  10. package/dist/skills/greptile-review-loop/references/review-protocol.md +1 -1
  11. package/dist/skills/issue-reviewer/SKILL.md +10 -13
  12. package/dist/skills/issue-reviewer/references/review-format.md +1 -1
  13. package/dist/skills/issue-reviewer/references/triage.md +6 -6
  14. package/dist/skills/question-gate/SKILL.md +6 -8
  15. package/dist/skills/question-gate/references/client-hooks.md +10 -10
  16. package/dist/skills/question-gate/references/diagram-routing.md +3 -3
  17. package/dist/skills/skill-clean-architecture/SKILL.md +2 -3
  18. package/dist/skills/skill-clean-architecture/references/source-headers.md +2 -3
  19. package/dist/skills/tool-depot/references/readonly-access.md +1 -1
  20. package/dist/skills/tool-depot/references/tool-catalog.json +2 -2
  21. package/dist/skills/watcher-observability/SKILL.md +3 -4
  22. package/dist/skills/watcher-observability/references/batch-protocol.md +6 -6
  23. package/dist/skills/watcher-observability/references/configuration.md +1 -1
  24. package/dist/skills/watcher-observability/references/error-scan.md +1 -1
  25. package/dist/skills/watcher-observability/references/live-protocol.md +8 -8
  26. package/dist/skills/watcher-observability/references/server-account.md +8 -8
  27. package/dist/skills/watcher-observability/server/watcher-gate.sh +1 -1
  28. package/dist/skills/watcher-observability/tests/watcher-gate.test.sh +10 -7
  29. package/dist/skills/workflow-auditor/SKILL.md +3 -5
  30. package/dist/skills/workflow-auditor/references/audit-protocol.md +3 -3
  31. package/dist/skills/workflow-auditor/references/ledger.md +1 -1
  32. package/package.json +26 -27
  33. package/dist/skills/code-quality-gate/scripts/extract-diff-scope.py +0 -225
  34. package/dist/skills/code-quality-gate/tests/extract-diff-scope.test.sh +0 -200
  35. package/dist/skills/delivery-coordinator/scripts/check-issue-claim.py +0 -363
  36. package/dist/skills/delivery-coordinator/scripts/check-worktree-guard.py +0 -220
  37. package/dist/skills/delivery-coordinator/scripts/classify-change-lane.py +0 -263
  38. package/dist/skills/delivery-coordinator/tests/check-issue-claim.test.sh +0 -221
  39. package/dist/skills/delivery-coordinator/tests/check-worktree-guard.test.sh +0 -123
  40. package/dist/skills/delivery-coordinator/tests/classify-change-lane.test.sh +0 -124
  41. package/dist/skills/greptile-review-loop/scripts/review-loop.py +0 -435
  42. package/dist/skills/greptile-review-loop/tests/review-loop.test.sh +0 -331
  43. package/dist/skills/issue-reviewer/scripts/fetch-issue-attachments.py +0 -239
  44. package/dist/skills/issue-reviewer/scripts/plan-issue-triage.py +0 -311
  45. package/dist/skills/issue-reviewer/tests/fetch-issue-attachments.test.sh +0 -90
  46. package/dist/skills/issue-reviewer/tests/plan-issue-triage.test.sh +0 -168
  47. package/dist/skills/question-gate/scripts/triage-question.py +0 -713
  48. package/dist/skills/question-gate/tests/question-corpus.test.sh +0 -32
  49. package/dist/skills/question-gate/tests/triage-question.test.sh +0 -441
  50. package/dist/skills/skill-clean-architecture/scripts/measure-bigo.py +0 -427
  51. package/dist/skills/skill-clean-architecture/tests/measure-bigo.test.sh +0 -222
  52. package/dist/skills/watcher-observability/scripts/error-scan.py +0 -318
  53. package/dist/skills/watcher-observability/scripts/resolve-containers.py +0 -155
  54. package/dist/skills/watcher-observability/scripts/save-counts.py +0 -381
  55. package/dist/skills/watcher-observability/scripts/summarize-logs.py +0 -113
  56. package/dist/skills/watcher-observability/scripts/watch-live.py +0 -606
  57. package/dist/skills/watcher-observability/tests/error-scan.test.sh +0 -257
  58. package/dist/skills/watcher-observability/tests/live-windows.test.sh +0 -177
  59. package/dist/skills/watcher-observability/tests/resolve-containers.test.sh +0 -87
  60. package/dist/skills/watcher-observability/tests/save-counts.test.sh +0 -338
  61. package/dist/skills/watcher-observability/tests/sleuth.test.sh +0 -176
  62. package/dist/skills/watcher-observability/tests/summarize-logs.test.sh +0 -105
  63. package/dist/skills/watcher-observability/tests/watcher-config.test.sh +0 -70
  64. package/dist/skills/workflow-auditor/scripts/audit-ledger.py +0 -624
  65. package/dist/skills/workflow-auditor/scripts/list-zed-commands.py +0 -183
  66. package/dist/skills/workflow-auditor/scripts/render-workflow.py +0 -201
  67. package/dist/skills/workflow-auditor/scripts/validate-skills.py +0 -444
  68. package/dist/skills/workflow-auditor/tests/audit-ledger.test.sh +0 -660
  69. package/dist/skills/workflow-auditor/tests/list-zed-commands.test.sh +0 -93
  70. package/dist/skills/workflow-auditor/tests/render-workflow.test.sh +0 -135
  71. package/dist/skills/workflow-auditor/tests/validate-skills.test.sh +0 -190
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Accuracy ratchet for triage-question.py over a labelled corpus of agent drafts (#54).
3
- # Labels are the correct routing per the workflow diagram; misses are expected and
4
- # listed. Raise MIN_ACCURACY when the classifier improves; never lower it.
5
- set -eu
6
- cd -- "${BASH_SOURCE[0]%/*}/.."
7
- PYTHON_BIN=$(command -v python3 || command -v python)
8
- MIN_ACCURACY=${MIN_ACCURACY_OVERRIDE:-0.96}
9
- "$PYTHON_BIN" -I -B - "$MIN_ACCURACY" <<'PY'
10
- import json, runpy, sys
11
- from pathlib import Path
12
-
13
- minimum = float(sys.argv[1])
14
- evaluate = runpy.run_path('scripts/triage-question.py')['evaluate_text']
15
- corpus = json.loads(Path('tests/fixtures/question-corpus.json').read_text(encoding='utf-8'))['items']
16
- assert len(corpus) >= 50, f'corpus too small: {len(corpus)}'
17
- hits, misses = 0, []
18
- for item in corpus:
19
- report = evaluate(item['text'])
20
- got = (report['verdict'], sorted(g['role'] for g in report['human_gates']), sorted(report['resolved_by']))
21
- want = (item['verdict'], sorted(item['owners']), sorted(item['skills']))
22
- if got == want:
23
- hits += 1
24
- else:
25
- misses.append(f' {item["text"].splitlines()[-6] if "BOSS GATE" in item["text"] else item["text"]!r}\n'
26
- f' got {got}\n want {want}')
27
- accuracy = hits / len(corpus)
28
- print(f'question-corpus: {hits}/{len(corpus)} correct ({accuracy:.1%}); minimum {minimum:.0%}')
29
- if misses:
30
- print('misses (backlog for the classifier):\n' + '\n'.join(misses))
31
- sys.exit(0 if accuracy >= minimum else 1)
32
- PY
@@ -1,441 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -eu
3
- cd -- "${BASH_SOURCE[0]%/*}/.."
4
- PYTHON_BIN=$(command -v python3 || command -v python)
5
- "$PYTHON_BIN" -I -B - <<'PY'
6
- import contextlib
7
- import io
8
- import json
9
- import os
10
- from pathlib import Path
11
- import runpy
12
- import subprocess
13
- import sys
14
- import tempfile
15
-
16
- entry = Path('scripts/triage-question.py').resolve()
17
- if not entry.is_file():
18
- sys.exit('triage-question.py is missing')
19
- main = runpy.run_path(str(entry))['main']
20
- scratch = Path(tempfile.mkdtemp())
21
- checks = 0
22
- failures = []
23
-
24
-
25
- def run_cli(argv, stdin_text=None):
26
- out = io.StringIO()
27
- old_stdin = sys.stdin
28
- try:
29
- if stdin_text is not None:
30
- sys.stdin = io.StringIO(stdin_text)
31
- with contextlib.redirect_stdout(out):
32
- code = main(argv)
33
- finally:
34
- sys.stdin = old_stdin
35
- return code, json.loads(out.getvalue())
36
-
37
-
38
- def expect(label, argv, expected_code, expected_verdict, expected_skills=None, stdin_text=None):
39
- global checks
40
- checks += 1
41
- code, report = run_cli(argv, stdin_text=stdin_text)
42
- if code != expected_code or report.get('verdict') != expected_verdict:
43
- failures.append(
44
- f'{label}: expected ({expected_code}, {expected_verdict}), got ({code}, {report.get("verdict")}) -> {report}'
45
- )
46
- return report
47
- if expected_skills is not None and report.get('resolved_by') != expected_skills:
48
- failures.append(
49
- f'{label}: expected resolved_by {expected_skills}, got {report.get("resolved_by")}'
50
- )
51
- return report
52
-
53
-
54
- # 1. Exact user scenario without ledger: blocks "probarlo primero en local" via regression-testing,
55
- # while keeping only the isolated commit/PR approval as a human gate.
56
- rep = expect(
57
- 'compound commit + local test question without ledger',
58
- [
59
- '--no-ledger',
60
- '--question',
61
- '¿Quieres que haga el commit, cree la issue y abra el PR en el repositorio o prefieres probarlo primero en local?',
62
- ],
63
- 1,
64
- 'block_question',
65
- ['regression-testing'],
66
- )
67
- if len(rep.get('human_gates', [])) != 1 or rep['human_gates'][0]['stage'] != 'commit_pr':
68
- failures.append(f'compound question should isolate commit_pr human gate, got {rep.get("human_gates")}')
69
-
70
- # 2. Same question when ledger already authorizes commit_pr and verify+quality are done -> do not ask at all.
71
- authorized_ledger = scratch / 'authorized.json'
72
- authorized_ledger.write_text(json.dumps({
73
- 'version': 1,
74
- 'kind': 'change',
75
- 'authorizations': [{'id': 'AUTH-1', 'by': 'person', 'role': 'Tech Lead', 'covers': ['implement', 'commit_pr']}],
76
- 'stages': [
77
- {'stage': 'specify', 'status': 'done'},
78
- {'stage': 'reproduce', 'status': 'done'},
79
- {'stage': 'implement', 'status': 'done', 'authorization': 'AUTH-1'},
80
- {'stage': 'verify', 'status': 'done'},
81
- {'stage': 'quality', 'status': 'done'},
82
- ],
83
- }), encoding='utf-8')
84
- rep_auth = expect(
85
- 'compound question with authorized commit_pr ledger',
86
- [
87
- '--ledger', str(authorized_ledger),
88
- '--question',
89
- '¿Quieres que haga el commit, cree la issue y abra el PR en el repositorio o prefieres probarlo primero en local?',
90
- ],
91
- 1,
92
- 'block_question',
93
- ['delivery-coordinator', 'regression-testing'],
94
- )
95
- if rep_auth.get('human_gates'):
96
- failures.append(f'authorized ledger should leave zero human_gates, got {rep_auth.get("human_gates")}')
97
-
98
- # 3. English compound commit + local testing question
99
- expect(
100
- 'english compound commit + local test question',
101
- [
102
- '--no-ledger',
103
- '--question',
104
- 'Should I commit and open the PR or would you prefer to test locally first?',
105
- ],
106
- 1,
107
- 'block_question',
108
- ['regression-testing'],
109
- )
110
-
111
- # 3b. Missing prerequisites in ledger block commit/PR question before asking
112
- missing_prereqs_ledger = scratch / 'missing-prereqs.json'
113
- missing_prereqs_ledger.write_text(json.dumps({
114
- 'version': 1,
115
- 'kind': 'change',
116
- 'authorizations': [],
117
- 'stages': [
118
- {'stage': 'specify', 'status': 'done'},
119
- {'stage': 'reproduce', 'status': 'done'},
120
- {'stage': 'implement', 'status': 'done'},
121
- ],
122
- }), encoding='utf-8')
123
- expect(
124
- 'commit question blocked when verify/quality missing in ledger',
125
- ['--ledger', str(missing_prereqs_ledger), '--question', '¿Quieres que haga el commit y abra el PR?'],
126
- 1,
127
- 'block_question',
128
- ['regression-testing'],
129
- )
130
- expect(
131
- 'do you want to test it first routed to QA',
132
- ['--no-ledger', '--question', '¿Prefieres que lo pruebes tú primero?'],
133
- 1,
134
- 'block_question',
135
- ['regression-testing'],
136
- )
137
-
138
- # 4. Delegable single-skill questions across the diagram
139
- expect('lint/quality question', ['--no-ledger', '--question', '¿Quieres que ejecute el typecheck y lint?'], 1, 'block_question', ['code-quality-gate'])
140
- expect('docs audit question', ['--no-ledger', '--question', '¿Quieres que revise si la documentación fue afectada?'], 1, 'block_question', ['documentation-steward'])
141
- expect('risk scout question', ['--no-ledger', '--question', '¿Analizo qué puede fallar en producción?'], 1, 'block_question', ['risk-scout'])
142
- expect('greptile question', ['--no-ledger', '--question', '¿Reviso los comentarios de Greptile en el PR?'], 1, 'block_question', ['greptile-review-loop'])
143
- expect('workflow audit question', ['--no-ledger', '--question', '¿Quieres que audite si el ledger cumple el diagrama?'], 1, 'block_question', ['workflow-auditor'])
144
- expect('next step question', ['--no-ledger', '--question', '¿Qué hacemos ahora?'], 1, 'block_question', ['delivery-coordinator'])
145
-
146
- # 5. Pure genuine human gates are allowed (exit 0)
147
- expect('code owner merge gate', ['--no-ledger', '--question', '¿Quieres que haga merge del PR #50?'], 0, 'allow_question', [])
148
- expect('release owner deploy gate', ['--no-ledger', '--question', '¿Quieres desplegar a producción ahora?'], 0, 'allow_question', [])
149
- expect('product open decision', ['--no-ledger', '--question', '¿Prefieres abrir el enlace en nueva pestaña o en la misma pestaña?'], 0, 'allow_question', [])
150
-
151
- # 6. Hook formats & non-question assistant messages
152
- checks += 1
153
- code, cursor_payload = run_cli(
154
- ['--no-ledger', '--stdin', '--format', 'cursor-hook'],
155
- stdin_text=json.dumps({'last_assistant_message': '¿Prefieres probarlo primero en local?'}),
156
- )
157
- if code != 0 or 'followup_message' not in cursor_payload:
158
- failures.append(f'cursor-hook should emit followup_message, got {(code, cursor_payload)}')
159
-
160
- # 6b. Cursor native stop payload reading transcript_path + loop_count / aborted guards
161
- transcript = scratch / 'cursor-transcript.jsonl'
162
- transcript.write_text(
163
- json.dumps({'role': 'user', 'message': {'content': [{'type': 'text', 'text': 'Fix it'}]}}) + '\n'
164
- + json.dumps({'role': 'assistant', 'message': {'content': [{'type': 'text', 'text': 'Listo, ¿quieres que haga el commit y abra el PR o prefieres probarlo primero en local?'}]}}) + '\n',
165
- encoding='utf-8',
166
- )
167
- checks += 1
168
- code, cursor_tx = run_cli(
169
- ['--no-ledger', '--stdin', '--format', 'cursor-hook'],
170
- stdin_text=json.dumps({'status': 'completed', 'loop_count': 0, 'transcript_path': str(transcript)}),
171
- )
172
- if code != 0 or 'followup_message' not in cursor_tx:
173
- failures.append(f'cursor-hook should read transcript_path and emit followup_message, got {(code, cursor_tx)}')
174
-
175
- checks += 1
176
- code, cursor_aborted = run_cli(
177
- ['--no-ledger', '--stdin', '--format', 'cursor-hook'],
178
- stdin_text=json.dumps({'status': 'aborted', 'loop_count': 0, 'transcript_path': str(transcript)}),
179
- )
180
- if code != 0 or cursor_aborted != {}:
181
- failures.append(f'cursor-hook aborted turn must not trigger followup, got {(code, cursor_aborted)}')
182
-
183
- checks += 1
184
- code, cursor_looped = run_cli(
185
- ['--no-ledger', '--stdin', '--format', 'cursor-hook'],
186
- stdin_text=json.dumps({'status': 'completed', 'loop_count': 2, 'transcript_path': str(transcript)}),
187
- )
188
- if code != 0 or cursor_looped != {}:
189
- failures.append(f'cursor-hook loop_count >= 2 must stop cleanly, got {(code, cursor_looped)}')
190
-
191
- checks += 1
192
- code, claude_payload = run_cli(
193
- ['--no-ledger', '--stdin', '--format', 'claude-hook'],
194
- stdin_text=json.dumps({'last_assistant_message': 'Should I run tests locally first?', 'stop_hook_active': False}),
195
- )
196
- if code != 0 or claude_payload.get('decision') != 'block':
197
- failures.append(f'claude-hook should emit decision=block, got {(code, claude_payload)}')
198
-
199
- checks += 1
200
- code, claude_loop = run_cli(
201
- ['--no-ledger', '--stdin', '--format', 'claude-hook'],
202
- stdin_text=json.dumps({'last_assistant_message': 'Should I run tests locally first?', 'stop_hook_active': True}),
203
- )
204
- if code != 0 or claude_loop != {}:
205
- failures.append(f'claude-hook with stop_hook_active=true must allow stop, got {(code, claude_loop)}')
206
-
207
- checks += 1
208
- code, codex_payload = run_cli(
209
- ['--no-ledger', '--stdin', '--format', 'codex-hook'],
210
- stdin_text=json.dumps({'last_assistant_message': '¿Quieres que ejecute lint?', 'stop_hook_active': False}),
211
- )
212
- if code != 0 or codex_payload.get('decision') != 'block':
213
- failures.append(f'codex-hook should emit decision=block, got {(code, codex_payload)}')
214
-
215
- checks += 1
216
- code, gemini_payload = run_cli(
217
- ['--no-ledger', '--stdin', '--format', 'gemini-hook'],
218
- stdin_text=json.dumps({'prompt_response': '¿Prefieres probarlo primero en local?', 'stop_hook_active': False}),
219
- )
220
- if code != 0 or gemini_payload.get('decision') != 'deny':
221
- failures.append(f'gemini-hook should emit decision=deny, got {(code, gemini_payload)}')
222
-
223
- expect(
224
- 'non-question message passes cleanly',
225
- ['--no-ledger', '--stdin'],
226
- 0,
227
- 'no_question',
228
- [],
229
- stdin_text=json.dumps({'last_assistant_message': 'Listo, PR #50 abierto y Greptile 5/5.'}),
230
- )
231
-
232
- # 6c. HUD / Boss Gate format enforcement in hook modes and --require-hud
233
- checks += 1
234
- code, unformatted_human = run_cli(
235
- ['--no-ledger', '--stdin', '--format', 'cursor-hook'],
236
- stdin_text=json.dumps({'last_assistant_message': '¿Quieres que haga merge del PR #50?'}),
237
- )
238
- if code != 0 or 'BOSS GATE' not in unformatted_human.get('followup_message', ''):
239
- failures.append(f'cursor-hook should block unformatted human gate, got {(code, unformatted_human)}')
240
-
241
- checks += 1
242
- code, unformatted_offer = run_cli(
243
- ['--no-ledger', '--stdin', '--format', 'cursor-hook'],
244
- stdin_text=json.dumps({
245
- 'last_assistant_message': 'Si quieres:\n1. La abro en Vista Previa.\n2. Genero otra captura sin recorte.',
246
- }),
247
- )
248
- if code != 0 or 'BOSS GATE' not in unformatted_offer.get('followup_message', ''):
249
- failures.append(f'cursor-hook should block unformatted numbered choice offer, got {(code, unformatted_offer)}')
250
-
251
- checks += 1
252
- code, factual_list = run_cli(
253
- ['--no-ledger', '--stdin', '--format', 'cursor-hook'],
254
- stdin_text=json.dumps({
255
- 'last_assistant_message': 'Resumen aplicado:\n1. Se actualizó el título.\n2. Se conservó el adjunto original.',
256
- }),
257
- )
258
- if code != 0 or factual_list != {}:
259
- failures.append(f'cursor-hook must allow factual numbered list without offer cue, got {(code, factual_list)}')
260
-
261
- formatted_boss_gate = (
262
- '🎮 QUEST ACTUAL ─ Revisar Issue #746\n'
263
- '│ 📍 Checkpoint: Borrador listo\n\n'
264
- '🟡 BOSS GATE ─ Product Manager\n'
265
- '│\n'
266
- '├── ❓ ¿Aplico este título y descripción en el issue #746?\n'
267
- '├── 👉 Recomendado: [A]\n'
268
- '│ └── Conserva los adjuntos originales\n'
269
- '└── ⚡ Opciones\n'
270
- ' ├── [A] Actualizar issue #746\n'
271
- ' └── [B] Ajustar borrador'
272
- )
273
- checks += 1
274
- code, formatted_cursor = run_cli(
275
- ['--no-ledger', '--stdin', '--format', 'cursor-hook'],
276
- stdin_text=json.dumps({'last_assistant_message': formatted_boss_gate}),
277
- )
278
- if code != 0 or formatted_cursor != {}:
279
- failures.append(f'cursor-hook should allow formatted Boss Gate, got {(code, formatted_cursor)}')
280
-
281
- checks += 1
282
- code, unformatted_claude = run_cli(
283
- ['--no-ledger', '--stdin', '--format', 'claude-hook'],
284
- stdin_text=json.dumps({'last_assistant_message': '¿Quieres desplegar a producción ahora?', 'stop_hook_active': False}),
285
- )
286
- if code != 0 or unformatted_claude.get('decision') != 'block':
287
- failures.append(f'claude-hook should block unformatted human gate, got {(code, unformatted_claude)}')
288
-
289
- expect(
290
- '--require-hud blocks unformatted human gate in json mode',
291
- ['--no-ledger', '--require-hud', '--question', '¿Quieres que haga merge del PR #50?'],
292
- 1,
293
- 'block_format',
294
- [],
295
- )
296
-
297
- expect(
298
- '--require-hud allows formatted Boss Gate in json mode',
299
- ['--no-ledger', '--require-hud', '--question', formatted_boss_gate],
300
- 0,
301
- 'allow_question',
302
- [],
303
- )
304
-
305
- # 7. Unusable input returns exit 2
306
- bad_ledger = scratch / 'bad.json'
307
- bad_ledger.write_text('{bad', encoding='utf-8')
308
- expect(
309
- 'invalid ledger returns unusable',
310
- ['--ledger', str(bad_ledger), '--question', '¿Merge?'],
311
- 2,
312
- 'unusable',
313
- )
314
-
315
- # 8. Incomplete ledger with verify/quality BEFORE any implement still blocks commit_pr
316
- no_impl_ledger = scratch / 'no-impl.json'
317
- no_impl_ledger.write_text(json.dumps({
318
- 'version': 1,
319
- 'authorizations': [{'id': 'AUTH-1', 'by': 'person', 'covers': ['commit_pr']}],
320
- 'stages': [
321
- {'stage': 'verify', 'status': 'done'},
322
- {'stage': 'quality', 'status': 'done'},
323
- ],
324
- }), encoding='utf-8')
325
- expect(
326
- 'ledger without implement never treats verify/quality as post-implement',
327
- ['--ledger', str(no_impl_ledger), '--question', '¿Abro el PR?'],
328
- 1,
329
- 'block_question',
330
- ['regression-testing'],
331
- )
332
-
333
- # 9. Malformed JSON on stdin returns unusable (exit 2)
334
- expect(
335
- 'malformed stdin JSON returns unusable',
336
- ['--no-ledger', '--stdin'],
337
- 2,
338
- 'unusable',
339
- stdin_text='{not-valid-json',
340
- )
341
-
342
- # 10. Loose [A] and [B] without BOSS GATE card fails hud_format_ok
343
- expect(
344
- 'loose [A] and [B] without BOSS GATE triggers block_format',
345
- ['--no-ledger', '--require-hud', '--question', 'Si quieres:\n[A] Seguir\n[B] Parar'],
346
- 1,
347
- 'block_format',
348
- [],
349
- )
350
-
351
- # 11. Spanish first-person verbs (#42): delegable clauses must not fall to "Human decision".
352
- expect('es: corro las pruebas', ['--no-ledger', '--question', '¿Corro las pruebas antes de seguir?'],
353
- 1, 'block_question', ['regression-testing'])
354
- expect('es: ejecuto los tests', ['--no-ledger', '--question', '¿Ejecuto los tests ahora?'],
355
- 1, 'block_question', ['regression-testing'])
356
- expect('es: lanzo el build', ['--no-ledger', '--question', '¿Lanzo el build para verificar?'],
357
- 1, 'block_question', ['regression-testing'])
358
- expect('es: reviso la documentacion', ['--no-ledger', '--question', '¿Reviso la documentación afectada?'],
359
- 1, 'block_question', ['documentation-steward'])
360
-
361
-
362
- def expect_owners(label, question, owners):
363
- global checks
364
- checks += 1
365
- _, report = run_cli(['--no-ledger', '--question', question])
366
- got = sorted({gate.get('role') for gate in report.get('human_gates', [])})
367
- if report.get('verdict') != 'allow_question' or got != sorted(owners):
368
- failures.append(f'{label}: expected allow_question with owners {owners}, got {report.get("verdict")} {got}')
369
-
370
-
371
- # #54 lifted the one-owner-per-clause limitation: both human owners are kept.
372
- expect_owners('es: hago merge y despliego', '¿Hago merge a main y despliego a producción?', ['Code Owner', 'Release Owner'])
373
- expect_owners('es: despliego', '¿Despliego a producción?', ['Release Owner'])
374
- expect_owners('es: mergeo el pr', '¿Mergeo el PR #12?', ['Code Owner'])
375
-
376
- # 12. #54 part 1: a clause joined by "y"/"and" is split when every part is
377
- # recognised and the parts have different owners.
378
- def expect_gates(label, question, verdict, owners, skills=()):
379
- global checks
380
- checks += 1
381
- _, report = run_cli(['--no-ledger', '--question', question])
382
- got_owners = sorted(g['role'] for g in report.get('human_gates', []))
383
- got_skills = sorted(report.get('resolved_by', []))
384
- if report.get('verdict') != verdict or got_owners != sorted(owners) or got_skills != sorted(skills):
385
- failures.append(f'{label}: got {report.get("verdict")} owners={got_owners} skills={got_skills}; '
386
- f'want {verdict} owners={sorted(owners)} skills={sorted(skills)}')
387
-
388
-
389
- expect_gates('two owners: merge and deploy (es)', '¿Hago merge a main y despliego a producción?',
390
- 'allow_question', ['Code Owner', 'Release Owner'])
391
- expect_gates('two owners: merge and deploy (en)', 'Should I merge the PR and deploy to production?',
392
- 'allow_question', ['Code Owner', 'Release Owner'])
393
- # Before the fix the delegable docs clause swallowed the whole sentence, and the
394
- # Code Owner decision disappeared.
395
- expect_gates('human gate kept next to a delegable part', '¿Hago merge del PR y reviso la documentación?',
396
- 'block_question', ['Code Owner'], ['documentation-steward'])
397
- # Same owner on both sides: one gate, unchanged.
398
- expect_gates('same owner stays one clause', '¿Haga el commit, cree la issue y abra el PR?',
399
- 'allow_question', ['Tech Lead / Commit & PR authorization'])
400
-
401
- # 13. #54 part 2: an unrecognised clause is not a human gate by default. It is
402
- # blocked until the draft declares its owner with a valid BOSS GATE role
403
- # (hud-output.md: PM | Tech Lead | Commit & PR | Code Owner | Release Owner),
404
- # so a hook can never loop: the agent always has a legitimate way to ask.
405
- expect_gates('unrecognised clause is blocked', '¿Reescribo el módulo de pagos?', 'block_question', [])
406
- checks += 1
407
- _, report = run_cli(['--no-ledger', '--question', '¿Reescribo el módulo de pagos?'])
408
- if 'BOSS GATE' not in (report.get('rewrite_suggestion') or '') or \
409
- report['clauses'][0]['disposition'] != 'needs_classification':
410
- failures.append(f'unrecognised clause: needs a BOSS GATE hint and needs_classification -> {report}')
411
- declared = ('🟡 BOSS GATE ─ Tech Lead\n❓ ¿Reescribo el módulo de pagos?\n'
412
- '👉 Recomendado: [A]\n⚡ Opciones\n[A] Sí, en una rama\n[B] No')
413
- expect_gates('declared owner is allowed', declared, 'allow_question', ['Tech Lead'])
414
- expect_gates('declared PM alias', declared.replace('Tech Lead', 'PM'), 'allow_question', ['Product Manager'])
415
- expect_gates('invented role stays blocked', declared.replace('Tech Lead', 'Wizard'), 'block_question', [])
416
- # Recognised human rules need no declaration.
417
- expect_gates('known human rule still allowed', '¿Quieres desplegar a producción ahora?', 'allow_question', ['Release Owner'])
418
- checks += 1
419
- code, hook = run_cli(['--stdin', '--format', 'claude-hook'],
420
- stdin_text=json.dumps({'last_assistant_message': '¿Reescribo el módulo de pagos?'}))
421
- if hook.get('decision') != 'block' or 'BOSS GATE' not in hook.get('reason', ''):
422
- failures.append(f'claude-hook unrecognised clause: {code} {hook}')
423
-
424
- # 14. A console code page such as Windows cp1252 cannot encode the 🟡 marker; the
425
- # CLI must still print its verdict instead of crashing with UnicodeEncodeError.
426
- checks += 1
427
- result = subprocess.run([sys.executable, '-B', str(entry), '--no-ledger', '--question', declared],
428
- capture_output=True, env=dict(os.environ, PYTHONIOENCODING='cp1252'))
429
- try:
430
- verdict = json.loads(result.stdout.decode('utf-8'))['verdict']
431
- except ValueError:
432
- verdict = None
433
- if result.returncode != 0 or verdict != 'allow_question':
434
- failures.append(f'non-UTF-8 stdout: exit {result.returncode}, verdict {verdict}, stderr {result.stderr[-200:]!r}')
435
-
436
- for failure in failures:
437
- print('FAIL ' + failure, file=sys.stderr)
438
- if failures:
439
- sys.exit(1)
440
- print('PASS ' + str(checks) + ' checks')
441
- PY