diff --git a/package-lock.json b/package-lock.json index 2ce6f14148..c5b10b01cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "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", @@ -36,7 +36,7 @@ "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" @@ -6848,9 +6848,9 @@ } }, "node_modules/node-forge": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.4.0.tgz", - "integrity": "sha512-LarFH0+6VfriEhqMMcLX2F7SwSXeWwnEAJEsYm5QKWchiVYVvJyV9v7UDvUv+w5HO23ZpQTXDv/GxdDdMyOuoQ==", + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.4.3.tgz", + "integrity": "sha512-P6wzfh6t70avmV8FrVEAd/36sOPJQ+hkaJVX1Laap9J/77m7M0eyozDvc8SwnDf4P7MP94gwbAAo0rg3YVXT+g==", "dev": true, "license": "(BSD-3-Clause OR GPL-2.0)", "engines": { @@ -8953,9 +8953,9 @@ } }, "node_modules/undici": { - "version": "7.29.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-7.29.0.tgz", - "integrity": "sha512-IDxfleLmmbSskfWSUATiN1nfn2rDuvnMOqb5CWR92iIfojA0Ud+ulOAAEQ57LPr9rWmsreUyf5lwyao+7GNNVw==", + "version": "7.30.2", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.30.2.tgz", + "integrity": "sha512-mLyPQnHwUxaM/rideoK/+KL8DaAJLRl4aBCfmX444aCSLnIaomqPLtNRe2jdCYcsk5wZzXrDIQC8ZeYNRAYyIA==", "dev": true, "license": "MIT", "engines": { diff --git a/package.json b/package.json index a8cb666aaa..f2c54bdbce 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "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", @@ -87,7 +87,7 @@ "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" diff --git a/tests/issue2419-dsh-skill-catalog.test.ts b/tests/issue2419-dsh-skill-catalog.test.ts index 601e06eaf8..9230d458c0 100644 --- a/tests/issue2419-dsh-skill-catalog.test.ts +++ b/tests/issue2419-dsh-skill-catalog.test.ts @@ -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); } diff --git a/tests/issue2446-dsh-mcp-catalog.test.ts b/tests/issue2446-dsh-mcp-catalog.test.ts index 3252ecee51..bea9440da8 100644 --- a/tests/issue2446-dsh-mcp-catalog.test.ts +++ b/tests/issue2446-dsh-mcp-catalog.test.ts @@ -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); } diff --git a/tests/issue2447-dsh-workspace-instructions.test.ts b/tests/issue2447-dsh-workspace-instructions.test.ts index b9221c50bd..43fafc21cf 100644 --- a/tests/issue2447-dsh-workspace-instructions.test.ts +++ b/tests/issue2447-dsh-workspace-instructions.test.ts @@ -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); } diff --git a/tests/issue2481-dsh-runtime-context.test.ts b/tests/issue2481-dsh-runtime-context.test.ts index 2710056884..54b98d51c5 100644 --- a/tests/issue2481-dsh-runtime-context.test.ts +++ b/tests/issue2481-dsh-runtime-context.test.ts @@ -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); } diff --git a/tests/issue2817-crosswire-persona-fold.test.ts b/tests/issue2817-crosswire-persona-fold.test.ts index e6e9379ae1..06b756713e 100644 --- a/tests/issue2817-crosswire-persona-fold.test.ts +++ b/tests/issue2817-crosswire-persona-fold.test.ts @@ -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++) { @@ -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 @@ -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 @@ -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(); diff --git a/tests/issue5403-watermark-fastpath.test.ts b/tests/issue5403-watermark-fastpath.test.ts index dce35597d2..9e454422f0 100644 --- a/tests/issue5403-watermark-fastpath.test.ts +++ b/tests/issue5403-watermark-fastpath.test.ts @@ -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). @@ -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`);