From 94cf4f2e8b6e975835e9395bc04909d0a9f8109d Mon Sep 17 00:00:00 2001 From: ci-check Date: Tue, 17 Nov 2026 01:54:26 +0800 Subject: [PATCH] fix(dsh): read the status wire field `fallback`, not the internal `viaFallback` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DSH client's ownership gate (sessionOurs) read o.viaFallback from the /__bili/plugin/status response, but the server has always sent fallback (src/plugin.ts handlePluginStatus). The field never matched, so sessionOurs was a constant true and the gate never fired: a host session with no bili lane entry (seeded forks, pre-lane sessions, fresh sessions) rendered another, unrelated session's handoff in its Context tab. Fix the client to read the real wire field (o.fallback). Works against every server version (all send fallback); no server change, no redundant field. The existing regression test simulated the server sending viaFallback: true — a response the server never emits — so it passed without ever exercising the gate. It now simulates the real wire field (fallback: true), and a new negative-direction case pins that a fallback resolving to OUR OWN session is still framed (#3617 both directions). Closes #6968 --- src/agent/dsh-native-client.ts | 5 ++++- tests/dsh-settings-ui.test.ts | 32 +++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/agent/dsh-native-client.ts b/src/agent/dsh-native-client.ts index f4a074173c..9adedbe3c1 100644 --- a/src/agent/dsh-native-client.ts +++ b/src/agent/dsh-native-client.ts @@ -205,7 +205,10 @@ function parseCtxStatus(raw: unknown): CtxStatus | undefined { panelPresent: o.panel !== undefined, sessionId: typeof o.sessionId === "string" && o.sessionId.length > 0 ? o.sessionId : null, conversationId: typeof o.conversationId === "string" && o.conversationId.length > 0 ? o.conversationId : null, - viaFallback: o.viaFallback === true, + // #6968: the wire key is `fallback` (src/plugin.ts handlePluginStatus), + // not `viaFallback` — the internal variable name. Reading the wrong + // key made sessionOurs a constant true and the ownership gate dead. + viaFallback: o.fallback === true, }; } diff --git a/tests/dsh-settings-ui.test.ts b/tests/dsh-settings-ui.test.ts index 6c8ac47268..55972a41b9 100644 --- a/tests/dsh-settings-ui.test.ts +++ b/tests/dsh-settings-ui.test.ts @@ -1963,7 +1963,10 @@ test("#3862: conversation.view Context tab embeds the web UI session page, polls fetch: async (url: string) => { const u = String(url); if (u.endsWith("/bili/origin")) return { ok: true, json: async () => ({ origin: ORIGIN }) }; - if (u.endsWith(statusUrl)) return { ok: true, json: async () => ({ ok: true, panel: "x", sessionId: "sub-session-id", conversationId: "some-other-conversation", viaFallback: true }) }; + // #6968: the REAL wire key is `fallback` (src/plugin.ts), not + // `viaFallback` — the pre-fix test simulated a response the + // server never sends, so the ownership gate was never exercised. + if (u.endsWith(statusUrl)) return { ok: true, json: async () => ({ ok: true, panel: "x", sessionId: "sub-session-id", conversationId: "some-other-conversation", fallback: true }) }; if (u.endsWith("/__bili/?embed=1")) return htmlOk(); throw new Error(`unexpected fetch: ${u}`); }, @@ -1977,6 +1980,33 @@ test("#3862: conversation.view Context tab embeds the web UI session page, polls assert.equal(findTag(hm.component() as ElementNode, "iframe"), undefined, "no frame for someone else's session"); hm.runCleanups(); } + { + // #6968 negative direction (#3617): a fallback that resolves to OUR OWN + // session (conversationId === hostSessionId) is trusted — the ownership + // gate must NOT fire. The gate triggers on FOREIGN fallback rows only; + // pinning this direction stops a future over-tight gate from refusing + // our own fallback-resolved session (the pre-first-request case the + // fallback exists for). + const om = await mountClient({ + __BILI__: { origin: ORIGIN }, + open: (_url: string) => {}, + fetch: async (url: string) => { + const u = String(url); + if (u.endsWith("/bili/origin")) return { ok: true, json: async () => ({ origin: ORIGIN }) }; + if (u.endsWith(statusUrl)) return { ok: true, json: async () => ({ ok: true, panel: "x", sessionId: "own-session-id", conversationId: HOST_CONVERSATION_ID, fallback: true }) }; + if (u.endsWith("/__bili/?embed=1")) return htmlOk(); + throw new Error(`unexpected fetch: ${u}`); + }, + ...noopTimers, + }, "conversation.view", { sessionId: HOST_CONVERSATION_ID }); + om.resetHooks(); + om.component(); + await tick(); + const ot = textOf(om.component() as ElementNode); + assert.ok(!ot.includes("暂无上下文数据"), "own-session fallback is framed, not the not-yet hint"); + assert.ok(findTag(om.component() as ElementNode, "iframe") !== undefined, "frame for our own fallback-resolved session"); + om.runCleanups(); + } { // The URL answered but not with our contract shape: degrade honestly. const st = await subMount({ something: "else" });