Skip to content

Commit aaa870f

Browse files
committed
test(qa): record Matrix route state inventory
1 parent 0869edc commit aaa870f

15 files changed

Lines changed: 2021 additions & 73 deletions

‎docs/concepts/qa-matrix.md‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ Plain `pnpm openclaw qa matrix` runs `--profile all` and does not stop on first
2323

2424
## What the lane does
2525

26-
1. Provisions a disposable Tuwunel homeserver in Docker (default image `ghcr.io/matrix-construct/tuwunel:v1.5.1`, server name `matrix-qa.test`, port `28008`).
26+
1. Provisions a disposable Tuwunel homeserver in Docker (default image `ghcr.io/matrix-construct/tuwunel:v1.5.1`, server name `matrix-qa.test`, port `28008`) behind a bounded redacting request/response recorder.
2727
2. Registers three temporary users - `driver` (sends inbound traffic), `sut` (the OpenClaw Matrix account under test), `observer` (third-party traffic capture).
2828
3. Seeds rooms required by the selected scenarios (main, threading, media, restart, secondary, allowlist, E2EE, verification DM, etc.).
29-
4. Starts a child OpenClaw gateway with the real Matrix plugin scoped to the SUT account; `qa-channel` is not loaded in the child.
30-
5. Runs scenarios in sequence, observing events through the driver/observer Matrix clients.
31-
6. Tears down the homeserver, writes report and summary artifacts, then exits.
29+
4. Runs the substrate-neutral `matrix-qa-v1` protocol probe against the recorded Tuwunel boundary. Unit tests prove the probe contract with the Matrix protocol fixture; the canonical QA transport adapter host in [#99707](https://github.com/openclaw/openclaw/pull/99707) owns real Crabline target wiring.
30+
5. Starts a child OpenClaw gateway with the real Matrix plugin scoped to the SUT account; `qa-channel` is not loaded in the child.
31+
6. Runs scenarios in sequence, observing events through the driver/observer Matrix clients and deriving route/state expectations from the recorded traffic.
32+
7. Tears down the homeserver, writes report and evidence artifacts, then exits.
3233

3334
## CLI
3435

@@ -38,14 +39,14 @@ pnpm openclaw qa matrix [options]
3839

3940
### Common flags
4041

41-
| Flag | Default | Description |
42-
| --------------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
43-
| `--profile <profile>` | `all` | Scenario profile. See [Profiles](#profiles). |
44-
| `--fail-fast` | off | Stop after the first failed check or scenario. |
45-
| `--scenario <id>` | - | Run only this scenario. Repeatable. See [Scenarios](#scenarios). |
46-
| `--output-dir <path>` | `<repo>/.artifacts/qa-e2e/matrix-<timestamp>` | Where reports, summary, observed events, and the output log are written. Relative paths resolve against `--repo-root`. |
47-
| `--repo-root <path>` | `process.cwd()` | Repository root when invoking from a neutral working directory. |
48-
| `--sut-account <id>` | `sut` | Matrix account id inside the QA gateway config. |
42+
| Flag | Default | Description |
43+
| --------------------- | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
44+
| `--profile <profile>` | `all` | Scenario profile. See [Profiles](#profiles). |
45+
| `--fail-fast` | off | Stop after the first failed check or scenario. |
46+
| `--scenario <id>` | - | Run only this scenario. Repeatable. See [Scenarios](#scenarios). |
47+
| `--output-dir <path>` | `<repo>/.artifacts/qa-e2e/matrix-<timestamp>` | Where reports, summary, route/state inventory, observed events, and the output log are written. Relative paths resolve against `--repo-root`. |
48+
| `--repo-root <path>` | `process.cwd()` | Repository root when invoking from a neutral working directory. |
49+
| `--sut-account <id>` | `sut` | Matrix account id inside the QA gateway config. |
4950

5051
### Provider flags
5152

@@ -114,6 +115,7 @@ Written to `--output-dir`:
114115

115116
- `matrix-qa-report.md` - Markdown protocol report (what passed, failed, was skipped, and why).
116117
- `matrix-qa-summary.json` - Structured summary suitable for CI parsing and dashboards.
118+
- `matrix-qa-route-state-manifest.json` - Dynamic `matrix-qa-v1` inventory keyed by scenario id. It records redacted route/body shapes, request ordering, observed retries, errors, sync-token continuity, and device/key/media/backup state families observed during that run. This is executable evidence, not a checked-in baseline.
117119
- `matrix-qa-observed-events.json` - Observed Matrix events from the driver and observer clients. Bodies are redacted unless `OPENCLAW_QA_MATRIX_CAPTURE_CONTENT=1`; approval metadata is summarized with selected safe fields and truncated command preview.
118120
- `matrix-qa-output.log` - Combined stdout/stderr from the run. If `OPENCLAW_RUN_NODE_OUTPUT_LOG` is set, the outer launcher's log is reused instead.
119121

‎extensions/qa-matrix/src/cli.runtime.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe("matrix qa cli runtime", () => {
6363
reportPath: "/tmp/matrix-report.md",
6464
summaryPath: "/tmp/matrix-summary.json",
6565
observedEventsPath: "/tmp/matrix-events.json",
66+
routeStateManifestPath: "/tmp/matrix-route-state.json",
6667
});
6768
const originalStdoutWrite = process.stdout["write"];
6869
process.stdout.write = (() => true) as typeof process.stdout.write;
@@ -104,6 +105,7 @@ describe("matrix qa cli runtime", () => {
104105
reportPath: "/tmp/matrix-report.md",
105106
summaryPath: "/tmp/matrix-summary.json",
106107
observedEventsPath: "/tmp/matrix-events.json",
108+
routeStateManifestPath: "/tmp/matrix-route-state.json",
107109
});
108110
const originalStdoutWrite = process.stdout["write"];
109111
process.stdout.write = vi.fn(() => true) as unknown as typeof process.stdout.write;

‎extensions/qa-matrix/src/cli.runtime.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export async function runQaMatrixCommand(opts: LiveTransportQaCommandOptions) {
7272
const result = await runMatrixQaLive(checkedRunOptions);
7373
printLiveTransportQaArtifacts("Matrix QA", {
7474
report: result.reportPath,
75+
"route/state manifest": result.routeStateManifestPath,
7576
summary: result.summaryPath,
7677
"observed events": result.observedEventsPath,
7778
});

‎extensions/qa-matrix/src/runners/contract/runtime.test.ts‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function buildMatrixQaSummaryInput(
3737
artifactPaths: {
3838
observedEvents: "/tmp/observed.json",
3939
report: "/tmp/report.md",
40+
routeStateManifest: "/tmp/route-state.json",
4041
summary: "/tmp/summary.json",
4142
},
4243
checks: [{ name: "Matrix harness ready", status: "pass" }],
@@ -53,6 +54,11 @@ function buildMatrixQaSummaryInput(
5354
}),
5455
scenarios: [],
5556
},
57+
differentialProbe: {
58+
profile: "matrix-qa-v1",
59+
steps: [],
60+
sync: { continuity: true, incrementalStatus: 200, initialStatus: 200 },
61+
},
5662
finishedAt: "2026-04-10T10:05:00.000Z",
5763
harness: {
5864
baseUrl: "http://127.0.0.1:28008/",
@@ -78,6 +84,25 @@ function buildMatrixQaSummaryInput(
7884
}
7985

8086
describe("matrix live qa runtime", () => {
87+
it("preserves a failed differential probe check without a probe payload", () => {
88+
const summary = liveTesting.buildMatrixQaSummary(
89+
buildMatrixQaSummaryInput({
90+
checks: [
91+
{ name: "Matrix harness ready", status: "pass" },
92+
{
93+
details: "missing-state response did not return M_NOT_FOUND",
94+
name: "Matrix differential probe",
95+
status: "fail",
96+
},
97+
],
98+
differentialProbe: undefined,
99+
}),
100+
);
101+
102+
expect(summary.differentialProbe).toBeUndefined();
103+
expect(summary.counts).toEqual({ failed: 1, passed: 1, total: 2 });
104+
});
105+
81106
it("uses unique default artifact directories", () => {
82107
const repoRoot = "/repo";
83108
const firstOutputDir = liveTesting.resolveMatrixQaOutputDir({ repoRoot });
@@ -86,9 +111,9 @@ describe("matrix live qa runtime", () => {
86111
expect(path.dirname(firstOutputDir)).toBe(path.join(repoRoot, ".artifacts", "qa-e2e"));
87112
expect(path.basename(firstOutputDir)).toMatch(/^matrix-[a-z0-9]+-[a-f0-9]{8}$/u);
88113
expect(secondOutputDir).not.toBe(firstOutputDir);
89-
expect(
90-
liveTesting.resolveMatrixQaOutputDir({ outputDir: ".artifacts/custom", repoRoot }),
91-
).toBe(".artifacts/custom");
114+
expect(liveTesting.resolveMatrixQaOutputDir({ outputDir: ".artifacts/custom", repoRoot })).toBe(
115+
".artifacts/custom",
116+
);
92117
});
93118

94119
it("prints Matrix QA progress by default for non-interactive runs", () => {
@@ -388,6 +413,7 @@ describe("matrix live qa runtime", () => {
388413
artifactPaths: {
389414
observedEvents: "/tmp/observed.json",
390415
report: "/tmp/report.md",
416+
routeStateManifest: "/tmp/route-state.json",
391417
summary: "/tmp/summary.json",
392418
},
393419
checks: [{ name: "Matrix harness ready", status: "pass" }],
@@ -450,6 +476,11 @@ describe("matrix live qa runtime", () => {
450476
},
451477
],
452478
},
479+
differentialProbe: {
480+
profile: "matrix-qa-v1",
481+
steps: [],
482+
sync: { continuity: true, incrementalStatus: 200, initialStatus: 200 },
483+
},
453484
finishedAt: "2026-04-10T10:05:00.000Z",
454485
harness: {
455486
baseUrl: "http://127.0.0.1:28008/",

‎extensions/qa-matrix/src/runners/contract/runtime.ts‎

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
type QaReportCheck,
1919
} from "openclaw/plugin-sdk/qa-runtime";
2020
import { normalizeQaProviderMode, type QaProviderModeInput } from "../../run-config.js";
21+
import { createLiveTransportQaRunId } from "../../shared/live-transport-artifacts.js";
2122
import { buildMatrixQaObservedEventsArtifact } from "../../substrate/artifacts.js";
2223
import { provisionMatrixQaRoom, type MatrixQaProvisionResult } from "../../substrate/client.js";
2324
import {
@@ -27,9 +28,12 @@ import {
2728
type MatrixQaConfigOverrides,
2829
type MatrixQaConfigSnapshot,
2930
} from "../../substrate/config.js";
31+
import {
32+
runMatrixQaDifferentialProbe,
33+
type MatrixQaDifferentialProbeResult,
34+
} from "../../substrate/differential-probe.js";
3035
import type { MatrixQaObservedEvent } from "../../substrate/events.js";
3136
import { startMatrixQaHarness } from "../../substrate/harness.runtime.js";
32-
import { createLiveTransportQaRunId } from "../../shared/live-transport-artifacts.js";
3337
import { resolveMatrixQaModels, type ResolvedMatrixQaModels } from "./model-selection.js";
3438
import type { MatrixQaSyncStreams } from "./scenario-runtime-shared.js";
3539
import {
@@ -135,9 +139,11 @@ type MatrixQaSummary = {
135139
serverName: string;
136140
};
137141
canary?: MatrixQaCanaryArtifact;
142+
differentialProbe?: MatrixQaDifferentialProbeResult;
138143
observedEventCount: number;
139144
observedEventsPath: string;
140145
reportPath: string;
146+
routeStateManifestPath: string;
141147
scenarios: MatrixQaScenarioResult[];
142148
startedAt: string;
143149
summaryPath: string;
@@ -153,6 +159,7 @@ type MatrixQaSummary = {
153159
type MatrixQaArtifactPaths = {
154160
observedEvents: string;
155161
report: string;
162+
routeStateManifest: string;
156163
summary: string;
157164
};
158165

@@ -468,6 +475,7 @@ type MatrixQaRunResult = {
468475
observedEventsPath: string;
469476
outputDir: string;
470477
reportPath: string;
478+
routeStateManifestPath: string;
471479
scenarios: MatrixQaScenarioResult[];
472480
summaryPath: string;
473481
};
@@ -477,6 +485,7 @@ function buildMatrixQaSummary(params: {
477485
canary?: MatrixQaCanaryArtifact;
478486
checks: QaReportCheck[];
479487
config: MatrixQaSummary["config"];
488+
differentialProbe?: MatrixQaDifferentialProbeResult;
480489
finishedAt: string;
481490
harness: MatrixQaSummary["harness"];
482491
observedEventCount: number;
@@ -500,9 +509,11 @@ function buildMatrixQaSummary(params: {
500509
finishedAt: params.finishedAt,
501510
harness: params.harness,
502511
canary: params.canary,
512+
differentialProbe: params.differentialProbe,
503513
observedEventCount: params.observedEventCount,
504514
observedEventsPath: params.artifactPaths.observedEvents,
505515
reportPath: params.artifactPaths.report,
516+
routeStateManifestPath: params.artifactPaths.routeStateManifest,
506517
scenarios: params.scenarios,
507518
startedAt: params.startedAt,
508519
summaryPath: params.artifactPaths.summary,
@@ -729,7 +740,6 @@ export async function runMatrixQaLive(params: {
729740
writeMatrixQaProgress(
730741
`topology ready ${formatMatrixQaDurationMs(provisioningMs)} rooms=${provisioning.topology.rooms.length}`,
731742
);
732-
733743
const checks: QaReportCheck[] = [
734744
{
735745
name: "Matrix harness ready",
@@ -743,6 +753,28 @@ export async function runMatrixQaLive(params: {
743753
].join("\n"),
744754
},
745755
];
756+
harness.recording.setScenarioId("matrix-qa-v1-probe");
757+
let differentialProbe: MatrixQaDifferentialProbeResult | undefined;
758+
try {
759+
differentialProbe = await withMatrixQaRunDeadline(
760+
runDeadline,
761+
"Matrix differential probe",
762+
() =>
763+
runMatrixQaDifferentialProbe({
764+
accessToken: provisioning.driver.accessToken,
765+
baseUrl: harness.baseUrl,
766+
roomId: provisioning.roomId,
767+
userId: provisioning.driver.userId,
768+
}),
769+
);
770+
checks.push({ name: "Matrix differential probe", status: "pass" });
771+
} catch (error) {
772+
checks.push({
773+
details: error instanceof Error ? error.message : String(error),
774+
name: "Matrix differential probe",
775+
status: "fail",
776+
});
777+
}
746778
const scenarioResults: Array<MatrixQaScenarioResult | undefined> = Array.from({
747779
length: scenarios.length,
748780
});
@@ -755,7 +787,7 @@ export async function runMatrixQaLive(params: {
755787
const syncState: { driver?: string; observer?: string } = {};
756788
const syncStreams: MatrixQaSyncStreams = {};
757789
let canaryMs: number | undefined;
758-
let initialGatewayBootMs;
790+
let initialGatewayBootMs = 0;
759791
let scenarioGatewayBootMs = 0;
760792
let scenarioRestartGatewayMs = 0;
761793
let scenarioTransportInterruptMs = 0;
@@ -777,7 +809,12 @@ export async function runMatrixQaLive(params: {
777809

778810
const scheduledScenarios = scheduleMatrixQaScenariosInCatalogOrder(scenarios);
779811

780-
try {
812+
matrixQaExecution: try {
813+
if (params.failFast && !differentialProbe) {
814+
writeMatrixQaProgress("fail-fast stop");
815+
break matrixQaExecution;
816+
}
817+
harness.recording.setScenarioId("canary");
781818
const ensureGatewayHarness = async (selection: MatrixQaGatewaySelection = {}) => {
782819
const models = resolveMatrixQaGatewayModels({
783820
defaultModels,
@@ -890,6 +927,7 @@ export async function runMatrixQaLive(params: {
890927

891928
if (!canaryFailed) {
892929
for (const { scenario, originalIndex } of scheduledScenarios) {
930+
harness.recording.setScenarioId(scenario.id);
893931
const { entry: scenarioConfigEntry, summary: scenarioConfigSummary } =
894932
buildMatrixQaScenarioConfigEntry({
895933
gatewayConfigParams,
@@ -916,6 +954,8 @@ export async function runMatrixQaLive(params: {
916954
driverDeviceId: provisioning.driver.deviceId,
917955
driverPassword: provisioning.driver.password,
918956
driverUserId: provisioning.driver.userId,
957+
faultProxyObserver: harness.recording,
958+
faultProxyTargetBaseUrl: harness.upstreamBaseUrl,
919959
interruptTransport: async () => {
920960
writeMatrixQaProgress(`transport interrupt start ${scenario.id}`);
921961
const measuredInterrupt = await measureMatrixQaStep(async () => {
@@ -1079,6 +1119,7 @@ export async function runMatrixQaLive(params: {
10791119
}
10801120
}
10811121
} finally {
1122+
harness.recording.setScenarioId("cleanup");
10821123
if (gatewayHarness) {
10831124
try {
10841125
const shouldPreserveGatewayDebugArtifacts =
@@ -1137,11 +1178,22 @@ export async function runMatrixQaLive(params: {
11371178
const reportPath = path.join(outputDir, "matrix-qa-report.md");
11381179
const summaryPath = path.join(outputDir, "matrix-qa-summary.json");
11391180
const observedEventsPath = path.join(outputDir, "matrix-qa-observed-events.json");
1181+
const routeStateManifestPath = path.join(outputDir, "matrix-qa-route-state-manifest.json");
11401182
const artifactPaths = {
11411183
observedEvents: observedEventsPath,
11421184
report: reportPath,
1185+
routeStateManifest: routeStateManifestPath,
11431186
summary: summaryPath,
11441187
} satisfies MatrixQaArtifactPaths;
1188+
const routeStateManifest = harness.recording.buildManifest({
1189+
generatedAt: finishedAt,
1190+
requestedProfile: params.profile?.trim() || "all",
1191+
scenarioIds: completedScenarioResults.map((scenario) => scenario.id),
1192+
substrate: {
1193+
id: "tuwunel",
1194+
version: harness.image,
1195+
},
1196+
});
11451197
const report = renderQaMarkdownReport({
11461198
title: "Matrix QA Report",
11471199
startedAt: startedAtDate,
@@ -1173,6 +1225,7 @@ export async function runMatrixQaLive(params: {
11731225
default: defaultConfigSnapshot,
11741226
scenarios: scenarioConfigSnapshots,
11751227
},
1228+
differentialProbe,
11761229
finishedAt,
11771230
harness: {
11781231
baseUrl: harness.baseUrl,
@@ -1221,6 +1274,10 @@ export async function runMatrixQaLive(params: {
12211274
)}\n`,
12221275
{ encoding: "utf8", mode: 0o600 },
12231276
);
1277+
await fs.writeFile(routeStateManifestPath, `${JSON.stringify(routeStateManifest, null, 2)}\n`, {
1278+
encoding: "utf8",
1279+
mode: 0o600,
1280+
});
12241281
summary.timings.artifactWriteMs = Date.now() - artifactWriteStartedAtMs;
12251282
summary.timings.totalMs = Date.now() - runStartedAtMs;
12261283
await fs.writeFile(summaryPath, `${JSON.stringify(summary, null, 2)}\n`, {
@@ -1263,6 +1320,7 @@ export async function runMatrixQaLive(params: {
12631320
observedEventsPath,
12641321
outputDir,
12651322
reportPath,
1323+
routeStateManifestPath,
12661324
scenarios: completedScenarioResults,
12671325
summaryPath,
12681326
};

0 commit comments

Comments
 (0)