





















@@ -13,6 +13,10 @@ let setActivePluginRegistry: typeof import("../plugins/runtime.js").setActivePlu
1313let createChannelTestPluginBase: typeof import("../test-utils/channel-plugins.js").createChannelTestPluginBase;
1414let createTestRegistry: typeof import("../test-utils/channel-plugins.js").createTestRegistry;
1515let getHealthSnapshot: typeof import("./health.js").getHealthSnapshot;
16+let buildTelegramHealthSummaryForTest = buildTelegramHealthSummary;
17+let probeTelegramAccountForTestOverride:
18+| ((account: TelegramHealthAccount, timeoutMs: number) => Promise<Record<string, unknown>>)
19+| undefined;
16201721type TelegramHealthAccount = {
1822accountId: string;
@@ -289,9 +293,12 @@ function createTelegramHealthPlugin(): Pick<
289293isConfigured: (account) => Boolean((account as TelegramHealthAccount).token.trim()),
290294},
291295status: {
292-buildChannelSummary: ({ snapshot }) => buildTelegramHealthSummary(snapshot),
296+buildChannelSummary: ({ snapshot }) => buildTelegramHealthSummaryForTest(snapshot),
293297probeAccount: async ({ account, timeoutMs }) =>
294-await probeTelegramAccountForTest(account as TelegramHealthAccount, timeoutMs),
298+await (probeTelegramAccountForTestOverride ?? probeTelegramAccountForTest)(
299+account as TelegramHealthAccount,
300+timeoutMs,
301+),
295302},
296303};
297304}
@@ -307,6 +314,8 @@ describe("getHealthSnapshot", () => {
307314});
308315309316beforeEach(() => {
317+buildTelegramHealthSummaryForTest = buildTelegramHealthSummary;
318+probeTelegramAccountForTestOverride = undefined;
310319setActivePluginRegistry(
311320createTestRegistry([
312321{ pluginId: "telegram", plugin: createTelegramHealthPlugin(), source: "test" },
@@ -421,6 +430,116 @@ describe("getHealthSnapshot", () => {
421430}
422431});
423432433+it("preserves runtime state and probe payloads when plugin summaries omit them", async () => {
434+testConfig = { channels: { telegram: { botToken: "t-1" } } };
435+testStore = {};
436+vi.stubEnv("DISCORD_BOT_TOKEN", "");
437+buildTelegramHealthSummaryForTest = (snapshot) => ({
438+accountId: snapshot.accountId,
439+configured: Boolean(snapshot.configured),
440+});
441+probeTelegramAccountForTestOverride = async () => ({
442+ok: true,
443+bot: { username: "runtime_bot" },
444+});
445+446+const snap = await getHealthSnapshot({
447+timeoutMs: 25,
448+runtimeSnapshot: {
449+channels: {
450+telegram: {
451+accountId: "default",
452+connected: true,
453+lastConnectedAt: 123,
454+},
455+},
456+channelAccounts: {},
457+},
458+});
459+const telegram = snap.channels.telegram as {
460+connected?: boolean;
461+lastConnectedAt?: number;
462+probe?: { ok?: boolean; bot?: { username?: string } };
463+accounts?: Record<
464+string,
465+{
466+connected?: boolean;
467+lastConnectedAt?: number;
468+probe?: { ok?: boolean; bot?: { username?: string } };
469+}
470+>;
471+};
472+473+expect(telegram.connected).toBe(true);
474+expect(telegram.lastConnectedAt).toBe(123);
475+expect(telegram.probe?.bot?.username).toBe("runtime_bot");
476+expect(telegram.accounts?.default?.connected).toBe(true);
477+expect(telegram.accounts?.default?.probe?.ok).toBe(true);
478+});
479+480+it("omits secret runtime fields and raw probe payloads from non-sensitive health snapshots", async () => {
481+testConfig = { channels: { telegram: { botToken: "t-1" } } };
482+testStore = {};
483+vi.stubEnv("DISCORD_BOT_TOKEN", "");
484+buildTelegramHealthSummaryForTest = (snapshot) => ({
485+accountId: snapshot.accountId,
486+configured: Boolean(snapshot.configured),
487+probe: { ok: true, token: "summary-secret" },
488+});
489+probeTelegramAccountForTestOverride = async () => ({
490+ok: true,
491+bot: { username: "runtime_bot" },
492+token: "probe-secret",
493+});
494+495+const snap = await getHealthSnapshot({
496+timeoutMs: 25,
497+includeSensitive: false,
498+runtimeSnapshot: {
499+channels: {
500+telegram: {
501+accountId: "default",
502+connected: true,
503+lastConnectedAt: 123,
504+channelAccessToken: "line-token",
505+channelSecret: "line-secret", // pragma: allowlist secret
506+webhookUrl: "https://example.test/hook?secret=1",
507+},
508+},
509+channelAccounts: {},
510+},
511+});
512+const telegram = snap.channels.telegram as {
513+connected?: boolean;
514+lastConnectedAt?: number;
515+probe?: unknown;
516+channelAccessToken?: string;
517+channelSecret?: string;
518+webhookUrl?: string;
519+accounts?: Record<
520+string,
521+{
522+connected?: boolean;
523+lastConnectedAt?: number;
524+probe?: unknown;
525+channelAccessToken?: string;
526+channelSecret?: string;
527+webhookUrl?: string;
528+}
529+>;
530+};
531+532+expect(telegram.connected).toBe(true);
533+expect(telegram.lastConnectedAt).toBe(123);
534+expect(telegram.probe).toBeUndefined();
535+expect(telegram.channelAccessToken).toBeUndefined();
536+expect(telegram.channelSecret).toBeUndefined();
537+expect(telegram.webhookUrl).toBeUndefined();
538+expect(telegram.accounts?.default?.connected).toBe(true);
539+expect(telegram.accounts?.default?.probe).toBeUndefined();
540+expect(telegram.accounts?.default?.channelAccessToken).toBeUndefined();
541+});
542+424543it("returns structured telegram probe errors", async () => {
425544testConfig = { channels: { telegram: { botToken: "bad-token" } } };
426545testStore = {};
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。