Skip to content

Commit c00ef9e

Browse files
committed
test(console): pin the push route hosting in the listener and the catch-all
Claude-Session: https://claude.ai/code/session_01QsR2jVL7fzYGjxa3ani6k8 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 92a6f43 commit c00ef9e

3 files changed

Lines changed: 232 additions & 3 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/console': patch
4+
---
5+
6+
fix(console): a push route from the mobile shell opens the record, hosted under an app the way the inbox hosts it
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
A push delivery carries the notification's link as `route`: app-relative (`/opportunity/123`) or already a Console route (`/apps/crm/opportunity/123`). The Console's listener for the mobile shell's navigate event moved its router to that route as written, so `/opportunity/123` matched no route and the person landed on Home instead of the record.
12+
13+
What changes:
14+
15+
- The listener resolves the route with the same resolver the inbox bell and Home use for that notification. An app-relative route is hosted under the app the person is in or last had open; an `/apps/...` route passes through unchanged.
16+
- With no app open yet (a tap that starts the app), the route goes to the router as given, and the Console's unmatched-route page hosts it under the default app once the app list has loaded: the app the person last had open while it is still active, else the first active app. The same page handles an app-relative path that arrives as the page's first URL, which the shell sends when it re-creates its web view at a held route or when no listener answered.
17+
- A path whose first segment names a Console route served outside an app (`/home`, `/dev`, `/studio`, ...) still redirects to `/`, as before. A path such as `/foo/bar` that names no Console route now opens `/apps/<default app>/foo/bar` instead of Home.
18+
- `@object-ui/app-shell` exports `resolveNotificationTarget`, its `NotificationTarget` type and `CONSOLE_ROOT_SEGMENTS` from the package root.
19+
20+
What to do: nothing.

‎ui/apps/console/src/__tests__/App.nativeShellMode-29039.test.tsx‎

Lines changed: 151 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,42 @@ import {
3333
} from '../../../../packages/mobile/src/nativeHost';
3434
import { resetNativeHostWatchForTests } from '../../../../packages/mobile/src/useNativeHost';
3535

36-
const { passthrough, stub } = vi.hoisted(() => {
36+
const { passthrough, stub, shellState } = vi.hoisted(() => {
3737
const passthrough = ({ children }: { children?: ReactNode }) => <>{children}</>;
3838
const stub = (testid: string) => () => <div data-testid={testid} />;
39-
return { passthrough, stub };
39+
// objectstack#29750: what the shell's navigation context and the metadata
40+
// provider answer. The defaults are what this file's other cases read
41+
// without either provider: no current app, an empty app list, not loading.
42+
const shellState = {
43+
currentAppName: undefined as string | undefined,
44+
apps: [] as Array<Record<string, unknown>>,
45+
loading: false,
46+
appStatus: undefined as 'idle' | 'loading' | 'ready' | 'error' | undefined,
47+
};
48+
return { passthrough, stub, shellState };
4049
});
4150

4251
vi.mock('@object-ui/app-shell', async (importOriginal) => ({
4352
...(await importOriginal<Record<string, unknown>>()),
4453
ConsoleShell: passthrough,
4554
ConsoleToaster: () => null,
4655
LoadingScreen: stub('loading-screen'),
47-
RedirectWithSplash: stub('redirect-with-splash'),
56+
// Records where it would go, so the catch-all's answer is readable.
57+
RedirectWithSplash: ({ to }: { to: string }) => <div data-testid="redirect-with-splash" data-to={to} />,
58+
LoadingFallback: stub('loading-fallback'),
59+
useNavigationContext: () => ({
60+
context: 'app',
61+
setContext: () => {},
62+
currentAppName: shellState.currentAppName,
63+
setCurrentAppName: () => {},
64+
recordTitle: undefined,
65+
setRecordTitle: () => {},
66+
}),
67+
useMetadata: () => ({
68+
apps: shellState.apps,
69+
loading: shellState.loading,
70+
getTypeStatus: (type: string) => (type === 'app' ? shellState.appStatus : undefined),
71+
}),
4872
RequireAiSurface: passthrough,
4973
SystemRedirect: () => null,
5074
DefaultHomeLayout: passthrough,
@@ -134,6 +158,10 @@ function dispatchNavigate(route: unknown): CustomEvent {
134158
beforeEach(() => {
135159
resetNativeHostEventsForTests();
136160
resetNativeHostWatchForTests();
161+
shellState.currentAppName = undefined;
162+
shellState.apps = [];
163+
shellState.loading = false;
164+
shellState.appStatus = undefined;
137165
window.history.pushState({}, '', '/login');
138166
});
139167

@@ -188,3 +216,123 @@ describe('control: the Console in a browser behaves as today', () => {
188216
expect(window.location.pathname).toBe('/login');
189217
});
190218
});
219+
220+
/**
221+
* objectstack#29750 — the shell's route is a push route, the notification's
222+
* `actionUrl`, and the push contract (`packages/spec/src/api/push-delivery.zod.ts`)
223+
* says it is resolved "as the inbox does, never verbatim": app-relative paths
224+
* are hosted under `/apps/APP/`, an `/apps/…` route passes through. Navigated
225+
* verbatim, `/opportunity/123` matched no route and the catch-all sent the
226+
* person to Home.
227+
*/
228+
describe('a push route from the shell is hosted the way the inbox hosts it', () => {
229+
it('an app-relative route is hosted under the app in the URL', async () => {
230+
installBridge();
231+
window.history.pushState({}, '', '/apps/crm/opportunity');
232+
render(<App />);
233+
await screen.findByTestId('app-content');
234+
const event = dispatchNavigate('/opportunity/123?tab=activity#notes');
235+
expect(event.defaultPrevented).toBe(true);
236+
expect(`${window.location.pathname}${window.location.search}${window.location.hash}`)
237+
.toBe('/apps/crm/opportunity/123?tab=activity#notes');
238+
});
239+
240+
it('the app the shell last published wins over the URL, as for the inbox bell', async () => {
241+
installBridge();
242+
shellState.currentAppName = 'sales';
243+
window.history.pushState({}, '', '/home');
244+
render(<App />);
245+
await screen.findByTestId('home-page');
246+
dispatchNavigate('/opportunity/123');
247+
expect(window.location.pathname).toBe('/apps/sales/opportunity/123');
248+
});
249+
250+
it('a Console route under /apps passes through unchanged', async () => {
251+
installBridge();
252+
window.history.pushState({}, '', '/apps/crm/opportunity');
253+
render(<App />);
254+
await screen.findByTestId('app-content');
255+
const event = dispatchNavigate('/apps/x/y/1');
256+
expect(event.defaultPrevented).toBe(true);
257+
expect(window.location.pathname).toBe('/apps/x/y/1');
258+
});
259+
260+
it('with no app open, the catch-all hosts the handed-over route under the default app', async () => {
261+
installBridge();
262+
shellState.apps = [{ name: 'crm', active: true }];
263+
shellState.appStatus = 'ready';
264+
render(<App />);
265+
await screen.findByTestId('login-page');
266+
const event = dispatchNavigate('/opportunity/123');
267+
expect(event.defaultPrevented).toBe(true);
268+
expect(window.location.pathname).toBe('/opportunity/123');
269+
expect((await screen.findByTestId('redirect-with-splash')).getAttribute('data-to'))
270+
.toBe('/apps/crm/opportunity/123');
271+
});
272+
});
273+
274+
/**
275+
* objectstack#29750 — the same push route can arrive as the page's FIRST URL:
276+
* the mobile shell starts a re-created WebView at a held route, and falls back
277+
* to `location.assign` of it when no navigate listener answered. The
278+
* catch-all hosts an app-relative path like the inbox; a stale Console link
279+
* keeps the old redirect to `/`.
280+
*/
281+
describe('the catch-all hosts an app-relative first URL under an app', () => {
282+
function catchAllTarget(): Promise<string | null> {
283+
return screen.findByTestId('redirect-with-splash').then((el) => el.getAttribute('data-to'));
284+
}
285+
286+
it('hosts it under the first active app, query and hash kept', async () => {
287+
shellState.apps = [{ name: 'gone', active: false }, { name: 'crm', active: true }];
288+
shellState.appStatus = 'ready';
289+
window.history.pushState({}, '', '/opportunity/123?tab=activity#notes');
290+
render(<App />);
291+
expect(await catchAllTarget()).toBe('/apps/crm/opportunity/123?tab=activity#notes');
292+
});
293+
294+
it('hosts it under the app the person last had open while that app is still active', async () => {
295+
shellState.apps = [{ name: 'crm', active: true }, { name: 'sales', active: true }];
296+
shellState.appStatus = 'ready';
297+
shellState.currentAppName = 'sales';
298+
window.history.pushState({}, '', '/opportunity/123');
299+
render(<App />);
300+
expect(await catchAllTarget()).toBe('/apps/sales/opportunity/123');
301+
});
302+
303+
it('waits for the app list before it answers', async () => {
304+
shellState.loading = true;
305+
window.history.pushState({}, '', '/opportunity/123');
306+
render(<App />);
307+
expect(await screen.findByTestId('loading-fallback')).toBeInTheDocument();
308+
expect(screen.queryByTestId('redirect-with-splash')).toBeNull();
309+
});
310+
311+
it('an app list that failed to load is no answer: the old redirect to / runs', async () => {
312+
shellState.appStatus = 'error';
313+
window.history.pushState({}, '', '/opportunity/123');
314+
render(<App />);
315+
expect(await catchAllTarget()).toBe('/');
316+
});
317+
318+
it('control: a stale Console link still redirects to /', async () => {
319+
shellState.apps = [{ name: 'crm', active: true }];
320+
shellState.appStatus = 'ready';
321+
for (const path of ['/dev/nope', '/home/nope', '/apps']) {
322+
window.history.pushState({}, '', path);
323+
render(<App />);
324+
expect(await catchAllTarget()).toBe('/');
325+
cleanup();
326+
}
327+
});
328+
329+
it('control: a real top-level Console route is never rewritten', async () => {
330+
shellState.apps = [{ name: 'crm', active: true }];
331+
shellState.appStatus = 'ready';
332+
window.history.pushState({}, '', '/home');
333+
render(<App />);
334+
expect(await screen.findByTestId('home-page')).toBeInTheDocument();
335+
expect(screen.queryByTestId('redirect-with-splash')).toBeNull();
336+
expect(window.location.pathname).toBe('/home');
337+
});
338+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#29750 — where a route the native shell hands the Console lands,
11+
* at the unit level. The wiring into the real router is pinned in
12+
* `App.nativeShellMode-29039.test.tsx`; this file holds the two answers that
13+
* no listener input can reach (the resolver's `null` and `external`), because
14+
* `isInAppRoute` refuses a blank route and any scheme or `//host` before the
15+
* Console ever sees it, and the unmatched-path predicate's table.
16+
*/
17+
18+
import { describe, expect, it } from 'vitest';
19+
import { isAppRelativeUnmatchedPath, nativeShellRouteTarget } from '../nativeShellRoute';
20+
21+
describe('nativeShellRouteTarget', () => {
22+
it('hosts an app-relative route under the hinted app', () => {
23+
expect(nativeShellRouteTarget('/opportunity/123', 'crm', [])).toBe('/apps/crm/opportunity/123');
24+
});
25+
26+
it('passes a Console route under /apps through', () => {
27+
expect(nativeShellRouteTarget('/apps/x/y/1', 'crm', [])).toBe('/apps/x/y/1');
28+
});
29+
30+
it('re-checks the hint against an app list in reach, as the inbox does', () => {
31+
const apps = [{ name: 'crm', active: true }, { name: 'old', active: false }];
32+
expect(nativeShellRouteTarget('/opportunity/123', 'old', apps)).toBe('/apps/crm/opportunity/123');
33+
});
34+
35+
it('with no hint, hands the route to the router unchanged', () => {
36+
expect(nativeShellRouteTarget('/opportunity/123', undefined, [])).toBe('/opportunity/123');
37+
});
38+
39+
it('a blank route resolves to nothing: no navigation', () => {
40+
expect(nativeShellRouteTarget('', 'crm', [])).toBeNull();
41+
expect(nativeShellRouteTarget(' ', 'crm', [])).toBeNull();
42+
});
43+
44+
it('an off-console route resolves to nothing for the router: no navigation', () => {
45+
expect(nativeShellRouteTarget('https://evil.example/x', 'crm', [])).toBeNull();
46+
expect(nativeShellRouteTarget('//evil.example/x', 'crm', [])).toBeNull();
47+
});
48+
});
49+
50+
describe('isAppRelativeUnmatchedPath', () => {
51+
it('a path whose first segment names no Console route is app-relative', () => {
52+
expect(isAppRelativeUnmatchedPath('/opportunity/123')).toBe(true);
53+
expect(isAppRelativeUnmatchedPath('/showcase_task')).toBe(true);
54+
});
55+
56+
it('a Console route served outside an app, the landing and /apps are not', () => {
57+
for (const path of ['/', '/home/x', '/dev/nope', '/studio/x/y', '/forms/x/y', '/apps', '/apps/']) {
58+
expect(isAppRelativeUnmatchedPath(path), path).toBe(false);
59+
}
60+
});
61+
});

0 commit comments

Comments
 (0)