Skip to content

Commit 2857eaa

Browse files
authored
fix(qa): reset Matrix scenario streaming state (#116454)
1 parent d24cdea commit 2857eaa

4 files changed

Lines changed: 45 additions & 18 deletions

File tree

‎extensions/qa-lab/src/live-transports/matrix/scenarios/scenario-environment.test.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ import { afterEach, describe, expect, it, vi } from "vitest";
44
const buildMatrixQaConfig = vi.hoisted(() =>
55
vi.fn(() => ({ channels: { matrix: { execApprovals: { enabled: true } } } })),
66
);
7+
const runMatrixQaCanary = vi.hoisted(() =>
8+
vi.fn(async () => ({
9+
driverEventId: "$canary-driver",
10+
reply: { eventId: "$canary-reply" },
11+
token: "MATRIX_QA_CANARY",
12+
})),
13+
);
714

815
vi.mock("../substrate/config.js", () => ({ buildMatrixQaConfig }));
9-
vi.mock("./scenario-runtime-room.js", () => ({ runMatrixQaCanary: vi.fn() }));
16+
vi.mock("./scenario-runtime-room.js", () => ({ runMatrixQaCanary }));
1017

1118
import { createMatrixQaScenarioEnvironment } from "./scenario-environment.js";
1219
import type { MatrixQaScenarioContext } from "./scenario-runtime-shared.js";
@@ -74,12 +81,12 @@ describe("matrix scenario environment", () => {
7481
} as never,
7582
});
7683
const input = {
77-
config: {},
84+
config: { matrixRequireCanary: true },
7885
gateway,
7986
outputDir: "/tmp/matrix-qa/output",
8087
scenarioId: "matrix-observer-reset",
8188
scenarioTitle: "Matrix observer reset",
82-
timeoutMs: 1_000,
89+
timeoutMs: 8_000,
8390
waitForConfigRestartSettle: vi.fn(),
8491
};
8592
const first = await environment.prepareFlow(input);
@@ -93,6 +100,7 @@ describe("matrix scenario environment", () => {
93100

94101
expect(second.scenarioContext.syncState).toEqual({});
95102
expect(second.scenarioContext.syncStreams).toEqual({});
103+
expect(runMatrixQaCanary).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: 60_000 }));
96104
});
97105

98106
it("waits for the changed Matrix account to restart before accepting readiness", async () => {

‎extensions/qa-lab/src/live-transports/matrix/scenarios/scenario-environment.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type AdapterDefinition = Awaited<ReturnType<AdapterFactory["create"]>>;
1818
type FlowPreparationInput = Parameters<NonNullable<AdapterDefinition["prepareFlow"]>>[0];
1919
type MatrixQaHarness = Awaited<ReturnType<typeof startMatrixQaHarness>>;
2020

21+
const MATRIX_QA_CANARY_TIMEOUT_MS = 60_000;
22+
2123
type MatrixQaScenarioEnvironmentParams = {
2224
accountId: string;
2325
harness: MatrixQaHarness;
@@ -396,7 +398,12 @@ export function createMatrixQaScenarioEnvironment(params: MatrixQaScenarioEnviro
396398
}),
397399
} satisfies MatrixQaScenarioContext;
398400
if (input.config.matrixRequireCanary === true && !canary) {
399-
canary = await runMatrixQaCanary(scenarioContext);
401+
canary = await runMatrixQaCanary({
402+
...scenarioContext,
403+
// The scenario timeout can intentionally be a short no-reply window.
404+
// A live model round trip needs its own bounded preparation budget.
405+
timeoutMs: Math.max(input.timeoutMs, MATRIX_QA_CANARY_TIMEOUT_MS),
406+
});
400407
}
401408
scenarioContext.canary = canary;
402409
return { scenarioContext };

‎extensions/qa-lab/src/live-transports/matrix/substrate/config.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ describe("matrix qa config", () => {
7373
requireMention: true,
7474
});
7575
expect(sut?.replyToMode).toBe("off");
76+
expect(sut?.streaming).toEqual({
77+
block: { enabled: false },
78+
chunkMode: "length",
79+
mode: "off",
80+
preview: { toolProgress: true },
81+
});
7682
expect(sut?.threadReplies).toBe("inbound");
7783
expect(next.messages?.groupChat?.visibleReplies).toBe("automatic");
7884
});
@@ -233,7 +239,12 @@ describe("matrix qa config", () => {
233239

234240
expect(reset.channels?.matrix?.accounts?.sut?.autoJoin).toBeUndefined();
235241
expect(reset.channels?.matrix?.accounts?.sut?.autoJoinAllowlist).toBeUndefined();
236-
expect(reset.channels?.matrix?.accounts?.sut?.streaming).toBeUndefined();
242+
expect(reset.channels?.matrix?.accounts?.sut?.streaming).toEqual({
243+
block: { enabled: false },
244+
chunkMode: "length",
245+
mode: "off",
246+
preview: { toolProgress: true },
247+
});
237248
});
238249

239250
it("normalizes Matrix QA overrides into the written account config", () => {
@@ -264,6 +275,7 @@ describe("matrix qa config", () => {
264275
expect(account?.groupPolicy).toBe("open");
265276
expect(account?.streaming).toEqual({
266277
block: { enabled: true },
278+
chunkMode: "length",
267279
mode: "partial",
268280
preview: { toolProgress: true },
269281
});
@@ -298,10 +310,14 @@ describe("matrix qa config", () => {
298310
});
299311

300312
expect(optedOut.channels?.matrix?.accounts?.sut?.streaming).toEqual({
313+
block: { enabled: false },
314+
chunkMode: "length",
301315
mode: "quiet",
302316
preview: { toolProgress: false },
303317
});
304318
expect(reset.channels?.matrix?.accounts?.sut?.streaming).toEqual({
319+
block: { enabled: false },
320+
chunkMode: "length",
305321
mode: "quiet",
306322
preview: { toolProgress: true },
307323
});

‎extensions/qa-lab/src/live-transports/matrix/substrate/config.ts‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -437,20 +437,16 @@ function buildMatrixQaChannelAccountConfig(params: {
437437
);
438438
// Matrix accepts only the nested streaming shape; harness overrides keep
439439
// their scalar/boolean vocabulary and normalize here before config write.
440-
const streamingSlots = {
441-
...(params.overrides?.streaming !== undefined
442-
? {
443-
mode: resolveMatrixQaStreamingMode(params.overrides.streaming),
444-
preview: { toolProgress: params.snapshot.streamingPreviewToolProgress },
445-
}
446-
: {}),
447-
...(params.snapshot.chunkMode !== undefined ? { chunkMode: params.snapshot.chunkMode } : {}),
448-
...(params.overrides?.blockStreaming !== undefined
449-
? { block: { enabled: params.snapshot.blockStreaming } }
450-
: {}),
440+
// Scenario config is applied with config.patch, which recursively merges objects.
441+
// Write every slot so a prior streaming scenario cannot leak into the next one.
442+
const streamingConfig = {
443+
streaming: {
444+
block: { enabled: params.snapshot.blockStreaming },
445+
chunkMode: params.snapshot.chunkMode ?? "length",
446+
mode: params.snapshot.streaming,
447+
preview: { toolProgress: params.snapshot.streamingPreviewToolProgress },
448+
},
451449
};
452-
const streamingConfig =
453-
Object.keys(streamingSlots).length > 0 ? { streaming: streamingSlots } : {};
454450
const startupVerificationConfig =
455451
params.snapshot.startupVerification !== undefined
456452
? { startupVerification: params.snapshot.startupVerification }

0 commit comments

Comments
 (0)