From 21746581f0dd2be418112c2e74a6d02fa15a46f3 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 00:31:20 +0800 Subject: [PATCH 1/5] e2e: pin dual-write storage in client lanes + tolerate half-deleted install dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pure-SQLite storage default (owner decision 2026-11-13, 5a80e2b8e) stopped writing JSONL session envelopes by default. Five hermetic client e2e lanes (native-pi / native-dsh / native-opencode / pi-codex-ws / subagent-sessions) assert those envelopes and were not updated with the default flip: they now fail with 'proxy must persist the session (got 0 sessions)' (reproduced locally with the CI-pinned pi-stable 0.83.6 and on the PR head). Pin BILI_STORAGE_JSON_WRITER=1 in the spawned-client env: these lanes cover proxy/session semantics, not the storage default — the pure-SQLite path stays covered by unit tests and the real-model gate. Also: the advisory-rollback waitFor probes crashed with ENOENT when the updater's uninstall->reinstall half-deletes the install dir (npm drops package.json before the directory; reproduced locally). New pkgVersionOrAbsent() helper treats that window as 'not there yet'; non-ENOENT errors still throw. This was the ubuntu flake behind the 'hermetic registry e2e' red on 16b8d9b (run 43454198949). --- tests/e2e/e2e-advisory-rollback.test.ts | 17 +++++++++++++++-- tests/e2e/e2e-native-dsh.test.ts | 4 ++++ tests/e2e/e2e-native-opencode.test.ts | 4 ++++ tests/e2e/e2e-native-pi.test.ts | 6 ++++++ tests/e2e/e2e-pi-codex-ws.test.ts | 4 ++++ tests/e2e/e2e-subagent-sessions.test.ts | 4 ++++ 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/e2e/e2e-advisory-rollback.test.ts b/tests/e2e/e2e-advisory-rollback.test.ts index 0e7cf12fa2..f7082e2053 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; } +// The updater's uninstall→reinstall half-deletes the install dir (npm drops +// package.json before the directory): 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.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, From af49339a1f1920f228d3b383f895194663ef9a8f Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 00:50:08 +0800 Subject: [PATCH 2/5] tests: unpin CI storage-baseline env in notice-registry suite The CI-only baseline preload (tests/preload-storage-baseline.mjs) pins BILI_STORAGE_UNIFIED=legacy for the legacy-default corpus. The sqlite-default notice test asserts the production default (absent spelling => pure-sqlite), so without an explicit unpin it passes locally (no preload) and reds every CI test shard carrying this file. Also unpin BILI_STORAGE_JSON_WRITER for the same predicate. --- tests/notice-registry.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) 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"); From cc472152c53c5a2792165e8e8fb47befb63c725f Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 01:43:36 +0800 Subject: [PATCH 3/5] e2e: pin dual-write storage in dsh-persona lane too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tests/e2e/e2e-native-dsh-persona.test.ts asserts JSONL session envelopes ('the raw conversation key persisted a session') but its spawned env missed the same pin as the other client lanes — red in the e2e-dsh lane. --- tests/e2e/e2e-native-dsh-persona.test.ts | 5 +++++ 1 file changed, 5 insertions(+) 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, From ada04fd361259a3c25391c37143186dfe406026b Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 14 Nov 2026 04:05:53 +0800 Subject: [PATCH 4/5] test(persist): close store sidecars before tmp-dir teardown (Windows EBUSY) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dual-write pins added with the pure-sqlite default flip make persist-zstd and persist-metadata-fold-gate open index.db; the suites never closed their stores, so the tmp-dir teardown raced a still-open SQLite handle — Windows cannot unlink an open file, and the retry budget in tmp-rm.ts lost deterministically (EBUSY unlink .../index.db on windows 22/1, 22/3, 24/1, 24/3; same suites green on v0.1.213). Close every store (closeQuietly: cancel pending writes + sidecar close) before rmrf. closeQuietly is idempotent-safe where flushAll already closed the sidecar. --- tests/persist-metadata-fold-gate.test.ts | 4 ++++ tests/persist-zstd.test.ts | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) 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 { From ad0616d6b3361fd5bc716ab0e0b24bc2edde7ab9 Mon Sep 17 00:00:00 2001 From: ci-check Date: Sat, 14 Nov 2026 04:14:05 +0800 Subject: [PATCH 5/5] test: correct advisory-flake probe comment (updater has no uninstall path) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The original comment asserted the updater 'uninstall→reinstall half-deletes the install dir (npm drops package.json before the directory)'. Verified against src/update.ts: there is no npm uninstall anywhere; every install (normal self-update, advisory forceInstallVersion, manual) goes through installViaTarball, whose success path overwrites package.json in place (cp staging→installDir) and never deletes it. The only installDir deletion is restoreFromBackup (failure path only, immediately restored). So the stated mechanism does not exist. Reword the comment to describe the observed behavior (transient ENOENT while the updater rewrites the install dir) without asserting an unverified mechanism. The pkgVersionOrAbsent fix itself is unchanged and remains correct: ENOENT→null→keep polling, timeout still fails, non-ENOENT still throws. --- tests/e2e/e2e-advisory-rollback.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/e2e/e2e-advisory-rollback.test.ts b/tests/e2e/e2e-advisory-rollback.test.ts index f7082e2053..36c926f645 100644 --- a/tests/e2e/e2e-advisory-rollback.test.ts +++ b/tests/e2e/e2e-advisory-rollback.test.ts @@ -78,10 +78,10 @@ async function readPkgVersion(dir: string): Promise { return (JSON.parse(await fs.promises.readFile(path.join(dir, "package.json"), "utf8")) as { version: string }).version; } -// The updater's uninstall→reinstall half-deletes the install dir (npm drops -// package.json before the directory): 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. +// 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);