Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test: settle two mount barriers on rendered state instead of a fixed tick (#7597)
[._.]/ Adam Eivy2974e3736c85
diff --git a/client/src/components/brain/tabs/DailyLogTab.test.jsx b/client/src/components/brain/tabs/DailyLogTab.test.jsxindex 2d5374c4cc..77a26dc5a1 100644--- a/client/src/components/brain/tabs/DailyLogTab.test.jsx+++ b/client/src/components/brain/tabs/DailyLogTab.test.jsx@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';import { render, screen, fireEvent, act, within } from '@testing-library/react';import { MemoryRouter } from 'react-router';import { __resetVisibilityEventForTests } from '../../../hooks/useVisibilityEvent';+import { awaitPageLoaded } from '../../../test/pageLoadBarrier';// ── Mock toast ────────────────────────────────────────────────────────────────const mockToast = vi.hoisted(() => Object.assign(vi.fn(), { success: vi.fn(), error: vi.fn() }));@@ -62,11 +63,36 @@ const entryFor = (date, content) => ({let store;+/*+ * Mount, settle, and only then hand the test a running fake clock.+ *+ * The tick-counting form this replaced — `advanceTimersByTimeAsync(0)` inside+ * one `act` flush — settles a FIXED number of microtask turns, not "the mount+ * fetches finished". A mount chain needing one more turn on a loaded machine is+ * measured mid-flight (#7592, the #7448 wrong-barrier shape), and every test in+ * this file inherited that from the shared helper.+ *+ * `awaitPageLoaded` is two-sided on purpose: the spinner must be on screen when+ * the wait starts, so a renamed label fails loudly instead of degrading to a+ * no-op that lets the whole file run against the loading state. 'Loading' is+ * the `text` this tab hands its `BrailleSpinner`, which is also the spinner's+ * accessible name; it is replaced by the editor once `getDailyLog` resolves.+ *+ * Fake timers are armed AFTER that, not in `beforeEach`, because the barrier+ * cannot run under them: @testing-library/dom@10's `jestFakeTimersAreEnabled`+ * only recognizes JEST's, so with vitest's installed it takes its REAL-timer+ * path and then waits on a `setTimeout`/`setInterval` the frozen fake clock+ * owns — `waitFor` never polls again and the test burns its whole timeout.+ * Only `Date` is faked up front, because the open day derives from the system+ * clock; every autosave debounce is armed by a keystroke, which is always+ * after this point, so no timer under test is left on the real clock.+ */const renderTab = async (initialEntries = ['/']) => {// Router context is required: the open day derives from the ?date= param.const result = render(<MemoryRouter initialEntries={initialEntries}><DailyLogTab /></MemoryRouter>);- // Flush the mount fetches (entry + server-today + history + settings).- await act(async () => { await vi.advanceTimersByTimeAsync(0); });+ await awaitPageLoaded('Loading');+ vi.useFakeTimers();+ vi.setSystemTime(new Date(`${TODAY}T12:00:00`));return result;};@@ -76,7 +102,8 @@ const editor = () => document.querySelector('textarea');beforeEach(() => {vi.clearAllMocks();- vi.useFakeTimers();+ // Date only until the mount has settled — see renderTab.+ vi.useFakeTimers({ toFake: ['Date'] });vi.setSystemTime(new Date(`${TODAY}T12:00:00`));store = { [TODAY]: entryFor(TODAY, 'existing'), [YESTERDAY]: entryFor(YESTERDAY, 'old day') };diff --git a/client/src/components/media/MediaJobsQueue.test.jsx b/client/src/components/media/MediaJobsQueue.test.jsxindex 3d5e386bc7..4fe622a789 100644--- a/client/src/components/media/MediaJobsQueue.test.jsx+++ b/client/src/components/media/MediaJobsQueue.test.jsx@@ -486,7 +486,7 @@ describe('MediaJobsQueue — training rows', () => {// tab. This is the gated (`enabled`) half of the migration; MemoryManagement// covers the unconditional half.describe('MediaJobsQueue — hidden-tab polling (#5697)', () => {- beforeEach(() => { vi.useFakeTimers(); });+ beforeEach(() => { vi.useFakeTimers({ shouldAdvanceTime: true }); });afterEach(() => { vi.useRealTimers(); });it('pauses the checkpoint poll while the tab is hidden and re-fires on return', async () => {@@ -494,7 +494,41 @@ describe('MediaJobsQueue — hidden-tab polling (#5697)', () => {listLoraTrainingCheckpoints.mockResolvedValue({ checkpoints: [] });render(<MediaJobsQueue kind="training" />);- await act(async () => { await vi.advanceTimersByTimeAsync(0); });+ /*+ * Settle the mount on an OBSERVABLE state before taking the baseline call+ * counts below.+ *+ * The tick-counting form this replaced — `advanceTimersByTimeAsync(0)`+ * inside one `act` flush — settles a FIXED number of microtask turns, not+ * "the mount fetches finished". A mount chain needing one more turn on a+ * loaded machine is measured mid-flight, and the counts race BOTH ways+ * (#7592/#7448): the checkpoint assertion goes red, and+ * `listMediaJobs.mock.calls.length` is a baseline taken before the list had+ * loaded — so "the count did not move" then passes for the wrong reason,+ * because nothing had loaded to move it.+ *+ * `TrainingJobDetail` renders this copy only once `listLoraTrainingCheckpoints`+ * has RESOLVED (`checkpoints` leaves its `null` loading sentinel), and it+ * only renders at all once the job list has landed and produced the row —+ * so it is the end of both mount chains.+ *+ * The fake clock stays armed across the mount, unlike BeeperTab's+ * settle-then-arm order (#7592): BOTH polls under test here are+ * `setInterval`s registered during mount, so a real-timer mount would leave+ * them on the real clock where `advanceTimersByTimeAsync` cannot reach them+ * — and both "did not fire while hidden" assertions would pass vacuously+ * again, for a new reason.+ *+ * `shouldAdvanceTime` is what makes the barrier possible under that armed+ * clock, and is NOT optional here. @testing-library/dom@10's+ * `jestFakeTimersAreEnabled` only recognizes JEST's fake timers, so with+ * vitest's installed `waitFor` takes its REAL-timer path and then waits on+ * a timer the fake clock owns: against a frozen clock it never polls again+ * and the test burns its whole timeout. Auto-advancing in step with real+ * time keeps that poll alive at the cost of a few ms of fake clock — three+ * orders below the 5s poll interval these assertions measure.+ */+ await screen.findByText(/No checkpoints yet/);expect(listLoraTrainingCheckpoints).toHaveBeenCalledTimes(1);const jobListCalls = listMediaJobs.mock.calls.length;diff --git a/client/src/test/pageLoadBarrier.js b/client/src/test/pageLoadBarrier.jsindex 5675a6a988..e99ab36d15 100644--- a/client/src/test/pageLoadBarrier.js+++ b/client/src/test/pageLoadBarrier.js@@ -15,8 +15,11 @@ import { screen, waitForElementToBeRemoved } from '@testing-library/react';* `waitForElementToBeRemoved` throws when the element was not there to begin* with, so a label that stops matching fails loudly instead of silently* becoming a no-op. Pass the `label` a page hands its `PageSkeleton`, which is- * the skeleton's accessible name.+ * the skeleton's accessible name — or the accessible name of whatever else the+ * page shows while loading, e.g. the `text` handed to a `BrailleSpinner`+ * (`DailyLogTab` waits on `'Loading'`).*- * @param {string} label the PageSkeleton `label` prop, e.g. 'Loading timeline project'+ * @param {string} label the loading indicator's accessible name, e.g. the+ * PageSkeleton `label` prop 'Loading timeline project'*/export const awaitPageLoaded = (label) => waitForElementToBeRemoved(screen.getByLabelText(label));