Skip to content

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

test: wait for the progress stream before failing it in the recovery page tests (#10066)

[._.]/ Adam Eivy2af3a1322e29
diff --git a/client/src/pages/PipelineContinuityBible.recovery.test.jsx b/client/src/pages/PipelineContinuityBible.recovery.test.jsx
index adaed0cc4a..7b53da3090 100644
--- a/client/src/pages/PipelineContinuityBible.recovery.test.jsx
+++ b/client/src/pages/PipelineContinuityBible.recovery.test.jsx
@@ -28,6 +28,13 @@ const SAVED = {
facts: [{ id: 'f-1', category: 'physical', source: 'prose', subject: 'Alice', statement: 'Alice has green eyes.', issueNumber: 1 }],
};
+// The EventSource is opened by a passive effect after the busy state renders, so
+// wait for it rather than assuming it exists the instant the button appears.
+const failStream = async () => {
+ await waitFor(() => expect(lastEventSource()).toBeDefined());
+ await act(async () => { lastEventSource().fail(); });
+};
+
const renderPage = () => render(
<MemoryRouter initialEntries={['/pipeline/series/ser-1/continuity-bible']}>
<Routes>
@@ -60,7 +67,7 @@ describe('PipelineContinuityBible stream recovery', () => {
// The run finished and was pruned: the progress GET 404s, status says inactive.
getContinuityBibleStatus.mockResolvedValue({ active: false });
getContinuityBible.mockResolvedValue(SAVED);
- act(() => lastEventSource().fail());
+ await failStream();
await waitFor(() => expect(screen.getByRole('button', { name: 'Rebuild ledger' })).toBeEnabled());
expect(await screen.findByText(/Alice has green eyes/)).toBeInTheDocument();
@@ -100,10 +107,10 @@ describe('PipelineContinuityBible stream recovery', () => {
await screen.findByRole('button', { name: /Building/ });
getContinuityBibleStatus.mockResolvedValue({ active: true });
- act(() => lastEventSource().fail());
+ await failStream();
await user.click(await screen.findByRole('button', { name: 'Reattach' }));
- expect(MockEventSource.instances).toHaveLength(2);
+ await waitFor(() => expect(MockEventSource.instances).toHaveLength(2));
expect(screen.getByRole('button', { name: /Cancel/ })).toBeEnabled();
expect(generateContinuityBible).toHaveBeenCalledTimes(1);
});
@@ -115,7 +122,7 @@ describe('PipelineContinuityBible stream recovery', () => {
await screen.findByRole('button', { name: /Building/ });
getContinuityBibleStatus.mockRejectedValueOnce(new Error('offline'));
- act(() => lastEventSource().fail());
+ await failStream();
const retry = await screen.findByRole('button', { name: 'Retry status' });
expect(screen.getByRole('button', { name: /Building/ })).toBeDisabled();
diff --git a/client/src/pages/PipelineReverseOutline.recovery.test.jsx b/client/src/pages/PipelineReverseOutline.recovery.test.jsx
index 5a4b0bc140..8209af0705 100644
--- a/client/src/pages/PipelineReverseOutline.recovery.test.jsx
+++ b/client/src/pages/PipelineReverseOutline.recovery.test.jsx
@@ -28,6 +28,13 @@ const SAVED = {
scenes: [{ id: 'sc-1', plotlineId: 'pl-1', heading: 'Opening scene', summary: 'The first beat.', issueNumber: 1 }],
};
+// The EventSource is opened by a passive effect after the busy state renders, so
+// wait for it rather than assuming it exists the instant the button appears.
+const failStream = async () => {
+ await waitFor(() => expect(lastEventSource()).toBeDefined());
+ await act(async () => { lastEventSource().fail(); });
+};
+
const renderPage = () => render(
<MemoryRouter initialEntries={['/pipeline/series/ser-1/reverse-outline']}>
<Routes>
@@ -60,7 +67,7 @@ describe('PipelineReverseOutline stream recovery', () => {
// The run finished and was pruned: the progress GET 404s, status says inactive.
getReverseOutlineStatus.mockResolvedValue({ active: false });
getReverseOutline.mockResolvedValue(SAVED);
- act(() => lastEventSource().fail());
+ await failStream();
await waitFor(() => expect(screen.getByRole('button', { name: 'Regenerate' })).toBeEnabled());
expect(screen.getByTitle('Opening scene')).toBeInTheDocument();
@@ -100,10 +107,10 @@ describe('PipelineReverseOutline stream recovery', () => {
await screen.findByRole('button', { name: /Generating/ });
getReverseOutlineStatus.mockResolvedValue({ active: true });
- act(() => lastEventSource().fail());
+ await failStream();
await user.click(await screen.findByRole('button', { name: 'Reattach' }));
- expect(MockEventSource.instances).toHaveLength(2);
+ await waitFor(() => expect(MockEventSource.instances).toHaveLength(2));
expect(screen.getByRole('button', { name: /Cancel/ })).toBeEnabled();
expect(generateReverseOutline).toHaveBeenCalledTimes(1);
});
@@ -115,7 +122,7 @@ describe('PipelineReverseOutline stream recovery', () => {
await screen.findByRole('button', { name: /Generating/ });
getReverseOutlineStatus.mockRejectedValueOnce(new Error('offline'));
- act(() => lastEventSource().fail());
+ await failStream();
const retry = await screen.findByRole('button', { name: 'Retry status' });
expect(screen.getByRole('button', { name: /Generating/ })).toBeDisabled();