Files
pi-map/tests/llm-batch.test.ts
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

57 lines
1.5 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { withRetry, processFiles } from "../src/llm/llm-batch.js";
import { LLMError } from "../src/llm-error.js";
describe("withRetry", () => {
it("returns result on first success", async () => {
const result = await withRetry(async () => "success");
expect(result).toBe("success");
});
it("retries on failure and eventually succeeds", async () => {
let attempts = 0;
const result = await withRetry(async () => {
attempts++;
if (attempts < 3) throw new Error("transient");
return "success";
});
expect(result).toBe("success");
expect(attempts).toBe(3);
});
it("throws after max retries", async () => {
let attempts = 0;
await expect(
withRetry(async () => {
attempts++;
throw new Error("persistent");
}, { maxRetries: 2, retryDelaysMs: [10, 20] }),
).rejects.toThrow("persistent");
expect(attempts).toBe(3); // initial + 2 retries
});
});
describe("processFiles", () => {
it("processes all files in parallel", async () => {
const files = [1, 2, 3, 4, 5];
const results = await processFiles(files, async (n) => n * 2, {
concurrency: 2,
});
expect(results).toEqual([2, 4, 6, 8, 10]);
});
it("retries failed files", async () => {
let attempts = 0;
const results = await processFiles(
[1],
async () => {
attempts++;
if (attempts < 2) throw new Error("fail");
return "ok";
},
{ maxRetries: 2, retryDelaysMs: [10, 20] },
);
expect(results).toEqual(["ok"]);
});
});