diff --git a/.tmp/proof/issue-151-component-lifecycles.png b/.tmp/proof/issue-151-component-lifecycles.png new file mode 100644 index 0000000..2622152 Binary files /dev/null and b/.tmp/proof/issue-151-component-lifecycles.png differ diff --git a/.tmp/proof/issue-151-home.png b/.tmp/proof/issue-151-home.png new file mode 100644 index 0000000..38d6a03 Binary files /dev/null and b/.tmp/proof/issue-151-home.png differ diff --git a/.tmp/proof/issue-151-verification.txt b/.tmp/proof/issue-151-verification.txt new file mode 100644 index 0000000..e0c9385 --- /dev/null +++ b/.tmp/proof/issue-151-verification.txt @@ -0,0 +1,75 @@ +Verification for issue #151 + +MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run install +Passed. Dependency installation completed with existing peer-dependency warnings. +No dependency manifest or lockfile changes. + +MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run lint +[lint] $ ./scripts/lint +Checked 2 files in packages/backend 1.15s +(node:19149) 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.05s +Checked 1 files in packages/backstage-theme-github 1.48s +(node:19149) 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 1.52s +(node:19149) 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 55 files in packages/app 2.30s +(node:19149) 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) + +MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run test -- --runInBand --verbose +PASS app packages/app/src/components/home/HomePage.test.tsx + HomePage component lifecycles + ✓ counts component lifecycles, including custom and missing values, without claiming health (184 ms) + ✓ explains the data source while loading and does not show zero counts (98 ms) + ✓ distinguishes an empty component catalog from unavailable data (93 ms) + ✓ reports unavailable data after a catalog failure without showing empty or zero counts (111 ms) + ✓ keeps loaded lifecycle counts when a later template request fails (91 ms) + +Test Suites: 1 skipped, 11 passed, 11 of 12 total +Tests: 1 skipped, 76 passed, 77 total +Snapshots: 0 total +Time: 25.398 s +Ran all test suites in 4 projects. + +Existing test warnings included jsdom stylesheet parsing and React/MUI warnings. + +BROWSER=none MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run dev +Rspack compiled successfully. Frontend / returned HTTP 200. +Backend /.backstage/health/v1/readiness returned HTTP 200. +The dev stack was stopped after verification. + +Paseo browser capture was blocked: No browser automation host is connected. +The local Playwright CLI fallback succeeded using Chrome and Guest > Enter. +It was invoked through a temporary mise task named proof-browser, which wrapped +/Users/johnny/.agents/skills/playwright/scripts/playwright_cli.sh with the session +backstage-issue-151. The temporary task was removed after capture. + +MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run proof-browser open http://localhost:3000 --browser chrome +MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run proof-browser click e18 +MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run proof-browser resize 1440 1200 +MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run proof-browser snapshot +MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run proof-browser screenshot e401 --filename=.tmp/proof/issue-151-component-lifecycles.png +MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run proof-browser screenshot --full-page --filename=.tmp/proof/issue-151-home.png +MISE_TRUSTED_CONFIG_PATHS="$PWD" mise run proof-browser click e425 + +The section capture includes its heading, explanation, all four lifecycle counts +and Browse components. The home capture shows the surrounding page at 1440x1200; +the page uses an internal scroll area, so it is a viewport rather than the entire +home-page content. The local catalog had 13 production components and zero in +the other three groups. Browse components opened the catalog with kind=component +and All Components (13). No responses were mocked for the browser captures. + +Browser warnings included the existing signals WebSocket 404, React Router future +flags and React deprecations. The backend also reported missing TechDocs search +indexes. These are outside this slice. + +mise run build was not run locally because this slice changes frontend UI and +component tests only. The PR Build workflow runs install, lint, test and the Docker +build without publishing an image. + +git diff --check +Passed. diff --git a/packages/app/src/components/home/HomePage.test.tsx b/packages/app/src/components/home/HomePage.test.tsx new file mode 100644 index 0000000..930d330 --- /dev/null +++ b/packages/app/src/components/home/HomePage.test.tsx @@ -0,0 +1,150 @@ +import { fireEvent, screen, within } from '@testing-library/react'; +import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; +import { catalogApiRef } from '@backstage/plugin-catalog-react'; +import { Entity } from '@backstage/catalog-model'; +import { useLocation } from 'react-router-dom'; +import { HomePage } from './HomePage'; + +const component = (name: string, lifecycle?: string): Entity => ({ + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { name }, + spec: { type: 'service', owner: 'guest', ...(lifecycle && { lifecycle }) }, +}); + +const LocationDisplay = () => { + const location = useLocation(); + return ( +
{location.pathname + location.search}
+ ); +}; + +describe('HomePage component lifecycles', () => { + const getEntities = jest.fn(); + const renderPage = () => + renderInTestApp( + + + + , + ); + const lifecycleCard = () => + within(screen.getByRole('region', { name: 'Component lifecycles' })); + const expectExplanation = () => { + expect( + lifecycleCard().getByText(/Counts use component lifecycle metadata/), + ).toHaveTextContent('They do not report live service health.'); + expect(screen.queryByText('System Health')).not.toBeInTheDocument(); + expect(screen.queryByText('Overall Health')).not.toBeInTheDocument(); + expect(lifecycleCard().queryByText(/%/)).not.toBeInTheDocument(); + }; + + beforeEach(() => { + getEntities.mockReset(); + }); + + it('counts component lifecycles, including custom and missing values, without claiming health', async () => { + const components = [ + component('production-one', 'production'), + component('production-two', 'production'), + component('experiment', 'experimental'), + component('old-service', 'deprecated'), + component('preview', 'preview'), + component('unspecified'), + { ...component('no-spec'), spec: undefined }, + ]; + getEntities.mockImplementation(({ filter }) => + Promise.resolve({ + items: + filter[0].kind === 'component' && Object.keys(filter[0]).length === 1 + ? components + : [], + }), + ); + + await renderPage(); + + expectExplanation(); + const card = lifecycleCard(); + for (const [label, count] of [ + ['Production', '2'], + ['Experimental', '1'], + ['Deprecated', '1'], + ['Other or unspecified', '3'], + ]) { + const term = card.getByText(label); + expect(term.tagName).toBe('DT'); + expect(term.nextElementSibling).toHaveTextContent( + new RegExp(`^${count}$`), + ); + } + expect(card.queryByRole('progressbar')).not.toBeInTheDocument(); + + fireEvent.click(card.getByRole('button', { name: 'Browse components' })); + expect(screen.getByTestId('location')).toHaveTextContent( + '/catalog?filters[kind]=component', + ); + }); + + it('explains the data source while loading and does not show zero counts', async () => { + getEntities.mockReturnValue(new Promise(() => {})); + + await renderPage(); + + expectExplanation(); + expect(lifecycleCard().getByRole('status')).toHaveTextContent( + 'Loading component lifecycles...', + ); + expect(lifecycleCard().queryByRole('definition')).not.toBeInTheDocument(); + }); + + it('distinguishes an empty component catalog from unavailable data', async () => { + getEntities.mockResolvedValue({ items: [] }); + + await renderPage(); + + expectExplanation(); + expect( + lifecycleCard().getByText('No components found in the catalog.'), + ).toBeInTheDocument(); + expect(lifecycleCard().queryByRole('alert')).not.toBeInTheDocument(); + expect(lifecycleCard().queryByRole('definition')).not.toBeInTheDocument(); + }); + + it('reports unavailable data after a catalog failure without showing empty or zero counts', async () => { + getEntities.mockRejectedValue(new Error('Catalog unavailable')); + + await renderPage(); + + expectExplanation(); + expect(lifecycleCard().getByRole('alert')).toHaveTextContent( + 'Component lifecycle data is unavailable. Try reloading the page.', + ); + expect( + lifecycleCard().queryByText('No components found in the catalog.'), + ).not.toBeInTheDocument(); + expect(lifecycleCard().queryByRole('definition')).not.toBeInTheDocument(); + }); + + it('keeps loaded lifecycle counts when a later template request fails', async () => { + getEntities.mockImplementation(({ filter }) => { + if (filter[0].kind === 'template') { + return Promise.reject(new Error('Templates unavailable')); + } + return Promise.resolve({ + items: + filter[0].kind === 'component' && Object.keys(filter[0]).length === 1 + ? [component('production-service', 'production')] + : [], + }); + }); + + await renderPage(); + + expectExplanation(); + expect( + lifecycleCard().getByText('Production').nextElementSibling, + ).toHaveTextContent(/^1$/); + expect(lifecycleCard().queryByRole('alert')).not.toBeInTheDocument(); + }); +}); diff --git a/packages/app/src/components/home/HomePage.tsx b/packages/app/src/components/home/HomePage.tsx index cdda651..26c7467 100644 --- a/packages/app/src/components/home/HomePage.tsx +++ b/packages/app/src/components/home/HomePage.tsx @@ -10,10 +10,6 @@ import WidgetsIcon from '@mui/icons-material/Widgets'; import AccountTreeIcon from '@mui/icons-material/AccountTree'; import LibraryBooksIcon from '@mui/icons-material/LibraryBooks'; import ArrowForwardIcon from '@mui/icons-material/ArrowForward'; -import SpeedIcon from '@mui/icons-material/Speed'; -import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline'; -import WarningAmberIcon from '@mui/icons-material/WarningAmber'; -import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'; import TrendingUpIcon from '@mui/icons-material/TrendingUp'; import CodeIcon from '@mui/icons-material/Code'; import GroupsIcon from '@mui/icons-material/Groups'; @@ -41,7 +37,8 @@ import ListItemButton from '@mui/material/ListItemButton'; import Avatar from '@mui/material/Avatar'; import Paper from '@mui/material/Paper'; import Divider from '@mui/material/Divider'; -import LinearProgress from '@mui/material/LinearProgress'; +import Alert from '@mui/material/Alert'; +import CircularProgress from '@mui/material/CircularProgress'; import { useApi } from '@backstage/core-plugin-api'; import { catalogApiRef } from '@backstage/plugin-catalog-react'; import { useNavigate } from 'react-router-dom'; @@ -130,11 +127,11 @@ interface OnboardingDoc { tags: string[]; } -interface HealthStatus { - healthy: number; - warning: number; - critical: number; - unknown: number; +interface ComponentLifecycles { + production: number; + experimental: number; + deprecated: number; + other: number; } const SectionHeader = ({ @@ -183,12 +180,8 @@ export const HomePage = () => { const [recentEntities, setRecentEntities] = useState([]); const [templates, setTemplates] = useState([]); const [onboardingDocs, setOnboardingDocs] = useState([]); - const [healthStatus, setHealthStatus] = useState({ - healthy: 0, - warning: 0, - critical: 0, - unknown: 0, - }); + const [componentLifecycles, setComponentLifecycles] = + useState(); const [loadingRecent, setLoadingRecent] = useState(true); const [loadingTemplates, setLoadingTemplates] = useState(true); const [loadingDocs, setLoadingDocs] = useState(true); @@ -232,20 +225,20 @@ export const HomePage = () => { loading: false, }); - const healthCounts: HealthStatus = { - healthy: 0, - warning: 0, - critical: 0, - unknown: 0, + const lifecycleCounts: ComponentLifecycles = { + production: 0, + experimental: 0, + deprecated: 0, + other: 0, }; components.items.forEach((entity: Entity) => { - const lifecycle = entity.spec?.lifecycle as string; - if (lifecycle === 'production') healthCounts.healthy++; - else if (lifecycle === 'experimental') healthCounts.warning++; - else if (lifecycle === 'deprecated') healthCounts.critical++; - else healthCounts.unknown++; + const lifecycle = entity.spec?.lifecycle; + if (lifecycle === 'production') lifecycleCounts.production++; + else if (lifecycle === 'experimental') lifecycleCounts.experimental++; + else if (lifecycle === 'deprecated') lifecycleCounts.deprecated++; + else lifecycleCounts.other++; }); - setHealthStatus(healthCounts); + setComponentLifecycles(lifecycleCounts); const allEntities = [ ...components.items, @@ -401,20 +394,50 @@ export const HomePage = () => { }, ]; - const totalHealth = - healthStatus.healthy + - healthStatus.warning + - healthStatus.critical + - healthStatus.unknown; - const healthPercentage = - totalHealth > 0 - ? Math.round((healthStatus.healthy / totalHealth) * 100) - : 0; - let healthBarColor = theme.palette.error.main; - if (healthPercentage >= 80) { - healthBarColor = theme.palette.success.main; - } else if (healthPercentage >= 50) { - healthBarColor = theme.palette.warning.main; + let lifecycleContent: ReactNode; + if (stats.loading) { + lifecycleContent = ( + + + ); + } else if (!componentLifecycles) { + lifecycleContent = ( + + Component lifecycle data is unavailable. Try reloading the page. + + ); + } else if (stats.components === 0) { + lifecycleContent = ( + + No components found in the catalog. + + ); + } else { + const lifecycles = [ + { label: 'Production', count: componentLifecycles.production }, + { label: 'Experimental', count: componentLifecycles.experimental }, + { label: 'Deprecated', count: componentLifecycles.deprecated }, + { label: 'Other or unspecified', count: componentLifecycles.other }, + ]; + lifecycleContent = ( + + {lifecycles.map(({ label, count }) => ( + + + {label} + + + {count} + + + ))} + + ); } let templatesContent: ReactNode; @@ -502,7 +525,9 @@ export const HomePage = () => { } else { templatesContent = ( - + No templates available yet.{' '} { } else { onboardingDocsContent = ( - + No onboarding docs tagged yet. Tag a docs entity with{' '} @@ -637,9 +664,15 @@ export const HomePage = () => { + - {index < recentEntities.length - 1 && } @@ -866,9 +899,7 @@ export const HomePage = () => { } /> - - {recentEntitiesContent} - + {recentEntitiesContent} @@ -876,179 +907,30 @@ export const HomePage = () => { } - title="System Health" + title="Component lifecycles" /> - + - - - - Overall Health - - - {stats.loading ? ( - - ) : ( - `${healthPercentage}%` - )} - - - - - - - - - - - {stats.loading ? ( - - ) : ( - healthStatus.healthy - )} - - - Production - - - - - - - - - - {stats.loading ? ( - - ) : ( - healthStatus.warning - )} - - - Experimental - - - - - - - - - - {stats.loading ? ( - - ) : ( - healthStatus.critical - )} - - - Deprecated - - - - - - - - - - {stats.loading ? ( - - ) : ( - healthStatus.unknown - )} - - - Other - - - - - + + Counts use component lifecycle metadata from the catalog. + They do not report live service health. + + {lifecycleContent}