From 434e3d81f3ef90c329a09eed412b2e91ba1bd5a6 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 20 Apr 2026 19:27:04 +0100 Subject: [PATCH] test: share session conversation fallback fixtures --- ...sion-conversation.bundled-fallback.test.ts | 105 ++++++------------ 1 file changed, 36 insertions(+), 69 deletions(-) diff --git a/src/channels/plugins/session-conversation.bundled-fallback.test.ts b/src/channels/plugins/session-conversation.bundled-fallback.test.ts index e3c2e3850d2..73a8fd693e1 100644 --- a/src/channels/plugins/session-conversation.bundled-fallback.test.ts +++ b/src/channels/plugins/session-conversation.bundled-fallback.test.ts @@ -32,6 +32,37 @@ vi.mock("../../plugin-sdk/facade-runtime.js", async () => { import { resolveSessionConversationRef, resolveSessionThreadInfo } from "./session-conversation.js"; +type ResolveSessionConversation = NonNullable; + +function enableBundledFallback( + dirName: string, + resolveSessionConversation: ResolveSessionConversation, +) { + fallbackState.activeDirName = dirName; + fallbackState.resolveSessionConversation = resolveSessionConversation; + setRuntimeConfigSnapshot({ + plugins: { + entries: { + [dirName]: { + enabled: true, + }, + }, + }, + }); +} + +function enableThreadedFallback() { + enableBundledFallback("mock-threaded", ({ rawId }) => { + const [conversationId, threadId] = rawId.split(":topic:"); + return { + id: conversationId, + threadId, + baseConversationId: conversationId, + parentConversationCandidates: [conversationId], + }; + }); +} + describe("session conversation bundled fallback", () => { beforeEach(() => { fallbackState.activeDirName = null; @@ -45,25 +76,7 @@ describe("session conversation bundled fallback", () => { }); it("delegates pre-bootstrap thread parsing to the active bundled channel plugin", () => { - fallbackState.activeDirName = "mock-threaded"; - fallbackState.resolveSessionConversation = ({ rawId }) => { - const [conversationId, threadId] = rawId.split(":topic:"); - return { - id: conversationId, - threadId, - baseConversationId: conversationId, - parentConversationCandidates: [conversationId], - }; - }; - setRuntimeConfigSnapshot({ - plugins: { - entries: { - "mock-threaded": { - enabled: true, - }, - }, - }, - }); + enableThreadedFallback(); expect(resolveSessionConversationRef("agent:main:mock-threaded:group:room:topic:42")).toEqual({ channel: "mock-threaded", @@ -78,25 +91,7 @@ describe("session conversation bundled fallback", () => { }); it("can skip bundled fallback probing for hot generic-only callers", () => { - fallbackState.activeDirName = "mock-threaded"; - fallbackState.resolveSessionConversation = ({ rawId }) => { - const [conversationId, threadId] = rawId.split(":topic:"); - return { - id: conversationId, - threadId, - baseConversationId: conversationId, - parentConversationCandidates: [conversationId], - }; - }; - setRuntimeConfigSnapshot({ - plugins: { - entries: { - "mock-threaded": { - enabled: true, - }, - }, - }, - }); + enableThreadedFallback(); expect( resolveSessionConversationRef("agent:main:mock-threaded:group:room:topic:42", { @@ -123,21 +118,11 @@ describe("session conversation bundled fallback", () => { }); it("uses explicit bundled parent candidates before registry bootstrap", () => { - fallbackState.activeDirName = "mock-parent"; - fallbackState.resolveSessionConversation = ({ rawId }) => ({ + enableBundledFallback("mock-parent", ({ rawId }) => ({ id: rawId, baseConversationId: "room", parentConversationCandidates: ["room:topic:root", "room"], - }); - setRuntimeConfigSnapshot({ - plugins: { - entries: { - "mock-parent": { - enabled: true, - }, - }, - }, - }); + })); expect( resolveSessionConversationRef("agent:main:mock-parent:group:room:topic:root:sender:user"), @@ -154,25 +139,7 @@ describe("session conversation bundled fallback", () => { }); it("reuses the bundled fallback loader result across repeated calls", () => { - fallbackState.activeDirName = "mock-threaded"; - fallbackState.resolveSessionConversation = ({ rawId }) => { - const [conversationId, threadId] = rawId.split(":topic:"); - return { - id: conversationId, - threadId, - baseConversationId: conversationId, - parentConversationCandidates: [conversationId], - }; - }; - setRuntimeConfigSnapshot({ - plugins: { - entries: { - "mock-threaded": { - enabled: true, - }, - }, - }, - }); + enableThreadedFallback(); expect(resolveSessionConversationRef("agent:main:mock-threaded:group:room:topic:42")).toEqual( expect.objectContaining({