Files
pi-map/tests/ast-extract.test.ts
T
alex 2f198ea0d2 feat: remove heuristics, go LLM-only with mocks + restructure
BREAKING: Heuristic fallback removed — LLM client now required

Changes:
- Remove extractFileHeuristic, extractPackageHeuristic, all helpers
- extractFileLLM / extractPackageLLM now throw LLMError when client missing
- Add hybrid binary detection: extension blacklist + content sniffing
- Increase file size limit: 50KB → 500KB (text files only)
- Restructure src/ into subdirectories:
  - src/llm/ — all LLM clients, extract, batch, cache, error
  - src/ast/ — AST extraction
  - src/cli/ — CLI entry point
- Update all imports across codebase and tests
- Add tests/mock-llm.ts helper for deterministic mock clients
- Update all tests to use mock LLM clients (no heuristics dependency)
- All 52 tests passing (including 8 real LLM integration tests)
2026-06-10 17:34:37 +02:00

43 lines
1.3 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { extractFileAST } from "../src/ast/ast-extract.js";
import { mkdtempSync, writeFileSync } from "fs";
import { join } from "path";
import { tmpdir } from "os";
describe("ast-extract", () => {
it("extracts TypeScript exports and imports", async () => {
const dir = mkdtempSync(join(tmpdir(), "pi-map-ast-"));
const file = join(dir, "test.ts");
writeFileSync(
file,
`import { foo } from "./bar";
import type { Qux } from "qux-lib";
export function hello() {}
export class MyClass {}
export const value = 1;
export interface Config {}
export type MyType = string;
export { foo as renamedFoo };
`,
);
const result = await extractFileAST(file);
expect(result).not.toBeNull();
expect(result!.exports).toContain("hello");
expect(result!.exports).toContain("MyClass");
expect(result!.exports).toContain("value");
expect(result!.exports).toContain("Config");
expect(result!.exports).toContain("MyType");
expect(result!.deps).toContain("./bar");
expect(result!.deps).toContain("qux-lib");
});
it("returns null for unsupported languages", async () => {
const dir = mkdtempSync(join(tmpdir(), "pi-map-ast-"));
const file = join(dir, "test.xyz");
writeFileSync(file, `some content`);
const result = await extractFileAST(file);
expect(result).toBeNull();
});
});