gitgram/aitimemachine/gitnexus/test/unit/cross-file-routes.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

53 lines
2.0 KiB
TypeScript

import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import type { ExtractedRoute } from '../../src/core/ingestion/workers/parse-worker.js';
// Hoisted so the (also-hoisted) vi.mock factory below can reference it.
const { extractRoutesSpy } = vi.hoisted(() => ({
extractRoutesSpy: vi.fn((): ExtractedRoute[] => {
throw new Error('boom from a misbehaving provider');
}),
}));
// Override only the route hooks on the real Python provider so the main-thread
// pass reaches extractRoutes and the throw exercises the in-loop guard. Every
// other dependency (parser, parse, fs reader) stays real.
vi.mock('../../src/core/ingestion/languages/index.js', async (importOriginal) => {
const actual =
await importOriginal<typeof import('../../src/core/ingestion/languages/index.js')>();
return {
...actual,
getProvider: (lang: Parameters<typeof actual.getProvider>[0]) => ({
...actual.getProvider(lang),
discoverRootRouteFiles: () => ['proj/urls.py'],
extractRoutes: extractRoutesSpy,
}),
};
});
import { extractCrossFileRoutes } from '../../src/core/ingestion/pipeline-phases/parse-impl.js';
let repoDir: string;
beforeAll(() => {
repoDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gitnexus-xfr-'));
fs.mkdirSync(path.join(repoDir, 'proj'), { recursive: true });
fs.writeFileSync(path.join(repoDir, 'proj/urls.py'), 'urlpatterns = []\n');
});
afterAll(() => {
fs.rmSync(repoDir, { recursive: true, force: true });
});
describe('extractCrossFileRoutes', () => {
it('isolates a throwing provider.extractRoutes instead of aborting the run', async () => {
const routes = await extractCrossFileRoutes(['proj/urls.py'], repoDir);
// The guard caught the throw (provider was actually reached) and the run
// produced no routes rather than propagating the error.
expect(extractRoutesSpy).toHaveBeenCalledTimes(1);
expect(routes).toEqual([]);
});
});