mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
test: move inline directive stripping coverage
This commit is contained in:
@@ -9,7 +9,6 @@ import {
|
||||
makeWhatsAppDirectiveConfig,
|
||||
mockEmbeddedTextResult,
|
||||
replyText,
|
||||
replyTexts,
|
||||
sessionStorePath,
|
||||
withTempHome,
|
||||
} from "./reply.directive.directive-behavior.e2e-harness.js";
|
||||
@@ -22,16 +21,6 @@ import { handleDirectiveOnly } from "./reply/directive-handling.impl.js";
|
||||
import type { HandleDirectiveOnlyParams } from "./reply/directive-handling.params.js";
|
||||
import { parseInlineDirectives } from "./reply/directive-handling.parse.js";
|
||||
|
||||
function makeDefaultModelConfig(home: string) {
|
||||
return makeWhatsAppDirectiveConfig(home, {
|
||||
model: { primary: "anthropic/claude-opus-4-6" },
|
||||
models: {
|
||||
"anthropic/claude-opus-4-6": {},
|
||||
"openai/gpt-4.1-mini": {},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function runReplyToCurrentCase(home: string, text: string) {
|
||||
runEmbeddedPiAgentMock.mockResolvedValue(makeEmbeddedTextResult(text));
|
||||
|
||||
@@ -213,43 +202,6 @@ describe("directive behavior", () => {
|
||||
expect(result.sessionEntry.providerOverride).toBe("openai");
|
||||
expect(runEmbeddedPiAgentMock).not.toHaveBeenCalled();
|
||||
});
|
||||
it("ignores inline /model and /think directives while still running agent content", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
mockEmbeddedTextResult("done");
|
||||
|
||||
const inlineModelRes = await getReplyFromConfig(
|
||||
{
|
||||
Body: "please sync /model openai/gpt-4.1-mini now",
|
||||
From: "+1004",
|
||||
To: "+2000",
|
||||
},
|
||||
{},
|
||||
makeDefaultModelConfig(home),
|
||||
);
|
||||
|
||||
const texts = replyTexts(inlineModelRes);
|
||||
expect(texts).toContain("done");
|
||||
expect(runEmbeddedPiAgentMock).toHaveBeenCalledOnce();
|
||||
const call = runEmbeddedPiAgentMock.mock.calls[0]?.[0];
|
||||
expect(call?.provider).toBe("anthropic");
|
||||
expect(call?.model).toBe("claude-opus-4-6");
|
||||
runEmbeddedPiAgentMock.mockClear();
|
||||
|
||||
mockEmbeddedTextResult("done");
|
||||
const inlineThinkRes = await getReplyFromConfig(
|
||||
{
|
||||
Body: "please sync /think:high now",
|
||||
From: "+1004",
|
||||
To: "+2000",
|
||||
},
|
||||
{},
|
||||
makeWhatsAppDirectiveConfig(home, { model: { primary: "anthropic/claude-opus-4-6" } }),
|
||||
);
|
||||
|
||||
expect(replyTexts(inlineThinkRes)).toContain("done");
|
||||
expect(runEmbeddedPiAgentMock).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
it("persists /reasoning off on discord even when model defaults reasoning on", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const storePath = sessionStorePath(home);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
extractThinkDirective,
|
||||
extractVerboseDirective,
|
||||
} from "./reply.js";
|
||||
import { parseInlineDirectives } from "./reply/directive-handling.parse.js";
|
||||
import { extractFastDirective, extractStatusDirective } from "./reply/directives.js";
|
||||
|
||||
describe("directive parsing", () => {
|
||||
@@ -164,6 +165,20 @@ describe("directive parsing", () => {
|
||||
expect(res.cleaned).toBe("please now");
|
||||
});
|
||||
|
||||
it("strips inline /model and /think directives while keeping user text", () => {
|
||||
expect(parseInlineDirectives("please sync /model openai/gpt-4.1-mini now")).toMatchObject({
|
||||
cleaned: "please sync now",
|
||||
hasModelDirective: true,
|
||||
rawModelDirective: "openai/gpt-4.1-mini",
|
||||
});
|
||||
|
||||
expect(parseInlineDirectives("please sync /think:high now")).toMatchObject({
|
||||
cleaned: "please sync now",
|
||||
hasThinkDirective: true,
|
||||
thinkLevel: "high",
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves spacing when stripping think directives before paths", () => {
|
||||
const res = extractThinkDirective("thats not /think high/tmp/hello");
|
||||
expect(res.hasDirective).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user