Gateway: add presence-only probe mode for status
This commit is contained in:
parent
a2cb81199e
commit
d8e138c743
@ -246,6 +246,9 @@ describe("scanStatus", () => {
|
||||
await scanStatus({ json: true }, {} as never);
|
||||
|
||||
expect(mocks.ensurePluginRegistryLoaded).toHaveBeenCalledWith({ scope: "channels" });
|
||||
expect(mocks.probeGateway).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ detailLevel: "presence" }),
|
||||
);
|
||||
expect(mocks.callGateway).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ method: "channels.status" }),
|
||||
);
|
||||
|
||||
@ -98,6 +98,7 @@ async function resolveGatewayProbeSnapshot(params: {
|
||||
url: gatewayConnection.url,
|
||||
auth: gatewayProbeAuthResolution.auth,
|
||||
timeoutMs: Math.min(params.opts.all ? 5000 : 2500, params.opts.timeoutMs ?? 10_000),
|
||||
detailLevel: "presence",
|
||||
}).catch(() => null);
|
||||
if (gatewayProbeAuthWarning && gatewayProbe?.ok === false) {
|
||||
gatewayProbe.error = gatewayProbe.error
|
||||
|
||||
@ -81,4 +81,18 @@ describe("probeGateway", () => {
|
||||
expect(result.ok).toBe(true);
|
||||
expect(gatewayClientState.requests).toEqual([]);
|
||||
});
|
||||
|
||||
it("fetches only presence for presence-only probes", async () => {
|
||||
const result = await probeGateway({
|
||||
url: "ws://127.0.0.1:18789",
|
||||
timeoutMs: 1_000,
|
||||
detailLevel: "presence",
|
||||
});
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
expect(gatewayClientState.requests).toEqual(["system-presence"]);
|
||||
expect(result.health).toBeNull();
|
||||
expect(result.status).toBeNull();
|
||||
expect(result.configSnapshot).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@ -34,6 +34,7 @@ export async function probeGateway(opts: {
|
||||
auth?: GatewayProbeAuth;
|
||||
timeoutMs: number;
|
||||
includeDetails?: boolean;
|
||||
detailLevel?: "none" | "presence" | "full";
|
||||
}): Promise<GatewayProbeResult> {
|
||||
const startedAt = Date.now();
|
||||
const instanceId = randomUUID();
|
||||
@ -49,6 +50,8 @@ export async function probeGateway(opts: {
|
||||
}
|
||||
})();
|
||||
|
||||
const detailLevel = opts.includeDetails === false ? "none" : (opts.detailLevel ?? "full");
|
||||
|
||||
return await new Promise<GatewayProbeResult>((resolve) => {
|
||||
let settled = false;
|
||||
const settle = (result: Omit<GatewayProbeResult, "url">) => {
|
||||
@ -79,7 +82,7 @@ export async function probeGateway(opts: {
|
||||
},
|
||||
onHelloOk: async () => {
|
||||
connectLatencyMs = Date.now() - startedAt;
|
||||
if (opts.includeDetails === false) {
|
||||
if (detailLevel === "none") {
|
||||
settle({
|
||||
ok: true,
|
||||
connectLatencyMs,
|
||||
@ -93,6 +96,20 @@ export async function probeGateway(opts: {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (detailLevel === "presence") {
|
||||
const presence = await client.request("system-presence");
|
||||
settle({
|
||||
ok: true,
|
||||
connectLatencyMs,
|
||||
error: null,
|
||||
close,
|
||||
health: null,
|
||||
status: null,
|
||||
presence: Array.isArray(presence) ? (presence as SystemPresence[]) : null,
|
||||
configSnapshot: null,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const [health, status, presence, configSnapshot] = await Promise.all([
|
||||
client.request("health"),
|
||||
client.request("status"),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user