mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-12-04 00:17:24 +00:00
* fix(ingestion): enable qualifiedNodeId for Python/C#/Kotlin/Swift nested types (#4188) When two enclosing types each define a nested type with the same simple name (e.g. `Outer.Inner` vs `Other.Inner`), the graph collapsed them into a single Class node because the class-extractor configs for Python, C#, Kotlin, and Swift lacked `qualifiedNodeId: true`. Enable the flag in all four language configs — the same fix already applied to C++ and Ruby in #1978/#2874 — so nested type node IDs use their fully-qualified ancestor path. Add integration tests covering all four languages with minimal fixtures that reproduce the same-tail collision and verify distinct nodes + correct method ownership. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ingestion): qualify colliding nested type IDs only Ported from #4210. Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> * fix(csharp): preserve ownership of same-name nested members Ported from #4210. Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> * fix(kotlin): preserve ownership of same-name nested members Ported from #4210. Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> * fix(python): resolve methods to their enclosing nested types Ported from #4210. Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> * fix(swift): resolve methods to their enclosing nested types Ported from #4210. Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> * fix(csharp): keep IDs stable for types with unique names Ported from abhigyanpatwari/GitNexus#4210. Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> * fix(kotlin): keep IDs stable for types with unique names Ported from abhigyanpatwari/GitNexus#4210. Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> * test(ingestion): cover nested type IDs and same-name members Ported from abhigyanpatwari/GitNexus#4210. Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> * test(resolver): prevent calls from crossing nested owners Ported from abhigyanpatwari/GitNexus#4210. Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> * test(swift): assert the fully qualified nested targets Ported from abhigyanpatwari/GitNexus#4210. Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> * test(ingestion): record nested type capture goldens * perf(ingestion): index related class owners per syntax tree Reuse the enclosing-class lookup for repeat queries without traversing unrelated declarations. * perf(ingestion): bound nested class owner resolution Consult the per-tree owner index for declaration scope and preserve the defining declaration when matching extensions. * fix(swift): match extensions to the real type declaration Handle reversed declaration order and keep a file-level extension separate from a function-local type. * fix(kotlin): preserve qualified heritage capture owners Carry the qualified declaration identity through Kotlin captures so inheritance edges retain the correct sources. * fix(kotlin): resolve members against their declaring owner Use package-aware nested identities consistently in the Kotlin provider. * fix(python): reuse nested class ownership lookups Resolve owners through the shared collision-aware class extractor. * fix(swift): reuse declaration-aware owner resolution Use the Swift class extractor when resolving container owners. * test(resolver): assert exact constructor call counts Require the expected number of targets in each language fixture, including unresolved calls. * test(ingestion): cover nested identities and declaration order Assert graph identities, declaration ranges and extension ownership across source orders. * test(resolver): verify exact nested inheritance and owners Cover the emitted relationships for colliding nested type names. * test(ingestion): retain contributor regressions for nested identities Retains the seven regression cases contributed by @DewmithMihisara in 1603cad15 for Kotlin inheritance, C# partials and Swift extension order. * test(ingestion): enforce bounded descendant searches Measure repeat queries and single lookups beside unrelated subtrees at increasing nesting depths. * fix(ingestion): distinguish genuinely colliding nested owners Qualify declarations only when their fully qualified identities differ. Preserve ordinary partial declarations. * fix(kotlin): preserve the package for nested type identity Record the provider data used to distinguish colliding declarations in a common package. * refactor(ingestion): read the enclosing owner once per stack step Use the current top entry directly while closing finished declaration scopes. * refactor(ingestion): reuse the enclosing scope while indexing Read the last stack entry once per step when selecting the enclosing scope. * refactor(swift): simplify extension type lookup Guard the declaration kind before reading its optional name. * test(kotlin): bound owner scans across provider hooks Exercise class extraction and container resolution on one parsed file with 32 colliding nested declarations. The second hook must reuse both indexes without a new full-file scan. Restoring an uncached collision scan makes the test fail with 33 scans. * test(resolvers): respect optional grammars in ownership fixtures Use the existing grammar availability check so the optional parser cases run on supported installations. The required-language regression coverage still runs when Swift or Kotlin is disabled. * test(ingestion): retain required node ID coverage without optional grammars Use the existing grammar availability check so the optional parser cases run on supported installations. The required-language regression coverage still runs when Swift or Kotlin is disabled. * test(resolvers): gate optional nested collision fixtures Use the existing grammar availability check so the optional parser cases run on supported installations. The required-language regression coverage still runs when Swift or Kotlin is disabled. * test(resolvers): run nested calls for installed language grammars Use the existing grammar availability check so the optional parser cases run on supported installations. The required-language regression coverage still runs when Swift or Kotlin is disabled. * test(kotlin): run the owner scan budget when the grammar is installed Use the existing grammar availability check so the optional parser cases run on supported installations. The required-language regression coverage still runs when Swift or Kotlin is disabled. * test(swift): verify the source text selected by declaration spans Verify the complete class declaration using its zero-based inclusive graph span in both nested source orders and for an extension-first top-level class. Shifting the span by a single row fails both regressions. * docs(ingestion): explain how class and member owner IDs agree Document the separate per-symbol and member-owner paths verified by the compiled-worker mutation. * test(swift): cover extension ownership in provider coverage Add tests for Swift extension captures and member owners. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Gergő Magyar <gergomagyar@icloud.com> Co-authored-by: DewmithMihisara <mihisaralokuhewage@gmail.com> Co-authored-by: Abhinav Pandey <abhinavpandey1230@gmail.com> Co-authored-by: Abhigyan Patwari <126312502+abhigyanpatwari@users.noreply.github.com> Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
185 lines
7.1 KiB
TypeScript
185 lines
7.1 KiB
TypeScript
/**
|
|
* Same-tail nested-type collision — Python, C#, Kotlin, Swift (#4188).
|
|
*
|
|
* When two enclosing types each define a nested type with the same simple name,
|
|
* the graph must produce two distinct Class nodes keyed by their fully-qualified
|
|
* path (e.g. Outer.Inner vs Other.Inner). Without `qualifiedNodeId: true` in
|
|
* the class-extractor config, both collapse into a single node and methods
|
|
* cross-wire. Modeled on the C++/Ruby fix verified in #1978/#2874.
|
|
*/
|
|
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import path from 'path';
|
|
import { SupportedLanguages } from 'gitnexus-shared';
|
|
import { optionalGrammarGate } from '../../helpers/optional-grammar.js';
|
|
|
|
import {
|
|
FIXTURES,
|
|
getRelationships,
|
|
useFixture,
|
|
getNodesByLabelFull,
|
|
findDanglingEdges,
|
|
runPipelineFromRepo,
|
|
type PipelineResult,
|
|
} from './helpers.js';
|
|
|
|
const describeKotlin = describe.skipIf(optionalGrammarGate(SupportedLanguages.Kotlin).skip);
|
|
const describeSwift = describe.skipIf(optionalGrammarGate(SupportedLanguages.Swift).skip);
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Python: class UserForm > class Meta vs class PostForm > class Meta
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('Python nested same-tail collision — distinct qualified nodes (#4188)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(FIXTURES, 'python-nested-tail-collision'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('materializes UserForm.Meta and PostForm.Meta as two distinct Class nodes', () => {
|
|
const qns = getNodesByLabelFull(result, 'Class')
|
|
.map((n) => n.properties.qualifiedName)
|
|
.filter((q) => q === 'UserForm.Meta' || q === 'PostForm.Meta')
|
|
.sort();
|
|
expect(qns).toEqual(['PostForm.Meta', 'UserForm.Meta']);
|
|
});
|
|
|
|
it('owns clean_username / clean_title through their OWN parent (not Meta)', () => {
|
|
expect(findDanglingEdges(result, ['HAS_METHOD'])).toEqual([]);
|
|
const hm = getRelationships(result, 'HAS_METHOD');
|
|
const ownerQn = (target: string) => {
|
|
const e = hm.find((x) => x.target === target);
|
|
if (!e) throw new Error(`Missing HAS_METHOD edge to ${target}`);
|
|
return result.graph.getNode(e.rel.sourceId)?.properties.qualifiedName;
|
|
};
|
|
expect(ownerQn('clean_username')).toBe('UserForm');
|
|
expect(ownerQn('clean_title')).toBe('PostForm');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// C#: class Outer > class Inner vs class Other > class Inner
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('C# nested same-tail collision — distinct qualified nodes (#4188)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(FIXTURES, 'csharp-nested-tail-collision'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('materializes Outer.Inner and Other.Inner as two distinct Class nodes', () => {
|
|
const qns = getNodesByLabelFull(result, 'Class')
|
|
.map((n) => n.properties.qualifiedName)
|
|
.filter((q) => q === 'Outer.Inner' || q === 'Other.Inner')
|
|
.sort();
|
|
expect(qns).toEqual(['Other.Inner', 'Outer.Inner']);
|
|
});
|
|
|
|
it('owns FromOuter / FromOther through their OWN distinct node', () => {
|
|
expect(findDanglingEdges(result, ['HAS_METHOD'])).toEqual([]);
|
|
const hm = getRelationships(result, 'HAS_METHOD');
|
|
const ownerQn = (target: string) => {
|
|
const e = hm.find((x) => x.target === target);
|
|
if (!e) throw new Error(`Missing HAS_METHOD edge to ${target}`);
|
|
return result.graph.getNode(e.rel.sourceId)?.properties.qualifiedName;
|
|
};
|
|
expect(ownerQn('FromOuter')).toBe('Outer.Inner');
|
|
expect(ownerQn('FromOther')).toBe('Other.Inner');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Kotlin: class Outer > class Inner vs class Other > class Inner
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describeKotlin('Kotlin nested same-tail collision — distinct qualified nodes (#4188)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(FIXTURES, 'kotlin-nested-tail-collision'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('materializes Outer.Inner and Other.Inner as two distinct Class nodes', () => {
|
|
const qns = getNodesByLabelFull(result, 'Class')
|
|
.map((n) => n.properties.qualifiedName)
|
|
.filter((q) => q === 'Outer.Inner' || q === 'Other.Inner')
|
|
.sort();
|
|
expect(qns).toEqual(['Other.Inner', 'Outer.Inner']);
|
|
});
|
|
|
|
it('owns fromOuter / fromOther through their OWN distinct node', () => {
|
|
expect(findDanglingEdges(result, ['HAS_METHOD'])).toEqual([]);
|
|
const hm = getRelationships(result, 'HAS_METHOD');
|
|
const ownerQn = (target: string) => {
|
|
const e = hm.find((x) => x.target === target);
|
|
if (!e) throw new Error(`Missing HAS_METHOD edge to ${target}`);
|
|
return result.graph.getNode(e.rel.sourceId)?.properties.qualifiedName;
|
|
};
|
|
expect(ownerQn('fromOuter')).toBe('Outer.Inner');
|
|
expect(ownerQn('fromOther')).toBe('Other.Inner');
|
|
});
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Swift: class Outer > class Inner vs class Other > class Inner
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describeSwift('Swift nested same-tail collision — distinct qualified nodes (#4188)', () => {
|
|
let result: PipelineResult;
|
|
|
|
beforeAll(async () => {
|
|
result = await runPipelineFromRepo(
|
|
path.join(FIXTURES, 'swift-nested-tail-collision'),
|
|
() => {},
|
|
);
|
|
}, 60000);
|
|
|
|
it('materializes Outer.Inner and Other.Inner as two distinct Class nodes', () => {
|
|
const qns = getNodesByLabelFull(result, 'Class')
|
|
.map((n) => n.properties.qualifiedName)
|
|
.filter((q) => q === 'Outer.Inner' || q === 'Other.Inner')
|
|
.sort();
|
|
expect(qns).toEqual(['Other.Inner', 'Outer.Inner']);
|
|
});
|
|
|
|
it('owns fromOuter / fromOther through their OWN distinct node', () => {
|
|
expect(findDanglingEdges(result, ['HAS_METHOD'])).toEqual([]);
|
|
const hm = getRelationships(result, 'HAS_METHOD');
|
|
const ownerQn = (target: string) => {
|
|
const e = hm.find((x) => x.target === target);
|
|
if (!e) throw new Error(`Missing HAS_METHOD edge to ${target}`);
|
|
return result.graph.getNode(e.rel.sourceId)?.properties.qualifiedName;
|
|
};
|
|
expect(ownerQn('fromOuter')).toBe('Outer.Inner');
|
|
expect(ownerQn('fromOther')).toBe('Other.Inner');
|
|
});
|
|
});
|
|
|
|
describeKotlin('Kotlin same-tail inheritance uses the declaring type', () => {
|
|
const run = useFixture('nested-kotlin-heritage', {
|
|
'M.kt':
|
|
'package app\nopen class First\nopen class Second\n' +
|
|
'class A { class Inner : First() }\nclass B { class Inner : Second() }\n',
|
|
});
|
|
|
|
it('keeps both complete EXTENDS pairs distinct', () => {
|
|
expect(
|
|
getRelationships(run(), 'EXTENDS')
|
|
.map(({ rel }) => [rel.sourceId, rel.targetId])
|
|
.sort(),
|
|
).toEqual([
|
|
['Class:M.kt:app.A.Inner', 'Class:M.kt:First'],
|
|
['Class:M.kt:app.B.Inner', 'Class:M.kt:Second'],
|
|
]);
|
|
});
|
|
});
|