mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-21 00:21:30 +00:00
* fix(ingestion): reduce parse-phase memory for huge repos (#1983)
Stop retaining full parse-cache chunks in RAM alongside the merged graph,
slim on-disk shards, defer worker ParsedFile emission for scope-resolver
languages, and add GITNEXUS_DEBUG_HEAP probes for OOM diagnosis.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(ingestion): address #2038 tri-review findings (parse-phase memory)
Resolves the confirmed review findings on PR #2038:
- P1: thread exportedTypeMap through the sequential parse path
(processParsingSequential) so a no-worker run over a partially-warm
cache no longer silently drops the sequential-miss files' exported
types. Cache hits made exportedTypeMap.size > 0, suppressing the
end-of-loop buildExportedTypeMapFromGraph rebuild, but the sequential
path never populated the map. Regression test added (fails on the
pre-fix tree, passes after) plus a fully-sequential differential oracle.
- P2: saveParseCache builds its on-disk index from hashes actually
written/copied (writtenKeys), never a usedKeys hash whose shard write
or copy was skipped — no more phantom index entries.
- P2: add a unit test asserting SCOPE_RESOLUTION_LANGUAGES stays in sync
with SCOPE_RESOLVERS (asymmetric drift would lose a language's ParsedFile).
- Backfill cache coverage: loadParseCacheChunk missing/corrupt -> undefined,
pruneCache onDiskKeys branch, slim preserves nodes, saveParseCache
copy-evicted-shard round-trip.
- Cleanups: single-source heap-probe gating via isDebugHeapEnabled();
hoist the per-chunk mkdir in persistParseCacheChunk behind a
process-scoped Set; gate COBOL's unused worker-side ParsedFile
extraction (graph nodes still come from cobolPhase) while keeping
fileCount/progress unconditional.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* refactor(ingestion): remove dead worker-side ParsedFile extraction
After #2038 gated worker `ParsedFile` emission behind `!isScopeResolutionLanguage(language)`, and with all 16 SupportedLanguages registered in SCOPE_RESOLVERS, that gate was structurally always true — the worker already produced no ParsedFiles and scope-resolution re-extracts each file from source on the main thread (run.ts). Remove the now-dead machinery:
- Drop both worker `extractParsedFile` call-sites (tree-sitter processFileGroup + the standalone-provider branch) and the `result.parsedFiles.push`. The standalone branch keeps fileCount/onFileProcessed per file. `result.parsedFiles` stays declared but empty (field removal deferred).
- Remove the now-orphaned `scopeSourceKind` var + `ScopeCaptureSourceKind`/`extractParsedFile`/`isScopeResolutionLanguage` imports.
- Delete the consumerless `migrated-languages.ts` (isScopeResolutionLanguage + SCOPE_RESOLUTION_LANGUAGES) and its drift-guard test — parse-worker was their only importer. Also improves AGENTS.md "shared ingestion code must not name languages" compliance.
`extractParsedFile` and the scope-extractor-bridge stay (scope-resolution/run.ts + Vue resolver use them). Behavior-preserving: worker-sequential-parity passes before and after; tsc/eslint clean; no baseline/golden drift.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* refactor(ingestion): worker-pool-only parsing; remove sequential parser (#1983)
Completes the #1983 huge-repo parse-OOM effort by making the worker pool
GitNexus's sole parse path.
Parallel serialization (the perf core): workers serialize their ParsedFiles to
a disk store in parallel and stream them back to scope-resolution, so the main
thread no longer re-parses every file (the tree-sitter native-memory leak that
caused the OOM). Adds chunk merge-pipelining + work-proportional chunk sizing so
the pool stays saturated.
Remove the sequential parser: `--workers 0`, `GITNEXUS_WORKER_POOL_SIZE=0`, and
`skipWorkers` now hard-error (no silent degrade — #1741); the small-repo
threshold no longer selects an in-process path; pool creation stays lazy /
cache-miss-gated so warm all-hit runs never spawn workers.
Worker-path parity fixes — removing sequential surfaced two pre-existing gaps
that tiny-fixture tests had masked by running below the worker threshold, both
fixed by carrying per-file metadata as DATA across the worker boundary (never
re-parsing on the main thread, preserving the OOM fix):
- C++: templateConstraints wired into worker node identity (SFINAE overload
disambiguation) + ADL / inline-namespace capture side-channel serialized
onto the ParsedFile.
- Kotlin: companion-scope side-channel serialized the same way (companion /
static dispatch).
Validation: tsc + build clean; full suite green (10,190 pass — the only
deterministic failures were the now-fixed C++/Kotlin worker-path gaps; the 2
remaining full-run failures are pre-existing load flakiness, green in
isolation); cpp-pipeline benchmark stays linear on a 1-worker pool.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(ingestion): wire C static-linkage side-channel + ADL O(1) collect + tri-review cleanups (#1983)
Follow-up to the worker-pool-only refactor, from a tri-review of the parse path.
- C static-linkage side-channel (P1): cProvider had no collect/applyCaptureSideChannel,
so on the now-sole worker path C `static` file-local marks were lost across the worker
boundary -> false cross-file CALLS edges + over-broad #include wildcard visibility on
every C analysis (the Linux kernel is C). Mirror the C++/Kotlin wiring: serialize
`staticNames` per file onto ParsedFile.captureSideChannel and restore it on the main
thread (no re-parse). + a worker-path regression test (the existing c-static-isolation
fixture passed vacuously — its collision resolves via #include before the global
free-call fallback ever consults static-linkage).
- captureSideChannel `kind` discriminant: add `kind:'cpp'`/`kind:'c'` tags + guards
(Kotlin already had one) now that C/C++/Kotlin share the single generic field.
- Perf: collectCppAdlSideChannel scanned the whole argInfoBySite/noAdlSites maps per file
(O(F^2) per sub-batch, ~100M parseSiteKey calls at kernel scale). Add per-filePath
lockstep indexes -> O(1) collect; serialized snapshot byte-identical.
- Cleanups: inline the one-line processParsingWithWorkers wrapper into processParsing;
drop the always-empty WorkerExtractedData.calls/assignments/constructorBindings fields;
remove the voided astCache param from processParsing; refresh stale "sequential
fallback" JSDoc.
Validation: tsc + build clean; cpp 297/297, c 8/8 (incl. the new worker-path
static-linkage guard), typescript + parsedfile-store green; cpp ADL benchmark stays linear.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* perf(scope-resolution): index C/C++ #include resolution in finalize (O(n²)→O(n))
Kernel-scale C/C++ analysis ground in finalizeScopeModel because three
per-#include operations each did a full O(F) scan with no index — the
finalize O(n²) that surfaced once the #1983 parse-phase OOM was fixed:
- expand{C,Cpp}WildcardNames: parsedFiles.find() per wildcard edge → O(R·F)
- resolveImportTarget: new Set(allFilePaths) rebuilt per #include
- resolveCImportTarget: suffix-match scanned all workspace paths
Each is replaced with a WeakMap-per-pass index keyed on the stable
parsedFiles/allFilePaths references that scope-resolution run.ts passes
once per pass:
- Map<ScopeId,ParsedFile> for wildcard expansion (c/static-linkage.ts +
cpp/file-local-linkage.ts)
- memoized augmented header set (c/scope-resolver.ts + cpp/scope-resolver.ts)
- basename-bucketed suffix index in resolveCImportTarget (c/import-target.ts),
shared by C and C++ since resolveCppImportTarget delegates to it
Collapses the C/C++ finalize from O(R·F) to O(R+F). Pure-perf, byte-identical
edge output: 962 targeted tests green (490 C + 472 C/C++ scope-resolution);
the basename index preserves the exact endsWith('/'+target) match and the
fewest-path-components-then-lexicographic tie-break.
The kernel's ~25-30k .h headers are classified C++, so both providers must
be fixed. Proven on the Linux kernel: the C finalize completed
(sr-post-finalize lang=c → sr-end lang=c), which the pre-fix run never
reached in 16+ min of grinding.
Build-independent follow-ups (separate from this finalize fix), documented
for later: emitFreeCallFallback same-name buckets (emit phase),
buildGraphNodeLookup + precount global setup, the ParsedFile store-load,
the dart/go/ruby expand-wildcards .find siblings, and the ~26GB
scope-resolution memory floor (full kernel completion needs >~40GB RAM).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test(bench): regenerate C scope-capture baseline for the #1983 c-static-linkage-worker fixture
bench/scope-capture/measure.mjs fingerprints emitCScopeCaptures over the
lang-resolution/c-* fixture corpus. The #1983 PR added the
c-static-linkage-worker fixture (caller.c/lib.c/lib.h/local.c — the
worker-path static-linkage side-channel test) but did not regenerate the C
baseline, so `--check` has been red on this branch (main, lacking the
fixture, still matches 0de009b).
Pure fixture-corpus drift — no c/captures.ts or query change branch-vs-main,
existing fixtures' captures byte-identical (c-captures.test.ts 45/45),
scaling stays linear (~0.97). Regenerated: 0de009b -> 39f3a83. Bench now
PASS (14 languages). Unrelated to the finalize O(n²) fix.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* perf(scope-resolution): lower kernel-scale resident memory floor + setup cost
Reduce the scope-resolution resident-memory floor and setup throughput on
huge repos (Linux kernel), the wall that remains after #1983 (parse OOM) and
the finalize O(n^2) fix (b71c77b8). Five units; all preserve byte-identical
edge output (C fixture 177n/255e + c/cpp/cross-file/php/static-linkage suites
green, 619 tests).
U1 (src/cli/analyze.ts): RAM-aware auto heap-cap. Replace the hardcoded
16384MB cap with computeHeapCapMb = max(16384, floor(0.75*effectiveRAM)),
where effectiveRAM = min(os.totalmem(), process.constrainedMemory()) with the
unconstrained-sentinel guard. Add --max-semi-space-size=128 on the respawn.
A user-supplied NODE_OPTIONS heap still wins (no re-exec). Verified: 23973MB
on a 31964MB box, 16384 floor on small machines, cgroup-aware, sentinel safe.
U2 (src/storage/parsedfile-store.ts, .../pipeline/phase.ts): export forceGc()
and call it at the per-language eviction boundary, so a finished language's
ParsedFiles are reclaimed before the next language's store-load instead of
collected lazily under the next pass's allocation pressure (which at cap>=RAM
degrades into swap-thrash). Measured on a real drivers/net/ethernet run:
C 2113->894MB and C++ 1754->1057MB reclaimed at the boundary (no fragmentation
defeat). Answers the plan's Open Question 1.
U3 (src/storage/parsedfile-store.ts): intern def objects by nodeId in the load
reviver so a SymbolDefinition's three serialized copies (localDefs /
scope.ownedDefs / scope.bindings[].def) collapse to one shared object on load.
Per-shard def pool (a def's copies are shard-local). Measured ~42% off the
def-object retained heap (3->1; 1.8M->600k distinct objects on 600k defs).
U4 (.../passes/free-call-fallback.ts): memoize pickUniqueGlobalCallable's
post-filter candidate list per (name, callerFilePath), only when no per-caller
visibility filter applies (the list is then a pure function of name+file), so
repeated free calls of one name from a file reuse the same-name-bucket scan
instead of re-walking a potentially huge bucket per site. The cached array is
read-only-consumed by the .filter()-based arity/overload narrowers. Exported
pickUniqueGlobalCallable + buildGlobalCallableIndex and added an equivalence
test (memoized == un-memoized reference for every (name, file, arity),
including warm-cache repeats and cross-file file-local exclusion).
U5 (.../pipeline/phase.ts): replace the O(L*F) per-language precount + repeated
scannedFiles.filter() with a single O(F) partition-by-language pass; bracket
buildGraphNodeLookup with scope-setup-nodeLookup heap probes so the long setup
is no longer silent.
Plan: docs/plans/2026-06-06-001-perf-kernel-scope-resolution-memory-plan.md
(U6 out-of-core global index deferred). Note: the kernel's full C++ pass floor
(~20k headers + the 8.8GB graph) likely still exceeds 24GB by itself, which is
why U6 remains the only unit that clears the wall.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(test): match OOM-guidance e2e assertions to the U1 reworded hint
The analyze-heap-oom-e2e real-child-OOM test still asserted the pre-U1
wording ('...out of memory.' + a hardcoded 24576 cap). U1 reworded the hint
to mention the auto heap-cap and use a <MB> placeholder, so the three
toContain substrings no longer matched (the assertion at line 62 failed on
all platforms). Update them to the current message. The unit twin
(analyze-heap-respawn) was already updated in 85bfc216; this integration
test was missed by the targeted local run.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* perf(lbug): U6a — deterministic id-sorted graph output behind GITNEXUS_SORT_GRAPH_OUTPUT
First increment of U6 (out-of-core scope-resolution). Adds an optional
deterministic ordering of node + relationship CSV rows by their unique graph
id, behind GITNEXUS_SORT_GRAPH_OUTPUT (default OFF = today's graph-insertion
order, byte-identical — the iterator is returned untouched). With the flag ON
the CSV becomes a pure function of the node/edge SET rather than of emit order.
This is the structural enabler for the windowed/out-of-core resolve (U6b-U6d):
csv-generator.ts:518 currently iterates graph.iterRelationships() in insertion
order with NO terminal sort, so any deviation from parsedFiles-order emit would
change bytes. With U6a on, a windowed emit need only reproduce the same edge
SET, not the global insertion order — removing the single largest byte-identical
hazard from every later windowing step.
Verified: default off keeps the existing csv-pipeline suite byte-identical; on,
node rows are id-sorted and output is independent of graph insertion order
(set-build) with the same node/edge set.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* perf(storage): U6d foundation — disk-backed scope store + lazy ScopeTree
Adds scope-index-store.ts: persistScopeShards (per-file scope shards via the
proven mapReplacer + def-interning reviver) + DiskBackedScopeTree, a lazy
ScopeTree that serves getScope from a bounded LRU of decoded shards plus a small
resident skeleton (scopeId -> {shard, childIds, parent}). Exports
makeInterningReviver from parsedfile-store for reuse.
This is the contained, highest-risk mechanism of U6d (out-of-core scope
resolution): the emit passes reach the heavy per-Scope binding payload
(~17-20GB on the kernel) ONLY through scopeTree.getScope (a point lookup) and
getChildren — they never read parsed.scopes directly — so moving that payload to
disk behind getScope is transparent. Every consumer reads a Scope BY VALUE, so a
value-faithful disk round-trip is byte-identical to resolution.
Proven in isolation: DiskBackedScopeTree is value-identical to buildScopeTree
for getScope/getChildren/getParent/getAncestors/has/size across multiple files
and after LRU eviction, and preserves the def-identity collapse (ownedDefs[i]
=== binding.def). Nothing wires it yet (the resolution-pipeline integration is
the next increment) — zero production impact; default off.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* perf(scope-resolution): U6d integration — seal scopeTree to disk before emit (GITNEXUS_DISK_SCOPE_INDEX)
Wires the U6d out-of-core scope index into the live pipeline behind
GITNEXUS_DISK_SCOPE_INDEX (default OFF = byte-identical). When on:
- finalize-orchestrator builds a TransitionalScopeTree (validated, fully
resident) instead of buildScopeTree, so finalize/propagate/resolve are
unchanged.
- After resolve, before emit, run.ts seals it: persists the scopes to a
file-sharded scope-index-store, swaps the model's scopeTree to disk-backed
serving from the inside (the frozen bundle can't be reassigned, but the
wrapper nulls its own resident backing), and drops the heavy Scope.bindings
payload from all THREE holders — the model's tree (seal), the caller's
preExtractedParsedFiles, and run.ts's own parsedFiles (scope-stripped copies
for emit). Emit reads scopes only via scopeTree.getScope (a point lookup,
now disk-backed + LRU) — verified it never reads parsed.scopes.
Purpose: lower the per-language resident PEAK (kernel C pass ~20→~12 GB by
moving the ~8-9 GB scope payload to disk) so the analysis fits on smaller-RAM
machines. At >=24 GB the full kernel already fits with U1-U5 (U2's 8.7 GB
inter-language forceGc reclaim keeps each pass under cap) — empirically
confirmed — so this is the sub-24 GB lever, not needed at 24 GB.
Byte-identical evidence: DiskBackedScopeTree/TransitionalScopeTree return
value-identical scopes vs buildScopeTree (getScope/getChildren/getParent/
getAncestors, across files + after LRU eviction + post-seal); emit reads only
getScope + referenceSites; flag-off (394 tests) and flag-on-resident (91 tests)
resolver suites stay green; an end-to-end A/B on a 212-file C+cpp+rust subset
produced identical 17,444 nodes / 31,343 edges with the seal firing per language
(c: 410→141 MB reclaimed). Kernel-scale peak-drop measurement pending the
in-flight verdict run freeing memory.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* perf(scope-resolution): U6d — id-back workspaceIndex so the disk seal can reclaim scopes
The kernel run revealed the contained scopeTree seal didn't lower the heap:
WorkspaceResolutionIndex held Scope OBJECTS (classScopeByDefId / moduleScopeByFile),
built from every ParsedFile and live through emit, so the ~28k module + class
scopes stayed pinned past the seal (sr-seal-pre 17,583 -> sr-seal-post 17,771 MB,
no drop). It was the sole residual Scope-object holder (SemanticModel holds none).
Fix: classScopeByDefId / moduleScopeByFile become id-backed ScopeByKeyView
instances — a ReadonlyMap<K, Scope> facade over a K->ScopeId map + the scopeTree,
whose .get fetches via scopeTree.getScope(id). The index now pins only ids, so
once the tree seals to disk the scopes become collectible. Byte-identical: the
view returns the same Scope the resident tree holds (or a value-identical revived
one in disk mode), and iteration keeps the old insertion order. buildWorkspace
ResolutionIndex takes an optional scopeTree (live pipeline passes it); without it
(unit tests) the legacy direct Scope-object maps are returned unchanged.
Verified byte-identical: 733 tests across workspace-index / imported-return-types
/ c / cpp / cross-file / go / java. Kernel peak-drop re-measurement to follow.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* perf(scope-resolution): U6d — precompute exportedCallableByName (fix disk-getScope thrash)
The workspaceIndex id-backing freed the kernel scopes but exposed a throughput
collapse: findExportedDefByName's workspace fallback (walkers.ts:1019) scanned
EVERY module scope's bindings per unresolved free call, and under the U6d
disk-backed scopeTree each module-scope access faulted a shard in from disk —
lib ON went ~1min -> ~7.5min.
Fix: precompute the fallback result once into
WorkspaceResolutionIndex.exportedCallableByName (simpleName -> first module-local
callable def, first-file-wins — the exact semantics the scan returned), built
from the resident module-scope bindings at index-build time. findExportedDefByName
now does an O(1) lookup with zero disk reads.
Result: lib ON ~7.5min -> 21s (cache-warm), byte-identical 17,444/31,343; 758
tests green across workspace-index + c/cpp/cross-file/go/python.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* docs: rename cryptic U-unit codes to descriptive names in comments
The plan-unit shorthand (U3/U4/U6a/U6d/...) was meaningless in the code.
Renamed in comments + test descriptions (no behavior change, byte-identical):
out-of-core scope index (was U6)
deterministic output (was U6a)
disk-backed scope seal (was U6d)
def-object interning (was U3)
free-call candidate cache (was U4)
Also renamed throughout the PR title/summary. Pushed commit messages keep
their original U-codes as historical record.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(ingestion): durable ParsedFile shards for warm-cache coverage (#2038)
On a warm re-analyze where every chunk is a parse-cache HIT, no parse worker
runs, the run-scoped ParsedFile store is cleared at parse start, and the cached
ParseWorkerResult carries no ParsedFiles (the worker writes them to the store
and empties them from the message). Scope-resolution then found an empty store
and fell back to main-thread extractParsedFile — re-opening the #1983
tree-sitter native-leak OOM the disk store closes (abhigyanpatwari review on
parse-cache.ts).
Fix: workers ALSO write their ParsedFiles to a durable, content-addressed store
(parsedfile-cache/) keyed by chunk hash, mirroring the parse cache's lifecycle
(version-gated by PARSE_CACHE_VERSION, pruned in lockstep to the surviving
keys). On a warm hit the chunk's durable shards are byte-COPIED into the
run-scoped store (no re-parse, no re-serialize -> byte-identical), so
scope-resolution streams them exactly as on a cold run. A coherence gate
re-dispatches the worker whenever a cached chunk's durable shards are missing
(migration / pruned / version-stale) -- never the main-thread extract.
- worker-pool/parse-worker: thread chunkHash through dispatch->job->flush
(incl. split/requeue) so the worker tags its durable shard by content
- parsedfile-store: durable persist / restore / index / prune API (sibling
dir, never cleared per run); content-addressing makes stale reuse impossible
- parse-impl: load durable index, gate the cache hit on durable coverage,
restore on hit, dispatch chunkHash on miss
- run-analyze: prune+save the durable store to the parse cache's surviving keys
- saveParseCache returns its written keys (the durable keepKeys)
Verified on linux/lib: warm preExtractedHits = full coverage (520/207/1, zero
main-thread re-parse), byte-identical cold==warm (17,456n/31,353e), warm 8.5x
faster. New two-run + mixed-mode + coherence-gate regression test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(ingestion): clear stale scope-index-store shards on each seal (#2038)
The disk-backed scope index writes sequential s<n>.json shards into a shared
<storagePath>/scope-index-store/ dir, with the index resetting per
persistScopeShards call. A seal that writes fewer shards than a previous one
(a later language with fewer files, or a re-run of a shrunken repo) left stale
tail shards on disk indefinitely -- never read by the disk-backed tree, but
multi-GB on kernel-scale repos.
Add clearScopeIndexStore() and clear at the start of persistScopeShards: the
previously sealed language has finished emit and been released before the next
seal runs, so its DiskBackedScopeTree never reads those shards again. Unit
tests: a stale prior-run shard is removed, a fewer-files re-seal leaves no tail
shards, and the helper is idempotent.
Addresses abhigyanpatwari review on run.ts (disk hygiene for the
GITNEXUS_DISK_SCOPE_INDEX path).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2375 lines
91 KiB
TypeScript
2375 lines
91 KiB
TypeScript
/**
|
|
* Java: class extends + implements multiple interfaces + ambiguous package disambiguation
|
|
*/
|
|
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import path from 'path';
|
|
import {
|
|
FIXTURES,
|
|
CROSS_FILE_FIXTURES,
|
|
getRelationships,
|
|
getNodesByLabel,
|
|
getNodesByLabelFull,
|
|
edgeSet,
|
|
runPipelineFromRepo,
|
|
type PipelineResult,
|
|
} from './helpers.js';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Heritage: class extends + implements multiple interfaces
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java heritage resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-heritage'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects exactly 3 classes and 2 interfaces', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toEqual(['BaseModel', 'User', 'UserService']);
|
|
expect(getNodesByLabel(result, 'Interface')).toEqual(['Serializable', 'Validatable']);
|
|
});
|
|
|
|
it('emits exactly 1 EXTENDS edge: User → BaseModel', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
expect(extends_.length).toBe(1);
|
|
expect(extends_[0].source).toBe('User');
|
|
expect(extends_[0].target).toBe('BaseModel');
|
|
});
|
|
|
|
it('emits exactly 2 IMPLEMENTS edges: User → Serializable, User → Validatable', () => {
|
|
const implements_ = getRelationships(result, 'IMPLEMENTS');
|
|
expect(implements_.length).toBe(2);
|
|
expect(edgeSet(implements_)).toEqual(['User → Serializable', 'User → Validatable']);
|
|
});
|
|
|
|
it('resolves exactly 4 IMPORTS edges', () => {
|
|
const imports = getRelationships(result, 'IMPORTS');
|
|
expect(imports.length).toBe(4);
|
|
expect(edgeSet(imports)).toEqual([
|
|
'User.java → Serializable.java',
|
|
'User.java → Validatable.java',
|
|
'UserService.java → Serializable.java',
|
|
'UserService.java → User.java',
|
|
]);
|
|
});
|
|
|
|
it('does not emit EXTENDS edges to interfaces', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
expect(extends_.some((e) => e.target === 'Serializable')).toBe(false);
|
|
expect(extends_.some((e) => e.target === 'Validatable')).toBe(false);
|
|
});
|
|
|
|
it('emits exactly 3 CALLS edges', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
expect(calls.length).toBe(3);
|
|
expect(edgeSet(calls)).toEqual([
|
|
'processUser → save',
|
|
'processUser → serialize',
|
|
'processUser → validate',
|
|
]);
|
|
});
|
|
|
|
it('no OVERRIDES edges target Property nodes', () => {
|
|
const overrides = getRelationships(result, 'METHOD_OVERRIDES');
|
|
for (const edge of overrides) {
|
|
const target = result.graph.getNode(edge.rel.targetId);
|
|
expect(target).toBeDefined();
|
|
expect(target!.label).not.toBe('Property');
|
|
}
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Generic-base heritage (#1951): extends Box<T> + implements IFoo<T>. An
|
|
// earlier query was type_identifier-only and matched 0 generic bases; the synth
|
|
// resolves the generic base to its bare name. Scope-resolution (the single path
|
|
// since #942) owns these edges.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java generic-base heritage resolution (#1951)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-generic-base'), () => {});
|
|
}, 60000);
|
|
|
|
it('emits EXTENDS Service → Box for a generic superclass (extends Box<String>)', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
expect(edgeSet(extends_)).toEqual(['Service → Box']);
|
|
});
|
|
|
|
it('emits IMPLEMENTS Service → IFoo for a generic interface (implements IFoo<String>)', () => {
|
|
const implements_ = getRelationships(result, 'IMPLEMENTS');
|
|
expect(edgeSet(implements_)).toEqual(['Service → IFoo']);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Qualified (namespaced) bases (#1956 tri-review U2). Three shapes:
|
|
// - Service: 3-segment generic (extends app.base.Box<T>, implements app.base.IFoo<T>)
|
|
// - Plain: 2-segment plain (extends base.Base, implements base.IBar)
|
|
// - Two: 2-segment generic (extends base.Box<T>, implements base.IFoo<T>)
|
|
// Scope-resolution resolves each by its scoped-name tail (end-anchored
|
|
// scoped_type_identifier handling). The 2-segment cases are the regression
|
|
// guard: an un-anchored arm double-matches a 2-segment base (both segments are
|
|
// direct type_identifier children) and emits a spurious prefix edge — this
|
|
// asserts exactly one edge per base.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java qualified-base heritage resolution (#1956 U2)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-qualified-base'), () => {});
|
|
}, 60000);
|
|
|
|
it('emits exactly one EXTENDS per class, tail-resolved (no spurious prefix edge)', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
expect(edgeSet(extends_)).toEqual(['Plain → Base', 'Service → Box', 'Two → Box']);
|
|
});
|
|
|
|
it('emits exactly one IMPLEMENTS per class, tail-resolved (no spurious prefix edge)', () => {
|
|
const implements_ = getRelationships(result, 'IMPLEMENTS');
|
|
expect(edgeSet(implements_)).toEqual(['Plain → IBar', 'Service → IFoo', 'Two → IFoo']);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Interface-to-interface EXTENDS (#1951): `interface IA extends IB, IC<String>`.
|
|
// An earlier synth walked class_declaration ONLY, so it NEVER emitted
|
|
// interface-to-interface heritage — production silently dropped these edges.
|
|
// Widening the synth's traversal to also walk
|
|
// interface_declaration > extends_interfaces > type_list closes it.
|
|
// Both bases resolve to Interface symbols, so preEmitInheritanceEdges emits them
|
|
// as IMPLEMENTS. IC<String> exercises the generic-base reduction (IC<String> ->
|
|
// IC). Scope-resolution (the single resolution path since #942) owns these
|
|
// edges.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java interface-extends-interface heritage resolution (#1951)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-iface-extends'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects 3 interfaces and no classes', () => {
|
|
expect(getNodesByLabel(result, 'Interface')).toEqual(['IA', 'IB', 'IC']);
|
|
expect(getNodesByLabel(result, 'Class')).toEqual([]);
|
|
});
|
|
|
|
it('emits IMPLEMENTS IA → IB and IA → IC for interface-to-interface extends', () => {
|
|
const implements_ = getRelationships(result, 'IMPLEMENTS');
|
|
expect(edgeSet(implements_)).toEqual(['IA → IB', 'IA → IC']);
|
|
});
|
|
|
|
it('emits no EXTENDS edges (interface bases resolve to Interface → IMPLEMENTS)', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
expect(extends_).toEqual([]);
|
|
});
|
|
|
|
it('all interface-heritage edges point to real Interface graph nodes', () => {
|
|
for (const edge of getRelationships(result, 'IMPLEMENTS')) {
|
|
const target = result.graph.getNode(edge.rel.targetId);
|
|
expect(target).toBeDefined();
|
|
expect(target!.properties.name).toBe(edge.target);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Ambiguous: Handler + Processor in two packages, imports disambiguate
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java ambiguous symbol resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-ambiguous'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects 2 Handler classes and 2 Processor interfaces', () => {
|
|
const classes = getNodesByLabel(result, 'Class');
|
|
expect(classes.filter((n) => n === 'Handler').length).toBe(2);
|
|
expect(classes).toContain('UserHandler');
|
|
const ifaces = getNodesByLabel(result, 'Interface');
|
|
expect(ifaces.filter((n) => n === 'Processor').length).toBe(2);
|
|
});
|
|
|
|
it('resolves EXTENDS to models/Handler (not other/Handler)', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
expect(extends_.length).toBe(1);
|
|
expect(extends_[0].source).toBe('UserHandler');
|
|
expect(extends_[0].target).toBe('Handler');
|
|
expect(extends_[0].targetFilePath).toBe('models/Handler.java');
|
|
});
|
|
|
|
it('resolves IMPLEMENTS to models/Processor (not other/Processor)', () => {
|
|
const implements_ = getRelationships(result, 'IMPLEMENTS');
|
|
expect(implements_.length).toBe(1);
|
|
expect(implements_[0].source).toBe('UserHandler');
|
|
expect(implements_[0].target).toBe('Processor');
|
|
expect(implements_[0].targetFilePath).toBe('models/Processor.java');
|
|
});
|
|
|
|
it('import edges point to models/ not other/', () => {
|
|
const imports = getRelationships(result, 'IMPORTS');
|
|
const targets = imports.map((e) => e.target).sort();
|
|
expect(targets).toContain('Handler.java');
|
|
expect(targets).toContain('Processor.java');
|
|
for (const imp of imports) {
|
|
expect(imp.targetFilePath).toMatch(/^models\//);
|
|
}
|
|
});
|
|
|
|
it('all heritage edges point to real graph nodes', () => {
|
|
for (const edge of [
|
|
...getRelationships(result, 'EXTENDS'),
|
|
...getRelationships(result, 'IMPLEMENTS'),
|
|
]) {
|
|
const target = result.graph.getNode(edge.rel.targetId);
|
|
expect(target).toBeDefined();
|
|
expect(target!.properties.name).toBe(edge.target);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('Java qualified class names', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-qualified-types'), () => {});
|
|
}, 60000);
|
|
|
|
it('stores distinct qualified names for same-named classes across packages', () => {
|
|
const users = getNodesByLabelFull(result, 'Class').filter((node) => node.name === 'User');
|
|
expect(users).toHaveLength(2);
|
|
expect(users.map((node) => node.properties.qualifiedName).sort()).toEqual([
|
|
'com.example.admin.User',
|
|
'com.example.models.User',
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe('Java call resolution with arity filtering', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-calls'), () => {});
|
|
}, 60000);
|
|
|
|
it('resolves processUser → writeAudit to util/OneArg.java via arity narrowing', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
expect(calls.length).toBe(1);
|
|
expect(calls[0].source).toBe('processUser');
|
|
expect(calls[0].target).toBe('writeAudit');
|
|
expect(calls[0].targetFilePath).toBe('util/OneArg.java');
|
|
expect(calls[0].rel.reason).toBe('import-resolved');
|
|
});
|
|
});
|
|
|
|
describe('Java same-module priority for duplicate FQNs', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-duplicate-fqn-modules'), () => {});
|
|
}, 60000);
|
|
|
|
it('resolves Module1App.run calls to module1 UserService, not module2', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const module1ToModule1 = calls.filter(
|
|
(c) =>
|
|
c.source === 'run' &&
|
|
c.target === 'UserService' &&
|
|
c.sourceFilePath === 'module1/src/main/java/com/example/Module1App.java' &&
|
|
c.targetFilePath === 'module1/src/main/java/com/example/UserService.java',
|
|
);
|
|
const module1ToModule2 = calls.filter(
|
|
(c) =>
|
|
c.source === 'run' &&
|
|
c.target === 'UserService' &&
|
|
c.sourceFilePath === 'module1/src/main/java/com/example/Module1App.java' &&
|
|
c.targetFilePath === 'module2/src/main/java/com/example/UserService.java',
|
|
);
|
|
const module1ToAnyUserService = calls.filter(
|
|
(c) =>
|
|
c.source === 'run' &&
|
|
c.target === 'UserService' &&
|
|
c.sourceFilePath === 'module1/src/main/java/com/example/Module1App.java' &&
|
|
/module[12]\/src\/main\/java\/com\/example\/UserService\.java/.test(c.targetFilePath),
|
|
);
|
|
|
|
expect(module1ToModule1.length).toBe(1);
|
|
expect(module1ToModule2.length).toBe(0);
|
|
expect(module1ToAnyUserService.length).toBe(1);
|
|
});
|
|
|
|
it('resolves Module2App.run calls to module2 UserService, not module1', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const module2ToModule2 = calls.filter(
|
|
(c) =>
|
|
c.source === 'run' &&
|
|
c.target === 'UserService' &&
|
|
c.sourceFilePath === 'module2/src/main/java/com/example/Module2App.java' &&
|
|
c.targetFilePath === 'module2/src/main/java/com/example/UserService.java',
|
|
);
|
|
const module2ToModule1 = calls.filter(
|
|
(c) =>
|
|
c.source === 'run' &&
|
|
c.target === 'UserService' &&
|
|
c.sourceFilePath === 'module2/src/main/java/com/example/Module2App.java' &&
|
|
c.targetFilePath === 'module1/src/main/java/com/example/UserService.java',
|
|
);
|
|
const module2ToAnyUserService = calls.filter(
|
|
(c) =>
|
|
c.source === 'run' &&
|
|
c.target === 'UserService' &&
|
|
c.sourceFilePath === 'module2/src/main/java/com/example/Module2App.java' &&
|
|
/module[12]\/src\/main\/java\/com\/example\/UserService\.java/.test(c.targetFilePath),
|
|
);
|
|
|
|
expect(module2ToModule2.length).toBe(1);
|
|
expect(module2ToModule1.length).toBe(0);
|
|
expect(module2ToAnyUserService.length).toBe(1);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Member-call resolution: obj.method() resolves through pipeline
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java member-call resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-member-calls'), () => {});
|
|
}, 60000);
|
|
|
|
it('resolves processUser → save as a member call on User', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save');
|
|
expect(saveCall).toBeDefined();
|
|
expect(saveCall!.source).toBe('processUser');
|
|
expect(saveCall!.targetFilePath).toBe('models/User.java');
|
|
});
|
|
|
|
it('detects User class and save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
});
|
|
|
|
it('emits HAS_METHOD edge from User to save', () => {
|
|
const hasMethod = getRelationships(result, 'HAS_METHOD');
|
|
const edge = hasMethod.find((e) => e.source === 'User' && e.target === 'save');
|
|
expect(edge).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Constructor resolution: new Foo() resolves to Constructor/Class
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java constructor-call resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-constructor-calls'), () => {});
|
|
}, 60000);
|
|
|
|
it('resolves new User() as a CALLS edge to the User constructor', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const ctorCall = calls.find((c) => c.target === 'User');
|
|
expect(ctorCall).toBeDefined();
|
|
expect(ctorCall!.source).toBe('processUser');
|
|
// Java has explicit constructor_declaration → Constructor node
|
|
expect(ctorCall!.targetLabel).toBe('Constructor');
|
|
expect(ctorCall!.targetFilePath).toBe('models/User.java');
|
|
});
|
|
|
|
it('also resolves user.save() as a member call', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save');
|
|
expect(saveCall).toBeDefined();
|
|
expect(saveCall!.source).toBe('processUser');
|
|
});
|
|
|
|
it('detects User class, User constructor, save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Constructor')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Receiver-constrained resolution: typed variables disambiguate same-named methods
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java receiver-constrained resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-receiver-resolution'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User and Repo classes, both with save methods', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Repo');
|
|
const saveMethods = getNodesByLabel(result, 'Method').filter((m) => m === 'save');
|
|
expect(saveMethods.length).toBe(2);
|
|
});
|
|
|
|
it('resolves user.save() to User.save and repo.save() to Repo.save via receiver typing', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCalls = calls.filter((c) => c.target === 'save');
|
|
expect(saveCalls.length).toBe(2);
|
|
|
|
const userSave = saveCalls.find((c) => c.targetFilePath === 'models/User.java');
|
|
const repoSave = saveCalls.find((c) => c.targetFilePath === 'models/Repo.java');
|
|
|
|
expect(userSave).toBeDefined();
|
|
expect(repoSave).toBeDefined();
|
|
expect(userSave!.source).toBe('processEntities');
|
|
expect(repoSave!.source).toBe('processEntities');
|
|
});
|
|
|
|
it('resolves constructor calls for both User and Repo', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userCtor = calls.find((c) => c.target === 'User');
|
|
const repoCtor = calls.find((c) => c.target === 'Repo');
|
|
expect(userCtor).toBeDefined();
|
|
expect(repoCtor).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Method references: expr::method, Type::method, Type::new, this::m, super::m
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java method-reference resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-method-reference'), () => {});
|
|
}, 60000);
|
|
|
|
it('resolves project method references to CALLS edges', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
|
|
expect(
|
|
calls.find(
|
|
(c) =>
|
|
c.source === 'mapViaInstanceBuilder' &&
|
|
c.target === 'buildResponse' &&
|
|
c.targetFilePath === 'models/ResponseBuilder.java',
|
|
),
|
|
).toBeDefined();
|
|
|
|
expect(
|
|
calls.find(
|
|
(c) =>
|
|
c.source === 'mapViaStaticUtil' &&
|
|
c.target === 'format' &&
|
|
c.targetFilePath === 'util/FormatUtil.java',
|
|
),
|
|
).toBeDefined();
|
|
|
|
expect(
|
|
calls.find(
|
|
(c) =>
|
|
c.source === 'mapUserNames' &&
|
|
c.target === 'getName' &&
|
|
c.targetFilePath === 'models/User.java',
|
|
),
|
|
).toBeDefined();
|
|
|
|
expect(
|
|
calls.find(
|
|
(c) =>
|
|
c.source === 'mapSaves' &&
|
|
c.target === 'saveOne' &&
|
|
c.targetFilePath === 'services/MethodRefService.java',
|
|
),
|
|
).toBeDefined();
|
|
|
|
expect(
|
|
calls.find(
|
|
(c) =>
|
|
c.source === 'wrapTransform' &&
|
|
c.target === 'transform' &&
|
|
c.targetFilePath === 'models/BaseHandler.java',
|
|
),
|
|
).toBeDefined();
|
|
});
|
|
|
|
it('resolves constructor references to Constructor nodes', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const ctorRef = calls.find(
|
|
(c) =>
|
|
c.source === 'mapNewUsers' &&
|
|
c.target === 'User' &&
|
|
c.targetFilePath === 'models/User.java',
|
|
);
|
|
|
|
expect(ctorRef).toBeDefined();
|
|
expect(ctorRef!.targetLabel).toBe('Constructor');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Named import disambiguation: two User classes, import resolves to correct one
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java named import disambiguation', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-named-imports'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects two User classes in different packages', () => {
|
|
const users = getNodesByLabel(result, 'Class').filter((n) => n === 'User');
|
|
expect(users.length).toBe(2);
|
|
});
|
|
|
|
it('resolves user.save() to com/example/models/User.java via named import', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save');
|
|
expect(saveCall).toBeDefined();
|
|
expect(saveCall!.source).toBe('run');
|
|
expect(saveCall!.targetFilePath).toBe('com/example/models/User.java');
|
|
});
|
|
|
|
it('resolves new User() to com/example/models/User.java, not other/', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const ctorCall = calls.find((c) => c.target === 'User' && c.source === 'run');
|
|
expect(ctorCall).toBeDefined();
|
|
expect(ctorCall!.targetFilePath).toBe('com/example/models/User.java');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Variadic resolution: String... doesn't get filtered by arity
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java variadic call resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-variadic-resolution'), () => {});
|
|
}, 60000);
|
|
|
|
it('resolves 3-arg call to varargs method record(String...) in Logger.java', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const logCall = calls.find((c) => c.target === 'record');
|
|
expect(logCall).toBeDefined();
|
|
expect(logCall!.source).toBe('run');
|
|
expect(logCall!.targetFilePath).toBe('com/example/util/Logger.java');
|
|
});
|
|
|
|
it('CALLS edges from within variadic method have valid sourceId (no ID mismatch)', () => {
|
|
// Collect all CALLS edges whose source is in Logger.java
|
|
const danglingSourceIds: string[] = [];
|
|
for (const rel of result.graph.iterRelationships()) {
|
|
if (rel.type !== 'CALLS') continue;
|
|
const sourceNode = result.graph.getNode(rel.sourceId);
|
|
if (!sourceNode) {
|
|
danglingSourceIds.push(rel.sourceId);
|
|
continue;
|
|
}
|
|
// Specifically flag Logger.java sources that don't resolve
|
|
if (
|
|
sourceNode.properties.filePath === 'com/example/util/Logger.java' &&
|
|
!result.graph.getNode(rel.sourceId)
|
|
) {
|
|
danglingSourceIds.push(rel.sourceId);
|
|
}
|
|
}
|
|
|
|
// No CALLS edge should have a dangling (unresolvable) sourceId.
|
|
// This catches the bug where definition creates Method:...record#N but
|
|
// findEnclosingFunctionId generates Method:...record (no suffix),
|
|
// producing CALLS edges whose sourceId doesn't match any graph node.
|
|
expect(danglingSourceIds).toEqual([]);
|
|
|
|
// Additionally verify that ALL relationships (not just CALLS) have
|
|
// resolvable sourceIds — a stronger invariant.
|
|
const allDangling: string[] = [];
|
|
for (const rel of result.graph.iterRelationships()) {
|
|
if (!result.graph.getNode(rel.sourceId)) {
|
|
allDangling.push(`${rel.type}:${rel.sourceId}`);
|
|
}
|
|
}
|
|
expect(allDangling).toEqual([]);
|
|
});
|
|
|
|
it('resolves 2-arg call to fixed-prefix varargs method format(int, String...) in Formatter.java', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const fmtCall = calls.find((c) => c.target === 'format' && c.source === 'run');
|
|
expect(fmtCall).toBeDefined();
|
|
expect(fmtCall!.targetFilePath).toBe('com/example/util/Formatter.java');
|
|
});
|
|
|
|
it('0-arg call to format(int, String...) still resolves in legacy mode (arity rejection is registry-only)', () => {
|
|
// When `requiredParameterCount = 1`, `javaArityCompatibility` returns
|
|
// 'incompatible' for 0-arg calls, which would prevent the CALLS edge.
|
|
// This test documents the current resolution behavior for this shape.
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const zeroArgFmtCall = calls.find((c) => c.target === 'format' && c.source === 'badCall');
|
|
expect(zeroArgFmtCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Wildcard import: `import com.example.models.*` resolves to a package file
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java wildcard import resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-wildcard-import'), () => {});
|
|
}, 60000);
|
|
|
|
it('parses wildcard import without errors and creates graph nodes', () => {
|
|
// The wildcard import (`import com.example.models.*`) exercises the
|
|
// directoryChild branch in resolveJavaImportTarget. Even if no IMPORTS
|
|
// edge is created (nondeterministic file selection — documented flip
|
|
// blocker), the graph must contain valid nodes for all classes.
|
|
const classes = getNodesByLabel(result, 'Class');
|
|
expect(classes).toContain('Main');
|
|
expect(classes).toContain('User');
|
|
expect(classes).toContain('Order');
|
|
});
|
|
|
|
it('resolves user.save() call via wildcard-imported User', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save' && c.source === 'run');
|
|
expect(saveCall).toBeDefined();
|
|
expect(saveCall!.targetFilePath).toBe('com/example/models/User.java');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Local shadow: same-file definition takes priority over imported name
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java local definition shadows import', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-local-shadow'), () => {});
|
|
}, 60000);
|
|
|
|
it('resolves run → save to same-file definition, not the imported one', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save' && c.source === 'run');
|
|
expect(saveCall).toBeDefined();
|
|
expect(saveCall!.targetFilePath).toBe('src/main/java/com/example/app/Main.java');
|
|
});
|
|
|
|
it('does NOT resolve save to Logger.java', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveToUtils = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.targetFilePath === 'src/main/java/com/example/utils/Logger.java',
|
|
);
|
|
expect(saveToUtils).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Constructor-inferred type resolution: var user = new User(); user.save()
|
|
// Java 10+ local variable type inference (no explicit type annotations)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java constructor-inferred type resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(FIXTURES, 'java-constructor-type-inference'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User and Repo classes, both with save methods', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Repo');
|
|
const saveMethods = getNodesByLabel(result, 'Method').filter((m) => m === 'save');
|
|
expect(saveMethods.length).toBe(2);
|
|
});
|
|
|
|
it('resolves user.save() to models/User.java via constructor-inferred type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) => c.target === 'save' && c.targetFilePath === 'models/User.java',
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
expect(userSave!.source).toBe('processEntities');
|
|
});
|
|
|
|
it('resolves repo.save() to models/Repo.java via constructor-inferred type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const repoSave = calls.find(
|
|
(c) => c.target === 'save' && c.targetFilePath === 'models/Repo.java',
|
|
);
|
|
expect(repoSave).toBeDefined();
|
|
expect(repoSave!.source).toBe('processEntities');
|
|
});
|
|
|
|
it('emits exactly 2 save() CALLS edges (one per receiver type)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCalls = calls.filter((c) => c.target === 'save');
|
|
expect(saveCalls.length).toBe(2);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// For-each loop element typing: for (User user : users) user.save()
|
|
// Java: explicit type in enhanced_for_statement binds loop variable
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java for-each loop element type resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-foreach'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User and Repo classes, both with save methods', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Repo');
|
|
const saveMethods = getNodesByLabel(result, 'Method').filter((m) => m === 'save');
|
|
expect(saveMethods.length).toBe(2);
|
|
});
|
|
|
|
it('resolves user.save() in for-each to User#save (not Repo#save)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) => c.target === 'save' && c.targetFilePath === 'models/User.java',
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
expect(userSave!.source).toBe('processEntities');
|
|
});
|
|
|
|
it('resolves repo.save() in for-each to Repo#save (not User#save)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const repoSave = calls.find(
|
|
(c) => c.target === 'save' && c.targetFilePath === 'models/Repo.java',
|
|
);
|
|
expect(repoSave).toBeDefined();
|
|
expect(repoSave!.source).toBe('processEntities');
|
|
});
|
|
|
|
it('emits exactly 2 save() CALLS edges (one per receiver type)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCalls = calls.filter((c) => c.target === 'save');
|
|
expect(saveCalls.length).toBe(2);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// this.save() resolves to enclosing class's own save method
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java this resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-self-this-resolution'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User and Repo classes, each with a save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toEqual(['Repo', 'User']);
|
|
const saveMethods = getNodesByLabel(result, 'Method').filter((m) => m === 'save');
|
|
expect(saveMethods.length).toBe(2);
|
|
});
|
|
|
|
it('resolves this.save() inside User.process to User.save, not Repo.save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save' && c.source === 'process');
|
|
expect(saveCall).toBeDefined();
|
|
expect(saveCall!.targetFilePath).toBe('src/models/User.java');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Parent class resolution: EXTENDS + IMPLEMENTS edges
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java parent resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-parent-resolution'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects BaseModel and User classes plus Serializable interface', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toEqual(['BaseModel', 'User']);
|
|
expect(getNodesByLabel(result, 'Interface')).toEqual(['Serializable']);
|
|
});
|
|
|
|
it('emits EXTENDS edge: User → BaseModel', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
expect(extends_.length).toBe(1);
|
|
expect(extends_[0].source).toBe('User');
|
|
expect(extends_[0].target).toBe('BaseModel');
|
|
});
|
|
|
|
it('emits IMPLEMENTS edge: User → Serializable', () => {
|
|
const implements_ = getRelationships(result, 'IMPLEMENTS');
|
|
expect(implements_.length).toBe(1);
|
|
expect(implements_[0].source).toBe('User');
|
|
expect(implements_[0].target).toBe('Serializable');
|
|
});
|
|
|
|
it('all heritage edges point to real graph nodes', () => {
|
|
for (const edge of [
|
|
...getRelationships(result, 'EXTENDS'),
|
|
...getRelationships(result, 'IMPLEMENTS'),
|
|
]) {
|
|
const target = result.graph.getNode(edge.rel.targetId);
|
|
expect(target).toBeDefined();
|
|
expect(target!.properties.name).toBe(edge.target);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// super.save() resolves to parent class's save method
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java super resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-super-resolution'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects BaseModel, User, and Repo classes', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toEqual(['BaseModel', 'Repo', 'User']);
|
|
});
|
|
|
|
it('resolves super.save() inside User to BaseModel.save, not Repo.save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const superSave = calls.find(
|
|
(c) =>
|
|
c.source === 'save' &&
|
|
c.target === 'save' &&
|
|
c.targetFilePath === 'src/models/BaseModel.java',
|
|
);
|
|
expect(superSave).toBeDefined();
|
|
const repoSave = calls.find(
|
|
(c) => c.target === 'save' && c.targetFilePath === 'src/models/Repo.java',
|
|
);
|
|
expect(repoSave).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// super.save() resolves to generic parent class's save method
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java generic parent super resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(FIXTURES, 'java-generic-parent-resolution'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects BaseModel, User, and Repo classes', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toEqual(['BaseModel', 'Repo', 'User']);
|
|
});
|
|
|
|
it('resolves super.save() inside User to BaseModel.save, not Repo.save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const superSave = calls.find(
|
|
(c) =>
|
|
c.source === 'save' &&
|
|
c.target === 'save' &&
|
|
c.targetFilePath === 'src/models/BaseModel.java',
|
|
);
|
|
expect(superSave).toBeDefined();
|
|
const repoSave = calls.find(
|
|
(c) => c.target === 'save' && c.targetFilePath === 'src/models/Repo.java',
|
|
);
|
|
expect(repoSave).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Return type inference: var user = svc.getUser("alice"); user.save()
|
|
// Java's CONSTRUCTOR_BINDING_SCANNER handles `var` declarations with
|
|
// method_invocation values, enabling end-to-end return type inference.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java return type inference via explicit method return type', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-return-type-inference'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User and UserService classes', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('UserService');
|
|
});
|
|
|
|
it('detects save and getUser methods', () => {
|
|
const methods = getNodesByLabel(result, 'Method');
|
|
expect(methods).toContain('save');
|
|
expect(methods).toContain('getUser');
|
|
});
|
|
|
|
it('resolves user.save() to User#save via return type of getUser(): User', () => {
|
|
// Java's CONSTRUCTOR_BINDING_SCANNER binds `var user = svc.getUser()` to the
|
|
// return type of getUser (User), so the subsequent user.save() call resolves
|
|
// to User#save rather than an unresolved target.
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'processUser' && c.targetFilePath.includes('models'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Nullable receiver: Java uses explicit type annotations (User user = findUser())
|
|
// Tests that regular typed receiver resolution works with competing save() methods
|
|
// when the variable is assigned from a factory method returning the same type.
|
|
// Note: Java Optional<User> stores just "Optional" in TypeEnv (generics stripped),
|
|
// so this test uses plain typed variables to validate receiver disambiguation.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java nullable receiver resolution (typed factory return)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-nullable-receiver'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User and Repo classes, both with save methods', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Repo');
|
|
const saveMethods = getNodesByLabel(result, 'Method').filter((m) => m === 'save');
|
|
expect(saveMethods.length).toBe(2);
|
|
});
|
|
|
|
it('resolves user.save() to User.save via receiver typing', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) => c.target === 'save' && c.targetFilePath === 'models/User.java',
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
expect(userSave!.source).toBe('processEntities');
|
|
});
|
|
|
|
it('resolves repo.save() to Repo.save via receiver typing', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const repoSave = calls.find(
|
|
(c) => c.target === 'save' && c.targetFilePath === 'models/Repo.java',
|
|
);
|
|
expect(repoSave).toBeDefined();
|
|
expect(repoSave!.source).toBe('processEntities');
|
|
});
|
|
|
|
it('user.save() does NOT resolve to Repo.save (negative disambiguation)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCalls = calls.filter((c) => c.target === 'save' && c.source === 'processEntities');
|
|
// Each save() call should resolve to exactly one target file
|
|
expect(saveCalls.filter((c) => c.targetFilePath === 'models/User.java').length).toBe(1);
|
|
expect(saveCalls.filter((c) => c.targetFilePath === 'models/Repo.java').length).toBe(1);
|
|
});
|
|
|
|
it('emits exactly 2 save() CALLS edges (one per receiver type)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCalls = calls.filter((c) => c.target === 'save');
|
|
expect(saveCalls.length).toBe(2);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Assignment chain propagation (Phase 4.3)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java assignment chain propagation', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-assignment-chain'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User and Repo classes each with a save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Repo');
|
|
const saveMethods = getNodesByLabel(result, 'Method').filter((m) => m === 'save');
|
|
expect(saveMethods.length).toBe(2);
|
|
});
|
|
|
|
it('resolves alias.save() to User#save via assignment chain', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
// Positive: alias.save() must resolve to User#save
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processEntities' &&
|
|
c.targetFilePath.includes('User.java'),
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
});
|
|
|
|
it('alias.save() does NOT resolve to Repo#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
// Negative: alias comes from User, so only one edge to User.java
|
|
const wrongCall = calls.filter(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processEntities' &&
|
|
c.targetFilePath.includes('User.java'),
|
|
);
|
|
expect(wrongCall.length).toBe(1);
|
|
});
|
|
|
|
it('resolves rAlias.save() to Repo#save via assignment chain', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
// Positive: rAlias.save() must resolve to Repo#save
|
|
const repoSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processEntities' &&
|
|
c.targetFilePath.includes('Repo.java'),
|
|
);
|
|
expect(repoSave).toBeDefined();
|
|
});
|
|
|
|
it('each alias resolves to its own class, not the other', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processEntities' &&
|
|
c.targetFilePath.includes('User.java'),
|
|
);
|
|
const repoSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processEntities' &&
|
|
c.targetFilePath.includes('Repo.java'),
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
expect(repoSave).toBeDefined();
|
|
expect(userSave!.targetFilePath).not.toBe(repoSave!.targetFilePath);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Java Optional<User> receiver resolution — extractSimpleTypeName unwraps
|
|
// Optional<User> to "User" via NULLABLE_WRAPPER_TYPES, enabling receiver
|
|
// disambiguation when the declaration type is Optional<T>.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java Optional<User> receiver resolution via wrapper unwrapping', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-optional-receiver'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User and Repo classes each with a save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Repo');
|
|
const saveMethods = getNodesByLabel(result, 'Method').filter((m) => m === 'save');
|
|
expect(saveMethods.length).toBe(2);
|
|
});
|
|
|
|
it('resolves user.save() to User#save with Optional<User> in scope', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processEntities' &&
|
|
c.targetFilePath?.includes('User.java'),
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
});
|
|
|
|
it('resolves repo.save() to Repo#save alongside Optional usage', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const repoSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processEntities' &&
|
|
c.targetFilePath?.includes('Repo.java'),
|
|
);
|
|
expect(repoSave).toBeDefined();
|
|
});
|
|
|
|
it('disambiguates user.save() and repo.save() to different files', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processEntities' &&
|
|
c.targetFilePath?.includes('User.java'),
|
|
);
|
|
const repoSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processEntities' &&
|
|
c.targetFilePath?.includes('Repo.java'),
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
expect(repoSave).toBeDefined();
|
|
expect(userSave!.targetFilePath).not.toBe(repoSave!.targetFilePath);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Chained method call resolution: svc.getUser().save()
|
|
// The receiver of save() is a method_invocation (getUser()), not a simple identifier.
|
|
// Resolution must walk the chain: getUser() returns User, so save() → User#save.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java chained method call resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-chain-call'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User, Repo and UserService classes', () => {
|
|
const classes = getNodesByLabel(result, 'Class');
|
|
expect(classes).toContain('User');
|
|
expect(classes).toContain('Repo');
|
|
expect(classes).toContain('UserService');
|
|
});
|
|
|
|
it('detects save methods on both User and Repo', () => {
|
|
const saveMethods = getNodesByLabel(result, 'Method').filter((m) => m === 'save');
|
|
expect(saveMethods.length).toBe(2);
|
|
});
|
|
|
|
it('detects getUser method on UserService', () => {
|
|
const methods = getNodesByLabel(result, 'Method');
|
|
expect(methods).toContain('getUser');
|
|
});
|
|
|
|
it('resolves svc.getUser().save() to User#save, NOT Repo#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'processUser' && c.targetFilePath.includes('User.java'),
|
|
);
|
|
const repoSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'processUser' && c.targetFilePath.includes('Repo.java'),
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
expect(repoSave).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Java 16+ instanceof pattern variable: `if (obj instanceof User user)`
|
|
// Phase 5.2: extractPatternBinding on instanceof_expression binds user → User.
|
|
// Disambiguation: User.save vs Repo.save — only User.save should be called.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java instanceof pattern variable resolution (Phase 5.2)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-instanceof-pattern'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User and Repo classes each with a save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Repo');
|
|
const saveMethods = getNodesByLabel(result, 'Method').filter((m) => m === 'save');
|
|
expect(saveMethods.length).toBe(2);
|
|
});
|
|
|
|
it('resolves user.save() inside if (obj instanceof User user) to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'process' && c.targetFilePath.includes('User.java'),
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
});
|
|
|
|
it('does NOT resolve user.save() to Repo#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const repoSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'process' && c.targetFilePath.includes('Repo.java'),
|
|
);
|
|
expect(repoSave).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Enum static method calls: Status.fromCode(200) should resolve via
|
|
// class-as-receiver with Enum type included in the filter.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java enum static method call resolution (Phase 5 review fix)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-enum-static-call'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects Status as an Enum and App as a Class', () => {
|
|
expect(getNodesByLabel(result, 'Enum')).toContain('Status');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('App');
|
|
});
|
|
|
|
it('detects fromCode and label methods on Status', () => {
|
|
const methods = getNodesByLabel(result, 'Method');
|
|
expect(methods).toContain('fromCode');
|
|
expect(methods).toContain('label');
|
|
});
|
|
|
|
it('resolves Status.fromCode(200) to Status#fromCode via class-as-receiver', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const fromCodeCall = calls.find(
|
|
(c) =>
|
|
c.target === 'fromCode' &&
|
|
c.source === 'process' &&
|
|
c.targetFilePath?.includes('Status.java'),
|
|
);
|
|
expect(fromCodeCall).toBeDefined();
|
|
});
|
|
|
|
it('resolves s.label() to Status#label', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const labelCall = calls.find(
|
|
(c) =>
|
|
c.target === 'label' && c.source === 'process' && c.targetFilePath?.includes('Status.java'),
|
|
);
|
|
expect(labelCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Java 21+ switch pattern matching: switch (obj) { case User user -> user.save(); }
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java switch pattern binding', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-switch-pattern'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User and Repo classes, both with save methods', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Repo');
|
|
const saveMethods = getNodesByLabel(result, 'Method').filter((m) => m === 'save');
|
|
expect(saveMethods.length).toBe(2);
|
|
});
|
|
|
|
it('resolves user.save() in switch case User to models/User.java', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'processAny' && c.targetFilePath === 'models/User.java',
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
});
|
|
|
|
it('resolves repo.save() in switch case Repo to models/Repo.java', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const repoSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'processAny' && c.targetFilePath === 'models/Repo.java',
|
|
);
|
|
expect(repoSave).toBeDefined();
|
|
});
|
|
|
|
it('resolves user.save() in handleUser switch case User to models/User.java', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'handleUser' && c.targetFilePath === 'models/User.java',
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
});
|
|
|
|
it('does NOT cross-resolve handleUser switch case User to Repo.save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const wrongSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'handleUser' && c.targetFilePath === 'models/Repo.java',
|
|
);
|
|
expect(wrongSave).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Java Map .values() for-loop — method-aware type arg resolution
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java Map .values() for-loop resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-map-keys-values'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User class with save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
});
|
|
|
|
it('resolves user.save() via Map.values() to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'processValues' && c.targetFilePath?.includes('User'),
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
});
|
|
|
|
it('does NOT resolve user.save() to Repo#save (negative)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const wrongSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'processValues' && c.targetFilePath?.includes('Repo'),
|
|
);
|
|
expect(wrongSave).toBeUndefined();
|
|
});
|
|
|
|
it('resolves user.save() via List iteration to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'processList' && c.targetFilePath?.includes('User'),
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Java enhanced for-loop with call_expression iterable: for (User user : getUsers())
|
|
// Phase 7.3: call_expression iterable resolution via ReturnTypeLookup
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java foreach call_expression iterable resolution (Phase 7.3)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-foreach-call-expr'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User and Repo classes with competing save methods', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Repo');
|
|
});
|
|
|
|
it('resolves user.save() in foreach over User.getUsers() to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const userSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processUsers' &&
|
|
c.targetFilePath?.includes('User.java'),
|
|
);
|
|
expect(userSave).toBeDefined();
|
|
});
|
|
|
|
it('resolves repo.save() in foreach over Repo.getRepos() to Repo#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const repoSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processRepos' &&
|
|
c.targetFilePath?.includes('Repo.java'),
|
|
);
|
|
expect(repoSave).toBeDefined();
|
|
});
|
|
|
|
it('does NOT resolve user.save() to Repo#save (negative)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const wrongSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processUsers' &&
|
|
c.targetFilePath?.includes('Repo.java'),
|
|
);
|
|
expect(wrongSave).toBeUndefined();
|
|
});
|
|
|
|
it('does NOT resolve repo.save() to User#save (negative)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const wrongSave = calls.find(
|
|
(c) =>
|
|
c.target === 'save' &&
|
|
c.source === 'processRepos' &&
|
|
c.targetFilePath?.includes('User.java'),
|
|
);
|
|
expect(wrongSave).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Phase 8: Field/property type resolution (1-level)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Field type resolution (Java)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-field-types'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects classes: Address, App, User', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toEqual(['Address', 'App', 'User']);
|
|
});
|
|
|
|
it('detects Property nodes for Java fields', () => {
|
|
const properties = getNodesByLabel(result, 'Property');
|
|
expect(properties).toContain('address');
|
|
expect(properties).toContain('name');
|
|
expect(properties).toContain('city');
|
|
});
|
|
|
|
it('emits HAS_PROPERTY edges linking properties to classes', () => {
|
|
const propEdges = getRelationships(result, 'HAS_PROPERTY');
|
|
expect(propEdges.length).toBe(3);
|
|
expect(edgeSet(propEdges)).toContain('User → address');
|
|
expect(edgeSet(propEdges)).toContain('User → name');
|
|
expect(edgeSet(propEdges)).toContain('Address → city');
|
|
});
|
|
|
|
it('resolves user.address.save() → Address#save via field type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCalls = calls.filter((e) => e.target === 'save');
|
|
const addressSave = saveCalls.find(
|
|
(e) => e.source === 'processUser' && e.targetFilePath.includes('Address'),
|
|
);
|
|
expect(addressSave).toBeDefined();
|
|
});
|
|
|
|
it('emits ACCESSES read edge for user.address field access in chain', () => {
|
|
const accesses = getRelationships(result, 'ACCESSES');
|
|
const addressReads = accesses.filter((e) => e.target === 'address' && e.rel.reason === 'read');
|
|
expect(addressReads.length).toBe(1);
|
|
expect(addressReads[0].source).toBe('processUser');
|
|
expect(addressReads[0].targetLabel).toBe('Property');
|
|
});
|
|
|
|
it('populates field metadata (visibility, isStatic, declaredType) on Property nodes', () => {
|
|
const properties = getNodesByLabelFull(result, 'Property');
|
|
|
|
const city = properties.find((p) => p.name === 'city');
|
|
expect(city).toBeDefined();
|
|
expect(city!.properties.visibility).toBe('public');
|
|
expect(city!.properties.isStatic).toBe(false);
|
|
expect(city!.properties.isReadonly).toBe(false);
|
|
expect(city!.properties.declaredType).toBe('String');
|
|
|
|
const addr = properties.find((p) => p.name === 'address');
|
|
expect(addr).toBeDefined();
|
|
expect(addr!.properties.visibility).toBe('public');
|
|
expect(addr!.properties.declaredType).toBe('Address');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Phase 8A: Deep field chain resolution (3-level)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Deep field chain resolution (Java)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-deep-field-chain'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects classes: Address, App, City, User', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toEqual(['Address', 'App', 'City', 'User']);
|
|
});
|
|
|
|
it('detects Property nodes for Java fields', () => {
|
|
const properties = getNodesByLabel(result, 'Property');
|
|
expect(properties).toContain('address');
|
|
expect(properties).toContain('city');
|
|
expect(properties).toContain('zipCode');
|
|
});
|
|
|
|
it('emits HAS_PROPERTY edges for nested type chain', () => {
|
|
const propEdges = getRelationships(result, 'HAS_PROPERTY');
|
|
expect(edgeSet(propEdges)).toContain('User → address');
|
|
expect(edgeSet(propEdges)).toContain('Address → city');
|
|
expect(edgeSet(propEdges)).toContain('City → zipCode');
|
|
});
|
|
|
|
it('resolves 2-level chain: user.address.save() → Address#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCalls = calls.filter((e) => e.target === 'save' && e.source === 'processUser');
|
|
const addressSave = saveCalls.find((e) => e.targetFilePath.includes('Address'));
|
|
expect(addressSave).toBeDefined();
|
|
});
|
|
|
|
it('resolves 3-level chain: user.address.city.getName() → City#getName', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const getNameCalls = calls.filter((e) => e.target === 'getName' && e.source === 'processUser');
|
|
const cityGetName = getNameCalls.find((e) => e.targetFilePath.includes('City'));
|
|
expect(cityGetName).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Mixed field+call chain resolution (Java)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Mixed field+call chain resolution (Java)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-mixed-chain'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects classes: Address, App, City, User, UserService', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toEqual([
|
|
'Address',
|
|
'App',
|
|
'City',
|
|
'User',
|
|
'UserService',
|
|
]);
|
|
});
|
|
|
|
it('detects Property nodes for mixed-chain fields', () => {
|
|
const properties = getNodesByLabel(result, 'Property');
|
|
expect(properties).toContain('city');
|
|
expect(properties).toContain('address');
|
|
});
|
|
|
|
it('resolves call→field chain: svc.getUser().address.save() → Address#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCalls = calls.filter((e) => e.target === 'save' && e.source === 'processWithService');
|
|
expect(saveCalls.length).toBe(1);
|
|
expect(saveCalls[0].targetFilePath).toContain('Address');
|
|
});
|
|
|
|
it('resolves field→call chain: user.getAddress().city.getName() → City#getName', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const getNameCalls = calls.filter(
|
|
(e) => e.target === 'getName' && e.source === 'processWithUser',
|
|
);
|
|
expect(getNameCalls.length).toBe(1);
|
|
expect(getNameCalls[0].targetFilePath).toContain('City');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ACCESSES write edges from assignment expressions
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Write access tracking (Java)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-write-access'), () => {});
|
|
}, 60000);
|
|
|
|
it('emits ACCESSES write edges for field assignments', () => {
|
|
const accesses = getRelationships(result, 'ACCESSES');
|
|
const writes = accesses.filter((e) => e.rel.reason === 'write');
|
|
expect(writes.length).toBe(2);
|
|
const nameWrite = writes.find((e) => e.target === 'name');
|
|
const addressWrite = writes.find((e) => e.target === 'address');
|
|
expect(nameWrite).toBeDefined();
|
|
expect(nameWrite!.source).toBe('updateUser');
|
|
expect(addressWrite).toBeDefined();
|
|
expect(addressWrite!.source).toBe('updateUser');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Call-result variable binding (Phase 9): var user = getUser(); user.save()
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java call-result variable binding (Tier 2b)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-call-result-binding'), () => {});
|
|
}, 60000);
|
|
|
|
it('resolves user.save() to User#save via call-result binding', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'processUser' && c.targetFilePath.includes('User'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Method chain binding (Phase 9C): getUser() → .address → .getCity() → .save()
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java method chain binding via unified fixpoint (Phase 9C)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-method-chain-binding'), () => {});
|
|
}, 60000);
|
|
|
|
it('resolves city.save() to City#save via method chain', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) =>
|
|
c.target === 'save' && c.source === 'processChain' && c.targetFilePath.includes('Models'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Phase B: Deep MRO — walkParentChain() at depth 2 (C→B→A)
|
|
// greet() is defined on A, accessed via C. Tests BFS depth-2 parent traversal.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java grandparent method resolution via MRO (Phase B)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(FIXTURES, 'java-grandparent-resolution'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects A, B, C, Greeting classes', () => {
|
|
const classes = getNodesByLabel(result, 'Class');
|
|
expect(classes).toContain('A');
|
|
expect(classes).toContain('B');
|
|
expect(classes).toContain('C');
|
|
expect(classes).toContain('Greeting');
|
|
});
|
|
|
|
it('emits EXTENDS edges: B→A, C→B', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
expect(edgeSet(extends_)).toContain('B → A');
|
|
expect(edgeSet(extends_)).toContain('C → B');
|
|
});
|
|
|
|
it('resolves c.greet().save() to Greeting#save via depth-2 MRO lookup', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.targetFilePath.includes('Greeting'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
|
|
it('resolves c.greet() to A#greet (method found via MRO walk)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const greetCall = calls.find(
|
|
(c) => c.target === 'greet' && c.targetFilePath.includes('A.java'),
|
|
);
|
|
expect(greetCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ── Phase P: Overload Disambiguation via Parameter Types ─────────────────
|
|
|
|
describe('Java overload disambiguation by parameter types', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-overload-param-types'), () => {});
|
|
}, 60000);
|
|
|
|
it('produces distinct graph nodes for same-arity overloads via type-hash suffix', () => {
|
|
const methods = getNodesByLabelFull(result, 'Method');
|
|
const lookupNodes = methods.filter((m) => m.name === 'lookup');
|
|
// Type-hash disambiguation → 2 distinct graph nodes (lookup#1~int, lookup#1~String)
|
|
expect(lookupNodes.length).toBe(2);
|
|
const types = lookupNodes.map((n) => n.properties.parameterTypes).sort();
|
|
expect(types).toEqual([['String'], ['int']]);
|
|
});
|
|
|
|
it('callById() emits exactly one CALLS edge to lookup(int)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const fromCallById = calls.filter((c) => c.source === 'callById' && c.target === 'lookup');
|
|
expect(fromCallById.length).toBe(1);
|
|
const targetNode = result.graph.getNode(fromCallById[0].rel.targetId);
|
|
expect(targetNode?.properties.parameterTypes).toEqual(['int']);
|
|
});
|
|
|
|
it('callByName() emits exactly one CALLS edge to lookup(String)', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const fromCallByName = calls.filter((c) => c.source === 'callByName' && c.target === 'lookup');
|
|
expect(fromCallByName.length).toBe(1);
|
|
const targetNode = result.graph.getNode(fromCallByName[0].rel.targetId);
|
|
expect(targetNode?.properties.parameterTypes).toEqual(['String']);
|
|
});
|
|
});
|
|
|
|
// ── Phase P: Same-arity overloads — cross-file + chain resolution ─────────
|
|
|
|
describe('Java same-arity overload cross-file and chain resolution', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-same-arity-cross-file'), () => {});
|
|
}, 60000);
|
|
|
|
// -- Cross-file: caller in App.java → overloaded method in DbLookup.java --
|
|
|
|
it('crossFileById() emits exactly one CALLS edge to find(int) in DbLookup', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const edges = calls.filter(
|
|
(c) =>
|
|
c.source === 'crossFileById' &&
|
|
c.target === 'find' &&
|
|
c.targetFilePath.includes('DbLookup'),
|
|
);
|
|
expect(edges.length).toBe(1);
|
|
const targetNode = result.graph.getNode(edges[0].rel.targetId);
|
|
expect(targetNode?.properties.parameterTypes).toEqual(['int']);
|
|
});
|
|
|
|
it('crossFileByName() emits exactly one CALLS edge to find(String) in DbLookup', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const edges = calls.filter(
|
|
(c) =>
|
|
c.source === 'crossFileByName' &&
|
|
c.target === 'find' &&
|
|
c.targetFilePath.includes('DbLookup'),
|
|
);
|
|
expect(edges.length).toBe(1);
|
|
const targetNode = result.graph.getNode(edges[0].rel.targetId);
|
|
expect(targetNode?.properties.parameterTypes).toEqual(['String']);
|
|
});
|
|
|
|
// -- METHOD_IMPLEMENTS: DbLookup.find(int) → ILookup.find(int) etc. --
|
|
|
|
it('emits METHOD_IMPLEMENTS from DbLookup.find(int) → ILookup.find(int)', () => {
|
|
const mi = getRelationships(result, 'METHOD_IMPLEMENTS');
|
|
const edges = mi.filter(
|
|
(e) =>
|
|
e.source === 'find' &&
|
|
e.target === 'find' &&
|
|
e.sourceFilePath.includes('DbLookup') &&
|
|
e.targetFilePath.includes('ILookup'),
|
|
);
|
|
// Two distinct edges: find(int)→find(int) and find(String)→find(String)
|
|
expect(edges.length).toBe(2);
|
|
for (const edge of edges) {
|
|
const sourceNode = result.graph.getNode(edge.rel.sourceId);
|
|
const targetNode = result.graph.getNode(edge.rel.targetId);
|
|
expect(sourceNode?.properties.parameterTypes).toEqual(targetNode?.properties.parameterTypes);
|
|
}
|
|
});
|
|
|
|
// -- Chain: db.find(42) → result → fmt.format(result) --
|
|
|
|
it('chainIntToFormat() calls find and format — each resolves to exactly one overload', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const findEdges = calls.filter((c) => c.source === 'chainIntToFormat' && c.target === 'find');
|
|
const formatEdges = calls.filter(
|
|
(c) => c.source === 'chainIntToFormat' && c.target === 'format',
|
|
);
|
|
// find(42) → find(int)
|
|
expect(findEdges.length).toBe(1);
|
|
const findTarget = result.graph.getNode(findEdges[0].rel.targetId);
|
|
expect(findTarget?.properties.parameterTypes).toEqual(['int']);
|
|
// format(result) where result is String → format(String)
|
|
expect(formatEdges.length).toBe(1);
|
|
const formatTarget = result.graph.getNode(formatEdges[0].rel.targetId);
|
|
expect(formatTarget?.properties.parameterTypes).toEqual(['String']);
|
|
});
|
|
|
|
it('chainNameToFormat() calls find and format — each resolves to exactly one overload', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const findEdges = calls.filter((c) => c.source === 'chainNameToFormat' && c.target === 'find');
|
|
const formatEdges = calls.filter(
|
|
(c) => c.source === 'chainNameToFormat' && c.target === 'format',
|
|
);
|
|
// find("alice") → find(String)
|
|
expect(findEdges.length).toBe(1);
|
|
const findTarget = result.graph.getNode(findEdges[0].rel.targetId);
|
|
expect(findTarget?.properties.parameterTypes).toEqual(['String']);
|
|
// format(result) where result is String → format(String)
|
|
expect(formatEdges.length).toBe(1);
|
|
const formatTarget = result.graph.getNode(formatEdges[0].rel.targetId);
|
|
expect(formatTarget?.properties.parameterTypes).toEqual(['String']);
|
|
});
|
|
});
|
|
|
|
// ── Phase P: Virtual Dispatch via Constructor Type ───────────────────────
|
|
|
|
describe('Java virtual dispatch via constructor type (same-file)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-virtual-dispatch'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects Animal, Dog, and App classes in same file', () => {
|
|
const classes = getNodesByLabel(result, 'Class');
|
|
expect(classes).toContain('Animal');
|
|
expect(classes).toContain('Dog');
|
|
expect(classes).toContain('App');
|
|
});
|
|
|
|
it('detects Dog extends Animal heritage', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
const dogExtends = extends_.find((e) => e.source === 'Dog' && e.target === 'Animal');
|
|
expect(dogExtends).toBeDefined();
|
|
});
|
|
|
|
it('detects fetchBall() as Dog-only method', () => {
|
|
const methods = getNodesByLabel(result, 'Method');
|
|
expect(methods).toContain('fetchBall');
|
|
});
|
|
|
|
it('resolves fetchBall() calls from run() — proves virtual dispatch override', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const fetchCalls = calls.filter((c) => c.source === 'run' && c.target === 'fetchBall');
|
|
// animal.fetchBall() only resolves if constructorTypeMap overrides
|
|
// receiver from Animal → Dog (since only Dog has fetchBall).
|
|
// dog.fetchBall() resolves directly via Dog type.
|
|
// Both target same nodeId → 1 CALLS edge after dedup.
|
|
expect(fetchCalls.length).toBe(1);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Phase 14: Cross-file binding propagation
|
|
// models/UserFactory.java exports static getUser() returning User
|
|
// app/App.java static-imports getUser, calls var user = getUser(); user.save()
|
|
// → user is typed User via cross-file return type propagation
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java cross-file binding propagation', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'java-cross-file'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User class with save and getName methods', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('getName');
|
|
});
|
|
|
|
it('detects UserFactory class with getUser method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('UserFactory');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('getUser');
|
|
});
|
|
|
|
it('detects App class with run method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('App');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('run');
|
|
});
|
|
|
|
it('emits IMPORTS edge from App.java to UserFactory.java', () => {
|
|
const imports = getRelationships(result, 'IMPORTS');
|
|
const edge = imports.find(
|
|
(e) => e.sourceFilePath.includes('App') && e.targetFilePath.includes('UserFactory'),
|
|
);
|
|
expect(edge).toBeDefined();
|
|
});
|
|
|
|
it('resolves user.save() in run() to User#save via cross-file return type propagation', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'run' && c.targetFilePath.includes('User.java'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
|
|
it('resolves user.getName() in run() to User#getName via cross-file return type propagation', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const getNameCall = calls.find(
|
|
(c) => c.target === 'getName' && c.source === 'run' && c.targetFilePath.includes('User.java'),
|
|
);
|
|
expect(getNameCall).toBeDefined();
|
|
});
|
|
|
|
it('emits HAS_METHOD edges linking save and getName to User', () => {
|
|
const hasMethod = getRelationships(result, 'HAS_METHOD');
|
|
const saveEdge = hasMethod.find((e) => e.source === 'User' && e.target === 'save');
|
|
const getNameEdge = hasMethod.find((e) => e.source === 'User' && e.target === 'getName');
|
|
expect(saveEdge).toBeDefined();
|
|
expect(getNameEdge).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Method enrichment: abstract, static, annotations, parameterTypes
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java method enrichment', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-method-enrichment'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects Animal and Dog classes', () => {
|
|
const classes = getNodesByLabel(result, 'Class');
|
|
expect(classes).toContain('Animal');
|
|
expect(classes).toContain('Dog');
|
|
});
|
|
|
|
it('emits HAS_METHOD edges for Animal methods', () => {
|
|
const hasMethod = getRelationships(result, 'HAS_METHOD');
|
|
const animalMethods = hasMethod.filter((e) => e.source === 'Animal').map((e) => e.target);
|
|
expect(animalMethods).toContain('speak');
|
|
expect(animalMethods).toContain('classify');
|
|
expect(animalMethods).toContain('breathe');
|
|
});
|
|
|
|
it('emits HAS_METHOD edge for Dog.speak', () => {
|
|
const hasMethod = getRelationships(result, 'HAS_METHOD');
|
|
const dogSpeak = hasMethod.find((e) => e.source === 'Dog' && e.target === 'speak');
|
|
expect(dogSpeak).toBeDefined();
|
|
});
|
|
|
|
it('emits EXTENDS edge Dog -> Animal', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
const dogExtends = extends_.find((e) => e.source === 'Dog' && e.target === 'Animal');
|
|
expect(dogExtends).toBeDefined();
|
|
});
|
|
|
|
it('marks abstract speak as isAbstract (conditional)', () => {
|
|
const methods = getNodesByLabelFull(result, 'Function');
|
|
const speak = methods.find(
|
|
(n) => n.name === 'speak' && n.properties.filePath?.includes('Animal.java'),
|
|
);
|
|
if (speak?.properties.isAbstract !== undefined) {
|
|
expect(speak.properties.isAbstract).toBe(true);
|
|
}
|
|
});
|
|
|
|
it('marks breathe as NOT isAbstract (conditional)', () => {
|
|
const methods = getNodesByLabelFull(result, 'Function');
|
|
const breathe = methods.find((n) => n.name === 'breathe');
|
|
if (breathe?.properties.isAbstract !== undefined) {
|
|
expect(breathe.properties.isAbstract).toBe(false);
|
|
}
|
|
});
|
|
|
|
it('marks classify as isStatic (conditional)', () => {
|
|
const methods = getNodesByLabelFull(result, 'Function');
|
|
const classify = methods.find((n) => n.name === 'classify');
|
|
if (classify?.properties.isStatic !== undefined) {
|
|
expect(classify.properties.isStatic).toBe(true);
|
|
}
|
|
});
|
|
|
|
it('marks breathe as NOT isStatic (conditional)', () => {
|
|
const methods = getNodesByLabelFull(result, 'Function');
|
|
const breathe = methods.find((n) => n.name === 'breathe');
|
|
if (breathe?.properties.isStatic !== undefined) {
|
|
expect(breathe.properties.isStatic).toBe(false);
|
|
}
|
|
});
|
|
|
|
it('captures @Override annotation on Dog.speak (conditional)', () => {
|
|
const methods = getNodesByLabelFull(result, 'Function');
|
|
const dogSpeak = methods.find(
|
|
(n) => n.name === 'speak' && n.properties.annotations?.includes('@Override'),
|
|
);
|
|
if (dogSpeak) {
|
|
expect(dogSpeak.properties.annotations).toContain('@Override');
|
|
}
|
|
});
|
|
|
|
it('populates parameterTypes for classify (conditional)', () => {
|
|
const methods = getNodesByLabelFull(result, 'Function');
|
|
const classify = methods.find((n) => n.name === 'classify');
|
|
if (classify?.properties.parameterTypes !== undefined) {
|
|
expect(classify.properties.parameterTypes).toContain('String');
|
|
}
|
|
});
|
|
|
|
it('resolves dog.speak() CALLS edge', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const speakCall = calls.find(
|
|
(c) => c.target === 'speak' && c.sourceFilePath.includes('App.java'),
|
|
);
|
|
expect(speakCall).toBeDefined();
|
|
});
|
|
|
|
it('resolves Animal.classify() static CALLS edge', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const classifyCall = calls.find(
|
|
(c) => c.target === 'classify' && c.sourceFilePath.includes('App.java'),
|
|
);
|
|
expect(classifyCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Java interface dispatch (METHOD_IMPLEMENTS)
|
|
// Action interface: execute(), priority()
|
|
// LogEvent implements Action, SendEmail implements Action
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java interface dispatch (METHOD_IMPLEMENTS)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-interface-dispatch'), () => {});
|
|
}, 60000);
|
|
|
|
it('emits METHOD_IMPLEMENTS edges from LogEvent.execute → Action.execute', () => {
|
|
const mi = getRelationships(result, 'METHOD_IMPLEMENTS');
|
|
const edge = mi.find(
|
|
(e) =>
|
|
e.source === 'execute' &&
|
|
e.target === 'execute' &&
|
|
e.sourceFilePath.includes('LogEvent') &&
|
|
e.targetFilePath.includes('Action'),
|
|
);
|
|
expect(edge).toBeDefined();
|
|
});
|
|
|
|
it('emits METHOD_IMPLEMENTS edges from SendEmail.execute → Action.execute', () => {
|
|
const mi = getRelationships(result, 'METHOD_IMPLEMENTS');
|
|
const edge = mi.find(
|
|
(e) =>
|
|
e.source === 'execute' &&
|
|
e.target === 'execute' &&
|
|
e.sourceFilePath.includes('SendEmail') &&
|
|
e.targetFilePath.includes('Action'),
|
|
);
|
|
expect(edge).toBeDefined();
|
|
});
|
|
|
|
it('emits METHOD_IMPLEMENTS for priority() in both implementors', () => {
|
|
const mi = getRelationships(result, 'METHOD_IMPLEMENTS');
|
|
const priorityEdges = mi.filter(
|
|
(e) =>
|
|
e.source === 'priority' && e.target === 'priority' && e.targetFilePath.includes('Action'),
|
|
);
|
|
expect(priorityEdges.length).toBe(2);
|
|
const sourceFiles = priorityEdges.map((e) => e.sourceFilePath).sort();
|
|
expect(sourceFiles.some((f) => f.includes('LogEvent'))).toBe(true);
|
|
expect(sourceFiles.some((f) => f.includes('SendEmail'))).toBe(true);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Java overloaded method disambiguation (METHOD_IMPLEMENTS with arity)
|
|
// Repository interface: find(int), find(String, boolean), save(String)
|
|
// SqlRepository implements Repository with matching overloads
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java overloaded method disambiguation (METHOD_IMPLEMENTS)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-overload-dispatch'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects distinct Method nodes for overloaded find methods on SqlRepository', () => {
|
|
const methods = getNodesByLabelFull(result, 'Method');
|
|
const findMethods = methods.filter(
|
|
(m) => m.name === 'find' && m.properties.filePath?.includes('SqlRepository'),
|
|
);
|
|
expect(findMethods.length).toBe(2);
|
|
const paramCounts = findMethods.map((m) => m.properties.parameterCount).sort();
|
|
expect(paramCounts).toEqual([1, 2]);
|
|
});
|
|
|
|
it('detects distinct Method nodes for overloaded find methods on Repository interface', () => {
|
|
const methods = getNodesByLabelFull(result, 'Method');
|
|
const findMethods = methods.filter(
|
|
(m) =>
|
|
m.name === 'find' &&
|
|
m.properties.filePath?.includes('Repository') &&
|
|
!m.properties.filePath?.includes('SqlRepository'),
|
|
);
|
|
expect(findMethods.length).toBe(2);
|
|
const paramCounts = findMethods.map((m) => m.properties.parameterCount).sort();
|
|
expect(paramCounts).toEqual([1, 2]);
|
|
});
|
|
|
|
it('emits METHOD_IMPLEMENTS for find(int) → Repository.find(int)', () => {
|
|
const mi = getRelationships(result, 'METHOD_IMPLEMENTS');
|
|
const edge = mi.find(
|
|
(e) =>
|
|
e.source === 'find' &&
|
|
e.target === 'find' &&
|
|
e.sourceFilePath.includes('SqlRepository') &&
|
|
e.targetFilePath.includes('Repository'),
|
|
);
|
|
expect(edge).toBeDefined();
|
|
// Verify at least one find→find edge has arity 1 on source side
|
|
const findEdges = mi.filter(
|
|
(e) =>
|
|
e.source === 'find' &&
|
|
e.target === 'find' &&
|
|
e.sourceFilePath.includes('SqlRepository') &&
|
|
e.targetFilePath.includes('Repository'),
|
|
);
|
|
const sourceNodes = findEdges.map((e) => {
|
|
const methods = getNodesByLabelFull(result, 'Method');
|
|
return methods.find(
|
|
(m) =>
|
|
m.name === 'find' &&
|
|
m.properties.filePath?.includes('SqlRepository') &&
|
|
m.properties.parameterCount === 1,
|
|
);
|
|
});
|
|
expect(sourceNodes.some((n) => n !== undefined)).toBe(true);
|
|
});
|
|
|
|
it('emits METHOD_IMPLEMENTS for find(String, boolean) → Repository.find(String, boolean)', () => {
|
|
const mi = getRelationships(result, 'METHOD_IMPLEMENTS');
|
|
const findEdges = mi.filter(
|
|
(e) =>
|
|
e.source === 'find' &&
|
|
e.target === 'find' &&
|
|
e.sourceFilePath.includes('SqlRepository') &&
|
|
e.targetFilePath.includes('Repository'),
|
|
);
|
|
// There should be two find→find edges (one per overload)
|
|
expect(findEdges.length).toBe(2);
|
|
});
|
|
|
|
it('emits METHOD_IMPLEMENTS for save(String) → Repository.save(String)', () => {
|
|
const mi = getRelationships(result, 'METHOD_IMPLEMENTS');
|
|
const edge = mi.find(
|
|
(e) =>
|
|
e.source === 'save' &&
|
|
e.target === 'save' &&
|
|
e.sourceFilePath.includes('SqlRepository') &&
|
|
e.targetFilePath.includes('Repository'),
|
|
);
|
|
expect(edge).toBeDefined();
|
|
});
|
|
|
|
it('emits exactly 3 METHOD_IMPLEMENTS edges', () => {
|
|
const mi = getRelationships(result, 'METHOD_IMPLEMENTS');
|
|
const edges = mi.filter(
|
|
(e) => e.sourceFilePath.includes('SqlRepository') && e.targetFilePath.includes('Repository'),
|
|
);
|
|
expect(edges.length).toBe(3);
|
|
});
|
|
|
|
it('emits CALLS edges from run() to both find overloads', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const findCalls = calls.filter(
|
|
(c) =>
|
|
c.source === 'run' &&
|
|
c.target === 'find' &&
|
|
c.sourceFilePath.includes('App') &&
|
|
c.targetFilePath.includes('SqlRepository'),
|
|
);
|
|
expect(findCalls.length).toBe(2);
|
|
});
|
|
});
|
|
|
|
// ── Phase P: Sequential path parity — same-arity overloads ────────────────
|
|
|
|
describe('Java same-arity overloads (worker path)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-same-arity-cross-file'), () => {});
|
|
}, 60000);
|
|
|
|
it('produces distinct graph nodes for find(int) and find(String)', () => {
|
|
const methods = getNodesByLabelFull(result, 'Method');
|
|
const findNodes = methods.filter(
|
|
(m) => m.name === 'find' && m.properties.filePath?.includes('DbLookup'),
|
|
);
|
|
expect(findNodes.length).toBe(2);
|
|
const types = findNodes.map((n) => n.properties.parameterTypes).sort();
|
|
expect(types).toEqual([['String'], ['int']]);
|
|
});
|
|
|
|
it('crossFileById() → find(int) — sequential path', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const edges = calls.filter(
|
|
(c) =>
|
|
c.source === 'crossFileById' &&
|
|
c.target === 'find' &&
|
|
c.targetFilePath.includes('DbLookup'),
|
|
);
|
|
expect(edges.length).toBe(1);
|
|
const targetNode = result.graph.getNode(edges[0].rel.targetId);
|
|
expect(targetNode?.properties.parameterTypes).toEqual(['int']);
|
|
});
|
|
|
|
it('crossFileByName() → find(String) — sequential path', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const edges = calls.filter(
|
|
(c) =>
|
|
c.source === 'crossFileByName' &&
|
|
c.target === 'find' &&
|
|
c.targetFilePath.includes('DbLookup'),
|
|
);
|
|
expect(edges.length).toBe(1);
|
|
const targetNode = result.graph.getNode(edges[0].rel.targetId);
|
|
expect(targetNode?.properties.parameterTypes).toEqual(['String']);
|
|
});
|
|
|
|
it('METHOD_IMPLEMENTS edges match interface methods — sequential path', () => {
|
|
const mi = getRelationships(result, 'METHOD_IMPLEMENTS');
|
|
const edges = mi.filter(
|
|
(e) =>
|
|
e.source === 'find' &&
|
|
e.target === 'find' &&
|
|
e.sourceFilePath.includes('DbLookup') &&
|
|
e.targetFilePath.includes('ILookup'),
|
|
);
|
|
expect(edges.length).toBe(2);
|
|
for (const edge of edges) {
|
|
const sourceNode = result.graph.getNode(edge.rel.sourceId);
|
|
const targetNode = result.graph.getNode(edge.rel.targetId);
|
|
expect(sourceNode?.properties.parameterTypes).toEqual(targetNode?.properties.parameterTypes);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Cross-class pure method chain resolution via lookupMethodByOwner (#575)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Cross-class method chain resolution (Java) — #575', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(FIXTURES, 'java-method-chain-cross-class'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects classes: Address, App, City, User', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toEqual(['Address', 'App', 'City', 'User']);
|
|
});
|
|
|
|
it('two-step chain: user.getAddress().save() → Address#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCalls = calls.filter((e) => e.target === 'save' && e.source === 'twoStepChain');
|
|
expect(saveCalls.length).toBe(1);
|
|
expect(saveCalls[0].targetFilePath).toContain('Address');
|
|
});
|
|
|
|
it('two-step chain: user.getAddress().save() also emits CALLS to User#getAddress', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const getAddressCalls = calls.filter(
|
|
(e) => e.target === 'getAddress' && e.source === 'twoStepChain',
|
|
);
|
|
expect(getAddressCalls.length).toBe(1);
|
|
expect(getAddressCalls[0].targetFilePath).toContain('User');
|
|
});
|
|
|
|
it('three-step chain: user.getAddress().getCity().getZipCode() → City#getZipCode', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const zipCalls = calls.filter(
|
|
(e) => e.target === 'getZipCode' && e.source === 'threeStepChain',
|
|
);
|
|
expect(zipCalls.length).toBe(1);
|
|
expect(zipCalls[0].targetFilePath).toContain('City');
|
|
});
|
|
|
|
it('three-step chain emits CALLS for all intermediate steps', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const threeStepCalls = calls.filter((e) => e.source === 'threeStepChain');
|
|
const targets = threeStepCalls.map((e) => e.target).sort();
|
|
expect(targets).toContain('getAddress');
|
|
expect(targets).toContain('getCity');
|
|
expect(targets).toContain('getZipCode');
|
|
});
|
|
|
|
it('mixed chain: user.getAddress().city.getZipCode() → City#getZipCode', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const zipCalls = calls.filter((e) => e.target === 'getZipCode' && e.source === 'mixedChain');
|
|
expect(zipCalls.length).toBe(1);
|
|
expect(zipCalls[0].targetFilePath).toContain('City');
|
|
});
|
|
|
|
it('mixed chain emits ACCESSES edge for field step: .city on Address', () => {
|
|
const accesses = getRelationships(result, 'ACCESSES');
|
|
const cityAccess = accesses.filter((e) => e.target === 'city' && e.source === 'mixedChain');
|
|
expect(cityAccess.length).toBe(1);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// SM-9: inherited method resolution — class Child extends Parent
|
|
// child.parentMethod() resolves to Parent#parentMethod via the parent walk.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java Child extends Parent — inherited method resolution (SM-9)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(FIXTURES, 'java-child-extends-parent'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects Parent and Child classes', () => {
|
|
const classes = getNodesByLabel(result, 'Class');
|
|
expect(classes).toContain('Parent');
|
|
expect(classes).toContain('Child');
|
|
});
|
|
|
|
it('emits EXTENDS edge: Child → Parent', () => {
|
|
const extends_ = getRelationships(result, 'EXTENDS');
|
|
expect(edgeSet(extends_)).toContain('Child → Parent');
|
|
});
|
|
|
|
it('resolves c.parentMethod() to Parent#parentMethod via MRO walk', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const parentMethodCall = calls.find(
|
|
(c) => c.target === 'parentMethod' && c.targetFilePath.includes('Parent'),
|
|
);
|
|
expect(parentMethodCall).toBeDefined();
|
|
// Pin the caller too — not just the target — so a regression that
|
|
// misattributes the edge to a different source would fail loudly.
|
|
expect(parentMethodCall!.source).toBe('run');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// SM-11: Java User implements Validator — interface default method (Java 8+)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Java User implements Validator — interface default method (SM-11)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(FIXTURES, 'java-interface-default-method'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects Validator interface and User class', () => {
|
|
expect(getNodesByLabel(result, 'Interface')).toContain('Validator');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
});
|
|
|
|
it('emits IMPLEMENTS edge: User → Validator', () => {
|
|
const impls = getRelationships(result, 'IMPLEMENTS');
|
|
expect(edgeSet(impls)).toContain('User → Validator');
|
|
});
|
|
|
|
it('resolves user.validate() to Validator.validate via implements-split MRO', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const validateCall = calls.find(
|
|
(c) => c.target === 'validate' && c.targetFilePath.includes('Validator.java'),
|
|
);
|
|
expect(validateCall).toBeDefined();
|
|
expect(validateCall!.source).toBe('run');
|
|
});
|
|
});
|