From bcaa195c52d8bdd00701be40d4ff2c56003bf8c0 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 7 Apr 2026 15:15:54 +0100 Subject: [PATCH] fix(test): restore agentic and runtime shard coverage --- .../openclaw-tools.image-generation.test.ts | 76 +++++++++---------- vitest.process.config.ts | 12 ++- vitest.runtime-config.config.ts | 12 ++- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/src/agents/openclaw-tools.image-generation.test.ts b/src/agents/openclaw-tools.image-generation.test.ts index 9bbba1ee733..9e2fe5a986c 100644 --- a/src/agents/openclaw-tools.image-generation.test.ts +++ b/src/agents/openclaw-tools.image-generation.test.ts @@ -1,56 +1,45 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; -import * as imageGenerationRuntime from "../image-generation/runtime.js"; import { createOpenClawTools } from "./openclaw-tools.js"; +const hoisted = vi.hoisted(() => ({ + createImageGenerateTool: vi.fn(), +})); + vi.mock("../plugins/tools.js", () => ({ resolvePluginTools: () => [], copyPluginToolMeta: () => undefined, getPluginToolMeta: () => undefined, })); +vi.mock("./tools/image-generate-tool.js", () => ({ + createImageGenerateTool: (...args: unknown[]) => hoisted.createImageGenerateTool(...args), +})); + function asConfig(value: unknown): OpenClawConfig { return value as OpenClawConfig; } -function stubImageGenerationProviders() { - vi.spyOn(imageGenerationRuntime, "listRuntimeImageGenerationProviders").mockReturnValue([ - { - id: "openai", - defaultModel: "gpt-image-1", - models: ["gpt-image-1"], - capabilities: { - generate: { - supportsSize: true, - }, - edit: { - enabled: false, - }, - geometry: { - sizes: ["1024x1024"], - }, - }, - generateImage: vi.fn(async () => { - throw new Error("not used"); - }), - }, - ]); -} - describe("openclaw tools image generation registration", () => { - beforeEach(() => { - vi.stubEnv("OPENAI_API_KEY", ""); - vi.stubEnv("OPENAI_API_KEYS", ""); - vi.stubEnv("GEMINI_API_KEY", ""); - vi.stubEnv("GEMINI_API_KEYS", ""); - }); - afterEach(() => { - vi.restoreAllMocks(); - vi.unstubAllEnvs(); + hoisted.createImageGenerateTool.mockReset(); }); it("registers image_generate when image-generation config is present", () => { + hoisted.createImageGenerateTool.mockReturnValue({ + name: "image_generate", + description: "image fixture tool", + parameters: { + type: "object", + properties: {}, + }, + async execute() { + return { + content: [{ type: "text", text: "ok" }], + }; + }, + }); + const tools = createOpenClawTools({ config: asConfig({ agents: { @@ -68,8 +57,19 @@ describe("openclaw tools image generation registration", () => { }); it("registers image_generate when a compatible provider has env-backed auth", () => { - stubImageGenerationProviders(); - vi.stubEnv("OPENAI_API_KEY", "openai-test"); + hoisted.createImageGenerateTool.mockReturnValue({ + name: "image_generate", + description: "image fixture tool", + parameters: { + type: "object", + properties: {}, + }, + async execute() { + return { + content: [{ type: "text", text: "ok" }], + }; + }, + }); const tools = createOpenClawTools({ config: asConfig({}), @@ -80,7 +80,7 @@ describe("openclaw tools image generation registration", () => { }); it("omits image_generate when config is absent and no compatible provider auth exists", () => { - stubImageGenerationProviders(); + hoisted.createImageGenerateTool.mockReturnValue(null); const tools = createOpenClawTools({ config: asConfig({}), diff --git a/vitest.process.config.ts b/vitest.process.config.ts index 71928575ff4..f10414d6d1d 100644 --- a/vitest.process.config.ts +++ b/vitest.process.config.ts @@ -1,13 +1,23 @@ import { createScopedVitestConfig } from "./vitest.scoped-config.ts"; export function createProcessVitestConfig(env?: Record) { - return createScopedVitestConfig(["src/process/**/*.test.ts"], { + const config = createScopedVitestConfig(["src/process/**/*.test.ts"], { dir: "src", env, includeOpenClawRuntimeSetup: false, name: "process", passWithNoTests: true, }); + return { + ...config, + test: { + ...config.test, + sequence: { + ...config.test?.sequence, + groupOrder: 2, + }, + }, + }; } export default createProcessVitestConfig(); diff --git a/vitest.runtime-config.config.ts b/vitest.runtime-config.config.ts index 67931797ec1..c93c0140611 100644 --- a/vitest.runtime-config.config.ts +++ b/vitest.runtime-config.config.ts @@ -1,13 +1,23 @@ import { createScopedVitestConfig } from "./vitest.scoped-config.ts"; export function createRuntimeConfigVitestConfig(env?: Record) { - return createScopedVitestConfig(["src/config/**/*.test.ts"], { + const config = createScopedVitestConfig(["src/config/**/*.test.ts"], { dir: "src", env, includeOpenClawRuntimeSetup: false, name: "runtime-config", passWithNoTests: true, }); + return { + ...config, + test: { + ...config.test, + sequence: { + ...config.test?.sequence, + groupOrder: 3, + }, + }, + }; } export default createRuntimeConfigVitestConfig();