diff --git a/tests/e2e/e2e-advisory-rollback.test.ts b/tests/e2e/e2e-advisory-rollback.test.ts index 0e7cf12fa2..36c926f645 100644 --- a/tests/e2e/e2e-advisory-rollback.test.ts +++ b/tests/e2e/e2e-advisory-rollback.test.ts @@ -78,6 +78,19 @@ async function readPkgVersion(dir: string): Promise { return (JSON.parse(await fs.promises.readFile(path.join(dir, "package.json"), "utf8")) as { version: string }).version; } +// package.json can be momentarily absent while the updater rewrites the +// install dir: readPkgVersion ENOENTs inside that window. waitFor probes +// must treat "gone for a moment" as "not there yet", not crash — anything +// other than ENOENT still throws. +async function pkgVersionOrAbsent(dir: string): Promise { + try { + return await readPkgVersion(dir); + } catch (err) { + if ((err as NodeJS.ErrnoException).code === "ENOENT") return null; + throw err; + } +} + function packTarball(stage: string, packs: string, home: string): string { const listing = npmRunSync(["pack", "--silent", "--pack-destination", packs], { cwd: stage, env: { PATH: process.env.PATH ?? "", ...npmHomeEnv(home) } }) .trim() @@ -262,14 +275,14 @@ test("e2e: rollback-form advisory (#1588) — forced rollback, no ping-pong, per await waitFor( `disk ${START} → ${LATEST} via normal self-update`, 90_000, - async () => (await readPkgVersion(installDir)) === LATEST && installedRe.test(readLog()), + async () => (await pkgVersionOrAbsent(installDir)) === LATEST && installedRe.test(readLog()), ); assert.match(readLog(), installedRe); }); await t.test("rollback-form advisory lands: forced install of the older target + persistent restart banner", async () => { await reg.publish(await makeAdvisoryTarball(work)); - await waitFor(`disk ${LATEST} → ${TARGET} via forced advisory install`, 60_000, async () => (await readPkgVersion(installDir)) === TARGET); + await waitFor(`disk ${LATEST} → ${TARGET} via forced advisory install`, 60_000, async () => (await pkgVersionOrAbsent(installDir)) === TARGET); const log = readLog(); assert.match(log, new RegExp(`forcing update to ${escapeRe(TARGET)}`)); // #1588-B: disk left the range but the RUNNING process is still on the diff --git a/tests/e2e/e2e-native-dsh-persona.test.ts b/tests/e2e/e2e-native-dsh-persona.test.ts index 82f3abc94b..06d0d4ab65 100644 --- a/tests/e2e/e2e-native-dsh-persona.test.ts +++ b/tests/e2e/e2e-native-dsh-persona.test.ts @@ -400,6 +400,11 @@ function buildRig(tag: string, withAutoReview: boolean): Rig { const env: NodeJS.ProcessEnv = { ...cleanEnv(), + // Pure-SQLite is the default storage writer now (2026-11-13): this lane + // asserts the JSONL session envelopes — pin dual-write (same reason as + // the other client e2e lanes); pure-sqlite semantics are covered by the + // unit tests and the real-model gate. + BILI_STORAGE_JSON_WRITER: "1", HOME: home, TMPDIR: tmp, DSH_HOME: dshHome, diff --git a/tests/e2e/e2e-native-dsh.test.ts b/tests/e2e/e2e-native-dsh.test.ts index 7b7402356c..93d2521c7e 100644 --- a/tests/e2e/e2e-native-dsh.test.ts +++ b/tests/e2e/e2e-native-dsh.test.ts @@ -463,6 +463,10 @@ function dshRun( cwd: ctx.dshCwd, env: { ...cleanEnv(), + // Pure-SQLite is the default storage writer now (2026-11-13): this lane + // asserts the JSONL session envelopes — pin dual-write so coverage does + // not depend on the default (pure-SQLite path: unit tests + gate). + BILI_STORAGE_JSON_WRITER: "1", HOME: ctx.homeDir, TMPDIR: ctx.tmpDir, DSH_HOME: ctx.dshHome, diff --git a/tests/e2e/e2e-native-opencode.test.ts b/tests/e2e/e2e-native-opencode.test.ts index 8b5578020d..cf2200f2d2 100644 --- a/tests/e2e/e2e-native-opencode.test.ts +++ b/tests/e2e/e2e-native-opencode.test.ts @@ -421,6 +421,10 @@ async function ocRun( cwd: ctx.ocCwd, env: { ...cleanEnv(), + // Pure-SQLite is the default storage writer now (2026-11-13): this lane + // asserts the JSONL session envelopes — pin dual-write so coverage does + // not depend on the default (pure-SQLite path: unit tests + gate). + BILI_STORAGE_JSON_WRITER: "1", HOME: ctx.homeDir, TMPDIR: ctx.tmdir, XDG_CONFIG_HOME: ctx.xdg.config, diff --git a/tests/e2e/e2e-native-pi.test.ts b/tests/e2e/e2e-native-pi.test.ts index 7f0ee66eb3..7a4e55f660 100644 --- a/tests/e2e/e2e-native-pi.test.ts +++ b/tests/e2e/e2e-native-pi.test.ts @@ -468,6 +468,12 @@ function piRun( // (CI sentinel incident, #4599). Pin the legacy posture so this // coverage stays deterministic; inline posture is covered by // tests/pi-inline-ws.test.ts and tests/pi-native.test.ts. + // Pure-SQLite became the default storage writer (2026-11-13 owner + // decision): JSONL session envelopes stop being written unless + // dual-write is requested. This lane asserts the JSONL envelopes — + // pin dual-write so the coverage does not ride the default; the + // pure-SQLite path is covered by unit tests + the real-model gate. + BILI_STORAGE_JSON_WRITER: "1", BILI_PI_INLINE: "0", PI_CODING_AGENT_DIR: ctx.piAgentDir, XDG_CONFIG_HOME: ctx.xdg.config, diff --git a/tests/e2e/e2e-pi-codex-ws.test.ts b/tests/e2e/e2e-pi-codex-ws.test.ts index a8df48ae7c..bf4ea28acd 100644 --- a/tests/e2e/e2e-pi-codex-ws.test.ts +++ b/tests/e2e/e2e-pi-codex-ws.test.ts @@ -342,6 +342,10 @@ function piRun( cwd: ctx.piCwd, env: { ...cleanEnv(opts.extraEnv), + // Pure-SQLite is the default storage writer now (2026-11-13): + // this lane asserts the JSONL session envelopes — pin dual-write + // so coverage does not depend on the default. + BILI_STORAGE_JSON_WRITER: "1", PI_CODING_AGENT_DIR: ctx.piAgentDir, XDG_CONFIG_HOME: ctx.xdg.config, XDG_CACHE_HOME: ctx.xdg.cache, diff --git a/tests/e2e/e2e-subagent-sessions.test.ts b/tests/e2e/e2e-subagent-sessions.test.ts index af08050217..0acba3a090 100644 --- a/tests/e2e/e2e-subagent-sessions.test.ts +++ b/tests/e2e/e2e-subagent-sessions.test.ts @@ -394,6 +394,10 @@ async function ocRun( cwd: ctx.ocCwd, env: { ...cleanEnv(), + // Pure-SQLite is the default storage writer now (2026-11-13): this lane + // asserts the JSONL session envelopes — pin dual-write so coverage does + // not depend on the default (pure-SQLite path: unit tests + gate). + BILI_STORAGE_JSON_WRITER: "1", HOME: ctx.homeDir, TMPDIR: ctx.tmdir, XDG_CONFIG_HOME: ctx.xdg.config, diff --git a/tests/notice-registry.test.ts b/tests/notice-registry.test.ts index 6d3b60edb4..1235be3a60 100644 --- a/tests/notice-registry.test.ts +++ b/tests/notice-registry.test.ts @@ -17,6 +17,14 @@ const cfgPath = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "notice-reg-cfg- process.env.DSH_HOME = fs.mkdtempSync(path.join(os.tmpdir(), "notice-reg-dsh-")); process.env.XDG_STATE_HOME = stateDir; process.env.BILI_CONFIG_FILE = cfgPath; +// The CI baseline preload (tests/preload-storage-baseline.mjs) pins +// BILI_STORAGE_UNIFIED=legacy for the legacy-default corpus. This suite +// asserts the PRODUCTION default (absent spelling ⇒ pure-sqlite ⇒ the +// sqlite-default notice is active), so both storage-selection knobs must be +// unpinned explicitly — relying on the ambient default passes locally (no +// preload) but reds CI (the #4011 lesson written into that baseline file). +delete process.env.BILI_STORAGE_UNIFIED; +delete process.env.BILI_STORAGE_JSON_WRITER; const { NOTICES, visibleNotices, SQLITE_DEFAULT_NOTICE_ID } = await import("../src/notices.ts"); const { IOT_INCOMPAT_NOTICE_ID, PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID, dismissUpgradeNotice } = await import("../src/pck-notice.ts"); diff --git a/tests/persist-metadata-fold-gate.test.ts b/tests/persist-metadata-fold-gate.test.ts index bf1a8301d6..788d4cedaf 100644 --- a/tests/persist-metadata-fold-gate.test.ts +++ b/tests/persist-metadata-fold-gate.test.ts @@ -62,6 +62,7 @@ test("metadata fold is refused while live metadata diverges from the last commit foldGate(store).dropResidentMetadata(s); assert.equal(isDroppedMetadata(s.metadata), false, "fold must be refused while live metadata diverges from committed bytes"); assert.equal((s.metadata as Record).lateStamp, "unsaved", "the unsaved mutation must stay resident"); + store.closeQuietly(); // dual-write pin opens index.db — close before teardown (Windows cannot unlink an open SQLite file; see persist-zstd.test.ts for the family) } finally { rmrf(dir); } @@ -85,6 +86,8 @@ test("metadata fold proceeds once the divergent mutation has been committed (#55 assert.ok(back, "session reloaded"); assert.equal((back?.metadata as Record).lateStamp, "unsaved", "committed mutation survives the round trip"); await reloaded.flushAll([]); + store.closeQuietly(); + reloaded.closeQuietly(); } finally { rmrf(dir); } @@ -99,6 +102,7 @@ test("metadata fold stays closed for a session with no committed save yet (#5506 foldGate(store).dropResidentMetadata(s); assert.equal(isDroppedMetadata(s.metadata), false, "no commit proof yet ⇒ fold must stay closed"); assert.equal((s.metadata as Record).onlyInMemory, true); + store.closeQuietly(); } finally { rmrf(dir); } diff --git a/tests/persist-zstd.test.ts b/tests/persist-zstd.test.ts index 93c668f7d7..887a0d4e49 100644 --- a/tests/persist-zstd.test.ts +++ b/tests/persist-zstd.test.ts @@ -48,31 +48,41 @@ function makeSession(id: string, fill = 0, fillRandom = false): Session { interface Harness { dir: string; logs: LogLine[]; + stores: SessionStore[]; } async function withTempDir(name: string, fn: (h: Harness) => Promise): Promise { await test(name, async () => { const dir = mkdtempSync(join(tmpdir(), "bili-zstd-")); const logs: LogLine[] = []; - const h = { dir, logs }; + const h: Harness = { dir, logs, stores: [] }; try { await fn(h); } finally { delete process.env.BILI_ENCRYPTION_KEY; delete process.env.BILI_PERSIST_ZSTD; _setZstdAvailableForTest(null); + // The dual-write pin above opens index.db in every store — Windows + // cannot unlink an open SQLite file, so close each sidecar before + // the tmp-dir teardown or the rmrf loses the EBUSY race (#5154 + // family, resurfaced by the pure-sqlite-default test pins). + for (const s of h.stores) { + try { s.closeQuietly(); } catch { /* already closed */ } + } rmrf(dir); } }); } function newStore(h: Harness, debounceMs = 0): SessionStore { - return new SessionStore({ + const store = new SessionStore({ dir: h.dir, debounceMs, enabled: true, log: (level, msg) => h.logs.push({ level, msg }), }); + h.stores.push(store); + return store; } function filePath(dir: string, id: string): string {