mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 21:58:26 +00:00
refactor(test): reuse think directive fixtures
This commit is contained in:
@@ -9,6 +9,54 @@ import {
|
|||||||
} from "./reply.directive.directive-behavior.e2e-harness.js";
|
} from "./reply.directive.directive-behavior.e2e-harness.js";
|
||||||
import { getReplyFromConfig } from "./reply.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", () => {
|
describe("directive behavior", () => {
|
||||||
installDirectiveBehaviorE2EHooks();
|
installDirectiveBehaviorE2EHooks();
|
||||||
|
|
||||||
@@ -26,15 +74,7 @@ describe("directive behavior", () => {
|
|||||||
const res = await getReplyFromConfig(
|
const res = await getReplyFromConfig(
|
||||||
{ Body: "/think", From: "+1222", To: "+1222", CommandAuthorized: true },
|
{ Body: "/think", From: "+1222", To: "+1222", CommandAuthorized: true },
|
||||||
{},
|
{},
|
||||||
{
|
makeThinkConfig(home),
|
||||||
agents: {
|
|
||||||
defaults: {
|
|
||||||
model: "anthropic/claude-opus-4-5",
|
|
||||||
workspace: path.join(home, "openclaw"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
session: { store: path.join(home, "sessions.json") },
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||||
@@ -57,15 +97,7 @@ describe("directive behavior", () => {
|
|||||||
const res = await getReplyFromConfig(
|
const res = await getReplyFromConfig(
|
||||||
{ Body: "/think", From: "+1222", To: "+1222", CommandAuthorized: true },
|
{ Body: "/think", From: "+1222", To: "+1222", CommandAuthorized: true },
|
||||||
{},
|
{},
|
||||||
{
|
makeThinkConfig(home),
|
||||||
agents: {
|
|
||||||
defaults: {
|
|
||||||
model: "anthropic/claude-opus-4-5",
|
|
||||||
workspace: path.join(home, "openclaw"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
session: { store: path.join(home, "sessions.json") },
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
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 () => {
|
it("strips reply tags and maps reply_to_current to MessageSid", async () => {
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
const payload = await runReplyToCurrentCase(home, "hello [[reply_to_current]]");
|
||||||
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;
|
|
||||||
expect(payload?.text).toBe("hello");
|
expect(payload?.text).toBe("hello");
|
||||||
expect(payload?.replyToId).toBe("msg-123");
|
expect(payload?.replyToId).toBe("msg-123");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("strips reply tags with whitespace and maps reply_to_current to MessageSid", async () => {
|
it("strips reply tags with whitespace and maps reply_to_current to MessageSid", async () => {
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
const payload = await runReplyToCurrentCase(home, "hello [[ reply_to_current ]]");
|
||||||
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;
|
|
||||||
expect(payload?.text).toBe("hello");
|
expect(payload?.text).toBe("hello");
|
||||||
expect(payload?.replyToId).toBe("msg-123");
|
expect(payload?.replyToId).toBe("msg-123");
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user