mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-29 23:37:41 +00:00
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
* test(java): compare overload resolution with javac in CI * test(conformance): share call resolution reports across tools * test(java): cover the overload conversion matrix with javac (#4057) Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> * test(java): run Java-backed fixtures in dedicated CI shards * test(java): replace handwritten resolution cases with javac comparisons * test(java): compare lambda and receiver fixtures against javac * fix(ci): restore Java test evidence and use locked toolchain commands * test(skills): fail incomplete CLI generation checks (#4056) * test(java): compare method references with javac * fix(java): resolve qualified bases and static wildcard overloads * test(java): preserve declared dollar names in compiler comparisons * fix(java): preserve distinct call targets for colliding type names * fix(conformance): resolve private nested bases and retain overload selections * fix(java): distinguish variadic overloads in the published graph * fix(java): match javac for nested types, imports and initializer calls * Move Java fixture testing out of Vitest and into compiler conformance * Verify Java graph endpoints and leave call selection to javac * Match javac for annotated bases and legal static imports * Resolve nested Java member types and clean up failed conformance fixtures * Preserve qualified Java bases across unrelated static wildcard imports * test(java): run inline source fixtures in compiler conformance * test(conformance): check fetch callers, lexical bindings and cleanup * test(java): move virtual source and text fixtures into conformance * fix(java): resolve imported member types and qualified base collisions * Match javac constructor overloads and preserve Java conformance coverage * Compare recovered Java inheritance with javac in the conformance runner * Run the Java query compilation smoke test in native conformance * Clarify Java conformance expectations and check populated suites * Write javac conformance records as UTF-8 on Windows * Compile the Java conformance tools for SonarCloud analysis * Compare Java method implementation edges with javac * Resolve fixture writers and inherited Java methods in their lexical context * Resolve qualified Java bases through their accessible type members * Match local qualified Java bases and bounded varargs identities to javac * Match Java call resolution to javac across the conformance corpus Preserve generic declaration identity, follow nested call results, and type lambda aliases and enhanced-loop variables in their declaration scopes. Report proven JDK call targets without creating workspace edges. Compare every selected source and binary call against javac and remove the twelve mismatch lists. * Compare Java recovery targets as sets and check empty destination addresses Keep repeated uses of the same declaration equivalent across graph producers while detecting missing and extra targets. Check raw destination addresses and document the source and classpath inputs to the compiler comparison. * Avoid extra native parent walks while capturing Java call facts Index lambda origins by spelling before walking lexical scopes, and only check value shadowing for qualifiers rooted in an identifier. This restores the capture traversal budget for anonymous classes while preserving javac call targets. * Refresh the Java capture fingerprint for corrected fixture comments The module captures include the revised comments and the following declarations move to earlier lines. Both emitters produce the same 4,288 capture groups when given the same fixture revision. * Preserve Java conformance assertions and use trusted fixture paths Use explicit canonical sort orders, require missing evidence to fail assertions, and keep pending query results in the replay cache. Resolve the Git executable independently of the test repository and isolate the Spring workspace per test. * Resolve inherited Java members through the scoped superclass * Reuse validated analyzer build hashes for parser cache identity * Resolve SonarCloud findings in Java resolution and compiler conformance * Align Java compiler tool packages and pin benchmark baselines to the tested merge * Honor wildcard method families and fixture ownership in Java conformance * fix(java): resolve inherited and annotation member types against javac Keep workspace links tied to import declarations and compare Java varargs overloads through comments. Make generated-project selection, method metadata checks and Java fixture ownership explicit in conformance. * fix(java): resolve bounded and imported bases during dispatch Keep the type selected from a qualified heritage clause available during overload resolution. Compare annotated bounds, inherited static imports, and String.valueOf arguments directly with javac. Detect Java fixture paths on either side of a filesystem rename. * Conform Java method visibility and wildcard lambda bounds to javac Compare method access at source positions, recognize CommonJS fixture reads, and preserve diagnostics when native conformance setup fails. * Match javac for qualified member overloads and selective call diagnostics * Track reassigned Java fixture paths at their point of use * Respect Java visibility and Node path semantics in conformance checks * Align Java graph benchmarks with compiler-verified visibility * Record the public Java record accessor in the mixed-provider benchmark * Address remaining Java conformance analysis findings Keep repository import scans sequential, simplify Java header and overload resolution, and reuse Spring conformance measurements. Preserve compiler comparison assertions and emitted fixture contents. * Match javac on nested binary names, null factories and recovered calls Preserve the qualified annotation target in workspace links. Compare valid and invalid arguments separately so an attributed recovery symbol cannot mask a failed invocation. --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
412 lines
15 KiB
TypeScript
412 lines
15 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { afterEach, describe, it } from 'node:test';
|
|
import { getJavaParser } from '../../../../../src/core/ingestion/languages/java/query.js';
|
|
import {
|
|
captureJavaOverloadFacts,
|
|
clearJavaOverloadFacts,
|
|
getJavaOverloadCall,
|
|
getJavaOverloadFacts,
|
|
isJavaOverloadFileFacts,
|
|
setJavaOverloadFacts,
|
|
} from '../../../../../src/core/ingestion/languages/java/overload-argument-facts.js';
|
|
|
|
function capture(source: string) {
|
|
const tree = getJavaParser().parse(source);
|
|
return captureJavaOverloadFacts(tree.rootNode)!;
|
|
}
|
|
afterEach(clearJavaOverloadFacts);
|
|
|
|
describe('Java lossless overload argument facts', () => {
|
|
it('does not compare bindings from unrelated methods with the same parameter name', () => {
|
|
const size = 128;
|
|
const tree = getJavaParser().parse(
|
|
`class Wide { ${Array.from(
|
|
{ length: size },
|
|
(_, i) => `void method${i}(String value) { use(value); }`,
|
|
).join('\n')} }`,
|
|
);
|
|
const owner = tree.rootNode.namedChildren[0]!;
|
|
const id = owner.id;
|
|
let reads = 0;
|
|
Object.defineProperty(owner, 'id', {
|
|
get() {
|
|
reads++;
|
|
return id;
|
|
},
|
|
});
|
|
const facts = captureJavaOverloadFacts(tree.rootNode)!;
|
|
assert.equal(facts.calls.length, size);
|
|
for (const call of facts.calls)
|
|
assert.partialDeepStrictEqual(call.arguments[0], { kind: 'typed', spelling: 'String' });
|
|
assert.ok(reads <= size * 16);
|
|
});
|
|
|
|
it('materializes a wide class body once during traversal', () => {
|
|
const source = `class Wide { ${Array.from(
|
|
{ length: 128 },
|
|
(_, i) => `void method${i}() { use("text"); }`,
|
|
).join('\n')} }`;
|
|
const tree = getJavaParser().parse(source);
|
|
const body = tree.rootNode.namedChildren[0]!.childForFieldName('body')!;
|
|
const children = body.namedChildren;
|
|
let reads = 0;
|
|
Object.defineProperty(body, 'namedChildren', {
|
|
get() {
|
|
reads++;
|
|
return children;
|
|
},
|
|
});
|
|
const facts = captureJavaOverloadFacts(tree.rootNode)!;
|
|
assert.equal(facts.methods.length, 128);
|
|
assert.equal(facts.calls.length, 128);
|
|
assert.equal(reads, 1);
|
|
});
|
|
|
|
it('keeps formal parameters in their own methods and respects field/block shadowing', () => {
|
|
const facts = capture(`class A {
|
|
Long value;
|
|
void first(String value) { use(value); }
|
|
void second(Long value) { use(value); }
|
|
void blocks() { { String value = "x"; use(value); } use(value); }
|
|
}`);
|
|
assert.partialDeepStrictEqual(
|
|
facts.calls.filter((call) => call.name === 'use').map((call) => call.arguments[0]),
|
|
[
|
|
{ kind: 'typed', spelling: 'String' },
|
|
{ kind: 'typed', spelling: 'Long' },
|
|
{ kind: 'typed', spelling: 'String' },
|
|
{ kind: 'typed', spelling: 'Long' },
|
|
],
|
|
);
|
|
});
|
|
|
|
it('does not let a later local declaration hide the field at an earlier call', () => {
|
|
const facts = capture(
|
|
'class A { Long value; void run() { use(value); String value = "x"; use(value); } }',
|
|
);
|
|
assert.partialDeepStrictEqual(
|
|
facts.calls.map((call) => call.arguments[0]),
|
|
[
|
|
{ kind: 'typed', spelling: 'Long' },
|
|
{ kind: 'typed', spelling: 'String' },
|
|
],
|
|
);
|
|
});
|
|
|
|
it('uses an explicit this field declaration despite a local with the same name', () => {
|
|
const facts = capture(
|
|
'class A { Long value; void run(String value) { use(value); use(this.value); } }',
|
|
);
|
|
assert.partialDeepStrictEqual(
|
|
facts.calls.map((call) => call.arguments[0]),
|
|
[
|
|
{ kind: 'typed', spelling: 'String' },
|
|
{ kind: 'typed', spelling: 'Long' },
|
|
],
|
|
);
|
|
});
|
|
|
|
it('looks up inherited fields before enclosing fields and retains declaration context', () => {
|
|
const facts = capture(`class Base { String value; }
|
|
class Outer { Long value; class Inner<String> extends Base {
|
|
void run(Long value) { use(this.value); use(value); }
|
|
void implicit() { use(value); }
|
|
} }`);
|
|
const arguments_ = facts.calls
|
|
.filter((call) => call.name === 'use')
|
|
.map((call) => call.arguments[0]);
|
|
assert.partialDeepStrictEqual(arguments_, [
|
|
{ kind: 'typed', spelling: 'String', at: { startLine: 1 } },
|
|
{ kind: 'typed', spelling: 'Long', at: { startLine: 3 } },
|
|
{ kind: 'typed', spelling: 'String', at: { startLine: 1 } },
|
|
]);
|
|
});
|
|
|
|
it('keeps enhanced-for bindings out of the iterable expression', () => {
|
|
const facts = capture(
|
|
'class A { Long item; void run() { for (String item : source(item)) use(item); } }',
|
|
);
|
|
assert.partialDeepStrictEqual(
|
|
facts.calls.map((call) => call.arguments[0]),
|
|
[
|
|
{ kind: 'typed', spelling: 'Long' },
|
|
{ kind: 'typed', spelling: 'String' },
|
|
],
|
|
);
|
|
});
|
|
|
|
for (const example of [
|
|
['unknown superclass', '', 'extends External'],
|
|
['generic field substitution', 'class Base<T> { T value; }', 'extends Base<String>'],
|
|
[
|
|
'ambiguous interface fields',
|
|
'interface Left { String value = "x"; } interface Right { Long value = 1L; }',
|
|
'implements Left, Right',
|
|
],
|
|
] as const) {
|
|
it(`does not infer an outer field across ${example[0]}`, () => {
|
|
const [_description, declarations, heritage] = example;
|
|
|
|
const facts = capture(`${declarations} class Outer { Long value; class Inner ${heritage} {
|
|
void run() { use(value); use(this.value); }
|
|
} }`);
|
|
assert.deepEqual(
|
|
facts.calls.filter((call) => call.name === 'use').map((call) => call.arguments[0]),
|
|
[{ kind: 'unknown' }, { kind: 'unknown' }],
|
|
);
|
|
});
|
|
}
|
|
|
|
it('does not inherit private fields or use an outer field for explicit this', () => {
|
|
const facts = capture(
|
|
'class Base { private String value; } class Outer { Long value; class Inner extends Base { void run() { use(value); use(this.value); } } }',
|
|
);
|
|
assert.partialDeepStrictEqual(
|
|
facts.calls.map((call) => call.arguments[0]),
|
|
[{ kind: 'typed', spelling: 'Long' }, { kind: 'unknown' }],
|
|
);
|
|
});
|
|
|
|
it('resolves an enclosing field through a deep empty inheritance diamond', () => {
|
|
const declarations = ['interface A0 {}', 'interface B0 {}'];
|
|
// Without memoization this small hierarchy expands into millions of paths.
|
|
for (let depth = 1; depth <= 24; depth++) {
|
|
declarations.push(
|
|
`interface A${depth} extends A${depth - 1}, B${depth - 1} {}`,
|
|
`interface B${depth} extends A${depth - 1}, B${depth - 1} {}`,
|
|
);
|
|
}
|
|
const facts = capture(`${declarations.join('\n')}
|
|
class Outer { Long value; class Inner implements A24, B24 {
|
|
void run() { use(value); use(value); }
|
|
} }`);
|
|
assert.partialDeepStrictEqual(
|
|
facts.calls.map((call) => call.arguments[0]),
|
|
[
|
|
{ kind: 'typed', spelling: 'Long' },
|
|
{ kind: 'typed', spelling: 'Long' },
|
|
],
|
|
);
|
|
});
|
|
|
|
it('does not reuse a shallow field proof beyond the inheritance depth bound', () => {
|
|
const declarations = ['interface A0 {}'];
|
|
for (let depth = 1; depth <= 63; depth++)
|
|
declarations.push(`interface A${depth} extends A${depth - 1} {}`);
|
|
const facts = capture(`${declarations.join('\n')}
|
|
class Outer { Long value; class Inner implements A0, A63 {
|
|
void run() { use(value); use(value); }
|
|
} }`);
|
|
assert.deepEqual(
|
|
facts.calls.map((call) => call.arguments[0]),
|
|
[{ kind: 'unknown' }, { kind: 'unknown' }],
|
|
);
|
|
});
|
|
|
|
it('keeps cyclic field inheritance unknown across repeated lookups', () => {
|
|
const facts = capture(`interface Left extends Right {} interface Right extends Left {}
|
|
class Outer { Long value; class Inner implements Left, Right {
|
|
void run() { use(value); use(value); }
|
|
} }`);
|
|
assert.deepEqual(
|
|
facts.calls.map((call) => call.arguments[0]),
|
|
[{ kind: 'unknown' }, { kind: 'unknown' }],
|
|
);
|
|
});
|
|
|
|
it('retains numeric suffixes, declared containers, dimensions, casts, and null separately', () => {
|
|
const facts = capture(
|
|
'class A { void run(java.util.List<Long> ids, int[][] grid) { use(1L, 1f, ids, grid, (String)null, null); } }',
|
|
);
|
|
assert.partialDeepStrictEqual(facts.calls[0]!.arguments, [
|
|
{ kind: 'typed', spelling: 'long' },
|
|
{ kind: 'typed', spelling: 'float' },
|
|
{ kind: 'typed', spelling: 'java.util.List<Long>' },
|
|
{ kind: 'typed', spelling: 'int[][]' },
|
|
{ kind: 'typed', spelling: 'String' },
|
|
{ kind: 'null' },
|
|
]);
|
|
});
|
|
|
|
it('retains qualified generic formal types and array dimensions in candidate declarations', () => {
|
|
const facts = capture(
|
|
'class A { void use(java.util.Collection<Long> ids, String[] names, int value[], Long... rest) {} }',
|
|
);
|
|
assert.deepEqual(facts.methods[0]!.parameterTypes, [
|
|
'java.util.Collection<Long>',
|
|
'String[]',
|
|
'int[]',
|
|
'Long',
|
|
'varargs',
|
|
]);
|
|
});
|
|
|
|
it('preserves trailing dimensions on method and explicitly typed lambda formals', () => {
|
|
const facts = capture(
|
|
'class A { void run(String value[]) { use(value); java.util.function.Consumer<String[]> lambda = (String item[]) -> use(item); } }',
|
|
);
|
|
assert.partialDeepStrictEqual(
|
|
facts.calls.filter((call) => call.name === 'use').map((call) => call.arguments[0]),
|
|
[
|
|
{ kind: 'typed', spelling: 'String[]' },
|
|
{ kind: 'typed', spelling: 'String[]' },
|
|
],
|
|
);
|
|
});
|
|
|
|
it('retains poly factories and explicit type arguments rather than freezing List<Long>', () => {
|
|
const facts = capture(
|
|
'import java.util.Arrays; class A { void run(Long id) { use(Arrays.<Number>asList(id, 1L)); } }',
|
|
);
|
|
assert.partialDeepStrictEqual(facts.calls.find((call) => call.name === 'use')!.arguments[0], {
|
|
kind: 'factory',
|
|
owner: 'Arrays',
|
|
name: 'asList',
|
|
typeArguments: ['Number'],
|
|
shadowed: false,
|
|
arguments: [
|
|
{ kind: 'typed', spelling: 'Long' },
|
|
{ kind: 'typed', spelling: 'long' },
|
|
],
|
|
});
|
|
});
|
|
|
|
it('records value shadowing of a factory qualifier and type-parameter declarations', () => {
|
|
const facts = capture(
|
|
'class A<Long> { <String> void run(Object Arrays) { use(Arrays.asList(1L)); } }',
|
|
);
|
|
assert.deepEqual(facts.types[0]!.typeParameters, ['Long']);
|
|
assert.deepEqual(facts.methods[0]!.typeParameters, ['String']);
|
|
assert.partialDeepStrictEqual(facts.calls.find((call) => call.name === 'use')!.arguments[0], {
|
|
kind: 'factory',
|
|
shadowed: true,
|
|
});
|
|
});
|
|
|
|
it('keeps same-start chained call sites distinct through a plain-data round trip', () => {
|
|
const facts = capture('class A { void run(Long id) { lookup.find(id).get(id); } }');
|
|
const wire = JSON.stringify(facts);
|
|
const restored: unknown = JSON.parse(wire);
|
|
assert.equal(isJavaOverloadFileFacts(restored), true);
|
|
setJavaOverloadFacts('A.java', restored as typeof facts);
|
|
for (const call of facts.calls)
|
|
assert.deepEqual(getJavaOverloadCall('A.java', call.range, call.name), call);
|
|
setJavaOverloadFacts('A.java', undefined);
|
|
assert.equal(getJavaOverloadFacts('A.java'), undefined);
|
|
assert.equal(
|
|
getJavaOverloadCall('A.java', facts.calls[0]!.range, facts.calls[0]!.name),
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
it('assigns enum constant methods to their synthetic owners and retains the host base', () => {
|
|
const facts = capture(`class Host { enum Mode {
|
|
FIRST { void hook() { helper(); } }, SECOND { void hook() {} }, PLAIN;
|
|
void helper() {}
|
|
} }`);
|
|
assert.deepEqual(
|
|
facts.types.map(({ name, simpleName, bases }) => ({ name, simpleName, bases })),
|
|
[
|
|
{ name: 'Host', simpleName: 'Host', bases: [] },
|
|
{ name: 'Mode', simpleName: 'Mode', bases: [] },
|
|
{ name: 'Host$Mode$1', simpleName: 'Host$Mode$1', bases: ['Mode'] },
|
|
{ name: 'Host$Mode$2', simpleName: 'Host$Mode$2', bases: ['Mode'] },
|
|
],
|
|
);
|
|
assert.deepEqual(
|
|
facts.methods.map(({ owner, name }) => `${owner}.${name}`),
|
|
['Host$Mode$1.hook', 'Host$Mode$2.hook', 'Mode.helper'],
|
|
);
|
|
});
|
|
|
|
it('captures implicit record accessors without duplicating explicit zero-argument accessors', () => {
|
|
const facts = capture(`class Host { void run() {
|
|
record Data(String name, int count, String... tags) {
|
|
public String name() { return name; }
|
|
int count(int factor) { return count * factor; }
|
|
}
|
|
} }`);
|
|
const accessors = facts.methods.filter((method) => method.owner === 'Host$1Data');
|
|
assert.deepEqual(
|
|
accessors.map(({ name, parameterTypes, modifiers }) => ({
|
|
name,
|
|
parameterTypes,
|
|
modifiers,
|
|
})),
|
|
[
|
|
{ name: 'count', parameterTypes: [], modifiers: ['public'] },
|
|
{ name: 'tags', parameterTypes: [], modifiers: ['public'] },
|
|
{ name: 'name', parameterTypes: [], modifiers: ['public'] },
|
|
{ name: 'count', parameterTypes: ['int'], modifiers: [] },
|
|
],
|
|
);
|
|
const wire = JSON.stringify(facts);
|
|
assert.equal(isJavaOverloadFileFacts(JSON.parse(wire)), true);
|
|
});
|
|
|
|
it('does not synthesize accessor facts for malformed record component names', () => {
|
|
const facts = capture('record Missing(int x, y) {} record Unnamed(int _) {}');
|
|
assert.deepEqual(
|
|
facts.methods.map(({ owner, name }) => `${owner}.${name}`),
|
|
['Missing.x'],
|
|
);
|
|
});
|
|
|
|
it('retains type visibility and gives only direct interface members implicit public access', () => {
|
|
const facts = capture(`public class Outer {
|
|
private static class Hidden {}
|
|
protected class Protected {}
|
|
class PackageMember {}
|
|
}
|
|
interface API {
|
|
class Member {}
|
|
enum Mode { VALUE }
|
|
default void run() { class Local {} }
|
|
}
|
|
@interface Annotation { class Member {} }`);
|
|
assert.deepEqual(
|
|
facts.types.map(({ name, modifiers }) => ({ name, modifiers })),
|
|
[
|
|
{ name: 'Outer', modifiers: ['public'] },
|
|
{ name: 'Hidden', modifiers: ['private', 'static'] },
|
|
{ name: 'Protected', modifiers: ['protected'] },
|
|
{ name: 'PackageMember', modifiers: [] },
|
|
{ name: 'API', modifiers: [] },
|
|
{ name: 'Member', modifiers: ['public'] },
|
|
{ name: 'Mode', modifiers: ['public'] },
|
|
{ name: 'API$1Local', modifiers: [] },
|
|
{ name: 'Annotation', modifiers: [] },
|
|
{ name: 'Member', modifiers: ['public'] },
|
|
],
|
|
);
|
|
});
|
|
|
|
it('validates optional persisted type modifiers without rejecting older facts', () => {
|
|
const facts = capture('public class A {}');
|
|
const { modifiers: _modifiers, ...olderType } = facts.types[0]!;
|
|
assert.equal(isJavaOverloadFileFacts({ ...facts, types: [olderType] }), true);
|
|
const wire = JSON.stringify(facts);
|
|
assert.equal(isJavaOverloadFileFacts(JSON.parse(wire)), true);
|
|
assert.equal(
|
|
isJavaOverloadFileFacts({ ...facts, types: [{ ...olderType, modifiers: null }] }),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
isJavaOverloadFileFacts({ ...facts, types: [{ ...olderType, modifiers: [1] }] }),
|
|
false,
|
|
);
|
|
});
|
|
|
|
it('rejects malformed persisted facts and retains empty types for inherited inventories', () => {
|
|
assert.partialDeepStrictEqual(capture('class Empty {}').types, [{ name: 'Empty', bases: [] }]);
|
|
const facts = capture('class A { void run() { use(null); } }');
|
|
assert.equal(
|
|
isJavaOverloadFileFacts({
|
|
...facts,
|
|
calls: [{ ...facts.calls[0], arguments: [{ kind: 'typed', spelling: 1 }] }],
|
|
}),
|
|
false,
|
|
);
|
|
assert.equal(isJavaOverloadFileFacts({ ...facts, methods: [null] }), false);
|
|
});
|
|
});
|