Files
pi-map/tests/llm-cache.test.ts
T
alex 69d3acda5d feat: M7 proper LLM integration with dual providers, caching, and parallel batching
- Add LLM client abstraction (src/llm-client.ts) with factory pattern
- Add OpenAI-compatible external client (src/external-llm-client.ts)
- Add Kimi.com client using Anthropic-based API (src/kimi-llm-client.ts)
- Add Pi native LLM stub (src/pi-llm-client.ts) for future ExtensionAPI wiring
- Add SHA-256 disk cache at ~/.cache/pi-project-map/ (src/llm-cache.ts)
- Add parallel batching with p-limit, retry + exponential backoff (src/llm-batch.ts)
- Rewrite llm-extract.ts to use real LLM calls with structured prompts
  - File-level: PURPOSE, DEPS, CONCEPTS
  - Package-level: ROLE, ARCH
  - Context truncation, 50KB skip, cache before LLM call
- Wire CLI with --llm-provider, --llm-model, --llm-base-url flags
- Update config.ts with llmProvider, llmBaseUrl fields
- Update init.ts and patch.ts to accept optional LLMClient
- Add sample project fixture for manual testing
- Add tests: llm-cache (3), llm-batch (5), llm-integration (8 with real Kimi API),
  pi-extension (14 mocked)
- All 56 tests pass
2026-06-09 22:49:34 +02:00

41 lines
1.1 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { getCached, setCached } from "../src/llm-cache.js";
import { existsSync, unlinkSync, rmdirSync } from "fs";
import { join } from "path";
import { homedir } from "os";
const TEST_CACHE_DIR = join(homedir(), ".cache", "pi-project-map");
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");
expect(result).toBeUndefined();
});
it("stores and retrieves cached results", () => {
setCached("abc123", "PURPOSE: test\nDEPS: none\nCONCEPTS: none");
const result = getCached("abc123");
expect(result).toBe("PURPOSE: test\nDEPS: none\nCONCEPTS: none");
});
it("overwrites existing entries", () => {
setCached("abc123", "old");
setCached("abc123", "new");
const result = getCached("abc123");
expect(result).toBe("new");
});
});