test: tighten channel summary coverage

This commit is contained in:
Peter Steinberger
2026-03-13 23:53:20 +00:00
parent a5a2e487c7
commit 2e409da274

View File

@@ -66,6 +66,64 @@ function makeSlackHttpSummaryPlugin(): ChannelPlugin {
};
}
function makeTelegramSummaryPlugin(params: {
enabled: boolean;
configured: boolean;
linked?: boolean;
authAgeMs?: number;
allowFrom?: string[];
}): ChannelPlugin {
return {
id: "telegram",
meta: {
id: "telegram",
label: "Telegram",
selectionLabel: "Telegram",
docsPath: "/channels/telegram",
blurb: "test",
},
capabilities: { chatTypes: ["direct"] },
config: {
listAccountIds: () => ["primary"],
defaultAccountId: () => "primary",
inspectAccount: () => ({
accountId: "primary",
name: "Main Bot",
enabled: params.enabled,
configured: params.configured,
linked: params.linked,
allowFrom: params.allowFrom ?? [],
dmPolicy: "mutuals",
tokenSource: "env",
}),
resolveAccount: () => ({
accountId: "primary",
name: "Main Bot",
enabled: params.enabled,
configured: params.configured,
linked: params.linked,
allowFrom: params.allowFrom ?? [],
dmPolicy: "mutuals",
tokenSource: "env",
}),
isConfigured: (account) => Boolean((account as { configured?: boolean }).configured),
isEnabled: (account) => Boolean((account as { enabled?: boolean }).enabled),
formatAllowFrom: () => ["alice", "bob", "carol"],
},
status: {
buildChannelSummary: async () => ({
linked: params.linked,
configured: params.configured,
authAgeMs: params.authAgeMs,
self: { e164: "+15551234567" },
}),
},
actions: {
listActions: () => ["send"],
},
};
}
describe("buildChannelSummary", () => {
it("preserves Slack HTTP signing-secret unavailable state from source config", async () => {
vi.mocked(listChannelPlugins).mockReturnValue([makeSlackHttpSummaryPlugin()]);
@@ -81,4 +139,37 @@ describe("buildChannelSummary", () => {
" - primary (Primary) (bot:config, signing:config, secret unavailable in this command path)",
);
});
it("shows disabled status without configured account detail lines", async () => {
vi.mocked(listChannelPlugins).mockReturnValue([
makeTelegramSummaryPlugin({ enabled: false, configured: false }),
]);
const lines = await buildChannelSummary({ channels: {} } as never, {
colorize: false,
includeAllowFrom: true,
});
expect(lines).toEqual(["Telegram: disabled +15551234567"]);
});
it("includes linked summary metadata and truncates allow-from details", async () => {
vi.mocked(listChannelPlugins).mockReturnValue([
makeTelegramSummaryPlugin({
enabled: true,
configured: true,
linked: true,
authAgeMs: 300_000,
allowFrom: ["alice", "bob", "carol"],
}),
]);
const lines = await buildChannelSummary({ channels: {} } as never, {
colorize: false,
includeAllowFrom: true,
});
expect(lines).toContain("Telegram: linked +15551234567 auth 5m ago");
expect(lines).toContain(" - primary (Main Bot) (dm:mutuals, token:env, allow:alice,bob)");
});
});