Skip to content

fix: scope codegraph batch complexity targets to file paths#1808

Merged
carlos-alm merged 1 commit into
mainfrom
fix/issue-1721-batch-complexity-file-target
Jul 5, 2026
Merged

fix: scope codegraph batch complexity targets to file paths#1808
carlos-alm merged 1 commit into
mainfrom
fix/issue-1721-batch-complexity-file-target

Conversation

@carlos-alm

@carlos-alm carlos-alm commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • codegraph batch complexity <files...> passed each file path through opts.target (a symbol-name filter), never opts.file (the file-path filter), so every target silently fell back to whole-repo stats instead of erroring.
  • Added a general targetKey field on BatchCommandEntry so dbOnly commands can declare which opts key their targets map to; complexity now declares targetKey: 'file'.
  • Added a regression test in tests/integration/batch.test.ts asserting distinct file targets return distinct, correctly-scoped results.

Closes #1721

Test plan

  • npm test — full suite green (3349 passed, 0 failed)
  • npm run lint — clean
  • Manual: node dist/cli.js batch complexity <fileA> <fileB> -T --json now matches per-file codegraph complexity --file <f> output

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-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a silent bug where codegraph batch complexity <files...> routed each file-path target into opts.target (a symbol-name filter) instead of opts.file (the file-scope filter), causing every target to silently return whole-repo stats. The fix introduces a targetKey field on BatchCommandEntry so any dbOnly command can declare which opts key its targets belong to, and wires complexity to targetKey: 'file'.

  • dbOnlyTargetOpts helper centralises the target-key resolution in one place; both batchData and multiBatchData now call it, so the fix covers both batch entry points.
  • The regression test inserts per-file complexity fixtures and asserts that two distinct file targets return distinct, correctly-scoped function lists — directly proving the old bug is gone.

Confidence Score: 5/5

Safe 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

Filename Overview
src/features/batch.ts Adds targetKey to BatchCommandEntry and a dbOnlyTargetOpts helper; correctly applied in both batchData and multiBatchData; change is minimal and well-contained.
tests/integration/batch.test.ts Adds insertComplexity helper, seeds per-file complexity fixtures, and replaces the old trivial smoke test with two focused regression tests; assertions are specific and correctly reflect the fixture data.

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[]"]
Loading
%%{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[]"]
Loading

Reviews (2): Last reviewed commit: "fix: scope codegraph batch complexity ta..." | Re-trigger Greptile

Comment thread tests/integration/batch.test.ts
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

4 functions changed6 callers affected across 4 files

  • BatchCommandEntry.targetKey in src/features/batch.ts:29 (0 transitive callers)
  • dbOnlyTargetOpts in src/features/batch.ts:51 (6 transitive callers)
  • batchData in src/features/batch.ts:81 (4 transitive callers)
  • multiBatchData in src/features/batch.ts:162 (2 transitive callers)

@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@carlos-alm carlos-alm merged commit 530c716 into main Jul 5, 2026
32 checks passed
@carlos-alm carlos-alm deleted the fix/issue-1721-batch-complexity-file-target branch July 5, 2026 22:29
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codegraph batch complexity ignores file-path targets, returns global summary for every file

1 participant