mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:30:42 +00:00
fix(qa): use exported runner sdk seam
This commit is contained in:
@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
const loadQaRuntimeModule = vi.hoisted(() => vi.fn());
|
||||
const defaultQaRuntimeModelForMode = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/qa-runtime", () => ({
|
||||
vi.mock("openclaw/plugin-sdk/qa-runner-runtime", () => ({
|
||||
loadQaRuntimeModule,
|
||||
}));
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { loadQaRuntimeModule } from "openclaw/plugin-sdk/qa-runtime";
|
||||
import { loadQaRuntimeModule } from "openclaw/plugin-sdk/qa-runner-runtime";
|
||||
import { normalizeQaProviderMode, type QaProviderModeInput } from "../../run-config.js";
|
||||
|
||||
export type ResolvedMatrixQaModels = {
|
||||
|
||||
@@ -4,7 +4,7 @@ import path from "node:path";
|
||||
import { setTimeout as sleep } from "node:timers/promises";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
||||
import { loadQaRuntimeModule } from "openclaw/plugin-sdk/qa-runtime";
|
||||
import { loadQaRuntimeModule } from "openclaw/plugin-sdk/qa-runner-runtime";
|
||||
import type { QaReportCheck } from "../../report.js";
|
||||
import { renderQaMarkdownReport } from "../../report.js";
|
||||
import { type QaProviderModeInput } from "../../run-config.js";
|
||||
|
||||
@@ -32,6 +32,32 @@ describe("plugin-sdk qa-runner-runtime", () => {
|
||||
expect(tryLoadActivatedBundledPluginPublicSurfaceModuleSync).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("loads the qa-lab runtime public surface through the public runner seam", async () => {
|
||||
const runtimeSurface = {
|
||||
defaultQaRuntimeModelForMode: vi.fn(),
|
||||
startQaLiveLaneGateway: vi.fn(),
|
||||
};
|
||||
loadBundledPluginPublicSurfaceModuleSync.mockReturnValue(runtimeSurface);
|
||||
|
||||
const module = await import("./qa-runner-runtime.js");
|
||||
|
||||
expect(module.loadQaRuntimeModule()).toBe(runtimeSurface);
|
||||
expect(loadBundledPluginPublicSurfaceModuleSync).toHaveBeenCalledWith({
|
||||
dirName: "qa-lab",
|
||||
artifactBasename: "runtime-api.js",
|
||||
});
|
||||
});
|
||||
|
||||
it("reports the qa runtime as unavailable when the qa-lab surface is missing", async () => {
|
||||
loadBundledPluginPublicSurfaceModuleSync.mockImplementation(() => {
|
||||
throw new Error("Unable to resolve bundled plugin public surface qa-lab/runtime-api.js");
|
||||
});
|
||||
|
||||
const module = await import("./qa-runner-runtime.js");
|
||||
|
||||
expect(module.isQaRuntimeAvailable()).toBe(false);
|
||||
});
|
||||
|
||||
it("returns activated runner registrations declared in plugin manifests", async () => {
|
||||
const register = vi.fn((qa: Command) => qa);
|
||||
loadPluginManifestRegistry.mockReturnValue({
|
||||
|
||||
@@ -15,6 +15,17 @@ type QaRunnerRuntimeSurface = {
|
||||
qaRunnerCliRegistrations?: readonly QaRunnerCliRegistration[];
|
||||
};
|
||||
|
||||
type QaRuntimeSurface = {
|
||||
defaultQaRuntimeModelForMode: (
|
||||
mode: string,
|
||||
options?: {
|
||||
alternate?: boolean;
|
||||
preferredLiveModel?: string;
|
||||
},
|
||||
) => string;
|
||||
startQaLiveLaneGateway: (...args: unknown[]) => Promise<unknown>;
|
||||
};
|
||||
|
||||
export type QaRunnerCliContribution =
|
||||
| {
|
||||
pluginId: string;
|
||||
@@ -30,6 +41,36 @@ export type QaRunnerCliContribution =
|
||||
status: "blocked";
|
||||
};
|
||||
|
||||
function isMissingQaRuntimeError(error: unknown) {
|
||||
if (!(error instanceof Error)) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
error.message.includes("qa-lab") &&
|
||||
(error.message.includes("runtime-api.js") ||
|
||||
error.message.startsWith("Unable to open bundled plugin public surface "))
|
||||
);
|
||||
}
|
||||
|
||||
export function loadQaRuntimeModule(): QaRuntimeSurface {
|
||||
return loadBundledPluginPublicSurfaceModuleSync<QaRuntimeSurface>({
|
||||
dirName: ["qa", "lab"].join("-"),
|
||||
artifactBasename: ["runtime-api", "js"].join("."),
|
||||
});
|
||||
}
|
||||
|
||||
export function isQaRuntimeAvailable(): boolean {
|
||||
try {
|
||||
loadQaRuntimeModule();
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (isMissingQaRuntimeError(error)) {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function listDeclaredQaRunnerPlugins(): Array<
|
||||
PluginManifestRecord & {
|
||||
qaRunners: NonNullable<PluginManifestRecord["qaRunners"]>;
|
||||
|
||||
Reference in New Issue
Block a user