mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-25 17:06:59 +00:00
* refactor: share QA runtime helpers * refactor: keep QA helpers private * refactor: keep QA helpers on private runtime seam * chore: prune stale QA duplicate ignores * fix: align qa runtime boundary alias * fix: avoid startup memory lint conversion
143 lines
4.5 KiB
TypeScript
143 lines
4.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
cleanupTempDirs,
|
|
expectPrivateQaLabRuntimeSurfaceLoad,
|
|
expectQaLabRuntimeSurfaceLoad,
|
|
restorePrivateQaCliEnv,
|
|
} from "./qa-runtime.test-helpers.js";
|
|
|
|
const loadBundledPluginPublicSurfaceModuleSync = vi.hoisted(() => vi.fn());
|
|
const resolveOpenClawPackageRootSync = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("./facade-runtime.js", () => ({
|
|
loadBundledPluginPublicSurfaceModuleSync,
|
|
}));
|
|
|
|
vi.mock("../infra/openclaw-root.js", () => ({
|
|
resolveOpenClawPackageRootSync,
|
|
}));
|
|
|
|
describe("plugin-sdk qa-runtime", () => {
|
|
const tempDirs: string[] = [];
|
|
const originalPrivateQaCli = process.env.OPENCLAW_ENABLE_PRIVATE_QA_CLI;
|
|
|
|
beforeEach(() => {
|
|
loadBundledPluginPublicSurfaceModuleSync.mockReset();
|
|
resolveOpenClawPackageRootSync.mockReset().mockReturnValue(null);
|
|
delete process.env.OPENCLAW_ENABLE_PRIVATE_QA_CLI;
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanupTempDirs(tempDirs);
|
|
restorePrivateQaCliEnv(originalPrivateQaCli);
|
|
});
|
|
|
|
it("stays cold until the runtime seam is used", async () => {
|
|
const module = await import("./qa-runtime.js");
|
|
|
|
expect(loadBundledPluginPublicSurfaceModuleSync).not.toHaveBeenCalled();
|
|
expect(module.loadQaRuntimeModule).toBeTypeOf("function");
|
|
expect(module.isQaRuntimeAvailable).toBeTypeOf("function");
|
|
});
|
|
|
|
it("loads the qa-lab runtime public surface through the generic seam", async () => {
|
|
await expectQaLabRuntimeSurfaceLoad({
|
|
importRuntime: () => import("./qa-runtime.js"),
|
|
loadBundledPluginPublicSurfaceModuleSync,
|
|
});
|
|
});
|
|
|
|
it("uses the source bundled tree for qa-lab runtime loading in private qa mode", async () => {
|
|
await expectPrivateQaLabRuntimeSurfaceLoad({
|
|
tempDirs,
|
|
importRuntime: () => import("./qa-runtime.js"),
|
|
loadBundledPluginPublicSurfaceModuleSync,
|
|
resolveOpenClawPackageRootSync,
|
|
});
|
|
});
|
|
|
|
it("reports the 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-runtime.js");
|
|
|
|
expect(module.isQaRuntimeAvailable()).toBe(false);
|
|
});
|
|
|
|
it("renders shared QA markdown reports with multiline details", async () => {
|
|
const module = await import("./qa-runtime.js");
|
|
|
|
const report = module.renderQaMarkdownReport({
|
|
title: "QA Report",
|
|
startedAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
finishedAt: new Date("2026-01-01T00:00:02.000Z"),
|
|
checks: [{ name: "preflight", status: "pass" }],
|
|
scenarios: [
|
|
{
|
|
name: "transport reply",
|
|
status: "fail",
|
|
details: "line one\nline two",
|
|
steps: [{ name: "send", status: "pass", details: "ok" }],
|
|
},
|
|
],
|
|
timeline: ["sent request"],
|
|
notes: ["kept artifacts"],
|
|
});
|
|
|
|
expect(report).toContain("# QA Report");
|
|
expect(report).toContain("- Duration ms: 2000");
|
|
expect(report).toContain("- Passed: 1");
|
|
expect(report).toContain("- Failed: 1");
|
|
expect(report).toContain("```text\nline one\nline two\n```");
|
|
expect(report).toContain("- [x] send");
|
|
expect(report).toContain("## Timeline");
|
|
});
|
|
|
|
it("builds shared live-lane artifact errors", async () => {
|
|
const module = await import("./qa-runtime.js");
|
|
|
|
expect(
|
|
module.buildQaLiveLaneArtifactsError({
|
|
heading: "Matrix QA failed.",
|
|
details: ["cleanup: ok"],
|
|
artifacts: {
|
|
report: "/tmp/report.md",
|
|
summary: "/tmp/summary.json",
|
|
},
|
|
}),
|
|
).toBe(
|
|
[
|
|
"Matrix QA failed.",
|
|
"cleanup: ok",
|
|
"Artifacts:",
|
|
"- report: /tmp/report.md",
|
|
"- summary: /tmp/summary.json",
|
|
].join("\n"),
|
|
);
|
|
});
|
|
|
|
it("shares Docker health parsing across array and jsonl compose output", async () => {
|
|
const module = await import("./qa-runtime.js");
|
|
const runtime = module.createQaDockerRuntime({ auditContext: "qa-test" });
|
|
const dockerPsOutputs = ['[{"Health":"starting"}]', '{"State":"running"}\n'];
|
|
const runCommand = vi.fn(async () => ({
|
|
stdout: dockerPsOutputs.shift() ?? '{"State":"running"}',
|
|
stderr: "",
|
|
}));
|
|
const sleepImpl = vi.fn(async () => {});
|
|
|
|
await runtime.waitForDockerServiceHealth(
|
|
"homeserver",
|
|
"/tmp/docker-compose.yml",
|
|
"/repo",
|
|
runCommand,
|
|
sleepImpl,
|
|
);
|
|
|
|
expect(runCommand).toHaveBeenCalledTimes(2);
|
|
expect(sleepImpl).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|