2f198ea0d2
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)
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
import { getCached, setCached } from "../src/llm/llm-cache.js";
|
|
import { existsSync, unlinkSync } from "fs";
|
|
import { join } from "path";
|
|
import { tmpdir } from "os";
|
|
|
|
const TEST_CACHE_DIR = join(tmpdir(), "pi-project-map-test-cache");
|
|
const TEST_CACHE_FILE = join(TEST_CACHE_DIR, "llm-cache.json");
|
|
|
|
describe("llm-cache", () => {
|
|
beforeEach(() => {
|
|
if (existsSync(TEST_CACHE_FILE)) {
|
|
unlinkSync(TEST_CACHE_FILE);
|
|
}
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (existsSync(TEST_CACHE_FILE)) {
|
|
unlinkSync(TEST_CACHE_FILE);
|
|
}
|
|
});
|
|
|
|
it("returns undefined for missing entries", () => {
|
|
const result = getCached("nonexistent-hash", TEST_CACHE_DIR);
|
|
expect(result).toBeUndefined();
|
|
});
|
|
|
|
it("stores and retrieves cached results", () => {
|
|
setCached(
|
|
"abc123",
|
|
"PURPOSE: test\nDEPS: none\nCONCEPTS: none",
|
|
TEST_CACHE_DIR,
|
|
);
|
|
const result = getCached("abc123", TEST_CACHE_DIR);
|
|
expect(result).toBe("PURPOSE: test\nDEPS: none\nCONCEPTS: none");
|
|
});
|
|
|
|
it("overwrites existing entries", () => {
|
|
setCached("abc123", "old", TEST_CACHE_DIR);
|
|
setCached("abc123", "new", TEST_CACHE_DIR);
|
|
const result = getCached("abc123", TEST_CACHE_DIR);
|
|
expect(result).toBe("new");
|
|
});
|
|
});
|