fix(cli): node <symbol> -f <file> includes the source body (#1314)
The CLI's bare-symbol branch passes includeCode=true to the codegraph_node handler, but the symbol-pinned-to-file branch didn't — so exactly when a user disambiguated an overloaded name to one file (the point of -f), they got Location + trail with no code (#1284). Fixes #1284 Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
8dcf92f285
commit
ce983a08fe
@@ -78,3 +78,42 @@ describe('codegraph node — argument handling (#1044)', () => {
|
||||
expect(stderr).not.toMatch(/missing required argument/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('codegraph node — symbol pinned to a file includes the body (#1284)', () => {
|
||||
let tempDir: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-node-pin-'));
|
||||
fs.mkdirSync(path.join(tempDir, 'a'));
|
||||
fs.mkdirSync(path.join(tempDir, 'b'));
|
||||
// Two same-named definitions, so `-f` is genuinely disambiguating.
|
||||
fs.writeFileSync(
|
||||
path.join(tempDir, 'a', 'state.ts'),
|
||||
'export function setState(x: number): void {\n console.log("A", x);\n}\n'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(tempDir, 'b', 'state.ts'),
|
||||
'export function setState(y: string): void {\n console.log("B", y);\n}\n'
|
||||
);
|
||||
const cg = CodeGraph.initSync(tempDir);
|
||||
await cg.indexAll();
|
||||
cg.close();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('`node <symbol> -f <file>` prints the pinned definition WITH its source body', () => {
|
||||
// The exact #1284 shape: `-f` narrowed the overload correctly but printed
|
||||
// only Location + trail — no code fence — so the user had nothing to read.
|
||||
const { stdout, code } = runNode(tempDir, ['setState', '-f', 'a/state.ts']);
|
||||
expect(code).toBe(0);
|
||||
expect(stdout).toContain('a/state.ts');
|
||||
// The body is present (line-numbered fence), and it's the pinned overload.
|
||||
expect(stdout).toMatch(/1\s+export function setState\(x: number\)/);
|
||||
expect(stdout).toContain('console.log("A", x)');
|
||||
// The other file's overload is not what was pinned.
|
||||
expect(stdout).not.toContain('console.log("B", y)');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user