From 0e477fceae9f4f368c848cada3112b491471da52 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 10:44:36 +0000 Subject: [PATCH] fix(app-shell): a package's non-first app opens itself from the avatar menu, palette, switcher, Home tiles and report index The avatar menu's hidden-app entry, the palette's app switch, the app switcher's rows, Home's tiles and the report index's other-apps links linked to an app's package id, which /apps/SEGMENT resolves to the package's FIRST app. They now use appAddressSegment, the app's one address: the package id where it resolves back to the app, else its name. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jSQKM1ZF6P3HSnWrEQ --- .../29024-hidden-app-avatar-menu-address.md | 12 + ...ndPalette.packageAppAddress-29024.test.tsx | 98 ++++++++ .../app-shell/src/chrome/CommandPalette.tsx | 2 +- .../src/console/home/HomeAppsStrip.tsx | 19 +- .../app-shell/src/console/home/HomePage.tsx | 1 + .../HomeAppsStrip.branding-27386.test.tsx | 1 + ...AppsStrip.packageAppAddress-29024.test.tsx | 62 +++++ ...HomeAppsStrip.tilesAreLinks-12305.test.tsx | 1 + .../app-shell/src/layout/AppHeader.tsx | 10 +- .../app-shell/src/layout/AppSwitcher.tsx | 3 +- .../AppHeader.hiddenAppAddress-29024.test.tsx | 217 ++++++++++++++++++ ...pSwitcher.packageAppAddress-29024.test.tsx | 121 ++++++++++ .../src/views/AppReportIndexView.tsx | 5 +- ...eportIndex.otherAppsAddress-29024.test.tsx | 113 +++++++++ .../src/views/app-launcher-renderer.tsx | 1 + 15 files changed, 656 insertions(+), 10 deletions(-) create mode 100644 .changeset/29024-hidden-app-avatar-menu-address.md create mode 100644 ui/packages/app-shell/src/chrome/CommandPalette.packageAppAddress-29024.test.tsx create mode 100644 ui/packages/app-shell/src/console/home/__tests__/HomeAppsStrip.packageAppAddress-29024.test.tsx create mode 100644 ui/packages/app-shell/src/layout/__tests__/AppHeader.hiddenAppAddress-29024.test.tsx create mode 100644 ui/packages/app-shell/src/layout/__tests__/AppSwitcher.packageAppAddress-29024.test.tsx create mode 100644 ui/packages/app-shell/src/views/__tests__/AppReportIndex.otherAppsAddress-29024.test.tsx diff --git a/.changeset/29024-hidden-app-avatar-menu-address.md b/.changeset/29024-hidden-app-avatar-menu-address.md new file mode 100644 index 00000000000..87f2ea1fac9 --- /dev/null +++ b/.changeset/29024-hidden-app-avatar-menu-address.md @@ -0,0 +1,12 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(app-shell): an app that shares its package with the package's first app opens itself from the avatar menu, the ⌘K palette, the app switcher, Home's tiles and the report index's other-apps links + +Clause-②: no +Metadata-protocol: none + +`/apps/PACKAGE_ID` opens a package's first app, so a link keyed on the package id cannot reach the package's other apps; their name is the only address that does. The avatar menu's entry for a hidden app linked to its package id, so a hidden app shipped beside its package's main app (a settings-style app) opened the main app instead and could not be reached from the menu at all. The ⌘K palette's "Switch app" items, the app switcher's rows, Home's "Your apps" tiles (and the `app:launcher` block, which draws the same tiles) and the empty report index's "Reports in your other apps" links had the same fault for every non-first app of a package. + +Each now links to the app's one address, the address the Console already resolves an open app to: the package id when it opens this very app, else the app's name. An app that is the only or first app of its package keeps its package-id address. Home's tiles resolve the address among the full app list, hidden apps included, so a visible app behind its package's hidden first app also opens itself. diff --git a/ui/packages/app-shell/src/chrome/CommandPalette.packageAppAddress-29024.test.tsx b/ui/packages/app-shell/src/chrome/CommandPalette.packageAppAddress-29024.test.tsx new file mode 100644 index 00000000000..f27a397aec8 --- /dev/null +++ b/ui/packages/app-shell/src/chrome/CommandPalette.packageAppAddress-29024.test.tsx @@ -0,0 +1,98 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack-ai/objectstack#29024 — the ⌘K palette's "Switch app" item opens + * the app it names, a package's non-first app included. + * + * `/apps/PACKAGE_ID` resolves to the package's FIRST app, so switching by the + * package id opened that first app for every other app of the package (a + * hidden one, which the palette offers too, included). The item now hands + * `onAppChange` the app's one address (`appAddressSegment`): the package id + * where it resolves back to the app, else the app's name. + * + * The harness is `CommandPalette.launcherHiddenApps-26838.test.tsx`'s. + */ + +import * as React from 'react'; +import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'; +import { render, waitFor, cleanup, fireEvent } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import { createI18n, I18nProvider } from '@object-ui/i18n'; + +const state = vi.hoisted(() => ({ apps: [] as Array> })); + +vi.mock('@object-ui/auth', async (importOriginal) => ({ + ...(await importOriginal>()), + useAuth: () => ({ user: { id: 'u1' }, activeOrganization: null }), +})); +// The provider reads the app list from the metadata cache; the rest of the +// cache is the real (empty) one the palette's other groups read. +vi.mock('../providers/MetadataProvider', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + useMetadata: () => ({ ...actual.useMetadata(), apps: state.apps, loading: false }), + }; +}); + +import { CommandPalette } from './CommandPalette'; +import { CommandPaletteProvider } from '../context/CommandPaletteProvider'; +import { LauncherAppsProvider } from '../hooks/useLauncherApps'; + +const FIRST = { name: 'qsixn_app', label: 'R6 App', _packageId: 'com.qa.r6nav', navigation: [] }; +const SECOND = { name: 'qsixn_hidden_app', label: 'R6 Hidden App', hidden: true, _packageId: 'com.qa.r6nav', navigation: [] }; +const SOLO = { name: 'solo_app', label: 'Solo', _packageId: 'com.qa.solo', navigation: [] }; + +function mount(onAppChange: (segment: string) => void) { + render( + + + new Response('{}', { status: 404 })) as unknown as typeof fetch}> + + ({ data: [] })), searchAll: vi.fn(async () => ({ hits: [] })) }} + /> + + + + , + ); + if (!document.querySelector('[cmdk-input]')) throw new Error('the palette did not open'); +} + +/** The cmdk item of the app labelled `label`. */ +function appItem(label: string): Element { + const item = Array.from(document.querySelectorAll('[cmdk-item][data-value^="app "]')).find( + (el) => (el.textContent ?? '').replace(/Current$/, '').trim() === label, + ); + if (!item) throw new Error(`no "Switch app" item for ${label}`); + return item; +} + +beforeEach(() => { + state.apps = [FIRST, SECOND, SOLO]; +}); + +afterEach(() => cleanup()); + +describe('the palette switches to the app it names (objectstack-ai/objectstack#29024)', () => { + it('a package\'s second app is switched to by its name', async () => { + const onAppChange = vi.fn(); + mount(onAppChange); + await waitFor(() => appItem('R6 Hidden App')); + fireEvent.click(appItem('R6 Hidden App')); + await waitFor(() => expect(onAppChange).toHaveBeenCalledWith('qsixn_hidden_app')); + }); + + it('a package\'s first app keeps its package-id address', async () => { + const onAppChange = vi.fn(); + mount(onAppChange); + await waitFor(() => appItem('R6 App')); + fireEvent.click(appItem('R6 App')); + await waitFor(() => expect(onAppChange).toHaveBeenCalledWith('com.qa.r6nav')); + }); +}); diff --git a/ui/packages/app-shell/src/chrome/CommandPalette.tsx b/ui/packages/app-shell/src/chrome/CommandPalette.tsx index 6a5136aeb56..e9f0f5a39d8 100644 --- a/ui/packages/app-shell/src/chrome/CommandPalette.tsx +++ b/ui/packages/app-shell/src/chrome/CommandPalette.tsx @@ -685,7 +685,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates runCommand(() => confirmUnsavedLeave(() => onAppChange(appRouteSegment(app) ?? app.name)))} + onSelect={() => runCommand(() => confirmUnsavedLeave(() => onAppChange(appAddressSegment(apps, app) ?? app.name)))} > {resolveKeyedI18nLabel(app.label, t)} diff --git a/ui/packages/app-shell/src/console/home/HomeAppsStrip.tsx b/ui/packages/app-shell/src/console/home/HomeAppsStrip.tsx index 75c080baaaf..35971535dd1 100644 --- a/ui/packages/app-shell/src/console/home/HomeAppsStrip.tsx +++ b/ui/packages/app-shell/src/console/home/HomeAppsStrip.tsx @@ -41,7 +41,8 @@ import { Link } from 'react-router-dom'; import { LayoutGrid, Plus, Settings, Star } from 'lucide-react'; import { cn } from '@object-ui/components'; import { useDisplayLocale, useObjectTranslation, useObjectLabel } from '@object-ui/i18n'; -import { appRouteSegment, resolveKeyedI18nLabel } from '../../utils/index.js'; +import { resolveKeyedI18nLabel } from '../../utils/index.js'; +import { appAddressSegment } from '../../utils/appRoute.js'; import { getIcon } from '../../utils/getIcon.js'; import { timeAgo } from '../../utils/relativeTime.js'; import { TILE_OPENED_TIME_FORMAT } from './appLastOpened.js'; @@ -101,6 +102,7 @@ function LauncherAppIcon({ app, children }: { app: any; children?: ReactNode }) export function HomeAppsStrip({ apps, + routeApps, favorites, onBrowseMarketplace, isAdmin, @@ -111,6 +113,14 @@ export function HomeAppsStrip({ lastOpened, }: { apps: any[]; + /** + * Every app the console's `/apps/SEGMENT` route resolves against: the + * metadata app list, hidden apps included. A tile links to its app's one + * address among THESE (`appAddressSegment`), never among `apps`: a package + * whose first app is hidden or withheld still opens that first app on its + * package id, so the tile list alone would misaddress the package's others. + */ + routeApps: readonly any[]; favorites: FavoriteItem[]; onBrowseMarketplace: () => void; isAdmin: boolean; @@ -224,9 +234,10 @@ export function HomeAppsStrip({ return ( diff --git a/ui/packages/app-shell/src/console/home/HomePage.tsx b/ui/packages/app-shell/src/console/home/HomePage.tsx index 07e099a3c06..356212cf27e 100644 --- a/ui/packages/app-shell/src/console/home/HomePage.tsx +++ b/ui/packages/app-shell/src/console/home/HomePage.tsx @@ -788,6 +788,7 @@ export function HomePage() { the heading's "System Settings" link rather than a tile */} [], favorites: { id: string }[ {}} isAdmin={false} diff --git a/ui/packages/app-shell/src/console/home/__tests__/HomeAppsStrip.packageAppAddress-29024.test.tsx b/ui/packages/app-shell/src/console/home/__tests__/HomeAppsStrip.packageAppAddress-29024.test.tsx new file mode 100644 index 00000000000..0946f7e2ceb --- /dev/null +++ b/ui/packages/app-shell/src/console/home/__tests__/HomeAppsStrip.packageAppAddress-29024.test.tsx @@ -0,0 +1,62 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack-ai/objectstack#29024 — a "Your apps" tile opens the app it + * names, a package's second app included. + * + * `/apps/PACKAGE_ID` resolves to the package's FIRST app among the metadata + * app list, so a tile keyed on the package id opened that first app for every + * other app of the package. A tile now links to the app's one address + * (`appAddressSegment`) among `routeApps`, the list the route resolves on: + * the package id where it resolves back to the app, else the app's name. + * Resolving among the tiles alone would miss a package whose first app is + * hidden (no tile) and so still opens on the package id. + * + * A real render inside a `MemoryRouter`, as `HomeAppsStrip.tilesAreLinks-12305`. + */ + +import '@testing-library/jest-dom/vitest'; +import { describe, it, expect, afterEach } from 'vitest'; +import React from 'react'; +import { render, screen, cleanup } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import { HomeAppsStrip } from '../HomeAppsStrip'; + +const R6_APP = { name: 'r6_app', label: 'R6 App', _packageId: 'com.qa.r6nav' }; +const R6_BOARD = { name: 'r6_board', label: 'R6 Board', _packageId: 'com.qa.r6nav' }; +const LEAD_SETTINGS = { name: 'lead_settings', label: 'Lead Settings', hidden: true, _packageId: 'com.qa.lead' }; +const LEAD_APP = { name: 'lead_app', label: 'Lead App', _packageId: 'com.qa.lead' }; +const SOLO = { name: 'solo', label: 'Solo', _packageId: 'com.qa.solo' }; + +/** The metadata app list; the tiles are its visible apps, as Home passes them. */ +const ROUTE_APPS = [R6_APP, R6_BOARD, LEAD_SETTINGS, LEAD_APP, SOLO]; +const TILES = [R6_APP, R6_BOARD, LEAD_APP, SOLO]; + +afterEach(() => cleanup()); + +function renderStrip() { + render( + + {}} isAdmin={false} /> + , + ); +} + +describe('HomeAppsStrip tiles open the app they name (objectstack-ai/objectstack#29024)', () => { + it('a package\'s second app links by its name; the first keeps its package id', () => { + renderStrip(); + expect(screen.getByTestId('app-tile-r6_board')).toHaveAttribute('href', '/apps/r6_board'); + expect(screen.getByTestId('app-tile-r6_app')).toHaveAttribute('href', '/apps/com.qa.r6nav'); + }); + + it('a visible app behind its package\'s hidden first app links by its name', () => { + renderStrip(); + expect(screen.queryByTestId('app-tile-lead_settings')).toBeNull(); + expect(screen.getByTestId('app-tile-lead_app')).toHaveAttribute('href', '/apps/lead_app'); + }); + + it('an app alone in its package keeps its package-id address', () => { + renderStrip(); + expect(screen.getByTestId('app-tile-solo')).toHaveAttribute('href', '/apps/com.qa.solo'); + }); +}); diff --git a/ui/packages/app-shell/src/console/home/__tests__/HomeAppsStrip.tilesAreLinks-12305.test.tsx b/ui/packages/app-shell/src/console/home/__tests__/HomeAppsStrip.tilesAreLinks-12305.test.tsx index 6dec45e4338..3dfd9d01422 100644 --- a/ui/packages/app-shell/src/console/home/__tests__/HomeAppsStrip.tilesAreLinks-12305.test.tsx +++ b/ui/packages/app-shell/src/console/home/__tests__/HomeAppsStrip.tilesAreLinks-12305.test.tsx @@ -65,6 +65,7 @@ function renderStrip( {}} isAdmin={false} diff --git a/ui/packages/app-shell/src/layout/AppHeader.tsx b/ui/packages/app-shell/src/layout/AppHeader.tsx index 521f8419e4e..c31a43efaf5 100644 --- a/ui/packages/app-shell/src/layout/AppHeader.tsx +++ b/ui/packages/app-shell/src/layout/AppHeader.tsx @@ -89,7 +89,8 @@ import type { BreadcrumbItem as BreadcrumbItemType } from '@object-ui/types'; import { useAuth, getUserInitials } from '@object-ui/auth'; import { useMetadata } from '../providers/MetadataProvider.js'; import { useBundledReads } from '../providers/bundledReads.js'; -import { resolveKeyedI18nLabel, preferLocal, matchAppBySegment, appRouteSegment, appStudioRoutePath } from '../utils/index.js'; +import { resolveKeyedI18nLabel, preferLocal, matchAppBySegment, appStudioRoutePath } from '../utils/index.js'; +import { appAddressSegment } from '../utils/appRoute.js'; import { getIcon } from '../utils/getIcon.js'; import { useNavigationContext } from '../context/NavigationContext.js'; import { useCommandPalette, useCommandPaletteProviderMounted } from '../context/CommandPaletteProvider.js'; @@ -1290,6 +1291,11 @@ export function AppHeader({ * next to business apps — Personal Settings, etc. The `account` * app is represented by the explicit Profile link above, so it * is filtered out here to avoid a duplicate (dead) entry. + * + * Each entry links to the app's one address (`appAddressSegment`), + * never its bare package id: a hidden app that shares its package + * with the package's first app is reached by its name alone, and + * the package id would open that first app instead. */} {(metadataApps || []) .filter((a: any) => a.active !== false && a.hidden === true && a.name !== 'account') @@ -1299,7 +1305,7 @@ export function AppHeader({ return ( leaveTo(`/apps/${appRouteSegment(app) ?? app.name}`)} + onClick={() => leaveTo(`/apps/${appAddressSegment(metadataApps, app)}`)} className="cursor-pointer" > diff --git a/ui/packages/app-shell/src/layout/AppSwitcher.tsx b/ui/packages/app-shell/src/layout/AppSwitcher.tsx index c855d2dbcf5..b6b2b4f08d2 100644 --- a/ui/packages/app-shell/src/layout/AppSwitcher.tsx +++ b/ui/packages/app-shell/src/layout/AppSwitcher.tsx @@ -36,6 +36,7 @@ import { import { ChevronDown, Check, Eye, Home, LayoutGrid, Pencil, Settings } from 'lucide-react'; import { useMetadata } from '../providers/MetadataProvider.js'; import { resolveKeyedI18nLabel, matchAppBySegment, appRouteSegment } from '../utils/index.js'; +import { appAddressSegment } from '../utils/appRoute.js'; import { useObjectTranslation, useObjectLabel } from '@object-ui/i18n'; import { useHomePath } from '../hooks/useHomePath.js'; import { useLauncherApps } from '../hooks/useLauncherApps.js'; @@ -166,7 +167,7 @@ export function AppSwitcher({ activeAppName, onAppChange, designInStudioPath, st return ( onAppChange(appRouteSegment(app) ?? app.name)} + onClick={() => onAppChange(appAddressSegment(apps, app) ?? app.name)} className="flex items-center gap-2.5 py-2" data-testid={`app-switcher-row-${app.name}`} > diff --git a/ui/packages/app-shell/src/layout/__tests__/AppHeader.hiddenAppAddress-29024.test.tsx b/ui/packages/app-shell/src/layout/__tests__/AppHeader.hiddenAppAddress-29024.test.tsx new file mode 100644 index 00000000000..a82e1423caf --- /dev/null +++ b/ui/packages/app-shell/src/layout/__tests__/AppHeader.hiddenAppAddress-29024.test.tsx @@ -0,0 +1,217 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack-ai/objectstack#29024 — the avatar menu's entry for a hidden app + * opens THAT app. + * + * `hidden: true` keeps an app off the launcher and the switcher; the avatar + * menu is the door left to it. The entry linked to the app's package id, and + * `/apps/PACKAGE_ID` resolves to the package's FIRST app, so a hidden app that + * shares its package with a visible first app could not be reached from the + * menu at all: the entry opened the first app. It now links to the app's one + * address (`appAddressSegment`): the package id where that resolves back to + * the app, else the app's name. + * + * The card's reproduction (QA run #29002): package `com.qa.r6nav` ships + * `qsixn_app` (first, visible) and `qsixn_hidden_app` (hidden). A hidden app + * that is its package's only or first app keeps its package-id address. + * + * The avatar-menu harness is `AppHeader.myOrganizations.test.tsx`'s: + * passthrough menu primitives, so the entries render and click without radix. + */ + +import '@testing-library/jest-dom/vitest'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { render, screen } from '@testing-library/react'; + +const navigate = vi.fn(); + +vi.mock('react-router-dom', () => ({ + useLocation: () => ({ pathname: '/home', search: '', hash: '', state: null, key: 'test' }), + useParams: () => ({}), + useNavigate: () => navigate, + useSearchParams: () => [new URLSearchParams(), vi.fn()] as const, + Link: ({ children, to, ...p }: any) => {children}, +})); + +vi.mock('@object-ui/i18n', async (importOriginal) => ({ + ...(await importOriginal>()), + useObjectTranslation: () => ({ + language: 'en', + t: (key: string, options?: Record) => String(options?.defaultValue ?? key), + }), + useObjectLabel: () => ({ + objectLabel: (n: string) => n, + dashboardLabel: (n: string) => n, + pageLabel: (n: string) => n, + reportLabel: (n: string) => n, + viewLabel: (n: string) => n, + appLabel: (x: { name?: string; label?: string }) => String(x?.label ?? x?.name ?? ''), + }), +})); + +/** + * Passthrough menu primitives — unlike the sibling inbox test, the avatar + * dropdown's CONTENT is the subject here, so `DropdownMenuContent` must render + * its children rather than the `() => null` that suffices when only the bell is + * under test. Radix would otherwise keep the closed menu unmounted in jsdom. + */ +vi.mock('@object-ui/components', async (importOriginal) => { + const actual = await importOriginal>(); + const stripProps = (p: any) => { + const { asChild, variant, size, align, sideOffset, ...rest } = p ?? {}; + return rest; + }; + const Pass = ({ children, ...p }: any) =>
{children}
; + return { + ...actual, + Button: ({ children, asChild, variant, size, ...p }: any) => ( + + ), + DropdownMenu: Pass, + DropdownMenuTrigger: Pass, + DropdownMenuContent: Pass, + // Menu items must be clickable — the assertion is where `onClick` navigates. + DropdownMenuItem: ({ children, onClick, ...p }: any) => ( + + ), + DropdownMenuLabel: Pass, + DropdownMenuSeparator: () => null, + DropdownMenuGroup: Pass, + Avatar: Pass, + AvatarImage: () => null, + AvatarFallback: Pass, + Popover: Pass, + PopoverTrigger: Pass, + PopoverContent: () => null, + Tabs: Pass, + TabsList: Pass, + TabsTrigger: ({ children }: any) => , + TabsContent: Pass, + cn: (...c: any[]) => c.filter(Boolean).join(' '), + }; +}); + +vi.mock('lucide-react', () => { + const Icon = () => ; + return new Proxy({ __esModule: true } as Record, { + get: (target, prop) => { + if (prop === 'then' || prop === '__esModule' || typeof prop === 'symbol') { + return target[prop]; + } + return Icon; + }, + has: (_target, prop) => prop !== 'then', + }); +}); + +vi.mock('@object-ui/react', async (importOriginal) => ({ + ...(await importOriginal>()), + useOffline: () => ({ isOnline: true }), +})); + +vi.mock('@object-ui/collaboration', async (importOriginal) => ({ + ...(await importOriginal>()), + PresenceAvatars: () => null, + useTenantPresence: () => [], +})); + +vi.mock('../ModeToggle', () => ({ ModeToggle: () => null })); +vi.mock('../LocaleSwitcher', () => ({ LocaleSwitcher: () => null })); +vi.mock('../ConnectionStatus', () => ({ ConnectionStatus: () => null })); +vi.mock('../AppSwitcher', () => ({ AppSwitcher: () => null })); +vi.mock('../LocalizedSidebarTrigger', () => ({ LocalizedSidebarTrigger: () => null })); +vi.mock('../PreviewBadge', () => ({ PreviewBadge: () => null })); + +vi.mock('../WorkspaceSwitcher', () => ({ WorkspaceSwitcher: () => null })); + +/** The metadata app list the menu reads, which `/apps/SEGMENT` also resolves on. */ +const served = vi.hoisted(() => ({ apps: [] as Array> })); +vi.mock('../../providers/MetadataProvider', () => ({ + useMetadata: () => ({ apps: served.apps, dashboards: [], pages: [], reports: [] }), +})); + +vi.mock('@object-ui/auth', async (importOriginal) => { + // One stable identity for the file: the header resolves it in an effect + // keyed on it, so a fresh closure per call would loop (see the + // `AppHeader.myOrganizations` harness). + const getAuthConfig = () => Promise.resolve({ features: { multiOrgEnabled: true } }); + const org = { id: 'org_1', name: 'Acme', slug: 'acme' }; + return { + ...(await importOriginal>()), + useAuth: () => ({ + user: { id: 'u1', name: 'Zhang San', email: 'zs@example.com' }, + signOut: vi.fn(), + isAuthEnabled: true, + organizations: [org], + activeOrganization: org, + isOrganizationsLoading: false, + switchOrganization: vi.fn(), + getAuthConfig, + }), + getUserInitials: () => 'ZS', + useWorkspaceAdminStatus: () => ({ isAdmin: false, isResolved: true }), + }; +}); + +/** Stable adapter identity: the bell's pollers key their effects off it. */ +const fakeAdapter = { + find: () => Promise.resolve({ data: [] }), + getClient: () => undefined, +}; + +vi.mock('../../providers/AdapterProvider', () => ({ + useAdapter: () => fakeAdapter, +})); + +import { AppHeader } from '../AppHeader'; + +const FIRST = { name: 'qsixn_app', label: 'R6 App', icon: 'folder', _packageId: 'com.qa.r6nav' }; +const HIDDEN = { name: 'qsixn_hidden_app', label: 'R6 Hidden App', icon: 'settings', hidden: true, _packageId: 'com.qa.r6nav' }; +const SOLO = { name: 'solo_settings', label: 'Solo Settings', icon: 'settings', hidden: true, _packageId: 'com.qa.solo' }; +const HIDDEN_FIRST = { name: 'lead_settings', label: 'Lead Settings', icon: 'settings', hidden: true, _packageId: 'com.qa.lead' }; +const AFTER_HIDDEN = { name: 'lead_app', label: 'Lead App', icon: 'folder', _packageId: 'com.qa.lead' }; + +beforeEach(() => { + navigate.mockClear(); + served.apps = [FIRST, HIDDEN, SOLO, HIDDEN_FIRST, AFTER_HIDDEN]; + vi.stubGlobal('fetch', vi.fn(() => Promise.resolve(new Response('{}', { status: 404 })))); +}); + +afterEach(() => { + vi.unstubAllGlobals(); +}); + +describe('AppHeader avatar menu — a hidden app opens itself (objectstack-ai/objectstack#29024)', () => { + it('a hidden app sharing its package with the first app opens on its own name', () => { + render(); + + screen.getByRole('button', { name: 'R6 Hidden App' }).click(); + + expect(navigate).toHaveBeenCalledTimes(1); + expect(navigate).toHaveBeenCalledWith('/apps/qsixn_hidden_app'); + }); + + it('a hidden app alone in its package keeps its package-id address', () => { + render(); + + screen.getByRole('button', { name: 'Solo Settings' }).click(); + + expect(navigate).toHaveBeenCalledWith('/apps/com.qa.solo'); + }); + + it('a hidden app that is its package\'s first app keeps its package-id address', () => { + render(); + + screen.getByRole('button', { name: 'Lead Settings' }).click(); + + expect(navigate).toHaveBeenCalledWith('/apps/com.qa.lead'); + }); + + it('lists hidden apps only: the visible apps are not avatar-menu entries', () => { + render(); + + expect(screen.queryByRole('button', { name: 'R6 App' })).toBeNull(); + expect(screen.queryByRole('button', { name: 'Lead App' })).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/layout/__tests__/AppSwitcher.packageAppAddress-29024.test.tsx b/ui/packages/app-shell/src/layout/__tests__/AppSwitcher.packageAppAddress-29024.test.tsx new file mode 100644 index 00000000000..b21116c6948 --- /dev/null +++ b/ui/packages/app-shell/src/layout/__tests__/AppSwitcher.packageAppAddress-29024.test.tsx @@ -0,0 +1,121 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack-ai/objectstack#29024 — an App Switcher row opens the app it + * names, a package's second app included. + * + * `/apps/PACKAGE_ID` resolves to the package's FIRST app, so a row keyed on the + * package id switched to that first app for every other app of the package. A + * row now hands `onAppChange` the app's one address (`appAddressSegment`) among + * the metadata app list: the package id where it resolves back to the app, + * else the app's name. That list holds hidden apps too, so a package whose + * first app is hidden addresses its visible second app by name. + * + * The menu harness is `AppSwitcher.launcherHiddenApps-26838.test.tsx`'s, + * without a `/me/apps` answer (no provider: every active app is offered). + */ + +import '@testing-library/jest-dom/vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { cleanup, render, screen, within } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; + +// Passthrough dropdown primitives so the menu CONTENT renders without an +// interaction — the same idiom as WorkspaceSwitcher.test.tsx. What is under +// measurement is which apps reach the list, not radix's open/close machinery. +vi.mock('@object-ui/components', async (importOriginal) => ({ + ...(await importOriginal>()), + DropdownMenu: (p: any) =>
{p.children}
, + DropdownMenuTrigger: (p: any) =>
{p.children}
, + // Scoped: the trigger renders the ACTIVE app's label too, so an unscoped + // `getByText` would match twice. Every assertion below reads the LIST. + DropdownMenuContent: (p: any) =>
{p.children}
, + DropdownMenuItem: ({ onClick, children }: any) =>
{children}
, + DropdownMenuLabel: (p: any) =>
, + DropdownMenuSeparator: () =>
, +})); +vi.mock('lucide-react', async (importOriginal) => ({ + ...(await importOriginal>()), + ChevronDown: () => , + Check: () => , +})); +// `getIcon` wraps lucide's DynamicIcon (a per-icon dynamic import); stub it so +// no unbounded module load races the assertions. +vi.mock('../../utils/getIcon', () => ({ getIcon: () => () => })); + +// Spread the real module rather than replacing it: other modules in this graph +// import further exports from it, and a bare factory would blank them out. +vi.mock('@object-ui/i18n', async () => { + const actual = await vi.importActual>('@object-ui/i18n'); + return { + ...actual, + useObjectTranslation: () => ({ + t: (key: string, o?: { defaultValue?: string }) => o?.defaultValue ?? key, + }), + useObjectLabel: () => ({ + appLabel: ({ name, label }: { name: string; label?: string }) => label ?? name, + }), + }; +}); + +// Keep the real route-segment matching (`appRouteSegment` / `matchAppBySegment`); +// only the keyed-i18n resolver is stubbed. +vi.mock('../../utils', async () => { + const appRoute = await vi.importActual('../../utils/appRoute'); + return { + ...appRoute, + resolveKeyedI18nLabel: (label: unknown) => (typeof label === 'string' ? label : undefined), + }; +}); + +let apps: Array> = []; +vi.mock('../../providers/MetadataProvider', () => ({ + useMetadata: () => ({ apps, loading: false }), +})); +vi.mock('@object-ui/auth', async (importOriginal) => ({ + ...(await importOriginal>()), + useAuth: () => ({ user: { id: 'u1' } }), +})); + +import { AppSwitcher } from '../AppSwitcher'; + +function renderSwitcher(onAppChange: (segment: string) => void) { + render( + + + , + ); + return within(screen.getByTestId('app-switcher-menu')); +} + +beforeEach(() => { + apps = [ + { name: 'crm', label: 'CRM' }, + { name: 'r6_app', label: 'R6 App', _packageId: 'com.qa.r6nav' }, + { name: 'r6_board', label: 'R6 Board', _packageId: 'com.qa.r6nav' }, + { name: 'lead_settings', label: 'Lead Settings', hidden: true, _packageId: 'com.qa.lead' }, + { name: 'lead_app', label: 'Lead App', _packageId: 'com.qa.lead' }, + ]; +}); + +afterEach(() => { + cleanup(); +}); + +describe('AppSwitcher rows open the app they name (objectstack-ai/objectstack#29024)', () => { + it('a package\'s second app is switched to by its name; the first keeps its package id', () => { + const onAppChange = vi.fn(); + const menu = renderSwitcher(onAppChange); + menu.getByText('R6 Board').click(); + menu.getByText('R6 App').click(); + expect(onAppChange.mock.calls).toEqual([['r6_board'], ['com.qa.r6nav']]); + }); + + it('a visible app behind its package\'s hidden first app is switched to by its name', () => { + const onAppChange = vi.fn(); + const menu = renderSwitcher(onAppChange); + expect(menu.queryByText('Lead Settings')).toBeNull(); + menu.getByText('Lead App').click(); + expect(onAppChange).toHaveBeenCalledWith('lead_app'); + }); +}); diff --git a/ui/packages/app-shell/src/views/AppReportIndexView.tsx b/ui/packages/app-shell/src/views/AppReportIndexView.tsx index d29ab14d20f..8e8c3b8666f 100644 --- a/ui/packages/app-shell/src/views/AppReportIndexView.tsx +++ b/ui/packages/app-shell/src/views/AppReportIndexView.tsx @@ -39,7 +39,8 @@ import { Empty, EmptyTitle, EmptyDescription, Input, cn } from '@object-ui/compo import { useDisplayLocale, useObjectLabel, useObjectTranslation } from '@object-ui/i18n'; import { useMetadata } from '../providers/MetadataProvider.js'; import { useLauncherApps } from '../hooks/useLauncherApps.js'; -import { appRouteSegment, resolveKeyedI18nLabel } from '../utils/index.js'; +import { resolveKeyedI18nLabel } from '../utils/index.js'; +import { appAddressSegment } from '../utils/appRoute.js'; import { useExpressionContext } from '../providers/ExpressionProvider.js'; import { useNavMemberGates } from '../hooks/useNavMemberGates.js'; import { useRecentItems } from '../context/RecentItemsProvider.js'; @@ -196,7 +197,7 @@ export function AppReportIndexView() { {otherApps.map((other) => (
  • diff --git a/ui/packages/app-shell/src/views/__tests__/AppReportIndex.otherAppsAddress-29024.test.tsx b/ui/packages/app-shell/src/views/__tests__/AppReportIndex.otherAppsAddress-29024.test.tsx new file mode 100644 index 00000000000..95f422f7cd5 --- /dev/null +++ b/ui/packages/app-shell/src/views/__tests__/AppReportIndex.otherAppsAddress-29024.test.tsx @@ -0,0 +1,113 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack-ai/objectstack#29024 — the empty report index's "Reports in your + * other apps" links open the app they name, a package's second app included. + * + * `/apps/PACKAGE_ID` resolves to the package's FIRST app, so a link keyed on + * the package id opened CRM for "CRM Service". Each link now carries the app's + * one address (`appAddressSegment`): the package id where it resolves back to + * the app, else the app's name. + * + * The harness is `AppReportIndex.otherApps-27356.test.tsx`'s, with a second + * app in CRM's package. + */ + +import '@testing-library/jest-dom/vitest'; +import * as React from 'react'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { render, screen, cleanup, within } from '@testing-library/react'; +import { MemoryRouter, Route, Routes } from 'react-router-dom'; +import { createI18n, I18nProvider } from '@object-ui/i18n'; +import { MePermissionsProvider, type MePermissionsAuthenticatedResponse } from '@object-ui/permissions'; + +vi.mock('@object-ui/auth', async (importOriginal) => ({ + ...(await importOriginal>()), + useAuth: () => ({ user: { id: 'u_admin' }, activeOrganization: null }), +})); + +import { MetadataProvider } from '../../providers/MetadataProvider'; +import { ExpressionProvider } from '../../providers/ExpressionProvider'; +import { AppReportIndexView } from '../AppReportIndexView'; + +const SETUP_APP = { name: 'setup', label: 'Setup', active: true, _packageId: 'com.objectstack.setup', navigation: [] }; +const CRM_APP = { name: 'crm', label: 'CRM', active: true, _packageId: 'com.example.crm', navigation: [] }; +const HR_APP = { name: 'hr', label: 'People', active: true, _packageId: 'com.example.hr', navigation: [] }; +// The package's second app: its package id opens CRM, the package's first. +const CRM_SERVICE_APP = { name: 'crm_service', label: 'CRM Service', active: true, _packageId: 'com.example.crm', navigation: [] }; + +const REPORTS = [ + { name: 'crm_win_rate', label: 'Win Rate', dataset: 'ds_accounts', _packageId: 'com.example.crm' }, + { name: 'hr_salaries', label: 'Salaries', dataset: 'ds_salaries', _packageId: 'com.example.hr' }, +]; + +const DATASETS = [ + { name: 'ds_accounts', object: 'crm_account' }, + { name: 'ds_salaries', object: 'hr_salary' }, +]; + +const ANSWER: MePermissionsAuthenticatedResponse = { + authenticated: true, + userId: 'u_admin', + tenantId: null, + positions: [], + hasAnyQueue: false, + permissionSets: ['admin'], + systemPermissions: [], + objects: { + crm_account: { allowRead: true }, + hr_salary: { allowRead: false }, + }, + fields: {}, +}; + +function adapterFor(apps: unknown[]) { + const items: Record = { app: apps, report: REPORTS, dataset: DATASETS }; + return { + clearCache: vi.fn(), + getObjectSchema: () => Promise.resolve(null), + getClient: () => ({ + meta: { + getItems: (type: string) => Promise.resolve({ type, items: items[type] ?? [] }), + getItem: () => Promise.resolve({ item: null }), + }, + }), + } as unknown as Parameters[0]['adapter']; +} + +function renderIndex(current: any) { + const fetcher = vi.fn(async () => ({ ok: true, status: 200, json: async () => ANSWER }) as unknown as Response); + render( + + + + + + + } /> + + + + + + , + ); +} + +beforeEach(() => { + cleanup(); + localStorage.clear(); + sessionStorage.clear(); +}); + +describe('the other-apps links open the app they name (objectstack-ai/objectstack#29024)', () => { + it('a package\'s second app links by its name; the first keeps the package id', async () => { + renderIndex(SETUP_APP); + const nav = await screen.findByTestId('report-index-other-apps'); + const links = within(nav).getAllByRole('link'); + expect(links.map((a) => [a.textContent, a.getAttribute('href')])).toEqual([ + ['CRM', '/apps/com.example.crm/reports'], + ['CRM Service', '/apps/crm_service/reports'], + ]); + }); +}); diff --git a/ui/packages/app-shell/src/views/app-launcher-renderer.tsx b/ui/packages/app-shell/src/views/app-launcher-renderer.tsx index 2e90735f84d..1db2de09221 100644 --- a/ui/packages/app-shell/src/views/app-launcher-renderer.tsx +++ b/ui/packages/app-shell/src/views/app-launcher-renderer.tsx @@ -127,6 +127,7 @@ export const AppLauncherRenderer: React.FC = ({ >