mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 00:54:33 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import fs from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, expect, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
@@ -134,6 +135,60 @@ export function makeCfg(home: string): OpenClawConfig {
|
||||
} as OpenClawConfig;
|
||||
}
|
||||
|
||||
export function makeWhatsAppElevatedCfg(
|
||||
home: string,
|
||||
opts?: { elevatedEnabled?: boolean; requireMentionInGroups?: boolean },
|
||||
): OpenClawConfig {
|
||||
const cfg = makeCfg(home);
|
||||
cfg.channels ??= {};
|
||||
cfg.channels.whatsapp = {
|
||||
...cfg.channels.whatsapp,
|
||||
allowFrom: ["+1000"],
|
||||
};
|
||||
if (opts?.requireMentionInGroups !== undefined) {
|
||||
cfg.channels.whatsapp.groups = { "*": { requireMention: opts.requireMentionInGroups } };
|
||||
}
|
||||
|
||||
cfg.tools = {
|
||||
...cfg.tools,
|
||||
elevated: {
|
||||
allowFrom: { whatsapp: ["+1000"] },
|
||||
...(opts?.elevatedEnabled === false ? { enabled: false } : {}),
|
||||
},
|
||||
};
|
||||
return cfg;
|
||||
}
|
||||
|
||||
export async function runDirectElevatedToggleAndLoadStore(params: {
|
||||
cfg: OpenClawConfig;
|
||||
getReplyFromConfig: typeof import("./reply.js").getReplyFromConfig;
|
||||
body?: string;
|
||||
}): Promise<{
|
||||
text: string | undefined;
|
||||
store: Record<string, { elevatedLevel?: string }>;
|
||||
}> {
|
||||
const res = await params.getReplyFromConfig(
|
||||
{
|
||||
Body: params.body ?? "/elevated on",
|
||||
From: "+1000",
|
||||
To: "+2000",
|
||||
Provider: "whatsapp",
|
||||
SenderE164: "+1000",
|
||||
CommandAuthorized: true,
|
||||
},
|
||||
{},
|
||||
params.cfg,
|
||||
);
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
const storePath = params.cfg.session?.store;
|
||||
if (!storePath) {
|
||||
throw new Error("session.store is required in test config");
|
||||
}
|
||||
const storeRaw = await fs.readFile(storePath, "utf-8");
|
||||
const store = JSON.parse(storeRaw) as Record<string, { elevatedLevel?: string }>;
|
||||
return { text, store };
|
||||
}
|
||||
|
||||
export async function runGreetingPromptForBareNewOrReset(params: {
|
||||
home: string;
|
||||
body: "/new" | "/reset";
|
||||
@@ -169,3 +224,27 @@ export function installTriggerHandlingE2eTestHooks() {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
}
|
||||
|
||||
export function mockRunEmbeddedPiAgentOk(text = "ok"): AnyMock {
|
||||
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
|
||||
runEmbeddedPiAgentMock.mockResolvedValue({
|
||||
payloads: [{ text }],
|
||||
meta: {
|
||||
durationMs: 1,
|
||||
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
||||
},
|
||||
});
|
||||
return runEmbeddedPiAgentMock;
|
||||
}
|
||||
|
||||
export function createBlockReplyCollector() {
|
||||
const blockReplies: Array<{ text?: string }> = [];
|
||||
return {
|
||||
blockReplies,
|
||||
handlers: {
|
||||
onBlockReply: async (payload: { text?: string }) => {
|
||||
blockReplies.push(payload);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user