mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:58:27 +00:00
fix(presence): stabilize instance identity
This commit is contained in:
40
src/infra/system-presence.test.ts
Normal file
40
src/infra/system-presence.test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
listSystemPresence,
|
||||
updateSystemPresence,
|
||||
upsertPresence,
|
||||
} from "./system-presence.js";
|
||||
|
||||
describe("system-presence", () => {
|
||||
it("dedupes entries across sources by case-insensitive instanceId key", () => {
|
||||
const instanceIdUpper = `AaBb-${randomUUID()}`.toUpperCase();
|
||||
const instanceIdLower = instanceIdUpper.toLowerCase();
|
||||
|
||||
upsertPresence(instanceIdUpper, {
|
||||
host: "clawdis-mac",
|
||||
mode: "app",
|
||||
instanceId: instanceIdUpper,
|
||||
reason: "connect",
|
||||
});
|
||||
|
||||
updateSystemPresence({
|
||||
text: "Node: Peter-Mac-Studio (10.0.0.1) · app 2.0.0 · last input 5s ago · mode app · reason beacon",
|
||||
instanceId: instanceIdLower,
|
||||
host: "Peter-Mac-Studio",
|
||||
ip: "10.0.0.1",
|
||||
mode: "app",
|
||||
version: "2.0.0",
|
||||
lastInputSeconds: 5,
|
||||
reason: "beacon",
|
||||
});
|
||||
|
||||
const matches = listSystemPresence().filter(
|
||||
(e) => (e.instanceId ?? "").toLowerCase() === instanceIdLower,
|
||||
);
|
||||
expect(matches).toHaveLength(1);
|
||||
expect(matches[0]?.host).toBe("Peter-Mac-Studio");
|
||||
expect(matches[0]?.ip).toBe("10.0.0.1");
|
||||
expect(matches[0]?.lastInputSeconds).toBe(5);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user