Skip to content

Commit 0cd33ba

Browse files
authored
fix(plugin-sdk): project recorded health facts through computed account status (#117236)
* fix(plugin-sdk): project recorded health facts through computed account status * fix(plugin-sdk): regenerate API baseline and pin ingressUnavailable literal in test
1 parent 1f9ee89 commit 0cd33ba

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bba5540be7cf9613a163663decdb2affe2af9bbd3ad7914989ab186f9c2abec1 module/channel
4545
0ceb4378709eb2d92a62a275f87fa04e18f77df8f942a9a0acef81019ebc1e24 module/channel-secret-runtime
4646
7c90157a95bc0523fc66b1f78ce140f7ec7dbf809dfa3a480244efc01f972754 module/channel-send-result
4747
fb123c1b557ed2527e335f13c3d6de41ab0c3305151001cf2b1075d1da8034c5 module/channel-setup
48-
8de651a14a46014dc86fb8ccaff819e0854cf6bb2e3b59e642f1e55b37ef43c2 module/channel-status
48+
16fe7770b385f46ba17b4e11fea7ebaf953b3a08ffe45cb9f94380d364210123 module/channel-status
4949
d904e33114f056022ef9fec184edcfe37c30b539b268e28b0ff485f0a02b9c59 module/channel-streaming
5050
14f0103adb14627b662fbe9fdd5ed08596ed702a250853e8beb8bb8dd1361588 module/cli-argv
5151
c89ec1b194b76f67a6f4dd108dccf460da6065646cba31374c8aa748f23a39e4 module/collection-runtime
@@ -63,7 +63,7 @@ c1ea9510dfda047609a99d5d2cd1f1560f5d469a36e6b695766213d695c25b0f module/convers
6363
f70c93d28053ca2e8353e45e6515ce7acef188097c6117d1545965d0699c8004 module/device-bootstrap
6464
6215d3af5923bf5a616d73062534968b69f448e3e30adc64ae9caebdd1a46d71 module/diagnostic-runtime
6565
ea81ef06956c1bc0853fa00afbbc2b5a4019116aaf8a436e1b27d06f7a2c9e88 module/directory-runtime
66-
da97e1dc476d65758734ec482d45aa732d195622ef97b3806d4d60ca9c069eca module/discord
66+
82eb830878b9fa58a62a0a4f3dd0dc12790986a8a6d9bf6e6ed67d9e4df4b9b4 module/discord
6767
f65408d85477bb362ebe6ed9148c1bb6b9eb7839733e5e3119f4ff8f1cfd0567 module/error-runtime
6868
b013053a61e7d9be3d0c683c02baf57fa7e4393ec54e0df6a46ab0f2fe2348fd module/extension-shared
6969
ceacad83db01c66e7be6aa21a291597020f13f737b697690eae7d47098e6499a module/gateway-method-runtime
@@ -132,7 +132,7 @@ ae469f32799380e6b045abaefefee6eb3f00d714ffbf36b6eeef5025dc529472 module/speech-
132132
9e521fe9073dfd1a6a6855f909fa6befe8613e18403f0a65faaba973a8b630c1 module/ssrf-policy
133133
f85d5be0f635de6a77bbd9224a37c373998e098a8dcf2048ddc2c9ac735b47ef module/ssrf-runtime
134134
ff35f9f74d35d37a2eb6126b57f3dc5a4d580b6222fe3a34c9368779ad32eab7 module/state-paths
135-
9d44964935615a6c2cd83f2dd2307690f15d714b13b85422f711808e0cf4afcc module/status-helpers
135+
64c51c24cfaaf93199e4734abbb64c3eb50dc75488400c65a412eedeefe21f61 module/status-helpers
136136
537047854c21ad20ea0572f8019503cbda3bbafece8194a28c30b0639bde2fde module/string-coerce-runtime
137137
1b5b9a4532db991fce807ba736b550de27aa5f9de2e1f508a8f4f09cae76ea29 module/telegram-account
138138
110944726884fca94f38c9c329b5950629438b9a719f4782c4beeade8bd67746 module/temp-path

‎src/plugin-sdk/status-helpers.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Status helper tests cover plugin status normalization and user-facing summaries.
22
import { describe, expect, it } from "vitest";
3+
import { evaluateChannelHealth } from "../gateway/channel-health-policy.js";
34
import {
45
createAsyncComputedAccountStatusAdapter,
56
buildBaseAccountStatusSnapshot,
@@ -354,6 +355,28 @@ describe("computed account status adapters", () => {
354355
).resolves.toEqual(expectedAdapterAccountSnapshot());
355356
},
356357
);
358+
359+
it("preserves ingress failure for channel health evaluation", async () => {
360+
const status = createComputedStatusAdapter();
361+
const snapshot = await status.buildAccountSnapshot!({
362+
account: adapterAccount,
363+
cfg: {} as never,
364+
runtime: {
365+
...adapterRuntime,
366+
ingressUnavailable: true,
367+
},
368+
probe: adapterProbe,
369+
});
370+
371+
expect(
372+
evaluateChannelHealth(snapshot, {
373+
channelId: "discord",
374+
now: 100_000,
375+
channelConnectGraceMs: 10_000,
376+
staleEventThresholdMs: 30_000,
377+
}),
378+
).toEqual({ healthy: false, reason: "ingress-unavailable" });
379+
});
357380
});
358381

359382
describe("buildRuntimeAccountStatusSnapshot", () => {
@@ -389,6 +412,11 @@ describe("buildRuntimeAccountStatusSnapshot", () => {
389412
lastEventAt: 13,
390413
lastTransportActivityAt: 14,
391414
healthState: "healthy",
415+
ingressUnavailable: true as const,
416+
busy: true,
417+
activeRuns: 2,
418+
lastRunActivityAt: 15,
419+
activeRunStartedAt: 16,
392420
running: true,
393421
},
394422
},
@@ -404,6 +432,11 @@ describe("buildRuntimeAccountStatusSnapshot", () => {
404432
lastEventAt: 13,
405433
lastTransportActivityAt: 14,
406434
healthState: "healthy",
435+
ingressUnavailable: true,
436+
busy: true,
437+
activeRuns: 2,
438+
lastRunActivityAt: 15,
439+
activeRunStartedAt: 16,
407440
probe: undefined,
408441
},
409442
},
@@ -428,6 +461,12 @@ describe("buildRuntimeAccountStatusSnapshot", () => {
428461
])("$name", ({ input, extra, expected }) => {
429462
expect(buildRuntimeAccountStatusSnapshot(input, extra)).toEqual(expected);
430463
});
464+
465+
it("omits ingress availability when no failure was recorded", () => {
466+
expect(buildRuntimeAccountStatusSnapshot({ runtime: { running: true } })).not.toHaveProperty(
467+
"ingressUnavailable",
468+
);
469+
});
431470
});
432471

433472
describe("buildTokenChannelStatusSummary", () => {

‎src/plugin-sdk/status-helpers.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ type RuntimeLifecycleSnapshot = {
4343
lastEventAt?: number | null;
4444
lastTransportActivityAt?: number | null;
4545
healthState?: string | null;
46+
ingressUnavailable?: true | null;
4647
terminalDisconnect?: boolean | null;
4748
lastStartAt?: number | null;
4849
lastStopAt?: number | null;
4950
lastError?: string | null;
5051
lastInboundAt?: number | null;
5152
lastOutboundAt?: number | null;
53+
busy?: boolean | null;
54+
activeRuns?: number | null;
55+
lastRunActivityAt?: number | null;
56+
activeRunStartedAt?: number | null;
5257
};
5358

5459
type StatusSnapshotExtra = Record<string, unknown>;
@@ -398,7 +403,17 @@ export function buildRuntimeAccountStatusSnapshot<TExtra extends StatusSnapshotE
398403
? { lastTransportActivityAt: runtime.lastTransportActivityAt }
399404
: {}),
400405
...(typeof runtime?.healthState === "string" ? { healthState: runtime.healthState } : {}),
406+
// Absence means unknown; only a recorded ingress failure crosses the projection.
407+
...(runtime?.ingressUnavailable === true ? { ingressUnavailable: true as const } : {}),
401408
...(runtime?.terminalDisconnect ? { terminalDisconnect: runtime.terminalDisconnect } : {}),
409+
...(typeof runtime?.busy === "boolean" ? { busy: runtime.busy } : {}),
410+
...(typeof runtime?.activeRuns === "number" ? { activeRuns: runtime.activeRuns } : {}),
411+
...(typeof runtime?.lastRunActivityAt === "number"
412+
? { lastRunActivityAt: runtime.lastRunActivityAt }
413+
: {}),
414+
...(typeof runtime?.activeRunStartedAt === "number"
415+
? { activeRunStartedAt: runtime.activeRunStartedAt }
416+
: {}),
402417
...(extra ?? ({} as TExtra)),
403418
};
404419
}

0 commit comments

Comments
 (0)