From 98f2ad56a6bd68d91e1e0cc4f988fd6ab8ec533b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 14 Feb 2026 23:45:34 +0000 Subject: [PATCH] refactor(test): reuse think directive fixtures --- ...ow-reasoning-capable-models-no.e2e.test.ts | 128 +++++++----------- 1 file changed, 52 insertions(+), 76 deletions(-) diff --git a/src/auto-reply/reply.directive.directive-behavior.defaults-think-low-reasoning-capable-models-no.e2e.test.ts b/src/auto-reply/reply.directive.directive-behavior.defaults-think-low-reasoning-capable-models-no.e2e.test.ts index 14d0459cd90..983ed0f1d8d 100644 --- a/src/auto-reply/reply.directive.directive-behavior.defaults-think-low-reasoning-capable-models-no.e2e.test.ts +++ b/src/auto-reply/reply.directive.directive-behavior.defaults-think-low-reasoning-capable-models-no.e2e.test.ts @@ -9,6 +9,54 @@ import { } from "./reply.directive.directive-behavior.e2e-harness.js"; import { getReplyFromConfig } from "./reply.js"; +function makeThinkConfig(home: string) { + return { + agents: { + defaults: { + model: "anthropic/claude-opus-4-5", + workspace: path.join(home, "openclaw"), + }, + }, + session: { store: path.join(home, "sessions.json") }, + } as const; +} + +function makeWhatsAppConfig(home: string) { + return { + agents: { + defaults: { + model: "anthropic/claude-opus-4-5", + workspace: path.join(home, "openclaw"), + }, + }, + channels: { whatsapp: { allowFrom: ["*"] } }, + session: { store: path.join(home, "sessions.json") }, + } as const; +} + +async function runReplyToCurrentCase(home: string, text: string) { + vi.mocked(runEmbeddedPiAgent).mockResolvedValue({ + payloads: [{ text }], + meta: { + durationMs: 5, + agentMeta: { sessionId: "s", provider: "p", model: "m" }, + }, + }); + + const res = await getReplyFromConfig( + { + Body: "ping", + From: "+1004", + To: "+2000", + MessageSid: "msg-123", + }, + {}, + makeWhatsAppConfig(home), + ); + + return Array.isArray(res) ? res[0] : res; +} + describe("directive behavior", () => { installDirectiveBehaviorE2EHooks(); @@ -26,15 +74,7 @@ describe("directive behavior", () => { const res = await getReplyFromConfig( { Body: "/think", From: "+1222", To: "+1222", CommandAuthorized: true }, {}, - { - agents: { - defaults: { - model: "anthropic/claude-opus-4-5", - workspace: path.join(home, "openclaw"), - }, - }, - session: { store: path.join(home, "sessions.json") }, - }, + makeThinkConfig(home), ); const text = Array.isArray(res) ? res[0]?.text : res?.text; @@ -57,15 +97,7 @@ describe("directive behavior", () => { const res = await getReplyFromConfig( { Body: "/think", From: "+1222", To: "+1222", CommandAuthorized: true }, {}, - { - agents: { - defaults: { - model: "anthropic/claude-opus-4-5", - workspace: path.join(home, "openclaw"), - }, - }, - session: { store: path.join(home, "sessions.json") }, - }, + makeThinkConfig(home), ); const text = Array.isArray(res) ? res[0]?.text : res?.text; @@ -76,70 +108,14 @@ describe("directive behavior", () => { }); it("strips reply tags and maps reply_to_current to MessageSid", async () => { await withTempHome(async (home) => { - vi.mocked(runEmbeddedPiAgent).mockResolvedValue({ - payloads: [{ text: "hello [[reply_to_current]]" }], - meta: { - durationMs: 5, - agentMeta: { sessionId: "s", provider: "p", model: "m" }, - }, - }); - - const res = await getReplyFromConfig( - { - Body: "ping", - From: "+1004", - To: "+2000", - MessageSid: "msg-123", - }, - {}, - { - agents: { - defaults: { - model: "anthropic/claude-opus-4-5", - workspace: path.join(home, "openclaw"), - }, - }, - channels: { whatsapp: { allowFrom: ["*"] } }, - session: { store: path.join(home, "sessions.json") }, - }, - ); - - const payload = Array.isArray(res) ? res[0] : res; + const payload = await runReplyToCurrentCase(home, "hello [[reply_to_current]]"); expect(payload?.text).toBe("hello"); expect(payload?.replyToId).toBe("msg-123"); }); }); it("strips reply tags with whitespace and maps reply_to_current to MessageSid", async () => { await withTempHome(async (home) => { - vi.mocked(runEmbeddedPiAgent).mockResolvedValue({ - payloads: [{ text: "hello [[ reply_to_current ]]" }], - meta: { - durationMs: 5, - agentMeta: { sessionId: "s", provider: "p", model: "m" }, - }, - }); - - const res = await getReplyFromConfig( - { - Body: "ping", - From: "+1004", - To: "+2000", - MessageSid: "msg-123", - }, - {}, - { - agents: { - defaults: { - model: "anthropic/claude-opus-4-5", - workspace: path.join(home, "openclaw"), - }, - }, - channels: { whatsapp: { allowFrom: ["*"] } }, - session: { store: path.join(home, "sessions.json") }, - }, - ); - - const payload = Array.isArray(res) ? res[0] : res; + const payload = await runReplyToCurrentCase(home, "hello [[ reply_to_current ]]"); expect(payload?.text).toBe("hello"); expect(payload?.replyToId).toBe("msg-123"); });