mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 09:30:22 +00:00
161 lines
5.1 KiB
TypeScript
161 lines
5.1 KiB
TypeScript
import "./reply.directive.directive-behavior.e2e-mocks.js";
|
|
import { beforeAll, describe, expect, it } from "vitest";
|
|
import { loadSessionStore } from "../config/sessions.js";
|
|
import {
|
|
installDirectiveBehaviorE2EHooks,
|
|
makeWhatsAppDirectiveConfig,
|
|
replyText,
|
|
sessionStorePath,
|
|
withTempHome,
|
|
} from "./reply.directive.directive-behavior.e2e-harness.js";
|
|
import { runEmbeddedPiAgentMock } from "./reply.directive.directive-behavior.e2e-mocks.js";
|
|
|
|
let getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig;
|
|
|
|
async function runThinkDirectiveAndGetText(home: string): Promise<string | undefined> {
|
|
const res = await getReplyFromConfig(
|
|
{ Body: "/think", From: "+1222", To: "+1222", CommandAuthorized: true },
|
|
{},
|
|
makeWhatsAppDirectiveConfig(home, {
|
|
model: "anthropic/claude-opus-4-6",
|
|
thinkingDefault: "high",
|
|
}),
|
|
);
|
|
return replyText(res);
|
|
}
|
|
|
|
describe("directive behavior", () => {
|
|
installDirectiveBehaviorE2EHooks();
|
|
|
|
beforeAll(async () => {
|
|
({ getReplyFromConfig } = await import("./reply.js"));
|
|
});
|
|
|
|
it("handles standalone verbose directives and persistence", async () => {
|
|
await withTempHome(async (home) => {
|
|
const storePath = sessionStorePath(home);
|
|
|
|
const enabledRes = await getReplyFromConfig(
|
|
{ Body: "/verbose on", From: "+1222", To: "+1222", CommandAuthorized: true },
|
|
{},
|
|
makeWhatsAppDirectiveConfig(home, { model: "anthropic/claude-opus-4-6" }),
|
|
);
|
|
expect(replyText(enabledRes)).toMatch(/^⚙️ Verbose logging enabled\./);
|
|
|
|
const disabledRes = await getReplyFromConfig(
|
|
{ Body: "/verbose off", From: "+1222", To: "+1222", CommandAuthorized: true },
|
|
{},
|
|
makeWhatsAppDirectiveConfig(
|
|
home,
|
|
{ model: "anthropic/claude-opus-4-6" },
|
|
{
|
|
session: { store: storePath },
|
|
},
|
|
),
|
|
);
|
|
|
|
const text = replyText(disabledRes);
|
|
expect(text).toMatch(/Verbose logging disabled\./);
|
|
const store = loadSessionStore(storePath);
|
|
const entry = Object.values(store)[0];
|
|
expect(entry?.verboseLevel).toBe("off");
|
|
expect(runEmbeddedPiAgentMock).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
it("covers think status", async () => {
|
|
await withTempHome(async (home) => {
|
|
const text = await runThinkDirectiveAndGetText(home);
|
|
expect(text).toContain("Current thinking level: high");
|
|
expect(text).toContain("Options: off, minimal, low, medium, high, adaptive.");
|
|
expect(runEmbeddedPiAgentMock).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
it("keeps reserved command aliases from matching after trimming", async () => {
|
|
await withTempHome(async (home) => {
|
|
const res = await getReplyFromConfig(
|
|
{
|
|
Body: "/help",
|
|
From: "+1222",
|
|
To: "+1222",
|
|
CommandAuthorized: true,
|
|
},
|
|
{},
|
|
makeWhatsAppDirectiveConfig(
|
|
home,
|
|
{
|
|
model: "anthropic/claude-opus-4-6",
|
|
models: {
|
|
"anthropic/claude-opus-4-6": { alias: " help " },
|
|
},
|
|
},
|
|
{ session: { store: sessionStorePath(home) } },
|
|
),
|
|
);
|
|
|
|
const text = replyText(res);
|
|
expect(text).toContain("Help");
|
|
expect(runEmbeddedPiAgentMock).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
it("reports invalid queue options and current queue settings", async () => {
|
|
await withTempHome(async (home) => {
|
|
const invalidRes = await getReplyFromConfig(
|
|
{
|
|
Body: "/queue collect debounce:bogus cap:zero drop:maybe",
|
|
From: "+1222",
|
|
To: "+1222",
|
|
CommandAuthorized: true,
|
|
},
|
|
{},
|
|
makeWhatsAppDirectiveConfig(
|
|
home,
|
|
{ model: "anthropic/claude-opus-4-6" },
|
|
{
|
|
session: { store: sessionStorePath(home) },
|
|
},
|
|
),
|
|
);
|
|
|
|
const invalidText = replyText(invalidRes);
|
|
expect(invalidText).toContain("Invalid debounce");
|
|
expect(invalidText).toContain("Invalid cap");
|
|
expect(invalidText).toContain("Invalid drop policy");
|
|
|
|
const currentRes = await getReplyFromConfig(
|
|
{
|
|
Body: "/queue",
|
|
From: "+1222",
|
|
To: "+1222",
|
|
Provider: "whatsapp",
|
|
CommandAuthorized: true,
|
|
},
|
|
{},
|
|
makeWhatsAppDirectiveConfig(
|
|
home,
|
|
{ model: "anthropic/claude-opus-4-6" },
|
|
{
|
|
messages: {
|
|
queue: {
|
|
mode: "collect",
|
|
debounceMs: 1500,
|
|
cap: 9,
|
|
drop: "summarize",
|
|
},
|
|
},
|
|
session: { store: sessionStorePath(home) },
|
|
},
|
|
),
|
|
);
|
|
|
|
const text = replyText(currentRes);
|
|
expect(text).toContain(
|
|
"Current queue settings: mode=collect, debounce=1500ms, cap=9, drop=summarize.",
|
|
);
|
|
expect(text).toContain(
|
|
"Options: modes steer, followup, collect, steer+backlog, interrupt; debounce:<ms|s|m>, cap:<n>, drop:old|new|summarize.",
|
|
);
|
|
expect(runEmbeddedPiAgentMock).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|