From 0e1ac721dfa820e031988cb24497fc82f91bd66a Mon Sep 17 00:00:00 2001 From: Johnny Huynh <27847622+johnnyhuy@users.noreply.github.com> Date: Mon, 16 Nov 2026 20:15:50 +1100 Subject: [PATCH 1/2] fix: let visitors retry failed Pulse Check loads Co-authored-by: OpenAI Codex --- .tmp/proof/issue-149-verification.txt | 59 +++++++++ .../pulse-check/PulseCheckPage.test.tsx | 121 ++++++++++++++++-- .../components/pulse-check/PulseCheckPage.tsx | 48 +++++-- 3 files changed, 203 insertions(+), 25 deletions(-) create mode 100644 .tmp/proof/issue-149-verification.txt diff --git a/.tmp/proof/issue-149-verification.txt b/.tmp/proof/issue-149-verification.txt new file mode 100644 index 0000000..243576a --- /dev/null +++ b/.tmp/proof/issue-149-verification.txt @@ -0,0 +1,59 @@ +$ MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run install +➤ YN0000: · Done with warnings in 28m 41s +Finished in 325.23s +exit 0; no lockfile changes + +$ MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run lint +[lint] $ ./scripts/lint +Checked 2 files in packages/backend 3.98s +(node:70265) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. +(Use `node --trace-warnings ...` to show where the warning was created) +Checked 3 files in plugins/permission-backend-module-default 0.16s +Checked 1 files in packages/backstage-theme-github 5.10s +(node:70265) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. +(Use `node --trace-warnings ...` to show where the warning was created) +Checked 8 files in plugins/plausible 5.51s +(node:70265) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. +(Use `node --trace-warnings ...` to show where the warning was created) +Checked 54 files in packages/app 7.88s +(node:70265) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. +(Use `node --trace-warnings ...` to show where the warning was created) +exit 0 + +$ MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run test -- --runInBand --verbose +PASS app packages/app/src/components/pulse-check/PulseCheckPage.test.tsx (11.484 s) + PulseCheckPage + ✓ identifies simulated health and fixture metrics on the populated dashboard (959 ms) + ✓ keeps the sample-data notice visible while services load (211 ms) + ✓ keeps the sample-data notice visible when the catalog fails (740 ms) + ✓ retries a failed catalog load and restores the dashboard after a pending request (1073 ms) + ✓ offers another retry after a second failure and handles an empty recovery (988 ms) + ✓ offers retry when the catalog rejects without an Error object (329 ms) + ✓ identifies example metrics even when the catalog has no services (425 ms) + +Test Suites: 1 skipped, 10 passed, 10 of 11 total +Tests: 1 skipped, 71 passed, 72 total +Snapshots: 0 total +Time: 141.774 s +Ran all test suites in 4 projects. +exit 0 + +The test excerpt above contains the complete PulseCheckPage result block and overall totals. Existing jsdom stylesheet and React/MUI warnings are omitted. + +$ BROWSER=none MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run dev +[0] Rspack compiled successfully +[1] 2026-11-16T09:13:39.229Z backstage info Plugin initialization complete, newly initialized: 'notifications', 'scaffolder', 'catalog' type="initialization" +[1] 2026-11-16T09:13:40.323Z signals warn Event subscribe request failed with status 404, events backend not found. Will only receive events that were sent locally on this process. +[1] yarn start-backend exited with code 0 +[0] yarn start exited with code 0 +The stack was stopped with Ctrl+C after verification. + +$ curl --silent --output /dev/null --write-out "GET /pulse-check -> HTTP %{http_code}\n" http://localhost:3000/pulse-check +GET /pulse-check -> HTTP 200 + +Screenshot method (a) was blocked. Attempting to open http://localhost:3000/pulse-check with the browser tool returned "The browser access host is unavailable". No screenshot was captured and browser rendering remains unverified. Method (b) succeeded with the regression-test output above. + +$ git diff --check +exit 0 + +mise run build was not run locally. This slice changes frontend controls and component tests only; backend and packaging are unchanged. The PR Build workflow runs all four mise gates including the Docker image build. diff --git a/packages/app/src/components/pulse-check/PulseCheckPage.test.tsx b/packages/app/src/components/pulse-check/PulseCheckPage.test.tsx index c53ab30..4dc40cd 100644 --- a/packages/app/src/components/pulse-check/PulseCheckPage.test.tsx +++ b/packages/app/src/components/pulse-check/PulseCheckPage.test.tsx @@ -1,10 +1,16 @@ -import { screen } from '@testing-library/react'; +import { act, fireEvent, screen, waitFor } from '@testing-library/react'; import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; import { catalogApiRef } from '@backstage/plugin-catalog-react'; import { PulseCheckPage } from './PulseCheckPage'; describe('PulseCheckPage', () => { const getEntities = jest.fn(); + const demoService = { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { name: 'demo-service' }, + spec: { type: 'service', lifecycle: 'experimental', owner: 'guest' }, + }; const renderPage = () => renderInTestApp( @@ -14,9 +20,11 @@ describe('PulseCheckPage', () => { ); const expectSampleDataNotice = () => { - expect(screen.getByRole('alert')).toHaveTextContent( - 'Sample data only. Service names come from the catalog. Health and uptime are simulated; incidents and deployment metrics are examples. This page does not report live service status.', - ); + expect( + screen.getByText( + 'Sample data only. Service names come from the catalog. Health and uptime are simulated; incidents and deployment metrics are examples. This page does not report live service status.', + ), + ).toBeVisible(); expect( screen.getByText('Explore a service health dashboard with sample data'), ).toBeInTheDocument(); @@ -28,14 +36,7 @@ describe('PulseCheckPage', () => { it('identifies simulated health and fixture metrics on the populated dashboard', async () => { getEntities.mockResolvedValue({ - items: [ - { - apiVersion: 'backstage.io/v1alpha1', - kind: 'Component', - metadata: { name: 'demo-service' }, - spec: { type: 'service', lifecycle: 'experimental', owner: 'guest' }, - }, - ], + items: [demoService], }); await renderPage(); @@ -53,7 +54,9 @@ describe('PulseCheckPage', () => { await renderPage(); expectSampleDataNotice(); - expect(screen.getByRole('progressbar')).toBeInTheDocument(); + expect( + screen.getByRole('progressbar', { name: 'Loading services' }), + ).toBeInTheDocument(); }); it('keeps the sample-data notice visible when the catalog fails', async () => { @@ -63,8 +66,98 @@ describe('PulseCheckPage', () => { expectSampleDataNotice(); expect( - screen.getByText('Error loading services: Catalog unavailable'), + screen.getByRole('alert', { name: 'Could not load services' }), + ).toHaveTextContent('Catalog unavailable'); + expect(screen.getByRole('button', { name: 'Retry' })).toBeInTheDocument(); + expect(screen.queryByText('Total Deployments')).not.toBeInTheDocument(); + }); + + it('retries a failed catalog load and restores the dashboard after a pending request', async () => { + let resolveRetry: () => void; + const retry = new Promise<{ items: (typeof demoService)[] }>(resolve => { + resolveRetry = () => resolve({ items: [demoService] }); + }); + getEntities + .mockRejectedValueOnce(new Error('Catalog unavailable')) + .mockReturnValueOnce(retry); + + await renderPage(); + fireEvent.click(screen.getByRole('button', { name: 'Retry' })); + + expectSampleDataNotice(); + expect( + screen.getByRole('progressbar', { name: 'Loading services' }), + ).toBeInTheDocument(); + expect( + screen.queryByRole('alert', { name: 'Could not load services' }), + ).not.toBeInTheDocument(); + expect( + screen.queryByRole('button', { name: 'Retry' }), + ).not.toBeInTheDocument(); + expect(screen.queryByText('Total Deployments')).not.toBeInTheDocument(); + expect(getEntities).toHaveBeenCalledTimes(2); + expect(getEntities).toHaveBeenLastCalledWith({ + filter: [{ kind: 'component', 'spec.type': 'service' }], + }); + + await act(async () => resolveRetry()); + + expectSampleDataNotice(); + expect(screen.getByText('demo-service')).toBeInTheDocument(); + expect(screen.getByText('Total Deployments')).toBeInTheDocument(); + expect( + screen.queryByRole('alert', { name: 'Could not load services' }), + ).not.toBeInTheDocument(); + expect(screen.queryByRole('progressbar')).not.toBeInTheDocument(); + expect(getEntities).toHaveBeenCalledTimes(2); + }); + + it('offers another retry after a second failure and handles an empty recovery', async () => { + getEntities + .mockRejectedValueOnce(new Error('Catalog unavailable')) + .mockRejectedValueOnce(new Error('Still unavailable')) + .mockResolvedValueOnce({ items: [] }); + + await renderPage(); + fireEvent.click(screen.getByRole('button', { name: 'Retry' })); + + await waitFor(() => + expect( + screen.getByRole('alert', { name: 'Could not load services' }), + ).toHaveTextContent('Still unavailable'), + ); + expectSampleDataNotice(); + expect(screen.queryByText('Catalog unavailable')).not.toBeInTheDocument(); + expect(screen.queryByText('Total Deployments')).not.toBeInTheDocument(); + expect( + screen.queryByText('No services found in the catalog.'), + ).not.toBeInTheDocument(); + fireEvent.click(screen.getByRole('button', { name: 'Retry' })); + + expect( + await screen.findByText('No services found in the catalog.'), ).toBeInTheDocument(); + expectSampleDataNotice(); + expect(screen.getByText('Total Deployments')).toBeInTheDocument(); + expect( + screen.queryByRole('alert', { name: 'Could not load services' }), + ).not.toBeInTheDocument(); + expect( + screen.queryByRole('button', { name: 'Retry' }), + ).not.toBeInTheDocument(); + expect(getEntities).toHaveBeenCalledTimes(3); + }); + + it('offers retry when the catalog rejects without an Error object', async () => { + getEntities.mockRejectedValue(null); + + await renderPage(); + + expectSampleDataNotice(); + expect( + screen.getByRole('alert', { name: 'Could not load services' }), + ).toHaveTextContent('The catalog is unavailable.'); + expect(screen.getByRole('button', { name: 'Retry' })).toBeInTheDocument(); expect(screen.queryByText('Total Deployments')).not.toBeInTheDocument(); }); diff --git a/packages/app/src/components/pulse-check/PulseCheckPage.tsx b/packages/app/src/components/pulse-check/PulseCheckPage.tsx index e60a623..ac70f13 100644 --- a/packages/app/src/components/pulse-check/PulseCheckPage.tsx +++ b/packages/app/src/components/pulse-check/PulseCheckPage.tsx @@ -6,6 +6,8 @@ import CircularProgress from '@mui/material/CircularProgress'; import Card from '@mui/material/Card'; import CardContent from '@mui/material/CardContent'; import Alert from '@mui/material/Alert'; +import AlertTitle from '@mui/material/AlertTitle'; +import Button from '@mui/material/Button'; import { useTheme } from '@mui/material/styles'; import { Page, Header, Content } from '@backstage/core-components'; import { useApi } from '@backstage/core-plugin-api'; @@ -116,23 +118,35 @@ export const PulseCheckPage = () => { const [entities, setEntities] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [loadAttempt, setLoadAttempt] = useState(0); useEffect(() => { + let active = true; const fetchEntities = async () => { + setLoading(true); + setError(null); try { - setLoading(true); const response = await catalogApi.getEntities({ filter: [{ kind: 'component', 'spec.type': 'service' }], }); - setEntities(response.items); + if (active) setEntities(response.items); } catch (err) { - setError(err as Error); + if (active) { + setError( + err instanceof Error + ? err + : new Error('The catalog is unavailable.'), + ); + } } finally { - setLoading(false); + if (active) setLoading(false); } }; fetchEntities(); - }, [catalogApi]); + return () => { + active = false; + }; + }, [catalogApi, loadAttempt]); const healthData = entities.map(generateMockHealth); @@ -159,7 +173,7 @@ export const PulseCheckPage = () => { minHeight: 400, }} > - + @@ -175,11 +189,23 @@ export const PulseCheckPage = () => { /> - - - Error loading services: {error.message} - - + setLoadAttempt(attempt => attempt + 1)} + > + Retry + + } + > + + Could not load services + + {error.message} + ); From 68a7184f322d5efe002e0247b7b0a290855fdb7a Mon Sep 17 00:00:00 2001 From: Johnny Huynh <27847622+johnnyhuy@users.noreply.github.com> Date: Mon, 16 Nov 2026 20:16:18 +1100 Subject: [PATCH 2/2] chore: trim verification transcript whitespace Co-authored-by: OpenAI Codex --- .tmp/proof/issue-149-verification.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tmp/proof/issue-149-verification.txt b/.tmp/proof/issue-149-verification.txt index 243576a..e8b3d13 100644 --- a/.tmp/proof/issue-149-verification.txt +++ b/.tmp/proof/issue-149-verification.txt @@ -43,7 +43,7 @@ The test excerpt above contains the complete PulseCheckPage result block and ove $ BROWSER=none MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run dev [0] Rspack compiled successfully [1] 2026-11-16T09:13:39.229Z backstage info Plugin initialization complete, newly initialized: 'notifications', 'scaffolder', 'catalog' type="initialization" -[1] 2026-11-16T09:13:40.323Z signals warn Event subscribe request failed with status 404, events backend not found. Will only receive events that were sent locally on this process. +[1] 2026-11-16T09:13:40.323Z signals warn Event subscribe request failed with status 404, events backend not found. Will only receive events that were sent locally on this process. [1] yarn start-backend exited with code 0 [0] yarn start exited with code 0 The stack was stopped with Ctrl+C after verification.