|
1 | 1 | // Qa Lab tests cover suite runtime flow plugin behavior. |
2 | 2 | import { parseModelRef, resolveModelRefFromString } from "openclaw/plugin-sdk/agent-runtime"; |
3 | | -import { describe, expect, it, vi } from "vitest"; |
| 3 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
4 | 4 |
|
5 | 5 | const createQaScenarioRuntimeApi = vi.hoisted(() => vi.fn()); |
6 | 6 | const runScenarioFlow = vi.hoisted(() => vi.fn(async (params: { api: unknown }) => params.api)); |
@@ -43,9 +43,74 @@ import { runQaSuiteScenarioDefinition, runQaSuiteScenarioSteps } from "./suite-r |
43 | 43 | import * as suiteRuntimeGateway from "./suite-runtime-gateway.js"; |
44 | 44 | import * as suiteRuntimeTransport from "./suite-runtime-transport.js"; |
45 | 45 | import type { QaSuiteRuntimeEnv } from "./suite-runtime-types.js"; |
| 46 | +import { makeQaSuiteTestScenario } from "./suite-test-helpers.js"; |
46 | 47 | import * as webRuntime from "./web-runtime.js"; |
47 | 48 |
|
| 49 | +const qaSuiteRuntimeFlowTestConstants = { |
| 50 | + imageUnderstandingPngBase64: "small", |
| 51 | + imageUnderstandingLargePngBase64: "large", |
| 52 | + imageUnderstandingValidPngBase64: "valid", |
| 53 | +}; |
| 54 | + |
| 55 | +function createQaSuiteRuntimeFlowTestEnv( |
| 56 | + transportOverrides: Partial<QaSuiteRuntimeEnv["transport"]> = {}, |
| 57 | +) { |
| 58 | + return { |
| 59 | + lab: { baseUrl: "http://127.0.0.1:4444" }, |
| 60 | + webSessionIds: new Set<string>(), |
| 61 | + gateway: {} as QaSuiteRuntimeEnv["gateway"], |
| 62 | + transport: { |
| 63 | + id: "qa-channel", |
| 64 | + label: "QA Channel", |
| 65 | + accountId: "qa-channel", |
| 66 | + waitReady: vi.fn(), |
| 67 | + createGatewayConfig: vi.fn(), |
| 68 | + buildAgentDelivery: vi.fn(), |
| 69 | + requiredPluginIds: [], |
| 70 | + supportedActions: [], |
| 71 | + handleAction: vi.fn(), |
| 72 | + createReportNotes: vi.fn(), |
| 73 | + reset: vi.fn(), |
| 74 | + sendInbound: vi.fn(), |
| 75 | + sendNativeCommand: vi.fn(), |
| 76 | + waitForNoOutbound: vi.fn(), |
| 77 | + waitForOutbound: vi.fn(), |
| 78 | + waitForOutboundSequence: vi.fn(), |
| 79 | + state: { |
| 80 | + reset: vi.fn(), |
| 81 | + getSnapshot: vi.fn(), |
| 82 | + addInboundMessage: vi.fn(), |
| 83 | + addOutboundMessage: vi.fn(), |
| 84 | + readMessage: vi.fn(), |
| 85 | + searchMessages: vi.fn(), |
| 86 | + waitFor: vi.fn(), |
| 87 | + }, |
| 88 | + waitForCondition: vi.fn(), |
| 89 | + ...transportOverrides, |
| 90 | + }, |
| 91 | + outputDir: "/artifacts", |
| 92 | + repoRoot: "/repo", |
| 93 | + providerMode: "mock-openai", |
| 94 | + primaryModel: "openai/gpt-5.6-luna", |
| 95 | + alternateModel: "openai/gpt-5.6-luna-mini", |
| 96 | + mock: null, |
| 97 | + cfg: { |
| 98 | + agents: { |
| 99 | + defaults: { |
| 100 | + models: { |
| 101 | + "anthropic/claude-opus-5": { alias: "opus" }, |
| 102 | + }, |
| 103 | + }, |
| 104 | + }, |
| 105 | + }, |
| 106 | + } satisfies Parameters<typeof runQaSuiteScenarioDefinition>[0]["env"]; |
| 107 | +} |
| 108 | + |
48 | 109 | describe("qa suite runtime flow", () => { |
| 110 | + beforeEach(() => { |
| 111 | + vi.clearAllMocks(); |
| 112 | + }); |
| 113 | + |
49 | 114 | it("records intentional scenario skips without running later steps", async () => { |
50 | 115 | const laterStep = vi.fn(); |
51 | 116 | const result = await runQaSuiteScenarioSteps("requires group credentials", [ |
@@ -73,54 +138,7 @@ describe("qa suite runtime flow", () => { |
73 | 138 | }); |
74 | 139 |
|
75 | 140 | it("wires the split suite runtime deps into the scenario runtime api", async () => { |
76 | | - const env = { |
77 | | - lab: { baseUrl: "http://127.0.0.1:4444" }, |
78 | | - webSessionIds: new Set<string>(), |
79 | | - gateway: {} as QaSuiteRuntimeEnv["gateway"], |
80 | | - transport: { |
81 | | - id: "qa-channel", |
82 | | - label: "QA Channel", |
83 | | - accountId: "qa-channel", |
84 | | - waitReady: vi.fn(), |
85 | | - createGatewayConfig: vi.fn(), |
86 | | - buildAgentDelivery: vi.fn(), |
87 | | - requiredPluginIds: [], |
88 | | - supportedActions: [], |
89 | | - handleAction: vi.fn(), |
90 | | - createReportNotes: vi.fn(), |
91 | | - reset: vi.fn(), |
92 | | - sendInbound: vi.fn(), |
93 | | - sendNativeCommand: vi.fn(), |
94 | | - waitForNoOutbound: vi.fn(), |
95 | | - waitForOutbound: vi.fn(), |
96 | | - waitForOutboundSequence: vi.fn(), |
97 | | - state: { |
98 | | - reset: vi.fn(), |
99 | | - getSnapshot: vi.fn(), |
100 | | - addInboundMessage: vi.fn(), |
101 | | - addOutboundMessage: vi.fn(), |
102 | | - readMessage: vi.fn(), |
103 | | - searchMessages: vi.fn(), |
104 | | - waitFor: vi.fn(), |
105 | | - }, |
106 | | - waitForCondition: vi.fn(), |
107 | | - }, |
108 | | - outputDir: "/artifacts", |
109 | | - repoRoot: "/repo", |
110 | | - providerMode: "mock-openai", |
111 | | - primaryModel: "openai/gpt-5.6-luna", |
112 | | - alternateModel: "openai/gpt-5.6-luna-mini", |
113 | | - mock: null, |
114 | | - cfg: { |
115 | | - agents: { |
116 | | - defaults: { |
117 | | - models: { |
118 | | - "anthropic/claude-opus-5": { alias: "opus" }, |
119 | | - }, |
120 | | - }, |
121 | | - }, |
122 | | - }, |
123 | | - } satisfies Parameters<typeof runQaSuiteScenarioDefinition>[0]["env"]; |
| 141 | + const env = createQaSuiteRuntimeFlowTestEnv(); |
124 | 142 | const scenario = { |
125 | 143 | id: "session-memory-ranking", |
126 | 144 | title: "Session memory ranking", |
@@ -149,11 +167,7 @@ describe("qa suite runtime flow", () => { |
149 | 167 | formatErrorMessage, |
150 | 168 | liveTurnTimeoutMs, |
151 | 169 | resolveQaLiveTurnTimeoutMs, |
152 | | - constants: { |
153 | | - imageUnderstandingPngBase64: "small", |
154 | | - imageUnderstandingLargePngBase64: "large", |
155 | | - imageUnderstandingValidPngBase64: "valid", |
156 | | - }, |
| 170 | + constants: qaSuiteRuntimeFlowTestConstants, |
157 | 171 | }); |
158 | 172 |
|
159 | 173 | expect(result).toEqual({ api: "ok" }); |
@@ -260,4 +274,73 @@ describe("qa suite runtime flow", () => { |
260 | 274 | expect(webOpenPage).toHaveBeenCalledWith({ url: "https://openclaw.ai", repoRoot: "/repo" }); |
261 | 275 | expect(env.webSessionIds.has("page-1")).toBe(true); |
262 | 276 | }); |
| 277 | + |
| 278 | + it("records live transport preparation as the first shared flow step", async () => { |
| 279 | + const prepareFlow = vi.fn(async () => { |
| 280 | + throw new Error("setup failed"); |
| 281 | + }); |
| 282 | + const env = createQaSuiteRuntimeFlowTestEnv({ |
| 283 | + label: "Matrix live", |
| 284 | + prepareFlow, |
| 285 | + }); |
| 286 | + const scenario = makeQaSuiteTestScenario("matrix-preparation-failure", { |
| 287 | + channel: "matrix", |
| 288 | + config: { expected: "value" }, |
| 289 | + }); |
| 290 | + if (scenario.execution.kind !== "flow") { |
| 291 | + throw new Error("expected flow scenario"); |
| 292 | + } |
| 293 | + scenario.execution.timeoutMs = 45_000; |
| 294 | + const runScenario = vi.fn(runQaSuiteScenarioSteps); |
| 295 | + |
| 296 | + createQaScenarioRuntimeApi.mockReturnValueOnce({ api: "ok" }); |
| 297 | + await runQaSuiteScenarioDefinition({ |
| 298 | + env, |
| 299 | + scenario, |
| 300 | + runScenario, |
| 301 | + splitModelRef: (raw) => parseModelRef(raw, "openai"), |
| 302 | + formatErrorMessage: (error) => String(error), |
| 303 | + liveTurnTimeoutMs: () => 60_000, |
| 304 | + resolveQaLiveTurnTimeoutMs: () => 60_000, |
| 305 | + constants: qaSuiteRuntimeFlowTestConstants, |
| 306 | + }); |
| 307 | + |
| 308 | + expect(createQaScenarioRuntimeApi).toHaveBeenCalledTimes(1); |
| 309 | + const capturedCall = createQaScenarioRuntimeApi.mock.calls[0]?.[0]; |
| 310 | + if (!capturedCall) { |
| 311 | + throw new Error("expected QA scenario runtime API call"); |
| 312 | + } |
| 313 | + const capturedDeps = ( |
| 314 | + capturedCall as { |
| 315 | + deps: { |
| 316 | + runScenario: Parameters<typeof runQaSuiteScenarioDefinition>[0]["runScenario"]; |
| 317 | + }; |
| 318 | + } |
| 319 | + ).deps; |
| 320 | + const scenarioStep = vi.fn(async () => "not reached"); |
| 321 | + await expect( |
| 322 | + capturedDeps.runScenario("Matrix preparation", [{ name: "Scenario", run: scenarioStep }]), |
| 323 | + ).resolves.toEqual({ |
| 324 | + name: "Matrix preparation", |
| 325 | + status: "fail", |
| 326 | + steps: [{ name: "Prepare Matrix live", status: "fail", details: "setup failed" }], |
| 327 | + details: "setup failed", |
| 328 | + }); |
| 329 | + |
| 330 | + expect(runScenario).toHaveBeenCalledWith("Matrix preparation", [ |
| 331 | + { name: "Prepare Matrix live", run: expect.any(Function) }, |
| 332 | + { name: "Scenario", run: scenarioStep }, |
| 333 | + ]); |
| 334 | + expect(prepareFlow).toHaveBeenCalledWith({ |
| 335 | + config: { expected: "value" }, |
| 336 | + gateway: env.gateway, |
| 337 | + outputDir: "/artifacts", |
| 338 | + primaryModel: "openai/gpt-5.6-luna", |
| 339 | + scenarioId: "matrix-preparation-failure", |
| 340 | + scenarioTitle: "matrix-preparation-failure", |
| 341 | + timeoutMs: 45_000, |
| 342 | + waitForConfigRestartSettle: expect.any(Function), |
| 343 | + }); |
| 344 | + expect(scenarioStep).not.toHaveBeenCalled(); |
| 345 | + }); |
263 | 346 | }); |
0 commit comments