-
Notifications
You must be signed in to change notification settings - Fork 16
fix: replace fixed-depth directory-proximity check with symmetric distance #1894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
2b6a00d
fix: scope codegraph batch complexity targets to file paths
carlos-alm b28051a
fix: exclude parameters and interface/type members from dead-role cla…
carlos-alm 17fbcba
fix: credit import-type usages as exports consumers
carlos-alm 26918bb
fix: prevent fn-impact/query crash when -f/--file is passed
carlos-alm be6432c
fix: correct exported-symbol detection for literal and object-literal…
carlos-alm 4ead840
fix: exclude primitive type keywords from ast --kind string matching
carlos-alm f6326bf
fix: resolve call edges through renamed import specifiers
carlos-alm 590f560
fix: couple file_hashes updates with edge regeneration in incremental…
carlos-alm d3ea4a4
fix: compare signature-change diffs using new-file line ranges
carlos-alm c306812
feat: add environment doctor check for stale native binary and missin…
carlos-alm 8bb5893
fix: eliminate non-deterministic ordering in community detection
carlos-alm 46037b1
fix: sync update-graph.sh hook extension allowlist with EXTENSIONS
carlos-alm 6a84cf9
fix: recompute directory structure metrics for affected directories o…
carlos-alm 8d936d1
refactor: register hardcoded execFileSync/execSync maxBuffer values i…
carlos-alm 11c84be
fix: gate blast-radius check on newly introduced risk, not pre-existi…
carlos-alm 963301a
fix: gate identifier-argument dynamic call edges on callback-acceptin…
carlos-alm 3e8035d
fix: gate Array.from's callback arg by position, not just callee name
carlos-alm 879635e
fix: scope reexportedSymbols to actually-named re-export specifiers
carlos-alm 0fe9fc3
fix: stop CFG block/edge count from overriding AST-derived cyclomatic…
carlos-alm ccf3c19
fix: backfill edges.technique for incrementally-inserted calls edges
carlos-alm d5b1162
fix: wrap remote embedding JSON parse failure in EngineError
carlos-alm 8971017
refactor: extract shared platform-default-path helper in config.ts
carlos-alm 056c5e4
refactor: decompose loadConfig and related high-effort functions in c…
carlos-alm 0738171
refactor: decompose findDbPath and openRepo in db/connection.ts (docs…
carlos-alm 6f2423c
refactor: dedupe busy/locked error detection into isBusyOrLockedError
carlos-alm 4c02378
fix: log statSync failures in findDbPath instead of silently swallowi…
carlos-alm 0698e16
test: add direct unit coverage for closeDbPair/closeDbPairDeferred/cl…
carlos-alm 4ac3b99
fix: correct blast-radius/fn-impact computation for line-shifted decl…
carlos-alm 6767f09
feat: wire points-to solver max-iterations cap through DEFAULTS.analy…
carlos-alm 5f6f30a
refactor: route console.log calls in domain/search through logger
carlos-alm b479318
refactor: reduce cyclomatic complexity of computeDeltaModularityDirected
carlos-alm c39ac40
refactor: unify impact-level rendering format between audit and fn-im…
carlos-alm 067674f
refactor: dedupe computeSavings via pct helper and persist partial to…
carlos-alm f6807b4
fix: add main.rs driver to rust dynamic tracer fixture
carlos-alm 1c07a54
fix: scope diff file-header detection to between-hunk positions
carlos-alm bf82aa2
fix: update titan-grind's dead-symbol script for current roles --json…
carlos-alm cd02d27
fix: thread configured busyTimeoutMs through remaining read-only quer…
carlos-alm 980b5dc
fix: resolve computed string-literal keys in object-literal extractio…
carlos-alm 4a873a3
fix: add same-class bare-call fallback to incremental rebuild path (d…
carlos-alm 8f3348a
fix: unify Object.defineProperty accessor fallback kind-filtering bet…
carlos-alm acf804c
refactor: share chunked statement-cache primitive between builder and…
carlos-alm 986c851
refactor: cache prepared statements in applyEdgeTechniquesAfterNative…
carlos-alm 71e9174
fix: replace fixed-depth directory-proximity check with symmetric dis…
carlos-alm d82ab58
fix: resolve merge conflicts with main
carlos-alm eae348c
perf: use a map lookup instead of linear scan in directoryDistance
carlos-alm bca424b
perf: memoize directoryDistance to fix hot-path regression
carlos-alm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
tests/integration/issue-1769-parent-dir-receiver-typed-call.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /** | ||
| * Regression test for #1769: a function parameter typed with a class name, | ||
| * declared in a *different, less-deeply-nested directory*, must still | ||
| * resolve method calls on that parameter back to the class's declaration. | ||
| * | ||
| * Root cause: `computeConfidenceJS` (and its Rust mirror `compute_confidence`) | ||
| * scored directory proximity using a fixed-depth check — comparing the | ||
| * parent of the caller's directory to the parent of the target's directory. | ||
| * That check only matched when both files sat at the *same* depth, so a | ||
| * subdirectory file (e.g. `graph/algorithms/bfs.ts`) calling a method on a | ||
| * class declared in its direct parent directory (`graph/model.ts`) was | ||
| * scored as maximally distant (0.3) — well below the 0.5 threshold used by | ||
| * the call-edge resolver's typed-method lookup (`resolveViaTypedMethod` in | ||
| * src/domain/graph/resolver/strategy.ts), so the call edge was silently | ||
| * dropped even though the parameter's type annotation correctly resolved | ||
| * `foo: Foo` to `typeMap['foo'] = 'Foo'`. | ||
| * | ||
| * Setup mirrors the real-world shape from src/graph/algorithms/bfs.ts calling | ||
| * src/graph/model.ts: | ||
| * - model.ts (parent directory): `export class Foo { bar(x): number {...} }` | ||
| * - algorithms/consumer.ts (child directory): a function whose PARAMETER is | ||
| * typed `foo: Foo` (via type annotation, not `new Foo()` construction) | ||
| * calls `foo.bar(x)`. | ||
| * | ||
| * Expected: a `calls` edge from `useFoo` to `Foo.bar`, in both engines. | ||
| */ | ||
|
|
||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import Database from 'better-sqlite3'; | ||
| import { afterAll, beforeAll, describe, expect, it } from 'vitest'; | ||
| import { buildGraph } from '../../src/domain/graph/builder.js'; | ||
|
|
||
| const TSCONFIG = JSON.stringify({ | ||
| compilerOptions: { | ||
| target: 'es2022', | ||
| module: 'esnext', | ||
| moduleResolution: 'bundler', | ||
| strict: true, | ||
| }, | ||
| include: ['**/*.ts'], | ||
| }); | ||
|
|
||
| const MODEL_TS = ` | ||
| export class Foo { | ||
| bar(x: number): number { | ||
| return x + 1; | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| // Nested one directory deeper than model.ts — mirrors graph/algorithms/bfs.ts | ||
| // receiving a `graph: CodeGraph` parameter from graph/model.ts. | ||
| const CONSUMER_TS = ` | ||
| import type { Foo } from '../model.js'; | ||
|
|
||
| export function useFoo(foo: Foo, x: number): number { | ||
| return foo.bar(x); | ||
| } | ||
| `; | ||
|
|
||
| let tmpWasm: string; | ||
| let tmpNative: string; | ||
|
|
||
| function writeFixture(dir: string): void { | ||
| fs.writeFileSync(path.join(dir, 'tsconfig.json'), TSCONFIG); | ||
| // Both files live under a shared `graph/` directory — NOT at the fixture | ||
| // root — so their relative-path depths mirror the real src/graph/model.ts | ||
| // vs src/graph/algorithms/bfs.ts shape. Placing model.ts directly at the | ||
| // fixture root would make `path.dirname()` hit its "." fixed point at the | ||
| // same recursion depth for both files, which accidentally masks the #1769 | ||
| // bug (the old fixed-depth check happens to coincide at the filesystem | ||
| // root regardless of the asymmetry it's supposed to detect). | ||
| fs.mkdirSync(path.join(dir, 'graph', 'algorithms'), { recursive: true }); | ||
| fs.writeFileSync(path.join(dir, 'graph', 'model.ts'), MODEL_TS); | ||
| fs.writeFileSync(path.join(dir, 'graph', 'algorithms', 'consumer.ts'), CONSUMER_TS); | ||
| } | ||
|
|
||
| beforeAll(async () => { | ||
| tmpWasm = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-1769-wasm-')); | ||
| writeFixture(tmpWasm); | ||
|
|
||
| tmpNative = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-1769-native-')); | ||
| writeFixture(tmpNative); | ||
|
|
||
| await Promise.all([ | ||
| buildGraph(tmpWasm, { incremental: false, skipRegistry: true, engine: 'wasm' }), | ||
| buildGraph(tmpNative, { incremental: false, skipRegistry: true, engine: 'native' }), | ||
| ]); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| fs.rmSync(tmpWasm, { recursive: true, force: true }); | ||
| fs.rmSync(tmpNative, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| function hasCallEdge(dbPath: string, sourceName: string, targetName: string): boolean { | ||
| const db = new Database(dbPath, { readonly: true }); | ||
| try { | ||
| const row = db | ||
| .prepare( | ||
| `SELECT 1 | ||
| FROM edges e | ||
| JOIN nodes n1 ON e.source_id = n1.id | ||
| JOIN nodes n2 ON e.target_id = n2.id | ||
| WHERE e.kind = 'calls' AND n1.name = ? AND n2.name = ?`, | ||
| ) | ||
| .get(sourceName, targetName); | ||
| return row !== undefined; | ||
| } finally { | ||
| db.close(); | ||
| } | ||
| } | ||
|
|
||
| describe('parameter-typed receiver call to a parent-directory class (#1769)', () => { | ||
| it('WASM: resolves foo.bar(x) to Foo.bar across a child->parent directory boundary', () => { | ||
| expect(hasCallEdge(path.join(tmpWasm, '.codegraph', 'graph.db'), 'useFoo', 'Foo.bar')).toBe( | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| it('Native: resolves foo.bar(x) to Foo.bar across a child->parent directory boundary', () => { | ||
| expect(hasCallEdge(path.join(tmpNative, '.codegraph', 'graph.db'), 'useFoo', 'Foo.bar')).toBe( | ||
| true, | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.