mirror of https://github.com/openclaw/openclaw.git
refactor: share agent tool fixture helpers
This commit is contained in:
parent
6e3f0f9fcb
commit
88de4769de
|
|
@ -60,6 +60,13 @@ async function runRoleMutation(params: {
|
|||
await params.mutate({ guildId, userId, roleId });
|
||||
}
|
||||
|
||||
function readChannelPermissionTarget(params: Record<string, unknown>) {
|
||||
return {
|
||||
channelId: readStringParam(params, "channelId", { required: true }),
|
||||
targetId: readStringParam(params, "targetId", { required: true }),
|
||||
};
|
||||
}
|
||||
|
||||
export async function handleDiscordGuildAction(
|
||||
action: string,
|
||||
params: Record<string, unknown>,
|
||||
|
|
@ -453,10 +460,7 @@ export async function handleDiscordGuildAction(
|
|||
if (!isActionEnabled("channels")) {
|
||||
throw new Error("Discord channel management is disabled.");
|
||||
}
|
||||
const channelId = readStringParam(params, "channelId", {
|
||||
required: true,
|
||||
});
|
||||
const targetId = readStringParam(params, "targetId", { required: true });
|
||||
const { channelId, targetId } = readChannelPermissionTarget(params);
|
||||
const targetTypeRaw = readStringParam(params, "targetType", {
|
||||
required: true,
|
||||
});
|
||||
|
|
@ -489,10 +493,7 @@ export async function handleDiscordGuildAction(
|
|||
if (!isActionEnabled("channels")) {
|
||||
throw new Error("Discord channel management is disabled.");
|
||||
}
|
||||
const channelId = readStringParam(params, "channelId", {
|
||||
required: true,
|
||||
});
|
||||
const targetId = readStringParam(params, "targetId", { required: true });
|
||||
const { channelId, targetId } = readChannelPermissionTarget(params);
|
||||
if (accountId) {
|
||||
await removeChannelPermissionDiscord(channelId, targetId, { accountId });
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -48,6 +48,19 @@ async function withTempWorkspacePng(
|
|||
}
|
||||
}
|
||||
|
||||
function registerImageToolEnvReset(priorFetch: typeof global.fetch, keys: string[]) {
|
||||
beforeEach(() => {
|
||||
for (const key of keys) {
|
||||
vi.stubEnv(key, "");
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
global.fetch = priorFetch;
|
||||
});
|
||||
}
|
||||
|
||||
function stubMinimaxOkFetch() {
|
||||
const fetch = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
|
|
@ -229,24 +242,18 @@ function findSchemaUnionKeywords(schema: unknown, path = "root"): string[] {
|
|||
|
||||
describe("image tool implicit imageModel config", () => {
|
||||
const priorFetch = global.fetch;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.stubEnv("OPENAI_API_KEY", "");
|
||||
vi.stubEnv("ANTHROPIC_API_KEY", "");
|
||||
vi.stubEnv("ANTHROPIC_OAUTH_TOKEN", "");
|
||||
vi.stubEnv("MINIMAX_API_KEY", "");
|
||||
vi.stubEnv("ZAI_API_KEY", "");
|
||||
vi.stubEnv("Z_AI_API_KEY", "");
|
||||
registerImageToolEnvReset(priorFetch, [
|
||||
"OPENAI_API_KEY",
|
||||
"ANTHROPIC_API_KEY",
|
||||
"ANTHROPIC_OAUTH_TOKEN",
|
||||
"MINIMAX_API_KEY",
|
||||
"ZAI_API_KEY",
|
||||
"Z_AI_API_KEY",
|
||||
// Avoid implicit Copilot provider discovery hitting the network in tests.
|
||||
vi.stubEnv("COPILOT_GITHUB_TOKEN", "");
|
||||
vi.stubEnv("GH_TOKEN", "");
|
||||
vi.stubEnv("GITHUB_TOKEN", "");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
global.fetch = priorFetch;
|
||||
});
|
||||
"COPILOT_GITHUB_TOKEN",
|
||||
"GH_TOKEN",
|
||||
"GITHUB_TOKEN",
|
||||
]);
|
||||
|
||||
it("stays disabled without auth when no pairing is possible", async () => {
|
||||
await withTempAgentDir(async (agentDir) => {
|
||||
|
|
@ -683,18 +690,12 @@ describe("image tool MiniMax VLM routing", () => {
|
|||
const pngB64 =
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/woAAn8B9FD5fHAAAAAASUVORK5CYII=";
|
||||
const priorFetch = global.fetch;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.stubEnv("MINIMAX_API_KEY", "");
|
||||
vi.stubEnv("COPILOT_GITHUB_TOKEN", "");
|
||||
vi.stubEnv("GH_TOKEN", "");
|
||||
vi.stubEnv("GITHUB_TOKEN", "");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
global.fetch = priorFetch;
|
||||
});
|
||||
registerImageToolEnvReset(priorFetch, [
|
||||
"MINIMAX_API_KEY",
|
||||
"COPILOT_GITHUB_TOKEN",
|
||||
"GH_TOKEN",
|
||||
"GITHUB_TOKEN",
|
||||
]);
|
||||
|
||||
async function createMinimaxVlmFixture(baseResp: { status_code: number; status_msg: string }) {
|
||||
const fetch = stubMinimaxFetch(baseResp, baseResp.status_code === 0 ? "ok" : "");
|
||||
|
|
|
|||
Loading…
Reference in New Issue