From ebf3a5b7ecd3dabaf413491c84dbbc77f5e0a3f6 Mon Sep 17 00:00:00 2001 From: Afloat Date: Sat, 14 Nov 2026 00:04:42 +0800 Subject: [PATCH 01/12] fix: normalize inline requests with Fetch semantics --- src/inline-engine.ts | 42 +------- tests/inline-request-init.test.ts | 153 ++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+), 37 deletions(-) create mode 100644 tests/inline-request-init.test.ts diff --git a/src/inline-engine.ts b/src/inline-engine.ts index c156b0fa36..9e214fb504 100644 --- a/src/inline-engine.ts +++ b/src/inline-engine.ts @@ -28,7 +28,6 @@ export const INLINE_ORIGIN = "http://billion-context.inline"; const INLINE_HOSTNAME = new URL(INLINE_ORIGIN).hostname; type FetchInput = string | URL | Request; -type BodyLike = string | URLSearchParams | Blob | ArrayBuffer | ArrayBufferView | ReadableStream | AsyncIterable; export interface InlineEngine { origin: string; @@ -69,22 +68,6 @@ function normalizeHeaderPairs(value: Record * undici recomputes length and framing from the actual stream. */ const HOP_HEADERS = new Set(["connection", "keep-alive", "proxy-authenticate", "proxy-authorization", "te", "trailer", "transfer-encoding", "upgrade", "host", "content-length"]); -async function bodyToBuffer(body: BodyLike | null | undefined): Promise { - if (body === null || body === undefined) return Buffer.alloc(0); - if (typeof body === "string") return Buffer.from(body); - if (body instanceof URLSearchParams) return Buffer.from(body.toString()); - if (body instanceof Blob) return Buffer.from(await body.arrayBuffer()); - if (body instanceof ArrayBuffer) return Buffer.from(body); - if (ArrayBuffer.isView(body)) return Buffer.from(body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength)); - const iterator = (body as { [Symbol.asyncIterator]?: unknown })[Symbol.asyncIterator]; - if (typeof iterator === "function") { - const parts: Buffer[] = []; - for await (const chunk of body as AsyncIterable) parts.push(Buffer.from(chunk)); - return Buffer.concat(parts); - } - throw new Error(`inline engine: unsupported request body type ${Object.prototype.toString.call(body)}`); -} - /** Minimal duck-type of http.IncomingMessage covering everything the pipeline * reads: url/method/headers/socket identity plus the readBody event surface. * Body delivery is LAZY (microtask after listener registration) — readBody @@ -224,38 +207,23 @@ class InlineRes extends EventEmitter { } async function toInlineReq(input: FetchInput, init?: RequestInit): Promise { - let url: string; - let baseHeaders: Headers | [string, string][] | Record | undefined; - let requestMethod: string | undefined; - let requestBody: BodyLike | null | undefined; - if (typeof input === "string") url = input; - else if (input instanceof URL) url = input.href; - else { - url = input.url; - baseHeaders = input.headers; - requestMethod = input.method; - requestBody = await input.arrayBuffer().catch(() => null); - } - const headers = new Headers(baseHeaders); - if (init?.headers !== undefined) new Headers(init.headers).forEach((v, k) => headers.set(k, v)); + const request = new Request(input, init); const headerMap: Record = {}; - headers.forEach((value, key) => { + request.headers.forEach((value, key) => { const existing = headerMap[key]; headerMap[key] = existing === undefined ? value : Array.isArray(existing) ? [...existing, value] : [existing, value]; }); - const method = (init?.method ?? requestMethod ?? "GET").toUpperCase(); - const bodySource = init?.body !== undefined ? init.body as BodyLike | null : requestBody; - const body = await bodyToBuffer(bodySource); + const body = Buffer.from(await request.arrayBuffer()); // The pipeline reads req.url as an ORIGIN-FORM request target ("/bili/…" — // what node:http hands a server for a normal connection). An absolute-form // URL would fall into resolveUpstream's forward-proxy branch and be routed // to its own authority — the pseudo-origin — instead of the embedded host. - const parsed = new URL(url); + const parsed = new URL(request.url); // Pseudo-origin traffic is same-process by definition — present the // loopback identity so the admin surface's DNS-rebinding Host gate passes // without weakening the gate itself. Other origins keep their real host. if (headerMap["host"] === undefined) headerMap["host"] = parsed.hostname === INLINE_HOSTNAME ? "127.0.0.1" : parsed.host; - return new InlineReq(parsed.pathname + parsed.search, method, headerMap, body); + return new InlineReq(parsed.pathname + parsed.search, request.method, headerMap, body); } function responseFrom(res: InlineRes): Response { diff --git a/tests/inline-request-init.test.ts b/tests/inline-request-init.test.ts new file mode 100644 index 0000000000..fc6a30a963 --- /dev/null +++ b/tests/inline-request-init.test.ts @@ -0,0 +1,153 @@ +import { after, test } from "node:test"; +import assert from "node:assert/strict"; +import http from "node:http"; +import type { AddressInfo } from "node:net"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +const root = fs.mkdtempSync(path.join(os.tmpdir(), "bili-inline-request-init-")); +const previous = new Map(); +for (const name of ["XDG_DATA_HOME", "XDG_STATE_HOME", "XDG_CONFIG_HOME"]) { + previous.set(name, process.env[name]); + process.env[name] = path.join(root, name); +} +const { getInlineEngine, INLINE_ORIGIN, _resetInlineEngineForTest } = await import("../src/inline-engine.ts"); +const engine = await getInlineEngine(); +let hits = 0; +const upstream = http.createServer((req, res) => { + const chunks: Buffer[] = []; + req.on("data", chunk => chunks.push(Buffer.from(chunk))); + req.on("end", () => { + hits++; + res.writeHead(200, { "content-type": "application/json" }); + res.end(JSON.stringify({ method: req.method, headers: req.headers, body: Buffer.concat(chunks).toString() })); + }); +}); +await new Promise(resolve => upstream.listen(0, "127.0.0.1", resolve)); +const target = `${INLINE_ORIGIN}/bili/http://127.0.0.1:${(upstream.address() as AddressInfo).port}/echo`; +after(async () => { + upstream.closeAllConnections(); + await new Promise(resolve => upstream.close(() => resolve())); + _resetInlineEngineForTest(); + for (const [name, value] of previous) { + if (value === undefined) delete process.env[name]; + else process.env[name] = value; + } + fs.rmSync(root, { recursive: true, force: true }); +}); + +interface Echo { method: string; headers: Record; body: string } +async function dispatch(input: string | URL | Request, init?: RequestInit): Promise { + const response = await engine.dispatch(input, init, globalThis.fetch); + assert.equal(response.status, 200); + return await response.json() as Echo; +} +function original(): Request { + return new Request(target, { method: "POST", headers: { authorization: "Bearer original", "x-original": "old", "content-type": "application/custom" }, body: "original" }); +} + +const headerCases: [string, NonNullable][] = [ + ["empty object", {}], + ["object", { "x-replacement": "new" }], + ["Headers", new Headers({ "x-replacement": "new" })], + ["tuples", [["x-replacement", "new"]]], +]; +for (const [name, headers] of headerCases) { + test(`RequestInit headers replace Request headers (${name})`, async () => { + const result = await dispatch(original(), { headers }); + assert.equal(result.headers.authorization, undefined); + assert.equal(result.headers["x-original"], undefined); + assert.equal(result.headers["content-type"], undefined); + assert.equal(result.headers["x-replacement"], new Headers(headers).get("x-replacement") ?? undefined); + assert.equal(result.body, "original"); + }); +} + +for (const body of [undefined, null]) { + test(`a ${body} body override inherits the Request body`, async () => { + const input = original(); + const result = await dispatch(input, { body }); + assert.equal(result.body, "original"); + assert.equal(result.headers.authorization, "Bearer original"); + assert.equal(input.bodyUsed, true); + }); +} + +for (const body of ["replacement", ""]) { + test(`an explicit ${body ? "nonempty" : "empty"} body override does not consume the original`, async () => { + const input = original(); + const result = await dispatch(input, { body }); + assert.equal(result.body, body); + assert.equal(await input.text(), "original"); + }); +} + +test("a body override does not wait for an unused original stream", { timeout: 10_000 }, async () => { + let finish!: () => void; + const body = new ReadableStream({ start(controller) { finish = () => controller.close(); } }); + const input = new Request(target, { method: "POST", body, duplex: "half" } as RequestInit); + const request = dispatch(input, { body: "replacement" }); + let timedOut = false; + const timeout = setTimeout(() => { timedOut = true; finish(); }, 1000); + try { + assert.equal((await request).body, "replacement"); + assert.equal(timedOut, false, "the overridden body must never delay dispatch"); + assert.equal(input.bodyUsed, false); + } finally { + clearTimeout(timeout); + if (!timedOut) finish(); + } +}); + +test("a consumed Request body fails before any upstream call", async () => { + const input = original(); + await input.text(); + const before = hits; + await assert.rejects(dispatch(input), TypeError); + assert.equal(hits, before); +}); + +test("a failing Request body propagates its error without sending an empty request", async () => { + const failure = new Error("source stream failed"); + const body = new ReadableStream({ start(controller) { controller.error(failure); } }); + const input = new Request(target, { method: "POST", body, duplex: "half" } as RequestInit); + const before = hits; + await assert.rejects(dispatch(input), error => error === failure); + assert.equal(hits, before); +}); + +test("explicit body replacement permits a previously consumed Request", async () => { + const input = original(); + await input.text(); + assert.equal((await dispatch(input, { body: "replacement" })).body, "replacement"); +}); + +test("string and URL inputs retain fetch body encoding and inferred content types", async () => { + for (const input of [target, new URL(target)]) { + const text = await dispatch(input, { method: "POST", body: "hello" }); + assert.equal(text.body, "hello"); + assert.equal(text.headers["content-type"], "text/plain;charset=UTF-8"); + const form = await dispatch(input, { method: "POST", body: new URLSearchParams({ query: "中文 & hello" }) }); + assert.equal(form.body, "query=%E4%B8%AD%E6%96%87+%26+hello"); + assert.equal(form.headers["content-type"], "application/x-www-form-urlencoded;charset=UTF-8"); + } +}); + +test("FormData receives the matching multipart boundary", async () => { + const form = new FormData(); + form.set("prompt", "hello"); + form.set("file", new Blob(["content"], { type: "text/plain" }), "notes.txt"); + const result = await dispatch(target, { method: "POST", body: form }); + const boundary = result.headers["content-type"]?.match(/^multipart\/form-data; boundary=(.+)$/)?.[1]; + assert.ok(boundary); + assert.ok(result.body.startsWith(`--${boundary}\r\n`)); + assert.ok(result.body.includes('name="file"; filename="notes.txt"')); + assert.ok(result.body.includes("content\r\n")); +}); + +test("GET body validation rejects before reaching the upstream", async () => { + const before = hits; + await assert.rejects(dispatch(target, { method: "GET", body: "invalid" }), TypeError); + assert.equal(hits, before); +}); From c6369fb6a195fbd1e8794c911adaff87d4dba0f0 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 04:35:44 +0800 Subject: [PATCH 02/12] fix(tests): pin pure-sqlite selection in notice-registry suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The suite baseline preload (preload-storage-baseline.mjs) pins BILI_STORAGE_UNIFIED="legacy" for the broad corpus. After #6480 flipped the storage default to pure-sqlite, the notice-registry suite's visibleNotices assertions expect the pure-sqlite default notice, which is gated on unifiedSelectionIsSqlite (unified "sqlite" or absent) — the preload's "legacy" made the notice silent, so the suite was born-red on master. Pin the selection explicitly (#4011 lesson: a test that depends on the production default passes locally but fails in CI). --- tests/notice-registry.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/notice-registry.test.ts b/tests/notice-registry.test.ts index 6d3b60edb4..b3b0d0e8a4 100644 --- a/tests/notice-registry.test.ts +++ b/tests/notice-registry.test.ts @@ -17,6 +17,11 @@ 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; +// #4011 lesson: this suite asserts the pure-sqlite default notice is visible, +// which requires the pure-sqlite SELECTION (unified "sqlite" or absent — the +// gate is unifiedSelectionIsSqlite, not the resolved mode). The suite baseline +// preload pins "legacy" for the broad corpus, so pin the selection explicitly. +process.env.BILI_STORAGE_UNIFIED = "sqlite"; 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 a5422460d9b77ed976217b25ae953fbdfbeff85b Mon Sep 17 00:00:00 2001 From: Afloat Date: Sat, 14 Nov 2026 04:55:48 +0800 Subject: [PATCH 03/12] fix: keep inline normalization independent of caller signals --- src/inline-engine.ts | 6 +- tests/inline-request-init.test.ts | 121 ++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 1 deletion(-) diff --git a/src/inline-engine.ts b/src/inline-engine.ts index 9e214fb504..194c436b38 100644 --- a/src/inline-engine.ts +++ b/src/inline-engine.ts @@ -207,7 +207,11 @@ class InlineRes extends EventEmitter { } async function toInlineReq(input: FetchInput, init?: RequestInit): Promise { - const request = new Request(input, init); + // Only normalize body/header semantics here; the dispatcher owns and + // detaches the caller's cancellation listener. A dependent Request signal + // would leave a second listener behind. Inherit dictionary members so + // prototype and non-enumerable RequestInit fields retain Fetch semantics. + const request = new Request(input, Object.create(init ?? null, { signal: { value: null } }) as RequestInit); const headerMap: Record = {}; request.headers.forEach((value, key) => { const existing = headerMap[key]; diff --git a/tests/inline-request-init.test.ts b/tests/inline-request-init.test.ts index fc6a30a963..6697554281 100644 --- a/tests/inline-request-init.test.ts +++ b/tests/inline-request-init.test.ts @@ -1,5 +1,6 @@ import { after, test } from "node:test"; import assert from "node:assert/strict"; +import { getEventListeners } from "node:events"; import http from "node:http"; import type { AddressInfo } from "node:net"; import fs from "node:fs"; @@ -15,17 +16,25 @@ for (const name of ["XDG_DATA_HOME", "XDG_STATE_HOME", "XDG_CONFIG_HOME"]) { const { getInlineEngine, INLINE_ORIGIN, _resetInlineEngineForTest } = await import("../src/inline-engine.ts"); const engine = await getInlineEngine(); let hits = 0; +const streamResponses: http.ServerResponse[] = []; const upstream = http.createServer((req, res) => { const chunks: Buffer[] = []; req.on("data", chunk => chunks.push(Buffer.from(chunk))); req.on("end", () => { hits++; + if (req.url === "/signal-stream") { + streamResponses.push(res); + res.writeHead(200, { "content-type": "text/plain" }); + res.write("first"); + return; + } res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify({ method: req.method, headers: req.headers, body: Buffer.concat(chunks).toString() })); }); }); await new Promise(resolve => upstream.listen(0, "127.0.0.1", resolve)); const target = `${INLINE_ORIGIN}/bili/http://127.0.0.1:${(upstream.address() as AddressInfo).port}/echo`; +const streamTarget = target.replace(/\/echo$/, "/signal-stream"); after(async () => { upstream.closeAllConnections(); await new Promise(resolve => upstream.close(() => resolve())); @@ -151,3 +160,115 @@ test("GET body validation rejects before reaching the upstream", async () => { await assert.rejects(dispatch(target, { method: "GET", body: "invalid" }), TypeError); assert.equal(hits, before); }); + +async function openStream(input: string | URL | Request, init?: RequestInit) { + const response = await engine.dispatch(input, init, globalThis.fetch); + const reader = response.body!.getReader(); + assert.equal(Buffer.from((await reader.read()).value!).toString(), "first"); + return { reader, source: streamResponses.at(-1)! }; +} + +async function finishStream(stream: Awaited>): Promise { + stream.source.end("last"); + let tail = ""; + for (;;) { + const chunk = await stream.reader.read(); + if (chunk.done) break; + tail += Buffer.from(chunk.value).toString(); + } + assert.equal(tail, "last"); +} + +async function closeStream(stream: Awaited>): Promise { + if (!stream.source.writableEnded) stream.source.end(); + await stream.reader.cancel().catch(() => {}); +} + +for (const kind of ["string", "URL"] as const) { + test(`normalizing a ${kind} input leaves cancellation with the dispatcher`, async () => { + const controller = new AbortController(); + const ownListener = (): void => {}; + controller.signal.addEventListener("abort", ownListener); + const stream = await openStream(kind === "string" ? streamTarget : new URL(streamTarget), { signal: controller.signal }); + try { + assert.equal(getEventListeners(controller.signal, "abort").length, 2, "only the caller and dispatcher own listeners"); + await finishStream(stream); + assert.deepEqual(getEventListeners(controller.signal, "abort"), [ownListener]); + } finally { + controller.abort(); + await closeStream(stream); + } + }); +} + +test("normalizing a Request does not retain a dependency on its signal", async () => { + const controller = new AbortController(); + const input = new Request(streamTarget, { signal: controller.signal }); + const before = getEventListeners(input.signal, "abort"); + const stream = await openStream(input); + try { + // Request-only dispatch signal inheritance is a separate transport + // concern; the temporary body/header normalizer must not own it. + await finishStream(stream); + assert.deepEqual(getEventListeners(input.signal, "abort"), before); + } finally { + controller.abort(); + await closeStream(stream); + } +}); + +test("an explicit init signal owns cancellation instead of the Request signal", async () => { + const original = new AbortController(); + const replacement = new AbortController(); + const input = new Request(streamTarget, { signal: original.signal }); + const stream = await openStream(input, { signal: replacement.signal }); + try { + assert.equal(getEventListeners(input.signal, "abort").length, 0); + assert.equal(getEventListeners(replacement.signal, "abort").length, 1); + original.abort(new Error("original request cancelled")); + assert.equal(replacement.signal.aborted, false); + replacement.abort(new Error("effective signal cancelled")); + await assert.rejects(stream.reader.read(), /client aborted/); + assert.equal(getEventListeners(replacement.signal, "abort").length, 0); + } finally { + original.abort(); + replacement.abort(); + await closeStream(stream); + } +}); + +test("an explicit null signal keeps an aborted Request override independent", async () => { + const original = new AbortController(); + const input = new Request(streamTarget, { signal: original.signal }); + original.abort(new Error("overridden request cancellation")); + const stream = await openStream(input, { signal: null }); + try { + await finishStream(stream); + assert.equal(getEventListeners(input.signal, "abort").length, 0); + } finally { await closeStream(stream); } +}); + +test("a body read failure does not retain the init signal before dispatch starts", async () => { + const controller = new AbortController(); + const failure = new Error("normalization body failed"); + const body = new ReadableStream({ start(stream) { stream.error(failure); } }); + const before = hits; + try { + await assert.rejects(dispatch(target, { method: "POST", body, duplex: "half", signal: controller.signal } as RequestInit), error => error === failure); + assert.equal(hits, before); + assert.equal(getEventListeners(controller.signal, "abort").length, 0); + } finally { controller.abort(); } +}); + +for (const kind of ["inherited", "non-enumerable"] as const) { + test(`RequestInit keeps ${kind} body, method, and header members`, async () => { + const fields: RequestInit = { method: "POST", body: "dictionary body", headers: { "x-dictionary": kind } }; + const init: RequestInit = kind === "inherited" + ? Object.create(fields) as RequestInit + : Object.create(null, Object.fromEntries(Object.entries(fields).map(([key, value]) => [key, { value }]))) as RequestInit; + const result = await dispatch(target, init); + assert.equal(result.method, "POST"); + assert.equal(result.body, "dictionary body"); + assert.equal(result.headers["x-dictionary"], kind); + }); +} From b1bc17b40454480c7204c2d2e7b44afb5216e367 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 10:20:31 +0800 Subject: [PATCH 04/12] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in CCR cold-disk-restore test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dsh plugin lane (ci-e2e-dsh.yml) runs node --import tsx --test WITHOUT the preload-storage-baseline.mjs preload, so BILI_STORAGE_UNIFIED is unset and the storage mode defaults to 'full'. Under the pure-sqlite default flip (5a80e2b8e, #6480), 'full' mode turns the JSON envelope writer OFF — so the .content-store.json sidecar is never written, and the test's readdirSync(namespace) hits ENOENT. Pin BILI_STORAGE_JSON_WRITER=on in the test so the content-store sidecar is written regardless of the storage mode. This keeps the corrupted-store detection path exercised in both full and legacy modes. Closes: dsh plugin lane red on master (run 43532980164, job 132255459726) --- tests/plugin-fork.test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/plugin-fork.test.ts b/tests/plugin-fork.test.ts index 2763aa2f4e..4bd98e328f 100644 --- a/tests/plugin-fork.test.ts +++ b/tests/plugin-fork.test.ts @@ -909,6 +909,12 @@ test("HTTP CCR shared payload deletion fails closed before persistence", { timeo for (const corruption of ["missing-ref", "missing-payload", "orphan-payload", "wrong-raw-alias", "changed-payload"] as const) { test(`HTTP CCR ${corruption} fails closed after cold disk restore`, async () => { + // The corrupted-store detection path needs the JSON content-store + // sidecar on disk. Under the pure-sqlite default (5a80e2b8e) the + // JSON writer is OFF, so pin it ON to keep exercising the envelope + // corruption path this test was written for. + const oldJsonWriter = process.env.BILI_STORAGE_JSON_WRITER; + process.env.BILI_STORAGE_JSON_WRITER = "on"; const h = await harness(true); try { const parent = resolveConversation("parent").session!; @@ -966,7 +972,11 @@ for (const corruption of ["missing-ref", "missing-payload", "orphan-payload", "w assert.equal(parentState(), before); assert.equal(readFileSync(path, "utf8"), JSON.stringify(disk)); store2.closeQuietly(); - } finally { await h.close(); } + } finally { + if (oldJsonWriter === undefined) delete process.env.BILI_STORAGE_JSON_WRITER; + else process.env.BILI_STORAGE_JSON_WRITER = oldJsonWriter; + await h.close(); + } }); } From 7492c35c2ad980560c3289c4cdb73e9f32af9dfe Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 12:11:32 +0800 Subject: [PATCH 05/12] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in native opencode e2e lane The pure-sqlite default flip (5a80e2b8e, #6480) turns the JSON envelope writer OFF, so the .json session file this lane asserts on is never written and 'proxy must persist the session' / 'no persisted session carried compressed blocks' fail after the 20s wait. Pin the writer ON in the spawned client's env (the bootstrapped proxy inherits it) so the envelope this test was written for is still produced. Closes: native opencode lane red on master (run 43547593803, job 132302438610) --- tests/e2e/e2e-native-opencode.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/e2e/e2e-native-opencode.test.ts b/tests/e2e/e2e-native-opencode.test.ts index 8b5578020d..78975d418d 100644 --- a/tests/e2e/e2e-native-opencode.test.ts +++ b/tests/e2e/e2e-native-opencode.test.ts @@ -421,6 +421,11 @@ async function ocRun( cwd: ctx.ocCwd, env: { ...cleanEnv(), + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // file. Pin the writer ON so the envelope this test was written for + // is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", HOME: ctx.homeDir, TMPDIR: ctx.tmdir, XDG_CONFIG_HOME: ctx.xdg.config, From 45f93dbb8fc88523e3015a413ea7620281d11d1e Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 12:11:32 +0800 Subject: [PATCH 06/12] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in native dsh e2e lane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same pure-sqlite default flip (5a80e2b8e, #6480) as the opencode lane: the JSON envelope writer is OFF, so 'proxy must persist the session within 20000ms' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned dsh client's env (the bootstrapped proxy inherits it). Closes: native dsh lane red on master (run 43547497015, job 132302138843) --- tests/e2e/e2e-native-dsh.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/e2e/e2e-native-dsh.test.ts b/tests/e2e/e2e-native-dsh.test.ts index 7b7402356c..ea8c3969e4 100644 --- a/tests/e2e/e2e-native-dsh.test.ts +++ b/tests/e2e/e2e-native-dsh.test.ts @@ -463,6 +463,11 @@ function dshRun( cwd: ctx.dshCwd, env: { ...cleanEnv(), + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // file. Pin the writer ON so the envelope this test was written for + // is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", HOME: ctx.homeDir, TMPDIR: ctx.tmpDir, DSH_HOME: ctx.dshHome, From d67cc43557b98d9aa9ce61c24f4dcff93d882558 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 12:11:32 +0800 Subject: [PATCH 07/12] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in pi codex-responses WS e2e lane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same pure-sqlite default flip (5a80e2b8e, #6480) as the opencode/dsh lanes: the JSON envelope writer is OFF, so 'session persisted' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned pi client's env (the bootstrapped proxy inherits it). Closes: pi codex-responses WS lane red on master (run 43547626291, job 132302540960) --- tests/e2e/e2e-pi-codex-ws.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/e2e/e2e-pi-codex-ws.test.ts b/tests/e2e/e2e-pi-codex-ws.test.ts index 15788e0224..c5b3625224 100644 --- a/tests/e2e/e2e-pi-codex-ws.test.ts +++ b/tests/e2e/e2e-pi-codex-ws.test.ts @@ -342,6 +342,12 @@ function piRun( cwd: ctx.piCwd, env: { ...cleanEnv(opts.extraEnv), + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON + // envelope writer OFF, but this lane asserts on the on-disk + // .json session file. Pin the writer ON so the envelope this + // test was written for is still produced regardless of the + // storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", PI_CODING_AGENT_DIR: ctx.piAgentDir, XDG_CONFIG_HOME: ctx.xdg.config, XDG_CACHE_HOME: ctx.xdg.cache, From c392237d4702601246f5bcb70235b46f8becdc8d Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 13:18:32 +0800 Subject: [PATCH 08/12] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in pi package-native e2e lane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4th lane of the pure-sqlite default flip (5a80e2b8e, #6480) family: the JSON envelope writer is OFF, so 'proxy must persist the session' and 'at least one persisted session must carry compressed blocks' fail — the on-disk .json session file is never written. Pin the writer ON in the spawned pi client's env (the bootstrapped proxy inherits it). Closes: pi package-native lane red on ci-fixes (run 43558179054, job 132336647955) --- tests/e2e/e2e-native-pi.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/e2e/e2e-native-pi.test.ts b/tests/e2e/e2e-native-pi.test.ts index 151b1606e1..cbedc8dd9b 100644 --- a/tests/e2e/e2e-native-pi.test.ts +++ b/tests/e2e/e2e-native-pi.test.ts @@ -468,8 +468,13 @@ 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. - BILI_PI_INLINE: "0", - PI_CODING_AGENT_DIR: ctx.piAgentDir, + BILI_PI_INLINE: "0", + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // file. Pin the writer ON so the envelope this test was written for + // is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", + PI_CODING_AGENT_DIR: ctx.piAgentDir, XDG_CONFIG_HOME: ctx.xdg.config, XDG_CACHE_HOME: ctx.xdg.cache, XDG_STATE_HOME: ctx.xdg.state, From 974cd4c2f67c9ee5a1f8879709224cc00b2f91df Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 13:18:32 +0800 Subject: [PATCH 09/12] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in fork-ccr-adoption suite Same pure-sqlite default flip (5a80e2b8e, #6480) family: the JSON writer is OFF, so the per-session CCR content-store sidecar (.content-store.json) that 'child persists its own companion and survives a proxy restart' asserts on is never written (0 !== 1). The earlier b1bc17b40 pin only covered tests/plugin-fork.test.ts, not this file. Pin the writer ON at module load (before any SessionStore is constructed). Closes: dsh plugin lane red on ci-fixes (run 43558179102, job 132336519539) --- tests/fork-ccr-adoption.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/fork-ccr-adoption.test.ts b/tests/fork-ccr-adoption.test.ts index 4cd9a7b586..ea8004f747 100644 --- a/tests/fork-ccr-adoption.test.ts +++ b/tests/fork-ccr-adoption.test.ts @@ -38,6 +38,12 @@ import { maybeAdoptForkBlocks } from "../src/fork-adoption.ts"; import { rmrf } from "./tmp-rm.ts"; process.env.BILI_PERSIST = "0"; +// Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope writer OFF, +// so the per-session CCR content-store sidecar (.content-store.json) this +// suite asserts on is never written. Pin the writer ON at module load (before +// any SessionStore is constructed) so the companion-envelope coverage this +// test was written for still runs regardless of the storage-mode default. +process.env.BILI_STORAGE_JSON_WRITER = "on"; const LIMIT = 200_000; const META = { protocol: "openai" as const, upstreamOrigin: "http://upstream.example/v1" }; From 271abba541666260a2142767c78cb2e53ea00595 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 13:31:56 +0800 Subject: [PATCH 10/12] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in subagent-sessions e2e lane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pure-sqlite default flip (5a80e2b8e, #6480) family: the JSON envelope writer is OFF, so 'proxy must persist the session' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned opencode client's env (the bootstrapped proxy inherits it). --- tests/e2e/e2e-subagent-sessions.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/e2e/e2e-subagent-sessions.test.ts b/tests/e2e/e2e-subagent-sessions.test.ts index af08050217..b1a6188bca 100644 --- a/tests/e2e/e2e-subagent-sessions.test.ts +++ b/tests/e2e/e2e-subagent-sessions.test.ts @@ -394,6 +394,11 @@ async function ocRun( cwd: ctx.ocCwd, env: { ...cleanEnv(), + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // file. Pin the writer ON so the envelope this test was written for + // is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", HOME: ctx.homeDir, TMPDIR: ctx.tmdir, XDG_CONFIG_HOME: ctx.xdg.config, From 5d47196a267e20b63ed7965b6fea58374cc599f7 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 13:31:56 +0800 Subject: [PATCH 11/12] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in dsh-persona e2e lane Pure-sqlite default flip (5a80e2b8e, #6480) family: the JSON envelope writer is OFF, so the on-disk .json session envelope this lane asserts on (exactly ONE persisted session under the raw key) is never written. Pin the writer ON in the spawned dsh client's env. --- 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..8d3ea3d34c 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 default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session + // envelope. Pin the writer ON so the envelope this test was written + // for is still produced regardless of the storage-mode default. + BILI_STORAGE_JSON_WRITER: "on", HOME: home, TMPDIR: tmp, DSH_HOME: dshHome, From 1ca40871581c5009fdb69eea944f448d002098e7 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sat, 14 Nov 2026 13:31:56 +0800 Subject: [PATCH 12/12] fix(tests): pin BILI_STORAGE_JSON_WRITER=on in update-state e2e lane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pure-sqlite default flip (5a80e2b8e, #6480) family: the JSON envelope writer is OFF, so the on-disk .json session file this lane asserts on (state survival across the OLD→NEW update) is never written. Pin the writer ON in the spawned proxy's env (both update phases share envBase). --- tests/e2e/e2e-update-state.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/e2e/e2e-update-state.test.ts b/tests/e2e/e2e-update-state.test.ts index 03f2b1db22..e31baf7659 100644 --- a/tests/e2e/e2e-update-state.test.ts +++ b/tests/e2e/e2e-update-state.test.ts @@ -299,6 +299,11 @@ test("self-update keeps live compression state: folds survive the OLD→NEW hop envBase.BILI_UPDATE_POLICY_URL = "http://127.0.0.1:1/no-policy.json"; envBase.BILI_PERSIST_DEBOUNCE_MS = "200"; envBase.BILI_SESSIONS_DIR = sessionsDir; + // Pure-sqlite default (5a80e2b8e, #6480) turns the JSON envelope + // writer OFF, but this lane asserts on the on-disk .json session file + // (state survival across the update). Pin the writer ON so the + // envelope this test was written for is still produced. + envBase.BILI_STORAGE_JSON_WRITER = "on"; const port = await freePort(); proxy = spawnProxy(installDir, port, envBase);