Files
socraticode/tests/unit/symbol-graph-cache.test.ts
Giancarlo Erra 59f630e1ca test+docs(impact): add symbol pipeline tests and Phase G docs
- 4 new unit test files (22 tests) for graph-symbols, graph-symbol-resolution,
  graph-entrypoints, symbol-graph-cache. All 799 tests pass.
- README/AGENTS/CLAUDE/GEMINI: document codebase_impact, codebase_flow,
  codebase_symbol, codebase_symbols and updated workflow guidance.
- DEVELOPER.md: new architectural section for symbol-level call graph,
  including sharded storage layout and resolution confidence levels.
- CHANGELOG: Unreleased section for the impact-analysis feature.
- Apply CodeRabbit fixes: dedupe in-flight cache loads, set ImpactResult.truncated
  when frontier extends beyond depth limit, drop redundant String() around Lang enum.
- Switch reverse-shard hash from SHA1 to SHA256 (Snyk hardening; non-cryptographic use).
2026-04-21 13:54:01 +01:00

65 lines
1.9 KiB
TypeScript

// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2026 Giancarlo Erra - Altaire Limited
import { describe, expect, it } from "vitest";
import { LRUCache, symbolIdToFile } from "../../src/services/symbol-graph-cache.js";
describe("LRUCache", () => {
it("stores and retrieves values up to capacity", () => {
const lru = new LRUCache<string, number>(3);
lru.set("a", 1);
lru.set("b", 2);
lru.set("c", 3);
expect(lru.get("a")).toBe(1);
expect(lru.size).toBe(3);
});
it("evicts the oldest entry when over capacity", () => {
const lru = new LRUCache<string, number>(2);
lru.set("a", 1);
lru.set("b", 2);
lru.set("c", 3); // evicts "a"
expect(lru.has("a")).toBe(false);
expect(lru.has("b")).toBe(true);
expect(lru.has("c")).toBe(true);
});
it("get() promotes a key to most-recently-used", () => {
const lru = new LRUCache<string, number>(2);
lru.set("a", 1);
lru.set("b", 2);
lru.get("a"); // a is now MRU
lru.set("c", 3); // evicts b
expect(lru.has("a")).toBe(true);
expect(lru.has("b")).toBe(false);
expect(lru.has("c")).toBe(true);
});
it("delete removes an entry", () => {
const lru = new LRUCache<string, number>(2);
lru.set("a", 1);
expect(lru.delete("a")).toBe(true);
expect(lru.has("a")).toBe(false);
expect(lru.delete("missing")).toBe(false);
});
it("clear empties the cache", () => {
const lru = new LRUCache<string, number>(2);
lru.set("a", 1);
lru.set("b", 2);
lru.clear();
expect(lru.size).toBe(0);
});
});
describe("symbolIdToFile", () => {
it("extracts file portion from a symbol id", () => {
expect(symbolIdToFile("src/a.ts::foo#10")).toBe("src/a.ts");
expect(symbolIdToFile("path/with/slashes/file.py::Foo.bar#42")).toBe("path/with/slashes/file.py");
});
it("returns null when separator missing", () => {
expect(symbolIdToFile("malformed")).toBeNull();
});
});