Skip to content

Commit 2bd89fb

Browse files
author
Peter Steinberger
committed
fix(cli): make status and provider diagnostics complete
1 parent 12297b7 commit 2bd89fb

15 files changed

Lines changed: 479 additions & 37 deletions

‎extensions/slack/src/account-inspect.test.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
// Slack tests cover account inspection and credential status reporting.
22
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
33
import { describe, expect, it } from "vitest";
4+
import { isSlackPluginAccountConfigured } from "./account-configured.js";
45
import { inspectSlackAccount } from "./account-inspect.js";
56

7+
function isInspectedSlackAccountUsable(account: ReturnType<typeof inspectSlackAccount>): boolean {
8+
return isSlackPluginAccountConfigured({
9+
...account,
10+
identity: account.identity ?? "bot",
11+
});
12+
}
13+
614
describe("inspectSlackAccount", () => {
715
it("reports user-token source and status for a configured user identity", () => {
816
const account = inspectSlackAccount({
@@ -107,6 +115,63 @@ describe("inspectSlackAccount", () => {
107115
expect(account).toMatchObject({
108116
botTokenSource: "config",
109117
botTokenStatus: "configured_unavailable",
118+
configured: true,
119+
});
120+
expect(isInspectedSlackAccountUsable(account)).toBe(false);
121+
});
122+
123+
it("keeps a healthy bot identity configured when its optional user token is unavailable", () => {
124+
const account = inspectSlackAccount({
125+
cfg: {
126+
channels: {
127+
slack: {
128+
botToken: "test-bot-token",
129+
appToken: "test-app-token",
130+
userToken: {
131+
source: "env",
132+
provider: "default",
133+
id: "OPENCLAW_TEST_MISSING_OPTIONAL_SLACK_USER_TOKEN",
134+
},
135+
},
136+
},
137+
} as OpenClawConfig,
138+
envBotToken: "",
139+
envAppToken: "",
140+
envUserToken: "",
141+
});
142+
143+
expect(account).toMatchObject({
144+
configured: true,
145+
botTokenStatus: "available",
146+
appTokenStatus: "available",
147+
userTokenStatus: "configured_unavailable",
148+
});
149+
expect(isInspectedSlackAccountUsable(account)).toBe(true);
150+
});
151+
152+
it("keeps incomplete required credentials unconfigured even when another token is unavailable", () => {
153+
const account = inspectSlackAccount({
154+
cfg: {
155+
channels: {
156+
slack: {
157+
botToken: {
158+
source: "env",
159+
provider: "default",
160+
id: "OPENCLAW_TEST_MISSING_REQUIRED_SLACK_BOT_TOKEN",
161+
},
162+
},
163+
},
164+
} as OpenClawConfig,
165+
envBotToken: "",
166+
envAppToken: "",
167+
envUserToken: "",
168+
});
169+
170+
expect(account).toMatchObject({
171+
configured: false,
172+
botTokenStatus: "configured_unavailable",
173+
appTokenStatus: "missing",
110174
});
175+
expect(isInspectedSlackAccountUsable(account)).toBe(false);
111176
});
112177
});

‎src/commands/agents.providers.test.ts‎

Lines changed: 152 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ describe("buildProviderStatusIndex", () => {
101101
expect(status?.name).toBe("Work");
102102
});
103103

104-
it("records accounts that throw during read-only resolution as not configured", async () => {
104+
it("keeps unresolved configured SecretRef accounts visible without exposing their refs", async () => {
105105
const plugin = {
106106
id: "quietchat",
107107
meta: { label: "QuietChat" },
108108
config: {
109109
listAccountIds: () => ["default"],
110110
resolveAccount: () => {
111-
throw new Error("unresolved SecretRef");
111+
throw new Error("unresolved SecretRef: PRIVATE_PROVIDER_TOKEN");
112112
},
113113
},
114114
status: {},
@@ -123,13 +123,161 @@ describe("buildProviderStatusIndex", () => {
123123
"quietchat:default",
124124
{
125125
provider: "quietchat",
126+
providerLabel: "QuietChat",
126127
accountId: "default",
127-
state: "not configured",
128-
configured: false,
128+
state: "configured unavailable",
129+
configured: true,
130+
visibleInConfiguredLists: true,
129131
},
130132
],
131133
]),
132134
);
135+
const statuses = await buildProviderStatusIndex({} as OpenClawConfig);
136+
expect(
137+
listProvidersForAgent({
138+
summaryIsDefault: true,
139+
cfg: {} as OpenClawConfig,
140+
bindings: [],
141+
providerStatus: statuses,
142+
providerMetadata: buildProviderSummaryMetadataIndex({} as OpenClawConfig),
143+
}),
144+
).toEqual(["QuietChat default: configured unavailable"]);
145+
expect(JSON.stringify([...statuses.values()])).not.toContain("PRIVATE_PROVIDER_TOKEN");
146+
});
147+
148+
it("keeps configured-but-unavailable Telegram-style accounts in default agent output", async () => {
149+
const account = {
150+
accountId: "default",
151+
enabled: true,
152+
configured: true,
153+
tokenStatus: "configured_unavailable" as const,
154+
};
155+
const plugin = {
156+
id: "telegram",
157+
meta: { label: "Telegram" },
158+
config: {
159+
listAccountIds: () => ["default"],
160+
inspectAccount: () => account,
161+
resolveAccount: () => account,
162+
describeAccount: () => ({
163+
accountId: "default",
164+
enabled: true,
165+
configured: true,
166+
tokenStatus: "configured_unavailable" as const,
167+
}),
168+
isConfigured: () => false,
169+
},
170+
status: {},
171+
} as never;
172+
const cfg = {
173+
channels: {
174+
telegram: {
175+
enabled: true,
176+
tokenFile: "/nonexistent/token",
177+
},
178+
},
179+
} as OpenClawConfig;
180+
mocks.listReadOnlyChannelPluginsForConfig.mockReturnValue([plugin]);
181+
182+
const statuses = await buildProviderStatusIndex(cfg);
183+
184+
expect(statuses.get("telegram:default")).toMatchObject({
185+
configured: true,
186+
state: "configured unavailable",
187+
});
188+
expect(
189+
listProvidersForAgent({
190+
summaryIsDefault: true,
191+
cfg,
192+
bindings: [],
193+
providerStatus: statuses,
194+
providerMetadata: buildProviderSummaryMetadataIndex(cfg),
195+
}),
196+
).toEqual(["Telegram default: configured unavailable"]);
197+
});
198+
199+
it("does not mark a healthy Slack account unavailable for an optional unresolved user token", async () => {
200+
const account = {
201+
accountId: "default",
202+
enabled: true,
203+
configured: true,
204+
botTokenStatus: "available" as const,
205+
appTokenStatus: "available" as const,
206+
userTokenStatus: "configured_unavailable" as const,
207+
};
208+
const plugin = {
209+
id: "slack",
210+
meta: { label: "Slack" },
211+
config: {
212+
listAccountIds: () => ["default"],
213+
inspectAccount: () => account,
214+
resolveAccount: () => account,
215+
describeAccount: () => ({ accountId: "default", enabled: true, configured: true }),
216+
isConfigured: () => true,
217+
},
218+
status: {},
219+
} as never;
220+
mocks.listReadOnlyChannelPluginsForConfig.mockReturnValue([plugin]);
221+
222+
expect(
223+
(await buildProviderStatusIndex({} as OpenClawConfig)).get("slack:default"),
224+
).toMatchObject({ configured: true, state: "configured" });
225+
});
226+
227+
it("does not treat an incomplete Slack account as configured when a required token is missing", async () => {
228+
const account = {
229+
accountId: "default",
230+
enabled: true,
231+
configured: false,
232+
botTokenStatus: "configured_unavailable" as const,
233+
appTokenStatus: "missing" as const,
234+
userTokenStatus: "missing" as const,
235+
};
236+
const plugin = {
237+
id: "slack",
238+
meta: { label: "Slack" },
239+
config: {
240+
listAccountIds: () => ["default"],
241+
inspectAccount: () => account,
242+
resolveAccount: () => account,
243+
describeAccount: () => ({ accountId: "default", enabled: true, configured: true }),
244+
isConfigured: () => false,
245+
},
246+
status: {},
247+
} as never;
248+
mocks.listReadOnlyChannelPluginsForConfig.mockReturnValue([plugin]);
249+
250+
expect(
251+
(await buildProviderStatusIndex({} as OpenClawConfig)).get("slack:default"),
252+
).toMatchObject({ configured: false, state: "not configured" });
253+
});
254+
255+
it("keeps a fully configured Slack account visible when a required token is unavailable", async () => {
256+
const account = {
257+
accountId: "default",
258+
enabled: true,
259+
configured: true,
260+
botTokenStatus: "configured_unavailable" as const,
261+
appTokenStatus: "available" as const,
262+
userTokenStatus: "missing" as const,
263+
};
264+
const plugin = {
265+
id: "slack",
266+
meta: { label: "Slack" },
267+
config: {
268+
listAccountIds: () => ["default"],
269+
inspectAccount: () => account,
270+
resolveAccount: () => account,
271+
describeAccount: () => ({ accountId: "default", enabled: true, configured: false }),
272+
isConfigured: () => false,
273+
},
274+
status: {},
275+
} as never;
276+
mocks.listReadOnlyChannelPluginsForConfig.mockReturnValue([plugin]);
277+
278+
expect(
279+
(await buildProviderStatusIndex({} as OpenClawConfig)).get("slack:default"),
280+
).toMatchObject({ configured: true, state: "configured unavailable" });
133281
});
134282

135283
it("does not inspect linkage for an unconfigured account", async () => {

‎src/commands/agents.providers.ts‎

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Provider/account summary helpers for `openclaw agents list`.
22
import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce";
3+
import { hasConfiguredUnavailableCredentialStatus } from "../channels/account-snapshot-fields.js";
34
import { isChannelVisibleInConfiguredLists } from "../channels/plugins/exposure.js";
45
import { resolveChannelDefaultAccountId } from "../channels/plugins/helpers.js";
56
import { normalizeChannelId } from "../channels/plugins/index.js";
@@ -22,7 +23,14 @@ type ProviderAccountStatus = {
2223
providerLabel?: string;
2324
accountId: string;
2425
name?: string;
25-
state: "linked" | "not linked" | "configured" | "not configured" | "enabled" | "disabled";
26+
state:
27+
| "linked"
28+
| "not linked"
29+
| "configured"
30+
| "configured unavailable"
31+
| "not configured"
32+
| "enabled"
33+
| "disabled";
2634
enabled?: boolean;
2735
configured?: boolean;
2836
visibleInConfiguredLists?: boolean;
@@ -155,9 +163,11 @@ export async function buildProviderStatusIndex(
155163
}
156164
map.set(providerAccountKey(plugin.id, accountId), {
157165
provider: plugin.id,
166+
providerLabel: plugin.meta.label,
158167
accountId,
159-
state: "not configured",
160-
configured: false,
168+
state: "configured unavailable",
169+
configured: true,
170+
visibleInConfiguredLists: isChannelVisibleInConfiguredLists(plugin.meta),
161171
});
162172
continue;
163173
}
@@ -175,6 +185,18 @@ export async function buildProviderStatusIndex(
175185
: snapshot?.configured;
176186
const resolvedEnabled = typeof enabled === "boolean" ? enabled : true;
177187
const resolvedConfigured = typeof configured === "boolean" ? configured : true;
188+
const inspectedConfigured = (account as { configured?: unknown }).configured;
189+
const configuredIntent =
190+
typeof inspectedConfigured === "boolean"
191+
? inspectedConfigured
192+
: snapshot?.configured === true;
193+
// Provider inspection owns which credentials are required. Only an account whose owner
194+
// reports complete configured intent but no usable runtime credentials is unavailable.
195+
const configuredUnavailable =
196+
!resolvedConfigured &&
197+
configuredIntent &&
198+
(hasConfiguredUnavailableCredentialStatus(snapshot) ||
199+
hasConfiguredUnavailableCredentialStatus(account));
178200
const linkState =
179201
resolvedConfigured && plugin.config.isLinked
180202
? await plugin.config.isLinked(account, cfg)
@@ -186,14 +208,16 @@ export async function buildProviderStatusIndex(
186208
configured: resolvedConfigured,
187209
enabled: resolvedEnabled,
188210
});
189-
const state = projectChannelAccountDisplayState(
190-
resolveChannelAccountState({
191-
enabled: resolvedEnabled,
192-
configured: resolvedConfigured,
193-
linked,
194-
}),
195-
fallbackState,
196-
);
211+
const state = configuredUnavailable
212+
? "configured unavailable"
213+
: projectChannelAccountDisplayState(
214+
resolveChannelAccountState({
215+
enabled: resolvedEnabled,
216+
configured: resolvedConfigured,
217+
linked,
218+
}),
219+
fallbackState,
220+
);
197221
const name = snapshot?.name ?? (account as { name?: string }).name;
198222
map.set(providerAccountKey(plugin.id, accountId), {
199223
provider: plugin.id,
@@ -202,7 +226,7 @@ export async function buildProviderStatusIndex(
202226
name,
203227
state,
204228
enabled,
205-
configured,
229+
configured: configuredUnavailable || configured,
206230
visibleInConfiguredLists: isChannelVisibleInConfiguredLists(plugin.meta),
207231
});
208232
}

‎src/commands/status-json-runtime.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ describe("status-json-runtime", () => {
153153
expect(payloadInput.pluginCompatibility).toBeUndefined();
154154
});
155155

156-
it("suppresses health errors when requested", async () => {
156+
it("preserves failed deep health probes in nonthrowing JSON output", async () => {
157157
mocks.resolveStatusRuntimeSnapshot.mockResolvedValueOnce({
158158
securityAudit: undefined,
159159
usage: undefined,
160-
health: undefined,
160+
health: { error: "gateway health probe timed out" },
161161
lastHeartbeat: { status: "ok" },
162162
gatewayService: { label: "LaunchAgent" },
163163
nodeService: { label: "node" },
@@ -173,7 +173,7 @@ describe("status-json-runtime", () => {
173173
expect(mocks.buildStatusJsonPayload).toHaveBeenCalledOnce();
174174
const payloadInput = requireStatusPayloadInput();
175175
expect(payloadInput.surface.gatewayProbeAuth).toStrictEqual({ token: "tok" });
176-
expect(payloadInput.health).toBeUndefined();
176+
expect(payloadInput.health).toEqual({ error: "gateway health probe timed out" });
177177
expect(mocks.resolveStatusRuntimeSnapshot).toHaveBeenCalledWith({
178178
config: { update: { channel: "stable" }, gateway: {} },
179179
sourceConfig: { gateway: {} },

0 commit comments

Comments
 (0)