test: expose bundled plugin QA test APIs

This commit is contained in:
Gustavo Madeira Santana
2026-04-16 16:14:01 -04:00
parent 5bb180061a
commit 21d500a65f
2 changed files with 34 additions and 0 deletions

View File

@@ -100,6 +100,31 @@ describe("plugin-sdk qa-runner-runtime", () => {
});
});
it("loads bundled plugin test APIs with the private QA source tree override", async () => {
const sourceRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-qa-test-api-root-"));
tempDirs.push(sourceRoot);
fs.mkdirSync(path.join(sourceRoot, "src"), { recursive: true });
fs.mkdirSync(path.join(sourceRoot, "extensions"), { recursive: true });
fs.writeFileSync(path.join(sourceRoot, ".git"), "gitdir: /tmp/mock\n", "utf8");
process.env.OPENCLAW_ENABLE_PRIVATE_QA_CLI = "1";
resolveOpenClawPackageRootSync.mockReturnValue(sourceRoot);
const testApi = { marker: "matrix-test-api" };
loadBundledPluginPublicSurfaceModuleSync.mockReturnValue(testApi);
const module = await import("./qa-runner-runtime.js");
expect(module.loadQaRunnerBundledPluginTestApi("matrix")).toBe(testApi);
expect(loadBundledPluginPublicSurfaceModuleSync).toHaveBeenCalledWith({
dirName: "matrix",
artifactBasename: "test-api.js",
env: expect.objectContaining({
OPENCLAW_ENABLE_PRIVATE_QA_CLI: "1",
OPENCLAW_BUNDLED_PLUGINS_DIR: path.join(sourceRoot, "extensions"),
}),
});
});
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");

View File

@@ -62,6 +62,15 @@ export function loadQaRuntimeModule(): QaRuntimeSurface {
});
}
export function loadQaRunnerBundledPluginTestApi<T extends object>(pluginId: string): T {
const env = resolvePrivateQaBundledPluginsEnv();
return loadBundledPluginPublicSurfaceModuleSync<T>({
dirName: pluginId,
artifactBasename: "test-api.js",
...(env ? { env } : {}),
});
}
export function isQaRuntimeAvailable(): boolean {
try {
loadQaRuntimeModule();