Skip to content

Commit 46cc264

Browse files
committed
refactor(qa): unify live channel runtime hosting
1 parent 0869edc commit 46cc264

20 files changed

Lines changed: 562 additions & 104 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ The minimum adoption bar for a new channel:
958958
1. Keep `qa-lab` as the owner of the shared `qa` root.
959959
2. Implement the transport runner on the shared `qa-lab` host seam.
960960
3. Keep transport-specific mechanics inside the runner plugin or channel harness.
961-
4. Mount the runner as `openclaw qa <runner>` instead of registering a competing root command. Runner plugins should declare `qaRunners` in `openclaw.plugin.json` and export a matching `qaRunnerCliRegistrations` array from `runtime-api.ts`. Keep `runtime-api.ts` light; lazy CLI and runner execution should stay behind separate entrypoints.
961+
4. Mount the runner as `openclaw qa <runner>` instead of registering a competing root command. Declare `qaRunners` in `openclaw.plugin.json` and export matching `qaRunnerCliRegistrations` from a lightweight `runtime-api.ts`. Set `adapterFactory` to use the shared suite host; registration-only runners remain direct-mounted for compatibility.
962962
5. Author or adapt YAML scenarios under the themed `qa/scenarios/` directories.
963963
6. Use the generic scenario helpers for new scenarios.
964964
7. Keep existing compatibility aliases working unless the repo is doing an intentional migration.

‎docs/help/testing.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ for Slack rows.
546546

547547
### Adding a channel to QA
548548

549-
The architecture and scenario-helper names for new channel adapters live in [QA overview → Adding a channel](/concepts/qa-e2e-automation#adding-a-channel). The minimum bar: implement the transport runner on the shared `qa-lab` host seam, declare `qaRunners` in the plugin manifest, mount as `openclaw qa <runner>`, and author scenarios under `qa/scenarios/`.
549+
The architecture and scenario helpers live in [QA overview → Adding a channel](/concepts/qa-e2e-automation#adding-a-channel). Add a QA runner with `adapterFactory`, declare it in `qaRunners`, mount it as `openclaw qa <runner>`, and author scenarios under `qa/scenarios/`.
550550

551551
## Test suites (what runs where)
552552

‎docs/plugins/manifest.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,10 @@ that best describes ownership.
472472
Use `qaRunners` when a plugin contributes one or more transport runners beneath
473473
the shared `openclaw qa` root. Keep this metadata cheap and static; the plugin
474474
runtime still owns actual CLI registration through a lightweight
475-
`runtime-api.ts` surface that exports `qaRunnerCliRegistrations`.
475+
`runtime-api.ts` surface that exports matching `qaRunnerCliRegistrations`.
476+
Set a registration's asynchronous `adapterFactory` to use the shared `qa-lab`
477+
suite host. Keep `runtime-api.ts` lightweight and lazy-load channel runtimes.
478+
Registration-only runners remain direct-mounted for compatibility.
476479

477480
```json
478481
{
@@ -490,6 +493,9 @@ runtime still owns actual CLI registration through a lightweight
490493
| `commandName` | Yes | `string` | Subcommand mounted beneath `openclaw qa`, for example `matrix`. |
491494
| `description` | No | `string` | Fallback help text used when the shared host needs a stub command. |
492495

496+
The `adapterFactory` id must match `commandName`. Do not export registrations
497+
for commands absent from the manifest.
498+
493499
## setup reference
494500

495501
Use `setup` when setup and onboarding surfaces need cheap plugin-owned metadata

‎extensions/qa-lab/src/cli.test.ts‎

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ const TEST_QA_RUNNER = {
1010
} as const;
1111

1212
function createAvailableQaRunnerContribution() {
13+
const adapterFactory = {
14+
id: TEST_QA_RUNNER.commandName,
15+
matches: vi.fn(() => true),
16+
create: vi.fn(),
17+
};
1318
return {
1419
pluginId: TEST_QA_RUNNER.pluginId,
1520
commandName: TEST_QA_RUNNER.commandName,
1621
status: "available" as const,
1722
registration: {
1823
commandName: TEST_QA_RUNNER.commandName,
19-
register: vi.fn((qa: Command) => {
20-
qa.command(TEST_QA_RUNNER.commandName).action(() => undefined);
24+
adapterFactory,
25+
register: vi.fn((qa: Command, run) => {
26+
qa.command(TEST_QA_RUNNER.commandName).action(async () => await run?.({}));
2127
}),
2228
},
2329
} satisfies QaRunnerCliContribution;
@@ -32,6 +38,20 @@ function createBlockedQaRunnerContribution(): QaRunnerCliContribution {
3238
};
3339
}
3440

41+
function createLegacyQaRunnerContribution(): QaRunnerCliContribution {
42+
return {
43+
pluginId: TEST_QA_RUNNER.pluginId,
44+
commandName: TEST_QA_RUNNER.commandName,
45+
status: "available",
46+
registration: {
47+
commandName: TEST_QA_RUNNER.commandName,
48+
register(qa) {
49+
qa.command(TEST_QA_RUNNER.commandName).action(() => undefined);
50+
},
51+
},
52+
};
53+
}
54+
3555
function createConflictingQaRunnerContribution(commandName: string): QaRunnerCliContribution {
3656
return {
3757
pluginId: TEST_QA_RUNNER.pluginId,
@@ -51,7 +71,7 @@ const {
5171
runQaProfileCommand,
5272
runQaProviderServerCommand,
5373
runQaSuiteCommand,
54-
runQaTelegramCommand,
74+
runQaHostedTransportSuite,
5575
runMantisBeforeAfterCommand,
5676
runMantisDesktopBrowserSmokeCommand,
5777
runMantisDiscordSmokeCommand,
@@ -67,7 +87,7 @@ const {
6787
runQaProfileCommand: vi.fn(),
6888
runQaProviderServerCommand: vi.fn(),
6989
runQaSuiteCommand: vi.fn(),
70-
runQaTelegramCommand: vi.fn(),
90+
runQaHostedTransportSuite: vi.fn(),
7191
runMantisBeforeAfterCommand: vi.fn(),
7292
runMantisDesktopBrowserSmokeCommand: vi.fn(),
7393
runMantisDiscordSmokeCommand: vi.fn(),
@@ -82,11 +102,11 @@ const { listQaRunnerCliContributions } = vi.hoisted(() => ({
82102
}));
83103

84104
function requireQaTelegramOptions() {
85-
const [call] = runQaTelegramCommand.mock.calls;
105+
const [call] = runQaHostedTransportSuite.mock.calls;
86106
if (!call) {
87107
throw new Error("expected qa telegram command call");
88108
}
89-
const [options] = call;
109+
const [, options] = call;
90110
return options;
91111
}
92112

@@ -103,8 +123,8 @@ vi.mock("openclaw/plugin-sdk/qa-runner-runtime", () => ({
103123
listQaRunnerCliContributions,
104124
}));
105125

106-
vi.mock("./live-transports/telegram/cli.runtime.js", () => ({
107-
runQaTelegramCommand,
126+
vi.mock("./suite-launch.runtime.js", () => ({
127+
runQaHostedTransportSuite,
108128
}));
109129

110130
vi.mock("./mantis/cli.runtime.js", () => ({
@@ -143,7 +163,7 @@ describe("qa cli registration", () => {
143163
runQaProfileCommand.mockReset();
144164
runQaProviderServerCommand.mockReset();
145165
runQaSuiteCommand.mockReset();
146-
runQaTelegramCommand.mockReset();
166+
runQaHostedTransportSuite.mockReset();
147167
runMantisBeforeAfterCommand.mockReset();
148168
runMantisDesktopBrowserSmokeCommand.mockReset();
149169
runMantisDiscordSmokeCommand.mockReset();
@@ -740,6 +760,18 @@ describe("qa cli registration", () => {
740760
expect(registration.register).toHaveBeenCalledTimes(1);
741761
});
742762

763+
it("mounts shipped registration-only runners without the adapter host", () => {
764+
listQaRunnerCliContributions.mockReset().mockReturnValue([createLegacyQaRunnerContribution()]);
765+
766+
const legacyProgram = new Command();
767+
registerQaLabCli(legacyProgram);
768+
769+
const qa = legacyProgram.commands.find((command) => command.name() === "qa");
770+
expect(qa?.commands.some((command) => command.name() === TEST_QA_RUNNER.commandName)).toBe(
771+
true,
772+
);
773+
});
774+
743775
it("keeps Telegram credential flags on the shared host CLI", () => {
744776
const qa = program.commands.find((command) => command.name() === "qa");
745777
const telegram = qa?.commands.find((command) => command.name() === "telegram");
@@ -850,20 +882,24 @@ describe("qa cli registration", () => {
850882
it("routes telegram CLI defaults into the lane runtime", async () => {
851883
await program.parseAsync(["node", "openclaw", "qa", "telegram"]);
852884

853-
expect(runQaTelegramCommand).toHaveBeenCalledWith({
854-
repoRoot: undefined,
855-
outputDir: undefined,
856-
providerMode: "live-frontier",
857-
primaryModel: undefined,
858-
alternateModel: undefined,
859-
fastMode: false,
860-
allowFailures: false,
861-
scenarioIds: [],
862-
listScenarios: false,
863-
sutAccountId: "sut",
864-
credentialSource: undefined,
865-
credentialRole: undefined,
866-
});
885+
expect(runQaHostedTransportSuite).toHaveBeenCalledWith(
886+
"telegram",
887+
{
888+
repoRoot: undefined,
889+
outputDir: undefined,
890+
providerMode: "live-frontier",
891+
primaryModel: undefined,
892+
alternateModel: undefined,
893+
fastMode: false,
894+
allowFailures: false,
895+
scenarioIds: [],
896+
listScenarios: false,
897+
sutAccountId: "sut",
898+
credentialSource: undefined,
899+
credentialRole: undefined,
900+
},
901+
expect.any(Array),
902+
);
867903
});
868904

869905
it("forwards --list-scenarios for telegram runs", async () => {

‎extensions/qa-lab/src/live-transports/cli.ts‎

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Qa Lab plugin module implements cli behavior.
22
import { listQaRunnerCliContributions } from "openclaw/plugin-sdk/qa-runner-runtime";
3+
import { runQaHostedTransportSuite } from "../suite-launch.runtime.js";
34
import { discordQaCliRegistration } from "./discord/cli.js";
45
import type { LiveTransportQaCliRegistration } from "./shared/live-transport-cli.js";
5-
import { slackQaCliRegistration } from "./slack/cli.js";
6-
import { telegramQaCliRegistration } from "./telegram/cli.js";
7-
import { whatsappQaCliRegistration } from "./whatsapp/cli.js";
6+
import { slackQaCliRegistration, slackQaTransportFactory } from "./slack/cli.js";
7+
import { telegramQaCliRegistration, telegramQaTransportFactory } from "./telegram/cli.js";
8+
import { whatsappQaCliRegistration, whatsappQaTransportFactory } from "./whatsapp/cli.js";
89

910
function createBlockedQaRunnerCliRegistration(params: {
1011
commandName: string;
@@ -29,7 +30,18 @@ function createQaRunnerCliRegistration(
2930
runner: ReturnType<typeof listQaRunnerCliContributions>[number],
3031
): LiveTransportQaCliRegistration {
3132
if (runner.status === "available") {
32-
return runner.registration;
33+
const adapterFactory = runner.registration.adapterFactory;
34+
if (!adapterFactory) {
35+
return runner.registration;
36+
}
37+
return {
38+
commandName: runner.commandName,
39+
register(qa) {
40+
runner.registration.register(qa, async (options) => {
41+
await runQaHostedTransportSuite(runner.commandName, options, [adapterFactory]);
42+
});
43+
},
44+
};
3345
}
3446
return createBlockedQaRunnerCliRegistration({
3547
commandName: runner.commandName,
@@ -38,11 +50,17 @@ function createQaRunnerCliRegistration(
3850
});
3951
}
4052

53+
const BUILT_IN_LIVE_TRANSPORT_FACTORIES = [
54+
telegramQaTransportFactory,
55+
slackQaTransportFactory,
56+
whatsappQaTransportFactory,
57+
] as const;
58+
4159
const LIVE_TRANSPORT_QA_CLI_REGISTRATIONS: readonly LiveTransportQaCliRegistration[] = [
42-
telegramQaCliRegistration,
60+
registerBuiltInLiveTransportQaCli(telegramQaCliRegistration),
4361
discordQaCliRegistration,
44-
slackQaCliRegistration,
45-
whatsappQaCliRegistration,
62+
registerBuiltInLiveTransportQaCli(slackQaCliRegistration),
63+
registerBuiltInLiveTransportQaCli(whatsappQaCliRegistration),
4664
];
4765

4866
export function listLiveTransportQaCliRegistrations(): readonly LiveTransportQaCliRegistration[] {
@@ -55,3 +73,20 @@ export function listLiveTransportQaCliRegistrations(): readonly LiveTransportQaC
5573

5674
return liveRegistrations;
5775
}
76+
77+
function registerBuiltInLiveTransportQaCli(
78+
registration: LiveTransportQaCliRegistration,
79+
): LiveTransportQaCliRegistration {
80+
return {
81+
commandName: registration.commandName,
82+
register(qa) {
83+
registration.register(qa, async (options) => {
84+
await runQaHostedTransportSuite(
85+
registration.commandName,
86+
options,
87+
BUILT_IN_LIVE_TRANSPORT_FACTORIES,
88+
);
89+
});
90+
},
91+
};
92+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Qa Lab tests cover canonical live transport adapter factory routing.
2+
import { describe, expect, it, vi } from "vitest";
3+
import { createQaBusState } from "../bus-state.js";
4+
import { createQaTransportAdapterFactoryRegistry } from "../qa-transport-registry.js";
5+
6+
const { runQaSlackCommand, runQaTelegramCommand, runQaWhatsAppCommand } = vi.hoisted(() => ({
7+
runQaSlackCommand: vi.fn(async () => undefined),
8+
runQaTelegramCommand: vi.fn(async () => undefined),
9+
runQaWhatsAppCommand: vi.fn(async () => undefined),
10+
}));
11+
12+
vi.mock("./slack/cli.runtime.js", () => ({ runQaSlackCommand }));
13+
vi.mock("./telegram/cli.runtime.js", () => ({ runQaTelegramCommand }));
14+
vi.mock("./whatsapp/cli.runtime.js", () => ({ runQaWhatsAppCommand }));
15+
16+
import { slackQaTransportFactory } from "./slack/cli.js";
17+
import { telegramQaTransportFactory } from "./telegram/cli.js";
18+
import { whatsappQaTransportFactory } from "./whatsapp/cli.js";
19+
20+
const factories = [
21+
telegramQaTransportFactory,
22+
slackQaTransportFactory,
23+
whatsappQaTransportFactory,
24+
] as const;
25+
26+
describe("live transport adapter factories", () => {
27+
it.each([
28+
["telegram", runQaTelegramCommand],
29+
["slack", runQaSlackCommand],
30+
["whatsapp", runQaWhatsAppCommand],
31+
] as const)(
32+
"adapts the existing %s runtime through the canonical registry",
33+
async (channelId, run) => {
34+
const options = { scenarioIds: [`${channelId}-canary`] };
35+
const registry = createQaTransportAdapterFactoryRegistry(factories);
36+
const created = await registry.create({
37+
channelId,
38+
commandOptions: options,
39+
driver: "live",
40+
outputDir: ".artifacts/qa-e2e",
41+
state: createQaBusState(),
42+
});
43+
44+
expect(created.adapter.kind).toBe("hosted");
45+
if (created.adapter.kind !== "hosted") {
46+
throw new Error("expected hosted live transport adapter");
47+
}
48+
await created.adapter.run();
49+
50+
expect(run).toHaveBeenCalledWith(options);
51+
},
52+
);
53+
});

‎extensions/qa-lab/src/live-transports/slack/cli.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
createLazyCliRuntimeLoader,
44
createLiveTransportQaCliRegistration,
55
type LiveTransportQaCliRegistration,
6-
type LiveTransportQaCommandOptions,
76
} from "../shared/live-transport-cli.js";
87

98
type SlackQaCliRuntime = typeof import("./cli.runtime.js");
@@ -12,14 +11,26 @@ const loadSlackQaCliRuntime = createLazyCliRuntimeLoader<SlackQaCliRuntime>(
1211
() => import("./cli.runtime.js"),
1312
);
1413

15-
async function runQaSlack(opts: LiveTransportQaCommandOptions) {
16-
const runtime = await loadSlackQaCliRuntime();
17-
await runtime.runQaSlackCommand(opts);
18-
}
14+
export const slackQaTransportFactory: NonNullable<
15+
LiveTransportQaCliRegistration["adapterFactory"]
16+
> = {
17+
id: "slack",
18+
matches: ({ channelId, driver }) => driver === "live" && channelId === "slack",
19+
async create(context) {
20+
const options = context.commandOptions ?? {};
21+
const runtime = await loadSlackQaCliRuntime();
22+
return {
23+
kind: "hosted",
24+
id: "slack",
25+
run: async () => await runtime.runQaSlackCommand(options),
26+
};
27+
},
28+
};
1929

2030
export const slackQaCliRegistration: LiveTransportQaCliRegistration =
2131
createLiveTransportQaCliRegistration({
2232
commandName: "slack",
33+
adapterFactory: slackQaTransportFactory,
2334
credentialOptions: {
2435
sourceDescription: "Credential source for Slack QA: env or convex (default: env)",
2536
roleDescription:
@@ -29,5 +40,4 @@ export const slackQaCliRegistration: LiveTransportQaCliRegistration =
2940
outputDirHelp: "Slack QA artifact directory",
3041
scenarioHelp: "Run only the named Slack QA scenario (repeatable)",
3142
sutAccountHelp: "Temporary Slack account id inside the QA gateway config",
32-
run: runQaSlack,
3343
});

0 commit comments

Comments
 (0)