mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-10-07 02:58:02 +00:00
* Initial plan * Initial setup - Phase 9 BindingAccumulator cross-file return type wiring Agent-Logs-Url: https://github.com/abhigyanpatwari/GitNexus/sessions/7cee6490-090d-4714-8cb5-a704168ff47a * feat(SM-15): wire BindingAccumulator into processCallsFromExtracted for Phase 9 cross-file return type propagation Agent-Logs-Url: https://github.com/abhigyanpatwari/GitNexus/sessions/7cee6490-090d-4714-8cb5-a704168ff47a * fix(SM-15): address all PR #763 review findings Performance (R1) - Changed _fileScopeByFile from Map<string, [string,string][]> to Map<string, Map<string,string>>. fileScopeGet(filePath, name) is now O(1) — replaces the O(n) linear scan + defensive-copy alloc that ran once per ConstructorBinding entry. fileScopeEntries() reconstructs tuples from Map.entries() for backward compat. - Updated finalize() dev-mode invariant to compare deduplicated Map size rather than raw array length (Map.set deduplicates same-name). Lifecycle (R2) - Documented that Phase 9 intentionally reads pre-finalize because finalize() cannot move before both the worker consumer (line 984) AND the sequential-path writer (line 1061). Pre-finalize reads are safe because finalize() is write-lock-only with no side effects. Replaced the ambiguous "populated but not yet finalized" comment with the full lifecycle ordering explanation. Sequential-path parity (R3) - Wired bindingAccumulator into processCalls at line 797 (sequential path) so verifyConstructorBindings gets the Phase 9 fallback. - Added bindingAccumulator parameter to processAssignmentsFromExtracted signature and wired it at the pipeline.ts call site (line 1026). - Both paths now produce identical Phase 9 behavior for the same code. Tracking comments (R4) - Added "Overlapping mechanism (N of 3)" cross-references at: 1. buildImportedReturnTypes (~line 109) 2. collectExportedBindings (~line 168) 3. Phase 9 fallback in verifyConstructorBindings (~line 563) Each links to the other two and notes future unification. Language coverage (R5) - Added 5 new Phase 9 integration test suites in cross-file-binding.test.ts: JavaScript, C++, C#, PHP, Ruby. Each uses the existing fixture directories and asserts getUser() → User → user.save() resolves. Total cross-file binding tests: 52 (was 37). Quality asymmetry (R6) - Added inline comment at the Phase 9 fallback noting worker-path entries are Tier 0/1 only and that binding accuracy is structurally lower for large repos where the worker path dominates. Tests (+21 new) - 6 fileScopeGet unit tests (happy path, unknown file/name, mixed scopes, post-dispose, duplicate varName last-write-wins) - 15 integration tests across 5 new language suites Verification - tsc --noEmit clean - 3147 unit tests pass (+6 new) - 52 cross-file binding integration tests pass (+15 new) - 1766 resolver integration tests pass - Zero regressions Plan: docs/plans/2026-04-10-001-fix-sm15-review-findings-plan.md Review: https://github.com/abhigyanpatwari/GitNexus/pull/763#issuecomment-4220354242 * fix(SM-15): gate accumulator fallback on resolution tier and fix sequential file-order dependency Two Codex adversarial reviews identified medium-severity bugs in the Phase 9 BindingAccumulator fallback: 1. Local-first violation: the fallback fired regardless of whether ctx.resolve() found same-file candidates, letting an imported callee shadow a local one and produce false CALLS edges. Fixed by gating on tiered.tier !== 'same-file' and callableDefs.length <= 1. 2. Sequential file-order dependency: processCalls flushed and verified per-file, so consumer files processed before their providers missed accumulator bindings. Fixed by splitting into a flush pre-pass (all files) then a resolution loop, mirroring the worker path's "all appends before any reads" pattern. Also adds 11 consumer-before-provider integration test fixtures (one per supported language) and 4 unit tests for tier gating edge cases. * refactor(SM-15): eliminate duplicated prepare logic in processCalls two-pass split Replace the duplicated pre-pass + legacy-path code (parse → query → heritage → TypeEnv → exports) with a single preparation loop followed by a resolution loop. Both paths now share the same preparation code — the only conditional is the accumulator flush. Side benefit: globalParentMap is now fully populated before any resolution runs, improving cross-file isSubclassOf accuracy regardless of file order. Net -118 lines (226 removed, 108 added). * fix(SM-15): address PR #763 third-pass review findings 1. Update stale dispose() JSDoc — remove forward-reference to Phase 9 wiring that is now complete; document actual consumers. 2. Add processAssignmentsFromExtracted Phase 9 unit test — verifies the accumulator fallback produces ACCESSES write edges when the SymbolTable has no returnType for the callee. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Gergo Magyar <gergomagyar@icloud.com>
790 lines
29 KiB
TypeScript
790 lines
29 KiB
TypeScript
/**
|
|
* Phase 14: Cross-file type binding propagation
|
|
*
|
|
* When file A exports `const user = getUser()` (resolved to type User), and
|
|
* file B imports `user`, Phase 14 seeds `user → User` into file B's type
|
|
* environment, enabling `user.save()` in file B to produce a CALLS edge to
|
|
* User#save.
|
|
*/
|
|
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import path from 'path';
|
|
import {
|
|
getRelationships,
|
|
getNodesByLabel,
|
|
runPipelineFromRepo,
|
|
type PipelineResult,
|
|
} from './resolvers/helpers.js';
|
|
|
|
const CROSS_FILE_FIXTURES = path.resolve(__dirname, '..', 'fixtures', 'cross-file-binding');
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Simple cross-file: models → service → app
|
|
// models.ts exports getUser(): User
|
|
// service.ts exports const user = getUser() (user → User via call-result)
|
|
// app.ts imports user from service → seeds user → User → resolves user.save()
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Cross-File Binding Propagation: TypeScript simple cross-file', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'ts-simple'), () => {});
|
|
}, 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 getUser function and main function', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('getUser');
|
|
expect(getNodesByLabel(result, 'Function')).toContain('main');
|
|
});
|
|
|
|
it('resolves user.save() in main() to User#save via cross-file binding', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'main' && c.targetFilePath.includes('models'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
|
|
it('resolves user.getName() in main() to User#getName via cross-file binding', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const getNameCall = calls.find(
|
|
(c) => c.target === 'getName' && c.source === 'main' && c.targetFilePath.includes('models'),
|
|
);
|
|
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();
|
|
});
|
|
|
|
it('emits IMPORTS edges across all three files', () => {
|
|
const imports = getRelationships(result, 'IMPORTS');
|
|
// service.ts → models.ts and app.ts → service.ts
|
|
expect(imports.length).toBeGreaterThanOrEqual(2);
|
|
const paths = imports.map((e) => `${e.sourceFilePath} → ${e.targetFilePath}`);
|
|
expect(paths.some((p) => p.includes('service') && p.includes('models'))).toBe(true);
|
|
expect(paths.some((p) => p.includes('app') && p.includes('service'))).toBe(true);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Re-export chain: core → index (barrel) → app
|
|
// core.ts exports getConfig(): Config
|
|
// index.ts re-exports getConfig from core (no new bindings)
|
|
// app.ts imports getConfig from index, creates local const config = getConfig()
|
|
// → config.validate() resolves to Config#validate via local call-result binding
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Cross-File Binding Propagation: TypeScript re-export chain', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'ts-reexport'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects Config class with validate method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Config');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('validate');
|
|
});
|
|
|
|
it('detects getConfig function and init function', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('getConfig');
|
|
expect(getNodesByLabel(result, 'Function')).toContain('init');
|
|
});
|
|
|
|
it('resolves config.validate() in init() to Config#validate', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const validateCall = calls.find(
|
|
(c) => c.target === 'validate' && c.source === 'init' && c.targetFilePath.includes('core'),
|
|
);
|
|
expect(validateCall).toBeDefined();
|
|
});
|
|
|
|
it('emits HAS_METHOD edge from Config to validate', () => {
|
|
const hasMethod = getRelationships(result, 'HAS_METHOD');
|
|
const edge = hasMethod.find((e) => e.source === 'Config' && e.target === 'validate');
|
|
expect(edge).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// E3: Cross-file return type propagation
|
|
// api.ts exports getConfig(): Config
|
|
// consumer.ts imports getConfig, calls const c = getConfig(); c.validate()
|
|
// → c is typed Config via importedReturnTypes (E3), enabling Config#validate edge
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Cross-File Binding Propagation: TypeScript E3 return type propagation', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'ts-return-type'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects Config class with validate method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('Config');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('validate');
|
|
});
|
|
|
|
it('detects getConfig function and run function', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('getConfig');
|
|
expect(getNodesByLabel(result, 'Function')).toContain('run');
|
|
});
|
|
|
|
it('resolves c.validate() in run() to Config#validate via cross-file return type propagation', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const validateCall = calls.find(
|
|
(c) => c.target === 'validate' && c.source === 'run' && c.targetFilePath.includes('api'),
|
|
);
|
|
expect(validateCall).toBeDefined();
|
|
});
|
|
|
|
it('emits HAS_METHOD edge from Config to validate', () => {
|
|
const hasMethod = getRelationships(result, 'HAS_METHOD');
|
|
const edge = hasMethod.find((e) => e.source === 'Config' && e.target === 'validate');
|
|
expect(edge).toBeDefined();
|
|
});
|
|
|
|
it('emits IMPORTS edge from consumer to api', () => {
|
|
const imports = getRelationships(result, 'IMPORTS');
|
|
const edge = imports.find(
|
|
(e) => e.sourceFilePath.includes('consumer') && e.targetFilePath.includes('api'),
|
|
);
|
|
expect(edge).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Circular imports: a.ts ↔ b.ts
|
|
// a.ts imports getB from b.ts; b.ts imports A from a.ts
|
|
// Conservative expectation: pipeline completes without error.
|
|
// Cross-file binding propagation across cycles is not guaranteed.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Cross-File Binding Propagation: TypeScript circular imports', () => {
|
|
let result: PipelineResult;
|
|
let pipelineError: unknown;
|
|
|
|
beforeAll(async () => {
|
|
try {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'ts-circular'), () => {});
|
|
} catch (err) {
|
|
pipelineError = err;
|
|
}
|
|
}, 60000);
|
|
|
|
it('pipeline completes without throwing on circular imports', () => {
|
|
expect(pipelineError).toBeUndefined();
|
|
});
|
|
|
|
it('detects both class A and class B', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('A');
|
|
expect(getNodesByLabel(result, 'Class')).toContain('B');
|
|
});
|
|
|
|
it('detects doA and doB methods', () => {
|
|
expect(getNodesByLabel(result, 'Method')).toContain('doA');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('doB');
|
|
});
|
|
|
|
it('detects processA and getB functions', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('processA');
|
|
expect(getNodesByLabel(result, 'Function')).toContain('getB');
|
|
});
|
|
|
|
it('emits IMPORTS edges reflecting the circular dependency', () => {
|
|
const imports = getRelationships(result, 'IMPORTS');
|
|
const paths = imports.map((e) => `${e.sourceFilePath} → ${e.targetFilePath}`);
|
|
// a.ts imports from b.ts
|
|
expect(paths.some((p) => p.includes('a.ts') && p.includes('b.ts'))).toBe(true);
|
|
// b.ts imports from a.ts
|
|
expect(paths.some((p) => p.includes('b.ts') && p.includes('a.ts'))).toBe(true);
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// SM-15 / Phase 9: Cross-file call-result variable binding — multi-language
|
|
//
|
|
// Each suite below loads a multi-file fixture where:
|
|
// - File A defines a factory function getUser() / get_user() → User
|
|
// - File B imports that function, calls `u = getUser()`, then calls u.save()
|
|
//
|
|
// The acceptance criteria: u.save() / u.save() / u.get_name() must resolve
|
|
// to the correct User method via cross-file call-result variable binding.
|
|
// These tests cover both the SymbolTable path (languages with explicit return
|
|
// type annotations) and validate that the Phase 9 BindingAccumulator wiring
|
|
// does not break existing behavior.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Phase 9 — Cross-File Call-Result Binding: Java', () => {
|
|
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 getUser factory and run method', () => {
|
|
expect(getNodesByLabel(result, 'Method')).toContain('getUser');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('run');
|
|
});
|
|
|
|
it('resolves user.save() in run() to User#save via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'run' && c.targetFilePath.includes('User'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
|
|
it('resolves user.getName() in run() to User#getName via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const getNameCall = calls.find(
|
|
(c) => c.target === 'getName' && c.source === 'run' && c.targetFilePath.includes('User'),
|
|
);
|
|
expect(getNameCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Phase 9 — Cross-File Call-Result Binding: Python', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'py-cross-file'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User class with save and get_name methods', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
// Python tree-sitter captures all function_definitions as Function, including methods
|
|
expect(getNodesByLabel(result, 'Function')).toContain('save');
|
|
expect(getNodesByLabel(result, 'Function')).toContain('get_name');
|
|
});
|
|
|
|
it('detects get_user function and run function', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('get_user');
|
|
expect(getNodesByLabel(result, 'Function')).toContain('run');
|
|
});
|
|
|
|
it('resolves u.save() in run() to User#save via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'run' && c.targetFilePath.includes('models'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
|
|
it('resolves u.get_name() in run() to User#get_name via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const getNameCall = calls.find(
|
|
(c) => c.target === 'get_name' && c.source === 'run' && c.targetFilePath.includes('models'),
|
|
);
|
|
expect(getNameCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Phase 9 — Cross-File Call-Result Binding: Go', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'go-cross-file'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User struct with Save and GetName methods', () => {
|
|
expect(getNodesByLabel(result, 'Struct')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('Save');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('GetName');
|
|
});
|
|
|
|
it('detects GetUser function and main function', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('GetUser');
|
|
expect(getNodesByLabel(result, 'Function')).toContain('main');
|
|
});
|
|
|
|
it('resolves user.Save() in main() to User#Save via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'Save' && c.source === 'main' && c.targetFilePath.includes('models'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Phase 9 — Cross-File Call-Result Binding: Kotlin', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'kotlin-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 getUser function and run method', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('getUser');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('run');
|
|
});
|
|
|
|
it('resolves u.save() in run() to User#save via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'run' && c.targetFilePath.includes('User'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Phase 9 — Cross-File Call-Result Binding: Rust', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'rs-cross-file'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User struct with save and get_name methods', () => {
|
|
expect(getNodesByLabel(result, 'Struct')).toContain('User');
|
|
// Rust tree-sitter captures impl fns as Function nodes
|
|
expect(getNodesByLabel(result, 'Function')).toContain('save');
|
|
expect(getNodesByLabel(result, 'Function')).toContain('get_name');
|
|
});
|
|
|
|
it('detects get_user function and process function', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('get_user');
|
|
expect(getNodesByLabel(result, 'Function')).toContain('process');
|
|
});
|
|
|
|
it('resolves u.save() in process() to User#save via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'process' && c.targetFilePath.includes('models'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ── R5: Missing language coverage (PR #763 review finding #5) ────────────
|
|
|
|
describe('Phase 9 — Cross-File Call-Result Binding: JavaScript', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'js-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 getUser factory and run function', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('getUser');
|
|
expect(getNodesByLabel(result, 'Function')).toContain('run');
|
|
});
|
|
|
|
it('resolves u.save() in run() to User#save via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'run' && c.targetFilePath.includes('models'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Phase 9 — Cross-File Call-Result Binding: C++', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'cpp-cross-file'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User class with save and get_name methods', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('get_name');
|
|
});
|
|
|
|
it('detects get_user factory function', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('get_user');
|
|
});
|
|
|
|
it('resolves user.save() in process() to User#save via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'process' && c.targetFilePath.includes('user'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Phase 9 — Cross-File Call-Result Binding: C#', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'csharp-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 GetUser factory and Run method', () => {
|
|
expect(getNodesByLabel(result, 'Method')).toContain('GetUser');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('Run');
|
|
});
|
|
|
|
it('resolves u.Save() in Run() to User#Save via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'Save' && c.source === 'Run' && c.targetFilePath.includes('User'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Phase 9 — Cross-File Call-Result Binding: PHP', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'php-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 getUser factory function', () => {
|
|
expect(getNodesByLabel(result, 'Function')).toContain('getUser');
|
|
});
|
|
|
|
it('resolves $u->save() in run() to User#save via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'run' && c.targetFilePath.includes('User'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Phase 9 — Cross-File Call-Result Binding: Ruby', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(path.join(CROSS_FILE_FIXTURES, 'rb-cross-file'), () => {});
|
|
}, 60000);
|
|
|
|
it('detects User class with save and get_name methods', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('get_name');
|
|
});
|
|
|
|
it('detects get_user factory method', () => {
|
|
expect(getNodesByLabel(result, 'Method')).toContain('get_user');
|
|
});
|
|
|
|
it('resolves user.save in process() to User#save via cross-file return type', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'process' && c.targetFilePath.includes('models'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Note: shadowed import tier gating is tested at the unit level
|
|
// (call-processor.test.ts "Phase 9 tier gating" tests) because the scenario
|
|
// requires invalid TypeScript (same name imported and locally defined).
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Regression: consumer file processed before provider in sequential path
|
|
// a-consumer.ts (alphabetically first) imports getUser from b-provider.ts.
|
|
// Without the two-pass flush fix, the accumulator wouldn't have b-provider's
|
|
// bindings when a-consumer's verifyConstructorBindings runs.
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// Consumer-before-provider regression tests (sequential ordering fix)
|
|
//
|
|
// Each language fixture has a consumer file that sorts alphabetically before
|
|
// the provider file. In the sequential path, the consumer is processed first.
|
|
// The two-pass flush ensures the accumulator has provider bindings before
|
|
// verifyConstructorBindings runs for the consumer.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Consumer-Before-Provider: TypeScript', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'ts-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User class and save method from provider', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
});
|
|
|
|
it('resolves x.save() to User#save despite consumer sorted before provider', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'main' && c.targetFilePath.includes('b-provider'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Consumer-Before-Provider: JavaScript', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'js-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User class and save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
});
|
|
|
|
it('resolves u.save() in main() to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'main' && c.targetFilePath.includes('b-provider'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Consumer-Before-Provider: Python', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'py-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User class and save function', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
// Python tree-sitter captures all function_definitions as Function, including methods
|
|
expect(getNodesByLabel(result, 'Function')).toContain('save');
|
|
});
|
|
|
|
it('resolves u.save() in main() to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find(
|
|
(c) => c.target === 'save' && c.source === 'main' && c.targetFilePath.includes('b_provider'),
|
|
);
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Consumer-Before-Provider: Java', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'java-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User class and save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
});
|
|
|
|
it('resolves user.save() in run() to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save' && c.source === 'run');
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Consumer-Before-Provider: Go', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'go-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User struct and Save method', () => {
|
|
expect(getNodesByLabel(result, 'Struct')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('Save');
|
|
});
|
|
|
|
it('resolves user.Save() in main() to User#Save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'Save' && c.source === 'main');
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Consumer-Before-Provider: C++', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'cpp-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User class and save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
});
|
|
|
|
it('resolves user.save() in process() to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save' && c.source === 'process');
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Consumer-Before-Provider: C#', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'csharp-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User class and Save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('Save');
|
|
});
|
|
|
|
it('resolves u.Save() in Run() to User#Save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'Save' && c.source === 'Run');
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Consumer-Before-Provider: Kotlin', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'kotlin-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User class and save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
});
|
|
|
|
it('resolves u.save() in run() to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save' && c.source === 'run');
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Consumer-Before-Provider: PHP', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'php-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User class and save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
});
|
|
|
|
it('resolves $u->save() in run() to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save' && c.source === 'run');
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Consumer-Before-Provider: Ruby', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'rb-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User class and save method', () => {
|
|
expect(getNodesByLabel(result, 'Class')).toContain('User');
|
|
expect(getNodesByLabel(result, 'Method')).toContain('save');
|
|
});
|
|
|
|
it('resolves user.save in process() to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save' && c.source === 'process');
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Consumer-Before-Provider: Rust', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(CROSS_FILE_FIXTURES, 'rs-consumer-before-provider'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('detects User struct and save function', () => {
|
|
expect(getNodesByLabel(result, 'Struct')).toContain('User');
|
|
// Rust tree-sitter captures impl fns as Function nodes
|
|
expect(getNodesByLabel(result, 'Function')).toContain('save');
|
|
});
|
|
|
|
it('resolves u.save() in process() to User#save', () => {
|
|
const calls = getRelationships(result, 'CALLS');
|
|
const saveCall = calls.find((c) => c.target === 'save' && c.source === 'process');
|
|
expect(saveCall).toBeDefined();
|
|
});
|
|
});
|