Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
2b6a00d
fix: scope codegraph batch complexity targets to file paths
carlos-alm Jul 5, 2026
b28051a
fix: exclude parameters and interface/type members from dead-role cla…
carlos-alm Jul 5, 2026
17fbcba
fix: credit import-type usages as exports consumers
carlos-alm Jul 5, 2026
26918bb
fix: prevent fn-impact/query crash when -f/--file is passed
carlos-alm Jul 5, 2026
be6432c
fix: correct exported-symbol detection for literal and object-literal…
carlos-alm Jul 5, 2026
4ead840
fix: exclude primitive type keywords from ast --kind string matching
carlos-alm Jul 5, 2026
f6326bf
fix: resolve call edges through renamed import specifiers
carlos-alm Jul 5, 2026
590f560
fix: couple file_hashes updates with edge regeneration in incremental…
carlos-alm Jul 5, 2026
d3ea4a4
fix: compare signature-change diffs using new-file line ranges
carlos-alm Jul 5, 2026
c306812
feat: add environment doctor check for stale native binary and missin…
carlos-alm Jul 5, 2026
8bb5893
fix: eliminate non-deterministic ordering in community detection
carlos-alm Jul 6, 2026
46037b1
fix: sync update-graph.sh hook extension allowlist with EXTENSIONS
carlos-alm Jul 6, 2026
6a84cf9
fix: recompute directory structure metrics for affected directories o…
carlos-alm Jul 6, 2026
8d936d1
refactor: register hardcoded execFileSync/execSync maxBuffer values i…
carlos-alm Jul 6, 2026
11c84be
fix: gate blast-radius check on newly introduced risk, not pre-existi…
carlos-alm Jul 6, 2026
963301a
fix: gate identifier-argument dynamic call edges on callback-acceptin…
carlos-alm Jul 6, 2026
3e8035d
fix: gate Array.from's callback arg by position, not just callee name
carlos-alm Jul 6, 2026
879635e
fix: scope reexportedSymbols to actually-named re-export specifiers
carlos-alm Jul 6, 2026
0fe9fc3
fix: stop CFG block/edge count from overriding AST-derived cyclomatic…
carlos-alm Jul 6, 2026
ccf3c19
fix: backfill edges.technique for incrementally-inserted calls edges
carlos-alm Jul 6, 2026
d5b1162
fix: wrap remote embedding JSON parse failure in EngineError
carlos-alm Jul 6, 2026
8971017
refactor: extract shared platform-default-path helper in config.ts
carlos-alm Jul 6, 2026
056c5e4
refactor: decompose loadConfig and related high-effort functions in c…
carlos-alm Jul 6, 2026
0738171
refactor: decompose findDbPath and openRepo in db/connection.ts (docs…
carlos-alm Jul 6, 2026
6f2423c
refactor: dedupe busy/locked error detection into isBusyOrLockedError
carlos-alm Jul 6, 2026
4c02378
fix: log statSync failures in findDbPath instead of silently swallowi…
carlos-alm Jul 6, 2026
0698e16
test: add direct unit coverage for closeDbPair/closeDbPairDeferred/cl…
carlos-alm Jul 6, 2026
4ac3b99
fix: correct blast-radius/fn-impact computation for line-shifted decl…
carlos-alm Jul 6, 2026
6767f09
feat: wire points-to solver max-iterations cap through DEFAULTS.analy…
carlos-alm Jul 6, 2026
5f6f30a
refactor: route console.log calls in domain/search through logger
carlos-alm Jul 6, 2026
b479318
refactor: reduce cyclomatic complexity of computeDeltaModularityDirected
carlos-alm Jul 6, 2026
c39ac40
refactor: unify impact-level rendering format between audit and fn-im…
carlos-alm Jul 6, 2026
067674f
refactor: dedupe computeSavings via pct helper and persist partial to…
carlos-alm Jul 6, 2026
f6807b4
fix: add main.rs driver to rust dynamic tracer fixture
carlos-alm Jul 6, 2026
1c07a54
fix: scope diff file-header detection to between-hunk positions
carlos-alm Jul 6, 2026
bf82aa2
fix: update titan-grind's dead-symbol script for current roles --json…
carlos-alm Jul 6, 2026
cd02d27
fix: thread configured busyTimeoutMs through remaining read-only quer…
carlos-alm Jul 6, 2026
980b5dc
fix: resolve computed string-literal keys in object-literal extractio…
carlos-alm Jul 6, 2026
4a873a3
fix: add same-class bare-call fallback to incremental rebuild path (d…
carlos-alm Jul 6, 2026
8f3348a
fix: unify Object.defineProperty accessor fallback kind-filtering bet…
carlos-alm Jul 6, 2026
acf804c
refactor: share chunked statement-cache primitive between builder and…
carlos-alm Jul 6, 2026
986c851
refactor: cache prepared statements in applyEdgeTechniquesAfterNative…
carlos-alm Jul 6, 2026
71e9174
fix: replace fixed-depth directory-proximity check with symmetric dis…
carlos-alm Jul 6, 2026
d2935cc
refactor: remove unreachable Partition delta-computation interface me…
carlos-alm Jul 6, 2026
6515186
fix: emit reference edges for function identifiers used as object-lit…
carlos-alm Jul 6, 2026
30c491a
refactor: unify call-ref and tests rendering format between audit and…
carlos-alm Jul 6, 2026
9db911b
fix: classify destructured bindings as constant, not function (docs c…
carlos-alm Jul 6, 2026
70559fc
refactor: adopt timeMedian in remaining benchmark timing loops
carlos-alm Jul 6, 2026
822e0eb
refactor: decompose runPerfBenchmarks in token-benchmark.ts
carlos-alm Jul 6, 2026
fcdfe7d
fix: attribute liveness to Lua functions assigned to global/builtin i…
carlos-alm Jul 6, 2026
ee6362c
refactor: extract shared sedi() helper for tracer scripts
carlos-alm Jul 6, 2026
d4e6212
fix: restore reflection dynamicKind for .call/.apply/.bind (docs chec…
carlos-alm Jul 6, 2026
aec5d2b
fix: restrict entry-role classification to function/method-kind symbo…
carlos-alm Jul 6, 2026
d250f8d
fix: credit destructured dynamic import() bindings as exports consumers
carlos-alm Jul 6, 2026
75978e2
fix: recognize Lua function nodes in complexity metrics computation (…
carlos-alm Jul 6, 2026
af17b6d
fix: scope global call-resolution fallback to same-language candidate…
carlos-alm Jul 6, 2026
dd447bc
fix: credit instanceof ClassName checks as exports consumers
carlos-alm Jul 6, 2026
a79a8a1
fix: update automated-review workflow to use current claude-code-acti…
carlos-alm Jul 6, 2026
d84f6b5
refactor: widen outputResult signature, remove redundant casts at cal…
carlos-alm Jul 6, 2026
e7a2255
fix: port Leiden algorithm to native Rust for cross-engine community-…
carlos-alm Jul 7, 2026
b54972a
feat: detect exported-symbol loss from full file deletion in checkNoS…
carlos-alm Jul 7, 2026
1821a8b
fix(complexity): scope summary stats to file/target/kind filters
carlos-alm Jul 7, 2026
d45aba7
fix(extractors): label property_signature interface/type members as k…
carlos-alm Jul 7, 2026
69d8a6f
fix(roles): exclude genuine class/struct properties from dead-role cl…
carlos-alm Jul 7, 2026
db08219
fix(resolver): scope extends/implements edges to same-file/import/lan…
carlos-alm Jul 7, 2026
79cd761
fix: track inline per-specifier type-only import modifier
carlos-alm Jul 7, 2026
cbfa954
fix(native): widen NativeRepository file filters to accept string[]
carlos-alm Jul 7, 2026
c0e7eae
fix(native): remove unused source param from get_first_call_arg
carlos-alm Jul 7, 2026
2dabe21
fix(extractors): align native/WASM definitions order for object-liter…
carlos-alm Jul 7, 2026
b1eb9af
fix(extractors): capture top-level const definitions regardless of in…
carlos-alm Jul 7, 2026
4a1e279
fix: exclude PHP scalar type-hint/cast keywords from ast --kind string
carlos-alm Jul 7, 2026
40b5e24
fix: track barrel re-export renames (export { X as Y } from ...)
carlos-alm Jul 7, 2026
1506896
fix: record local alias for dynamic import() destructuring renames
carlos-alm Jul 7, 2026
2dfd6bc
fix: resolve renamed-import receiver calls in qualified-method lookup
carlos-alm Jul 7, 2026
ccea0cb
fix(native): propagate edge/node write failures out of run_pipeline
carlos-alm Jul 7, 2026
93ccfa3
fix(exports): discriminate file-level from symbol-level consumer entries
carlos-alm Jul 7, 2026
e105c26
docs: refresh CONTRIBUTING.md for TypeScript architecture and current…
carlos-alm Jul 7, 2026
5d99bf0
fix(exports): credit plain imports of TypeScript interfaces/type aliases
carlos-alm Jul 7, 2026
e0ab9dc
fix(hooks): point update-graph.sh fallback build path at dist/cli.js
carlos-alm Jul 7, 2026
730b49b
fix(hooks): resolve track-edits.sh's PROJECT_DIR from the edited file…
carlos-alm Jul 7, 2026
0d7e8e6
fix: capture removed files' cross-directory neighbors before purge
carlos-alm Jul 7, 2026
c5b9a34
docs: fix stale codegraph check flag names in recommended-practices.md
carlos-alm Jul 7, 2026
2de6550
fix(cycles): classify cycles whose only closing edges are speculative
carlos-alm Jul 7, 2026
e5fe754
fix(resolver): recognize identifier args to user-defined higher-order…
carlos-alm Jul 8, 2026
4eef28e
fix(native): scope barrel-only import skipping to transient barrel re…
carlos-alm Jul 8, 2026
4090355
refactor(ast-analysis): extract shared CFG/complexity result-merging …
carlos-alm Jul 8, 2026
bf8e969
fix(incremental): port CHA/RTA dispatch, points-to, and dynamic-sink …
carlos-alm Jul 8, 2026
51b9e23
fix(config): derive ENV_LLM_KEYS from ENV_LLM_MAP to prevent drift
carlos-alm Jul 8, 2026
a62bab7
fix(resolver): resolveByGlobal picks the single best match, not every…
carlos-alm Jul 8, 2026
8f52d28
fix(embed): resolve default DB path from positional dir, not cwd
carlos-alm Jul 8, 2026
59220a5
refactor(leiden): extract makePartition's inline getters to cut cyclo…
carlos-alm Jul 8, 2026
2e1aa11
docs: regenerate stale audit/diff-impact example output blocks
carlos-alm Jul 8, 2026
3d436ca
fix(rust): resolve self.field, unit-struct, and constructor-typed locals
carlos-alm Jul 8, 2026
668451c
docs: add missing titan-grind mirror to claude-code-skills examples
carlos-alm Jul 8, 2026
4bccd4b
fix(scripts): migrate ts-resolve-loader.js off deprecated module.regi…
carlos-alm Jul 8, 2026
25ba42f
fix(native): recover renamed import names in the FFI hybrid import-ed…
carlos-alm Jul 8, 2026
431c0e5
fix: reconnect reverse-dep edges correctly when a sibling group's siz…
carlos-alm Jul 8, 2026
ab6a685
fix: derive loadConfig() rootDir from --db path in read-only query fu…
carlos-alm Jul 8, 2026
17e265b
fix(native): thread config.db.busyTimeoutMs into NativeDatabase open …
carlos-alm Jul 8, 2026
fdedff8
fix(extractors): unwrap computed string-literal keys in typeMap/proto…
carlos-alm Jul 8, 2026
6ef1731
fix(native): add Object.defineProperty accessor dispatch post-pass to…
carlos-alm Jul 8, 2026
afca17f
fix(resolver): kind-filter same-file bare-name lookup for receiver-be…
carlos-alm Jul 8, 2026
1e104f1
fix: resolve merge conflicts with main (docs check acknowledged)
carlos-alm Jul 10, 2026
c90afdf
test(native-db): cover the remaining 3 busyTimeoutMs threading call s…
carlos-alm Jul 10, 2026
4d5285e
Merge branch 'fix/issue-1882-thread-config-db-busytimeoutms-into-the-…
carlos-alm Jul 10, 2026
f122a6d
Merge branch 'fix/issue-1884-computed-string-literal-keys-not-unwrapp…
carlos-alm Jul 10, 2026
cd0f53c
fix: guard native iteration with isNativeAvailable() in definePropert…
carlos-alm Jul 10, 2026
0c721b2
Merge branch 'fix/issue-1887-native-engine-skips-object-definepropert…
carlos-alm Jul 11, 2026
49e694f
Merge branch 'main' into fix/issue-1888-same-file-bare-name-lookup-re…
carlos-alm Jul 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -948,14 +948,26 @@ fn find_enclosing_caller<'a>(defs: &[DefWithId<'a>], call_line: u32, file_node_i
/// confidence (e.g. several files at the same directory depth from the
/// caller) is genuinely ambiguous and returns nothing, letting the caller
/// fall through to the narrower same-class-sibling fallback.
///
/// A `this`/`self`/`super` call is additionally restricted to callable kinds
/// (`is_callable_kind`): such a call is logically "invoke a member of the
/// current instance", which a class/interface/struct/etc. declaration can
/// never satisfy, so an unrelated same-named type declaration must never
/// substitute for a real callable target just because no other candidate
/// exists (#1888). A genuinely bare call (no receiver at all) is left
/// unfiltered — at this layer it is indistinguishable from a `new
/// ClassName()` constructor invocation, which legitimately targets a
/// class-kind definition.
fn resolve_exact_global_match<'a>(
ctx: &EdgeContext<'a>,
call_name: &str,
rel_path: &str,
receiver: Option<&str>,
) -> Vec<&'a NodeInfo> {
let scored: Vec<(&'a NodeInfo, f64)> = ctx.nodes_by_name
.get(call_name)
.map(|v| v.iter()
.filter(|&&n| receiver.is_none() || is_callable_kind(&n.kind))
.map(|&n| (n, resolve::compute_confidence(rel_path, &n.file, None)))
.filter(|&(_, confidence)| confidence >= 0.5)
.collect())
Expand Down Expand Up @@ -1025,10 +1037,27 @@ fn resolve_call_targets<'a>(
if !pre_qualified.is_empty() { return pre_qualified; }
}

// 2. Same-file resolution
let targets = ctx.nodes_by_name_and_file
// 2. Same-file resolution. A receiver — concrete (`obj.x()`) or
// `this`/`self`/`super` — means the call is logically "invoke a member of
// some instance", which a class/interface/struct/etc. declaration can
// never satisfy; restrict those to definitively callable kinds
// (`is_callable_kind`) so an unrelated same-file type declaration that
// merely shares the call's name can never pre-empt a legitimate target
// that a more specific resolution tier (receiver typing, the
// Object.defineProperty accessor fallback, etc.) would otherwise find. A
// genuinely bare call (no receiver at all) is left unfiltered: at this
// layer it is indistinguishable from a `new ClassName()` constructor
// invocation, which legitimately targets a class-kind definition —
// kind-filtering it would break constructor-call resolution (#1888).
// Mirrors resolveCallTargets in call-resolver.ts.
let bare_matches = ctx.nodes_by_name_and_file
.get(&(call.name.as_str(), rel_path))
.cloned().unwrap_or_default();
let targets: Vec<&NodeInfo> = if call.receiver.is_some() {
bare_matches.into_iter().filter(|n| is_callable_kind(&n.kind)).collect()
} else {
bare_matches
};
if !targets.is_empty() { return targets; }

// 3. Type-aware resolution via receiver → type map.
Expand Down Expand Up @@ -1213,7 +1242,7 @@ fn resolve_call_targets<'a>(
}

// First try exact name match (e.g. an unqualified function named "area").
let exact = resolve_exact_global_match(ctx, call.name.as_str(), rel_path);
let exact = resolve_exact_global_match(ctx, call.name.as_str(), rel_path, call.receiver.as_deref());
if !exact.is_empty() { return exact; }

// Class-scoped exact lookup: prefer `ClassName.method` when the caller is a qualified
Expand Down
29 changes: 19 additions & 10 deletions src/domain/graph/builder/call-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* `resolveByMethodOrGlobal` delegates its two branches to strategy helpers
* in `../resolver/strategy.ts` to keep per-strategy complexity manageable.
*/
import { CALLABLE_SYMBOL_KINDS } from '../../../shared/kinds.js';
import { computeConfidence, isSameLanguageFamily } from '../resolve.js';
import {
isModuleScopedLanguage,
Expand Down Expand Up @@ -113,14 +114,6 @@ export function resolveDefinePropertyAccessorTarget(

// ── Shared resolution functions ──────────────────────────────────────────

/**
* Callable definition kinds — variable/constant bindings are NOT callable
* in the function-as-enclosing-scope sense (they are local declarations, not
* function bodies). Top-level variable bindings (e.g. Haskell `main = do …`)
* are handled separately as a fallback tier.
*/
const CALLABLE_KINDS = new Set(['function', 'method']);

/**
* Variable-like binding kinds that may act as top-level callers when no
* enclosing function/method exists (e.g. Haskell top-level `main` is a
Expand All @@ -145,7 +138,7 @@ function findEnclosingCallable(
let best: CallerMatch = null;
let bestSpan = Infinity;
for (const def of definitions) {
if (!CALLABLE_KINDS.has(def.kind)) continue;
if (!CALLABLE_SYMBOL_KINDS.has(def.kind)) continue;
if (def.line > callLine) continue;
const end = def.endLine ?? Infinity;
if (callLine > end) continue;
Expand Down Expand Up @@ -300,7 +293,23 @@ export function resolveCallTargets(
}

if (!targets || targets.length === 0) {
targets = lookup.byNameAndFile(call.name, relPath);
// Same-file bare-name lookup. A receiver — concrete (`obj.x()`) or
// `this`/`self`/`super` — means the call is logically "invoke a member of
// some instance", which a class/interface/struct/etc. declaration can
// never satisfy; restrict those to definitively callable kinds so an
// unrelated same-file type declaration that merely shares the call's name
// can never pre-empt a legitimate target that a more specific resolution
// tier (receiver typing, the Object.defineProperty accessor fallback,
// etc.) would otherwise find. A genuinely bare call (no receiver at all)
// is left unfiltered: at this layer it is indistinguishable from a `new
// ClassName()` constructor invocation, which legitimately targets a
// class-kind definition — kind-filtering it would break constructor-call
// resolution (#1888).
const bareMatches = lookup.byNameAndFile(call.name, relPath);
targets = call.receiver
? bareMatches.filter((n) => CALLABLE_SYMBOL_KINDS.has(n.kind ?? ''))
: bareMatches;

if (targets.length === 0) {
targets = resolveByMethodOrGlobal(
lookup,
Expand Down
14 changes: 13 additions & 1 deletion src/domain/graph/resolver/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* a circular dependency. The StrategyLookup interface mirrors CallNodeLookup structurally
* (TypeScript structural typing ensures compatibility without an explicit import).
*/
import { CALLABLE_SYMBOL_KINDS } from '../../../shared/kinds.js';
import { computeConfidence } from '../resolve.js';

// ── Lookup adapter (structural mirror of CallNodeLookup) ──────────────────────
Expand Down Expand Up @@ -357,14 +358,25 @@ function resolveViaSameClassSibling(
* ambiguous: there is no principled way to prefer one over another, so
* the match is dropped rather than fanning out, letting the caller fall
* through to the narrower resolveViaSameClassSibling fallback.
*
* A `this`/`self`/`super` call is additionally restricted to
* `CALLABLE_SYMBOL_KINDS`: such a call is logically "invoke a member of the
* current instance", which a class/interface/struct/etc. declaration can
* never satisfy, so an unrelated same-named type declaration must never
* substitute for a real callable target just because no other candidate
* exists (#1888). A genuinely bare call (no receiver at all) is left
* unfiltered — at this layer it is indistinguishable from a `new
* ClassName()` constructor invocation, which legitimately targets a
* class-kind definition.
*/
function resolveExactGlobalMatch(
lookup: StrategyLookup,
call: { name: string },
call: { name: string; receiver?: string | null },
relPath: string,
): ReadonlyArray<{ id: number; file: string }> {
const scored = lookup
.byName(call.name)
.filter((target) => !call.receiver || CALLABLE_SYMBOL_KINDS.has(target.kind ?? ''))
.map((target) => ({ target, confidence: computeConfidence(relPath, target.file, null) }))
.filter((candidate) => candidate.confidence >= 0.5);
if (scored.length === 0) return [];
Expand Down
15 changes: 15 additions & 0 deletions src/shared/kinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ export const EVERY_SYMBOL_KIND: readonly SymbolKind[] = [
...EXTENDED_SYMBOL_KINDS,
];

/**
* Symbol kinds that represent an actual invocable definition. A call site can
* legitimately target one of these — a class, interface, struct, or plain
* variable/constant binding cannot, in the general case, and must never win a
* same-name lookup that has no other type/receiver information to narrow it.
*
* Guards the "no other signal" tiers of call resolution — the same-file
* bare-name lookup in `resolveCallTargets` and `resolveByGlobal`'s exact
* global-name match (`call-resolver.ts`, `resolver/strategy.ts`) — so an
* unrelated same-named class/interface/variable never masquerades as a real
* callable target purely because those lookups otherwise carry no kind filter
* (#1888).
*/
export const CALLABLE_SYMBOL_KINDS: ReadonlySet<string> = new Set(['function', 'method']);

// Backward compat: ALL_SYMBOL_KINDS stays as the core 10
export const ALL_SYMBOL_KINDS: readonly CoreSymbolKind[] = CORE_SYMBOL_KINDS;

Expand Down
131 changes: 131 additions & 0 deletions tests/integration/issue-1888-same-file-bare-name-kind-filter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* Regression test for #1888: the same-file bare-name lookup in
* `resolveCallTargets` (`lookup.byNameAndFile(call.name, relPath)`) ran
* unconditionally for every call and was unfiltered by symbol kind. A call
* with a receiver — `this.x()`, `obj.x()` — is logically "invoke a member of
* some instance", so an unrelated same-file class/interface/etc. that merely
* shared the call's bare name won outright, before any more specific
* resolution tier (receiver typing, the Object.defineProperty accessor
* fallback, etc.) ever got a chance to run. The exact same defect existed in
* the mirrored Rust `resolve_call_targets` / `resolve_exact_global_match` in
* `build_edges.rs` — confirmed identical on both engines before the fix.
*
* Repro (from the issue): `this.bar()` inside a plain function `getter`,
* registered as a get-accessor for `obj` (an instance of `Registry`, which
* defines `bar()`) via `Object.defineProperty`, plus an unrelated
* `class bar {}` declared later in the same file.
*
* class Registry { bar() { return 1; } }
* const obj = new Registry();
* function getter() { this.bar(); }
* Object.defineProperty(obj, 'x', { get: getter });
* class bar {}
*
* Before the fix: `getter -> bar` (kind: class) — the coincidentally-named
* class pre-empted the correctly-typed `Registry.bar` method, which was only
* reachable via a later, more specific fallback tier that never got a
* chance to run.
*
* After the fix: `getter -> Registry.bar` (kind: method), and the unrelated
* `bar` class no longer receives a `calls` edge at all.
*
* The `new Registry()` constructor call (`obj -> Registry`) is also asserted
* to still resolve — that call has no receiver at all, so it is
* indistinguishable, at this resolution layer, from a plain bare call; kind
* must NOT be filtered for it, or constructor-call resolution regresses.
*/
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';
import { isNativeAvailable } from '../../src/infrastructure/native.js';
import type { EngineMode } from '../../src/types.js';

const FIXTURE = `
class Registry {
bar() {
return 1;
}
}

const obj = new Registry();

function getter() {
this.bar();
}

Object.defineProperty(obj, 'x', { get: getter });

class bar {}
`;

interface CallEdgeRow {
src: string;
srcKind: string;
tgt: string;
tgtKind: string;
}

function readCallEdges(dbPath: string): CallEdgeRow[] {
const db = new Database(dbPath, { readonly: true });
try {
return db
.prepare(
`SELECT n1.name AS src, n1.kind AS srcKind, n2.name AS tgt, n2.kind AS tgtKind
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'
ORDER BY n1.name, n2.name`,
)
.all() as CallEdgeRow[];
} finally {
db.close();
}
}

function runScenario(engine: EngineMode): void {
describe(`same-file bare-name lookup kind filter (#1888) — ${engine}`, () => {
let dir: string;

beforeAll(async () => {
dir = fs.mkdtempSync(path.join(os.tmpdir(), `cg-1888-${engine}-`));
fs.writeFileSync(path.join(dir, 'repro.js'), FIXTURE);
await buildGraph(dir, { engine, incremental: false, skipRegistry: true });
}, 30_000);

afterAll(() => {
fs.rmSync(dir, { recursive: true, force: true });
});

it('resolves this.bar() to Registry.bar, not the unrelated class bar', () => {
const edges = readCallEdges(path.join(dir, '.codegraph', 'graph.db'));

expect(edges).toContainEqual({
src: 'getter',
srcKind: 'function',
tgt: 'Registry.bar',
tgtKind: 'method',
});
expect(edges.some((e) => e.tgt === 'bar' && e.tgtKind === 'class')).toBe(false);
});

it('still resolves the new Registry() constructor call (bare call, no receiver)', () => {
const edges = readCallEdges(path.join(dir, '.codegraph', 'graph.db'));

expect(edges).toContainEqual({
src: 'obj',
srcKind: 'constant',
tgt: 'Registry',
tgtKind: 'class',
});
});
});
}

runScenario('wasm');
describe.skipIf(!isNativeAvailable())('native engine coverage', () => {
runScenario('native');
});
Loading
Loading