Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions tests/e2e/e2e-advisory-rollback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ async function readPkgVersion(dir: string): Promise<string> {
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<string | null> {
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()
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/e2e-native-dsh-persona.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/e2e-native-dsh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/e2e-native-opencode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/e2e-native-pi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/e2e-pi-codex-ws.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/e2e-subagent-sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tests/notice-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions tests/persist-metadata-fold-gate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>).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);
}
Expand All @@ -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<string, unknown>).lateStamp, "unsaved", "committed mutation survives the round trip");
await reloaded.flushAll([]);
store.closeQuietly();
reloaded.closeQuietly();
} finally {
rmrf(dir);
}
Expand All @@ -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<string, unknown>).onlyInMemory, true);
store.closeQuietly();
} finally {
rmrf(dir);
}
Expand Down
14 changes: 12 additions & 2 deletions tests/persist-zstd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>): Promise<void> {
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 {
Expand Down
Loading