@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.
- package/CHANGELOG.md +39 -0
- package/README.md +7 -5
- package/SKILL.md +1 -1
- package/bin/install.mjs +10 -11
- package/capability.json +1 -1
- package/launchers/windsurf-workflow.md +3 -1
- package/package.json +5 -2
- package/references/contracts.md +9 -9
- package/references/modes/bootstrap.md +3 -3
- package/references/modes/commit-guard.md +1 -1
- package/references/modes/recommendations.md +2 -2
- package/references/modes/upgrade.md +4 -4
- package/references/scripts/{archive-caps.mjs → archives/archive-caps.mjs} +1 -1
- package/references/scripts/{archive-changelog.mjs → archives/archive-changelog.mjs} +7 -9
- package/references/scripts/{archive-decisions.mjs → archives/archive-decisions.mjs} +13 -10
- package/references/scripts/{archive-issues.mjs → archives/archive-issues.mjs} +7 -8
- package/references/scripts/{check-docs-size.mjs → docs-size/check-docs-size.mjs} +3 -4
- package/references/scripts/docs-size/index.mjs +2 -0
- package/references/scripts/family.json +43 -0
- package/references/scripts/family.mjs +90 -0
- package/references/scripts/gates/kit-command-gates.mjs +117 -0
- package/references/scripts/{migrate-gates.mjs → gates/migrate-gates.mjs} +30 -13
- package/references/scripts/{install-git-hooks.mjs → git-hooks/install-git-hooks.mjs} +50 -38
- package/references/scripts/run.mjs +74 -0
- package/references/scripts/shared/index.mjs +3 -0
- package/references/scripts/shared/project-root.mjs +11 -0
- package/references/scripts/spec-schema/index.mjs +2 -0
- package/references/shared/composition-handoff.md +1 -1
- package/references/shared/deploy-tail.md +2 -2
- package/references/templates/SPEC_TEMPLATE.md +1 -1
- package/references/templates/adr-record.md +3 -3
- package/tools/apply-danger-check.mjs +9 -5
- package/tools/atomic-write.mjs +3 -1
- package/tools/direct-run.mjs +2 -0
- package/tools/distribution-files/retired.mjs +99 -0
- package/tools/distribution-files/scripts.mjs +67 -52
- package/tools/ensure-configs.mjs +21 -21
- package/tools/ensure-ops.mjs +60 -18
- package/tools/ensure-specs.mjs +82 -47
- package/tools/ensure-vocabulary.mjs +4 -4
- package/tools/epic-shape-cli.mjs +1 -1
- package/tools/epic-shape-ledger.mjs +1 -1
- package/tools/epic-shape.mjs +1 -1
- package/tools/family-registry.mjs +3 -1
- package/tools/feedback-record-cli.mjs +1 -1
- package/tools/fold-scope.mjs +2 -2
- package/tools/git-hooks.mjs +90 -65
- package/tools/jev-connect.mjs +1 -1
- package/tools/jev-guide.mjs +1 -1
- package/tools/jev-skill.mjs +1 -1
- package/tools/known-footprint.mjs +7 -29
- package/tools/node-evidence.mjs +29 -15
- package/tools/now-cli.mjs +1 -1
- package/tools/payload-prune.mjs +53 -58
- package/tools/plan-shape-cli.mjs +1 -1
- package/tools/plan-shape.mjs +1 -1
- package/tools/project-rules/rules-record.mjs +1 -1
- package/tools/queue-audit-cli.mjs +1 -1
- package/tools/queue-audit.mjs +2 -2
- package/tools/queue-purge-archive.mjs +1 -1
- package/tools/queue-purge-cli.mjs +1 -1
- package/tools/queue-purge.mjs +1 -1
- package/tools/recommendations.mjs +22 -19
- package/tools/script-priors.mjs +31 -3
- package/tools/source-size/piles.mjs +1 -1
- package/tools/spec-adoption.mjs +1 -1
- package/tools/spec-check-ops.mjs +2 -2
- package/tools/spec-check.mjs +2 -2
- package/tools/spec-coverage.mjs +1 -1
- package/tools/tier-guide.mjs +1 -1
- package/tools/transition/index.mjs +1 -1
- package/tools/upgrade-runlist.mjs +1 -1
- package/tools/write-lanes.mjs +2 -2
- package/references/scripts/_expect-shim.mjs +0 -41
- package/references/scripts/archive-caps.test.mjs +0 -321
- package/references/scripts/archive-changelog.test.mjs +0 -560
- package/references/scripts/archive-conservation.test.mjs +0 -466
- package/references/scripts/archive-decisions.test.mjs +0 -1503
- package/references/scripts/archive-issues.test.mjs +0 -825
- package/references/scripts/archiver-structure.test.mjs +0 -84
- package/references/scripts/check-docs-size-cli.test.mjs +0 -325
- package/references/scripts/check-docs-size-ensure.test.mjs +0 -360
- package/references/scripts/check-docs-size.test.mjs +0 -395
- package/references/scripts/install-git-hooks-repo-exec.test.mjs +0 -185
- package/references/scripts/install-git-hooks.test.mjs +0 -241
- package/references/scripts/markdown-blocks.test.mjs +0 -310
- package/references/scripts/migrate-gates-branches.test.mjs +0 -302
- package/references/scripts/migrate-gates.test.mjs +0 -517
- package/references/scripts/spec-schema.test.mjs +0 -352
- /package/references/scripts/{markdown-blocks.mjs → shared/markdown-blocks.mjs} +0 -0
- /package/references/scripts/{spec-schema.mjs → spec-schema/spec-schema.mjs} +0 -0
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
import { describe, it, beforeEach, afterEach } from 'node:test';
|
|
2
|
-
import { expect } from './_expect-shim.mjs';
|
|
3
|
-
import { mkdtemp, writeFile, mkdir, readFile, rm } from 'node:fs/promises';
|
|
4
|
-
import { existsSync } from 'node:fs';
|
|
5
|
-
import { spawnSync } from 'node:child_process';
|
|
6
|
-
import { tmpdir } from 'node:os';
|
|
7
|
-
import { join } from 'node:path';
|
|
8
|
-
import { fileURLToPath } from 'node:url';
|
|
9
|
-
import {
|
|
10
|
-
parseFrontmatter,
|
|
11
|
-
parseStaleAfter,
|
|
12
|
-
computeToday,
|
|
13
|
-
inspectFile,
|
|
14
|
-
buildIndex,
|
|
15
|
-
checkIndexFreshness,
|
|
16
|
-
walkMarkdownFiles,
|
|
17
|
-
regenerateIndex,
|
|
18
|
-
} from './check-docs-size.mjs';
|
|
19
|
-
|
|
20
|
-
describe('parseFrontmatter', () => {
|
|
21
|
-
it('extracts scalar fields from valid YAML frontmatter', () => {
|
|
22
|
-
const text = '---\ntype: reference\nmaxLines: 500\nstaleAfter: 30d\n---\n\nbody.';
|
|
23
|
-
const fm = parseFrontmatter(text);
|
|
24
|
-
expect(fm).toEqual({
|
|
25
|
-
type: 'reference',
|
|
26
|
-
maxLines: '500',
|
|
27
|
-
staleAfter: '30d',
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('returns null when no frontmatter block is present', () => {
|
|
32
|
-
expect(parseFrontmatter('just body text\n')).toBeNull();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('skips lines that do not match key:value pattern', () => {
|
|
36
|
-
const text = '---\ntype: reference\n# stray comment\nmaxLines: 100\n---\n';
|
|
37
|
-
const fm = parseFrontmatter(text);
|
|
38
|
-
expect(fm).toEqual({ type: 'reference', maxLines: '100' });
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('parseStaleAfter', () => {
|
|
43
|
-
it('parses Nd into Number', () => {
|
|
44
|
-
expect(parseStaleAfter('7d')).toBe(7);
|
|
45
|
-
expect(parseStaleAfter('30d')).toBe(30);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('returns null for "never", empty, or undefined', () => {
|
|
49
|
-
expect(parseStaleAfter('never')).toBeNull();
|
|
50
|
-
expect(parseStaleAfter('')).toBeNull();
|
|
51
|
-
expect(parseStaleAfter(undefined)).toBeNull();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('returns null for invalid formats', () => {
|
|
55
|
-
expect(parseStaleAfter('7days')).toBeNull();
|
|
56
|
-
expect(parseStaleAfter('7')).toBeNull();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('computeToday', () => {
|
|
61
|
-
it('parses YYYY-MM-DD into UTC-midnight Date', () => {
|
|
62
|
-
const d = computeToday('2026-05-24');
|
|
63
|
-
expect(d.toISOString()).toBe('2026-05-24T00:00:00.000Z');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('returns a Date when todayStr is null (no-throw smoke)', () => {
|
|
67
|
-
const d = computeToday(null);
|
|
68
|
-
expect(d).toBeInstanceOf(Date);
|
|
69
|
-
expect(Number.isNaN(d.getTime())).toBe(false);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('inspectFile', () => {
|
|
74
|
-
let dir;
|
|
75
|
-
|
|
76
|
-
beforeEach(async () => {
|
|
77
|
-
dir = await mkdtemp(join(tmpdir(), 'check-docs-size-test-'));
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
afterEach(async () => {
|
|
81
|
-
await rm(dir, { recursive: true, force: true });
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('reports no errors and no warnings for an in-cap, fresh file', async () => {
|
|
85
|
-
const path = join(dir, 'fresh.md');
|
|
86
|
-
await writeFile(
|
|
87
|
-
path,
|
|
88
|
-
'---\ntype: reference\nlastUpdated: 2026-05-24\nstaleAfter: 30d\nmaxLines: 100\n---\n\n# OK\n',
|
|
89
|
-
);
|
|
90
|
-
const result = await inspectFile(path, computeToday('2026-05-24'));
|
|
91
|
-
expect(result.errors).toEqual([]);
|
|
92
|
-
expect(result.warnings).toEqual([]);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('reports an error when lineCount > maxLines', async () => {
|
|
96
|
-
const path = join(dir, 'big.md');
|
|
97
|
-
const body = '\n'.repeat(20); // 20 lines of body → total ~26
|
|
98
|
-
await writeFile(
|
|
99
|
-
path,
|
|
100
|
-
`---\ntype: reference\nlastUpdated: 2026-05-24\nstaleAfter: 30d\nmaxLines: 5\n---\n\n# Too big${body}`,
|
|
101
|
-
);
|
|
102
|
-
const result = await inspectFile(path, computeToday('2026-05-24'));
|
|
103
|
-
expect(result.errors.some((e) => /lines > maxLines/.test(e))).toBe(true);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('reports an error when frontmatter is missing maxLines', async () => {
|
|
107
|
-
const path = join(dir, 'no-cap.md');
|
|
108
|
-
await writeFile(path, '---\ntype: reference\nlastUpdated: 2026-05-24\n---\n\nbody.\n');
|
|
109
|
-
const result = await inspectFile(path, computeToday('2026-05-24'));
|
|
110
|
-
expect(result.errors).toContain('frontmatter missing maxLines');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('reports a warning when lastUpdated is older than staleAfter window', async () => {
|
|
114
|
-
const path = join(dir, 'stale.md');
|
|
115
|
-
await writeFile(
|
|
116
|
-
path,
|
|
117
|
-
'---\ntype: reference\nlastUpdated: 2026-01-01\nstaleAfter: 30d\nmaxLines: 100\n---\n\nbody.\n',
|
|
118
|
-
);
|
|
119
|
-
const result = await inspectFile(path, computeToday('2026-05-24'));
|
|
120
|
-
expect(result.warnings.length).toBeGreaterThan(0);
|
|
121
|
-
expect(result.warnings[0]).toMatch(/staleAfter/);
|
|
122
|
-
expect(result.errors).toEqual([]);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('reports a single error when frontmatter is missing entirely', async () => {
|
|
126
|
-
const path = join(dir, 'no-fm.md');
|
|
127
|
-
await writeFile(path, '# Just a body, no frontmatter.\n');
|
|
128
|
-
const result = await inspectFile(path, computeToday('2026-05-24'));
|
|
129
|
-
expect(result.frontmatter).toBeNull();
|
|
130
|
-
expect(result.errors).toContain('missing YAML frontmatter');
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// The cap-validator discovers ONLY `*.md` files, so a non-`.md` doc — e.g. a hand-edited
|
|
135
|
-
// `docs/ai/orchestration.json` config — is inherently skipped: never validated for frontmatter / caps.
|
|
136
|
-
// This belt-and-suspenders regression pins that skip so adding a config `.json` under docs/ai can never
|
|
137
|
-
// start failing the docs gate.
|
|
138
|
-
describe('walkMarkdownFiles — only *.md is discovered (a config .json is skipped)', () => {
|
|
139
|
-
let dir;
|
|
140
|
-
beforeEach(async () => {
|
|
141
|
-
dir = await mkdtemp(join(tmpdir(), 'walk-md-test-'));
|
|
142
|
-
});
|
|
143
|
-
afterEach(async () => {
|
|
144
|
-
await rm(dir, { recursive: true, force: true });
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('returns the .md file and NOT a sibling orchestration.json', async () => {
|
|
148
|
-
await writeFile(join(dir, 'doc.md'), '---\ntype: reference\nmaxLines: 100\n---\n\nbody.\n');
|
|
149
|
-
await writeFile(join(dir, 'orchestration.json'), '{ "plan-authoring": { "review": "reviewed" } }\n');
|
|
150
|
-
const found = await walkMarkdownFiles(dir);
|
|
151
|
-
expect(found.some((f) => f.endsWith('doc.md'))).toBe(true);
|
|
152
|
-
expect(found.some((f) => f.endsWith('.json'))).toBe(false);
|
|
153
|
-
expect(found.some((f) => f.endsWith('orchestration.json'))).toBe(false);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// Synthetic row matching the shape produced by `inspectFile` + `formatRow`.
|
|
158
|
-
const makeRow = (path, overrides = {}) => ({
|
|
159
|
-
path,
|
|
160
|
-
lineCount: 50,
|
|
161
|
-
frontmatter: { type: 'reference', maxLines: '100', lastUpdated: '2026-05-29', staleAfter: '30d' },
|
|
162
|
-
errors: [],
|
|
163
|
-
warnings: [],
|
|
164
|
-
...overrides,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// The one-file-per-ADR store collapses to a SINGLE aggregate index row so the index stays under its
|
|
168
|
-
// own 80-line cap no matter how many records accumulate — while every body is still cap-checked.
|
|
169
|
-
describe('buildIndex — docs/ai/adr/ directory collapse (Decision 11)', () => {
|
|
170
|
-
it('200 synthetic AD-*.md records collapse to ONE aggregate row; the index stays ≤ 80 lines', () => {
|
|
171
|
-
const adr = Array.from({ length: 200 }, (_, i) => makeRow(`docs/ai/adr/AD-${String(i + 1).padStart(3, '0')}-record-${i}.md`, { frontmatter: { type: 'adr', maxLines: '400', lastUpdated: '2026-07-09', staleAfter: 'never' } }));
|
|
172
|
-
const rows = [makeRow('docs/ai/handover.md'), makeRow('docs/ai/adr/log.md', { frontmatter: { type: 'reference', maxLines: '200' } }), ...adr];
|
|
173
|
-
const out = buildIndex(rows, '2026-07-09');
|
|
174
|
-
const adrRowLines = out.split('\n').filter((l) => l.includes('](./adr/log.md)'));
|
|
175
|
-
expect(adrRowLines.length).toBe(1); // exactly one row references the whole adr/ tree
|
|
176
|
-
expect(out).not.toMatch(/AD-001-record-0\.md/); // individual records are NOT listed
|
|
177
|
-
expect(out.split('\n').length <= 80).toBe(true);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('a stray adr/ markdown file renders as its OWN visible row (never collapsed/hidden)', () => {
|
|
181
|
-
const rows = [makeRow('docs/ai/adr/AD-001-a.md', { frontmatter: { type: 'adr', maxLines: '400' } }), makeRow('docs/ai/adr/log.md', { frontmatter: { type: 'reference', maxLines: '200' } }), makeRow('docs/ai/adr/notes.md', { frontmatter: { type: 'reference', maxLines: '100' } })];
|
|
182
|
-
const out = buildIndex(rows, '2026-07-09');
|
|
183
|
-
expect(out).toMatch(/adr\/notes\.md/); // the stray is a visible row, not swallowed by the collapse
|
|
184
|
-
const aggregateRows = out.split('\n').filter((l) => l.includes('](./adr/log.md)'));
|
|
185
|
-
expect(aggregateRows.length).toBe(1); // exactly one aggregate row for the real record(s)
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('the aggregate row shows the record count and a NUMERIC id range (AD-200 … AD-1000)', () => {
|
|
189
|
-
const rows = [makeRow('docs/ai/adr/AD-200-a.md', { frontmatter: { type: 'adr', maxLines: '400' } }), makeRow('docs/ai/adr/AD-1000-b.md', { frontmatter: { type: 'adr', maxLines: '400' } }), makeRow('docs/ai/adr/log.md', { frontmatter: { type: 'reference', maxLines: '200' } })];
|
|
190
|
-
const out = buildIndex(rows, '2026-07-09');
|
|
191
|
-
expect(out).toMatch(/\[`adr\/`\]\(\.\/adr\/log\.md\) \| adr \| 2 records \| AD-200 … AD-1000/);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('adding a record drifts the collapse row → checkIndexFreshness flags it stale', () => {
|
|
195
|
-
const base = [makeRow('docs/ai/adr/AD-001-a.md', { frontmatter: { type: 'adr', maxLines: '400' } }), makeRow('docs/ai/adr/log.md', { frontmatter: { type: 'reference', maxLines: '200' } })];
|
|
196
|
-
const onDisk = buildIndex(base, '2026-07-09');
|
|
197
|
-
const grown = [...base, makeRow('docs/ai/adr/AD-002-b.md', { frontmatter: { type: 'adr', maxLines: '400' } })];
|
|
198
|
-
expect(checkIndexFreshness(grown, onDisk).fresh).toBe(false);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('a single adr record OVER its own cap still fails inspectFile (the collapse never hides a fat body)', async () => {
|
|
202
|
-
const dir = await mkdtemp(join(tmpdir(), 'adr-cap-'));
|
|
203
|
-
try {
|
|
204
|
-
const path = join(dir, 'AD-001-huge.md');
|
|
205
|
-
await writeFile(path, `---\ntype: adr\nlastUpdated: 2026-07-09\nscope: permanent\nstaleAfter: never\nowner: none\nmaxLines: 5\n---\n\n## AD-001 — Huge\n${'x\n'.repeat(20)}`);
|
|
206
|
-
const result = await inspectFile(path, computeToday('2026-07-09'));
|
|
207
|
-
expect(result.errors.some((e) => /lines > maxLines/.test(e))).toBe(true);
|
|
208
|
-
} finally {
|
|
209
|
-
await rm(dir, { recursive: true, force: true });
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// The spec store (docs/ai/specs/**) joins the collapse as a second GROUP: every file whose reader
|
|
215
|
-
// verdict is clean folds into ONE counted `specs/` row; a file the reader refuses keeps its own row.
|
|
216
|
-
const SPEC_FRONT = (kind, maxLines, extra = '') =>
|
|
217
|
-
`---\ntype: spec\nlastUpdated: 2026-08-23\nscope: permanent\nstaleAfter: 90d\nowner: none\nmaxLines: ${maxLines}\nkind: ${kind}\n${extra}---\n`;
|
|
218
|
-
const specBody = (slug) =>
|
|
219
|
-
`\n# Spec: ${slug}\n\n## Contract\n\nc\n\n## Scenarios\n\n- S1 a :: test/${slug}.test.mjs :: spec:${slug}/S1\n\n## Out of scope\n\n- b\n\n## Module\n\n- src/${slug}/\n`;
|
|
220
|
-
const specRow = (path, kind, errors = []) => makeRow(path, { frontmatter: { type: 'spec', maxLines: '150' }, spec: { kind, status: 'draft', revision: 1, errors, warnings: [] } });
|
|
221
|
-
const SPECS_ROW_RE = /\| \[`specs\/`\]\(\.\/specs\/index\.md\) \| spec \| (\d+) specs \| (\d+) parts · (\d+) indexes \| — \|/;
|
|
222
|
-
|
|
223
|
-
describe('buildIndex — docs/ai/specs/ store collapse (spec layer 1a)', () => {
|
|
224
|
-
it('1000 valid specs + their indexes render ONE counted specs/ row; the index stays <= 80 lines', () => {
|
|
225
|
-
const specs = Array.from({ length: 1000 }, (_, i) => specRow(`docs/ai/specs/d${Math.floor(i / 30)}/s${i}.md`, 'spec'));
|
|
226
|
-
const indexes = Array.from({ length: 34 }, (_, i) => specRow(`docs/ai/specs/d${i}/index.md`, 'index'));
|
|
227
|
-
const rows = [makeRow('docs/ai/handover.md'), specRow('docs/ai/specs/index.md', 'index'), ...indexes, ...specs];
|
|
228
|
-
const out = buildIndex(rows, '2026-08-23');
|
|
229
|
-
const lines = out.split('\n');
|
|
230
|
-
expect(lines.filter((l) => l.includes('](./specs/index.md)')).length).toBe(1);
|
|
231
|
-
expect(out).not.toMatch(/s999\.md/);
|
|
232
|
-
expect(lines.length <= 80).toBe(true);
|
|
233
|
-
expect(out.match(SPECS_ROW_RE).slice(1)).toEqual(['1000', '0', '35']);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it('the counted row carries live counts per kind; a malformed file under specs/ keeps its OWN visible row beside it', () => {
|
|
237
|
-
const rows = [specRow('docs/ai/specs/index.md', 'index'), specRow('docs/ai/specs/a/index.md', 'spec'), specRow('docs/ai/specs/a/p.md', 'part'), specRow('docs/ai/specs/b.md', 'spec'), specRow('docs/ai/specs/broken.md', null, [{ rule: 'kind', message: 'x' }])];
|
|
238
|
-
const out = buildIndex(rows, '2026-08-23');
|
|
239
|
-
expect(out).toMatch(/specs\/broken\.md/);
|
|
240
|
-
expect(out.match(SPECS_ROW_RE).slice(1)).toEqual(['2', '1', '1']);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('adding or removing one valid spec drifts the counted row -> the on-disk index is stale', () => {
|
|
244
|
-
const base = [specRow('docs/ai/specs/index.md', 'index'), specRow('docs/ai/specs/a.md', 'spec')];
|
|
245
|
-
const onDisk = buildIndex(base, '2026-08-23');
|
|
246
|
-
expect(checkIndexFreshness([...base, specRow('docs/ai/specs/b.md', 'spec')], onDisk).fresh).toBe(false);
|
|
247
|
-
expect(checkIndexFreshness(base.slice(0, 1), onDisk).fresh).toBe(false);
|
|
248
|
-
expect(checkIndexFreshness(base, onDisk).fresh).toBe(true);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it('inspectFile reads a file under docs/ai/specs/ through the reader: clean -> spec verdict, malformed -> advisory warnings only', async () => {
|
|
252
|
-
const root = await mkdtemp(join(tmpdir(), 'specs-inspect-'));
|
|
253
|
-
try {
|
|
254
|
-
await mkdir(join(root, 'docs', 'ai', 'specs'), { recursive: true });
|
|
255
|
-
const clean = join(root, 'docs', 'ai', 'specs', 'login.md');
|
|
256
|
-
await writeFile(clean, `${SPEC_FRONT('spec', 150, 'status: draft\nrevision: 1\n')}${specBody('login')}`);
|
|
257
|
-
const ok = await inspectFile(clean, computeToday('2026-08-23'), root);
|
|
258
|
-
expect(ok.errors).toEqual([]);
|
|
259
|
-
expect(ok.spec.kind).toBe('spec');
|
|
260
|
-
expect(ok.spec.errors).toEqual([]);
|
|
261
|
-
const malformed = join(root, 'docs', 'ai', 'specs', 'broken.md');
|
|
262
|
-
await writeFile(malformed, `${SPEC_FRONT('spec', 150, 'status: draft\nrevision: 1\n')}${specBody('login')}`);
|
|
263
|
-
const bad = await inspectFile(malformed, computeToday('2026-08-23'), root);
|
|
264
|
-
expect(bad.errors).toEqual([]);
|
|
265
|
-
expect(bad.spec.errors.map((e) => e.rule)).toEqual(['scenario-marker']);
|
|
266
|
-
expect(bad.warnings.some((w) => /spec scenario-marker/.test(w))).toBe(true);
|
|
267
|
-
await writeFile(join(root, 'docs', 'ai', 'handover.md'), `${SPEC_FRONT('spec', 150)}\n# outside the store\n`);
|
|
268
|
-
expect((await inspectFile(join(root, 'docs', 'ai', 'handover.md'), computeToday('2026-08-23'), root)).spec).toBe(null);
|
|
269
|
-
} finally {
|
|
270
|
-
await rm(root, { recursive: true, force: true });
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
describe('buildIndex', () => {
|
|
276
|
-
it('is deterministic, sorts rows by path, and excludes index.md itself', () => {
|
|
277
|
-
const rows = [makeRow('docs/ai/index.md'), makeRow('docs/ai/b.md'), makeRow('docs/ai/a.md')];
|
|
278
|
-
const out = buildIndex(rows, '2026-05-29');
|
|
279
|
-
expect(out).toBe(buildIndex(rows, '2026-05-29')); // deterministic
|
|
280
|
-
expect(out).not.toMatch(/\[`index\.md`\]/); // index.md row excluded
|
|
281
|
-
expect(out.indexOf('a.md')).toBeLessThan(out.indexOf('b.md')); // sorted
|
|
282
|
-
expect(out).toMatch(/lastUpdated: 2026-05-29/); // header date is the argument
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// `checkIndexFreshness` drives the `--check-index` exit code:
|
|
287
|
-
// fresh === true → script exits 0
|
|
288
|
-
// fresh === false → script exits 1 ("index stale, regenerate with --write-index")
|
|
289
|
-
describe('checkIndexFreshness', () => {
|
|
290
|
-
const rows = [makeRow('docs/ai/a.md'), makeRow('docs/ai/b.md')];
|
|
291
|
-
|
|
292
|
-
it('reports fresh when on-disk matches the regenerated index (→ exit 0)', () => {
|
|
293
|
-
const onDisk = buildIndex(rows, '2026-05-29');
|
|
294
|
-
expect(checkIndexFreshness(rows, onDisk).fresh).toBe(true);
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
it('reports stale when a source row drifted, e.g. line count changed (→ exit 1)', () => {
|
|
298
|
-
const onDisk = buildIndex(rows, '2026-05-29');
|
|
299
|
-
const drifted = [makeRow('docs/ai/a.md', { lineCount: 999 }), makeRow('docs/ai/b.md')];
|
|
300
|
-
expect(checkIndexFreshness(drifted, onDisk).fresh).toBe(false);
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
it('reports stale when index.md is missing entirely (→ exit 1)', () => {
|
|
304
|
-
expect(checkIndexFreshness(rows, null).fresh).toBe(false);
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it('does NOT flag stale on a mere day-rollover with unchanged content (uses on-disk header date)', () => {
|
|
308
|
-
const onDisk = buildIndex(rows, '2026-05-01'); // index regenerated weeks ago
|
|
309
|
-
// Same source rows, "today" is later — content unchanged, so it must stay fresh.
|
|
310
|
-
expect(checkIndexFreshness(rows, onDisk).fresh).toBe(true);
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
// ── (h) — root-parameterization: the ADR-rotation hook regenerates ANOTHER root's index ────
|
|
315
|
-
// The generator's module ROOT is the CLI default only; --root / regenerateIndex(root) target an
|
|
316
|
-
// arbitrary tree so the rotation hook (and hermetic tests) never touch the real repo.
|
|
317
|
-
describe('root parameterization (item (h))', () => {
|
|
318
|
-
let root;
|
|
319
|
-
beforeEach(async () => {
|
|
320
|
-
root = await mkdtemp(join(tmpdir(), 'check-docs-root-'));
|
|
321
|
-
await mkdir(join(root, 'docs', 'ai'), { recursive: true });
|
|
322
|
-
});
|
|
323
|
-
afterEach(async () => {
|
|
324
|
-
await rm(root, { recursive: true, force: true });
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
const seedDoc = (name, extra = '') =>
|
|
328
|
-
writeFile(join(root, 'docs', 'ai', name), `---\ntype: reference\nlastUpdated: 2026-07-08\nscope: permanent\nstaleAfter: 30d\nowner: none\nmaxLines: 100\n---\n\n# ${name}\n${extra}`);
|
|
329
|
-
|
|
330
|
-
it('inspectFile computes the file path RELATIVE to the passed root (not the module ROOT)', async () => {
|
|
331
|
-
await seedDoc('handover.md');
|
|
332
|
-
const result = await inspectFile(join(root, 'docs', 'ai', 'handover.md'), computeToday('2026-07-08'), root);
|
|
333
|
-
expect(result.path).toBe('docs/ai/handover.md');
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
it('regenerateIndex(root, today) writes THAT root\'s docs/ai/index.md from its frontmatter', async () => {
|
|
337
|
-
await seedDoc('a.md');
|
|
338
|
-
await seedDoc('b.md');
|
|
339
|
-
const res = await regenerateIndex(root, '2026-07-08');
|
|
340
|
-
expect(res.indexPath).toBe(join(root, 'docs', 'ai', 'index.md'));
|
|
341
|
-
expect(existsSync(res.indexPath)).toBe(true);
|
|
342
|
-
const index = await readFile(res.indexPath, 'utf8');
|
|
343
|
-
expect(index).toMatch(/lastUpdated: 2026-07-08/); // header date is the argument
|
|
344
|
-
expect(index).toMatch(/a\.md/);
|
|
345
|
-
expect(index).toMatch(/b\.md/);
|
|
346
|
-
expect(index).not.toMatch(/\[`index\.md`\]/); // the index never lists itself
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it('a re-run with unchanged sources is byte-identical (deterministic, --check-index safe)', async () => {
|
|
350
|
-
await seedDoc('a.md');
|
|
351
|
-
const first = await regenerateIndex(root, '2026-07-08');
|
|
352
|
-
const bytesA = await readFile(first.indexPath, 'utf8');
|
|
353
|
-
await regenerateIndex(root, '2026-07-08');
|
|
354
|
-
const bytesB = await readFile(first.indexPath, 'utf8');
|
|
355
|
-
expect(bytesB).toBe(bytesA);
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
// The CLI entry (main) over --root — a subprocess smoke so the --help usage + the --check-index
|
|
359
|
-
// fresh/stale branches (root-parameterized) are exercised end-to-end.
|
|
360
|
-
const SCRIPT = fileURLToPath(new URL('./check-docs-size.mjs', import.meta.url));
|
|
361
|
-
const runCli = (args) => spawnSync(process.execPath, [SCRIPT, ...args], { encoding: 'utf8' });
|
|
362
|
-
|
|
363
|
-
it('--help prints the usage (naming --root) and exits 0', () => {
|
|
364
|
-
const r = runCli(['--help']);
|
|
365
|
-
expect(r.status).toBe(0);
|
|
366
|
-
expect(r.stdout).toMatch(/--root=/);
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
it('--check-index --root: a fresh index is OK (exit 0); a drifted one is stale (exit 1)', async () => {
|
|
370
|
-
await seedDoc('a.md');
|
|
371
|
-
expect(runCli(['--write-index', `--root=${root}`]).status).toBe(0);
|
|
372
|
-
const fresh = runCli(['--check-index', `--root=${root}`]);
|
|
373
|
-
expect(fresh.status).toBe(0);
|
|
374
|
-
expect(fresh.stdout).toMatch(/in sync/);
|
|
375
|
-
await seedDoc('b.md'); // a new source row drifts the on-disk index
|
|
376
|
-
const stale = runCli(['--check-index', `--root=${root}`]);
|
|
377
|
-
expect(stale.status).toBe(1);
|
|
378
|
-
expect(stale.stderr).toMatch(/stale/);
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
it('the hook path over a real specs/ store: ONE counted row in the written index, a new spec makes --check-index exit 1', async () => {
|
|
382
|
-
const store = join(root, 'docs', 'ai', 'specs');
|
|
383
|
-
await mkdir(store, { recursive: true });
|
|
384
|
-
await writeFile(join(store, 'index.md'), `${SPEC_FRONT('index', 80)}\n# Specs\n\n> Up: [technical_specification.md](../technical_specification.md)\n\n## Children\n\n- [login](./login.md)\n`);
|
|
385
|
-
await writeFile(join(store, 'login.md'), `${SPEC_FRONT('spec', 150, 'status: draft\nrevision: 1\n')}${specBody('login')}`);
|
|
386
|
-
expect(runCli(['--write-index', `--root=${root}`]).status).toBe(0);
|
|
387
|
-
const index = await readFile(join(root, 'docs', 'ai', 'index.md'), 'utf8');
|
|
388
|
-
expect(index.match(SPECS_ROW_RE).slice(1)).toEqual(['1', '0', '1']);
|
|
389
|
-
expect(index).not.toMatch(/specs\/login\.md/);
|
|
390
|
-
expect(runCli(['--check-index', `--root=${root}`]).status).toBe(0);
|
|
391
|
-
await writeFile(join(store, 'signup.md'), `${SPEC_FRONT('spec', 150, 'status: draft\nrevision: 1\n')}${specBody('signup')}`);
|
|
392
|
-
expect(runCli(['--check-index', `--root=${root}`]).status).toBe(1);
|
|
393
|
-
expect(runCli([`--root=${root}`]).status).toBe(0);
|
|
394
|
-
});
|
|
395
|
-
});
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
// install-git-hooks-repo-exec.test.mjs — the SIBLING installer executed IN PLACE (no deploy
|
|
2
|
-
// copy): GIT_DIR pins every git answer to a fixture repo, so the run exercises this tree's own
|
|
3
|
-
// file — the D3(d) changed-line check reads real executions of the shipped bytes, while the
|
|
4
|
-
// deploy-copy suite (install-git-hooks.test.mjs) keeps the consumer-shaped behavior pins. Every
|
|
5
|
-
// branch of the installer runs from here: fresh install, the guard arm/carry/disable/conflict
|
|
6
|
-
// lanes, the rules-check and layout-check arm/carry/duplicate/refusal lanes (win32 included), the
|
|
7
|
-
// unmanaged refusal, the up-to-date short-circuit, the not-a-git-checkout skip, and the S71
|
|
8
|
-
// real-commit lane (real `git commit` through the written hook over stand-in scripts). Every child
|
|
9
|
-
// runs with each inherited GIT_* variable stripped, so a hook's environment never leaks in.
|
|
10
|
-
|
|
11
|
-
import { describe, it } from 'node:test';
|
|
12
|
-
import assert from 'node:assert/strict';
|
|
13
|
-
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync, realpathSync, chmodSync, statSync } from 'node:fs';
|
|
14
|
-
import { tmpdir } from 'node:os';
|
|
15
|
-
import { join, dirname } from 'node:path';
|
|
16
|
-
import { fileURLToPath } from 'node:url';
|
|
17
|
-
import { spawnSync } from 'node:child_process';
|
|
18
|
-
|
|
19
|
-
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
20
|
-
const INSTALLER = join(HERE, 'install-git-hooks.mjs');
|
|
21
|
-
const WIN32 = ['--import', 'data:text/javascript,Object.defineProperty(process,"platform",{value:"win32"})'];
|
|
22
|
-
const BACKSLASH = String.fromCharCode(92);
|
|
23
|
-
const shown = (path) => (process.platform === 'win32' ? path.replaceAll(BACKSLASH, '/') : path);
|
|
24
|
-
|
|
25
|
-
const BASE_ENV = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^[Gg][Ii][Tt]_/.test(key)));
|
|
26
|
-
const envAt = (home, extra = {}) => ({
|
|
27
|
-
...BASE_ENV, HOME: home, XDG_CONFIG_HOME: join(home, '.config'), LC_ALL: 'C', GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_SYSTEM: '/dev/null',
|
|
28
|
-
GIT_CONFIG_NOSYSTEM: '1', GIT_ATTR_NOSYSTEM: '1', ...extra,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// A child that never started or was killed has no exit status to judge — it fails the cell outright.
|
|
32
|
-
const spawnChecked = (command, args, options) => {
|
|
33
|
-
const r = spawnSync(command, args, { encoding: 'utf8', ...options });
|
|
34
|
-
if (r.error) throw r.error;
|
|
35
|
-
if (r.signal !== null) throw new Error(`${command} was killed by ${r.signal}`);
|
|
36
|
-
return r;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const mkRepo = () => {
|
|
40
|
-
const root = realpathSync(mkdtempSync(join(tmpdir(), 'hooks-repo-exec-')));
|
|
41
|
-
assert.equal(spawnChecked('git', ['init', '-q'], { cwd: root, env: envAt(root) }).status, 0);
|
|
42
|
-
writeFileSync(join(root, 'guard.mjs'), '// a stand-in commit-guard tool\n');
|
|
43
|
-
return { root, gitDir: join(root, '.git') };
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// The installer anchors its git queries at its OWN parent dir — GIT_DIR overrides that anchor to
|
|
47
|
-
// the fixture repo, so running the in-place file NEVER touches this tree's hooks.
|
|
48
|
-
const runAt = (gitDir, args = [], pre = []) =>
|
|
49
|
-
spawnChecked(process.execPath, [...pre, INSTALLER, ...args], { env: envAt(dirname(gitDir), { GIT_DIR: gitDir }) });
|
|
50
|
-
|
|
51
|
-
const hookOf = ({ gitDir }) => readFileSync(join(gitDir, 'hooks', 'pre-commit'), 'utf8');
|
|
52
|
-
const stub = (root, rel) => (mkdirSync(dirname(join(root, rel)), { recursive: true }), writeFileSync(join(root, rel), '// a stand-in tool\n'), join(root, rel));
|
|
53
|
-
|
|
54
|
-
describe('install-git-hooks — the in-place installer under a GIT_DIR-pinned fixture', () => {
|
|
55
|
-
it('installs the managed hook, is idempotent, and refuses an UNMANAGED hook', () => {
|
|
56
|
-
const fx = mkRepo();
|
|
57
|
-
assert.equal(runAt(fx.gitDir).status, 0);
|
|
58
|
-
assert.match(hookOf(fx), /:install-git-hooks\.mjs/, 'the managed marker is written');
|
|
59
|
-
const again = runAt(fx.gitDir);
|
|
60
|
-
assert.equal(again.status, 0);
|
|
61
|
-
assert.match(again.stdout, /already up to date/);
|
|
62
|
-
writeFileSync(join(fx.gitDir, 'hooks', 'pre-commit'), '#!/bin/sh\nexit 0\n');
|
|
63
|
-
const refused = runAt(fx.gitDir);
|
|
64
|
-
assert.equal(refused.status, 1, 'an unmanaged hook is never overwritten');
|
|
65
|
-
assert.match(refused.stderr, /Refusing to overwrite/);
|
|
66
|
-
rmSync(fx.root, { recursive: true, force: true });
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('the guard lanes: arm (absolute path) → carry on flagless re-run → consented disable', () => {
|
|
70
|
-
const fx = mkRepo();
|
|
71
|
-
assert.equal(runAt(fx.gitDir, ['--commit-guard', join(fx.root, 'guard.mjs')]).status, 0);
|
|
72
|
-
assert.match(hookOf(fx), /guard\.mjs" --check/);
|
|
73
|
-
assert.equal(runAt(fx.gitDir).status, 0, 'the flagless re-run keeps the armed line');
|
|
74
|
-
assert.match(hookOf(fx), /guard\.mjs" --check/);
|
|
75
|
-
assert.equal(runAt(fx.gitDir, ['--no-commit-guard']).status, 0);
|
|
76
|
-
assert.doesNotMatch(hookOf(fx), /" --check$/m);
|
|
77
|
-
rmSync(fx.root, { recursive: true, force: true });
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('the guard refusals: both flags (usage), a bare flag (usage), a missing path, a duplicated line', () => {
|
|
81
|
-
const fx = mkRepo();
|
|
82
|
-
assert.equal(runAt(fx.gitDir, ['--commit-guard', join(fx.root, 'guard.mjs'), '--no-commit-guard']).status, 2);
|
|
83
|
-
assert.equal(runAt(fx.gitDir, ['--commit-guard']).status, 2, '--commit-guard without a path is a usage error');
|
|
84
|
-
assert.equal(runAt(fx.gitDir, ['--commit-guard', join(fx.root, 'no-such.mjs')]).status, 1, 'a nonexistent guard path refuses');
|
|
85
|
-
assert.equal(runAt(fx.gitDir, ['--commit-guard', join(fx.root, 'guard.mjs')]).status, 0);
|
|
86
|
-
const armed = hookOf(fx);
|
|
87
|
-
const guardLine = armed.split('\n').find((l) => /" --check$/.test(l));
|
|
88
|
-
writeFileSync(join(fx.gitDir, 'hooks', 'pre-commit'), `${armed}${guardLine}\n`);
|
|
89
|
-
const dup = runAt(fx.gitDir);
|
|
90
|
-
assert.equal(dup.status, 1, 'two guard lines are ambiguous — fail closed');
|
|
91
|
-
assert.match(dup.stderr, /commit-guard --check lines/);
|
|
92
|
-
rmSync(fx.root, { recursive: true, force: true });
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('the role lanes: arm both beside the guard in order → carry → duplicate fails closed; each refusal writes nothing', () => {
|
|
96
|
-
const fx = mkRepo();
|
|
97
|
-
const [rules, layout, guard] = ['t/rules-cli.mjs', 't/source-size-check.mjs', 'guard.mjs'].map((rel) => stub(fx.root, rel));
|
|
98
|
-
const ok = (args, pre) => { const r = runAt(fx.gitDir, args, pre); assert.equal(r.status, 0, r.stderr); return r; };
|
|
99
|
-
ok(['--commit-guard', guard, '--layout-check', layout, '--rules-check', rules]);
|
|
100
|
-
const tail = `node "${shown(rules)}" --check # rules-check\nnode "${shown(layout)}" --check # layout-check\nnode "${guard}" --check\n`;
|
|
101
|
-
assert.ok(hookOf(fx).endsWith(`node --test scripts/*.test.mjs\n${tail}`), hookOf(fx));
|
|
102
|
-
assert.match(ok([]).stdout, /already up to date/, 'the flagless re-run carries all three');
|
|
103
|
-
const before = hookOf(fx);
|
|
104
|
-
const cases = [
|
|
105
|
-
[['--rules-check', layout], 2], [['--layout-check', rules], 2], [['--rules-check'], 2], [['--layout-check'], 2],
|
|
106
|
-
[['--layout-check', join(fx.root, 'a$b', 'source-size-check.mjs')], 2], [['--rules-check', join(fx.root, 'no', 'rules-cli.mjs')], 1],
|
|
107
|
-
...(process.platform === 'win32' ? [] : [[['--rules-check', `${fx.root}/w${BACKSLASH}x/rules-cli.mjs`], 2]]),
|
|
108
|
-
];
|
|
109
|
-
for (const [args, status] of cases) {
|
|
110
|
-
const r = runAt(fx.gitDir, args);
|
|
111
|
-
assert.equal(r.status, status, `${JSON.stringify(args)}: ${r.stderr}`);
|
|
112
|
-
assert.equal(hookOf(fx), before, `${JSON.stringify(args)} wrote nothing`);
|
|
113
|
-
}
|
|
114
|
-
const winArmed = stub(fx.root, 'w/x/rules-cli.mjs');
|
|
115
|
-
ok(['--rules-check', `${fx.root}/w${BACKSLASH}x/rules-cli.mjs`], WIN32);
|
|
116
|
-
assert.ok(hookOf(fx).includes(`node "${shown(winArmed)}" --check # rules-check\n`), 'the win32 path arms with / separators');
|
|
117
|
-
const winHook = hookOf(fx);
|
|
118
|
-
writeFileSync(join(fx.gitDir, 'hooks', 'pre-commit'), `${winHook}node "${layout}" --check # layout-check\n`);
|
|
119
|
-
const dup = runAt(fx.gitDir);
|
|
120
|
-
assert.equal(dup.status, 1, dup.stderr);
|
|
121
|
-
assert.match(dup.stderr, /carries 2 layout-check lines/);
|
|
122
|
-
rmSync(fx.root, { recursive: true, force: true });
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('outside a git checkout the installer SKIPS loudly and writes nothing', () => {
|
|
126
|
-
const nowhere = mkdtempSync(join(tmpdir(), 'hooks-repo-exec-nogit-'));
|
|
127
|
-
const r = runAt(join(nowhere, 'absent-git-dir'));
|
|
128
|
-
assert.equal(r.status, 0);
|
|
129
|
-
assert.match(r.stdout, /skipping \(not a git checkout\)/);
|
|
130
|
-
assert.equal(existsSync(join(nowhere, 'absent-git-dir')), false, 'nothing was created');
|
|
131
|
-
rmSync(nowhere, { recursive: true, force: true });
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
// The commit lane also drops NODE_TEST_CONTEXT: an inherited one makes the hook's nested `node --test` skip every file.
|
|
136
|
-
const IDENTITY = { GIT_AUTHOR_NAME: 'p', GIT_AUTHOR_EMAIL: 'p@e', GIT_COMMITTER_NAME: 'p', GIT_COMMITTER_EMAIL: 'p@e' };
|
|
137
|
-
const bareAt = (home, extra = {}) => { const { NODE_TEST_CONTEXT: _, ...env } = envAt(home, { ...IDENTITY, ...extra }); return env; };
|
|
138
|
-
const passes = (r) => (assert.equal(r.status, 0, r.stderr), r);
|
|
139
|
-
|
|
140
|
-
// Passing stand-ins for every script the hook runs; check-docs-size.mjs, run right after the local line, records
|
|
141
|
-
// whether the marker existed. The marker and the record live in a sibling dir, outside the work tree.
|
|
142
|
-
const commitRepo = (root, side) => {
|
|
143
|
-
const [marker, record, local] = [join(side, 'marker'), join(side, 'record'), join(root, 'scripts', 'pre-commit.local')];
|
|
144
|
-
const git = (...args) => spawnChecked('git', args, { cwd: root, env: bareAt(root) });
|
|
145
|
-
mkdirSync(join(root, 'scripts'));
|
|
146
|
-
writeFileSync(join(root, 'scripts', 'check-docs-size.mjs'), `import { existsSync, writeFileSync } from 'node:fs';
|
|
147
|
-
if (!process.argv.includes('--check-index')) writeFileSync(${JSON.stringify(record)}, String(existsSync(${JSON.stringify(marker)})));\n`);
|
|
148
|
-
for (const name of ['archive-changelog', 'archive-issues', 'archive-decisions']) writeFileSync(join(root, 'scripts', `${name}.mjs`), 'process.exit(0);\n');
|
|
149
|
-
writeFileSync(join(root, 'scripts', 'stand-in.test.mjs'), "import { test } from 'node:test';\ntest('a passing stand-in', () => {});\n");
|
|
150
|
-
for (const args of [['init', '-q'], ['add', '-A'], ['commit', '-qm', 'base']]) passes(git(...args));
|
|
151
|
-
passes(spawnChecked(process.execPath, [INSTALLER], { env: bareAt(root, { GIT_DIR: join(root, '.git') }) }));
|
|
152
|
-
const head = () => git('rev-parse', 'HEAD').stdout.trim();
|
|
153
|
-
const commit = (body) => {
|
|
154
|
-
if (body !== undefined) { writeFileSync(local, body); chmodSync(local, 0o644); assert.equal(statSync(local).mode & 0o111, 0, 'the local file is not executable'); }
|
|
155
|
-
writeFileSync(join(root, 'change.txt'), 'change\n');
|
|
156
|
-
passes(git('add', 'change.txt'));
|
|
157
|
-
return git('commit', '-qm', 'change');
|
|
158
|
-
};
|
|
159
|
-
return { marker, record, head, commit };
|
|
160
|
-
};
|
|
161
|
-
const inCommitRepo = (cell) => () => {
|
|
162
|
-
const dirs = ['hooks-commit-', 'hooks-commit-side-'].map((prefix) => realpathSync(mkdtempSync(join(tmpdir(), prefix))));
|
|
163
|
-
try { cell(commitRepo(...dirs)); } finally { for (const dir of dirs) rmSync(dir, { recursive: true, force: true }); }
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
describe('spec:init-project/S71 the local hook file through real commits over stand-ins', () => {
|
|
167
|
-
it('a local file that writes a marker runs before the docs check, and the commit exits 0', { timeout: 120_000 }, inCommitRepo((fx) => {
|
|
168
|
-
passes(fx.commit(`printf made > "${fx.marker}"\n`));
|
|
169
|
-
assert.ok(existsSync(fx.marker), 'the local file ran: its marker appeared');
|
|
170
|
-
assert.equal(readFileSync(fx.record, 'utf8'), 'true', 'the marker existed when check-docs-size.mjs ran');
|
|
171
|
-
}));
|
|
172
|
-
|
|
173
|
-
it('a local file that exits 1 stops the commit: non-zero, no new commit', { timeout: 120_000 }, inCommitRepo((fx) => {
|
|
174
|
-
const before = fx.head();
|
|
175
|
-
assert.notEqual(fx.commit('exit 1\n').status, 0, 'a local file exiting 1 stops the commit');
|
|
176
|
-
assert.equal(fx.head(), before, 'no new commit');
|
|
177
|
-
}));
|
|
178
|
-
|
|
179
|
-
it('with no local file the commit exits 0', { timeout: 120_000 }, inCommitRepo((fx) => {
|
|
180
|
-
const before = fx.head();
|
|
181
|
-
passes(fx.commit());
|
|
182
|
-
assert.notEqual(fx.head(), before, 'the commit landed');
|
|
183
|
-
assert.equal(readFileSync(fx.record, 'utf8'), 'false', 'the hook ran its stand-ins, with no marker');
|
|
184
|
-
}));
|
|
185
|
-
});
|