import { chmodSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { describe, expect, test } from "bun:test"; import { scanPathEntries } from "./command_index"; import { assessSearch } from "./search"; import { IndexStore } from "./store/store"; describe("assess search", () => { test("blocks until every command is documented", () => { const root = tempDir("blocked"); const bin = join(root, "bin"); mkdirSync(bin, { recursive: true }); createExecutable(join(bin, "agent-browser")); createExecutable(join(bin, "firefox")); const index = scanPathEntries([bin]); const store = IndexStore.open(join(root, "index.sqlite3")); store.syncCommands(index); store.documentCommands( [{ name: "firefox", description: "Graphical web browser for general browsing." }], "manual", ); expect(assessSearch(store, index, "fingerprint")).toEqual({ needsCommandSync: false, needsSeedHydration: false, needsEmbeddingRefresh: true, undocumented: ["agent-browser"], }); }); test("requires hydration before undocumented checks when seeded metadata exists", () => { const root = tempDir("hydration"); const bin = join(root, "bin"); mkdirSync(bin, { recursive: true }); createExecutable(join(bin, "agent-browser")); const index = scanPathEntries([bin]); const store = IndexStore.open(join(root, "index.sqlite3")); store.syncCommands(index); store.importSeedEntries( [{ name: "agent-browser", description: "CLI for browser automation and screenshots." }], "seed-import", ); expect(assessSearch(store, index, "fingerprint")).toEqual({ needsCommandSync: false, needsSeedHydration: true, needsEmbeddingRefresh: false, undocumented: [], }); }); }); function createExecutable(path: string): void { writeFileSync(path, "#!/bin/sh\nexit 0\n"); chmodSync(path, 0o755); } function tempDir(label: string): string { return mkdtempSync(join(tmpdir(), `tool-query-${label}-`)); }