Skip to content

Commit c5b9a34

Browse files
committed
docs: fix stale codegraph check flag names in recommended-practices.md
--no-new-cycles, --max-blast-radius, and --no-boundary-violations were renamed to --cycles, --blast-radius, and --boundaries respectively; the docs examples still referenced the old names. Also drop the fabricated --max-complexity predicate (no such check flag exists) and add --signatures to the documented predicate list. Add a regression test that derives the valid flag set from the check command's own option definitions so future renames fail the test instead of drifting silently again.
1 parent 0d7e8e6 commit c5b9a34

2 files changed

Lines changed: 78 additions & 3 deletions

File tree

docs/guides/recommended-practices.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ Use `check` for pass/fail CI validation with configurable predicates:
149149
- name: Validate changes
150150
run: |
151151
npx codegraph build
152-
npx codegraph check --staged --no-new-cycles --max-blast-radius 50 --no-boundary-violations -T
152+
npx codegraph check --staged --cycles --blast-radius 50 --boundaries -T
153153
```
154154

155-
Combine multiple predicates — exit code 1 if any fails. Available predicates: `--no-new-cycles`, `--max-complexity <n>`, `--max-blast-radius <n>`, `--no-boundary-violations`.
155+
Combine multiple predicates — exit code 1 if any fails. Available predicates: `--cycles`, `--blast-radius <n>`, `--signatures`, `--boundaries`.
156156

157157
### Caching the graph database
158158

@@ -690,7 +690,7 @@ codegraph co-change --analyze
690690
codegraph check -T
691691
692692
# 8. (Optional) Set up CI validation gate
693-
# codegraph check --staged --no-new-cycles --max-blast-radius 50 -T
693+
# codegraph check --staged --cycles --blast-radius 50 -T
694694
695695
# 9. (Optional) Build embeddings for semantic search
696696
codegraph embed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Regression test for issue #1842: docs/guides/recommended-practices.md
3+
* referenced `codegraph check` predicate flags (`--no-new-cycles`,
4+
* `--max-blast-radius`, `--no-boundary-violations`) that were renamed to
5+
* `--cycles`, `--blast-radius`, `--boundaries` (plus `--signatures`, which
6+
* was never documented at all) and never updated.
7+
*
8+
* Rather than pin the doc to today's flag names, this derives the valid
9+
* flag set from `command.options` in src/cli/commands/check.ts — the single
10+
* source of truth — so a future rename that isn't reflected in the doc
11+
* fails here instead of silently drifting again.
12+
*/
13+
import { readFileSync } from 'node:fs';
14+
import path from 'node:path';
15+
import { describe, expect, it } from 'vitest';
16+
import { command as checkCommand } from '../../src/cli/commands/check.js';
17+
18+
const DOC_PATH = path.join(__dirname, '../../docs/guides/recommended-practices.md');
19+
20+
/** Extract long-form flag names (e.g. "--blast-radius") from a commander option tuple's flags string. */
21+
function longFlagNames(flags: string): string[] {
22+
return flags
23+
.split(',')
24+
.map((part) => part.trim())
25+
.filter((part) => part.startsWith('--'))
26+
.map((part) => part.split(/\s/)[0]);
27+
}
28+
29+
function validCheckFlags(): Set<string> {
30+
const valid = new Set<string>();
31+
for (const option of checkCommand.options) {
32+
const flags = option[0];
33+
for (const name of longFlagNames(flags)) {
34+
valid.add(name);
35+
}
36+
}
37+
return valid;
38+
}
39+
40+
/** Pull every `--flag`-shaped token out of `codegraph check ...` example lines. */
41+
function flagsUsedInCheckExamples(doc: string): string[] {
42+
const flags: string[] = [];
43+
for (const line of doc.split('\n')) {
44+
if (!/codegraph check\b/.test(line)) continue;
45+
for (const match of line.matchAll(/--[a-zA-Z][a-zA-Z-]*/g)) {
46+
flags.push(match[0]);
47+
}
48+
}
49+
return flags;
50+
}
51+
52+
describe('docs/guides/recommended-practices.md check flag references (#1842)', () => {
53+
const doc = readFileSync(DOC_PATH, 'utf-8');
54+
const valid = validCheckFlags();
55+
56+
it('does not reference known-stale codegraph check flag names', () => {
57+
const stale = [
58+
'--no-new-cycles',
59+
'--max-blast-radius',
60+
'--no-boundary-violations',
61+
'--max-complexity',
62+
];
63+
for (const flag of stale) {
64+
expect(doc).not.toContain(flag);
65+
}
66+
});
67+
68+
it('only references check flags that exist on the check command', () => {
69+
const used = flagsUsedInCheckExamples(doc);
70+
expect(used.length).toBeGreaterThan(0);
71+
for (const flag of used) {
72+
expect(valid.has(flag)).toBe(true);
73+
}
74+
});
75+
});

0 commit comments

Comments
 (0)