Skip to content

Commit 6804b7c

Browse files
committed
fix(matrix): ignore invalid device timestamps
1 parent 63470e9 commit 6804b7c

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

extensions/matrix/src/cli.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,28 @@ describe("matrix CLI verification commands", () => {
950950
expect(console.log).toHaveBeenCalledWith("- BritdXC6iL (OpenClaw Gateway)");
951951
});
952952

953+
it("omits invalid matrix device last seen timestamps", async () => {
954+
listMatrixOwnDevicesMock.mockResolvedValue([
955+
{
956+
deviceId: "DEVICE123",
957+
displayName: "OpenClaw Gateway",
958+
lastSeenIp: "127.0.0.1",
959+
lastSeenTs: 8_700_000_000_000_000,
960+
current: true,
961+
},
962+
]);
963+
const program = buildProgram();
964+
965+
await program.parseAsync(["matrix", "devices", "list", "--account", "poe"], { from: "user" });
966+
967+
expect(console.log).toHaveBeenCalledWith("Account: poe");
968+
expect(console.log).toHaveBeenCalledWith("- DEVICE123 (current, OpenClaw Gateway)");
969+
expect(console.log).toHaveBeenCalledWith(" Last IP: 127.0.0.1");
970+
expect(
971+
consoleLogMock.mock.calls.some(([message]) => String(message).startsWith(" Last seen:")),
972+
).toBe(false);
973+
});
974+
953975
it("prunes stale matrix gateway devices", async () => {
954976
pruneMatrixStaleGatewayDevicesMock.mockResolvedValue({
955977
before: [

extensions/matrix/src/cli.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Command } from "commander";
22
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
3-
import { parseStrictInteger } from "openclaw/plugin-sdk/number-runtime";
3+
import { parseStrictInteger, timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime";
44
import type { ChannelSetupInput } from "openclaw/plugin-sdk/setup";
55
import { resolveMatrixAccount, resolveMatrixAccountConfig } from "./matrix/accounts.js";
66
import { listMatrixOwnDevices, pruneMatrixStaleGatewayDevices } from "./matrix/actions/devices.js";
@@ -216,8 +216,9 @@ function printMatrixOwnDevices(
216216
console.log(
217217
`- ${formatMatrixCliText(device.deviceId)}${labels.length ? ` (${labels.join(", ")})` : ""}`,
218218
);
219-
if (device.lastSeenTs) {
220-
printTimestamp(" Last seen", new Date(device.lastSeenTs).toISOString());
219+
const lastSeenAt = timestampMsToIsoString(device.lastSeenTs);
220+
if (lastSeenAt) {
221+
printTimestamp(" Last seen", lastSeenAt);
221222
}
222223
if (device.lastSeenIp) {
223224
console.log(` Last IP: ${formatMatrixCliText(device.lastSeenIp)}`);

0 commit comments

Comments
 (0)