Skip to content

Commit b25d988

Browse files
committed
fix(qa): isolate runner discovery facades
1 parent 3be2964 commit b25d988

13 files changed

Lines changed: 200 additions & 38 deletions

‎docs/concepts/qa-e2e-automation.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,12 +1230,13 @@ The minimum adoption bar for a new channel:
12301230
4. Mount the runner as `openclaw qa <runner>` instead of registering a
12311231
competing root command. Runner plugins should declare `qaRunners` in
12321232
`openclaw.plugin.json` and export a matching `qaRunnerCliRegistrations`
1233-
array from `runtime-api.ts`. Keep `runtime-api.ts` light; lazy CLI and
1234-
runner execution should stay behind separate entrypoints. An optional
1235-
`adapterFactory` exposes the transport to shared scenarios without changing
1236-
the command's existing scenario catalog. Same-channel partitions are serial
1237-
unless the factory declares that every instance owns isolated credentials or
1238-
disposable servers, Gateway state, and artifact paths.
1233+
array from a lightweight `qa-runner-api.ts` surface. Installed plugins using
1234+
the shipped `runtime-api.ts` contract remain supported through 2026-10-01
1235+
while authors migrate. Keep runner execution behind lazy entrypoints. An
1236+
optional `adapterFactory` exposes the transport to shared scenarios without
1237+
changing the command's existing scenario catalog. Same-channel partitions
1238+
are serial unless the factory declares that every instance owns isolated
1239+
credentials or disposable servers, Gateway state, and artifact paths.
12391240
5. Author or adapt YAML scenarios under the themed `qa/scenarios/`
12401241
directories.
12411242
6. Use the generic scenario helpers for new scenarios.

‎docs/plugins/manifest.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,9 @@ Planner diagnostics can distinguish explicit activation hints from manifest owne
490490
Use `qaRunners` when a plugin contributes one or more transport runners beneath
491491
the shared `openclaw qa` root. Keep this metadata cheap and static; the plugin
492492
runtime still owns actual CLI registration through a lightweight
493-
`runtime-api.ts` surface that exports matching `qaRunnerCliRegistrations`. An
493+
`qa-runner-api.ts` surface that exports matching `qaRunnerCliRegistrations`. For
494+
plugins using the shipped `runtime-api.ts` contract, that legacy surface remains
495+
accepted through 2026-10-01 while authors migrate. An
494496
optional `adapterFactory` exposes the transport to shared QA scenarios without
495497
changing the registered command's runner.
496498

‎extensions/buzz/qa-runner-api.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { buzzQaCliRegistration } from "./src/qa/cli.js";
2+
3+
export const qaRunnerCliRegistrations = [buzzQaCliRegistration];

‎extensions/buzz/runtime-api.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
import { buzzQaCliRegistration } from "./src/qa/cli.js";
2-
31
export type { ChannelGatewayContext } from "openclaw/plugin-sdk/channel-contract";
42
export type { ChannelPlugin, PluginRuntime } from "openclaw/plugin-sdk/core";
5-
6-
export const qaRunnerCliRegistrations = [buzzQaCliRegistration];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { msteamsQaCliRegistration } from "./src/qa/cli.js";
2+
3+
export const qaRunnerCliRegistrations = [msteamsQaCliRegistration];

‎extensions/msteams/runtime-api.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Private runtime barrel for the bundled Microsoft Teams extension.
22
// Keep this barrel thin and aligned with the local extension surface.
33

4-
import { msteamsQaCliRegistration } from "./src/qa/cli.js";
5-
64
export { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
75
export type { AllowlistMatch } from "openclaw/plugin-sdk/allow-from";
86
export {
@@ -68,5 +66,3 @@ export { normalizeStringEntries } from "openclaw/plugin-sdk/string-normalization
6866
export { chunkTextForOutbound } from "openclaw/plugin-sdk/text-chunking";
6967
export { DEFAULT_WEBHOOK_MAX_BODY_BYTES } from "openclaw/plugin-sdk/webhook-ingress";
7068
export { setMSTeamsRuntime } from "./src/runtime.js";
71-
72-
export const qaRunnerCliRegistrations = [msteamsQaCliRegistration];

‎src/plugin-sdk/qa-runner-runtime.integration.test.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ describe("plugin-sdk qa-runner-runtime linked plugin smoke", () => {
106106
fs.writeFileSync(path.join(pluginDir, "index.js"), "export default {};\n", "utf8");
107107
fs.writeFileSync(
108108
path.join(pluginDir, "runtime-api.js"),
109+
'throw new Error("general runtime surface must not load during QA discovery");\n',
110+
"utf8",
111+
);
112+
fs.writeFileSync(
113+
path.join(pluginDir, "qa-runner-api.js"),
109114
[
110115
"export const qaRunnerCliRegistrations = [",
111116
" {",
@@ -143,6 +148,78 @@ describe("plugin-sdk qa-runner-runtime linked plugin smoke", () => {
143148
]);
144149
});
145150

151+
it("loads a legacy runtime-api runner from an installed linked plugin", () => {
152+
const stateDir = makeTempDir("openclaw-qa-runner-legacy-state-");
153+
const pluginDir = path.join(stateDir, "extensions", "qa-legacy");
154+
const configPath = path.join(stateDir, "openclaw.json");
155+
156+
fs.writeFileSync(configPath, JSON.stringify({ plugins: {} }), "utf8");
157+
process.env.OPENCLAW_CONFIG_PATH = configPath;
158+
process.env.OPENCLAW_STATE_DIR = stateDir;
159+
160+
fs.mkdirSync(pluginDir, { recursive: true });
161+
fs.writeFileSync(
162+
path.join(pluginDir, "openclaw.plugin.json"),
163+
JSON.stringify({
164+
id: "qa-legacy",
165+
qaRunners: [{ commandName: "legacy" }],
166+
configSchema: {
167+
type: "object",
168+
additionalProperties: false,
169+
properties: {},
170+
},
171+
}),
172+
"utf8",
173+
);
174+
fs.writeFileSync(
175+
path.join(pluginDir, "package.json"),
176+
JSON.stringify({
177+
name: "@openclaw/qa-legacy",
178+
type: "module",
179+
openclaw: {
180+
extensions: ["./index.js"],
181+
install: {
182+
npmSpec: "@openclaw/qa-legacy",
183+
},
184+
},
185+
}),
186+
"utf8",
187+
);
188+
fs.writeFileSync(path.join(pluginDir, "index.js"), "export default {};\n", "utf8");
189+
fs.writeFileSync(
190+
path.join(pluginDir, "runtime-api.js"),
191+
[
192+
"export const qaRunnerCliRegistrations = [",
193+
" {",
194+
' commandName: "legacy",',
195+
" register() {}",
196+
" }",
197+
"];",
198+
].join("\n"),
199+
"utf8",
200+
);
201+
202+
const contributions = listQaRunnerCliContributions();
203+
const contribution = contributions[0];
204+
expect(contribution?.status).toBe("available");
205+
if (!contribution || contribution.status !== "available") {
206+
throw new Error("Expected legacy linked QA runner contribution to be available");
207+
}
208+
const register = contribution.registration["register"];
209+
expect(typeof register).toBe("function");
210+
expect(contributions).toEqual([
211+
{
212+
pluginId: "qa-legacy",
213+
commandName: "legacy",
214+
status: "available",
215+
registration: {
216+
commandName: "legacy",
217+
register,
218+
},
219+
},
220+
]);
221+
});
222+
146223
it("ignores operator runner metadata and state during private QA discovery", () => {
147224
const stateDir = makeTempDir("openclaw-private-qa-operator-state-");
148225
const pluginDir = path.join(stateDir, "extensions", "operator-runner");

‎src/plugin-sdk/qa-runner-runtime.test.ts‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ describe("plugin-sdk qa-runner-runtime", () => {
175175
]);
176176
expect(loadBundledPluginPublicSurfaceModuleSync).toHaveBeenCalledWith({
177177
dirName: "qa-example",
178-
artifactBasename: "runtime-api.js",
178+
artifactBasename: "qa-runner-api.js",
179179
});
180180
});
181181

@@ -204,22 +204,28 @@ describe("plugin-sdk qa-runner-runtime", () => {
204204
]);
205205
});
206206

207-
it("keeps shipped registration-only runner contributions available", async () => {
207+
it("keeps shipped runtime-api runner contributions available for installed plugins", async () => {
208208
const register = vi.fn((qa: Command) => qa);
209209
loadPluginManifestRegistry.mockReturnValue({
210210
plugins: [
211211
{
212212
id: "qa-legacy",
213-
origin: "bundled",
213+
origin: "global",
214214
qaRunners: [{ commandName: "legacy" }],
215215
rootDir: "/tmp/qa-legacy",
216216
},
217217
],
218218
diagnostics: [],
219219
});
220-
loadBundledPluginPublicSurfaceModuleSync.mockReturnValue({
221-
qaRunnerCliRegistrations: [{ commandName: "legacy", register }],
222-
});
220+
tryLoadActivatedBundledPluginPublicSurfaceModuleSync
221+
.mockImplementationOnce(() => {
222+
throw new Error(
223+
"Unable to resolve bundled plugin public surface qa-legacy/qa-runner-api.js",
224+
);
225+
})
226+
.mockReturnValue({
227+
qaRunnerCliRegistrations: [{ commandName: "legacy", register }],
228+
});
223229

224230
const module = await import("./qa-runner-runtime.js");
225231

@@ -231,6 +237,14 @@ describe("plugin-sdk qa-runner-runtime", () => {
231237
registration: { commandName: "legacy", register },
232238
},
233239
]);
240+
expect(tryLoadActivatedBundledPluginPublicSurfaceModuleSync).toHaveBeenNthCalledWith(1, {
241+
dirName: "qa-legacy",
242+
artifactBasename: "qa-runner-api.js",
243+
});
244+
expect(tryLoadActivatedBundledPluginPublicSurfaceModuleSync).toHaveBeenNthCalledWith(2, {
245+
dirName: "qa-legacy",
246+
artifactBasename: "runtime-api.js",
247+
});
234248
});
235249

236250
it("prefers the source bundled tree for private qa discovery in repo checkouts", async () => {
@@ -278,7 +292,7 @@ describe("plugin-sdk qa-runner-runtime", () => {
278292

279293
const publicSurfaceCall = firstPublicSurfaceCall();
280294
expect(publicSurfaceCall?.dirName).toBe("qa-example");
281-
expect(publicSurfaceCall?.artifactBasename).toBe("runtime-api.js");
295+
expect(publicSurfaceCall?.artifactBasename).toBe("qa-runner-api.js");
282296
expect(publicSurfaceCall?.env?.OPENCLAW_ENABLE_PRIVATE_QA_CLI).toBe("1");
283297
expect(publicSurfaceCall?.env?.OPENCLAW_BUNDLED_PLUGINS_DIR).toBe(
284298
path.join(sourceRoot, "extensions"),
@@ -338,7 +352,7 @@ describe("plugin-sdk qa-runner-runtime", () => {
338352
const module = await import("./qa-runner-runtime.js");
339353

340354
expect(() => module.listQaRunnerCliContributions()).toThrow(
341-
'QA runner plugin "qa-example" exported "extra" from runtime-api.js but did not declare it in openclaw.plugin.json',
355+
'QA runner plugin "qa-example" exported "extra" from its QA runner surface but did not declare it in openclaw.plugin.json',
342356
);
343357
});
344358
});

‎src/plugin-sdk/qa-runner-runtime.ts‎

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,13 @@ export function createLiveTransportQaCliRegistration(
389389
};
390390
}
391391

392-
type QaRunnerRuntimeSurface = {
392+
type QaRunnerSurface = {
393393
qaRunnerCliRegistrations?: readonly QaRunnerCliRegistration[];
394394
};
395395

396+
const QA_RUNNER_API_ARTIFACT_BASENAME = "qa-runner-api.js";
397+
const LEGACY_QA_RUNNER_API_ARTIFACT_BASENAME = "runtime-api.js";
398+
396399
type QaRuntimeSurface = {
397400
defaultQaRuntimeModelForMode: (
398401
mode: string,
@@ -500,7 +503,7 @@ function listDeclaredQaRunnerPlugins(
500503

501504
function indexRuntimeRegistrations(
502505
pluginId: string,
503-
surface: QaRunnerRuntimeSurface,
506+
surface: QaRunnerSurface,
504507
): ReadonlyMap<string, QaRunnerCliRegistration> {
505508
const registrations = surface.qaRunnerCliRegistrations ?? [];
506509
const registrationByCommandName = new Map<string, QaRunnerCliRegistration>();
@@ -518,20 +521,38 @@ function indexRuntimeRegistrations(
518521
return registrationByCommandName;
519522
}
520523

521-
function loadQaRunnerRuntimeSurface(
524+
function loadQaRunnerSurface(
522525
plugin: PluginManifestRecord,
523526
env?: NodeJS.ProcessEnv,
524-
): QaRunnerRuntimeSurface | null {
527+
): QaRunnerSurface | null {
525528
if (plugin.origin === "bundled") {
526-
return loadBundledPluginPublicSurfaceModuleSync<QaRunnerRuntimeSurface>({
529+
return loadBundledPluginPublicSurfaceModuleSync<QaRunnerSurface>({
527530
dirName: plugin.id,
528-
artifactBasename: "runtime-api.js",
531+
artifactBasename: QA_RUNNER_API_ARTIFACT_BASENAME,
529532
...(env ? { env } : {}),
530533
});
531534
}
532-
return tryLoadActivatedBundledPluginPublicSurfaceModuleSync<QaRunnerRuntimeSurface>({
535+
try {
536+
return tryLoadActivatedBundledPluginPublicSurfaceModuleSync<QaRunnerSurface>({
537+
dirName: plugin.id,
538+
artifactBasename: QA_RUNNER_API_ARTIFACT_BASENAME,
539+
...(env ? { env } : {}),
540+
});
541+
} catch (error) {
542+
if (
543+
!(error instanceof Error) ||
544+
error.message !==
545+
`Unable to resolve bundled plugin public surface ${plugin.id}/${QA_RUNNER_API_ARTIFACT_BASENAME}`
546+
) {
547+
throw error;
548+
}
549+
}
550+
551+
// qaRunners shipped through runtime-api.js in v2026.6.9. Keep activated
552+
// installed plugins working until the 2026-10-01 removal review.
553+
return tryLoadActivatedBundledPluginPublicSurfaceModuleSync<QaRunnerSurface>({
533554
dirName: plugin.id,
534-
artifactBasename: "runtime-api.js",
555+
artifactBasename: LEGACY_QA_RUNNER_API_ARTIFACT_BASENAME,
535556
...(env ? { env } : {}),
536557
});
537558
}
@@ -542,9 +563,9 @@ export function listQaRunnerCliContributions(): readonly QaRunnerCliContribution
542563
const contributions = new Map<string, QaRunnerCliContribution>();
543564

544565
for (const plugin of listDeclaredQaRunnerPlugins(env)) {
545-
const runtimeSurface = loadQaRunnerRuntimeSurface(plugin, env);
546-
const runtimeRegistrationByCommandName = runtimeSurface
547-
? indexRuntimeRegistrations(plugin.id, runtimeSurface)
566+
const runnerSurface = loadQaRunnerSurface(plugin, env);
567+
const runtimeRegistrationByCommandName = runnerSurface
568+
? indexRuntimeRegistrations(plugin.id, runnerSurface)
548569
: null;
549570
const declaredCommandNames = new Set(plugin.qaRunners.map((runner) => runner.commandName));
550571

@@ -557,7 +578,7 @@ export function listQaRunnerCliContributions(): readonly QaRunnerCliContribution
557578
}
558579

559580
const registration = runtimeRegistrationByCommandName?.get(runner.commandName);
560-
if (!runtimeSurface) {
581+
if (!runnerSurface) {
561582
contributions.set(runner.commandName, {
562583
pluginId: plugin.id,
563584
commandName: runner.commandName,
@@ -568,7 +589,7 @@ export function listQaRunnerCliContributions(): readonly QaRunnerCliContribution
568589
}
569590
if (!registration) {
570591
throw new Error(
571-
`QA runner plugin "${plugin.id}" declared "${runner.commandName}" in openclaw.plugin.json but did not export a matching CLI registration`,
592+
`QA runner plugin "${plugin.id}" declared "${runner.commandName}" in openclaw.plugin.json but did not export a matching CLI registration from its QA runner surface`,
572593
);
573594
}
574595
const adapterFactory = registration.adapterFactory;
@@ -596,7 +617,7 @@ export function listQaRunnerCliContributions(): readonly QaRunnerCliContribution
596617
for (const commandName of runtimeRegistrationByCommandName?.keys() ?? []) {
597618
if (!declaredCommandNames.has(commandName)) {
598619
throw new Error(
599-
`QA runner plugin "${plugin.id}" exported "${commandName}" from runtime-api.js but did not declare it in openclaw.plugin.json`,
620+
`QA runner plugin "${plugin.id}" exported "${commandName}" from its QA runner surface but did not declare it in openclaw.plugin.json`,
600621
);
601622
}
602623
}

‎src/plugins/bundled-plugin-metadata.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,22 @@ describe("bundled plugin metadata", () => {
471471
});
472472
});
473473

474+
it("keeps QA runner discovery on narrow bundled runtime sidecars", () => {
475+
const runnerPlugins = listRepoBundledPluginMetadata().filter(
476+
(entry) => (entry.manifest.qaRunners?.length ?? 0) > 0,
477+
);
478+
expect(runnerPlugins.length).toBeGreaterThan(0);
479+
480+
for (const plugin of runnerPlugins) {
481+
expectArtifactPresence(plugin?.publicSurfaceArtifacts, {
482+
contains: ["qa-runner-api.js"],
483+
});
484+
expectArtifactPresence(plugin?.runtimeSidecarArtifacts, {
485+
contains: ["qa-runner-api.js"],
486+
});
487+
}
488+
});
489+
474490
it("loads tlon channel config metadata from the lightweight schema surface", () => {
475491
const tlonChannelConfig = collectRepoBundledChannelConfigsForTest("tlon")?.tlon as
476492
| { schema?: { type?: unknown } }

0 commit comments

Comments
 (0)