@bbcsoftwarefactory/skills 0.1.0 → 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,221 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- cd -- "${BASH_SOURCE[0]%/*}/.."
4
-
5
- SCRIPT="$PWD/scripts/check-issue-claim.py"
6
- PYTHON_BIN=$(command -v python3 || command -v python)
7
- "$PYTHON_BIN" -I -B - "$SCRIPT" <<'PY'
8
- import json
9
- from pathlib import Path
10
- import subprocess
11
- import sys
12
- import tempfile
13
-
14
- script = Path(sys.argv[1]).resolve()
15
- if not script.is_file():
16
- sys.exit('FAIL: missing script ' + str(script))
17
-
18
- scratch = Path(tempfile.mkdtemp())
19
- checks = 0
20
- failures = []
21
- NOW = '2026-11-30T12:00:00Z'
22
-
23
-
24
- def issue(state='open', assignees=(), labels=(), updated='2026-11-29T12:00:00Z', number=12, author='carla'):
25
- return {'number': number, 'state': state, 'user': {'login': author},
26
- 'assignees': [{'login': a} for a in assignees],
27
- 'labels': [{'name': name} for name in labels], 'updated_at': updated}
28
-
29
-
30
- def pull(number, author, head, body=''):
31
- return {'number': number, 'user': {'login': author}, 'head': {'ref': head}, 'title': 'Change', 'body': body}
32
-
33
-
34
- def assigned(login, at, event='assigned'):
35
- return {'event': event, 'assignee': {'login': login}, 'created_at': at}
36
-
37
-
38
- def labeled(actor, at, event='labeled', name='status:in-progress'):
39
- return {'event': event, 'label': {'name': name}, 'actor': {'login': actor}, 'created_at': at}
40
-
41
-
42
- def write(name, value):
43
- path = scratch / name
44
- path.write_text(value if isinstance(value, str) else json.dumps(value), encoding='utf-8')
45
- return str(path)
46
-
47
-
48
- def run(phase, issue_data, pulls=(), branches=(), events=None, claimant='ana', branch='feat/12-retry-dedup',
49
- extra=()):
50
- args = ['--phase', phase, '--issue-json', write('issue.json', issue_data), '--now', NOW]
51
- if phase != 'release':
52
- args += ['--pulls-json', write('pulls.json', list(pulls)),
53
- '--branches', write('branches.txt', ''.join('a' * 40 + '\trefs/heads/' + b + '\n' for b in branches))]
54
- if events is not None:
55
- args += ['--events-json', write('events.json', events)]
56
- if claimant is not None:
57
- args += ['--claimant', claimant]
58
- if branch is not None and phase in ('check', 'verify'):
59
- args += ['--branch', branch]
60
- result = subprocess.run([sys.executable, '-I', '-B', str(script), *args, *extra],
61
- capture_output=True, text=True, encoding='utf-8')
62
- try:
63
- report = json.loads(result.stdout)
64
- except ValueError:
65
- report = {'verdict': None, 'raw': result.stdout + result.stderr}
66
- return result.returncode, report
67
-
68
-
69
- def expect(label, observed, status, verdict, rules=()):
70
- global checks
71
- checks += 1
72
- code, report = observed
73
- got = (code, report.get('verdict'), sorted({f['rule'] for f in report.get('findings', [])}))
74
- want = (status, verdict, sorted(rules))
75
- if got != want:
76
- failures.append(label + ': expected ' + repr(want) + ', observed ' + repr(got) + ' ' + json.dumps(report))
77
-
78
-
79
- # check: decide before claiming
80
- expect('free issue', run('check', issue()), 0, 'free')
81
- expect('already assigned to the claimant', run('check', issue(assignees=['Ana'])), 0, 'claimed-by-you')
82
- expect('assigned to someone else (CL3)', run('check', issue(assignees=['bob'])), 1, 'claimed-by-other', ['CL3'])
83
- expect('open PR by someone else that closes the issue (CL4)',
84
- run('check', issue(), pulls=[pull(13, 'bob', 'fix/retry', 'Fixes #12')]), 1, 'claimed-by-other', ['CL4'])
85
- expect('a reference to #123 is not #12', run('check', issue(), pulls=[pull(13, 'bob', 'fix/x', 'Refs #123')]),
86
- 0, 'free')
87
- expect('a reference to another repository is not this issue',
88
- run('check', issue(), pulls=[pull(13, 'bob', 'fix/x', 'Closes other/repo#12')], extra=['--repo', 'example/repo']),
89
- 0, 'free')
90
- expect('a same-repository reference counts',
91
- run('check', issue(), pulls=[pull(13, 'bob', 'fix/x', 'Closes Example/Repo#12')], extra=['--repo', 'example/repo']),
92
- 1, 'claimed-by-other', ['CL4'])
93
- expect('an issue URL counts',
94
- run('check', issue(), pulls=[pull(13, 'bob', 'fix/x', 'See https://github.com/example/repo/issues/12')]),
95
- 1, 'claimed-by-other', ['CL4'])
96
- expect('a feat/<n>- head counts without a body reference',
97
- run('check', issue(), pulls=[pull(13, 'bob', 'feat/12-other-fix')]), 1, 'claimed-by-other', ['CL4'])
98
- expect('the claimant own PR means it is already yours',
99
- run('check', issue(), pulls=[pull(13, 'ana', 'feat/12-retry-dedup', 'Closes #12')]), 0, 'claimed-by-you')
100
- expect('another remote feat/<n>- branch (CL5)', run('check', issue(), branches=['feat/12-other']),
101
- 1, 'claimed-by-other', ['CL5'])
102
- expect('the claimant own remote branch is not a conflict', run('check', issue(), branches=['feat/12-retry-dedup']),
103
- 0, 'free')
104
- expect('feat/120- is not feat/12-', run('check', issue(), branches=['feat/120-other']), 0, 'free')
105
- expect('label without assignee is an orphan claim (CL6)', run('check', issue(labels=['status:in-progress'])),
106
- 1, 'orphan-claim', ['CL6'])
107
- expect('a custom claim label is honoured',
108
- run('check', issue(labels=['wip']), extra=['--label', 'wip']), 1, 'orphan-claim', ['CL6'])
109
- expect('closed issue (CL2)', run('check', issue(state='closed')), 1, 'closed', ['CL2'])
110
- expect('gh --json shape: upper-case state is closed', run('check', issue(state='CLOSED')), 1, 'closed', ['CL2'])
111
- expect('branch for another issue (CL7)', run('check', issue(), branch='feat/13-retry'), 1, 'invalid-branch', ['CL7'])
112
- expect('branch without issue number (CL7)', run('check', issue(), branch='feat/retry'), 1, 'invalid-branch', ['CL7'])
113
- expect('worst verdict wins and every rule is reported',
114
- run('check', issue(state='closed', assignees=['bob']), branch='feat/retry'),
115
- 1, 'closed', ['CL2', 'CL3', 'CL7'])
116
-
117
- # gh pr list --json shape (author.login, headRefName) and gh api --paginate --slurp pages
118
- gh_shape = [[{'number': 13, 'author': {'login': 'bob'}, 'headRefName': 'feat/12-x', 'title': 't', 'body': None}]]
119
- expect('gh --json and slurped pages', run('check', issue(), pulls=gh_shape), 1, 'claimed-by-other', ['CL4'])
120
-
121
- # verify: recheck right after claiming
122
- claimed = issue(assignees=['ana'], labels=['status:in-progress'])
123
- expect('claim recorded', run('verify', claimed), 0, 'claimed-by-you')
124
- expect('label missing after claiming (CL8)', run('verify', issue(assignees=['ana'])), 1, 'unrecorded-claim', ['CL8'])
125
- expect('assignee missing after claiming (CL8)', run('verify', issue(labels=['status:in-progress'])),
126
- 1, 'unrecorded-claim', ['CL8'])
127
- race = issue(assignees=['bob', 'ana'], labels=['status:in-progress'])
128
- expect('race won: earliest current assignment', run('verify', race, events=[
129
- assigned('ana', '2026-11-30T11:00:00Z'), assigned('bob', '2026-11-30T11:00:05Z')]), 0, 'claimed-by-you')
130
- expect('race lost (CL9)', run('verify', race, events=[
131
- assigned('bob', '2026-11-30T11:00:00Z'), assigned('ana', '2026-11-30T11:00:05Z')]), 1, 'contended-lost', ['CL9'])
132
- expect('an earlier assignment that was removed does not count', run('verify', race, events=[[
133
- assigned('ana', '2026-11-30T10:00:00Z'), assigned('ana', '2026-11-30T10:30:00Z', 'unassigned'),
134
- assigned('bob', '2026-11-30T11:00:00Z'), assigned('ana', '2026-11-30T11:00:05Z')]]), 1, 'contended-lost', ['CL9'])
135
- expect('race without events is unusable (CL1)', run('verify', race), 2, 'unusable', ['CL1'])
136
- expect('a PR by someone else appeared meanwhile', run('verify', claimed, pulls=[pull(14, 'bob', 'x', 'Closes #12')]),
137
- 1, 'claimed-by-other', ['CL4'])
138
-
139
- # release: give the issue back
140
- expect('released', run('release', issue()), 0, 'released')
141
- expect('still assigned (CL10)', run('release', issue(assignees=['ana'])), 1, 'still-held', ['CL10'])
142
- expect('label left behind (CL10)', run('release', issue(labels=['status:in-progress'])),
143
- 1, 'still-held', ['CL10'])
144
- expect('label belongs to the remaining assignee',
145
- run('release', issue(assignees=['bob'], labels=['status:in-progress'])), 0, 'released')
146
-
147
- # status: /daily, no claimant
148
- expect('unclaimed issue', run('status', issue(), claimant=None), 0, 'unclaimed')
149
- expect('active claim', run('status', claimed, pulls=[pull(13, 'ana', 'feat/12-x', 'Closes #12')], claimant=None),
150
- 0, 'claimed')
151
- expect('two open PRs for one issue (CL11)', run('status', claimed, claimant=None, pulls=[
152
- pull(13, 'ana', 'feat/12-a', 'Closes #12'), pull(14, 'bob', 'feat/12-b', 'Fixes #12')]),
153
- 1, 'duplicate-work', ['CL11'])
154
- stale = issue(assignees=['ana'], labels=['status:in-progress'], updated='2026-11-20T12:00:00Z')
155
- expect('stale claim (CL12)', run('status', stale, claimant=None), 1, 'stale-claim', ['CL12'])
156
- expect('a pushed branch keeps a claim alive', run('status', stale, branches=['feat/12-x'], claimant=None), 0, 'claimed')
157
- expect('stale window is configurable', run('status', stale, claimant=None, extra=['--stale-days', '14']), 0, 'claimed')
158
- expect('orphan label in status (CL6)', run('status', issue(labels=['status:in-progress']), claimant=None),
159
- 1, 'orphan-claim', ['CL6'])
160
-
161
- # reporter: issue-reviewer assigns the issue author; that is not a claim until the author adds the label
162
- triaged = issue(assignees=['carla'])
163
- expect('the author assigned by triage does not hold the issue', run('check', triaged), 0, 'free')
164
- expect('the author with the claim label holds it (CL3)',
165
- run('check', issue(assignees=['carla'], labels=['status:in-progress'])), 1, 'claimed-by-other', ['CL3'])
166
- expect('another assignee still holds it next to the author (CL3)',
167
- run('check', issue(assignees=['carla', 'bob'])), 1, 'claimed-by-other', ['CL3'])
168
- expect('gh --json author shape is honoured',
169
- run('check', {'number': 12, 'state': 'OPEN', 'author': {'login': 'carla'}, 'assignees': [{'login': 'carla'}],
170
- 'labels': []}), 0, 'free')
171
- claimed_next_to_author = issue(assignees=['carla', 'ana'], labels=['status:in-progress'])
172
- triage_then_claim = [assigned('carla', '2026-11-29T09:00:00Z'), assigned('ana', '2026-11-30T11:00:00Z'),
173
- labeled('ana', '2026-11-30T11:00:01Z')]
174
- expect('claim next to the triage assignment of the author',
175
- run('verify', claimed_next_to_author, events=triage_then_claim), 0, 'claimed-by-you')
176
- expect('the author claimed first by adding the label (CL9)', run('verify', claimed_next_to_author, events=[
177
- assigned('carla', '2026-11-29T09:00:00Z'), labeled('carla', '2026-11-30T11:00:00Z'),
178
- assigned('ana', '2026-11-30T11:00:02Z')]), 1, 'contended-lost', ['CL9'])
179
- expect('the author loses when someone else set the label', run('verify', claimed_next_to_author,
180
- events=triage_then_claim, claimant='carla'), 1, 'contended-lost', ['CL9'])
181
- expect('a removed label of the author no longer counts', run('verify', claimed_next_to_author, events=[
182
- assigned('carla', '2026-11-29T09:00:00Z'), labeled('carla', '2026-11-29T10:00:00Z'),
183
- labeled('carla', '2026-11-29T10:30:00Z', 'unlabeled'), assigned('ana', '2026-11-30T11:00:00Z'),
184
- labeled('ana', '2026-11-30T11:00:01Z')]), 0, 'claimed-by-you')
185
- stale_triage = issue(assignees=['carla'], updated='2026-11-01T12:00:00Z')
186
- expect('a triage assignment is not a stale claim', run('status', stale_triage, claimant=None), 0, 'unclaimed')
187
- expect('the author claim can go stale (CL12)', run('status', issue(
188
- assignees=['carla'], labels=['status:in-progress'], updated='2026-11-01T12:00:00Z'), claimant=None),
189
- 1, 'stale-claim', ['CL12'])
190
- expect('release removes the label left next to the triage assignment (CL10)',
191
- run('release', issue(assignees=['carla'], labels=['status:in-progress']), events=triage_then_claim),
192
- 1, 'still-held', ['CL10'])
193
- expect('release keeps the label the author set',
194
- run('release', issue(assignees=['carla'], labels=['status:in-progress']), events=[
195
- assigned('carla', '2026-11-29T09:00:00Z'), labeled('carla', '2026-11-30T11:00:00Z')]), 0, 'released')
196
- expect('release next to the author needs events (CL1)',
197
- run('release', issue(assignees=['carla'], labels=['status:in-progress'])), 2, 'unusable', ['CL1'])
198
- expect('a triage assignment alone is released', run('release', triaged), 0, 'released')
199
-
200
- # unusable input
201
- expect('claimant is required to claim', run('check', issue(), claimant=None), 2, 'unusable', ['CL1'])
202
- expect('branch is required to claim', run('check', issue(), branch=None), 2, 'unusable', ['CL1'])
203
- expect('issue JSON must be valid', run('check', '{'), 2, 'unusable', ['CL1'])
204
- expect('issue needs a state', run('check', {'number': 12}), 2, 'unusable', ['CL1'])
205
-
206
- checks += 1
207
- code, report = run('check', issue(assignees=['bob']))
208
- if report.get('holders', {}).get('assignees') != ['bob']:
209
- failures.append('holders must name who has the issue: ' + json.dumps(report))
210
-
211
- checks += 1
212
- result = subprocess.run([sys.executable, '-I', '-B', str(script), '--help'], capture_output=True, text=True)
213
- if result.returncode != 0 or 'Usage' not in result.stdout:
214
- failures.append('--help must print usage and exit 0')
215
-
216
- if failures:
217
- for item in failures:
218
- print('FAIL:', item, file=sys.stderr)
219
- sys.exit(1)
220
- print(f'PASS {checks} checks')
221
- PY
@@ -1,123 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- cd -- "${BASH_SOURCE[0]%/*}/.."
4
-
5
- SCRIPT="$PWD/scripts/check-worktree-guard.py"
6
- PYTHON_BIN=$(command -v python3 || command -v python)
7
- "$PYTHON_BIN" -I -B - "$SCRIPT" <<'PY'
8
- import json
9
- from pathlib import Path
10
- import subprocess
11
- import sys
12
- import tempfile
13
-
14
- script = Path(sys.argv[1]).resolve()
15
- if not script.is_file():
16
- sys.exit('FAIL: missing script ' + str(script))
17
-
18
- scratch = Path(tempfile.mkdtemp())
19
- checks = 0
20
- failures = []
21
-
22
-
23
- def run_cli(*args, cwd=None, stdin_text=None):
24
- return subprocess.run(
25
- [sys.executable, '-I', '-B', str(script), *args],
26
- cwd=str(cwd or scratch),
27
- input=stdin_text,
28
- capture_output=True,
29
- text=True,
30
- )
31
-
32
-
33
- def assert_eq(label, got, want):
34
- global checks
35
- checks += 1
36
- if got != want:
37
- failures.append(f'{label}: got {got!r}, want {want!r}')
38
-
39
-
40
- def assert_true(label, cond, detail=''):
41
- global checks
42
- checks += 1
43
- if not cond:
44
- failures.append(f'{label}: assertion failed ({detail})')
45
-
46
-
47
- # Setup primary repo on main + linked worktrees
48
- primary = scratch / 'primary'
49
- primary.mkdir()
50
- subprocess.run(['git', 'init', '-b', 'main', '-q', str(primary)], check=True)
51
- subprocess.run(['git', 'config', 'user.email', 'test@example.com'], cwd=primary, check=True)
52
- subprocess.run(['git', 'config', 'user.name', 'Test'], cwd=primary, check=True)
53
- (primary / 'README.md').write_text('# Repo\n', encoding='utf-8')
54
- subprocess.run(['git', 'add', 'README.md'], cwd=primary, check=True)
55
- subprocess.run(['git', 'commit', '-q', '-m', 'init'], cwd=primary, check=True)
56
-
57
- wt_feat = scratch / 'wt-feat'
58
- subprocess.run(['git', 'worktree', 'add', '-b', 'feat/sample-task', str(wt_feat)], cwd=primary, capture_output=True, check=True)
59
-
60
- wt_nonfeat = scratch / 'wt-nonfeat'
61
- subprocess.run(['git', 'worktree', 'add', '-b', 'chore/not-feat', str(wt_nonfeat)], cwd=primary, capture_output=True, check=True)
62
-
63
- # 1. Primary checkout on main must be blocked (exit 1)
64
- res = run_cli('--path', str(primary))
65
- assert_eq('primary main exit 1', res.returncode, 1)
66
- data = json.loads(res.stdout)
67
- assert_eq('primary main decision block', data['decision'], 'block')
68
- assert_eq('primary main branch', data['branch'], 'main')
69
-
70
- # 2. Primary checkout even on feat/ branch is still primary (not linked worktree) -> blocked
71
- subprocess.run(['git', 'checkout', '-q', '-b', 'feat/in-primary'], cwd=primary, check=True)
72
- res_prim_feat = run_cli('--path', str(primary))
73
- assert_eq('primary feat exit 1', res_prim_feat.returncode, 1)
74
- assert_eq('primary feat blocked', json.loads(res_prim_feat.stdout)['decision'], 'block')
75
- subprocess.run(['git', 'checkout', '-q', 'main'], cwd=primary, check=True)
76
-
77
- # 3. Linked worktree on non-feat branch -> blocked
78
- res_nonfeat = run_cli('--path', str(wt_nonfeat))
79
- assert_eq('linked non-feat exit 1', res_nonfeat.returncode, 1)
80
- assert_eq('linked non-feat blocked', json.loads(res_nonfeat.stdout)['decision'], 'block')
81
-
82
- # 4. Linked worktree on feat/<task> -> allowed (exit 0)
83
- res_ok = run_cli('--path', str(wt_feat))
84
- assert_eq('linked feat exit 0', res_ok.returncode, 0)
85
- data_ok = json.loads(res_ok.stdout)
86
- assert_eq('linked feat decision allow', data_ok['decision'], 'allow')
87
- assert_eq('linked feat is_linked_worktree', data_ok['is_linked_worktree'], True)
88
-
89
- # 5. Target file path inside primary checkout resolved even when cwd is linked worktree
90
- res_target_prim = run_cli('--target-path', str(primary / 'README.md'), cwd=wt_feat)
91
- assert_eq('target file inside primary blocked', res_target_prim.returncode, 1)
92
-
93
- # 6. Hook formats (--stdin --format claude-hook / cursor-hook)
94
- payload_prim = json.dumps({'tool_name': 'Edit', 'tool_input': {'file_path': str(primary / 'README.md')}})
95
- res_claude_block = run_cli('--stdin', '--format', 'claude-hook', cwd=primary, stdin_text=payload_prim)
96
- assert_eq('claude-hook block exit 0', res_claude_block.returncode, 0)
97
- hook_out = json.loads(res_claude_block.stdout)
98
- assert_eq('claude-hook decision block', hook_out['decision'], 'block')
99
- assert_true('claude-hook reason mentions worktree', 'worktree' in hook_out['reason'].lower(), hook_out)
100
-
101
- payload_ok = json.dumps({'tool_name': 'Edit', 'tool_input': {'file_path': str(wt_feat / 'README.md')}})
102
- res_claude_ok = run_cli('--stdin', '--format', 'claude-hook', cwd=wt_feat, stdin_text=payload_ok)
103
- assert_eq('claude-hook allow exit 0', res_claude_ok.returncode, 0)
104
- assert_eq('claude-hook allow empty json', json.loads(res_claude_ok.stdout), {})
105
-
106
- res_cursor_block = run_cli('--stdin', '--format', 'cursor-hook', cwd=primary, stdin_text=payload_prim)
107
- assert_eq('cursor-hook block exit 0', res_cursor_block.returncode, 0)
108
- cursor_out = json.loads(res_cursor_block.stdout)
109
- assert_true('cursor-hook sets followup_message or permission deny',
110
- 'followup_message' in cursor_out or cursor_out.get('permission') == 'deny', cursor_out)
111
-
112
- # 7. Non-git directory -> exit 2 (unusable)
113
- nongit = scratch / 'nongit'
114
- nongit.mkdir()
115
- res_ng = run_cli('--path', str(nongit))
116
- assert_eq('non-git exit 2', res_ng.returncode, 2)
117
-
118
- if failures:
119
- for item in failures:
120
- print('FAIL:', item, file=sys.stderr)
121
- sys.exit(1)
122
- print(f'PASS {checks} checks')
123
- PY
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- cd -- "${BASH_SOURCE[0]%/*}/.."
4
-
5
- SCRIPT="$PWD/scripts/classify-change-lane.py"
6
- PYTHON_BIN=$(command -v python3 || command -v python)
7
- "$PYTHON_BIN" -I -B - "$SCRIPT" <<'PY'
8
- import json
9
- from pathlib import Path
10
- import subprocess
11
- import sys
12
- import tempfile
13
-
14
- script = Path(sys.argv[1]).resolve()
15
- if not script.is_file():
16
- sys.exit('FAIL: missing script ' + str(script))
17
-
18
- scratch = Path(tempfile.mkdtemp())
19
- checks = 0
20
- failures = []
21
-
22
-
23
- def run_cli(*args, cwd=None):
24
- return subprocess.run(
25
- [sys.executable, '-I', '-B', str(script), *args],
26
- cwd=str(cwd or scratch),
27
- capture_output=True,
28
- text=True,
29
- )
30
-
31
-
32
- def assert_eq(label, got, want):
33
- global checks
34
- checks += 1
35
- if got != want:
36
- failures.append(f'{label}: got {got!r}, want {want!r}')
37
-
38
-
39
- def assert_true(label, cond, detail=''):
40
- global checks
41
- checks += 1
42
- if not cond:
43
- failures.append(f'{label}: assertion failed ({detail})')
44
-
45
-
46
- # 1. --files trivial (docs / markdown only)
47
- res = run_cli('--files', 'README.md', 'docs/commands.md')
48
- assert_eq('trivial exit', res.returncode, 0)
49
- data = json.loads(res.stdout)
50
- assert_eq('trivial lane', data['lane'], 'trivial')
51
- assert_eq('trivial files_changed', data['files_changed'], 2)
52
- assert_true('trivial skips risk-scout', 'risk-scout' in data['skipped_stages'], data)
53
- assert_true('trivial allows no-runnable-test', data['test_mode'] == 'proportional', data)
54
-
55
- # 2. --files standard (normal skill/app code)
56
- res = run_cli('--files', 'src/jobs/filter.ts', 'src/jobs/filter.test.ts')
57
- assert_eq('standard exit', res.returncode, 0)
58
- data = json.loads(res.stdout)
59
- assert_eq('standard lane', data['lane'], 'standard')
60
- assert_true('standard requires reproduce/verify', 'reproduce' in data['required_stages'] and 'verify' in data['required_stages'], data)
61
-
62
- # 3. --files high-risk (sensitive security/workflow/watcher/auth paths)
63
- for path in (
64
- 'skills/watcher-observability/scripts/watch-live.py',
65
- 'skills/tool-depot/references/tool-catalog.json',
66
- 'skills/workflow-auditor/scripts/audit-ledger.py',
67
- 'skills/question-gate/scripts/triage-question.py',
68
- '.github/workflows/suites.yml',
69
- 'src/auth/session-token.ts',
70
- 'prisma/migrations/001_init.sql',
71
- ):
72
- res = run_cli('--files', path)
73
- assert_eq(f'high-risk exit ({path})', res.returncode, 0)
74
- data = json.loads(res.stdout)
75
- assert_eq(f'high-risk lane ({path})', data['lane'], 'high-risk')
76
- assert_true(f'high-risk requires risk-scout ({path})', 'risk-scout' in data['required_stages'], data)
77
-
78
- # 4. Git repo modes: --working, --staged, --range, --head, plus size threshold -> high-risk
79
- repo = scratch / 'repo'
80
- repo.mkdir()
81
- subprocess.run(['git', 'init', '-q', str(repo)], check=True)
82
- subprocess.run(['git', 'config', 'user.email', 'test@example.com'], cwd=repo, check=True)
83
- subprocess.run(['git', 'config', 'user.name', 'Test'], cwd=repo, check=True)
84
- (repo / 'README.md').write_text('# Base\n', encoding='utf-8')
85
- subprocess.run(['git', 'add', 'README.md'], cwd=repo, check=True)
86
- subprocess.run(['git', 'commit', '-q', '-m', 'init'], cwd=repo, check=True)
87
-
88
- # 4a. Working docs edit -> trivial
89
- (repo / 'README.md').write_text('# Base\nUpdated\n', encoding='utf-8')
90
- res = run_cli('--working', cwd=repo)
91
- assert_eq('git working trivial', json.loads(res.stdout)['lane'], 'trivial')
92
-
93
- # 4b. Staged feature file -> standard; large diff (>300 lines) -> high-risk
94
- (repo / 'app.ts').write_text('export const ok = 1\n', encoding='utf-8')
95
- subprocess.run(['git', 'add', 'app.ts'], cwd=repo, check=True)
96
- res = run_cli('--staged', cwd=repo)
97
- assert_eq('git staged standard', json.loads(res.stdout)['lane'], 'standard')
98
-
99
- (repo / 'big.ts').write_text('\n'.join(f'export const v{i} = {i}' for i in range(320)) + '\n', encoding='utf-8')
100
- res = run_cli('--working', cwd=repo)
101
- big_data = json.loads(res.stdout)
102
- assert_eq('large diff -> high-risk', big_data['lane'], 'high-risk')
103
- assert_true('large diff counts lines', big_data['lines_changed'] >= 320, big_data)
104
-
105
- # 4c. Committed range / head
106
- subprocess.run(['git', 'add', '.'], cwd=repo, check=True)
107
- subprocess.run(['git', 'commit', '-q', '-m', 'add code'], cwd=repo, check=True)
108
- res_head = run_cli('--head', '1', cwd=repo)
109
- assert_eq('git --head 1 high-risk', json.loads(res_head.stdout)['lane'], 'high-risk')
110
-
111
- # 5. HUD format & invalid option
112
- res_hud = run_cli('--files', 'README.md', '--format', 'hud', cwd=repo)
113
- assert_eq('hud exit', res_hud.returncode, 0)
114
- assert_true('hud mentions lane', 'trivial' in res_hud.stdout, res_hud.stdout)
115
-
116
- res_bad = run_cli('--unknown-flag', cwd=repo)
117
- assert_true('bad flag exits non-zero', res_bad.returncode != 0, res_bad.returncode)
118
-
119
- if failures:
120
- for item in failures:
121
- print('FAIL:', item, file=sys.stderr)
122
- sys.exit(1)
123
- print(f'PASS {checks} checks')
124
- PY