Skip to content

Commit 8f0d838

Browse files
fix(app-shell): the Diagnostics page inside a package's Studio area sweeps only that package (#29230)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbY8yy1z7weZjvcF9CG3bmqs)_ Fixes #29179 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:Studio「全部元数据」区里,某个包内的诊断页现在只扫描这个包,和旁边的目录页一致;跨包入口(`~all`)和 Setup 的诊断页保持全环境扫描不变。 - **为什么改**:作者在包 A 里看到目录说「没有问题」,诊断页却列出别的包的无效项,点进去还跳到一个无关页面,无法找到要修的东西。 - **风险与回滚**:风险低,只多传一个包参数给已有的诊断请求(服务器早已支持按包过滤,目录页一直这样用);回滚即还原 `DiagnosticsPage.tsx` 一处改动。 - **先看**:`ui/packages/app-shell/src/views/metadata-admin/DiagnosticsPage.tsx`(读取区域宿主并传 `packageId` 那一段);`DiagnosticsPage.packageScope-29179.test.tsx`。 - **两分钟验证**:`pnpm --dir ui exec vitest run packages/app-shell/src/views/metadata-admin/DiagnosticsPage.packageScope-29179.test.tsx`,预期 5 个用例全绿(在 main 上其中 3 个红)。 - **需要你做的**:无,席位落地。 ## What changes `MetadataDiagnosticsPage` now reads the Studio area host (`useMetadataAreaHost()`) and passes `host.packageId` to `useGlobalDiagnostics` when the area is open on a package, the way `DirectoryPage` passes its `activePackage`. The request becomes `GET /api/v1/meta/diagnostics?severity=…&package=PKG`, so the page's count matches the directory's and every listed row is an item of the open package, whose area-relative link (`../TYPE/NAME`) opens that item in its own package's area. Unchanged: the cross-package leg (`/studio/~all/metadata/_diagnostics`, `packageId: null`) and Setup's page (no area host) keep the environment-wide sweep (#28561). No copy, i18n key or exported type changes. ## Why Inside `com.example.showcase`'s area the directory's scoped sweep found 0 issues (no "View all issues" link), while the Diagnostics page's unscoped sweep listed `pkga_qa_obj.qa_diag_view`, another package's item; its link resolved into the showcase area and landed on an unrelated Interfaces page. The server already filters the sweep by `packageId` at its list read, and diagnostics entries carry no package, so scoping the request is the whole fix. ## Tests New `DiagnosticsPage.packageScope-29179.test.tsx` runs the real `useGlobalDiagnostics` against a fake client that answers as the server does (a `packageId` narrows the sweep), with the page nested at `ROOT/_diagnostics` as the area and Setup mount it: - a package's area: the request carries the package, another package's invalid item is not listed, the page reads "All clear" (the card's scenario); - a package's area: an own invalid item links to `/studio/PKG/metadata/view/NAME`; - switching to Errors + Warnings keeps the package scope; - the `~all` leg and Setup keep the environment-wide request and list the foreign row (preservation pins). <details><summary>Red on main (ea150b7), green on the fix</summary> On `ea150b7f` with the test file alone: `Tests 3 failed | 2 passed (5)`, the three package-area cases failing with `expected [ { severity: 'error' } ] to deeply equal [ { severity: 'error', …(1) } ]`, `expected` the foreign row's anchor element `to be null` and `expected { severity: 'warning' } to deeply equal { severity: 'warning', …(1) }`. The two preservation cases pass on main by design. On the fix (`18d2b4cb`), with the two existing Diagnostics page tests: `Test Files 3 passed (3) · Tests 12 passed (12)`. </details> ## Acceptance notes - Setup's directory links `./_diagnostics` without its `?package=`, so Setup's Diagnostics page stays environment-wide beside a package-scoped directory count. This is outside the card's Studio reach and is left as is (noted, not fixed). - Ablation: the red-on-main run above is the before leg (the same test against the unfixed page, imported from source, so no dist rebuild is involved). ## Verification All readings on head `4cfc9074` (the fix merged with `origin/main` 104cd1a) unless stated. <details><summary>Derived gates: 34 derived, 34 run, 0 NOT-MEASURED</summary> `node scripts/pm/dispatch-gates.mjs --commands` derived 34 commands; the 33 unlocked ones each exit 0 in one loop, and `pnpm --dir ui exec vitest run scripts/` ran under the lock: `Test Files 169 passed | 2 skipped (171) · Tests 4900 passed | 2 skipped (4902)`, VERDICT command-exit 0. `node scripts/check-sdui-manifest.mjs` exit 0. `dispatch-gates --ran`: "34 derived famil(ies) accounted for — 34 run, 0 NOT-MEASURED". `pnpm check:new-line-citations` (from `ui/`): `0 new citation(s)`. </details> <details><summary>Type-check and related tests</summary> - `pnpm exec turbo run type-check --filter=@object-ui/app-shell --concurrency=2`: `Tasks: 65 successful, 65 total`, VERDICT command-exit 0. - The 19 test files that name `DiagnosticsPage` / `MetadataDiagnosticsPage` (`git grep -l` under `ui/packages` and `ui/apps`) plus the three `metadataAreaHost.*` tests (22 files): `Test Files 22 passed (22) · Tests 294 passed (294)`. The rest of app-shell is left to CI's Test UI (declared narrowing). </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (repo-wide lint is CI's) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (not touched) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jV7MUKsme1kh4FsABc)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 68ecc79 commit 8f0d838

3 files changed

Lines changed: 178 additions & 1 deletion

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): inside a package's Studio "All metadata" area, the Diagnostics page sweeps only that package, as the directory beside it does
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The Diagnostics page (`<root>/_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.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#29179 — inside a package's "All metadata" area (ADR-0146 D1),
5+
* the Diagnostics page sweeps that package, as the directory beside it does.
6+
* An unscoped sweep listed another package's invalid item under this package's
7+
* area, and its row link, relative to the area, opened an unrelated page.
8+
*
9+
* The real `useGlobalDiagnostics` runs against a fake client that answers as
10+
* the server does: a `packageId` narrows the sweep to that package's items,
11+
* none answers every package's. The cross-package leg and Setup (no area)
12+
* keep the environment-wide sweep.
13+
*/
14+
15+
import '@testing-library/jest-dom/vitest';
16+
import * as React from 'react';
17+
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
18+
import { render, screen, cleanup, fireEvent, within } from '@testing-library/react';
19+
import { MemoryRouter, Route, Routes } from 'react-router-dom';
20+
import type { MetadataDiagnosticsSummary } from '@object-ui/data-objectstack';
21+
import { MetadataAreaHostContext, type MetadataAreaHost } from './metadataAreaHost';
22+
23+
const SHOWCASE = 'com.example.showcase';
24+
const PKG_A = 'com.qa.pkga';
25+
26+
/** Each swept item and the package that owns it (the server's `_packageId`). */
27+
const SWEPT: Array<{ packageId: string; entry: MetadataDiagnosticsSummary['entries'][number] }> = [
28+
{
29+
packageId: PKG_A,
30+
entry: {
31+
type: 'view',
32+
name: 'pkga_qa_obj.qa_diag_view',
33+
diagnostics: { valid: false, errors: [{ path: 'columns.0.field', message: 'Expected string' }] },
34+
},
35+
},
36+
{
37+
packageId: SHOWCASE,
38+
entry: {
39+
type: 'object',
40+
name: 'showcase_loose',
41+
diagnostics: { valid: true, warnings: [{ path: 'label', message: 'Missing label' }] },
42+
},
43+
},
44+
];
45+
let showcaseInvalid: MetadataDiagnosticsSummary['entries'][number] | null = null;
46+
47+
const requests: Array<{ severity: 'error' | 'warning'; packageId?: string }> = [];
48+
const client = {
49+
diagnostics: async (opts: { severity: 'error' | 'warning'; packageId?: string }) => {
50+
requests.push(opts);
51+
const rows = [
52+
...SWEPT,
53+
...(showcaseInvalid ? [{ packageId: SHOWCASE, entry: showcaseInvalid }] : []),
54+
].filter((r) => opts.packageId === undefined || r.packageId === opts.packageId);
55+
const entries = rows
56+
.map((r) => r.entry)
57+
.filter((e) => (e.diagnostics.errors?.length ?? 0) > 0 || opts.severity === 'warning');
58+
return { entries, total: entries.length, scannedTypes: 2, scannedItems: rows.length, stats: {} };
59+
},
60+
};
61+
62+
vi.mock('./useMetadata', async (importActual) => {
63+
const actual = await importActual<typeof import('./useMetadata')>();
64+
return {
65+
...actual,
66+
useMetadataClient: () => client,
67+
useMetadataTypes: () => ({ loading: false, error: null, entries: [] }),
68+
};
69+
});
70+
vi.mock('./i18n', async (importOriginal) => ({
71+
...(await importOriginal<Record<string, unknown>>()),
72+
useMetadataLocale: () => 'en-US',
73+
}));
74+
75+
import { MetadataDiagnosticsPage } from './DiagnosticsPage';
76+
77+
beforeEach(() => {
78+
requests.length = 0;
79+
showcaseInvalid = null;
80+
});
81+
afterEach(cleanup);
82+
83+
/** The page at `<root>/_diagnostics`, nested as the area and Setup mount it, so its relative links resolve as there. */
84+
function mount(root: string, host: MetadataAreaHost | null) {
85+
const page = <MetadataDiagnosticsPage />;
86+
render(
87+
<MemoryRouter initialEntries={[`${root}/_diagnostics`]}>
88+
<Routes>
89+
<Route
90+
path={`${root}/*`}
91+
element={
92+
<Routes>
93+
<Route
94+
path="_diagnostics"
95+
element={host ? <MetadataAreaHostContext.Provider value={host}>{page}</MetadataAreaHostContext.Provider> : page}
96+
/>
97+
</Routes>
98+
}
99+
/>
100+
</Routes>
101+
</MemoryRouter>,
102+
);
103+
return screen.findByTestId('diagnostics-summary-badge');
104+
}
105+
106+
const areaOf = (packageId: string | null): MetadataAreaHost => {
107+
const basePath = `/studio/${packageId ?? '~all'}/metadata`;
108+
return { packageId, readOnly: false, basePath };
109+
};
110+
111+
describe('the Diagnostics page sweeps the package its area is open on (objectstack#29179)', () => {
112+
it("a package's area: another package's invalid item is not listed, and the page reads clean", async () => {
113+
await mount(`/studio/${SHOWCASE}/metadata`, areaOf(SHOWCASE));
114+
expect(requests).toEqual([{ severity: 'error', packageId: SHOWCASE }]);
115+
expect(await screen.findByText('All clear')).toBeInTheDocument();
116+
expect(screen.queryByText('pkga_qa_obj.qa_diag_view')).toBeNull();
117+
});
118+
119+
it("a package's area: each row is the package's own item and links to it in the area", async () => {
120+
showcaseInvalid = {
121+
type: 'view',
122+
name: 'showcase_broken_view',
123+
diagnostics: { valid: false, errors: [{ path: 'columns', message: 'Required' }] },
124+
};
125+
await mount(`/studio/${SHOWCASE}/metadata`, areaOf(SHOWCASE));
126+
const link = await screen.findByRole('link', { name: 'showcase_broken_view' });
127+
expect(link).toHaveAttribute('href', `/studio/${SHOWCASE}/metadata/view/showcase_broken_view`);
128+
expect(screen.queryByText('pkga_qa_obj.qa_diag_view')).toBeNull();
129+
});
130+
131+
it('switching to Errors + Warnings keeps the package scope', async () => {
132+
await mount(`/studio/${SHOWCASE}/metadata`, areaOf(SHOWCASE));
133+
fireEvent.click(screen.getByRole('tab', { name: 'Errors + Warnings' }));
134+
await screen.findByText('showcase_loose');
135+
expect(requests.at(-1)).toEqual({ severity: 'warning', packageId: SHOWCASE });
136+
expect(screen.queryByText('pkga_qa_obj.qa_diag_view')).toBeNull();
137+
});
138+
139+
it('the cross-package leg keeps the environment-wide sweep', async () => {
140+
const badge = await mount('/studio/~all/metadata', areaOf(null));
141+
expect(requests).toEqual([{ severity: 'error' }]);
142+
expect(within(badge).getByText(/1 issue\(s\)/)).toBeInTheDocument();
143+
expect(await screen.findByRole('link', { name: 'pkga_qa_obj.qa_diag_view' })).toHaveAttribute(
144+
'href',
145+
'/studio/~all/metadata/view/pkga_qa_obj.qa_diag_view',
146+
);
147+
});
148+
149+
it('Setup (no area) keeps the environment-wide sweep', async () => {
150+
await mount('/apps/setup/metadata', null);
151+
expect(requests).toEqual([{ severity: 'error' }]);
152+
expect(await screen.findByRole('link', { name: 'pkga_qa_obj.qa_diag_view' })).toHaveAttribute(
153+
'href',
154+
'/apps/setup/metadata/view/pkga_qa_obj.qa_diag_view',
155+
);
156+
});
157+
});

‎ui/packages/app-shell/src/views/metadata-admin/DiagnosticsPage.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
useGlobalDiagnostics,
3232
type MetadataDiagnosticsEntry,
3333
} from './useMetadata.js';
34+
import { useMetadataAreaHost } from './metadataAreaHost.js';
3435
import { t, tFormat, translateMetadataType, useMetadataLocale } from './i18n.js';
3536
import { diagnosticsHeaderTone, type DiagnosticsHeaderTone } from './diagnostics-tone.js';
3637

@@ -65,7 +66,16 @@ export function MetadataDiagnosticsPage() {
6566
const client = useMetadataClient();
6667
const locale = useMetadataLocale();
6768
const [severity, setSeverity] = React.useState<Severity>('error');
68-
const { loading, error, summary, reload } = useGlobalDiagnostics(client, severity);
69+
// objectstack ADR-0146 D1 — inside a package's area the sweep is that
70+
// package's, as the directory beside it is: an item of another package has
71+
// no row here, and every row's link stays inside its own package's area. The
72+
// cross-package leg (`packageId: null`) and Setup (no area) sweep everything.
73+
const host = useMetadataAreaHost();
74+
const { loading, error, summary, reload } = useGlobalDiagnostics(
75+
client,
76+
severity,
77+
host?.packageId ?? undefined,
78+
);
6979
const { entries: typesEntries } = useMetadataTypes(client);
7080

7181
// Index by type so we can look up the human label per-type without

0 commit comments

Comments
 (0)