test: dedupe qa matrix cli mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 16:27:28 +01:00
parent 263d7cbf27
commit 2379da6cf1

View File

@@ -1990,7 +1990,9 @@ describe("matrix live qa scenarios", () => {
expect(artifacts.roomKey).toBe("e2ee-sync-state-loss-crypto-intact-recovery");
await expectPathMissing(syncStorePath);
expect(registerWithToken.mock.calls.at(0)?.[0]?.registrationToken).toBe("registration-token");
expect(mockObjectArg(registerWithToken, "registerWithToken").registrationToken).toBe(
"registration-token",
);
expect(createPrivateRoom).toHaveBeenCalledWith({
encrypted: true,
inviteUserIds: ["@observer:matrix-qa.test", "@sync-gateway:matrix-qa.test"],
@@ -4701,7 +4703,7 @@ describe("matrix live qa scenarios", () => {
expect(artifacts.secondaryDeviceId).toBe("CLIDEVICE");
expect(startMatrixQaOpenClawCli).toHaveBeenCalledTimes(1);
expect(startMatrixQaOpenClawCli.mock.calls.at(0)?.[0].args).toEqual([
expect(mockObjectArg(startMatrixQaOpenClawCli, "startMatrixQaOpenClawCli").args).toEqual([
"matrix",
"verify",
"self",
@@ -4710,19 +4712,29 @@ describe("matrix live qa scenarios", () => {
"--timeout-ms",
"8000",
]);
expect(startMatrixQaOpenClawCli.mock.calls.at(0)?.[0].timeoutMs).toBe(16_000);
expect(mockObjectArg(startMatrixQaOpenClawCli, "startMatrixQaOpenClawCli").timeoutMs).toBe(
16_000,
);
expect(waitForOutput).toHaveBeenCalledTimes(2);
expect(writeStdin).toHaveBeenCalledWith("yes\n");
expect(endStdin).toHaveBeenCalledTimes(1);
expect(wait).toHaveBeenCalledTimes(1);
expect(kill).toHaveBeenCalledTimes(1);
const registrationRequest = registerWithToken.mock.calls.at(0)?.[0];
const registrationRequest = mockObjectArg(registerWithToken, "registerWithToken");
expect(registrationRequest?.deviceName).toBe(
"OpenClaw Matrix QA CLI Self Verification Owner",
);
expect(registrationRequest?.localpart?.startsWith("qa-cli-self-verification-")).toBe(true);
expect(registrationRequest?.localpart).toHaveLength("qa-cli-self-verification-".length + 8);
expect(registrationRequest?.password?.startsWith("matrix-qa-")).toBe(true);
if (
typeof registrationRequest.localpart !== "string" ||
typeof registrationRequest.password !== "string"
) {
throw new Error("expected registration request credentials");
}
const registrationLocalpart = registrationRequest.localpart;
const registrationPassword = registrationRequest.password;
expect(registrationLocalpart.startsWith("qa-cli-self-verification-")).toBe(true);
expect(registrationLocalpart).toHaveLength("qa-cli-self-verification-".length + 8);
expect(registrationPassword.startsWith("matrix-qa-")).toBe(true);
expect(registrationRequest?.registrationToken).toBe("registration-token");
expect(loginWithPassword).toHaveBeenCalledWith({
deviceName: "OpenClaw Matrix QA CLI Self Verification Device",
@@ -4750,7 +4762,8 @@ describe("matrix live qa scenarios", () => {
["matrix", "verify", "status", "--account", "cli", "--json"],
]);
expect(runMatrixQaOpenClawCli.mock.calls.at(0)?.[0].stdin).toBe("encoded-recovery-key\n");
const cliEnv = startMatrixQaOpenClawCli.mock.calls.at(0)?.[0].env;
const cliEnv = mockObjectArg(startMatrixQaOpenClawCli, "startMatrixQaOpenClawCli")
.env as Record<string, unknown>;
expect(cliEnv?.OPENCLAW_STATE_DIR).toContain("openclaw-matrix-cli-qa-");
expect(cliEnv?.OPENCLAW_CONFIG_PATH).toContain("openclaw-matrix-cli-qa-");
const configPath = String(cliEnv?.OPENCLAW_CONFIG_PATH);
@@ -4915,10 +4928,12 @@ describe("matrix live qa scenarios", () => {
],
["matrix", "verify", "status", "--account", "cli-add-e2ee", "--json"],
]);
expect(registerWithToken.mock.calls.at(0)?.[0]?.deviceName).toBe(
expect(mockObjectArg(registerWithToken, "registerWithToken").deviceName).toBe(
"OpenClaw Matrix QA CLI Account Add Owner",
);
expect(registerWithToken.mock.calls.at(0)?.[0]?.registrationToken).toBe("registration-token");
expect(mockObjectArg(registerWithToken, "registerWithToken").registrationToken).toBe(
"registration-token",
);
const [cliRunDir] = await readdir(path.join(outputDir, "cli-account-add-enable-e2ee"));
const cliArtifactDir = path.join(outputDir, "cli-account-add-enable-e2ee", cliRunDir ?? "");
await expect(
@@ -5049,12 +5064,18 @@ describe("matrix live qa scenarios", () => {
["matrix", "encryption", "setup", "--account", "cli-encryption-setup", "--json"],
["matrix", "verify", "status", "--account", "cli-encryption-setup", "--json"],
]);
expect(registerWithToken.mock.calls.at(0)?.[0]?.deviceName).toBe(
expect(mockObjectArg(registerWithToken, "registerWithToken").deviceName).toBe(
"OpenClaw Matrix QA CLI Encryption Setup Owner",
);
expect(registerWithToken.mock.calls.at(0)?.[0]?.registrationToken).toBe("registration-token");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.password).toBe("cli-setup-password");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.userId).toBe("@cli-setup:matrix-qa.test");
expect(mockObjectArg(registerWithToken, "registerWithToken").registrationToken).toBe(
"registration-token",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").password).toBe(
"cli-setup-password",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").userId).toBe(
"@cli-setup:matrix-qa.test",
);
const [cliRunDir] = await readdir(path.join(outputDir, "cli-encryption-setup"));
const cliArtifactDir = path.join(outputDir, "cli-encryption-setup", cliRunDir ?? "");
await expect(
@@ -5169,12 +5190,16 @@ describe("matrix live qa scenarios", () => {
["matrix", "encryption", "setup", "--account", "cli-encryption-idempotent", "--json"],
["matrix", "encryption", "setup", "--account", "cli-encryption-idempotent", "--json"],
]);
expect(registerWithToken.mock.calls.at(0)?.[0]?.deviceName).toBe(
expect(mockObjectArg(registerWithToken, "registerWithToken").deviceName).toBe(
"OpenClaw Matrix QA CLI Encryption Idempotent Owner",
);
expect(registerWithToken.mock.calls.at(0)?.[0]?.registrationToken).toBe("registration-token");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.password).toBe("cli-idempotent-password");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.userId).toBe(
expect(mockObjectArg(registerWithToken, "registerWithToken").registrationToken).toBe(
"registration-token",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").password).toBe(
"cli-idempotent-password",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").userId).toBe(
"@cli-idempotent:matrix-qa.test",
);
const [cliRunDir] = await readdir(path.join(outputDir, "cli-encryption-setup-idempotent"));
@@ -5292,7 +5317,7 @@ describe("matrix live qa scenarios", () => {
search: "",
}),
).toBe(true);
expect(startMatrixQaOpenClawCli.mock.calls.at(0)?.[0].args).toEqual([
expect(mockObjectArg(startMatrixQaOpenClawCli, "startMatrixQaOpenClawCli").args).toEqual([
"matrix",
"encryption",
"setup",
@@ -5300,18 +5325,29 @@ describe("matrix live qa scenarios", () => {
"cli-encryption-failure",
"--json",
]);
expect(startMatrixQaOpenClawCli.mock.calls.at(0)?.[0].env.OPENCLAW_CONFIG_PATH).toContain(
"openclaw-matrix-e2ee-setup-qa-",
);
expect(
(
mockObjectArg(startMatrixQaOpenClawCli, "startMatrixQaOpenClawCli").env as Record<
string,
unknown
>
).OPENCLAW_CONFIG_PATH,
).toContain("openclaw-matrix-e2ee-setup-qa-");
expect(output).toHaveBeenCalledTimes(1);
expect(wait).toHaveBeenCalledTimes(1);
expect(kill).toHaveBeenCalledTimes(1);
expect(registerWithToken.mock.calls.at(0)?.[0]?.deviceName).toBe(
expect(mockObjectArg(registerWithToken, "registerWithToken").deviceName).toBe(
"OpenClaw Matrix QA CLI Encryption Failure Owner",
);
expect(registerWithToken.mock.calls.at(0)?.[0]?.registrationToken).toBe("registration-token");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.password).toBe("cli-failure-password");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.userId).toBe("@cli-failure:matrix-qa.test");
expect(mockObjectArg(registerWithToken, "registerWithToken").registrationToken).toBe(
"registration-token",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").password).toBe(
"cli-failure-password",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").userId).toBe(
"@cli-failure:matrix-qa.test",
);
expect(proxyStop).toHaveBeenCalledTimes(1);
const [cliRunDir] = await readdir(
path.join(outputDir, "cli-encryption-setup-bootstrap-failure"),
@@ -5475,12 +5511,18 @@ describe("matrix live qa scenarios", () => {
"--json",
],
]);
expect(registerWithToken.mock.calls.at(0)?.[0]?.deviceName).toBe(
expect(mockObjectArg(registerWithToken, "registerWithToken").deviceName).toBe(
"OpenClaw Matrix QA CLI Recovery Key Owner",
);
expect(registerWithToken.mock.calls.at(0)?.[0]?.registrationToken).toBe("registration-token");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.password).toBe("cli-recovery-password");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.userId).toBe("@cli-recovery:matrix-qa.test");
expect(mockObjectArg(registerWithToken, "registerWithToken").registrationToken).toBe(
"registration-token",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").password).toBe(
"cli-recovery-password",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").userId).toBe(
"@cli-recovery:matrix-qa.test",
);
expect(deleteOwnDevices).toHaveBeenCalledWith(["CLIRECOVERYDEVICE"]);
expect(stop).toHaveBeenCalledTimes(1);
const [cliRunDir] = await readdir(path.join(outputDir, "cli-recovery-key-setup"));
@@ -5589,7 +5631,7 @@ describe("matrix live qa scenarios", () => {
expect(artifacts.recoveryKeyRejected).toBe(true);
expect(artifacts.setupSuccess).toBe(false);
expect(startMatrixQaOpenClawCli.mock.calls.at(0)?.[0].args).toEqual([
expect(mockObjectArg(startMatrixQaOpenClawCli, "startMatrixQaOpenClawCli").args).toEqual([
"matrix",
"encryption",
"setup",
@@ -5602,12 +5644,18 @@ describe("matrix live qa scenarios", () => {
expect(output).toHaveBeenCalledTimes(1);
expect(wait).toHaveBeenCalledTimes(1);
expect(kill).toHaveBeenCalledTimes(1);
expect(registerWithToken.mock.calls.at(0)?.[0]?.deviceName).toBe(
expect(mockObjectArg(registerWithToken, "registerWithToken").deviceName).toBe(
"OpenClaw Matrix QA CLI Invalid Recovery Key Owner",
);
expect(registerWithToken.mock.calls.at(0)?.[0]?.registrationToken).toBe("registration-token");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.password).toBe("cli-invalid-password");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.userId).toBe("@cli-invalid:matrix-qa.test");
expect(mockObjectArg(registerWithToken, "registerWithToken").registrationToken).toBe(
"registration-token",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").password).toBe(
"cli-invalid-password",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").userId).toBe(
"@cli-invalid:matrix-qa.test",
);
expect(deleteOwnDevices).toHaveBeenCalledWith(["CLIINVALIDDEVICE"]);
expect(stop).toHaveBeenCalledTimes(1);
const [cliRunDir] = await readdir(path.join(outputDir, "cli-recovery-key-invalid"));
@@ -5713,12 +5761,18 @@ describe("matrix live qa scenarios", () => {
expect(runMatrixQaOpenClawCli.mock.calls.map(([params]) => params.args)).toEqual([
["matrix", "encryption", "setup", "--account", "cli-multi-target", "--json"],
]);
expect(registerWithToken.mock.calls.at(0)?.[0]?.deviceName).toBe(
expect(mockObjectArg(registerWithToken, "registerWithToken").deviceName).toBe(
"OpenClaw Matrix QA CLI Multi Account Owner",
);
expect(registerWithToken.mock.calls.at(0)?.[0]?.registrationToken).toBe("registration-token");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.password).toBe("cli-multi-password");
expect(loginWithPassword.mock.calls.at(0)?.[0]?.userId).toBe("@cli-multi:matrix-qa.test");
expect(mockObjectArg(registerWithToken, "registerWithToken").registrationToken).toBe(
"registration-token",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").password).toBe(
"cli-multi-password",
);
expect(mockObjectArg(loginWithPassword, "loginWithPassword").userId).toBe(
"@cli-multi:matrix-qa.test",
);
const [cliRunDir] = await readdir(path.join(outputDir, "cli-encryption-setup-multi-account"));
const cliArtifactDir = path.join(
outputDir,