-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparity-sync.test.ts
More file actions
105 lines (94 loc) · 3.77 KB
/
Copy pathparity-sync.test.ts
File metadata and controls
105 lines (94 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { describe, expect, it } from 'vitest'
import { categories } from './parity-data'
import { parseDeferredFlags, readParityMd } from './parity-sync'
describe('parseDeferredFlags', () => {
it('joins soft-wrapped bullets and extracts the command + flags', () => {
const markdown = [
'### Deferred flags (tracked follow-ups, not silently dropped)',
'',
'Intro text.',
'',
'- `log -p` / `--stat` / `--decorate` / `--author` / `--grep` / `--since` /',
' `--until` / `--no-merges` / `--first-parent` / `--all` — needs the log',
' renderer + walk extensions.',
'- `diff -w` / `-b` / `-U<n>` — whitespace and context-line control.',
'',
'### Next section',
'',
'- not part of the deferred-flags list',
].join('\n')
const entries = parseDeferredFlags(markdown)
expect(entries).toEqual([
{
command: 'log',
flags: [
'-p',
'--stat',
'--decorate',
'--author',
'--grep',
'--since',
'--until',
'--no-merges',
'--first-parent',
'--all',
],
text: '`log -p` / `--stat` / `--decorate` / `--author` / `--grep` / `--since` / `--until` / `--no-merges` / `--first-parent` / `--all` — needs the log renderer + walk extensions.',
},
{
command: 'diff',
flags: ['-w', '-b', '-U<n>'],
text: '`diff -w` / `-b` / `-U<n>` — whitespace and context-line control.',
},
])
})
it('excludes bullets with prose before the em dash (a caveated sub-behavior, not a bare missing flag)', () => {
const markdown = [
'### Deferred flags (tracked follow-ups, not silently dropped)',
'',
'- `reset --mixed` "Unstaged changes after reset:" file list — needs a',
" worktree-vs-target-tree diff; `--hard`'s `HEAD is now at …` ships, `--mixed`",
' is otherwise silent.',
].join('\n')
expect(parseDeferredFlags(markdown)).toEqual([])
})
it('excludes bullets that name display commands rather than a git subcommand + flag', () => {
const markdown = [
'### Deferred flags (tracked follow-ups, not silently dropped)',
'',
'- color for `status` / `log` / `branch` (see above).',
].join('\n')
expect(parseDeferredFlags(markdown)).toEqual([])
})
it('throws a clear error if the heading is missing (section renamed/moved)', () => {
expect(() => parseDeferredFlags('# some other doc\n')).toThrow(/Deferred flags/)
})
it('parses the real docs/PARITY.md deferred-flags section', () => {
const entries = parseDeferredFlags(readParityMd())
// This is the load-bearing sanity check: if PARITY.md's deferred-flags
// list changes shape, this test documents exactly which commands the
// sync check currently derives from it.
expect(entries.map((e) => e.command).toSorted()).toEqual(['add', 'branch', 'log'])
})
})
describe('parity-data.ts stays in sync with docs/PARITY.md deferred flags', () => {
const deferred = parseDeferredFlags(readParityMd())
it('never renders a command with deferred flags as unqualified `parity` status', () => {
const violations: string[] = []
for (const category of categories) {
for (const item of category.items) {
if (item.status !== 'parity') continue
const names = item.cmd.split('/').map((s) => s.trim())
for (const entry of deferred) {
if (names.includes(entry.command)) {
violations.push(
`apps/web/src/lib/parity-data.ts: "${item.cmd}" is marked 'parity' but docs/PARITY.md defers ` +
`${entry.command} flags (${entry.flags.join(', ')}) — downgrade the status or update the note.`,
)
}
}
}
}
expect(violations).toEqual([])
})
})