refactor(qa): split Matrix QA into optional plugin (#66723)

Merged via squash.

Prepared head SHA: 27241bd089
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Gustavo Madeira Santana
2026-04-14 16:28:57 -04:00
committed by GitHub
parent 3425823dfb
commit 82a2db71e8
69 changed files with 2026 additions and 229 deletions

View File

@@ -131,11 +131,12 @@ describe("bundled plugin metadata", () => {
},
);
it("excludes private QA sidecars from the packaged runtime sidecar baseline", () => {
it("excludes non-packaged QA sidecars from the packaged runtime sidecar baseline", () => {
expect(BUNDLED_RUNTIME_SIDECAR_PATHS).not.toContain(
"dist/extensions/qa-channel/runtime-api.js",
);
expect(BUNDLED_RUNTIME_SIDECAR_PATHS).not.toContain("dist/extensions/qa-lab/runtime-api.js");
expect(BUNDLED_RUNTIME_SIDECAR_PATHS).not.toContain("dist/extensions/qa-matrix/runtime-api.js");
});
it("captures setup-entry metadata for bundled channel plugins", () => {

View File

@@ -1427,6 +1427,21 @@ describe("installPluginFromArchive", () => {
).toBe(true);
});
it("does not flag the real qa-matrix plugin as dangerous install code", async () => {
const pluginDir = path.resolve(process.cwd(), "extensions", "qa-matrix");
const scanResult = await installSecurityScan.scanPackageInstallSource({
extensions: ["./index.ts"],
logger: { warn: vi.fn() },
packageDir: pluginDir,
pluginId: "qa-matrix",
packageName: "@openclaw/qa-matrix",
manifestId: "qa-matrix",
});
expect(scanResult?.blocked).toBeUndefined();
});
it("keeps blocked dependency package checks active when forced unsafe install is set", async () => {
const { pluginDir, extensionsDir } = setupPluginInstallDirs();

View File

@@ -499,6 +499,33 @@ describe("loadPluginManifestRegistry", () => {
});
});
it("preserves qa runner descriptors from plugin manifests", () => {
const dir = makeTempDir();
writeManifest(dir, {
id: "qa-matrix",
qaRunners: [
{
commandName: "matrix",
description: "Run the Matrix live QA lane",
},
],
configSchema: { type: "object" },
});
const registry = loadSingleCandidateRegistry({
idHint: "qa-matrix",
rootDir: dir,
origin: "bundled",
});
expect(registry.plugins[0]?.qaRunners).toEqual([
{
commandName: "matrix",
description: "Run the Matrix live QA lane",
},
]);
});
it("preserves channel config metadata from plugin manifests", () => {
const dir = makeTempDir();
writeManifest(dir, {

View File

@@ -34,6 +34,7 @@ import {
type PluginManifestChannelConfig,
type PluginManifestContracts,
type PluginManifestModelSupport,
type PluginManifestQaRunner,
type PluginManifestSetup,
} from "./manifest.js";
import { checkMinHostVersion } from "./min-host-version.js";
@@ -92,6 +93,7 @@ export type PluginManifestRecord = {
providerAuthChoices?: PluginManifest["providerAuthChoices"];
activation?: PluginManifestActivation;
setup?: PluginManifestSetup;
qaRunners?: PluginManifestQaRunner[];
skills: string[];
settingsFiles?: string[];
hooks: string[];
@@ -333,6 +335,7 @@ function buildRecord(params: {
providerAuthChoices: params.manifest.providerAuthChoices,
activation: params.manifest.activation,
setup: params.manifest.setup,
qaRunners: params.manifest.qaRunners,
skills: params.manifest.skills ?? [],
settingsFiles: [],
hooks: [],

View File

@@ -80,6 +80,13 @@ export type PluginManifestSetup = {
requiresRuntime?: boolean;
};
export type PluginManifestQaRunner = {
/** Subcommand mounted beneath `openclaw qa`, for example `matrix`. */
commandName: string;
/** Optional user-facing help text for fallback host stubs. */
description?: string;
};
export type PluginManifestConfigLiteral = string | number | boolean | null;
export type PluginManifestDangerousConfigFlag = {
@@ -174,6 +181,8 @@ export type PluginManifest = {
activation?: PluginManifestActivation;
/** Cheap setup/onboarding metadata exposed before plugin runtime loads. */
setup?: PluginManifestSetup;
/** Cheap QA runner metadata exposed before plugin runtime loads. */
qaRunners?: PluginManifestQaRunner[];
skills?: string[];
name?: string;
description?: string;
@@ -484,6 +493,28 @@ function normalizeManifestSetup(value: unknown): PluginManifestSetup | undefined
return Object.keys(setup).length > 0 ? setup : undefined;
}
function normalizeManifestQaRunners(value: unknown): PluginManifestQaRunner[] | undefined {
if (!Array.isArray(value)) {
return undefined;
}
const normalized: PluginManifestQaRunner[] = [];
for (const entry of value) {
if (!isRecord(entry)) {
continue;
}
const commandName = normalizeOptionalString(entry.commandName) ?? "";
if (!commandName) {
continue;
}
const description = normalizeOptionalString(entry.description) ?? "";
normalized.push({
commandName,
...(description ? { description } : {}),
});
}
return normalized.length > 0 ? normalized : undefined;
}
function normalizeProviderAuthChoices(
value: unknown,
): PluginManifestProviderAuthChoice[] | undefined {
@@ -673,6 +704,7 @@ export function loadPluginManifest(
const providerAuthChoices = normalizeProviderAuthChoices(raw.providerAuthChoices);
const activation = normalizeManifestActivation(raw.activation);
const setup = normalizeManifestSetup(raw.setup);
const qaRunners = normalizeManifestQaRunners(raw.qaRunners);
const skills = normalizeTrimmedStringList(raw.skills);
const contracts = normalizeManifestContracts(raw.contracts);
const configContracts = normalizeManifestConfigContracts(raw.configContracts);
@@ -706,6 +738,7 @@ export function loadPluginManifest(
providerAuthChoices,
activation,
setup,
qaRunners,
skills,
name,
description,

View File

@@ -0,0 +1,74 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { listBundledPluginMetadata } from "./bundled-plugin-metadata.js";
export type QaRunnerCatalogEntry = {
pluginId: string;
commandName: string;
description?: string;
npmSpec: string;
};
const QA_RUNNER_CATALOG_JSON_PATH = fileURLToPath(
new URL("../../scripts/lib/qa-runner-catalog.json", import.meta.url),
);
export function listBundledQaRunnerCatalog(): readonly QaRunnerCatalogEntry[] {
if (!fs.existsSync(QA_RUNNER_CATALOG_JSON_PATH)) {
return [];
}
return JSON.parse(fs.readFileSync(QA_RUNNER_CATALOG_JSON_PATH, "utf8")) as QaRunnerCatalogEntry[];
}
export function collectBundledQaRunnerCatalog(params?: {
rootDir?: string;
}): readonly QaRunnerCatalogEntry[] {
const catalog: QaRunnerCatalogEntry[] = [];
const seenCommandNames = new Map<string, string>();
for (const entry of listBundledPluginMetadata({
rootDir: params?.rootDir,
includeChannelConfigs: false,
})) {
const qaRunners = entry.manifest.qaRunners ?? [];
const npmSpec = entry.packageManifest?.install?.npmSpec?.trim() || entry.packageName?.trim();
if (!npmSpec) {
continue;
}
for (const runner of qaRunners) {
const previousOwner = seenCommandNames.get(runner.commandName);
if (previousOwner) {
throw new Error(
`QA runner command "${runner.commandName}" declared by both "${previousOwner}" and "${entry.manifest.id}"`,
);
}
seenCommandNames.set(runner.commandName, entry.manifest.id);
catalog.push({
pluginId: entry.manifest.id,
commandName: runner.commandName,
...(runner.description ? { description: runner.description } : {}),
npmSpec,
});
}
}
return catalog.toSorted((left, right) => left.commandName.localeCompare(right.commandName));
}
export async function writeBundledQaRunnerCatalog(params: {
repoRoot: string;
check: boolean;
}): Promise<{ changed: boolean; jsonPath: string }> {
const jsonPath = path.join(params.repoRoot, "scripts", "lib", "qa-runner-catalog.json");
const expectedJson = `${JSON.stringify(collectBundledQaRunnerCatalog({ rootDir: params.repoRoot }), null, 2)}\n`;
const currentJson = fs.existsSync(jsonPath) ? fs.readFileSync(jsonPath, "utf8") : "";
const changed = currentJson !== expectedJson;
if (!params.check && changed) {
fs.mkdirSync(path.dirname(jsonPath), { recursive: true });
fs.writeFileSync(jsonPath, expectedJson, "utf8");
}
return { changed, jsonPath };
}

View File

@@ -2,7 +2,7 @@ import fs from "node:fs";
import path from "node:path";
import { listBundledPluginMetadata } from "./bundled-plugin-metadata.js";
const NON_PACKAGED_RUNTIME_SIDECAR_PLUGIN_DIRS = new Set(["qa-channel", "qa-lab"]);
const NON_PACKAGED_RUNTIME_SIDECAR_PLUGIN_DIRS = new Set(["qa-channel", "qa-lab", "qa-matrix"]);
function buildBundledDistArtifactPath(dirName: string, artifact: string): string {
return ["dist", "extensions", dirName, artifact].join("/");