Something went wrong. Try again.
An agent harness for spec-driven development.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041import fs from "node:fs/promises";import os from "node:os";import path from "node:path";import { describe, expect, test } from "vitest";import { buildSpecIndex, extractLinks, searchSpecIndex } from "../src/indexer.js";import { buildImportPlan } from "../src/spec-files.js";
describe("spec indexer", () => { test("extracts markdown links and wikilinks", () => { expect(extractLinks("See [Runtime](agent-runtime.md) and [[data-model|Data Model]].")).toEqual([ { kind: "markdown", raw: "[Runtime](agent-runtime.md)", target: "agent-runtime.md", normalizedTarget: "agent-runtime", text: "Runtime", }, { kind: "wikilink", raw: "[[data-model|Data Model]]", target: "data-model", normalizedTarget: "data-model", text: "Data Model", }, ]); });
test("builds term index and backlinks", async () => { const root = await fs.mkdtemp(path.join(os.tmpdir(), "charter-index-")); await fs.mkdir(path.join(root, "spec")); await fs.writeFile(path.join(root, "spec", "agent-runtime.md"), "---\nid: agent-runtime\ntitle: Agent Runtime\nkind: architecture\n---\n\n# Agent Runtime\n\nReads the [[data-model]].\n", "utf8"); await fs.writeFile(path.join(root, "spec", "data-model.md"), "---\nid: data-model\ntitle: Data Model\nkind: architecture\n---\n\n# Data Model\n\nAgent rows.\n", "utf8");
const plan = await buildImportPlan({ projectRoot: root }); const index = buildSpecIndex(plan); expect(index.termIndex.agent).toEqual(["agent-runtime", "data-model"]); expect(index.backlinks["data-model"]).toEqual(["agent-runtime"]); expect(searchSpecIndex(index, "runtime").map((document) => document.id)).toEqual(["agent-runtime"]); });});