fix(gateway): refresh health after account removal (#122620)

This commit is contained in:
Peter Steinberger
2026-08-12 05:56:01 -07:00
committed by GitHub
parent beb576c2ad
commit bdc595d1bd
2 changed files with 44 additions and 15 deletions
+7 -15
View File
@@ -33,17 +33,6 @@ function shouldScheduleRequestRefresh(
return true;
}
function cachedAccountForRuntimeSnapshot(params: {
cachedChannel: ChannelHealthSummary | undefined;
accountId: string | undefined;
}): ChannelHealthSummary | undefined {
const accountId = params.accountId;
if (accountId && params.cachedChannel?.accounts?.[accountId]) {
return params.cachedChannel.accounts[accountId];
}
return undefined;
}
function cachedLifecycleDiffersFromRuntime(params: {
cachedAccount: ChannelHealthSummary | undefined;
runtimeSnapshot: ChannelAccountSnapshot;
@@ -82,16 +71,19 @@ function cachedHealthDiffersFromRuntime(
continue;
}
const cachedChannel = cached.channels[channelId];
const cachedAccounts = cachedChannel?.accounts;
if (
Object.keys(cachedAccounts ?? {}).some((accountId) => !Object.hasOwn(accounts, accountId))
) {
return true;
}
for (const [accountId, runtimeSnapshot] of Object.entries(accounts)) {
if (!runtimeSnapshot) {
continue;
}
if (
cachedLifecycleDiffersFromRuntime({
cachedAccount: cachedAccountForRuntimeSnapshot({
cachedChannel,
accountId,
}),
cachedAccount: cachedAccounts?.[accountId],
runtimeSnapshot,
})
) {
@@ -4839,6 +4839,43 @@ describe("gateway healthHandlers.health cache freshness", () => {
});
expect(respond).toHaveBeenCalledWith(true, fresh, undefined);
});
it("refreshes cached health after hot reload removes a runtime account", async () => {
const current = createSingleChannelHealthSnapshot({
channelId: "discord",
label: "Discord",
running: true,
connected: true,
});
const cached = {
...current,
channels: {
discord: {
...current.channels.discord,
accounts: {
...current.channels.discord.accounts,
work: channelHealthAccount({ accountId: "work", running: true, connected: true }),
},
},
},
};
const { respond, refreshHealthSnapshot } = await requestHealthSnapshot({
cached,
fresh: current,
runtimeSnapshot: {
channels: {},
channelAccounts: {
discord: { default: { accountId: "default", running: true, connected: true } },
},
},
});
expect(refreshHealthSnapshot).toHaveBeenCalledWith({
probe: false,
includeSensitive: false,
});
expect(respond).toHaveBeenCalledWith(true, current, undefined);
});
});
describe("logs.tail", () => {