Matrix: match migration device ids to resolved creds

This commit is contained in:
Gustavo Madeira Santana
2026-03-12 02:40:28 +00:00
parent 690bea5e3d
commit d4847c0163
2 changed files with 58 additions and 1 deletions

View File

@@ -0,0 +1,57 @@
import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { withTempHome } from "../../test/helpers/temp-home.js";
import type { OpenClawConfig } from "../config/config.js";
import { resolveMatrixMigrationAccountTarget } from "./matrix-migration-config.js";
function writeFile(filePath: string, value: string) {
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, value, "utf8");
}
describe("resolveMatrixMigrationAccountTarget", () => {
it("ignores stored device IDs from stale cached Matrix credentials", async () => {
await withTempHome(async (home) => {
const stateDir = path.join(home, ".openclaw");
writeFile(
path.join(stateDir, "credentials", "matrix", "credentials-ops.json"),
JSON.stringify(
{
homeserver: "https://matrix.example.org",
userId: "@old-bot:example.org",
accessToken: "tok-old",
deviceId: "DEVICE-OLD",
},
null,
2,
),
);
const cfg: OpenClawConfig = {
channels: {
matrix: {
accounts: {
ops: {
homeserver: "https://matrix.example.org",
userId: "@new-bot:example.org",
accessToken: "tok-new",
},
},
},
},
};
const target = resolveMatrixMigrationAccountTarget({
cfg,
env: process.env,
accountId: "ops",
});
expect(target).not.toBeNull();
expect(target?.userId).toBe("@new-bot:example.org");
expect(target?.accessToken).toBe("tok-new");
expect(target?.storedDeviceId).toBeNull();
});
});
});

View File

@@ -211,7 +211,7 @@ export function resolveMatrixMigrationAccountTarget(params: {
userId,
accessToken,
rootDir,
storedDeviceId: stored?.deviceId ?? null,
storedDeviceId: matchingStored?.deviceId ?? null,
};
}