refactor(agent): dedupe harness and command workflows

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:09 +00:00
parent 04892ee230
commit f717a13039
204 changed files with 7366 additions and 11540 deletions

View File

@@ -62,6 +62,22 @@ function createMinimaxImageConfig(): OpenClawConfig {
};
}
async function expectImageToolExecOk(
tool: {
execute: (toolCallId: string, input: { prompt: string; image: string }) => Promise<unknown>;
},
image: string,
) {
await expect(
tool.execute("t1", {
prompt: "Describe the image.",
image,
}),
).resolves.toMatchObject({
content: [{ type: "text", text: "ok" }],
});
}
describe("image tool implicit imageModel config", () => {
const priorFetch = global.fetch;
@@ -220,14 +236,7 @@ describe("image tool implicit imageModel config", () => {
throw new Error("expected image tool");
}
await expect(
withWorkspace.execute("t1", {
prompt: "Describe the image.",
image: imagePath,
}),
).resolves.toMatchObject({
content: [{ type: "text", text: "ok" }],
});
await expectImageToolExecOk(withWorkspace, imagePath);
expect(fetch).toHaveBeenCalledTimes(1);
} finally {
@@ -250,14 +259,7 @@ describe("image tool implicit imageModel config", () => {
throw new Error("expected image tool");
}
await expect(
tool.execute("t1", {
prompt: "Describe the image.",
image: imagePath,
}),
).resolves.toMatchObject({
content: [{ type: "text", text: "ok" }],
});
await expectImageToolExecOk(tool, imagePath);
expect(fetch).toHaveBeenCalledTimes(1);
} finally {
@@ -383,15 +385,15 @@ describe("image tool MiniMax VLM routing", () => {
global.fetch = priorFetch;
});
it("calls /v1/coding_plan/vlm for minimax image models", async () => {
async function createMinimaxVlmFixture(baseResp: { status_code: number; status_msg: string }) {
const fetch = vi.fn().mockResolvedValue({
ok: true,
status: 200,
statusText: "OK",
headers: new Headers(),
json: async () => ({
content: "ok",
base_resp: { status_code: 0, status_msg: "" },
content: baseResp.status_code === 0 ? "ok" : "",
base_resp: baseResp,
}),
});
// @ts-expect-error partial global
@@ -407,6 +409,11 @@ describe("image tool MiniMax VLM routing", () => {
if (!tool) {
throw new Error("expected image tool");
}
return { fetch, tool };
}
it("calls /v1/coding_plan/vlm for minimax image models", async () => {
const { fetch, tool } = await createMinimaxVlmFixture({ status_code: 0, status_msg: "" });
const res = await tool.execute("t1", {
prompt: "Describe the image.",
@@ -428,29 +435,7 @@ describe("image tool MiniMax VLM routing", () => {
});
it("surfaces MiniMax API errors from /v1/coding_plan/vlm", async () => {
const fetch = vi.fn().mockResolvedValue({
ok: true,
status: 200,
statusText: "OK",
headers: new Headers(),
json: async () => ({
content: "",
base_resp: { status_code: 1004, status_msg: "bad key" },
}),
});
// @ts-expect-error partial global
global.fetch = fetch;
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-minimax-vlm-"));
vi.stubEnv("MINIMAX_API_KEY", "minimax-test");
const cfg: OpenClawConfig = {
agents: { defaults: { model: { primary: "minimax/MiniMax-M2.1" } } },
};
const tool = createImageTool({ config: cfg, agentDir });
expect(tool).not.toBeNull();
if (!tool) {
throw new Error("expected image tool");
}
const { tool } = await createMinimaxVlmFixture({ status_code: 1004, status_msg: "bad key" });
await expect(
tool.execute("t1", {