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>
313 lines
12 KiB
TypeScript
313 lines
12 KiB
TypeScript
/**
|
||
* Parity test for the two Spring route extractors (#2078 maintainer request,
|
||
* #2138 follow-up).
|
||
*
|
||
* GitNexus parses Spring `@(Get|Post|...)Mapping` annotations in TWO places:
|
||
* - ingestion `route-extractors/spring.ts` → `extractSpringRoutes` (produces
|
||
* graph `Route` nodes)
|
||
* - group `http-patterns/java.ts` → `JAVA_HTTP_PLUGIN.scan` (produces
|
||
* cross-repo HTTP contracts)
|
||
*
|
||
* They serve different layers and stay separate, but they MUST agree on the
|
||
* set of provider (method, path) routes they recognise for the same source —
|
||
* otherwise the graph under-covers what the group scan sees, which is exactly
|
||
* the divergence behind the #2265 array-form gap (the group query matched
|
||
* `@GetMapping({"/a","/b"})`, ingestion's didn't). This test runs one shared
|
||
* fixture through both and asserts the provider sets are identical for the
|
||
* shapes ingestion claims to cover: bare, named-arg, and array-form method
|
||
* routes under a *scalar* (or absent) class prefix.
|
||
*
|
||
* Known, deliberate divergence (NOT covered by the equality assertions): a
|
||
* method-level array route nested under a class-level *array-form*
|
||
* @RequestMapping. Ingestion suppresses it (it can't resolve which of several
|
||
* class prefixes to apply, and a dropped-prefix route is a wrong signal), while
|
||
* the group layer emits the full cross-product. The last test pins this so the
|
||
* suppression can't silently regress into emitting wrong routes; full
|
||
* class-array support is tracked in #2280.
|
||
*/
|
||
import assert from 'node:assert/strict';
|
||
import { describe, it } from 'node:test';
|
||
import Parser from 'tree-sitter';
|
||
import Java from 'tree-sitter-java';
|
||
import { extractSpringRoutes } from '../../../../../src/core/ingestion/route-extractors/spring.js';
|
||
import { JAVA_HTTP_PLUGIN } from '../../../../../src/core/group/extractors/http-patterns/java.js';
|
||
|
||
function parse(src: string): Parser.Tree {
|
||
const p = new Parser();
|
||
p.setLanguage(Java);
|
||
return p.parse(src);
|
||
}
|
||
|
||
/** Canonical `METHOD /a/b` form so prefix-join / slash / case differences wash out. */
|
||
function canon(method: string, ...segments: string[]): string {
|
||
const path = `/${segments.join('/').split('/').filter(Boolean).join('/')}`;
|
||
return `${method.toUpperCase()} ${path.toLowerCase()}`;
|
||
}
|
||
|
||
/** ingestion side: join the class prefix + method path the way the routes phase does. */
|
||
function ingestionProviders(src: string): Set<string> {
|
||
return new Set(
|
||
extractSpringRoutes(parse(src), 'X.java').map((r) =>
|
||
canon(r.httpMethod, r.prefix ?? '', r.routePath),
|
||
),
|
||
);
|
||
}
|
||
|
||
/** group side: provider detections (path already prefix-joined by the plugin). */
|
||
function groupProviders(src: string): Set<string> {
|
||
return new Set(
|
||
JAVA_HTTP_PLUGIN.scan(parse(src))
|
||
.filter((d) => d.role === 'provider')
|
||
.map((d) => canon(d.method, d.path)),
|
||
);
|
||
}
|
||
|
||
function groupConsumers(src: string): Set<string> {
|
||
return new Set(
|
||
JAVA_HTTP_PLUGIN.scan(parse(src))
|
||
.filter((d) => d.role === 'consumer' && d.framework === 'openfeign')
|
||
.map((d) => canon(d.method, d.path)),
|
||
);
|
||
}
|
||
|
||
describe('Spring route extractor parity — ingestion spring.ts vs group java.ts', () => {
|
||
it('agree on bare, named-arg, and array-form method routes under a class prefix', () => {
|
||
const src = `package com.example;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
@RestController
|
||
@RequestMapping("/api/orders")
|
||
public class OrderController {
|
||
@GetMapping("/list") public Object list() { return null; }
|
||
@PostMapping(path = "/make") public Object make() { return null; }
|
||
@PutMapping(value = "/update") public Object update() { return null; }
|
||
@GetMapping({"/a", "/b"}) public Object multi() { return null; }
|
||
}
|
||
`;
|
||
const ingestion = ingestionProviders(src);
|
||
const group = groupProviders(src);
|
||
|
||
// The array form is the regression that motivated this: both must see all four.
|
||
assert.deepEqual(
|
||
group,
|
||
new Set([
|
||
'GET /api/orders/list',
|
||
'POST /api/orders/make',
|
||
'PUT /api/orders/update',
|
||
'GET /api/orders/a',
|
||
'GET /api/orders/b',
|
||
]),
|
||
);
|
||
assert.deepEqual(ingestion, group);
|
||
});
|
||
|
||
it('agree on a no-prefix controller with a positional array', () => {
|
||
const src = `package com.example;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
@RestController
|
||
public class PlainController {
|
||
@GetMapping("/solo") public Object solo() { return null; }
|
||
@DeleteMapping({"/x", "/y", "/z"}) public Object many() { return null; }
|
||
}
|
||
`;
|
||
assert.deepEqual(ingestionProviders(src), groupProviders(src));
|
||
});
|
||
|
||
it('agree on named-arg ARRAY forms (path = {...} / value = {...})', () => {
|
||
// Guards the spring.ts named-array query branch specifically: positional
|
||
// arrays alone would not exercise it.
|
||
const src = `package com.example;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
@RestController
|
||
@RequestMapping("/api")
|
||
public class NamedArrayController {
|
||
@PutMapping(value = {"/update", "/modify"}) public Object upd() { return null; }
|
||
@DeleteMapping(path = {"/x", "/y"}) public Object del() { return null; }
|
||
}
|
||
`;
|
||
const group = groupProviders(src);
|
||
assert.deepEqual(
|
||
group,
|
||
new Set(['PUT /api/update', 'PUT /api/modify', 'DELETE /api/x', 'DELETE /api/y']),
|
||
);
|
||
assert.deepEqual(ingestionProviders(src), group);
|
||
});
|
||
|
||
it('agree on method-level @RequestMapping verbs and wildcard mappings', () => {
|
||
const src = `package com.example;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
@RestController
|
||
@RequestMapping("/api")
|
||
public class LegacyController {
|
||
@RequestMapping("/bare") public Object bare() { return null; }
|
||
@RequestMapping(value = "/named") public Object named() { return null; }
|
||
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
||
public Object save() { return null; }
|
||
@RequestMapping(path = "/multi", method = {RequestMethod.GET, RequestMethod.HEAD})
|
||
public Object multi() { return null; }
|
||
@RequestMapping(path = {"/one", "/two"}, method = {RequestMethod.GET, RequestMethod.POST})
|
||
public Object crossProduct() { return null; }
|
||
@RequestMapping(path = "/empty", method = {})
|
||
public Object empty() { return null; }
|
||
@RequestMapping(path = "/spaced", method = RequestMethod . PUT)
|
||
public Object spaced() { return null; }
|
||
@RequestMapping(path = "/commented", method = {
|
||
RequestMethod.GET, // read
|
||
/* write */ RequestMethod.POST,
|
||
})
|
||
public Object commented() { return null; }
|
||
@org.springframework.web.bind.annotation.RequestMapping(
|
||
path = "/fqn",
|
||
method = org.springframework.web.bind.annotation.RequestMethod.DELETE
|
||
)
|
||
public Object fqn() { return null; }
|
||
}
|
||
`;
|
||
const expected = new Set([
|
||
'* /api/bare',
|
||
'* /api/named',
|
||
'POST /api/save',
|
||
'GET /api/multi',
|
||
'HEAD /api/multi',
|
||
'GET /api/one',
|
||
'POST /api/one',
|
||
'GET /api/two',
|
||
'POST /api/two',
|
||
'* /api/empty',
|
||
'PUT /api/spaced',
|
||
'GET /api/commented',
|
||
'POST /api/commented',
|
||
'DELETE /api/fqn',
|
||
]);
|
||
|
||
assert.deepEqual(groupProviders(src), expected);
|
||
assert.deepEqual(ingestionProviders(src), expected);
|
||
});
|
||
|
||
it('intersects class verbs and emits pathless method mappings at the class prefix', () => {
|
||
const src = `package com.example;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
@RestController
|
||
@RequestMapping(path = "/api", method = RequestMethod.GET)
|
||
public class ConstrainedController {
|
||
@RequestMapping("/wild") public Object wildcard() { return null; }
|
||
@RequestMapping(method = RequestMethod.GET) public Object root() { return null; }
|
||
@GetMapping public Object shortcut() { return null; }
|
||
@PostMapping("/blocked") public Object blocked() { return null; }
|
||
}
|
||
`;
|
||
|
||
const expected = new Set(['GET /api/wild', 'GET /api']);
|
||
assert.deepEqual(groupProviders(src), expected);
|
||
assert.deepEqual(ingestionProviders(src), expected);
|
||
});
|
||
|
||
it('uses GET for verb-less Feign RequestMapping and rejects multi-method contracts', () => {
|
||
const src = `package com.example;
|
||
import org.springframework.cloud.openfeign.FeignClient;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
@FeignClient(name = "orders")
|
||
@RequestMapping("/api")
|
||
public interface OrdersClient {
|
||
@RequestMapping("/default") Object defaultCall();
|
||
@RequestMapping(path = "/multi", method = {RequestMethod.GET, RequestMethod.POST})
|
||
Object ambiguous();
|
||
}
|
||
`;
|
||
|
||
assert.deepEqual(groupConsumers(src), new Set(['GET /api/default']));
|
||
});
|
||
it('fails closed when @RequestMapping method is not statically resolvable', () => {
|
||
const src = `package com.example;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
@RestController
|
||
public class DynamicController {
|
||
private static final RequestMethod VERB = RequestMethod.POST;
|
||
@RequestMapping(path = "/dynamic", method = VERB)
|
||
public Object dynamic() { return null; }
|
||
}
|
||
`;
|
||
|
||
assert.deepEqual(groupProviders(src), new Set());
|
||
assert.deepEqual(ingestionProviders(src), new Set());
|
||
});
|
||
|
||
it('do not leak non-route arrays (consumes/produces) as routes — array analogue', () => {
|
||
// The scalar `produces` anti-regression already exists in the route tests;
|
||
// this is its array form. `consumes`/`produces` arrays must never surface as
|
||
// provider routes; only the path value does.
|
||
const src = `package com.example;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
@RestController
|
||
public class ContentTypeController {
|
||
@GetMapping(value = "/v", consumes = {"application/json", "application/xml"}, produces = {"application/json"})
|
||
public Object v() { return null; }
|
||
@PostMapping(consumes = {"application/json"})
|
||
public Object noPath() { return null; }
|
||
}
|
||
`;
|
||
const ingestion = ingestionProviders(src);
|
||
const group = groupProviders(src);
|
||
// Non-route arrays never become paths; the pathless POST binds to root.
|
||
assert.deepEqual(group, new Set(['GET /v', 'POST /']));
|
||
assert.deepEqual(ingestion, group);
|
||
|
||
// Pure consumes/produces members still describe pathless root mappings;
|
||
// their media-type values must never be misread as route paths.
|
||
const consumesOnly = `package com.example;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
@RestController
|
||
public class ConsumesOnlyController {
|
||
@PostMapping(consumes = {"application/json", "application/xml"})
|
||
public Object a() { return null; }
|
||
@PutMapping(produces = {"application/json"})
|
||
public Object b() { return null; }
|
||
}
|
||
`;
|
||
assert.deepEqual(groupProviders(consumesOnly), new Set(['POST /', 'PUT /']));
|
||
assert.deepEqual(ingestionProviders(consumesOnly), new Set(['POST /', 'PUT /']));
|
||
});
|
||
|
||
it('pins the deliberate class-array divergence: ingestion suppresses, group emits cross-product (#2280)', () => {
|
||
// A method-level array under a class-level ARRAY-form @RequestMapping. There
|
||
// is no single class prefix to apply, so ingestion suppresses the route
|
||
// rather than emit it unprefixed (a wrong signal). The group layer emits the
|
||
// full cross-product. This is a KNOWN gap (#2280), pinned here so the
|
||
// suppression can't silently regress into emitting wrong unprefixed routes.
|
||
const src = `package com.example;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
@RestController
|
||
@RequestMapping({"/base/one", "/base/two"})
|
||
public class MultiPrefixController {
|
||
@GetMapping({"/primary", "/alias"}) public Object x() { return null; }
|
||
}
|
||
`;
|
||
const ingestion = ingestionProviders(src);
|
||
const group = groupProviders(src);
|
||
|
||
// group: correct cross-product of the two class prefixes × two method paths.
|
||
assert.deepEqual(
|
||
group,
|
||
new Set([
|
||
'GET /base/one/primary',
|
||
'GET /base/two/primary',
|
||
'GET /base/one/alias',
|
||
'GET /base/two/alias',
|
||
]),
|
||
);
|
||
// ingestion: suppressed — emits NO route for the array method (never a wrong
|
||
// unprefixed `GET /primary` / `GET /alias`).
|
||
assert.deepEqual(ingestion, new Set());
|
||
// And the divergence is asymmetric-by-design: ingestion ⊊ group here.
|
||
assert.notDeepEqual(ingestion, group);
|
||
});
|
||
});
|