fix: scope codegraph batch complexity targets to file paths#1808
Conversation
BATCH_COMMANDS entries with sig: 'dbOnly' (currently only complexity) always wrote their target into opts.target. complexityData treats opts.target as a symbol-name filter and opts.file as the file-path filter, so batch complexity <file> never matched anything and the function list silently fell back to empty with a whole-repo summary regardless of which file was requested. Add an optional targetKey on BatchCommandEntry so each dbOnly command can declare which opts key its targets map to, and set it to 'file' for complexity. batchData and multiBatchData now route the target through the declared key instead of assuming opts.target. Fixes #1721 Impact: 4 functions changed, 6 affected
Greptile SummaryThis PR fixes a silent bug where
Confidence Score: 5/5Safe to merge — the change is a narrow, well-tested routing fix with no new external surface and no schema changes. The fix is minimal: one new optional field on an internal interface, one small helper function, and two call-site updates. Both batch entry points (batchData and multiBatchData) are updated consistently. The regression test directly exercises the broken code path with per-file fixtures, and the existing suite (3349 tests) continued to pass. There are no data mutations, no migration risk, and no change to any public API contract. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["batchData / multiBatchData\ncalled with targets[]"] --> B{entry.sig === 'dbOnly'?}
B -- No --> C["entry.fn(target, customDbPath, opts)\n(name / file / target sig)"]
B -- Yes --> D["dbOnlyTargetOpts(entry, opts, target)"]
D --> E{entry.targetKey defined?}
E -- No --> F["{ ...opts, target: batchTarget }\n(symbol-name filter)"]
E -- Yes --> G["{ ...opts, [targetKey]: batchTarget }\ne.g. { file: 'src/auth.js' }"]
F --> H["entry.fn(customDbPath, resolvedOpts)"]
G --> H
H --> I["Push result to results[]"]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["batchData / multiBatchData\ncalled with targets[]"] --> B{entry.sig === 'dbOnly'?}
B -- No --> C["entry.fn(target, customDbPath, opts)\n(name / file / target sig)"]
B -- Yes --> D["dbOnlyTargetOpts(entry, opts, target)"]
D --> E{entry.targetKey defined?}
E -- No --> F["{ ...opts, target: batchTarget }\n(symbol-name filter)"]
E -- Yes --> G["{ ...opts, [targetKey]: batchTarget }\ne.g. { file: 'src/auth.js' }"]
F --> H["entry.fn(customDbPath, resolvedOpts)"]
G --> H
H --> I["Push result to results[]"]
Reviews (2): Last reviewed commit: "fix: scope codegraph batch complexity ta..." | Re-trigger Greptile |
Codegraph Impact Analysis4 functions changed → 6 callers affected across 4 files
|
Summary
codegraph batch complexity <files...>passed each file path throughopts.target(a symbol-name filter), neveropts.file(the file-path filter), so every target silently fell back to whole-repo stats instead of erroring.targetKeyfield onBatchCommandEntrysodbOnlycommands can declare whichoptskey their targets map to;complexitynow declarestargetKey: 'file'.tests/integration/batch.test.tsasserting distinct file targets return distinct, correctly-scoped results.Closes #1721
Test plan
npm test— full suite green (3349 passed, 0 failed)npm run lint— cleannode dist/cli.js batch complexity <fileA> <fileB> -T --jsonnow matches per-filecodegraph complexity --file <f>output