mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-21 16:41:56 +00:00
test: merge elevated status directive shards
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
import "./reply.directive.directive-behavior.e2e-mocks.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { loadSessionStore } from "../config/sessions.js";
|
||||
import {
|
||||
AUTHORIZED_WHATSAPP_COMMAND,
|
||||
installDirectiveBehaviorE2EHooks,
|
||||
makeElevatedDirectiveConfig,
|
||||
replyText,
|
||||
makeRestrictedElevatedDisabledConfig,
|
||||
runEmbeddedPiAgent,
|
||||
sessionStorePath,
|
||||
withTempHome,
|
||||
} from "./reply.directive.directive-behavior.e2e-harness.js";
|
||||
import { getReplyFromConfig } from "./reply.js";
|
||||
|
||||
async function runAuthorizedCommand(home: string, body: string) {
|
||||
return getReplyFromConfig(
|
||||
{
|
||||
...AUTHORIZED_WHATSAPP_COMMAND,
|
||||
Body: body,
|
||||
},
|
||||
{},
|
||||
makeElevatedDirectiveConfig(home),
|
||||
);
|
||||
}
|
||||
|
||||
describe("directive behavior", () => {
|
||||
installDirectiveBehaviorE2EHooks();
|
||||
|
||||
it("shows current elevated level as off after toggling it off", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
await runAuthorizedCommand(home, "/elevated off");
|
||||
const res = await runAuthorizedCommand(home, "/elevated");
|
||||
const text = replyText(res);
|
||||
expect(text).toContain("Current elevated level: off");
|
||||
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
it("can toggle elevated off then back on (status reflects on)", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const storePath = sessionStorePath(home);
|
||||
await runAuthorizedCommand(home, "/elevated off");
|
||||
await runAuthorizedCommand(home, "/elevated on");
|
||||
const res = await runAuthorizedCommand(home, "/status");
|
||||
const text = replyText(res);
|
||||
const optionsLine = text?.split("\n").find((line) => line.trim().startsWith("⚙️"));
|
||||
expect(optionsLine).toBeTruthy();
|
||||
expect(optionsLine).toContain("elevated");
|
||||
|
||||
const store = loadSessionStore(storePath);
|
||||
expect(store["agent:main:main"]?.elevatedLevel).toBe("on");
|
||||
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
it("rejects per-agent elevated when disabled", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const res = await getReplyFromConfig(
|
||||
{
|
||||
Body: "/elevated on",
|
||||
From: "+1222",
|
||||
To: "+1222",
|
||||
Provider: "whatsapp",
|
||||
SenderE164: "+1222",
|
||||
SessionKey: "agent:restricted:main",
|
||||
CommandAuthorized: true,
|
||||
},
|
||||
{},
|
||||
makeRestrictedElevatedDisabledConfig(home) as unknown as OpenClawConfig,
|
||||
);
|
||||
|
||||
const text = replyText(res);
|
||||
expect(text).toContain("agents.list[].tools.elevated.enabled");
|
||||
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,13 @@
|
||||
import "./reply.directive.directive-behavior.e2e-mocks.js";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { loadSessionStore } from "../config/sessions.js";
|
||||
import {
|
||||
AUTHORIZED_WHATSAPP_COMMAND,
|
||||
assertElevatedOffStatusReply,
|
||||
installDirectiveBehaviorE2EHooks,
|
||||
makeElevatedDirectiveConfig,
|
||||
makeRestrictedElevatedDisabledConfig,
|
||||
makeWhatsAppDirectiveConfig,
|
||||
replyText,
|
||||
runEmbeddedPiAgent,
|
||||
@@ -111,6 +113,52 @@ describe("directive behavior", () => {
|
||||
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
it("shows current elevated level as off after toggling it off", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
await runElevatedCommand(home, "/elevated off");
|
||||
const res = await runElevatedCommand(home, "/elevated");
|
||||
const text = replyText(res);
|
||||
expect(text).toContain("Current elevated level: off");
|
||||
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
it("can toggle elevated off then back on (status reflects on)", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const storePath = sessionStorePath(home);
|
||||
await runElevatedCommand(home, "/elevated off");
|
||||
await runElevatedCommand(home, "/elevated on");
|
||||
const res = await runElevatedCommand(home, "/status");
|
||||
const text = replyText(res);
|
||||
const optionsLine = text?.split("\n").find((line) => line.trim().startsWith("⚙️"));
|
||||
expect(optionsLine).toBeTruthy();
|
||||
expect(optionsLine).toContain("elevated");
|
||||
|
||||
const store = loadSessionStore(storePath);
|
||||
expect(store["agent:main:main"]?.elevatedLevel).toBe("on");
|
||||
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
it("rejects per-agent elevated when disabled", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
const res = await getReplyFromConfig(
|
||||
{
|
||||
Body: "/elevated on",
|
||||
From: "+1222",
|
||||
To: "+1222",
|
||||
Provider: "whatsapp",
|
||||
SenderE164: "+1222",
|
||||
SessionKey: "agent:restricted:main",
|
||||
CommandAuthorized: true,
|
||||
},
|
||||
{},
|
||||
makeRestrictedElevatedDisabledConfig(home) as unknown as OpenClawConfig,
|
||||
);
|
||||
|
||||
const text = replyText(res);
|
||||
expect(text).toContain("agents.list[].tools.elevated.enabled");
|
||||
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
it("strips inline elevated directives from the user text (does not persist session override)", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
||||
|
||||
Reference in New Issue
Block a user