Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
da5d55a
fix: preserve null response bodies in the inline HTTP engine
Afloat16 Nov 12, 2026
6d3fbcf
Merge current master into PR #6502 for validation
Afloat16 Nov 13, 2026
a3b1afc
test(review): hermetic XDG storage for the inline null-body engine te…
Nov 13, 2026
fae9926
Merge remote-tracking branch 'origin/master' into pr6502-update
Nov 13, 2026
c6369fb
fix(tests): pin pure-sqlite selection in notice-registry suite
Nov 13, 2026
b1bc17b
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in CCR cold-disk-restore …
Nov 14, 2026
da7c052
Merge remote-tracking branch 'origin/master' into w5p
ranxianglei Nov 14, 2026
cd8bc8a
Merge remote-tracking branch 'origin/master' into ci-fixes
Nov 14, 2026
7492c35
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in native opencode e2e lane
Nov 14, 2026
45f93db
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in native dsh e2e lane
Nov 14, 2026
d67cc43
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in pi codex-responses WS …
Nov 14, 2026
c392237
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in pi package-native e2e …
Nov 14, 2026
974cd4c
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in fork-ccr-adoption suite
Nov 14, 2026
271abba
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in subagent-sessions e2e …
Nov 14, 2026
5d47196
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in dsh-persona e2e lane
Nov 14, 2026
1ca4087
fix(tests): pin BILI_STORAGE_JSON_WRITER=on in update-state e2e lane
Nov 14, 2026
5d3bac5
Merge upstream master and ci-fixes to refresh PR validation
Afloat16 Nov 14, 2026
b4ae654
Merge master into 2026-11-12_inline-null-response-bodies
Afloat16 Nov 14, 2026
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
7 changes: 4 additions & 3 deletions src/inline-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,14 @@ async function toInlineReq(input: FetchInput, init?: RequestInit): Promise<Inlin
return new InlineReq(parsed.pathname + parsed.search, method, headerMap, body);
}

function responseFrom(res: InlineRes): Response {
function responseFrom(res: InlineRes, method: string): Response {
const headers = new Headers();
for (const [k, v] of res.headHeaders) {
if (HOP_HEADERS.has(k.toLowerCase())) continue;
headers.append(k, v);
}
return new Response(res.bodyStream, { status: res.statusCode, statusText: res.statusMessage || undefined, headers });
const body = method === "HEAD" || res.statusCode === 204 || res.statusCode === 205 || res.statusCode === 304 ? null : res.bodyStream;
return new Response(body, { status: res.statusCode, statusText: res.statusMessage || undefined, headers });
}

function makeDispatcher(ctx: EngineContext): InlineEngine["dispatch"] {
Expand Down Expand Up @@ -374,7 +375,7 @@ function makeDispatcher(ctx: EngineContext): InlineEngine["dispatch"] {
res.once("close", detach);
}
}
return responseFrom(res);
return responseFrom(res, req.method);
};
}

Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/e2e-update-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
83 changes: 83 additions & 0 deletions tests/inline-null-body.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { after, test } from "node:test";
import assert from "node:assert/strict";
import http from "node:http";
import { once } from "node:events";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import type { AddressInfo } from "node:net";

// Hermetic storage BEFORE anything store-touching loads (same pattern as
// inline-streaming.test.ts): the engine boot below creates config + sqlite
// state, which must not land in a developer's real XDG dirs.
const STATE_ROOT = fs.mkdtempSync(path.join(os.tmpdir(), "bili-inline-null-body-state-"));
const DATA_ROOT = fs.mkdtempSync(path.join(os.tmpdir(), "bili-inline-null-body-data-"));
const CONFIG_ROOT = fs.mkdtempSync(path.join(os.tmpdir(), "bili-inline-null-body-config-"));
const PREV_STATE = process.env.XDG_STATE_HOME;
const PREV_DATA = process.env.XDG_DATA_HOME;
const PREV_CONFIG = process.env.XDG_CONFIG_HOME;
process.env.XDG_STATE_HOME = STATE_ROOT;
process.env.XDG_DATA_HOME = DATA_ROOT;
process.env.XDG_CONFIG_HOME = CONFIG_ROOT;

const upstream = http.createServer((req, res) => {
req.resume();
req.on("end", () => {
const status = Number(req.url?.slice(1));
res.writeHead(status, { "content-type": "text/plain", "x-inline-test": "preserved" });
res.end(status === 200 || status === 201 ? "upstream content" : undefined);
});
});
upstream.listen(0, "127.0.0.1");
await once(upstream, "listening");
const origin = `http://127.0.0.1:${(upstream.address() as AddressInfo).port}`;
const ie = await import("../src/inline-engine.ts");

after(async () => {
upstream.closeAllConnections();
await new Promise<void>((resolve) => upstream.close(() => resolve()));
try {
const { flushAllSessions } = await import("../src/session.ts");
await flushAllSessions();
} catch { /* engine never booted in this run */ }
ie._resetInlineEngineForTest();
if (PREV_STATE === undefined) delete process.env.XDG_STATE_HOME;
else process.env.XDG_STATE_HOME = PREV_STATE;
if (PREV_DATA === undefined) delete process.env.XDG_DATA_HOME;
else process.env.XDG_DATA_HOME = PREV_DATA;
if (PREV_CONFIG === undefined) delete process.env.XDG_CONFIG_HOME;
else process.env.XDG_CONFIG_HOME = PREV_CONFIG;
fs.rmSync(STATE_ROOT, { recursive: true, force: true });
fs.rmSync(DATA_ROOT, { recursive: true, force: true });
fs.rmSync(CONFIG_ROOT, { recursive: true, force: true });
});

for (const status of [204, 205, 304]) {
test(`inline HTTP ${status} has a null Response body`, { timeout: 30_000 }, async () => {
const engine = await ie.getInlineEngine();
const response = await engine.dispatch(`${ie.INLINE_ORIGIN}/bili/${origin}/${status}`, {}, globalThis.fetch);
assert.equal(response.status, status);
assert.equal(response.body, null);
assert.equal(await response.text(), "");
assert.equal(response.headers.get("x-inline-test"), "preserved");
});
}

test("inline HEAD has a null body even when the status allows a GET body", { timeout: 30_000 }, async () => {
const engine = await ie.getInlineEngine();
const response = await engine.dispatch(`${ie.INLINE_ORIGIN}/bili/${origin}/200`, { method: "HEAD" }, globalThis.fetch);
assert.equal(response.status, 200);
assert.equal(response.body, null);
assert.equal(await response.text(), "");
assert.equal(response.headers.get("x-inline-test"), "preserved");
});

for (const status of [200, 201]) {
test(`inline GET ${status} keeps its readable response content`, { timeout: 30_000 }, async () => {
const engine = await ie.getInlineEngine();
const response = await engine.dispatch(`${ie.INLINE_ORIGIN}/bili/${origin}/${status}`, {}, globalThis.fetch);
assert.equal(response.status, status);
assert.ok(response.body);
assert.equal(await response.text(), "upstream content");
});
}
Loading