fix(e2e): stop the login page requesting linked servers and update the background-activity test

This commit is contained in:
Chris Scott committed 2026-10-20 23:04:26 -04:00
1 parent 052f2bbe04
commit 884233d95c
5 files changed
+44 -11

No files matched your search

+6 -2
View File
@@ -149,6 +149,11 @@ function GlobalShortcuts() {
return null
}
function SidebarServerRouteSync() {
useSidebarServerRouteSync()
return null
}
function ServerScope({ children }: { children: ReactNode }) {
const { serverId } = useParams<{ serverId: string }>()
@@ -165,8 +170,6 @@ function AppShell() {
const rootRef = useRef<HTMLDivElement>(null)
const { openSheet, open } = useMobileTabBar()
useSidebarServerRouteSync()
const swipeNav = useSwipeNavigation()
const getRouteSwipeBackTarget = useCallback(
@@ -236,6 +239,7 @@ function AppShell() {
<RepoWorktreesProvider>
<KeyboardShortcutsProvider>
<GlobalShortcuts />
<SidebarServerRouteSync />
<div className="flex h-dvh w-full min-w-0 flex-col">
<PwaUpdatePrompt />
<div ref={rootRef} className="flex flex-1 min-h-0 w-full min-w-0">
@@ -12,6 +12,7 @@ const mocks = vi.hoisted(() => ({
useOpenCodeServerStatuses: vi.fn(),
useServerActivityState: vi.fn(),
useLocalActivityState: vi.fn(),
useAuth: vi.fn(),
}))
vi.mock('@/hooks/useOpenCodeServers', () => ({
@@ -19,6 +20,10 @@ vi.mock('@/hooks/useOpenCodeServers', () => ({
useOpenCodeServerStatuses: mocks.useOpenCodeServerStatuses,
}))
vi.mock('@/hooks/useAuth', () => ({
useAuth: mocks.useAuth,
}))
vi.mock('@/hooks/useActiveWork', () => ({
useServerActivityState: mocks.useServerActivityState,
useLocalActivityState: mocks.useLocalActivityState,
@@ -71,6 +76,7 @@ describe('LinkedServersNav', () => {
localStorage.clear()
useSidebarServerStore.setState({ serverId: LOCAL_OPENCODE_SERVER_ID })
setServers([])
mocks.useAuth.mockReturnValue({ isAuthenticated: true })
mocks.useServerActivityState.mockReturnValue(null)
mocks.useLocalActivityState.mockReturnValue(null)
mocks.useOpenCodeServerStatuses.mockReturnValue({
@@ -7,6 +7,7 @@ import { SIDEBAR_SERVER_STORAGE_KEY, useSidebarServerStore } from '@/stores/side
const mocks = vi.hoisted(() => ({
useOpenCodeServers: vi.fn(),
useAuth: vi.fn(),
}))
vi.mock('@/hooks/useOpenCodeServers', () => ({
@@ -14,6 +15,10 @@ vi.mock('@/hooks/useOpenCodeServers', () => ({
useOpenCodeServerStatuses: () => ({ statuses: [], statusById: {}, isLoading: false }),
}))
vi.mock('@/hooks/useAuth', () => ({
useAuth: mocks.useAuth,
}))
const kitchen = {
id: 'srv_kitchen',
name: 'Kitchen',
@@ -85,6 +90,7 @@ function renderHarness(initialEntry = '/', options?: { syncRoute?: boolean }) {
function resetSelection() {
localStorage.clear()
useSidebarServerStore.setState({ serverId: LOCAL_OPENCODE_SERVER_ID })
mocks.useAuth.mockReturnValue({ isAuthenticated: true })
mocks.useOpenCodeServers.mockReturnValue({
servers: [kitchen, office],
isLoading: false,
@@ -215,6 +221,14 @@ describe('useSidebarServerRouteSync', () => {
)
})
it('does not load the server list while unauthenticated', () => {
mocks.useAuth.mockReturnValue({ isAuthenticated: false })
renderHarness('/')
expect(mocks.useOpenCodeServers).toHaveBeenCalledWith({ enabled: false })
})
it('follows a linked server route with no sidebar consumer mounted', async () => {
render(
<MemoryRouter initialEntries={['/']}>
@@ -1,6 +1,7 @@
import { useEffect } from 'react'
import { useLocation, useMatch } from 'react-router-dom'
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
import { useAuth } from '@/hooks/useAuth'
import { useOpenCodeServers } from '@/hooks/useOpenCodeServers'
import { isAssistantPath, parseRepoRoute } from '@/lib/navigation'
import { useSidebarServerStore } from '@/stores/sidebarServerStore'
@@ -13,12 +14,14 @@ function isLocalRoute(pathname: string): boolean {
* Keeps the sidebar server selection in step with the location and the linked server list: a linked
* server route selects that server, a local repo or assistant route selects local, and a selected
* server that is missing or disabled in a successfully loaded list falls back to local. Mounted once
* by the app shell so the selection follows the route even when no sidebar consumer is rendered.
* inside `AuthProvider` by the app shell so the selection follows the route even when no sidebar
* consumer is rendered; the server list is only loaded once authenticated.
*/
export function useSidebarServerRouteSync(): void {
const { pathname } = useLocation()
const routeServerId = useMatch('/servers/:serverId/*')?.params.serverId
const { servers, isSuccess } = useOpenCodeServers()
const { isAuthenticated } = useAuth()
const { servers, isSuccess } = useOpenCodeServers({ enabled: isAuthenticated })
const serverId = useSidebarServerStore((state) => state.serverId)
const selectServer = useSidebarServerStore((state) => state.selectServer)