Skip to content

Commit 5c1e4f2

Browse files
committed
test(app-shell): the new-package door fails open on an unreported capability set
Home's no-agent chip, rendered inside the real MePermissionsProvider with no systemPermissions, sends the session to Setup's New Package; a reported set without the Setup pair sends it to All metadata (the control). The chip's old 'New in Studio' name leaves two test titles and four comments. Claude-Session: https://claude.ai/code/session_01QSeKYoTF7Fd6aNUuvXGukP Co-authored-by: Claude <noreply@anthropic.com>
1 parent f4aa8f8 commit 5c1e4f2

4 files changed

Lines changed: 51 additions & 10 deletions

File tree

‎ui/packages/app-shell/src/console/ai/AiUnavailable.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Studio is the other way to build, so a session that may author is offered
1818
* the new-package flow beside it (Setup → Packages with New Package open,
1919
* which lands in Studio on the new package): the same entry, under the same label
20-
* and on the same terms, as Home's "New in Studio" chip (an admin, on a
20+
* and on the same terms, as Home's "New blank app" chip (an admin, on a
2121
* runtime that offers authoring, holding the authoring capability).
2222
*/
2323

‎ui/packages/app-shell/src/console/home/HomePage.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ export function HomePage({ checklist }: HomePageProps = {}) {
964964
{/* objectstack#26614 — on a deployment whose agent catalog
965965
* is empty or absent, "Build an app" promises a build nothing
966966
* here can start. There the chip says what it opens instead,
967-
* "New in Studio", and opens New Package in Setup → Packages,
967+
* "New blank app", and opens New Package in Setup → Packages,
968968
* which lands in Studio on the new package (objectstack#36908); and
969969
* since Studio is then the ONLY way to build, a session that
970970
* may not author gets no chip rather than a dimmed one (the

‎ui/packages/app-shell/src/console/home/__tests__/HomePage.noAgentsBuildChip-26614.test.tsx‎

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* - with an agent in the catalog the chip is unchanged: "Build an app", to
1212
* `/studio`, dimmed with its reason for a session that may not author;
13-
* - with none it says what it opens, "New in Studio", and opens Studio's
13+
* - with none it says what it opens, "New blank app", and opens Studio's
1414
* new-package flow (`SETUP_NEW_PACKAGE_PATH`, Setup → Packages with New
1515
* Package open since objectstack#36908);
1616
* - with none, a session that may not author gets no build chip at all,
@@ -20,8 +20,8 @@
2020
*
2121
* objectstack#36969 — the AI form is drawn where the catalog serves the build
2222
* agent itself (alias-aware), not any agent: where in-app building is closed
23-
* the catalog keeps `ask` and drops `build`, and the chip takes the "New in
24-
* Studio" form there, as for an empty catalog. So the unchanged-chip cases
23+
* the catalog keeps `ask` and drops `build`, and the chip takes the "New
24+
* blank app" form there, as for an empty catalog. So the unchanged-chip cases
2525
* serve `build`; a catalog of `ask` or of another agent alone is pinned below.
2626
*
2727
* The catalog stand-in moves the way the real `useAgents` does: an empty first
@@ -44,8 +44,12 @@ const state = vi.hoisted(() => ({
4444
agents: [] as Array<{ name: string }>,
4545
/** Holds the catalog in flight. */
4646
catalogPending: false,
47-
/** Whether the session holds the Setup → Packages pair (`setup.access` + `manage_platform_settings`). */
48-
setupPair: true,
47+
/**
48+
* Whether the session holds the Setup → Packages pair (`setup.access` +
49+
* `manage_platform_settings`). `'unreported'` stubs nothing: the real
50+
* provider around the page answers, with no `systemPermissions` at all.
51+
*/
52+
setupPair: true as boolean | 'unreported',
4953
}));
5054

5155
vi.mock('react-router-dom', async () => {
@@ -117,6 +121,7 @@ vi.mock('@object-ui/permissions', async (importOriginal) => {
117121
...actual,
118122
usePermissions: () => {
119123
const real = actual.usePermissions();
124+
if (state.setupPair === 'unreported') return real;
120125
return {
121126
...real,
122127
hasCapabilities: (required: string[]) =>
@@ -174,6 +179,7 @@ vi.mock('../../deployment-notice/DeploymentNotice', () => ({ DeploymentNotice: (
174179
import '@objectstack/lint';
175180
import { HomePage } from '../HomePage';
176181
import { SETUP_NEW_PACKAGE_PATH } from '../../../views/metadata-admin/packageSource';
182+
import { MePermissionsProvider, type MePermissionsAuthenticatedResponse } from '@object-ui/permissions';
177183

178184
beforeEach(() => {
179185
navigateMock.mockReset();
@@ -213,7 +219,7 @@ describe('with the build agent in the catalog, the build chip is unchanged (obje
213219
});
214220

215221
describe('with no agent in the catalog (objectstack#26614)', () => {
216-
it('the chip reads "New in Studio" and opens Studio\'s new-package flow', async () => {
222+
it('the chip reads "New blank app" and opens Studio\'s new-package flow', async () => {
217223
const user = userEvent.setup();
218224
render(<HomePage />);
219225
const chip = await screen.findByTestId('home-build-in-studio');
@@ -234,6 +240,41 @@ describe('with no agent in the catalog (objectstack#26614)', () => {
234240
expect(navigateMock).not.toHaveBeenCalledWith(SETUP_NEW_PACKAGE_PATH);
235241
});
236242

243+
/**
244+
* objectstack#36908 — the doors fail OPEN where the server never reported
245+
* the capability set, as their own authoring gate (`useCanAuthorMetadata`)
246+
* does: the door is only a link, and Setup → Packages and the create route
247+
* keep their own server-side gates. Nothing is stubbed here: the real
248+
* provider answers, once with no `systemPermissions` and once (the control)
249+
* with a reported set that holds neither capability of the pair.
250+
*/
251+
it.each([
252+
['an unreported set (no `systemPermissions`) fails open, to Setup\'s New Package', undefined, SETUP_NEW_PACKAGE_PATH],
253+
['control: a reported set without the pair goes to the "All metadata" area', ['manage_metadata'], '/studio/~all/metadata'],
254+
])('%s', async (_case, systemPermissions, to) => {
255+
state.setupPair = 'unreported';
256+
const answer: MePermissionsAuthenticatedResponse = {
257+
authenticated: true,
258+
userId: 'u1',
259+
tenantId: 'org_1',
260+
positions: [],
261+
hasAnyQueue: false,
262+
objectsUsingQueues: [],
263+
permissionSets: ['member'],
264+
...(systemPermissions ? { systemPermissions } : {}),
265+
objects: {},
266+
fields: {},
267+
};
268+
const user = userEvent.setup();
269+
render(
270+
<MePermissionsProvider initialPermissions={answer}>
271+
<HomePage />
272+
</MePermissionsProvider>,
273+
);
274+
await user.click(await screen.findByTestId('home-build-in-studio'));
275+
expect(navigateMock).toHaveBeenCalledWith(to);
276+
});
277+
237278
it('a session that may not author gets no build chip; the template chip keeps the reason', async () => {
238279
state.canAuthorMetadata = false;
239280
render(<HomePage />);
@@ -249,7 +290,7 @@ describe('without the build agent in the catalog, the chip takes its Studio form
249290
it.each([
250291
['in-app building closed: `ask` served, `build` not', [{ name: 'ask' }]],
251292
['another agent only', [{ name: 'custom_helper' }]],
252-
])('%s: "New in Studio", to Studio\'s new-package flow, and no "Build an app"', async (_case, agents) => {
293+
])('%s: "New blank app", to Studio\'s new-package flow, and no "Build an app"', async (_case, agents) => {
253294
state.agents = agents;
254295
const user = userEvent.setup();
255296
render(<HomePage />);

‎ui/packages/app-shell/src/views/metadata-admin/packageSource.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export const SETUP_PACKAGES_PATH = `${packagesHref('/apps/setup')}?${PACKAGES_FA
207207

208208
/**
209209
* Setup → Packages with New Package open (objectstack#36908): the console's
210-
* new-package doors (Home's and the `/ai` screen's 「New in Studio」, the
210+
* new-package doors (Home's and the `/ai` screen's 「New blank app」, the
211211
* 「Add app」 menu). The create lands in Studio on the new package.
212212
*/
213213
export const SETUP_NEW_PACKAGE_PATH = `${SETUP_PACKAGES_PATH}&${PACKAGES_NEW_PARAM}=${PACKAGES_NEW_PACKAGE_VALUE}`;

0 commit comments

Comments
 (0)