fix: refresh watch scope on provider fallback

This commit is contained in:
777genius 2026-05-30 17:34:05 +03:00
parent 06036460e9
commit 9ed1988346
2 changed files with 13 additions and 1 deletions

View file

@ -76,7 +76,7 @@ export function markTeamEngaged(teamName: string, nowMs: number = Date.now()): v
return;
}
const currentScope = computeTeamWatchScope(nowMs);
const wasInScope = currentScope === null || currentScope.has(teamName);
const wasInScope = currentScope?.has(teamName) === true;
engagedAtByTeam.set(teamName, nowMs);
if (!wasInScope) {
scopeChangeListener?.();

View file

@ -69,6 +69,18 @@ describe('teamWatchScope', () => {
expect(computeTeamWatchScope(0)).toBeNull();
});
it('notifies on engagement when alive provider fails so watcher can refresh to fallback', () => {
const listener = vi.fn();
setAliveTeamsProvider(() => {
throw new Error('boom');
});
setTeamWatchScopeChangeListener(listener);
markTeamEngaged('x', 0);
expect(listener).toHaveBeenCalledTimes(1);
});
it('ignores empty team names', () => {
const listener = vi.fn();
setTeamWatchScopeChangeListener(listener);