Skip to content

Commit 288876d

Browse files
committed
fix(channels): list channel catalog status
1 parent b22c899 commit 288876d

3 files changed

Lines changed: 249 additions & 152 deletions

File tree

‎src/cli/channels-cli.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export async function registerChannelsCli(
100100
"after",
101101
() =>
102102
`\n${theme.heading("Examples:")}\n${formatHelpExamples([
103-
["openclaw channels list", "List configured channels and auth profiles."],
103+
["openclaw channels list", "List available and configured channels."],
104104
["openclaw channels status --probe", "Run channel status checks and probes."],
105105
[
106106
"openclaw channels add --channel telegram --token <token>",

src/commands/channels.list.auth-profiles.test.ts renamed to src/commands/channels.list.test.ts

Lines changed: 105 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ const mocks = vi.hoisted(() => ({
1010
effectiveConfig: config,
1111
diagnostics: [],
1212
})),
13-
loadAuthProfileStoreWithoutExternalProfiles: vi.fn(),
13+
listChatChannels: vi.fn(() => [
14+
{ id: "discord", label: "Discord", order: 10 },
15+
{ id: "telegram", label: "Telegram", order: 20 },
16+
]),
1417
listReadOnlyChannelPluginsForConfig: vi.fn<() => ChannelPlugin[]>(() => []),
18+
listTrustedChannelPluginCatalogEntries: vi.fn<() => any[]>(() => []),
1519
buildChannelAccountSnapshot: vi.fn(),
16-
loadProviderUsageSummary: vi.fn(),
1720
}));
1821

1922
vi.mock("../config/config.js", () => ({
@@ -28,8 +31,8 @@ vi.mock("../cli/command-secret-targets.js", () => ({
2831
getChannelsCommandSecretTargetIds: () => new Set<string>(),
2932
}));
3033

31-
vi.mock("../agents/auth-profiles.js", () => ({
32-
loadAuthProfileStoreWithoutExternalProfiles: mocks.loadAuthProfileStoreWithoutExternalProfiles,
34+
vi.mock("../channels/chat-meta.js", () => ({
35+
listChatChannels: mocks.listChatChannels,
3336
}));
3437

3538
vi.mock("../channels/plugins/read-only.js", () => ({
@@ -40,103 +43,108 @@ vi.mock("../channels/plugins/status.js", () => ({
4043
buildChannelAccountSnapshot: mocks.buildChannelAccountSnapshot,
4144
}));
4245

43-
vi.mock("../infra/provider-usage.js", () => ({
44-
formatUsageReportLines: () => [],
45-
loadProviderUsageSummary: mocks.loadProviderUsageSummary,
46+
vi.mock("./channel-setup/trusted-catalog.js", () => ({
47+
listTrustedChannelPluginCatalogEntries: mocks.listTrustedChannelPluginCatalogEntries,
4648
}));
4749

4850
import { channelsListCommand } from "./channels/list.js";
4951

50-
function createMockChannelPlugin(accountIds: string[]): ChannelPlugin {
52+
function createMockChannelPlugin(params: {
53+
id?: string;
54+
label?: string;
55+
accountIds?: string[];
56+
order?: number;
57+
}): ChannelPlugin {
58+
const id = params.id ?? "telegram";
5159
return {
52-
id: "telegram",
60+
id,
5361
meta: {
54-
id: "telegram",
55-
label: "Telegram",
56-
selectionLabel: "Telegram",
57-
docsPath: "/channels/telegram",
58-
blurb: "Telegram",
62+
id,
63+
label: params.label ?? id,
64+
selectionLabel: params.label ?? id,
65+
docsPath: `/channels/${id}`,
66+
blurb: params.label ?? id,
67+
order: params.order,
5968
},
6069
capabilities: { chatTypes: ["direct"] },
6170
config: {
62-
listAccountIds: () => accountIds,
71+
listAccountIds: () => params.accountIds ?? [],
6372
resolveAccount: () => ({}),
6473
},
6574
};
6675
}
6776

68-
describe("channels list auth profiles", () => {
77+
describe("channels list", () => {
6978
beforeEach(() => {
7079
mocks.readConfigFileSnapshot.mockReset();
7180
mocks.resolveCommandConfigWithSecrets.mockClear();
72-
mocks.loadAuthProfileStoreWithoutExternalProfiles.mockReset();
73-
mocks.loadProviderUsageSummary.mockReset();
81+
mocks.listChatChannels.mockReset();
82+
mocks.listChatChannels.mockReturnValue([
83+
{ id: "discord", label: "Discord", order: 10 },
84+
{ id: "telegram", label: "Telegram", order: 20 },
85+
]);
86+
mocks.listTrustedChannelPluginCatalogEntries.mockReset();
87+
mocks.listTrustedChannelPluginCatalogEntries.mockReturnValue([]);
7488
mocks.listReadOnlyChannelPluginsForConfig.mockReset();
7589
mocks.listReadOnlyChannelPluginsForConfig.mockReturnValue([]);
7690
mocks.buildChannelAccountSnapshot.mockReset();
7791
});
7892

79-
it("includes local auth profiles in JSON output without loading external profiles", async () => {
93+
it("lists only channels in JSON output", async () => {
8094
const runtime = createTestRuntime();
8195
mocks.readConfigFileSnapshot.mockResolvedValue({
8296
...baseConfigSnapshot,
8397
config: {},
8498
});
85-
mocks.loadAuthProfileStoreWithoutExternalProfiles.mockReturnValue({
86-
version: 1,
87-
profiles: {
88-
"anthropic:default": {
89-
type: "oauth",
90-
provider: "anthropic",
91-
access: "token",
92-
refresh: "refresh",
93-
expires: 0,
94-
created: 0,
95-
},
96-
"openai-codex:default": {
97-
type: "oauth",
98-
provider: "openai",
99-
access: "token",
100-
refresh: "refresh",
101-
expires: 0,
102-
created: 0,
103-
},
104-
},
105-
});
10699

107100
await channelsListCommand({ json: true, usage: false }, runtime);
108101

109102
expect(mocks.resolveCommandConfigWithSecrets).toHaveBeenCalledTimes(1);
110103
const payload = JSON.parse(runtime.log.mock.calls[0]?.[0] as string) as {
111-
auth?: Array<{ id: string }>;
104+
channels?: Array<{ id: string; configured: boolean; enabled: boolean; installed: boolean }>;
105+
auth?: unknown;
106+
usage?: unknown;
112107
};
113-
const ids = payload.auth?.map((entry) => entry.id) ?? [];
114-
expect(ids).toContain("anthropic:default");
115-
expect(ids).toContain("openai-codex:default");
108+
expect(payload.auth).toBeUndefined();
109+
expect(payload.usage).toBeUndefined();
110+
expect(payload.channels?.map((entry) => entry.id)).toEqual(["discord", "telegram"]);
111+
expect(payload.channels?.[0]).toMatchObject({
112+
id: "discord",
113+
configured: false,
114+
enabled: true,
115+
installed: false,
116+
});
116117
});
117118

118-
it("includes configured chat channel accounts in JSON output", async () => {
119+
it("includes bundled/catalog/configured channels with status flags", async () => {
119120
const runtime = createTestRuntime();
120121
mocks.listReadOnlyChannelPluginsForConfig.mockReturnValue([
121-
createMockChannelPlugin(["alerts", "default"]),
122+
createMockChannelPlugin({
123+
id: "telegram",
124+
label: "Telegram",
125+
accountIds: ["alerts"],
126+
order: 20,
127+
}),
128+
]);
129+
mocks.listTrustedChannelPluginCatalogEntries.mockReturnValue([
130+
{
131+
id: "slack",
132+
meta: { id: "slack", label: "Slack", selectionLabel: "Slack", order: 30 },
133+
install: { npmSpec: "@openclaw/slack" },
134+
},
122135
]);
123136
mocks.readConfigFileSnapshot.mockResolvedValue({
124137
...baseConfigSnapshot,
125138
config: {
126139
channels: {
127140
telegram: {
128-
accounts: {
129-
default: { botToken: "123:abc" },
130-
alerts: { botToken: "456:def" },
131-
},
141+
accounts: { alerts: { botToken: "456:def" } },
132142
},
143+
slack: { enabled: false },
144+
custom: { webhookUrl: "https://example.invalid/hook" },
133145
},
134146
},
135147
});
136-
mocks.loadAuthProfileStoreWithoutExternalProfiles.mockReturnValue({
137-
version: 1,
138-
profiles: {},
139-
});
140148

141149
await channelsListCommand({ json: true, usage: false }, runtime);
142150

@@ -145,36 +153,50 @@ describe("channels list auth profiles", () => {
145153
expect.objectContaining({ includeSetupFallbackPlugins: true }),
146154
);
147155
const payload = JSON.parse(runtime.log.mock.calls[0]?.[0] as string) as {
148-
chat?: Record<string, string[]>;
156+
channels: Array<{
157+
id: string;
158+
configured: boolean;
159+
enabled: boolean;
160+
installed: boolean;
161+
accounts: string[];
162+
}>;
149163
};
150-
expect(payload.chat?.telegram).toEqual(["alerts", "default"]);
151-
});
152-
153-
it("keeps JSON output valid when usage loading fails", async () => {
154-
const runtime = createTestRuntime();
155-
mocks.readConfigFileSnapshot.mockResolvedValue({
156-
...baseConfigSnapshot,
157-
config: {},
158-
});
159-
mocks.loadAuthProfileStoreWithoutExternalProfiles.mockReturnValue({
160-
version: 1,
161-
profiles: {},
162-
});
163-
mocks.loadProviderUsageSummary.mockRejectedValue(new Error("fetch failed"));
164-
165-
await channelsListCommand({ json: true }, runtime);
166-
167-
const payload = JSON.parse(runtime.log.mock.calls[0]?.[0] as string) as {
168-
usage?: unknown;
169-
};
170-
expect(payload.usage).toBeUndefined();
171-
expect(runtime.error).not.toHaveBeenCalled();
164+
expect(payload.channels).toEqual(
165+
expect.arrayContaining([
166+
expect.objectContaining({
167+
id: "telegram",
168+
configured: true,
169+
enabled: true,
170+
installed: true,
171+
accounts: ["alerts"],
172+
}),
173+
expect.objectContaining({
174+
id: "slack",
175+
configured: false,
176+
enabled: false,
177+
installed: false,
178+
accounts: [],
179+
}),
180+
expect.objectContaining({
181+
id: "custom",
182+
configured: true,
183+
enabled: true,
184+
installed: false,
185+
accounts: [],
186+
}),
187+
]),
188+
);
172189
});
173190

174-
it("prints configured chat channel accounts before auth providers", async () => {
191+
it("prints channel rows and account rows without auth providers", async () => {
175192
const runtime = createTestRuntime();
176193
mocks.listReadOnlyChannelPluginsForConfig.mockReturnValue([
177-
createMockChannelPlugin(["default"]),
194+
createMockChannelPlugin({
195+
id: "telegram",
196+
label: "Telegram",
197+
accountIds: ["default"],
198+
order: 20,
199+
}),
178200
]);
179201
mocks.buildChannelAccountSnapshot.mockResolvedValue({
180202
accountId: "default",
@@ -194,21 +216,14 @@ describe("channels list auth profiles", () => {
194216
},
195217
},
196218
});
197-
mocks.loadAuthProfileStoreWithoutExternalProfiles.mockReturnValue({
198-
version: 1,
199-
profiles: {},
200-
});
201219

202220
await channelsListCommand({ usage: false }, runtime);
203221

204-
expect(mocks.listReadOnlyChannelPluginsForConfig).toHaveBeenCalledWith(
205-
expect.any(Object),
206-
expect.objectContaining({ includeSetupFallbackPlugins: true }),
207-
);
208222
const output = stripAnsi(runtime.log.mock.calls[0]?.[0] as string);
209223
expect(output).toContain("Chat channels:");
210-
expect(output).toContain("Telegram default:");
211-
expect(output).toContain("configured");
212-
expect(output.indexOf("Telegram default:")).toBeLessThan(output.indexOf("Auth providers"));
224+
expect(output).toContain("Discord: not configured, enabled, not installed");
225+
expect(output).toContain("Telegram: configured, enabled, installed");
226+
expect(output).toContain("Telegram default: configured, token=config, enabled");
227+
expect(output).not.toContain("Auth providers");
213228
});
214229
});

0 commit comments

Comments
 (0)