mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 11:47:41 +00:00
refactor: centralize presence routing and version precedence coverage (#19609)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 10d9df5263
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
5c69e625f5
commit
07fdceb5fd
@@ -1,8 +1,12 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { listSystemPresence, updateSystemPresence, upsertPresence } from "./system-presence.js";
|
||||
|
||||
describe("system-presence", () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("dedupes entries across sources by case-insensitive instanceId key", () => {
|
||||
const instanceIdUpper = `AaBb-${randomUUID()}`.toUpperCase();
|
||||
const instanceIdLower = instanceIdUpper.toLowerCase();
|
||||
@@ -56,4 +60,25 @@ describe("system-presence", () => {
|
||||
expect(entry?.roles).toEqual(expect.arrayContaining(["operator", "node"]));
|
||||
expect(entry?.scopes).toEqual(expect.arrayContaining(["operator.admin", "system.run"]));
|
||||
});
|
||||
|
||||
it("prunes stale non-self entries after TTL", () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(Date.now());
|
||||
|
||||
const deviceId = randomUUID();
|
||||
upsertPresence(deviceId, {
|
||||
deviceId,
|
||||
host: "stale-host",
|
||||
mode: "ui",
|
||||
reason: "connect",
|
||||
});
|
||||
|
||||
expect(listSystemPresence().some((entry) => entry.deviceId === deviceId)).toBe(true);
|
||||
|
||||
vi.advanceTimersByTime(5 * 60 * 1000 + 1);
|
||||
|
||||
const entries = listSystemPresence();
|
||||
expect(entries.some((entry) => entry.deviceId === deviceId)).toBe(false);
|
||||
expect(entries.some((entry) => entry.reason === "self")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user