From d1ab85297262e552bedc2df8121d0dab261c1163 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 18 Feb 2026 03:37:53 +0000 Subject: [PATCH] test: extract shared e2e helpers for trigger handling and skills --- ...skills.agents-skills-directory.e2e.test.ts | 22 +----------------- src/agents/skills.compact-skill-paths.test.ts | 22 +----------------- src/agents/skills.test-helpers.ts | 23 +++++++++++++++++++ ...ed-sender-toggle-elevated-mode.e2e.test.ts | 12 +++------- ...ted-off-groups-without-mention.e2e.test.ts | 12 +++------- ...ed-directive-unapproved-sender.e2e.test.ts | 12 +++------- ...uth-profile-key-snippet-status.e2e.test.ts | 12 +++------- ....triggers.trigger-handling.test-harness.ts | 12 ++++++++++ 8 files changed, 49 insertions(+), 78 deletions(-) create mode 100644 src/agents/skills.test-helpers.ts diff --git a/src/agents/skills.agents-skills-directory.e2e.test.ts b/src/agents/skills.agents-skills-directory.e2e.test.ts index 78d862c4be..39cfead55a 100644 --- a/src/agents/skills.agents-skills-directory.e2e.test.ts +++ b/src/agents/skills.agents-skills-directory.e2e.test.ts @@ -3,27 +3,7 @@ import os from "node:os"; import path from "node:path"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { buildWorkspaceSkillsPrompt } from "./skills.js"; - -async function writeSkill(params: { - dir: string; - name: string; - description: string; - body?: string; -}) { - const { dir, name, description, body } = params; - await fs.mkdir(dir, { recursive: true }); - await fs.writeFile( - path.join(dir, "SKILL.md"), - `--- -name: ${name} -description: ${description} ---- - -${body ?? `# ${name}\n`} -`, - "utf-8", - ); -} +import { writeSkill } from "./skills.test-helpers.js"; function buildSkillsPrompt(workspaceDir: string, managedDir: string, bundledDir: string): string { return buildWorkspaceSkillsPrompt(workspaceDir, { diff --git a/src/agents/skills.compact-skill-paths.test.ts b/src/agents/skills.compact-skill-paths.test.ts index 74c284c95c..9d6423785d 100644 --- a/src/agents/skills.compact-skill-paths.test.ts +++ b/src/agents/skills.compact-skill-paths.test.ts @@ -3,27 +3,7 @@ import os from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; import { buildWorkspaceSkillsPrompt } from "./skills.js"; - -async function writeSkill(params: { - dir: string; - name: string; - description: string; - body?: string; -}) { - const { dir, name, description, body } = params; - await fs.mkdir(dir, { recursive: true }); - await fs.writeFile( - path.join(dir, "SKILL.md"), - `--- -name: ${name} -description: ${description} ---- - -${body ?? `# ${name}\n`} -`, - "utf-8", - ); -} +import { writeSkill } from "./skills.test-helpers.js"; describe("compactSkillPaths", () => { it("replaces home directory prefix with ~ in skill locations", async () => { diff --git a/src/agents/skills.test-helpers.ts b/src/agents/skills.test-helpers.ts new file mode 100644 index 0000000000..cb83086ac3 --- /dev/null +++ b/src/agents/skills.test-helpers.ts @@ -0,0 +1,23 @@ +import fs from "node:fs/promises"; +import path from "node:path"; + +export async function writeSkill(params: { + dir: string; + name: string; + description: string; + body?: string; +}) { + const { dir, name, description, body } = params; + await fs.mkdir(dir, { recursive: true }); + await fs.writeFile( + path.join(dir, "SKILL.md"), + `--- +name: ${name} +description: ${description} +--- + +${body ?? `# ${name}\n`} +`, + "utf-8", + ); +} diff --git a/src/auto-reply/reply.triggers.trigger-handling.allows-approved-sender-toggle-elevated-mode.e2e.test.ts b/src/auto-reply/reply.triggers.trigger-handling.allows-approved-sender-toggle-elevated-mode.e2e.test.ts index 35b30e0dc3..d053eed25f 100644 --- a/src/auto-reply/reply.triggers.trigger-handling.allows-approved-sender-toggle-elevated-mode.e2e.test.ts +++ b/src/auto-reply/reply.triggers.trigger-handling.allows-approved-sender-toggle-elevated-mode.e2e.test.ts @@ -3,27 +3,21 @@ import { beforeAll, describe, expect, it } from "vitest"; import { getRunEmbeddedPiAgentMock, installTriggerHandlingE2eTestHooks, + loadGetReplyFromConfig, MAIN_SESSION_KEY, makeWhatsAppElevatedCfg, + requireSessionStorePath, runDirectElevatedToggleAndLoadStore, withTempHome, } from "./reply.triggers.trigger-handling.test-harness.js"; let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig; beforeAll(async () => { - ({ getReplyFromConfig } = await import("./reply.js")); + getReplyFromConfig = await loadGetReplyFromConfig(); }); installTriggerHandlingE2eTestHooks(); -function requireSessionStorePath(cfg: { session?: { store?: string } }): string { - const storePath = cfg.session?.store; - if (!storePath) { - throw new Error("expected session store path"); - } - return storePath; -} - describe("trigger handling", () => { it("allows approved sender to toggle elevated mode", async () => { await withTempHome(async (home) => { diff --git a/src/auto-reply/reply.triggers.trigger-handling.allows-elevated-off-groups-without-mention.e2e.test.ts b/src/auto-reply/reply.triggers.trigger-handling.allows-elevated-off-groups-without-mention.e2e.test.ts index a46c4d4da8..a73f84aae9 100644 --- a/src/auto-reply/reply.triggers.trigger-handling.allows-elevated-off-groups-without-mention.e2e.test.ts +++ b/src/auto-reply/reply.triggers.trigger-handling.allows-elevated-off-groups-without-mention.e2e.test.ts @@ -3,27 +3,21 @@ import { beforeAll, describe, expect, it } from "vitest"; import { loadSessionStore } from "../config/sessions.js"; import { installTriggerHandlingE2eTestHooks, + loadGetReplyFromConfig, MAIN_SESSION_KEY, makeWhatsAppElevatedCfg, + requireSessionStorePath, runDirectElevatedToggleAndLoadStore, withTempHome, } from "./reply.triggers.trigger-handling.test-harness.js"; let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig; beforeAll(async () => { - ({ getReplyFromConfig } = await import("./reply.js")); + getReplyFromConfig = await loadGetReplyFromConfig(); }); installTriggerHandlingE2eTestHooks(); -function requireSessionStorePath(cfg: { session?: { store?: string } }): string { - const storePath = cfg.session?.store; - if (!storePath) { - throw new Error("expected session store path"); - } - return storePath; -} - describe("trigger handling", () => { it("allows elevated off in groups without mention", async () => { await withTempHome(async (home) => { diff --git a/src/auto-reply/reply.triggers.trigger-handling.ignores-inline-elevated-directive-unapproved-sender.e2e.test.ts b/src/auto-reply/reply.triggers.trigger-handling.ignores-inline-elevated-directive-unapproved-sender.e2e.test.ts index 4f5006a765..d0c80b74bd 100644 --- a/src/auto-reply/reply.triggers.trigger-handling.ignores-inline-elevated-directive-unapproved-sender.e2e.test.ts +++ b/src/auto-reply/reply.triggers.trigger-handling.ignores-inline-elevated-directive-unapproved-sender.e2e.test.ts @@ -5,27 +5,21 @@ import type { OpenClawConfig } from "../config/config.js"; import { getRunEmbeddedPiAgentMock, installTriggerHandlingE2eTestHooks, + loadGetReplyFromConfig, MAIN_SESSION_KEY, makeCfg, makeWhatsAppElevatedCfg, + requireSessionStorePath, withTempHome, } from "./reply.triggers.trigger-handling.test-harness.js"; let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig; beforeAll(async () => { - ({ getReplyFromConfig } = await import("./reply.js")); + getReplyFromConfig = await loadGetReplyFromConfig(); }); installTriggerHandlingE2eTestHooks(); -function requireSessionStorePath(cfg: { session?: { store?: string } }): string { - const storePath = cfg.session?.store; - if (!storePath) { - throw new Error("expected session store path"); - } - return storePath; -} - describe("trigger handling", () => { it("ignores inline elevated directive for unapproved sender", async () => { await withTempHome(async (home) => { diff --git a/src/auto-reply/reply.triggers.trigger-handling.reports-active-auth-profile-key-snippet-status.e2e.test.ts b/src/auto-reply/reply.triggers.trigger-handling.reports-active-auth-profile-key-snippet-status.e2e.test.ts index be8d82339b..8033ba4f5e 100644 --- a/src/auto-reply/reply.triggers.trigger-handling.reports-active-auth-profile-key-snippet-status.e2e.test.ts +++ b/src/auto-reply/reply.triggers.trigger-handling.reports-active-auth-profile-key-snippet-status.e2e.test.ts @@ -6,26 +6,20 @@ import { createBlockReplyCollector, getRunEmbeddedPiAgentMock, installTriggerHandlingE2eTestHooks, + loadGetReplyFromConfig, makeCfg, mockRunEmbeddedPiAgentOk, + requireSessionStorePath, withTempHome, } from "./reply.triggers.trigger-handling.test-harness.js"; let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig; beforeAll(async () => { - ({ getReplyFromConfig } = await import("./reply.js")); + getReplyFromConfig = await loadGetReplyFromConfig(); }); installTriggerHandlingE2eTestHooks(); -function requireSessionStorePath(cfg: { session?: { store?: string } }): string { - const storePath = cfg.session?.store; - if (!storePath) { - throw new Error("expected session store path"); - } - return storePath; -} - describe("trigger handling", () => { it("reports active auth profile and key snippet in status", async () => { await withTempHome(async (home) => { diff --git a/src/auto-reply/reply.triggers.trigger-handling.test-harness.ts b/src/auto-reply/reply.triggers.trigger-handling.test-harness.ts index ea03649292..f891acb51f 100644 --- a/src/auto-reply/reply.triggers.trigger-handling.test-harness.ts +++ b/src/auto-reply/reply.triggers.trigger-handling.test-harness.ts @@ -135,6 +135,18 @@ export function makeCfg(home: string): OpenClawConfig { } as OpenClawConfig; } +export async function loadGetReplyFromConfig() { + return (await import("./reply.js")).getReplyFromConfig; +} + +export function requireSessionStorePath(cfg: { session?: { store?: string } }): string { + const storePath = cfg.session?.store; + if (!storePath) { + throw new Error("expected session store path"); + } + return storePath; +} + export function makeWhatsAppElevatedCfg( home: string, opts?: { elevatedEnabled?: boolean; requireMentionInGroups?: boolean },