mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 23:50:22 +00:00
refactor: centralize computed channel status adapters
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user