Skip to content
Open
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
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@
"esbuild": "^0.27.0",
"fzstd": "0.1.1",
"jsonc-parser": "^3.3.1",
"node-forge": "^1.4.0",
"node-forge": "^1.4.1",
"prettier": "^3.3.0",
"semver": "7.8.5",
"tar": "^7.5.22",
"tsup": "^8.0.0",
"tsx": "^4.0.0",
"typebox": "^1.3.34",
"typescript": "^5.5.0",
"undici": "^7.29.0",
"undici": "^7.30.1",
"verdaccio": "^6.10.4",
"ws": "8.22.0",
"z3-solver": "^5.3.1"
Expand Down
28 changes: 17 additions & 11 deletions tests/issue2419-dsh-skill-catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,27 @@ test("session-level: the dsh lane stamps the guard onto the effective config", a
const rig = await startRig();
try {
const url = `http://127.0.0.1:${rig.proxyPort}/bili/http://127.0.0.1:${rig.upstreamPort}/v1/chat/completions`;
const r = await fetch(url, {
method: "POST",
headers: { "content-type": "application/json", "x-bili-plugin": "dsh", "x-bili-plugin-conversation": "i2419-stamp" },
body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: CATALOG_MSG }] }),
});
assert.equal(r.status, 200);
await r.text();
const s = peekSession("i2419-stamp");
assert.ok(s, "dsh session exists");
const headers = { "content-type": "application/json", "x-bili-plugin": "dsh", "x-bili-plugin-conversation": "i2419-stamp" };
// Turn 1 is a tool-less single-shot shape: the #5656 generic dsh
// single-shot sidecar gate diverts it onto the verbatim side lane
// (kernel no-touch — the declared residual), so no refs are assigned
// yet. No fold can happen before turn 2 (nothing compressible, no
// action surface), so protection landing on the first full-pipeline
// turn keeps the catalog safe against every possible fold.
const r1 = await fetch(url, { method: "POST", headers, body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: CATALOG_MSG }] }) });
assert.equal(r1.status, 200);
await r1.text();
assert.ok(peekSession("i2419-stamp"), "dsh session exists");
const r2 = await fetch(url, { method: "POST", headers, body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: CATALOG_MSG }, { role: "assistant", content: "ok" }, { role: "user", content: "Second turn after the catalog." }] }) });
assert.equal(r2.status, 200);
await r2.text();
// The stamped effective config (read by /__bili/plugin/tool) carries the
// guard — proven indirectly: the catalog got a BLOCKED ref, i.e. it was
// recognized as protected AT ASSIGNMENT TIME on the very first turn.
// recognized as protected AT ASSIGNMENT TIME on the first full-pipeline
// turn (turn 2 — turn 1 rides the #5656 side lane).
const sFull = getSession("i2419-stamp");
const catalogBlocked = Object.entries(sFull.state.messageRefs.byRaw).some(([, ref]) => ref === "BLOCKED");
assert.ok(catalogBlocked, "the catalog message must carry a BLOCKED ref (never advertised, never foldable)");
assert.ok(catalogBlocked, "the catalog message must carry a BLOCKED ref by the first full-pipeline turn (never advertised, never foldable)");
} finally {
await closeRig(rig);
}
Expand Down
28 changes: 17 additions & 11 deletions tests/issue2446-dsh-mcp-catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,27 @@ test("session-level: the dsh lane stamps the guard onto the effective config", a
const rig = await startRig();
try {
const url = `http://127.0.0.1:${rig.proxyPort}/bili/http://127.0.0.1:${rig.upstreamPort}/v1/chat/completions`;
const r = await fetch(url, {
method: "POST",
headers: { "content-type": "application/json", "x-bili-plugin": "dsh", "x-bili-plugin-conversation": "i2446-stamp" },
body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: MCP_MSG }] }),
});
assert.equal(r.status, 200);
await r.text();
const s = peekSession("i2446-stamp");
assert.ok(s, "dsh session exists");
const headers = { "content-type": "application/json", "x-bili-plugin": "dsh", "x-bili-plugin-conversation": "i2446-stamp" };
// Turn 1 is a tool-less single-shot shape: the #5656 generic dsh
// single-shot sidecar gate diverts it onto the verbatim side lane
// (kernel no-touch — the declared residual), so no refs are assigned
// yet. No fold can happen before turn 2 (nothing compressible, no
// action surface), so protection landing on the first full-pipeline
// turn keeps the catalog safe against every possible fold.
const r1 = await fetch(url, { method: "POST", headers, body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: MCP_MSG }] }) });
assert.equal(r1.status, 200);
await r1.text();
assert.ok(peekSession("i2446-stamp"), "dsh session exists");
const r2 = await fetch(url, { method: "POST", headers, body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: MCP_MSG }, { role: "assistant", content: "ok" }, { role: "user", content: "Second turn after the catalog." }] }) });
assert.equal(r2.status, 200);
await r2.text();
// The stamped effective config (read by /__bili/plugin/tool) carries the
// guard — proven indirectly: the catalog got a BLOCKED ref, i.e. it was
// recognized as protected AT ASSIGNMENT TIME on the very first turn.
// recognized as protected AT ASSIGNMENT TIME on the first full-pipeline
// turn (turn 2 — turn 1 rides the #5656 side lane).
const sFull = getSession("i2446-stamp");
const blockedRefs = Object.entries(sFull.state.messageRefs.byRaw).filter(([, ref]) => ref === "BLOCKED").length;
assert.ok(blockedRefs >= 1, "the catalog message must carry a BLOCKED ref (never advertised, never foldable)");
assert.ok(blockedRefs >= 1, "the catalog message must carry a BLOCKED ref by the first full-pipeline turn (never advertised, never foldable)");
} finally {
await closeRig(rig);
}
Expand Down
28 changes: 17 additions & 11 deletions tests/issue2447-dsh-workspace-instructions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,27 @@ test("session-level: the dsh lane stamps the guard onto the effective config", a
const rig = await startRig();
try {
const url = `http://127.0.0.1:${rig.proxyPort}/bili/http://127.0.0.1:${rig.upstreamPort}/v1/chat/completions`;
const r = await fetch(url, {
method: "POST",
headers: { "content-type": "application/json", "x-bili-plugin": "dsh", "x-bili-plugin-conversation": "i2447-stamp" },
body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: INSTR_MSG }] }),
});
assert.equal(r.status, 200);
await r.text();
const s = peekSession("i2447-stamp");
assert.ok(s, "dsh session exists");
const headers = { "content-type": "application/json", "x-bili-plugin": "dsh", "x-bili-plugin-conversation": "i2447-stamp" };
// Turn 1 is a tool-less single-shot shape: the #5656 generic dsh
// single-shot sidecar gate diverts it onto the verbatim side lane
// (kernel no-touch — the declared residual), so no refs are assigned
// yet. No fold can happen before turn 2 (nothing compressible, no
// action surface), so protection landing on the first full-pipeline
// turn keeps the baseline safe against every possible fold.
const r1 = await fetch(url, { method: "POST", headers, body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: INSTR_MSG }] }) });
assert.equal(r1.status, 200);
await r1.text();
assert.ok(peekSession("i2447-stamp"), "dsh session exists");
const r2 = await fetch(url, { method: "POST", headers, body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: INSTR_MSG }, { role: "assistant", content: "ok" }, { role: "user", content: "Second turn after the baseline." }] }) });
assert.equal(r2.status, 200);
await r2.text();
// The stamped effective config (read by /__bili/plugin/tool) carries the
// guard — proven indirectly: the baseline got a BLOCKED ref, i.e. it was
// recognized as protected AT ASSIGNMENT TIME on the very first turn.
// recognized as protected AT ASSIGNMENT TIME on the first full-pipeline
// turn (turn 2 — turn 1 rides the #5656 side lane).
const sFull = getSession("i2447-stamp");
const baselineBlocked = Object.entries(sFull.state.messageRefs.byRaw).some(([, ref]) => ref === "BLOCKED");
assert.ok(baselineBlocked, "the baseline message must carry a BLOCKED ref (never advertised, never foldable)");
assert.ok(baselineBlocked, "the baseline message must carry a BLOCKED ref by the first full-pipeline turn (never advertised, never foldable)");
} finally {
await closeRig(rig);
}
Expand Down
28 changes: 17 additions & 11 deletions tests/issue2481-dsh-runtime-context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,27 @@ test("session-level: the dsh lane stamps the guard onto the effective config", a
const rig = await startRig();
try {
const url = `http://127.0.0.1:${rig.proxyPort}/bili/http://127.0.0.1:${rig.upstreamPort}/v1/chat/completions`;
const r = await fetch(url, {
method: "POST",
headers: { "content-type": "application/json", "x-bili-plugin": "dsh", "x-bili-plugin-conversation": "i2481-stamp" },
body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: RT_MSG }] }),
});
assert.equal(r.status, 200);
await r.text();
const s = peekSession("i2481-stamp");
assert.ok(s, "dsh session exists");
const headers = { "content-type": "application/json", "x-bili-plugin": "dsh", "x-bili-plugin-conversation": "i2481-stamp" };
// Turn 1 is a tool-less single-shot shape: the #5656 generic dsh
// single-shot sidecar gate diverts it onto the verbatim side lane
// (kernel no-touch — the declared residual), so no refs are assigned
// yet. No fold can happen before turn 2 (nothing compressible, no
// action surface), so protection landing on the first full-pipeline
// turn keeps the snapshot safe against every possible fold.
const r1 = await fetch(url, { method: "POST", headers, body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: RT_MSG }] }) });
assert.equal(r1.status, 200);
await r1.text();
assert.ok(peekSession("i2481-stamp"), "dsh session exists");
const r2 = await fetch(url, { method: "POST", headers, body: JSON.stringify({ model: MODEL, max_tokens: 64_000, messages: [{ role: "system", content: MAIN_SYSTEM }, { role: "user", content: RT_MSG }, { role: "assistant", content: "ok" }, { role: "user", content: "Second turn after the snapshot." }] }) });
assert.equal(r2.status, 200);
await r2.text();
// The stamped effective config (read by /__bili/plugin/tool) carries the
// guard — proven indirectly: the snapshot got a BLOCKED ref, i.e. it was
// recognized as protected AT ASSIGNMENT TIME on the very first turn.
// recognized as protected AT ASSIGNMENT TIME on the first full-pipeline
// turn (turn 2 — turn 1 rides the #5656 side lane).
const sFull = getSession("i2481-stamp");
const blockedRefs = Object.entries(sFull.state.messageRefs.byRaw).filter(([, ref]) => ref === "BLOCKED").length;
assert.ok(blockedRefs >= 1, "the snapshot message must carry a BLOCKED ref (never advertised, never foldable)");
assert.ok(blockedRefs >= 1, "the snapshot message must carry a BLOCKED ref by the first full-pipeline turn (never advertised, never foldable)");
} finally {
await closeRig(rig);
}
Expand Down
12 changes: 8 additions & 4 deletions tests/issue2817-crosswire-persona-fold.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ test("issue #2817 regression: identified persona, PLUGIN-MODE fold on openai lan
assert.ok(blocksAfterFold.length >= 1, "plugin-mode fold landed on the openai lane");
const foldedBody = bodies.openai[bodies.openai.length - 1]!;
assert.ok(!foldedBody.includes(EARLY_FILLER_TAG), "covered head content folded away on the openai lane");
assert.equal(main.stats.requests, 9);
// #5656 residual: turn 1 is a tool-less single-shot shape and rides the
// verbatim side lane (kernel no-touch), so stats.requests counts from
// turn 2 — eight counted turns after nine wire turns. The fork teeth
// below are unchanged: a fork would still show as a missing increment.
assert.equal(main.stats.requests, 8);

// Turns 10-12: openai lane stays folded.
for (let t = 10; t <= 12; t++) {
Expand All @@ -202,7 +206,7 @@ test("issue #2817 regression: identified persona, PLUGIN-MODE fold on openai lan
await resp.text();
hist.push({ role: "assistant", text: `Reply about chapter ${t}: acknowledged. ` + FILLER(t, 0.2) });
}
assert.equal(getSession(CONV).stats.requests, 12, "12 openai turns all rode the raw key");
assert.equal(getSession(CONV).stats.requests, 11, "12 openai turns rode the raw key (turn 1 rides the #5656 side lane, uncounted)");
assert.deepEqual(getSession(CONV).state.blocks.map((b) => b.blockId), blocksAfterFold, "fold blocks stable on the openai lane");

// Phase B — THE INCIDENT: cross-wire model switch. The whole conversation
Expand All @@ -226,7 +230,7 @@ test("issue #2817 regression: identified persona, PLUGIN-MODE fold on openai lan

// 1) THE incident assertion: the switch turn rides the RAW persona key.
// Pre-fix it forked — stats.requests stays at 12 and a `|sub:` husk serves.
assert.equal(getSession(CONV).stats.requests, 13, `switch turn must keep riding the RAW persona key (fork would leave it at 12: incident #2817)`);
assert.equal(getSession(CONV).stats.requests, 12, `switch turn must keep riding the RAW persona key (fork would leave it at 11: incident #2817)`);
// 2) Fold attachment on the switched wire: covered early content ABSENT.
assert.equal((switchBody.match(new RegExp(EARLY_FILLER_TAG, "g")) ?? []).length, 0, "covered early content must NOT replay raw on the switch turn (incident blast)");
// 3) The upstream blast metric: the covered volume must actually stay
Expand Down Expand Up @@ -254,7 +258,7 @@ test("issue #2817 regression: identified persona, PLUGIN-MODE fold on openai lan
const r14Text = await r14.text();
if (r14.status !== 200) assert.fail(`anthropic turn 14: ${r14.status}: ${r14Text.slice(0, 200)}`);
const followUp = bodies.anthropic[bodies.anthropic.length - 1]!;
assert.equal(getSession(CONV).stats.requests, 14, "follow-up turn still rides the raw key");
assert.equal(getSession(CONV).stats.requests, 13, "follow-up turn still rides the raw key");
assert.equal((followUp.match(new RegExp(EARLY_FILLER_TAG, "g")) ?? []).length, 0, "covered content stays folded on the follow-up turn");
} finally {
proxy.close();
Expand Down
11 changes: 10 additions & 1 deletion tests/issue5403-watermark-fastpath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// 1. OUTBOUND byte equality: every upstream body is byte-identical modulo
// kernel time="…" attributes (the sanctioned normalization clause).
// 2. Watermark headers never leak past the proxy to the model endpoint.
// 3. Phase B stamps accumulate per measured wire length; Phase A emits none.
// 3. Phase B stamps accumulate per measured wire length (turn 0 rides the
// #5656 verbatim side lane, unstamped in both phases); Phase A emits none.
// 4. RESIDENCY BAND: after steady state the fastpath proxy pins only the
// tail window while the legacy proxy pins the full working copy
// (/__bili/memory breakdown.lastMessages < 0.8× legacy).
Expand Down Expand Up @@ -204,6 +205,14 @@ test("#5418 A/B byte-equality + residency band (hermetic dual-proxy)", async ()
ra.forEach((s, i) => assert.equal(s, null, `A stamp ${i}: legacy path must not stamp`));
const corpus = scriptTurns();
for (let i = 0; i < 8; i++) {
if (i === 0) {
// #5656 residual: turn 0 is a tool-less single-shot shape, so it
// rides the verbatim side lane (kernel no-touch) in BOTH phases
// — the gate predates this feature and ignores the rollout env —
// and the side lane neither scans nor stamps.
assert.equal(rb[i], null, `B stamp ${i}: side lane must not stamp`);
continue;
}
// The stamp is THIS TURN'S measured wire total (full resends grow
// monotonically by one appended element).
assert.equal(rb[i], corpus[i].messages.length, `B stamp ${i}: measured wire total`);
Expand Down
Loading