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
refactor: settle the Beeper mount on real timers and drop the duplicated barrier prose
[._.]/ Adam Eivy1760ade959c5
diff --git a/client/src/components/messages/BeeperTab.test.jsx b/client/src/components/messages/BeeperTab.test.jsxindex e13f9fd3fc..bf7f1f7120 100644--- a/client/src/components/messages/BeeperTab.test.jsx+++ b/client/src/components/messages/BeeperTab.test.jsx@@ -134,11 +134,17 @@ const renderTab = (initialPath = '/messages/beeper') => render(* #7448 wrong-barrier shape). Worse, the counts race BOTH ways: a test that* asserts a count did NOT move passes vacuously when nothing had loaded yet.*- * The rendered conversation title is the end of that chain. `findAllByText`+ * The rendered conversation title is the end of that chain — it is the default+ * `conversation()` fixture's own title, hence no parameter. `findAllByText`* rather than `findByText` because the title appears in the list row as well as* the thread header whenever the list fixture is populated.+ *+ * Call this BEFORE arming `vi.useFakeTimers`. Under fake timers Testing+ * Library's `waitFor` has no MutationObserver and degrades to an act-flush ++ * advance(50) poll loop: it costs ~20ms of wall clock per test and burns+ * fake-clock time on the very clock the debounce assertions are measuring.*/-const awaitThreadLoaded = (title = 'Example Conversation') => screen.findAllByText(title);+const awaitThreadLoaded = () => screen.findAllByText('Example Conversation');beforeEach(() => {vi.clearAllMocks();@@ -691,7 +697,6 @@ describe('the composer sends', () => {fireEvent.click(screen.getByRole('button', { name: 'Send' }));expect(await screen.findByText(/first message PortOS has sent to Example Contact on WhatsApp/)).toBeInTheDocument();const pendingRow = await screen.findByTestId('beeper-outbox-row');- expect(pendingRow).toBeInTheDocument();fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));@@ -700,7 +705,7 @@ describe('the composer sends', () => {// RESOLVES. Wait on the captured NODE rather than re-querying: a// `queryBy… toBeNull` wait passes on its first poll, so it would report// green against a row that had simply not been torn down yet, while this- // form is anchored by the assertion above that the node was really there.+ // form is anchored by the `findBy` above, which throws if it was never there.await waitFor(() => expect(pendingRow).not.toBeInTheDocument());// The question closes and the composer text is untouched — Cancel only// withdraws the send, it does not clear the draft.@@ -806,10 +811,10 @@ describe('realtime', () => {});it('refetches the list and the open thread after an invalidation frame', async () => {+ renderTab(`/messages/beeper/${CONV_A}`);+ await awaitThreadLoaded(); // settle on REAL timers — see the helpervi.useFakeTimers({ shouldAdvanceTime: true });try {- renderTab(`/messages/beeper/${CONV_A}`);- await awaitThreadLoaded();const listCalls = api.getBeeperConversations.mock.calls.length;const threadCalls = api.getBeeperMessages.mock.calls.length;@@ -833,10 +838,10 @@ describe('realtime', () => {// networks still refetch unconditionally (their previews/unread counts DO// change for any chat); only the thread refetch is now frame-scoped.it('does not refetch the open thread on an invalidation frame for another chat', async () => {+ renderTab(`/messages/beeper/${CONV_A}`);+ await awaitThreadLoaded(); // settle on REAL timers — see the helpervi.useFakeTimers({ shouldAdvanceTime: true });try {- renderTab(`/messages/beeper/${CONV_A}`);- await awaitThreadLoaded();const listCalls = api.getBeeperConversations.mock.calls.length;const threadCalls = api.getBeeperMessages.mock.calls.length;@@ -857,10 +862,10 @@ describe('realtime', () => {});it('refetches the open thread on a frame naming its chat, or with no chatID at all', async () => {+ renderTab(`/messages/beeper/${CONV_A}`);+ await awaitThreadLoaded(); // settle on REAL timers — see the helpervi.useFakeTimers({ shouldAdvanceTime: true });try {- renderTab(`/messages/beeper/${CONV_A}`);- await awaitThreadLoaded();let threadCalls = api.getBeeperMessages.mock.calls.length;act(() => {@@ -939,10 +944,10 @@ describe('realtime', () => {// each one arriving inside the previous frame's 350ms coalescing window —// reset it forever and the view never refreshed at all.it('still refetches within the bounded max wait despite a sustained stream of invalidation frames', async () => {+ renderTab(`/messages/beeper/${CONV_A}`);+ await awaitThreadLoaded(); // settle on REAL timers — see the helpervi.useFakeTimers({ shouldAdvanceTime: true });try {- renderTab(`/messages/beeper/${CONV_A}`);- await awaitThreadLoaded();const listCalls = api.getBeeperConversations.mock.calls.length;// A frame every 200ms, well inside the 350ms debounce, for 2.4s total —@@ -1086,14 +1091,10 @@ describe('list pagination (Load more)', () => {});describe('the two wired rail controls', () => {- /**- * The rail's scope chip and the thread header's action share a name, but only- * the chip is on screen before the conversation detail lands. A bare- * `findByRole` therefore resolves on the FIRST poll and `.at(-1)` hands back- * the RAIL chip — clicking it switches scope instead of writing, the awaited- * API call never happens, and the test burns its whole async budget (#7592).- * Wait for the second control, which is exactly "the thread has loaded".- */+ // The rail's scope chip and the thread header's action share a name, but only+ // the chip exists before the conversation detail lands — so `.at(-1)` on a+ // bare `findByRole` silently hands back the CHIP. Waiting for the second+ // control is exactly "the thread header has rendered".const findThreadAction = (name) => waitFor(() => {const controls = screen.getAllByRole('button', { name });expect(controls.length).toBeGreaterThan(1);@@ -1159,7 +1160,6 @@ describe('the local "seen in PortOS" watermark (#83)', () => {vi.useFakeTimers({ shouldAdvanceTime: true });try {renderTab(`/messages/beeper/${CONV_A}`);- await awaitThreadLoaded();await waitFor(() => expect(api.markBeeperConversationSeen).toHaveBeenCalledWith(CONV_A, { silent: true }));api.markBeeperConversationSeen.mockClear();@@ -1201,7 +1201,6 @@ describe('the local "seen in PortOS" watermark (#83)', () => {api.getBeeperMessages.mockResolvedValue({ messages: [known], nextCursor: null });renderTab(`/messages/beeper/${CONV_A}`);- await awaitThreadLoaded();await waitFor(() => expect(api.markBeeperConversationSeen).toHaveBeenCalledWith(CONV_A, { silent: true }));api.markBeeperConversationSeen.mockClear();diff --git a/client/src/components/music/MusicDesigner.test.jsx b/client/src/components/music/MusicDesigner.test.jsxindex ecbfb0c189..01e3530df1 100644--- a/client/src/components/music/MusicDesigner.test.jsx+++ b/client/src/components/music/MusicDesigner.test.jsx@@ -157,8 +157,8 @@ describe('<MusicDesigner>', () => {});renderAt('/music/generate/concept?trackId=track-saved');- // Wait for the saved track to actually hydrate — on the weaker barrier the- // key is trivially untouched because nothing has run yet.+ // Hydration is what could clobber the unrelated `activeDraft` key, so the+ // assertion below only means something once it has actually run.await awaitDraftLoaded(/what do you want to hear/i);expect(window.localStorage.getItem('portos.musicDesigner.activeDraft')).toBe('track-draft');});diff --git a/client/src/pages/StartStory.test.jsx b/client/src/pages/StartStory.test.jsxindex 85771b3479..2a8037fc6d 100644--- a/client/src/pages/StartStory.test.jsx+++ b/client/src/pages/StartStory.test.jsx@@ -18,17 +18,23 @@ vi.mock('../components/ui/Toast', () => ({default: { error: (...a) => toastError(...a) },}));-// The universe list gates the "Use an existing universe" radio — it renders-// `disabled` until a NAMED universe lands — but all three mode cards come from a-// static list and are on screen synchronously. Waiting on card text therefore-// resolves on the FIRST poll, before the fetch: the click then lands on a-// disabled radio, silently does nothing, and the next `findBy*` burns the whole-// async budget waiting for a select that will never render (#7592, the #7448-// wrong-barrier shape). Wait on the control the click actually needs instead.-const clickUseExistingUniverse = async () => {+// Opt into "use an existing universe" and return the picker it renders.+//+// The universe list gates that radio — it renders `disabled` until a NAMED+// universe lands — but all three mode cards come from a static list and are on+// screen synchronously. Waiting on card text therefore resolves on the FIRST+// poll, before the fetch: the click then lands on a disabled radio, silently+// does nothing, and the next `findBy*` burns the whole async budget waiting for+// a select that will never render (#7592, the #7448 wrong-barrier shape).+//+// Returning the select rather than nothing is deliberate — it makes the helper+// assert that opting in actually TOOK, so it stays honest even if the+// `disabled` gate it waits on is ever removed.+const openExistingUniversePicker = async () => {const radio = await screen.findByLabelText('Use an existing universe');await waitFor(() => expect(radio).not.toBeDisabled());fireEvent.click(radio);+ return screen.findByLabelText('Existing universe');};describe('StartStory onramp', () => {@@ -57,8 +63,7 @@ describe('StartStory onramp', () => {it('forwards the chosen universe to engines that consume it', async () => {render(<StartStory />);// Opt into an existing universe, then select one.- await clickUseExistingUniverse();- const select = await screen.findByLabelText('Existing universe');+ const select = await openExistingUniversePicker();fireEvent.change(select, { target: { value: 'u2' } });fireEvent.click(screen.getByText('From an idea'));@@ -70,8 +75,7 @@ describe('StartStory onramp', () => {it('does not forward a universe to prose mode (no universe link yet)', async () => {render(<StartStory />);- await clickUseExistingUniverse();- const select = await screen.findByLabelText('Existing universe');+ const select = await openExistingUniversePicker();fireEvent.change(select, { target: { value: 'u1' } });fireEvent.click(screen.getByText('From writing prose'));@@ -80,7 +84,7 @@ describe('StartStory onramp', () => {it('blocks the cards until a universe is picked when using an existing one', async () => {render(<StartStory />);- await clickUseExistingUniverse();+ await openExistingUniversePicker();// No universe selected yet — clicking a card should not navigate.fireEvent.click(screen.getByText('From an idea'));expect(navigateMock).not.toHaveBeenCalled();@@ -96,8 +100,7 @@ describe('StartStory onramp', () => {{ id: 'u3', name: ' ' },]);render(<StartStory />);- await clickUseExistingUniverse();- const select = await screen.findByLabelText('Existing universe');+ const select = await openExistingUniversePicker();// Only the placeholder + the one named universe.const options = select.querySelectorAll('option');expect(options.length).toBe(2);