Skip to content

Commit 300d0be

Browse files
fix(status): preserve batch repair laziness
1 parent 8761f78 commit 300d0be

6 files changed

Lines changed: 96 additions & 39 deletions

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,27 @@ describe("buildProviderStatusIndex", () => {
375375
);
376376
});
377377

378+
it("skips missing-plugin resolution for channels already represented in metadata", () => {
379+
const plugin = {
380+
id: "feishu",
381+
meta: { label: "Feishu" },
382+
config: {
383+
listAccountIds: () => ["default"],
384+
},
385+
} as never;
386+
mocks.listReadOnlyChannelPluginsForConfig.mockReturnValue([plugin]);
387+
mocks.listExplicitConfiguredChannelIdsForConfig.mockReturnValue(["feishu"]);
388+
389+
expect(
390+
buildProviderSummaryMetadataIndex({ channels: { feishu: { appId: "cli_xxx" } } } as never)
391+
.size,
392+
).toBe(1);
393+
expect(mocks.resolveMissingOfficialExternalChannelPluginRepairHints).toHaveBeenCalledWith({
394+
config: { channels: { feishu: { appId: "cli_xxx" } } },
395+
channelIds: [],
396+
});
397+
});
398+
378399
it("uses repair hints instead of unknown for bound missing external channels", () => {
379400
const lines = listProvidersForAgent({
380401
summaryIsDefault: false,

‎src/commands/agents.providers.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,15 @@ export function buildProviderSummaryMetadataIndex(
8282
},
8383
]),
8484
);
85-
const missingHintsByChannelId = new Map(
86-
resolveMissingOfficialExternalChannelPluginRepairHints({
87-
config: cfg,
88-
channelIds: listExplicitConfiguredChannelIdsForConfig(cfg),
89-
}).map((hint) => [hint.channelId, hint]),
85+
const missingChannelIds = listExplicitConfiguredChannelIdsForConfig(cfg).filter(
86+
(channelId) => !metadata.has(channelId as ChannelId),
9087
);
91-
for (const [channelId, hint] of missingHintsByChannelId) {
92-
if (metadata.has(channelId)) {
93-
continue;
94-
}
95-
metadata.set(channelId as ChannelId, {
88+
const missingHints = resolveMissingOfficialExternalChannelPluginRepairHints({
89+
config: cfg,
90+
channelIds: missingChannelIds,
91+
});
92+
for (const hint of missingHints) {
93+
metadata.set(hint.channelId as ChannelId, {
9694
label: hint.label,
9795
defaultAccountId: DEFAULT_ACCOUNT_ID,
9896
visibleInConfiguredLists: true,

‎src/commands/channels.status.command-flow.test.ts‎

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const mocks = vi.hoisted(() => ({
1515
listChannelPlugins: vi.fn(),
1616
listConfiguredAnnounceChannelIdsForConfig: vi.fn((_params: unknown) => ["discord"]),
1717
missingOfficialExternalChannels: new Set<string>(),
18+
repairHintChannelIdCalls: [] as string[][],
1819
withProgress: vi.fn(async (_opts: unknown, run: () => Promise<unknown>) => await run()),
1920
}));
2021

@@ -50,8 +51,9 @@ vi.mock("../plugins/official-external-plugin-repair-hints.js", () => ({
5051
channelIds,
5152
}: {
5253
channelIds: string[];
53-
}) =>
54-
channelIds.flatMap((channelId) =>
54+
}) => {
55+
mocks.repairHintChannelIdCalls.push([...channelIds]);
56+
return channelIds.flatMap((channelId) =>
5557
mocks.missingOfficialExternalChannels.has(channelId)
5658
? [
5759
{
@@ -66,7 +68,8 @@ vi.mock("../plugins/official-external-plugin-repair-hints.js", () => ({
6668
},
6769
]
6870
: [],
69-
),
71+
);
72+
},
7073
}));
7174

7275
vi.mock("./channels/shared.js", () => ({
@@ -216,6 +219,7 @@ describe("channelsStatusCommand SecretRef fallback flow", () => {
216219
mocks.requireValidConfigSnapshot.mockReset();
217220
mocks.listChannelPlugins.mockReset();
218221
mocks.missingOfficialExternalChannels.clear();
222+
mocks.repairHintChannelIdCalls.length = 0;
219223
mocks.listConfiguredAnnounceChannelIdsForConfig.mockClear();
220224
mocks.listConfiguredAnnounceChannelIdsForConfig.mockReturnValue(["discord"]);
221225
mocks.withProgress.mockClear();
@@ -342,6 +346,44 @@ describe("channelsStatusCommand SecretRef fallback flow", () => {
342346
);
343347
});
344348

349+
it("resolves config-only repair hints only for the requested channel", async () => {
350+
mocks.callGateway.mockRejectedValue(new Error("gateway closed"));
351+
const config = { channels: { feishu: { appId: "cli_xxx" }, matrix: { enabled: true } } };
352+
mocks.requireValidConfigSnapshot.mockResolvedValue(config);
353+
mocks.resolveCommandConfigWithSecrets.mockResolvedValue({
354+
resolvedConfig: config,
355+
effectiveConfig: config,
356+
diagnostics: [],
357+
});
358+
mocks.missingOfficialExternalChannels.add("feishu");
359+
mocks.missingOfficialExternalChannels.add("matrix");
360+
mocks.listChannelPlugins.mockReturnValue([]);
361+
const { runtime } = createCapturingTestRuntime();
362+
363+
await channelsStatusCommand({ channel: "feishu", probe: false }, runtime as never);
364+
365+
expect(mocks.repairHintChannelIdCalls).toEqual([["feishu"]]);
366+
});
367+
368+
it("excludes visible channels from config-only repair-hint resolution", async () => {
369+
mocks.callGateway.mockRejectedValue(new Error("gateway closed"));
370+
const config = {
371+
channels: { discord: { enabled: true }, feishu: { appId: "cli_xxx" } },
372+
};
373+
mocks.requireValidConfigSnapshot.mockResolvedValue(config);
374+
mocks.resolveCommandConfigWithSecrets.mockResolvedValue({
375+
resolvedConfig: config,
376+
effectiveConfig: config,
377+
diagnostics: [],
378+
});
379+
mocks.missingOfficialExternalChannels.add("feishu");
380+
const { runtime } = createCapturingTestRuntime();
381+
382+
await channelsStatusCommand({ probe: false }, runtime as never);
383+
384+
expect(mocks.repairHintChannelIdCalls).toEqual([["feishu"]]);
385+
});
386+
345387
it("keeps JSON fallback structured without rendering config-only text", async () => {
346388
mocks.callGateway.mockRejectedValue(
347389
new Error(

‎src/commands/channels/status-config-format.ts‎

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ import {
1515
import type { ChannelAccountSnapshot } from "../../channels/plugins/types.public.js";
1616
import type { OpenClawConfig } from "../../config/config.js";
1717
import { listExplicitConfiguredChannelIdsForConfig } from "../../plugins/channel-plugin-ids.js";
18-
import {
19-
type OfficialExternalPluginRepairHint,
20-
resolveMissingOfficialExternalChannelPluginRepairHints,
21-
} from "../../plugins/official-external-plugin-repair-hints.js";
18+
import { resolveMissingOfficialExternalChannelPluginRepairHints } from "../../plugins/official-external-plugin-repair-hints.js";
2219
import {
2320
appendBaseUrlBit,
2421
appendEnabledConfiguredLinkedBits,
@@ -109,34 +106,20 @@ export async function formatConfigChannelsStatusLines(
109106
}
110107
}
111108

112-
const missingHints: OfficialExternalPluginRepairHint[] = [];
113109
const missingChannelIds = [
114110
...new Set([
115111
...listExplicitConfiguredChannelIdsForConfig(sourceConfig),
116112
...listExplicitConfiguredChannelIdsForConfig(cfg),
117113
]),
118-
];
119-
const missingHintsByChannelId = new Map(
120-
resolveMissingOfficialExternalChannelPluginRepairHints({
121-
config: cfg,
122-
activationSourceConfig: sourceConfig,
123-
channelIds: missingChannelIds,
124-
}).map((hint) => [hint.channelId, hint]),
114+
].filter(
115+
(channelId) =>
116+
(!requestedChannel || channelId === requestedChannel) && !visibleChannelIds.has(channelId),
125117
);
126-
for (const channelId of missingChannelIds) {
127-
if (requestedChannel && channelId !== requestedChannel) {
128-
continue;
129-
}
130-
if (visibleChannelIds.has(channelId)) {
131-
continue;
132-
}
133-
const hint = missingHintsByChannelId.get(channelId);
134-
if (!hint?.channelId || visibleChannelIds.has(hint.channelId)) {
135-
continue;
136-
}
137-
missingHints.push(hint);
138-
visibleChannelIds.add(hint.channelId);
139-
}
118+
const missingHints = resolveMissingOfficialExternalChannelPluginRepairHints({
119+
config: cfg,
120+
activationSourceConfig: sourceConfig,
121+
channelIds: missingChannelIds,
122+
});
140123
if (missingHints.length > 0) {
141124
lines.push("");
142125
lines.push(theme.warn("Missing official external plugins:"));

‎src/plugins/official-external-plugin-repair-hints.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ describe("resolveMissingOfficialExternalChannelPluginRepairHint", () => {
7474
expect(mocks.resolveConfiguredChannelPresencePolicy).toHaveBeenCalledTimes(1);
7575
});
7676

77+
it("skips presence policy when no channel ids need repair hints", () => {
78+
expect(
79+
resolveMissingOfficialExternalChannelPluginRepairHints({
80+
config: {},
81+
channelIds: [],
82+
}),
83+
).toEqual([]);
84+
expect(mocks.resolveConfiguredChannelPresencePolicy).not.toHaveBeenCalled();
85+
});
86+
7787
it("prefers the ClawHub install hint for externalized WhatsApp", () => {
7888
mocks.resolveConfiguredChannelPresencePolicy.mockReturnValue([
7989
{

‎src/plugins/official-external-plugin-repair-hints.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export function resolveMissingOfficialExternalChannelPluginRepairHints(
7373
channelIds: readonly string[];
7474
},
7575
): MissingOfficialExternalChannelPluginRepairHint[] {
76+
if (params.channelIds.length === 0) {
77+
return [];
78+
}
7679
const policiesByChannelId = new Map(
7780
resolveConfiguredChannelPresencePolicy({
7881
config: params.config,

0 commit comments

Comments
 (0)