diff --git a/mobile/app/index.tsx b/mobile/app/index.tsx index 8a4a774b6..7670fec82 100644 --- a/mobile/app/index.tsx +++ b/mobile/app/index.tsx @@ -50,6 +50,7 @@ import { type TaskProvider } from '../src/tasks/mobile-task-providers' import { useResponsiveLayout } from '../src/layout/responsive-layout' +import { createMobileSessionHref } from '../src/session/mobile-session-route' function endpointLabel(endpoint: string): string { try { @@ -807,7 +808,11 @@ export default function HomeScreen() { style={({ pressed }) => [styles.resumeCard, pressed && styles.hostCardPressed]} onPress={() => router.push( - `/h/${resumeWorktree.hostId}/session/${encodeURIComponent(resumeWorktree.worktree.worktreeId)}` + createMobileSessionHref({ + hostId: resumeWorktree.hostId, + worktreeId: resumeWorktree.worktree.worktreeId, + name: resumeWorktree.worktree.displayName || resumeWorktree.worktree.repo + }) ) } > diff --git a/mobile/src/session/mobile-session-route.test.ts b/mobile/src/session/mobile-session-route.test.ts new file mode 100644 index 000000000..79b0c1264 --- /dev/null +++ b/mobile/src/session/mobile-session-route.test.ts @@ -0,0 +1,35 @@ +import { readFileSync } from 'node:fs' +import { describe, expect, it } from 'vitest' +import { createMobileSessionHref } from './mobile-session-route' + +const homeSource = readFileSync(new URL('../../app/index.tsx', import.meta.url), 'utf8') + +describe('mobile session route', () => { + it('keeps dynamic route identities raw for Expo Router to encode', () => { + expect( + createMobileSessionHref({ + hostId: 'host/one', + worktreeId: 'repo::/Users/ada/orca/workspaces/fix #1', + name: 'Fix #1' + }) + ).toEqual({ + pathname: '/h/[hostId]/session/[worktreeId]', + params: { + hostId: 'host/one', + worktreeId: 'repo::/Users/ada/orca/workspaces/fix #1', + name: 'Fix #1' + } + }) + }) + + it('routes the home Resume card through the typed dynamic href', () => { + const start = homeSource.indexOf('{/* ─── Resume card ─── */}') + const end = homeSource.indexOf('{/* ─── Quick actions ─── */}', start) + const resumeCard = homeSource.slice(start, end) + + expect(start).toBeGreaterThanOrEqual(0) + expect(end).toBeGreaterThan(start) + expect(resumeCard).toContain('createMobileSessionHref({') + expect(resumeCard).not.toContain('encodeURIComponent(resumeWorktree.worktree.worktreeId)') + }) +}) diff --git a/mobile/src/session/mobile-session-route.ts b/mobile/src/session/mobile-session-route.ts new file mode 100644 index 000000000..505e53bfb --- /dev/null +++ b/mobile/src/session/mobile-session-route.ts @@ -0,0 +1,17 @@ +export type MobileSessionRouteParams = { + hostId: string + worktreeId: string + name?: string +} + +export type MobileSessionHref = { + pathname: '/h/[hostId]/session/[worktreeId]' + params: MobileSessionRouteParams +} + +export function createMobileSessionHref(params: MobileSessionRouteParams): MobileSessionHref { + return { + pathname: '/h/[hostId]/session/[worktreeId]', + params + } +}