refactor: centralize computed channel status adapters

This commit is contained in:
Peter Steinberger
2026-03-22 21:15:09 +00:00
parent 29c0e783b1
commit 87b2672126
8 changed files with 185 additions and 104 deletions

View File

@@ -4,6 +4,7 @@ import {
buildBaseChannelStatusSummary,
buildComputedAccountStatusSnapshot,
buildRuntimeAccountStatusSnapshot,
createComputedAccountStatusAdapter,
buildTokenChannelStatusSummary,
collectStatusIssuesFromLastError,
createDefaultChannelRuntimeState,
@@ -191,6 +192,50 @@ describe("buildComputedAccountStatusSnapshot", () => {
});
});
describe("createComputedAccountStatusAdapter", () => {
it("builds account snapshots from computed account metadata and extras", () => {
const status = createComputedAccountStatusAdapter<
{ accountId: string; enabled: boolean; profileUrl: string },
{ ok: boolean }
>({
defaultRuntime: createDefaultChannelRuntimeState("default"),
resolveAccountSnapshot: ({ account, runtime, probe }) => ({
accountId: account.accountId,
enabled: account.enabled,
configured: true,
extra: {
profileUrl: account.profileUrl,
connected: runtime?.running ?? false,
probe,
},
}),
});
expect(
status.buildAccountSnapshot?.({
account: { accountId: "default", enabled: true, profileUrl: "https://example.test" },
cfg: {} as never,
runtime: { accountId: "default", running: true },
probe: { ok: true },
}),
).toEqual({
accountId: "default",
name: undefined,
enabled: true,
configured: true,
running: true,
lastStartAt: null,
lastStopAt: null,
lastError: null,
probe: { ok: true },
lastInboundAt: null,
lastOutboundAt: null,
profileUrl: "https://example.test",
connected: true,
});
});
});
describe("buildRuntimeAccountStatusSnapshot", () => {
it("builds runtime lifecycle fields with defaults", () => {
expect(buildRuntimeAccountStatusSnapshot({})).toEqual({