Files
kilocode/packages/core/test/preload.ts
T
Yury Zialionka 2cb8ff4e46 test(storage): make the storage root injectable and fail closed on disk databases
Closes #12997. Part of #12986.

- Storage.layerFromDir(dir) roots the service at an explicit directory;
  the default layer still resolves Global.Path.data/storage lazily, so
  production composition (app-runtime) is unchanged.
- storage.test.ts injects a tmp root directly instead of remapping six
  FSUtil methods under Global.Path.data - the remap hack and its
  keep-in-sync burden are gone.
- Both test preloads now assert the resolved database path is
  ":memory:" after all preload imports. Previously a dropped env write
  or import-order regression silently pointed unit tests at the real
  ~/.local/share/kilo database (locking errors, Windows EBUSY teardown
  crashes); now the run fails immediately with a clear message.
2026-08-13 13:49:08 -06:00

16 lines
729 B
TypeScript

import path from "path"
process.env.KILO_DB = ":memory:"
process.env.KILO_MODELS_PATH = path.join(import.meta.dir, "plugin", "fixtures", "models-dev.json")
process.env.KILO_DISABLE_MODELS_FETCH = "true"
// kilocode_change start - fail closed: core unit tests do not redirect XDG dirs, so KILO_DB
// is the only thing keeping them off the real ~/.local/share/kilo database. Verify the
// resolved path (env is read at flag import time, so this must stay after the env writes).
const { Database } = await import("../src/database/database")
const resolved = Database.path()
if (resolved !== ":memory:") {
throw new Error(`unit test preload: database path must resolve to ":memory:", got "${resolved}"`)
}
// kilocode_change end