Something went wrong. Try again.
An agent harness for spec-driven development.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import fs from "node:fs/promises";import os from "node:os";import path from "node:path";import { describe, expect, test } from "vitest";import { JazzCharterDatabase } from "../src/db/jazz.js";import type { ProjectEventRow, SpecDocumentRow, WorkItemRow } from "../src/types.js";
const baseRow: 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",};
const baseEvent: ProjectEventRow = { id: "event-1", type: "spec.document.upserted", documentId: "overview", path: "README.md", sha256: "abc", occurredAt: "2026-01-01T00:00:00.000Z", authority: "importer.sync",};
const baseWorkItem: WorkItemRow = { id: "work-1", kind: "spec-change", status: "queued", eventId: "event-1", documentId: "overview", path: "README.md", title: "Overview", createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z", authority: "importer.sync", attachedDocumentIds: ["overview"], matchedConsumerIds: [],};
describe("JazzCharterDatabase", () => { test("persists native Jazz rows across process-style shutdown and restart", async () => { const root = await fs.mkdtemp(path.join(os.tmpdir(), "charter-jazz-db-")); const options = { projectRoot: root, projectId: "test" }; const first = new JazzCharterDatabase(options);
await first.upsertDocument(baseRow); await first.appendEvent(baseEvent); await first.appendEvent(baseEvent); await first.upsertWorkItem(baseWorkItem);
const movedRow = { ...baseRow, path: "guide.md", sha256: "def", body: "# Guide" }; await first.upsertDocument(movedRow); await first.updateWorkItemStatus("work-1", "running", { claimedBy: "charter.agent", claimedAt: "2026-01-01T00:00:01.000Z", }); await first.saveSnapshot();
const firstManifest = await first.jazzManifest(); expect(firstManifest.adapter).toBe("jazz-2"); expect(firstManifest.projectRowId).not.toBe(""); expect(firstManifest.documentRowIds.overview).not.toBe(""); expect(firstManifest.versionRowIds["overview:abc"]).not.toBe(""); expect(firstManifest.versionRowIds["overview:def"]).not.toBe(""); await first.close();
const second = new JazzCharterDatabase(options); const snapshot = await second.loadSnapshot(); const secondManifest = await second.jazzManifest();
expect(snapshot.documents.overview?.path).toBe("guide.md"); expect(snapshot.pathIndex["README.md"]).toBeUndefined(); expect(snapshot.pathIndex["guide.md"]).toBe("overview"); expect(snapshot.events).toHaveLength(1); expect(snapshot.workItems["work-1"]?.status).toBe("running"); expect(snapshot.workItems["work-1"]?.claimedBy).toBe("charter.agent"); expect(secondManifest.projectRowId).toBe(firstManifest.projectRowId); expect(secondManifest.documentRowIds.overview).toBe(firstManifest.documentRowIds.overview); await expect(fs.access(path.join(root, ".spec", "state", "spec-db.json"))).rejects.toThrow();
const manifestFile = JSON.parse(await fs.readFile(path.join(root, ".spec", "state", "jazz-runtime.json"), "utf8")); expect(manifestFile.projectRowId).toBe(firstManifest.projectRowId); await second.close(); });});