test(dashboard): purge leaked mockResolvedValueOnce queues in App.test isolation reset

Root-cause fix for the order-sensitive 'closes board-opened main-panel
task detail on one browser back' flake: vi.clearAllMocks() clears calls
but never drops unconsumed mockResolvedValueOnce entries, and a plain
mockResolvedValue default does not purge them either — the once-queue
wins first. A prior test's unconsumed auth/settings/health/plugin-views
Once value poisoned the next test's first fetch, rendering an
auto-opened modal surface instead of the board. The global beforeEach
now mockReset()s every once-queue-prone API mock before re-applying its
default (fetchPluginDashboardViews gains an explicit empty default
since its factory impl dies with the reset). 4/4 consecutive full-file
runs green (was ~1-in-3 failing); no assertions changed, no quarantine
needed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-08-15 22:25:01 -07:00
parent 59d53b42a8
commit 4bb994f50c

View File

@@ -824,7 +824,20 @@ beforeEach(() => {
/*
* FNXC:DashboardTests 2026-06-22-03:47:
* App.test.tsx runs beside other dashboard specs in the same Vitest process, so reset API mock implementations as well as call counts to prevent cross-file implementation leakage.
*
* FNXC:DashboardTests 2026-08-16-05:22:
* vi.clearAllMocks() clears calls but NEVER drops unconsumed mockResolvedValueOnce queue
* entries, and a plain mockResolvedValue default does not purge them either — the once-queue
* always wins first. A test that queued a Once response and bailed before consuming it (auth
* status, settings, health, plugin views) therefore poisoned the NEXT test's first fetch,
* which is why "closes board-opened main-panel task detail on one browser back" flaked: a
* leaked auth/settings Once value made App render an auto-opened modal surface instead of the
* board. mockReset each once-queue-prone API mock here, then re-apply its default below.
*/
for (const onceProneApiMock of [fetchSettings, updateSettings, fetchGlobalSettings, fetchDashboardHealth, fetchAuthStatus, fetchModels, fetchScripts, runScript, fetchBoardWorkflows, fetchPluginDashboardViews]) {
vi.mocked(onceProneApiMock).mockReset();
}
vi.mocked(fetchPluginDashboardViews).mockResolvedValue([]);
vi.mocked(fetchSettings).mockResolvedValue({ ...defaultSettings });
vi.mocked(updateSettings).mockResolvedValue({ ...defaultSettings });
vi.mocked(fetchGlobalSettings).mockResolvedValue({ modelOnboardingComplete: true });