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
fix: wait on the control each step needs, not on markup that is already there (#7592)
[._.]/ Adam Eivy606b5b40ac60
diff --git a/client/src/components/messages/BeeperTab.test.jsx b/client/src/components/messages/BeeperTab.test.jsxindex 6c4c3fd226..e13f9fd3fc 100644--- a/client/src/components/messages/BeeperTab.test.jsx+++ b/client/src/components/messages/BeeperTab.test.jsx@@ -123,6 +123,23 @@ const renderTab = (initialPath = '/messages/beeper') => render(</MemoryRouter>,);+/**+ * "Every mount fetch has settled", as an OBSERVABLE state.+ *+ * The tick-counting form this replaced — `advanceTimersByTimeAsync(0)` plus one+ * `act` flush — settles a FIXED number of microtask turns. A mount chain that+ * takes one more turn on a loaded machine is then measured mid-flight, so the+ * baseline call counts taken after it are the wrong numbers and the refetch+ * assertion races the initial load instead of testing the frame (#7592, the+ * #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`+ * rather than `findByText` because the title appears in the list row as well as+ * the thread header whenever the list fixture is populated.+ */+const awaitThreadLoaded = (title = 'Example Conversation') => screen.findAllByText(title);+beforeEach(() => {vi.clearAllMocks();socketMock.handlers.clear();@@ -673,15 +690,21 @@ 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();- expect(await screen.findByTestId('beeper-outbox-row')).toBeInTheDocument();+ const pendingRow = await screen.findByTestId('beeper-outbox-row');+ expect(pendingRow).toBeInTheDocument();fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));await waitFor(() => expect(apiBeeper.discardOutboxEntry).toHaveBeenCalledWith('outbox-1', { silent: true }));- // The question closes, the phantom bubble is gone, and the composer text is- // untouched — Cancel only withdraws the send, it does not clear the draft.- await waitFor(() => expect(screen.queryByText(/send it\?/)).toBeNull());- expect(screen.queryByTestId('beeper-outbox-row')).toBeNull();+ // The discard CALL landing is not the removal — the row goes when that call+ // 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.+ 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.+ expect(screen.queryByText(/send it\?/)).toBeNull();expect(composer).toHaveValue(OUTBOUND_TEXT);// A GET /outbox after the cancel (e.g. a reload) no longer returns the row.@@ -701,7 +724,13 @@ describe('the composer sends', () => {await Promise.resolve();});- await waitFor(() => expect(apiBeeper.createOutboxEntry).toHaveBeenCalledTimes(1));+ // Wait on the LAST hop of the chain, not the first: `sendOutboxEntry` only+ // fires once the create resolves, so a barrier on the create count says+ // nothing about it. Both duplicates a broken latch would produce are issued+ // from the same render, so by the time the send lands they have landed too —+ // the exact counts below are what the latch is actually being held to.+ await waitFor(() => expect(apiBeeper.sendOutboxEntry).toHaveBeenCalled());+ expect(apiBeeper.createOutboxEntry).toHaveBeenCalledTimes(1);expect(apiBeeper.sendOutboxEntry).toHaveBeenCalledTimes(1);});@@ -780,10 +809,7 @@ describe('realtime', () => {vi.useFakeTimers({ shouldAdvanceTime: true });try {renderTab(`/messages/beeper/${CONV_A}`);- // Settle every mount fetch inside act() before measuring — otherwise the- // refetch assertion races the initial load rather than the frame.- await act(async () => { await vi.advanceTimersByTimeAsync(0); });- await act(async () => {});+ await awaitThreadLoaded();const listCalls = api.getBeeperConversations.mock.calls.length;const threadCalls = api.getBeeperMessages.mock.calls.length;@@ -810,8 +836,7 @@ describe('realtime', () => {vi.useFakeTimers({ shouldAdvanceTime: true });try {renderTab(`/messages/beeper/${CONV_A}`);- await act(async () => { await vi.advanceTimersByTimeAsync(0); });- await act(async () => {});+ await awaitThreadLoaded();const listCalls = api.getBeeperConversations.mock.calls.length;const threadCalls = api.getBeeperMessages.mock.calls.length;@@ -835,8 +860,7 @@ describe('realtime', () => {vi.useFakeTimers({ shouldAdvanceTime: true });try {renderTab(`/messages/beeper/${CONV_A}`);- await act(async () => { await vi.advanceTimersByTimeAsync(0); });- await act(async () => {});+ await awaitThreadLoaded();let threadCalls = api.getBeeperMessages.mock.calls.length;act(() => {@@ -918,8 +942,7 @@ describe('realtime', () => {vi.useFakeTimers({ shouldAdvanceTime: true });try {renderTab(`/messages/beeper/${CONV_A}`);- await act(async () => { await vi.advanceTimersByTimeAsync(0); });- await act(async () => {});+ await awaitThreadLoaded();const listCalls = api.getBeeperConversations.mock.calls.length;// A frame every 200ms, well inside the 350ms debounce, for 2.4s total —@@ -1018,8 +1041,10 @@ describe('thread pagination', () => {fireEvent.click(screen.getByRole('button', { name: 'Load earlier messages' }));await waitFor(() => expect(api.getBeeperMessages).toHaveBeenLastCalledWith(CONV_A, { cursor: 'cursor-a' }, { silent: true }));- // Switch conversations while A's load-more is still in flight.- fireEvent.click(screen.getByText('Example B'));+ // Switch conversations while A's load-more is still in flight. The thread+ // barrier above says nothing about the LIST, which is a separate fetch — so+ // the row has to be waited for in its own right.+ fireEvent.click(await screen.findByText('Example B'));await screen.findByText('Placeholder B newest');const loadMoreForB = await screen.findByRole('button', { name: 'Load earlier messages' });@@ -1061,16 +1086,26 @@ 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".+ */+ const findThreadAction = (name) => waitFor(() => {+ const controls = screen.getAllByRole('button', { name });+ expect(controls.length).toBeGreaterThan(1);+ return controls.at(-1);+ });+it('archives through the API and reflects the value the server returned', async () => {api.getBeeperConversation.mockResolvedValue(conversation({ title: 'Example Contact' }));api.setBeeperConversationArchived.mockResolvedValue(conversation({ title: 'Example Contact', isArchived: true }));renderTab(`/messages/beeper/${CONV_A}`);- const button = await screen.findByRole('button', { name: 'Archive', hidden: false });- // Two controls carry the Archive name (the rail scope and the thread- // action); the thread action is the one inside the header row.- const threadArchive = screen.getAllByRole('button', { name: 'Archive' }).at(-1);- expect(button).toBeTruthy();+ const threadArchive = await findThreadAction('Archive');act(() => { threadArchive.click(); });await waitFor(() => expect(api.setBeeperConversationArchived).toHaveBeenCalledWith(CONV_A, true, { silent: true }));@@ -1084,9 +1119,7 @@ describe('the two wired rail controls', () => {);renderTab(`/messages/beeper/${CONV_A}`);- const button = await screen.findByRole('button', { name: 'Low priority', hidden: false });- const threadControl = screen.getAllByRole('button', { name: 'Low priority' }).at(-1);- expect(button).toBeTruthy();+ const threadControl = await findThreadAction('Low priority');act(() => { threadControl.click(); });await waitFor(() => expect(toast.error).toHaveBeenCalledWith('Beeper request failed: connection refused'));@@ -1126,8 +1159,7 @@ describe('the local "seen in PortOS" watermark (#83)', () => {vi.useFakeTimers({ shouldAdvanceTime: true });try {renderTab(`/messages/beeper/${CONV_A}`);- await act(async () => { await vi.advanceTimersByTimeAsync(0); });- await act(async () => {});+ await awaitThreadLoaded();await waitFor(() => expect(api.markBeeperConversationSeen).toHaveBeenCalledWith(CONV_A, { silent: true }));api.markBeeperConversationSeen.mockClear();@@ -1169,8 +1201,7 @@ describe('the local "seen in PortOS" watermark (#83)', () => {api.getBeeperMessages.mockResolvedValue({ messages: [known], nextCursor: null });renderTab(`/messages/beeper/${CONV_A}`);- await act(async () => { await vi.advanceTimersByTimeAsync(0); });- await act(async () => {});+ 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 98ce7af81a..ecbfb0c189 100644--- a/client/src/components/music/MusicDesigner.test.jsx+++ b/client/src/components/music/MusicDesigner.test.jsx@@ -61,6 +61,19 @@ const renderAt = (path) => render(</MemoryRouter>,);+// Every step's field is on screen from the first paint but sits `disabled`+// until the draft create/get resolves, and the step's action buttons are gated+// on that same `draftReady`. A bare `findByLabelText` therefore resolves on the+// FIRST poll, before any of it — the interaction that follows lands on a+// disabled control, silently does nothing, and the next wait burns the whole+// async budget (#7592, the #7448 wrong-barrier shape). Wait for the field to be+// usable, which is exactly the state "the draft has loaded and hydrated".+const awaitDraftLoaded = async (label) => {+ const field = await screen.findByLabelText(label);+ await waitFor(() => expect(field).not.toBeDisabled());+ return field;+};+describe('<MusicDesigner>', () => {beforeEach(() => {vi.clearAllMocks();@@ -114,11 +127,14 @@ describe('<MusicDesigner>', () => {it('reopens the active unnamed draft after leaving the Music section', async () => {renderAt('/music/generate/concept');- await screen.findByLabelText(/what do you want to hear/i);+ // The resume hint is written by the hydrate that ends the draft load, so+ // unmounting on the weaker barrier would leave storage empty and the+ // second visit with nothing to reopen.+ await awaitDraftLoaded(/what do you want to hear/i);cleanup();renderAt('/music/generate/lyrics');- await screen.findByLabelText('Lyrics');+ await awaitDraftLoaded('Lyrics');expect(api.getTrack).toHaveBeenCalledWith('track-draft', { silent: true });});@@ -129,8 +145,7 @@ describe('<MusicDesigner>', () => {});renderAt('/music/generate/lyrics?trackId=track-saved');- expect(await screen.findByLabelText('Lyrics')).toHaveValue('[verse]\nKeep moving');- expect(screen.getByLabelText('Lyrics')).toHaveValue('[verse]\nKeep moving');+ expect(await awaitDraftLoaded('Lyrics')).toHaveValue('[verse]\nKeep moving');expect(api.getTrack).toHaveBeenCalledWith('track-saved', { silent: true });expect(api.createTrack).not.toHaveBeenCalled();});@@ -142,7 +157,9 @@ describe('<MusicDesigner>', () => {});renderAt('/music/generate/concept?trackId=track-saved');- await screen.findByLabelText(/what do you want to hear/i);+ // Wait for the saved track to actually hydrate — on the weaker barrier the+ // key is trivially untouched because nothing has run yet.+ await awaitDraftLoaded(/what do you want to hear/i);expect(window.localStorage.getItem('portos.musicDesigner.activeDraft')).toBe('track-draft');});@@ -153,7 +170,7 @@ describe('<MusicDesigner>', () => {});renderAt('/music/generate/render?trackId=track-saved');- const prompt = await screen.findByLabelText(/prompt for this render/i);+ const prompt = await awaitDraftLoaded(/prompt for this render/i);expect(prompt).toHaveValue('Warm synths and a patient beat.');fireEvent.change(prompt, { target: { value: 'A brighter pulse with hand percussion.' } });expect(screen.getByTestId('gen-panel')).toHaveAttribute('data-prompt', 'A brighter pulse with hand percussion.');@@ -167,7 +184,7 @@ describe('<MusicDesigner>', () => {it('lets a direct render visit supply the prompt before generating', async () => {renderAt('/music/generate/render?trackId=track-draft');- const prompt = await screen.findByLabelText(/prompt for this render/i);+ const prompt = await awaitDraftLoaded(/prompt for this render/i);expect(prompt).toHaveValue('');fireEvent.change(prompt, { target: { value: 'A quiet piano loop with tape hiss.' } });@@ -188,7 +205,7 @@ describe('<MusicDesigner>', () => {api.describeMusic.mockResolvedValue({ description: 'Lush pads over a broken beat.', llm: { provider: 'provider-a', model: 'model-a' } });renderAt('/music/generate/concept');- fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });+ fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });fireEvent.change(screen.getByLabelText(/extra guidance/i), { target: { value: 'under 100 BPM' } });fireEvent.click(screen.getByRole('button', { name: /describe it/i }));@@ -217,7 +234,7 @@ describe('<MusicDesigner>', () => {it('persists the provider pin after a successful describe', async () => {api.describeMusic.mockResolvedValue({ description: 'Lush pads.', llm: {} });renderAt('/music/generate/concept');- fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'x' } });+ fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'x' } });fireEvent.click(screen.getByRole('button', { name: /describe it/i }));await waitFor(() => expect(api.updateSettings).toHaveBeenCalledWith(@@ -229,7 +246,7 @@ describe('<MusicDesigner>', () => {it('keeps the user on the concept step when the call fails', async () => {api.describeMusic.mockRejectedValue(new Error('no provider'));renderAt('/music/generate/concept');- fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'x' } });+ fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'x' } });fireEvent.click(screen.getByRole('button', { name: /describe it/i }));await waitFor(() => expect(api.describeMusic).toHaveBeenCalled());@@ -243,7 +260,7 @@ describe('<MusicDesigner>', () => {api.generateLyrics.mockResolvedValue({ lyrics: '[verse]\nrain on the window', llm: {} });renderAt('/music/generate/concept');- fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });+ fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });fireEvent.click(screen.getByRole('button', { name: /describe it/i }));await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/description'));fireEvent.click(screen.getByRole('button', { name: /next: lyrics/i }));@@ -274,7 +291,7 @@ describe('<MusicDesigner>', () => {api.describeMusic.mockResolvedValue({ description: 'Lush pads over a broken beat.', llm: {} });renderAt('/music/generate/concept');- fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });+ fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'a rainy downtempo loop' } });fireEvent.click(screen.getByRole('button', { name: /describe it/i }));await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/description'));fireEvent.click(screen.getByRole('button', { name: /next: lyrics/i }));@@ -352,7 +369,7 @@ describe('<MusicDesigner>', () => {api.describeMusic.mockResolvedValue({ description: 'Terse.', llm: {} });renderAt('/music/generate/concept');- fireEvent.change(await screen.findByLabelText(/what do you want to hear/i), { target: { value: 'x' } });+ fireEvent.change(await awaitDraftLoaded(/what do you want to hear/i), { target: { value: 'x' } });fireEvent.click(screen.getByRole('button', { name: /advanced — meta-prompts/i }));await waitFor(() => expect(screen.getByLabelText(/description instruction/i)).toHaveValue('Be terse.'));@@ -361,6 +378,10 @@ describe('<MusicDesigner>', () => {expect.objectContaining({ template: 'Be terse.' }),{ silent: true },));+ // The CALL landing is not the end of the round-trip: its result advances the+ // wizard to the description step. Stepping back before that lands means the+ // late navigation overwrites the step and the concept controls disappear.+ await waitFor(() => expect(screen.getByTestId('location')).toHaveTextContent('/music/generate/description'));// Reset clears the override so the server falls back to the shipped default.fireEvent.click(screen.getByRole('tab', { name: /concept/i }));diff --git a/client/src/pages/StartStory.test.jsx b/client/src/pages/StartStory.test.jsxindex be1b3305ca..85771b3479 100644--- a/client/src/pages/StartStory.test.jsx+++ b/client/src/pages/StartStory.test.jsx@@ -18,6 +18,19 @@ 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 () => {+ const radio = await screen.findByLabelText('Use an existing universe');+ await waitFor(() => expect(radio).not.toBeDisabled());+ fireEvent.click(radio);+};+describe('StartStory onramp', () => {beforeEach(() => {navigateMock.mockReset();@@ -43,9 +56,8 @@ describe('StartStory onramp', () => {it('forwards the chosen universe to engines that consume it', async () => {render(<StartStory />);- await screen.findByText('From an idea');// Opt into an existing universe, then select one.- fireEvent.click(screen.getByLabelText('Use an existing universe'));+ await clickUseExistingUniverse();const select = await screen.findByLabelText('Existing universe');fireEvent.change(select, { target: { value: 'u2' } });@@ -58,8 +70,7 @@ describe('StartStory onramp', () => {it('does not forward a universe to prose mode (no universe link yet)', async () => {render(<StartStory />);- await screen.findByText('From writing prose');- fireEvent.click(screen.getByLabelText('Use an existing universe'));+ await clickUseExistingUniverse();const select = await screen.findByLabelText('Existing universe');fireEvent.change(select, { target: { value: 'u1' } });@@ -69,8 +80,7 @@ describe('StartStory onramp', () => {it('blocks the cards until a universe is picked when using an existing one', async () => {render(<StartStory />);- await screen.findByText('From an idea');- fireEvent.click(screen.getByLabelText('Use an existing universe'));+ await clickUseExistingUniverse();// No universe selected yet — clicking a card should not navigate.fireEvent.click(screen.getByText('From an idea'));expect(navigateMock).not.toHaveBeenCalled();@@ -86,8 +96,7 @@ describe('StartStory onramp', () => {{ id: 'u3', name: ' ' },]);render(<StartStory />);- await screen.findByText('From an idea');- fireEvent.click(screen.getByLabelText('Use an existing universe'));+ await clickUseExistingUniverse();const select = await screen.findByLabelText('Existing universe');// Only the placeholder + the one named universe.const options = select.querySelectorAll('option');