test: extract shared e2e helpers for trigger handling and skills

This commit is contained in:
Peter Steinberger
2026-02-18 03:37:53 +00:00
parent b099171db5
commit d1ab852972
8 changed files with 49 additions and 78 deletions

View File

@@ -3,27 +3,7 @@ import os from "node:os";
import path from "node:path"; import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { buildWorkspaceSkillsPrompt } from "./skills.js"; import { buildWorkspaceSkillsPrompt } from "./skills.js";
import { writeSkill } from "./skills.test-helpers.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",
);
}
function buildSkillsPrompt(workspaceDir: string, managedDir: string, bundledDir: string): string { function buildSkillsPrompt(workspaceDir: string, managedDir: string, bundledDir: string): string {
return buildWorkspaceSkillsPrompt(workspaceDir, { return buildWorkspaceSkillsPrompt(workspaceDir, {

View File

@@ -3,27 +3,7 @@ import os from "node:os";
import path from "node:path"; import path from "node:path";
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { buildWorkspaceSkillsPrompt } from "./skills.js"; import { buildWorkspaceSkillsPrompt } from "./skills.js";
import { writeSkill } from "./skills.test-helpers.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",
);
}
describe("compactSkillPaths", () => { describe("compactSkillPaths", () => {
it("replaces home directory prefix with ~ in skill locations", async () => { it("replaces home directory prefix with ~ in skill locations", async () => {

View File

@@ -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",
);
}

View File

@@ -3,27 +3,21 @@ import { beforeAll, describe, expect, it } from "vitest";
import { import {
getRunEmbeddedPiAgentMock, getRunEmbeddedPiAgentMock,
installTriggerHandlingE2eTestHooks, installTriggerHandlingE2eTestHooks,
loadGetReplyFromConfig,
MAIN_SESSION_KEY, MAIN_SESSION_KEY,
makeWhatsAppElevatedCfg, makeWhatsAppElevatedCfg,
requireSessionStorePath,
runDirectElevatedToggleAndLoadStore, runDirectElevatedToggleAndLoadStore,
withTempHome, withTempHome,
} from "./reply.triggers.trigger-handling.test-harness.js"; } from "./reply.triggers.trigger-handling.test-harness.js";
let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig; let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig;
beforeAll(async () => { beforeAll(async () => {
({ getReplyFromConfig } = await import("./reply.js")); getReplyFromConfig = await loadGetReplyFromConfig();
}); });
installTriggerHandlingE2eTestHooks(); 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", () => { describe("trigger handling", () => {
it("allows approved sender to toggle elevated mode", async () => { it("allows approved sender to toggle elevated mode", async () => {
await withTempHome(async (home) => { await withTempHome(async (home) => {

View File

@@ -3,27 +3,21 @@ import { beforeAll, describe, expect, it } from "vitest";
import { loadSessionStore } from "../config/sessions.js"; import { loadSessionStore } from "../config/sessions.js";
import { import {
installTriggerHandlingE2eTestHooks, installTriggerHandlingE2eTestHooks,
loadGetReplyFromConfig,
MAIN_SESSION_KEY, MAIN_SESSION_KEY,
makeWhatsAppElevatedCfg, makeWhatsAppElevatedCfg,
requireSessionStorePath,
runDirectElevatedToggleAndLoadStore, runDirectElevatedToggleAndLoadStore,
withTempHome, withTempHome,
} from "./reply.triggers.trigger-handling.test-harness.js"; } from "./reply.triggers.trigger-handling.test-harness.js";
let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig; let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig;
beforeAll(async () => { beforeAll(async () => {
({ getReplyFromConfig } = await import("./reply.js")); getReplyFromConfig = await loadGetReplyFromConfig();
}); });
installTriggerHandlingE2eTestHooks(); 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", () => { describe("trigger handling", () => {
it("allows elevated off in groups without mention", async () => { it("allows elevated off in groups without mention", async () => {
await withTempHome(async (home) => { await withTempHome(async (home) => {

View File

@@ -5,27 +5,21 @@ import type { OpenClawConfig } from "../config/config.js";
import { import {
getRunEmbeddedPiAgentMock, getRunEmbeddedPiAgentMock,
installTriggerHandlingE2eTestHooks, installTriggerHandlingE2eTestHooks,
loadGetReplyFromConfig,
MAIN_SESSION_KEY, MAIN_SESSION_KEY,
makeCfg, makeCfg,
makeWhatsAppElevatedCfg, makeWhatsAppElevatedCfg,
requireSessionStorePath,
withTempHome, withTempHome,
} from "./reply.triggers.trigger-handling.test-harness.js"; } from "./reply.triggers.trigger-handling.test-harness.js";
let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig; let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig;
beforeAll(async () => { beforeAll(async () => {
({ getReplyFromConfig } = await import("./reply.js")); getReplyFromConfig = await loadGetReplyFromConfig();
}); });
installTriggerHandlingE2eTestHooks(); 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", () => { describe("trigger handling", () => {
it("ignores inline elevated directive for unapproved sender", async () => { it("ignores inline elevated directive for unapproved sender", async () => {
await withTempHome(async (home) => { await withTempHome(async (home) => {

View File

@@ -6,26 +6,20 @@ import {
createBlockReplyCollector, createBlockReplyCollector,
getRunEmbeddedPiAgentMock, getRunEmbeddedPiAgentMock,
installTriggerHandlingE2eTestHooks, installTriggerHandlingE2eTestHooks,
loadGetReplyFromConfig,
makeCfg, makeCfg,
mockRunEmbeddedPiAgentOk, mockRunEmbeddedPiAgentOk,
requireSessionStorePath,
withTempHome, withTempHome,
} from "./reply.triggers.trigger-handling.test-harness.js"; } from "./reply.triggers.trigger-handling.test-harness.js";
let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig; let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig;
beforeAll(async () => { beforeAll(async () => {
({ getReplyFromConfig } = await import("./reply.js")); getReplyFromConfig = await loadGetReplyFromConfig();
}); });
installTriggerHandlingE2eTestHooks(); 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", () => { describe("trigger handling", () => {
it("reports active auth profile and key snippet in status", async () => { it("reports active auth profile and key snippet in status", async () => {
await withTempHome(async (home) => { await withTempHome(async (home) => {

View File

@@ -135,6 +135,18 @@ export function makeCfg(home: string): OpenClawConfig {
} as 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( export function makeWhatsAppElevatedCfg(
home: string, home: string,
opts?: { elevatedEnabled?: boolean; requireMentionInGroups?: boolean }, opts?: { elevatedEnabled?: boolean; requireMentionInGroups?: boolean },