Something went wrong. Try again.
An agent harness for spec-driven development.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import fs from "node:fs/promises";import os from "node:os";import path from "node:path";import { describe, expect, test } from "vitest";import { JsonCharterDatabase } from "../src/db/json.js";import type { SpecDocumentRow } from "../src/types.js";
describe("JsonCharterDatabase", () => { test("upserts documents and maintains the path index", async () => { const root = await fs.mkdtemp(path.join(os.tmpdir(), "charter-db-")); const db = new JsonCharterDatabase({ projectRoot: root, projectId: "test" }); const row: SpecDocumentRow = { id: "overview", path: "README.md", title: "Overview", kind: "architecture", status: "draft", body: "# Overview", frontmatterJson: "{}", headingsJson: "[]", sha256: "abc", sizeBytes: 10, mtimeMs: 1, importedAt: "2026-01-01T00:00:00.000Z", };
await db.upsertDocument(row); await db.saveSnapshot();
const snapshot = await new JsonCharterDatabase({ projectRoot: root }).loadSnapshot(); expect(snapshot.documents.overview?.title).toBe("Overview"); expect(snapshot.pathIndex["README.md"]).toBe("overview"); });
test("deletes documents and removes stale path index entries", async () => { const root = await fs.mkdtemp(path.join(os.tmpdir(), "charter-db-")); const db = new JsonCharterDatabase({ projectRoot: root, projectId: "test" }); const row: SpecDocumentRow = { id: "overview", path: "README.md", title: "Overview", kind: "architecture", status: "draft", body: "# Overview", frontmatterJson: "{}", headingsJson: "[]", sha256: "abc", sizeBytes: 10, mtimeMs: 1, importedAt: "2026-01-01T00:00:00.000Z", };
await db.upsertDocument(row); await db.deleteDocument("overview"); await db.saveSnapshot();
const snapshot = await new JsonCharterDatabase({ projectRoot: root }).loadSnapshot(); expect(snapshot.documents.overview).toBeUndefined(); expect(snapshot.pathIndex["README.md"]).toBeUndefined(); });});