|
|
@@ -1,5 +1,13 @@
|
|
|
import Database from "better-sqlite3"
|
|
|
-import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"
|
|
|
+import {
|
|
|
+ afterAll,
|
|
|
+ beforeAll,
|
|
|
+ beforeEach,
|
|
|
+ describe,
|
|
|
+ expect,
|
|
|
+ it,
|
|
|
+ vi,
|
|
|
+} from "vitest"
|
|
|
|
|
|
// Mock @enesis/editor — its dependency chain pulls in Vue files that vitest
|
|
|
// can't parse without a Vue plugin.
|
|
|
@@ -87,6 +95,11 @@ function opts(files: Record<string, string>, workspacePath = "/ws") {
|
|
|
}
|
|
|
|
|
|
describe("syncIndex", () => {
|
|
|
+ // Each test starts with a clean database so state doesn't leak between them
|
|
|
+ beforeEach(async () => {
|
|
|
+ await db.execute("DELETE FROM pages")
|
|
|
+ })
|
|
|
+
|
|
|
it("indexes new files", async () => {
|
|
|
const o = opts({ "pages/New.md": "# Hello World" })
|
|
|
await syncIndex(o, db)
|
|
|
@@ -201,6 +214,12 @@ describe("fullReindex", () => {
|
|
|
})
|
|
|
|
|
|
describe("migrateContentHash via initIndex", () => {
|
|
|
+ // This is the one integration-style test in the suite: it creates a real DB
|
|
|
+ // file on disk with the old schema, opens it through initIndex (which runs
|
|
|
+ // migrateContentHash), and verifies the column was added. Writing a temp
|
|
|
+ // file is unavoidable because initIndex opens the DB via a path string.
|
|
|
+ // If the test process is killed mid-run, the temp dir leaks — acceptable
|
|
|
+ // for a dev-only test.
|
|
|
it("adds content_hash column to existing old-schema database", async () => {
|
|
|
// Build the old schema manually (without content_hash)
|
|
|
const raw = new Database(":memory:")
|