From 18d2b4cb46fe055fd3204b042ee5ec6484d4d421 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 09:31:08 +0000 Subject: [PATCH] fix(app-shell): the Diagnostics page inside a package's area sweeps only that package The page asked for the environment-wide sweep even inside one package's Studio "All metadata" area, while the directory beside it is scoped, so another package's invalid item was listed there and its area-relative link opened an unrelated page. It now reads the area host and sends the package; the cross-package leg and Setup keep the environment-wide sweep. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jV7MUKsme1kh4FsABc --- .../29179-studio-diagnostics-package-scope.md | 10 ++ ...iagnosticsPage.packageScope-29179.test.tsx | 157 ++++++++++++++++++ .../views/metadata-admin/DiagnosticsPage.tsx | 12 +- 3 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 .changeset/29179-studio-diagnostics-package-scope.md create mode 100644 ui/packages/app-shell/src/views/metadata-admin/DiagnosticsPage.packageScope-29179.test.tsx diff --git a/.changeset/29179-studio-diagnostics-package-scope.md b/.changeset/29179-studio-diagnostics-package-scope.md new file mode 100644 index 00000000000..8d0cb6ca8be --- /dev/null +++ b/.changeset/29179-studio-diagnostics-package-scope.md @@ -0,0 +1,10 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(app-shell): inside a package's Studio "All metadata" area, the Diagnostics page sweeps only that package, as the directory beside it does + +Clause-②: no +Metadata-protocol: none + +The Diagnostics page (`/_diagnostics`) asked the server for the environment-wide sweep even inside one package's area, while the directory beside it asked for that package's. So a package whose directory read clean, with no "View all issues" link, listed another package's invalid item on its Diagnostics page, and that row's link, built relative to the open package's area, opened an unrelated page instead of the item. The page now reads the area's package and sends it with the sweep (`GET /api/v1/meta/diagnostics?package=…`), so its count matches the directory's and every row is an item of the open package, linked to it there. The cross-package leg (`/studio/~all/metadata/_diagnostics`) and Setup's Diagnostics page keep the environment-wide sweep. diff --git a/ui/packages/app-shell/src/views/metadata-admin/DiagnosticsPage.packageScope-29179.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/DiagnosticsPage.packageScope-29179.test.tsx new file mode 100644 index 00000000000..6c2623102de --- /dev/null +++ b/ui/packages/app-shell/src/views/metadata-admin/DiagnosticsPage.packageScope-29179.test.tsx @@ -0,0 +1,157 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#29179 — inside a package's "All metadata" area (ADR-0146 D1), + * the Diagnostics page sweeps that package, as the directory beside it does. + * An unscoped sweep listed another package's invalid item under this package's + * area, and its row link, relative to the area, opened an unrelated page. + * + * The real `useGlobalDiagnostics` runs against a fake client that answers as + * the server does: a `packageId` narrows the sweep to that package's items, + * none answers every package's. The cross-package leg and Setup (no area) + * keep the environment-wide sweep. + */ + +import '@testing-library/jest-dom/vitest'; +import * as React from 'react'; +import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'; +import { render, screen, cleanup, fireEvent, within } from '@testing-library/react'; +import { MemoryRouter, Route, Routes } from 'react-router-dom'; +import type { MetadataDiagnosticsSummary } from '@object-ui/data-objectstack'; +import { MetadataAreaHostContext, type MetadataAreaHost } from './metadataAreaHost'; + +const SHOWCASE = 'com.example.showcase'; +const PKG_A = 'com.qa.pkga'; + +/** Each swept item and the package that owns it (the server's `_packageId`). */ +const SWEPT: Array<{ packageId: string; entry: MetadataDiagnosticsSummary['entries'][number] }> = [ + { + packageId: PKG_A, + entry: { + type: 'view', + name: 'pkga_qa_obj.qa_diag_view', + diagnostics: { valid: false, errors: [{ path: 'columns.0.field', message: 'Expected string' }] }, + }, + }, + { + packageId: SHOWCASE, + entry: { + type: 'object', + name: 'showcase_loose', + diagnostics: { valid: true, warnings: [{ path: 'label', message: 'Missing label' }] }, + }, + }, +]; +let showcaseInvalid: MetadataDiagnosticsSummary['entries'][number] | null = null; + +const requests: Array<{ severity: 'error' | 'warning'; packageId?: string }> = []; +const client = { + diagnostics: async (opts: { severity: 'error' | 'warning'; packageId?: string }) => { + requests.push(opts); + const rows = [ + ...SWEPT, + ...(showcaseInvalid ? [{ packageId: SHOWCASE, entry: showcaseInvalid }] : []), + ].filter((r) => opts.packageId === undefined || r.packageId === opts.packageId); + const entries = rows + .map((r) => r.entry) + .filter((e) => (e.diagnostics.errors?.length ?? 0) > 0 || opts.severity === 'warning'); + return { entries, total: entries.length, scannedTypes: 2, scannedItems: rows.length, stats: {} }; + }, +}; + +vi.mock('./useMetadata', async (importActual) => { + const actual = await importActual(); + return { + ...actual, + useMetadataClient: () => client, + useMetadataTypes: () => ({ loading: false, error: null, entries: [] }), + }; +}); +vi.mock('./i18n', async (importOriginal) => ({ + ...(await importOriginal>()), + useMetadataLocale: () => 'en-US', +})); + +import { MetadataDiagnosticsPage } from './DiagnosticsPage'; + +beforeEach(() => { + requests.length = 0; + showcaseInvalid = null; +}); +afterEach(cleanup); + +/** The page at `/_diagnostics`, nested as the area and Setup mount it, so its relative links resolve as there. */ +function mount(root: string, host: MetadataAreaHost | null) { + const page = ; + render( + + + + {page} : page} + /> + + } + /> + + , + ); + return screen.findByTestId('diagnostics-summary-badge'); +} + +const areaOf = (packageId: string | null): MetadataAreaHost => { + const basePath = `/studio/${packageId ?? '~all'}/metadata`; + return { packageId, readOnly: false, basePath }; +}; + +describe('the Diagnostics page sweeps the package its area is open on (objectstack#29179)', () => { + it("a package's area: another package's invalid item is not listed, and the page reads clean", async () => { + await mount(`/studio/${SHOWCASE}/metadata`, areaOf(SHOWCASE)); + expect(requests).toEqual([{ severity: 'error', packageId: SHOWCASE }]); + expect(await screen.findByText('All clear')).toBeInTheDocument(); + expect(screen.queryByText('pkga_qa_obj.qa_diag_view')).toBeNull(); + }); + + it("a package's area: each row is the package's own item and links to it in the area", async () => { + showcaseInvalid = { + type: 'view', + name: 'showcase_broken_view', + diagnostics: { valid: false, errors: [{ path: 'columns', message: 'Required' }] }, + }; + await mount(`/studio/${SHOWCASE}/metadata`, areaOf(SHOWCASE)); + const link = await screen.findByRole('link', { name: 'showcase_broken_view' }); + expect(link).toHaveAttribute('href', `/studio/${SHOWCASE}/metadata/view/showcase_broken_view`); + expect(screen.queryByText('pkga_qa_obj.qa_diag_view')).toBeNull(); + }); + + it('switching to Errors + Warnings keeps the package scope', async () => { + await mount(`/studio/${SHOWCASE}/metadata`, areaOf(SHOWCASE)); + fireEvent.click(screen.getByRole('tab', { name: 'Errors + Warnings' })); + await screen.findByText('showcase_loose'); + expect(requests.at(-1)).toEqual({ severity: 'warning', packageId: SHOWCASE }); + expect(screen.queryByText('pkga_qa_obj.qa_diag_view')).toBeNull(); + }); + + it('the cross-package leg keeps the environment-wide sweep', async () => { + const badge = await mount('/studio/~all/metadata', areaOf(null)); + expect(requests).toEqual([{ severity: 'error' }]); + expect(within(badge).getByText(/1 issue\(s\)/)).toBeInTheDocument(); + expect(await screen.findByRole('link', { name: 'pkga_qa_obj.qa_diag_view' })).toHaveAttribute( + 'href', + '/studio/~all/metadata/view/pkga_qa_obj.qa_diag_view', + ); + }); + + it('Setup (no area) keeps the environment-wide sweep', async () => { + await mount('/apps/setup/metadata', null); + expect(requests).toEqual([{ severity: 'error' }]); + expect(await screen.findByRole('link', { name: 'pkga_qa_obj.qa_diag_view' })).toHaveAttribute( + 'href', + '/apps/setup/metadata/view/pkga_qa_obj.qa_diag_view', + ); + }); +}); diff --git a/ui/packages/app-shell/src/views/metadata-admin/DiagnosticsPage.tsx b/ui/packages/app-shell/src/views/metadata-admin/DiagnosticsPage.tsx index 714b89f43a8..5008f1633b7 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/DiagnosticsPage.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/DiagnosticsPage.tsx @@ -31,6 +31,7 @@ import { useGlobalDiagnostics, type MetadataDiagnosticsEntry, } from './useMetadata.js'; +import { useMetadataAreaHost } from './metadataAreaHost.js'; import { t, tFormat, translateMetadataType, useMetadataLocale } from './i18n.js'; import { diagnosticsHeaderTone, type DiagnosticsHeaderTone } from './diagnostics-tone.js'; @@ -65,7 +66,16 @@ export function MetadataDiagnosticsPage() { const client = useMetadataClient(); const locale = useMetadataLocale(); const [severity, setSeverity] = React.useState('error'); - const { loading, error, summary, reload } = useGlobalDiagnostics(client, severity); + // objectstack ADR-0146 D1 — inside a package's area the sweep is that + // package's, as the directory beside it is: an item of another package has + // no row here, and every row's link stays inside its own package's area. The + // cross-package leg (`packageId: null`) and Setup (no area) sweep everything. + const host = useMetadataAreaHost(); + const { loading, error, summary, reload } = useGlobalDiagnostics( + client, + severity, + host?.packageId ?? undefined, + ); const { entries: typesEntries } = useMetadataTypes(client); // Index by type so we can look up the human label per-type without