gitgram/aitimemachine/gitnexus/test/unit/spring-route-extractor-parity.test.ts
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

113 lines
3.7 KiB
TypeScript

/**
* Parity test: the two Spring route extractors must agree.
*
* The ingestion-layer extractor (`route-extractors/spring.ts`, producing
* graph `Route` nodes) and the group-layer extractor
* (`group/extractors/http-patterns/java.ts`, producing cross-repo HTTP
* contracts) share their low-level primitives via `route-extractors/
* spring-shared.ts`. They keep separate output shapes and the group layer
* carries extra consumer/inheritance handling the ingestion side doesn't
* need — but for plain Spring `@RestController` providers they MUST surface
* the same set of (HTTP method, full URL) pairs.
*
* This test parses one shared fixture through both extractors and asserts
* the provider method/path combinations match, so the two implementations
* can't drift apart on the semantics they share.
*/
import { describe, it, expect } from 'vitest';
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';
import { normalizeExtractedRoutePath } from '../../src/core/ingestion/pipeline-phases/routes.js';
function parse(code: string): Parser.Tree {
const parser = new Parser();
parser.setLanguage(Java);
return parser.parse(code);
}
/** Shared fixture: a Spring controller exercising every supported verb,
* positional + named args, and a class-level @RequestMapping prefix. */
const SPRING_FIXTURE = `
package com.example.controller;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/users")
public class UserController {
@GetMapping("/list")
public String list() { return "[]"; }
@PostMapping("/create")
public String create() { return "{}"; }
@PutMapping(value = "/update")
public void update() {}
@DeleteMapping(path = "/delete")
public void delete() {}
@PatchMapping("/patch")
public void patch() {}
}
`;
/** Normalize an ingestion route (separate routePath + prefix) to a full URL. */
function ingestionPairs(tree: Parser.Tree): Set<string> {
return new Set(
extractSpringRoutes(tree, 'UserController.java').map(
(r) => `${r.httpMethod} ${normalizeExtractedRoutePath(r.routePath, r.prefix ?? null)}`,
),
);
}
/** Normalize a group provider detection (path already prefix-joined) to a full URL. */
function groupPairs(tree: Parser.Tree): Set<string> {
return new Set(
JAVA_HTTP_PLUGIN.scan(tree)
.filter((d) => d.role === 'provider')
.map((d) => `${d.method} ${normalizeExtractedRoutePath(d.path, null)}`),
);
}
describe('Spring route extractor parity (ingestion vs group)', () => {
it('both extractors surface the same provider method/path combinations', () => {
const tree = parse(SPRING_FIXTURE);
const ingestion = ingestionPairs(tree);
const group = groupPairs(tree);
// Both must agree on the full set — no route only one side sees.
expect([...ingestion].sort()).toEqual([...group].sort());
// Sanity: the expected combinations are actually present (guards against
// both extractors silently agreeing on an empty set).
expect(ingestion).toEqual(
new Set([
'GET /api/users/list',
'POST /api/users/create',
'PUT /api/users/update',
'DELETE /api/users/delete',
'PATCH /api/users/patch',
]),
);
});
it('agree when there is no class-level prefix', () => {
const tree = parse(`
@RestController
public class HealthController {
@GetMapping("/health")
public String health() { return "OK"; }
@PostMapping("/ping")
public String ping() { return "OK"; }
}
`);
expect([...ingestionPairs(tree)].sort()).toEqual([...groupPairs(tree)].sort());
});
});