mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 21:01:43 +03:00
refactor(test): dedupe trigger greeting prompt cases
This commit is contained in:
+2
-39
@@ -1,10 +1,10 @@
|
|||||||
import { tmpdir } from "node:os";
|
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { beforeAll, describe, expect, it } from "vitest";
|
import { beforeAll, describe, expect, it } from "vitest";
|
||||||
import {
|
import {
|
||||||
getRunEmbeddedPiAgentMock,
|
getRunEmbeddedPiAgentMock,
|
||||||
installTriggerHandlingE2eTestHooks,
|
installTriggerHandlingE2eTestHooks,
|
||||||
makeCfg,
|
makeCfg,
|
||||||
|
runGreetingPromptForBareNewOrReset,
|
||||||
withTempHome,
|
withTempHome,
|
||||||
} from "./reply.triggers.trigger-handling.test-harness.js";
|
} from "./reply.triggers.trigger-handling.test-harness.js";
|
||||||
|
|
||||||
@@ -89,44 +89,7 @@ describe("trigger handling", () => {
|
|||||||
});
|
});
|
||||||
it("runs a greeting prompt for a bare /new", async () => {
|
it("runs a greeting prompt for a bare /new", async () => {
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
getRunEmbeddedPiAgentMock().mockResolvedValue({
|
await runGreetingPromptForBareNewOrReset({ home, body: "/new", getReplyFromConfig });
|
||||||
payloads: [{ text: "hello" }],
|
|
||||||
meta: {
|
|
||||||
durationMs: 1,
|
|
||||||
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await getReplyFromConfig(
|
|
||||||
{
|
|
||||||
Body: "/new",
|
|
||||||
From: "+1003",
|
|
||||||
To: "+2000",
|
|
||||||
CommandAuthorized: true,
|
|
||||||
},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
agents: {
|
|
||||||
defaults: {
|
|
||||||
model: "anthropic/claude-opus-4-5",
|
|
||||||
workspace: join(home, "openclaw"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
whatsapp: {
|
|
||||||
allowFrom: ["*"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
session: {
|
|
||||||
store: join(tmpdir(), `openclaw-session-test-${Date.now()}.json`),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
|
||||||
expect(text).toBe("hello");
|
|
||||||
expect(getRunEmbeddedPiAgentMock()).toHaveBeenCalledOnce();
|
|
||||||
const prompt = getRunEmbeddedPiAgentMock().mock.calls[0]?.[0]?.prompt ?? "";
|
|
||||||
expect(prompt).toContain("A new session was started via /new or /reset");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-38
@@ -4,6 +4,7 @@ import { beforeAll, describe, expect, it } from "vitest";
|
|||||||
import {
|
import {
|
||||||
getRunEmbeddedPiAgentMock,
|
getRunEmbeddedPiAgentMock,
|
||||||
installTriggerHandlingE2eTestHooks,
|
installTriggerHandlingE2eTestHooks,
|
||||||
|
runGreetingPromptForBareNewOrReset,
|
||||||
withTempHome,
|
withTempHome,
|
||||||
} from "./reply.triggers.trigger-handling.test-harness.js";
|
} from "./reply.triggers.trigger-handling.test-harness.js";
|
||||||
|
|
||||||
@@ -17,44 +18,7 @@ installTriggerHandlingE2eTestHooks();
|
|||||||
describe("trigger handling", () => {
|
describe("trigger handling", () => {
|
||||||
it("runs a greeting prompt for a bare /reset", async () => {
|
it("runs a greeting prompt for a bare /reset", async () => {
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
getRunEmbeddedPiAgentMock().mockResolvedValue({
|
await runGreetingPromptForBareNewOrReset({ home, body: "/reset", getReplyFromConfig });
|
||||||
payloads: [{ text: "hello" }],
|
|
||||||
meta: {
|
|
||||||
durationMs: 1,
|
|
||||||
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const res = await getReplyFromConfig(
|
|
||||||
{
|
|
||||||
Body: "/reset",
|
|
||||||
From: "+1003",
|
|
||||||
To: "+2000",
|
|
||||||
CommandAuthorized: true,
|
|
||||||
},
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
agents: {
|
|
||||||
defaults: {
|
|
||||||
model: "anthropic/claude-opus-4-5",
|
|
||||||
workspace: join(home, "openclaw"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
whatsapp: {
|
|
||||||
allowFrom: ["*"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
session: {
|
|
||||||
store: join(tmpdir(), `openclaw-session-test-${Date.now()}.json`),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
|
||||||
expect(text).toBe("hello");
|
|
||||||
expect(getRunEmbeddedPiAgentMock()).toHaveBeenCalledOnce();
|
|
||||||
const prompt = getRunEmbeddedPiAgentMock().mock.calls[0]?.[0]?.prompt ?? "";
|
|
||||||
expect(prompt).toContain("A new session was started via /new or /reset");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("does not reset for unauthorized /reset", async () => {
|
it("does not reset for unauthorized /reset", async () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { afterEach, vi } from "vitest";
|
import { afterEach, expect, vi } from "vitest";
|
||||||
import { withTempHome as withTempHomeBase } from "../../test/helpers/temp-home.js";
|
import { withTempHome as withTempHomeBase } from "../../test/helpers/temp-home.js";
|
||||||
|
|
||||||
// Avoid exporting vitest mock types (TS2742 under pnpm + d.ts emit).
|
// Avoid exporting vitest mock types (TS2742 under pnpm + d.ts emit).
|
||||||
@@ -133,6 +133,36 @@ export function makeCfg(home: string) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function runGreetingPromptForBareNewOrReset(params: {
|
||||||
|
home: string;
|
||||||
|
body: "/new" | "/reset";
|
||||||
|
getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig;
|
||||||
|
}) {
|
||||||
|
getRunEmbeddedPiAgentMock().mockResolvedValue({
|
||||||
|
payloads: [{ text: "hello" }],
|
||||||
|
meta: {
|
||||||
|
durationMs: 1,
|
||||||
|
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await params.getReplyFromConfig(
|
||||||
|
{
|
||||||
|
Body: params.body,
|
||||||
|
From: "+1003",
|
||||||
|
To: "+2000",
|
||||||
|
CommandAuthorized: true,
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
makeCfg(params.home),
|
||||||
|
);
|
||||||
|
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||||
|
expect(text).toBe("hello");
|
||||||
|
expect(getRunEmbeddedPiAgentMock()).toHaveBeenCalledOnce();
|
||||||
|
const prompt = getRunEmbeddedPiAgentMock().mock.calls[0]?.[0]?.prompt ?? "";
|
||||||
|
expect(prompt).toContain("A new session was started via /new or /reset");
|
||||||
|
}
|
||||||
|
|
||||||
export function installTriggerHandlingE2eTestHooks() {
|
export function installTriggerHandlingE2eTestHooks() {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
|
|||||||
Reference in New Issue
Block a user