@sabaiway/agent-workflow-kit 20.2.0 → 21.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +7 -5
  3. package/SKILL.md +1 -1
  4. package/bin/install.mjs +10 -11
  5. package/capability.json +1 -1
  6. package/launchers/windsurf-workflow.md +3 -1
  7. package/package.json +5 -2
  8. package/references/contracts.md +9 -9
  9. package/references/modes/bootstrap.md +3 -3
  10. package/references/modes/commit-guard.md +1 -1
  11. package/references/modes/recommendations.md +2 -2
  12. package/references/modes/upgrade.md +4 -4
  13. package/references/scripts/{archive-caps.mjs → archives/archive-caps.mjs} +1 -1
  14. package/references/scripts/{archive-changelog.mjs → archives/archive-changelog.mjs} +7 -9
  15. package/references/scripts/{archive-decisions.mjs → archives/archive-decisions.mjs} +13 -10
  16. package/references/scripts/{archive-issues.mjs → archives/archive-issues.mjs} +7 -8
  17. package/references/scripts/{check-docs-size.mjs → docs-size/check-docs-size.mjs} +3 -4
  18. package/references/scripts/docs-size/index.mjs +2 -0
  19. package/references/scripts/family.json +43 -0
  20. package/references/scripts/family.mjs +90 -0
  21. package/references/scripts/gates/kit-command-gates.mjs +117 -0
  22. package/references/scripts/{migrate-gates.mjs → gates/migrate-gates.mjs} +30 -13
  23. package/references/scripts/{install-git-hooks.mjs → git-hooks/install-git-hooks.mjs} +50 -38
  24. package/references/scripts/run.mjs +74 -0
  25. package/references/scripts/shared/index.mjs +3 -0
  26. package/references/scripts/shared/project-root.mjs +11 -0
  27. package/references/scripts/spec-schema/index.mjs +2 -0
  28. package/references/shared/composition-handoff.md +1 -1
  29. package/references/shared/deploy-tail.md +2 -2
  30. package/references/templates/SPEC_TEMPLATE.md +1 -1
  31. package/references/templates/adr-record.md +3 -3
  32. package/tools/apply-danger-check.mjs +9 -5
  33. package/tools/atomic-write.mjs +3 -1
  34. package/tools/direct-run.mjs +2 -0
  35. package/tools/distribution-files/retired.mjs +99 -0
  36. package/tools/distribution-files/scripts.mjs +67 -52
  37. package/tools/ensure-configs.mjs +21 -21
  38. package/tools/ensure-ops.mjs +60 -18
  39. package/tools/ensure-specs.mjs +82 -47
  40. package/tools/ensure-vocabulary.mjs +4 -4
  41. package/tools/epic-shape-cli.mjs +1 -1
  42. package/tools/epic-shape-ledger.mjs +1 -1
  43. package/tools/epic-shape.mjs +1 -1
  44. package/tools/family-registry.mjs +3 -1
  45. package/tools/feedback-record-cli.mjs +1 -1
  46. package/tools/fold-scope.mjs +2 -2
  47. package/tools/git-hooks.mjs +90 -65
  48. package/tools/jev-connect.mjs +1 -1
  49. package/tools/jev-guide.mjs +1 -1
  50. package/tools/jev-skill.mjs +1 -1
  51. package/tools/known-footprint.mjs +7 -29
  52. package/tools/node-evidence.mjs +29 -15
  53. package/tools/now-cli.mjs +1 -1
  54. package/tools/payload-prune.mjs +53 -58
  55. package/tools/plan-shape-cli.mjs +1 -1
  56. package/tools/plan-shape.mjs +1 -1
  57. package/tools/project-rules/rules-record.mjs +1 -1
  58. package/tools/queue-audit-cli.mjs +1 -1
  59. package/tools/queue-audit.mjs +2 -2
  60. package/tools/queue-purge-archive.mjs +1 -1
  61. package/tools/queue-purge-cli.mjs +1 -1
  62. package/tools/queue-purge.mjs +1 -1
  63. package/tools/recommendations.mjs +22 -19
  64. package/tools/script-priors.mjs +31 -3
  65. package/tools/source-size/piles.mjs +1 -1
  66. package/tools/spec-adoption.mjs +1 -1
  67. package/tools/spec-check-ops.mjs +2 -2
  68. package/tools/spec-check.mjs +2 -2
  69. package/tools/spec-coverage.mjs +1 -1
  70. package/tools/tier-guide.mjs +1 -1
  71. package/tools/transition/index.mjs +1 -1
  72. package/tools/upgrade-runlist.mjs +1 -1
  73. package/tools/write-lanes.mjs +2 -2
  74. package/references/scripts/_expect-shim.mjs +0 -41
  75. package/references/scripts/archive-caps.test.mjs +0 -321
  76. package/references/scripts/archive-changelog.test.mjs +0 -560
  77. package/references/scripts/archive-conservation.test.mjs +0 -466
  78. package/references/scripts/archive-decisions.test.mjs +0 -1503
  79. package/references/scripts/archive-issues.test.mjs +0 -825
  80. package/references/scripts/archiver-structure.test.mjs +0 -84
  81. package/references/scripts/check-docs-size-cli.test.mjs +0 -325
  82. package/references/scripts/check-docs-size-ensure.test.mjs +0 -360
  83. package/references/scripts/check-docs-size.test.mjs +0 -395
  84. package/references/scripts/install-git-hooks-repo-exec.test.mjs +0 -185
  85. package/references/scripts/install-git-hooks.test.mjs +0 -241
  86. package/references/scripts/markdown-blocks.test.mjs +0 -310
  87. package/references/scripts/migrate-gates-branches.test.mjs +0 -302
  88. package/references/scripts/migrate-gates.test.mjs +0 -517
  89. package/references/scripts/spec-schema.test.mjs +0 -352
  90. /package/references/scripts/{markdown-blocks.mjs → shared/markdown-blocks.mjs} +0 -0
  91. /package/references/scripts/{spec-schema.mjs → spec-schema/spec-schema.mjs} +0 -0
@@ -1,352 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import { expect } from './_expect-shim.mjs';
3
-
4
- // Dynamic import: the suite LOADS without the module (red-proof observes it failing pre-fix).
5
- const reader = await import('./spec-schema.mjs').catch(() => ({}));
6
- const { readSpecDocument, classifyPath, SPEC_SCHEMA, SPECS_COLLAPSE } = reader;
7
-
8
- // Inline fixtures ONLY — this suite runs inside a deployed project's scripts/ where no corpus exists.
9
- // The repo-only corpus (engine test/fixtures/specs) is the durable record; this is the unit pin.
10
-
11
- const frontmatter = (fields) =>
12
- `---\n${Object.entries(fields).map(([key, value]) => `${key}: ${value}`).join('\n')}\n---\n`;
13
-
14
- const SUBSTRATE = { type: 'spec', lastUpdated: '2026-08-23', scope: 'permanent', staleAfter: '90d', owner: 'none' };
15
- const UPLINK_LINE = '> Up: [technical_specification.md](../technical_specification.md)';
16
-
17
- const specDoc = ({ fields = {}, drop = [], title = '# Spec: Login', scenarios, outOfScope = '- Password reset', module = '- src/login/', extra = '' } = {}) => {
18
- const all = { ...SUBSTRATE, maxLines: '150', kind: 'spec', status: 'draft', revision: '1', ...fields };
19
- for (const key of drop) delete all[key];
20
- const lines = scenarios ?? ['- S1 happy path :: test/login.test.mjs :: spec:login/S1', '- S2 lockout :: unbound'];
21
- return `${frontmatter(all)}\n${title}\n\n## Contract\n\nAccepts a credential pair.\n\n## Scenarios\n\n${lines.join('\n')}\n\n## Out of scope\n\n${outOfScope}\n\n## Module\n\n${module}\n${extra}`;
22
- };
23
-
24
- const indexDoc = ({ fields = {}, children = ['- [login](./login.md)', '- [billing](./billing/index.md)'], preamble = '', title = '# Auth' } = {}) =>
25
- `${frontmatter({ ...SUBSTRATE, maxLines: '80', kind: 'index', ...fields })}\n${title}\n${preamble}\n## Children\n\n${children.join('\n')}\n`;
26
-
27
- const partDoc = ({ fields = {}, title = '# Part: Sessions', extra = '' } = {}) =>
28
- `${frontmatter({ ...SUBSTRATE, maxLines: '150', kind: 'part', ...fields })}\n${title}\n\nSession details.\n${extra}`;
29
-
30
- const rulesOf = (verdict) => verdict.errors.map((e) => e.rule);
31
- const refuses = (text, rel, rule) => {
32
- const verdict = readSpecDocument(text, rel);
33
- expect(rulesOf(verdict)).toEqual([rule]);
34
- };
35
- const withContract = (contract) => specDoc().replace('Accepts a credential pair.', contract);
36
- const openListErrors = (contract, rel = 'login.md') => readSpecDocument(withContract(contract), rel).errors;
37
-
38
- describe('readSpecDocument — accept', () => {
39
- it('a flat draft spec reads clean with kind/status/revision', () => {
40
- const verdict = readSpecDocument(specDoc(), 'login.md');
41
- expect(verdict.errors).toEqual([]);
42
- expect(verdict.warnings).toEqual([]);
43
- expect({ kind: verdict.kind, status: verdict.status, revision: verdict.revision }).toEqual({ kind: 'spec', status: 'draft', revision: 1 });
44
- });
45
-
46
- it('a promoted root under <slug>/index.md with ## Parts and ## Links reads clean', () => {
47
- const text = specDoc({ extra: '\n## Parts\n\n- [sessions](./sessions.md)\n\n## Links\n\n- [[AD-112]]\n' });
48
- expect(readSpecDocument(text, 'auth/login/index.md').errors).toEqual([]);
49
- });
50
-
51
- it('a domain index, the store root (with the up-link) and a part read clean', () => {
52
- expect(readSpecDocument(indexDoc(), 'auth/index.md').errors).toEqual([]);
53
- const root = indexDoc({ preamble: `\n${UPLINK_LINE}\n`, children: [] });
54
- const rootVerdict = readSpecDocument(root, 'index.md');
55
- expect(rootVerdict.errors).toEqual([]);
56
- expect(rootVerdict.kind).toBe('index');
57
- expect(readSpecDocument(partDoc(), 'auth/login/sessions.md').errors).toEqual([]);
58
- });
59
-
60
- it('a retired spec may carry *(empty)* as its module; a live spec with an unbound scenario WARNS, never refuses', () => {
61
- const retired = specDoc({ fields: { status: 'retired' }, module: '*(empty)*', scenarios: ['- S1 gone :: unbound'] });
62
- expect(readSpecDocument(retired, 'login.md').errors).toEqual([]);
63
- const live = readSpecDocument(specDoc({ fields: { status: 'live', revision: '3' } }), 'login.md');
64
- expect(live.errors).toEqual([]);
65
- expect(live.warnings.map((w) => w.rule)).toEqual(['unbound']);
66
- });
67
-
68
- it('CRLF line endings read identically', () => {
69
- expect(readSpecDocument(specDoc().replace(/\n/g, '\r\n'), 'login.md').errors).toEqual([]);
70
- });
71
-
72
- it('*(empty)* is a legal Out of scope; a file-list module is legal', () => {
73
- const text = specDoc({ outOfScope: '*(empty)*', module: '- src/a.mjs\n- src/b.mjs' });
74
- expect(readSpecDocument(text, 'login.md').errors).toEqual([]);
75
- });
76
- });
77
-
78
- describe('readSpecDocument — refuse, exactly one rule per defect', () => {
79
- it('frontmatter / substrate-key / type / kind / maxlines', () => {
80
- refuses('# Spec: Login\n', 'login.md', 'frontmatter');
81
- refuses(specDoc({ drop: ['owner'] }), 'login.md', 'substrate-key');
82
- refuses(specDoc({ fields: { type: 'reference' } }), 'login.md', 'type');
83
- refuses(specDoc({ fields: { kind: 'feature' } }), 'login.md', 'kind');
84
- refuses(specDoc({ drop: ['kind'] }), 'login.md', 'kind');
85
- refuses(specDoc({ fields: { maxLines: '400' } }), 'login.md', 'maxlines');
86
- });
87
-
88
- it('status / revision / root-owns', () => {
89
- refuses(specDoc({ fields: { status: 'approved' } }), 'login.md', 'status');
90
- refuses(specDoc({ drop: ['status'] }), 'login.md', 'status');
91
- refuses(specDoc({ fields: { revision: '0' } }), 'login.md', 'revision');
92
- refuses(specDoc({ fields: { revision: '1.5' } }), 'login.md', 'revision');
93
- refuses(indexDoc({ fields: { status: 'draft' } }), 'auth/index.md', 'root-owns');
94
- refuses(partDoc({ fields: { revision: '2' } }), 'auth/login/sessions.md', 'root-owns');
95
- });
96
-
97
- it('slug / kind-path / root-uplink', () => {
98
- refuses(specDoc({ scenarios: ['- S1 x :: unbound'] }), 'Login_Page.md', 'slug');
99
- refuses(indexDoc(), 'auth/Auth Stuff/index.md', 'slug');
100
- refuses(indexDoc(), 'auth/overview.md', 'kind-path');
101
- refuses(partDoc(), 'auth/login/index.md', 'kind-path');
102
- refuses(specDoc({ scenarios: ['- S1 x :: unbound'] }), 'index.md', 'kind-path');
103
- refuses(indexDoc({ children: [] }), 'index.md', 'root-uplink');
104
- });
105
-
106
- it('title / section-missing / section-order / section-forbidden', () => {
107
- refuses(specDoc({ title: '# Login' }), 'login.md', 'title');
108
- refuses(specDoc({ title: '# Spec: ' }), 'login.md', 'title');
109
- refuses(partDoc({ title: '# Sessions' }), 'auth/login/sessions.md', 'title');
110
- refuses(specDoc().replace('## Out of scope', '## Out-of-scope'), 'login.md', 'section-missing');
111
- refuses(specDoc().replace('## Contract\n\nAccepts a credential pair.\n\n', '').concat('\n## Contract\n\nlate\n'), 'login.md', 'section-order');
112
- refuses(indexDoc().concat('\n## Module\n\n- src/\n'), 'auth/index.md', 'section-forbidden');
113
- refuses(partDoc({ extra: '\n## Scenarios\n\n- S1 x :: unbound\n' }), 'auth/login/sessions.md', 'section-forbidden');
114
- });
115
-
116
- it('children-link / children-duplicate; the reader counts no children, so an index of 31 reads clean', () => {
117
- refuses(indexDoc({ children: ['- login'] }), 'auth/index.md', 'children-link');
118
- refuses(indexDoc({ children: ['- [login](../login.md)'] }), 'auth/index.md', 'children-link');
119
- refuses(indexDoc({ children: ['- [login](./login.md)', '- [login again](./login.md)'] }), 'auth/index.md', 'children-duplicate');
120
- const many = Array.from({ length: 31 }, (_, i) => `- [c${i}](./c${i}.md)`);
121
- const verdict = readSpecDocument(indexDoc({ children: many }), 'auth/index.md');
122
- expect({ errors: verdict.errors, children: verdict.structure.children.length }).toEqual({ errors: [], children: 31 });
123
- });
124
-
125
- it('scenario-line / scenario-number / scenario-marker / scenario-path', () => {
126
- refuses(specDoc({ scenarios: ['- S1 no binding'] }), 'login.md', 'scenario-line');
127
- refuses(specDoc({ scenarios: ['S1 happy :: unbound'] }), 'login.md', 'scenario-line');
128
- refuses(specDoc({ scenarios: ['- S1 a :: unbound', '- S3 b :: unbound'] }), 'login.md', 'scenario-number');
129
- refuses(specDoc({ scenarios: ['- S2 a :: unbound'] }), 'login.md', 'scenario-number');
130
- refuses(specDoc({ scenarios: ['- S1 a :: test/login.test.mjs :: spec:login/S2'] }), 'login.md', 'scenario-marker');
131
- refuses(specDoc({ scenarios: ['- S1 a :: test/login.test.mjs :: spec:signup/S1'] }), 'login.md', 'scenario-marker');
132
- refuses(specDoc({ scenarios: ['- S1 a :: ../test/login.test.mjs :: spec:login/S1'] }), 'login.md', 'scenario-path');
133
- refuses(specDoc({ scenarios: ['- S1 a :: /abs/login.test.mjs :: spec:login/S1'] }), 'login.md', 'scenario-path');
134
- });
135
-
136
- it('scenarios-empty / no empty-marker escape', () => {
137
- refuses(specDoc({ scenarios: [] }), 'login.md', 'scenarios-empty');
138
- refuses(specDoc({ scenarios: ['*(empty)*'] }), 'login.md', 'scenario-line');
139
- for (const status of SPEC_SCHEMA.statuses) {
140
- expect(readSpecDocument(specDoc({ scenarios: ['- S1 x :: unbound'], fields: { status } }), 'login.md').errors).toEqual([]);
141
- }
142
- });
143
-
144
- it('out-of-scope / module-empty / module-* path refusals / module-mix / parts', () => {
145
- refuses(specDoc({ outOfScope: '' }), 'login.md', 'out-of-scope');
146
- refuses(specDoc({ outOfScope: 'nothing excluded' }), 'login.md', 'out-of-scope');
147
- refuses(specDoc({ outOfScope: '- ' }), 'login.md', 'out-of-scope');
148
- refuses(specDoc({ module: '' }), 'login.md', 'module-empty');
149
- refuses(specDoc({ module: '*(empty)*' }), 'login.md', 'module-empty');
150
- refuses(specDoc({ module: '- ../src/' }), 'login.md', 'module-traversal');
151
- refuses(specDoc({ module: '- /src/login/' }), 'login.md', 'module-absolute');
152
- refuses(specDoc({ module: '- C:/src/login/' }), 'login.md', 'module-absolute');
153
- refuses(specDoc({ module: '- src\\login\\' }), 'login.md', 'module-backslash');
154
- refuses(specDoc({ module: '- src/**/*.mjs' }), 'login.md', 'module-glob');
155
- refuses(specDoc({ module: '- src/login/\n- src/login/a.mjs' }), 'login.md', 'module-mix');
156
- refuses(specDoc({ module: '- src/login/\n- src/signup/' }), 'login.md', 'module-mix');
157
- refuses(specDoc({ extra: '\n## Parts\n\n- [sessions](./sessions.md)\n' }), 'login.md', 'parts');
158
- refuses(specDoc({ extra: '\n## Parts\n\n- sessions\n' }), 'auth/login/index.md', 'parts');
159
- refuses(specDoc({ extra: '\n## Parts\n\n- [a](./a.md)\n- [b](./a.md)\n' }), 'auth/login/index.md', 'parts');
160
- });
161
-
162
- it('frontmatter-key: an unknown key, a duplicate key and a malformed line each refuse; an absent type is substrate-key ALONE', () => {
163
- refuses(specDoc({ fields: { priority: 'high' } }), 'login.md', 'frontmatter-key');
164
- refuses(specDoc().replace('owner: none\n', 'owner: none\nowner: none\n'), 'login.md', 'frontmatter-key');
165
- refuses(specDoc().replace('owner: none\n', 'owner: none\n- a list item\n'), 'login.md', 'frontmatter-key');
166
- refuses(specDoc({ drop: ['type'] }), 'login.md', 'substrate-key');
167
- });
168
-
169
- it('a part at the store root (no folder) is kind-path; a blank binding path is scenario-path; a blank module bullet is module-empty', () => {
170
- refuses(partDoc(), 'orphan.md', 'kind-path');
171
- refuses(specDoc({ scenarios: ['- S1 a :: :: spec:login/S1'] }), 'login.md', 'scenario-path');
172
- refuses(specDoc({ module: '- ' }), 'login.md', 'module-empty');
173
- });
174
-
175
- it('module-line: prose beside a module bullet refuses; root-uplink needs the exact markdown link, not a mention', () => {
176
- refuses(specDoc({ module: 'the root is\n- src/login/' }), 'login.md', 'module-line');
177
- refuses(indexDoc({ preamble: '\nSee technical_specification.md for the top spec.\n', children: [] }), 'index.md', 'root-uplink');
178
- expect(readSpecDocument(indexDoc({ preamble: `\n${UPLINK_LINE}\n`, children: [] }), 'index.md').errors).toEqual([]);
179
- });
180
-
181
- it('the reader parses no markdown code: a fence line refuses `fence`; the up-link is a whole exact line, so an inline span or a trailing note is root-uplink', () => {
182
- refuses(indexDoc({ preamble: `\n${UPLINK_LINE}\n\n\`\`\`\n${UPLINK_LINE}\n\`\`\`\n`, children: [] }), 'index.md', 'fence');
183
- refuses(partDoc({ extra: '\n~~~js\nconst sample = 1;\n~~~\n' }), 'auth/login/sessions.md', 'fence');
184
- refuses(indexDoc({ preamble: `\nWrite \`\`${UPLINK_LINE}\`\` here.\n`, children: [] }), 'index.md', 'root-uplink');
185
- refuses(indexDoc({ preamble: `\n${UPLINK_LINE} — the top spec\n`, children: [] }), 'index.md', 'root-uplink');
186
- });
187
-
188
- it('a frontmatter defect ENDS the read with frontmatter-key alone (a malformed kind line is not a missing kind)', () => {
189
- refuses(specDoc().replace('kind: spec\n', 'kind spec\n'), 'login.md', 'frontmatter-key');
190
- refuses(specDoc({ fields: { priority: 'high', kind: 'feature' } }), 'login.md', 'frontmatter-key');
191
- });
192
-
193
- it('the title precedes every section; prose-only Module is module-line; a blank Module on a retired spec is module-empty', () => {
194
- refuses(specDoc().replace('# Spec: Login\n', '## Surprise\n\nx\n\n# Spec: Login\n'), 'login.md', 'title');
195
- refuses(specDoc({ module: 'the root is src' }), 'login.md', 'module-line');
196
- refuses(specDoc({ fields: { status: 'retired' }, module: '' }), 'login.md', 'module-empty');
197
- });
198
-
199
- it('every rule id a refusal names is declared in SPEC_SCHEMA.rules', () => {
200
- for (const rule of ['frontmatter', 'frontmatter-key', 'fence', 'kind', 'module-mix', 'module-line', 'scenario-path', 'parts', 'root-uplink']) {
201
- expect(SPEC_SCHEMA.rules.includes(rule)).toBe(true);
202
- }
203
- expect(new Set(SPEC_SCHEMA.rules).size).toBe(SPEC_SCHEMA.rules.length);
204
- });
205
- });
206
-
207
- describe('readSpecDocument — the structure verdict (additive, slice 2a)', () => {
208
- const structureOf = (text, rel) => readSpecDocument(text, rel).structure;
209
- const BOTH_SCENARIOS = [
210
- { ordinal: 1, binding: { file: 'test/login.test.mjs', marker: 'spec:login/S1' } },
211
- { ordinal: 2, binding: null },
212
- ];
213
-
214
- it('a flat spec extracts scenarios (bound + unbound) and its one dir/ module root', () => {
215
- expect(structureOf(specDoc(), 'login.md')).toEqual({
216
- scenarios: BOTH_SCENARIOS,
217
- children: [],
218
- parts: [],
219
- module: { form: 'root', paths: ['src/login/'] },
220
- });
221
- });
222
-
223
- it('a promoted root extracts parts and a fileSet module; ## Links stays free prose, never extracted', () => {
224
- const text = specDoc({ module: '- src/a.mjs\n- src/b.mjs', extra: '\n## Parts\n\n- [sessions](./sessions.md)\n\n## Links\n\n- [[AD-112]]\n' });
225
- expect(structureOf(text, 'auth/login/index.md')).toEqual({
226
- scenarios: BOTH_SCENARIOS,
227
- children: [],
228
- parts: [{ name: 'sessions', target: './sessions.md' }],
229
- module: { form: 'fileSet', paths: ['src/a.mjs', 'src/b.mjs'] },
230
- });
231
- });
232
-
233
- it('an index extracts children with VERBATIM targets — ./x.md and ./x/index.md stay distinct strings', () => {
234
- expect(structureOf(indexDoc(), 'auth/index.md')).toEqual({
235
- scenarios: [],
236
- children: [{ name: 'login', target: './login.md' }, { name: 'billing', target: './billing/index.md' }],
237
- parts: [],
238
- module: null,
239
- });
240
- });
241
-
242
- it('a part extracts the empty structure; a retired *(empty)* module extracts null on a CLEAN document', () => {
243
- expect(structureOf(partDoc(), 'auth/login/sessions.md')).toEqual({ scenarios: [], children: [], parts: [], module: null });
244
- const retired = specDoc({ fields: { status: 'retired' }, module: '*(empty)*', scenarios: ['- S1 gone :: unbound'] });
245
- expect(structureOf(retired, 'login.md').module).toBeNull();
246
- });
247
-
248
- it('EVERY early refusal reads structure null: missing frontmatter, a frontmatter defect, an unknown or absent kind', () => {
249
- expect(structureOf('# Spec: Login\n', 'login.md')).toBeNull();
250
- expect(structureOf(specDoc({ fields: { priority: 'high' } }), 'login.md')).toBeNull();
251
- expect(structureOf(specDoc({ fields: { kind: 'feature' } }), 'login.md')).toBeNull();
252
- expect(structureOf(specDoc({ drop: ['kind'] }), 'login.md')).toBeNull();
253
- });
254
-
255
- it('a grammar-malformed scenario/child/part line is simply ABSENT — valid lines before and after it extract', () => {
256
- const s = structureOf(specDoc({ scenarios: ['- S1 a :: unbound', '- S2 broken', '- S3 c :: unbound'] }), 'login.md');
257
- expect(s.scenarios).toEqual([{ ordinal: 1, binding: null }, { ordinal: 3, binding: null }]);
258
- const c = structureOf(indexDoc({ children: ['- [a](./a.md)', '- broken', '- [b](./b/index.md)'] }), 'auth/index.md');
259
- expect(c.children).toEqual([{ name: 'a', target: './a.md' }, { name: 'b', target: './b/index.md' }]);
260
- const p = structureOf(specDoc({ extra: '\n## Parts\n\n- [a](./a.md)\n- broken\n- [b](./b.md)\n' }), 'auth/login/index.md');
261
- expect(p.parts).toEqual([{ name: 'a', target: './a.md' }, { name: 'b', target: './b.md' }]);
262
- });
263
-
264
- it('the module is a CONJUNCTION — prose, a refused path, a dir/file mix each extract null; a rule-refused scenario line still extracts verbatim', () => {
265
- for (const module of ['the root is\n- src/login/', '- ../src/', '- src/login/\n- src/login/a.mjs']) {
266
- expect(structureOf(specDoc({ module }), 'login.md').module).toBeNull();
267
- }
268
- const v = readSpecDocument(specDoc({ scenarios: ['- S1 a :: test/a.mjs :: spec:login/S2'] }), 'login.md');
269
- expect(v.errors.map((e) => e.rule)).toEqual(['scenario-marker']);
270
- expect(v.structure.scenarios).toEqual([{ ordinal: 1, binding: { file: 'test/a.mjs', marker: 'spec:login/S2' } }]);
271
- });
272
- });
273
-
274
- describe('readSpecDocument — open-list clauses', () => {
275
- const refusal = 'the clause "an anchor path reported modified, untracked…" is an open list — add a closing form to it such as "only if …; everything else …"';
276
- const open = '- an anchor path reported modified, untracked or ignored is the named refusal `anchor-dirty`';
277
- const closed = '- an anchor path is accepted only if `ls-files -v` lists it with tag `H` and `status` is silent — everything else, a path reported modified, untracked or ignored, is the named refusal `anchor-dirty`';
278
-
279
- it('refuses the measured clause with the exact message; verb alone, form alone and an in-clause closure pass', () => {
280
- expect(openListErrors(open)).toEqual([{ rule: 'open-list', message: refusal }]);
281
- for (const text of [closed, '- refuse one case', '- alpha, beta or gamma']) expect(openListErrors(text)).toEqual([]);
282
- });
283
-
284
- it('joins continuation lines, collapses whitespace and keeps an indented bullet in its top-level bullet', () => {
285
- for (const text of ['- refuse alpha,\n beta or ignored', '- refuse alpha,\n - beta or ignored']) expect(rulesOf(readSpecDocument(withContract(text), 'login.md'))).toEqual(['open-list']);
286
- });
287
-
288
- it('ends a bullet at a blank, the next top-level bullet or every ATX heading; Contract prose is ignored', () => {
289
- for (const tail of ['\n\nEverything else closes', '\n- Everything else closes', ...Array.from({ length: 6 }, (_, i) => `\n${'#'.repeat(i + 1)} Everything else closes`)]) {
290
- expect(rulesOf(readSpecDocument(withContract('- refuse alpha, beta or gamma' + tail), 'login.md'))).toEqual(['open-list']);
291
- }
292
- expect(openListErrors('refuse alpha, beta or gamma')).toEqual([]);
293
- });
294
-
295
- it('ends a bullet at indented and tab-separated ATX headings', () => {
296
- for (const tail of ['\n ## Everything else closes', '\n#\tEverything else closes']) expect(rulesOf(readSpecDocument(withContract('- refuse alpha, beta or gamma' + tail), 'login.md'))).toEqual(['open-list']);
297
- });
298
-
299
- it('starts a new empty top-level bullet before following prose', () => {
300
- for (const tail of ['\n- \nEverything else closes', '\n-\nonly if closes']) expect(rulesOf(readSpecDocument(withContract('- refuse alpha, beta or gamma' + tail), 'login.md'))).toEqual(['open-list']);
301
- });
302
-
303
- it('judges an open list in every Contract section', () => {
304
- const duplicate = specDoc().replace('## Scenarios', '## Contract\n\n- refuse alpha, beta or gamma\n\n## Scenarios');
305
- expect(rulesOf(readSpecDocument(duplicate, 'login.md')).includes('open-list')).toBe(true);
306
- });
307
-
308
- it('splits clauses at punctuation plus markdown tails, but not inside backtick spans', () => {
309
- for (const tail of ['.** ', '.` ', '.) ', '.] ', '; ']) expect(rulesOf(readSpecDocument(withContract(`- refuse alpha, beta or gamma${tail}Everything else closes`), 'login.md'))).toEqual(['open-list']);
310
- for (const text of ['- refuse `alpha. beta`, gamma or delta', '- refuse `alpha; beta`, gamma or delta', '- refuse `alpha. beta, gamma or delta']) expect(rulesOf(readSpecDocument(withContract(text), 'login.md'))).toEqual(['open-list']);
311
- expect(openListErrors('- refuse alpha``. beta, gamma or delta')).toEqual([]);
312
- });
313
-
314
- it('keeps span content in judgement, and a closure in a neighbouring clause cannot lift a refusal', () => {
315
- expect(rulesOf(readSpecDocument(withContract('- `refuse` alpha, beta or gamma'), 'login.md'))).toEqual(['open-list']);
316
- expect(openListErrors('- refuse alpha, beta or gamma with `everything else`')).toEqual([]);
317
- expect(rulesOf(readSpecDocument(withContract('- refuse alpha, beta or gamma. Everything else closes'), 'login.md'))).toEqual(['open-list']);
318
- });
319
-
320
- it('matches verbs, forms and closure tokens with the frozen case and boundary rules', () => {
321
- for (const verb of ['refuse', 'refuses', 'refused', 'refusal', 'refusals', 'REFUSE', 'REFUSAL']) expect(rulesOf(readSpecDocument(withContract(`- ${verb} alpha, beta or gamma`), 'login.md'))).toEqual(['open-list']);
322
- for (const text of ['- Refuse alpha, beta or gamma', '- refuse alpha, beta and gamma']) expect(openListErrors(text)).toEqual([]);
323
- expect(rulesOf(readSpecDocument(withContract('- refuse alpha · beta'), 'login.md'))).toEqual(['open-list']);
324
- for (const token of SPEC_SCHEMA.openList.closureTokens) expect(openListErrors(`- ${token.toUpperCase()}: refuse alpha, beta or gamma`)).toEqual([]);
325
- for (const text of ['- refuse alpha, beta or gamma — none of these', '- refuse alpha, beta or gamma — closed-key', '- refuse alpha, beta or gamma — READ-ONLY', '- refuse alpha, beta or gamma — if only this', '- refuse alpha, beta or gamma — not only this']) expect(rulesOf(readSpecDocument(withContract(text), 'login.md'))).toEqual(['open-list']);
326
- expect(openListErrors('- refuse alpha, beta or gamma — ONLY this')).toEqual([]);
327
- });
328
-
329
- it('judges every part bullet, never an index, and freezes every schema list and inner pair', () => {
330
- expect(rulesOf(readSpecDocument(partDoc({ extra: `\n${open}\n` }), 'auth/login/sessions.md'))).toEqual(['open-list']);
331
- expect(readSpecDocument(indexDoc({ children: [], preamble: `\n${open}\n` }), 'auth/index.md').errors).toEqual([]);
332
- expect(SPEC_SCHEMA.openList).toEqual({ checkVerbs: ['refuse', 'refusal', 'REFUSE', 'REFUSAL'], enumerationForms: [[',', ' or '], [' · ']], closureTokens: ['only if', 'only when', 'the only', 'everything else', 'anything else', 'nothing else', 'every other', 'any other', 'otherwise', 'exactly', 'one of', 'closed'], emphaticToken: 'ONLY' });
333
- expect([SPEC_SCHEMA.openList, SPEC_SCHEMA.openList.checkVerbs, SPEC_SCHEMA.openList.enumerationForms, ...SPEC_SCHEMA.openList.enumerationForms, SPEC_SCHEMA.openList.closureTokens].every(Object.isFrozen)).toBe(true);
334
- });
335
- });
336
-
337
- describe('classifyPath + the frozen constants', () => {
338
- it('classifies the lexical path forms', () => {
339
- expect(['src/', 'src/a.mjs', '../x', '/x', 'C:/x', 'a\\b', 'src/*.mjs'].map(classifyPath)).toEqual([
340
- 'dir', 'file', 'traversal', 'absolute', 'absolute', 'backslash', 'glob',
341
- ]);
342
- });
343
-
344
- it('SPEC_SCHEMA carries the frozen numbers, no children count, and SPECS_COLLAPSE joins the store root', () => {
345
- expect({ fanOutMax: Object.hasOwn(SPEC_SCHEMA, 'fanOutMax'), rules: SPEC_SCHEMA.rules.length, fanOut: SPEC_SCHEMA.rules.includes('fan-out') }).toEqual({ fanOutMax: false, rules: 34, fanOut: false });
346
- expect(SPEC_SCHEMA.maxLines).toEqual({ index: 80, spec: 150, part: 150 });
347
- expect(SPEC_SCHEMA.statuses).toEqual(['draft', 'live', 'retired']);
348
- expect(SPEC_SCHEMA.kinds).toEqual(['index', 'spec', 'part']);
349
- expect(Object.isFrozen(SPEC_SCHEMA)).toBe(true);
350
- expect(SPECS_COLLAPSE).toEqual({ prefix: 'docs/ai/specs/', navPath: 'docs/ai/specs/index.md', label: 'specs/', type: 'spec' });
351
- });
352
- });