Repository navigation
Show source scan notices accurately in mobile Agent History #24772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nwparker
wants to merge
2
commits into
main
Choose a base branch
from
nwparker/fix-mobile-history-scan-notices-15671
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
mobile/src/agent-history/agent-history-notice-scroll.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| import type { ReactElement } from 'react' | ||
| import { act, create, type ReactTestRenderer } from 'react-test-renderer' | ||
| import { afterEach, beforeEach, expect, it, vi } from 'vitest' | ||
| import type { AiVaultScanIssue, AiVaultSession } from '../../../src/shared/ai-vault-types' | ||
|
|
||
| const state = vi.hoisted(() => { | ||
| const sessions: AiVaultSession[] = [] | ||
| const issues: AiVaultScanIssue[] = [] | ||
| return { sessions, issues, refresh: vi.fn(() => Promise.resolve()) } | ||
| }) | ||
|
|
||
| vi.mock('react-native', async () => { | ||
| const { createElement, cloneElement } = await import('react') | ||
| return { | ||
| ActivityIndicator: 'ActivityIndicator', | ||
| Pressable: 'Pressable', | ||
| RefreshControl: 'RefreshControl', | ||
| Text: 'Text', | ||
| TextInput: 'TextInput', | ||
| View: 'View', | ||
| StyleSheet: { create: (value: unknown) => value }, | ||
| SectionList: ({ | ||
| sections, | ||
| ListHeaderComponent, | ||
| ListEmptyComponent, | ||
| renderItem, | ||
| ...props | ||
| }: { | ||
| sections: { data: unknown[] }[] | ||
| ListHeaderComponent?: ReactElement | ||
| ListEmptyComponent?: ReactElement | ||
| renderItem: (args: { item: unknown }) => ReactElement | ||
| }) => | ||
| createElement( | ||
| 'SectionList', | ||
| { ...props, sections }, | ||
| ListHeaderComponent, | ||
| sections.length === 0 | ||
| ? ListEmptyComponent | ||
| : sections.flatMap((section, group) => | ||
| section.data.map((item, index) => | ||
| cloneElement(renderItem({ item }), { key: `${group}:${index}` }) | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
| }) | ||
| vi.mock('react-native-safe-area-context', () => ({ SafeAreaView: 'SafeAreaView' })) | ||
| vi.mock('lucide-react-native', () => ({ ChevronLeft: 'Icon', Play: 'Icon', RefreshCw: 'Icon' })) | ||
| vi.mock('../components/MobileAgentIcon', () => ({ MobileAgentIcon: () => null })) | ||
| vi.mock('../navigation/route-handoff', () => ({ | ||
| useRouteHandoff: () => ({ back: vi.fn(), push: vi.fn() }) | ||
| })) | ||
| vi.mock('../transport/client-context', () => ({ | ||
| useHostClient: () => ({ client: null, state: 'disconnected' }) | ||
| })) | ||
| vi.mock('../platform/haptics', () => ({ triggerError: vi.fn(), triggerSuccess: vi.fn() })) | ||
| vi.mock('../hooks/use-now', () => ({ useNow: () => Date.parse('2026-10-02T00:00:00Z') })) | ||
| vi.mock('./use-mobile-agent-history-state', () => ({ | ||
| useMobileAgentHistoryState: () => ({ | ||
| scope: 'all', | ||
| screenState: { kind: 'ready', sessions: state.sessions, issues: state.issues }, | ||
| refreshing: false, | ||
| hostStatusResult: null, | ||
| activeWorktreePath: null, | ||
| scopeFilterPaths: [], | ||
| onSelectScope: vi.fn(), | ||
| onRefresh: state.refresh, | ||
| retry: null | ||
| }) | ||
| })) | ||
|
|
||
| import { MobileAgentSessionHistoryPanel } from './MobileAgentSessionHistoryPanel' | ||
| import { styles } from './agent-history-styles' | ||
|
|
||
| let tree: ReactTestRenderer | undefined | ||
|
|
||
| beforeEach(() => { | ||
| state.sessions = [] | ||
| state.issues = Array.from({ length: 500 }, (_, index) => ({ | ||
| agent: 'opencode2', | ||
| kind: 'scope', | ||
| executionHostId: 'ssh:history-host', | ||
| path: `/history/source-${index}/opencode.db`, | ||
| message: `Source ${index} unavailable. Refresh to try again.` | ||
| })) | ||
| state.refresh.mockClear() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| act(() => tree?.unmount()) | ||
| tree = undefined | ||
| }) | ||
|
|
||
| function mount() { | ||
| act(() => { | ||
| tree = create(<MobileAgentSessionHistoryPanel hostId="history-host" worktreeId="folder:test" />) | ||
| }) | ||
| if (!tree) { | ||
| throw new Error('History panel did not mount') | ||
| } | ||
| return tree.root | ||
| } | ||
|
|
||
| function visibleSession(): AiVaultSession { | ||
| return { | ||
| id: 'local:opencode2:session', | ||
| executionHostId: 'local', | ||
| agent: 'opencode2', | ||
| sessionId: 'session', | ||
| title: 'Existing history remains browsable', | ||
| cwd: '/history/project', | ||
| branch: null, | ||
| model: null, | ||
| filePath: '/history/opencode.db', | ||
| codexHome: null, | ||
| createdAt: null, | ||
| updatedAt: null, | ||
| modifiedAt: '2026-10-01T00:00:00Z', | ||
| messageCount: 2, | ||
| totalTokens: 0, | ||
| previewMessages: [], | ||
| queuedMessageCount: 0, | ||
| subagentTranscriptCount: 0, | ||
| resumeCommand: '', | ||
| subagent: null | ||
| } | ||
| } | ||
|
|
||
| it('keeps every source notice and session inside the same bounded scroll viewport', () => { | ||
| state.sessions = [visibleSession()] | ||
| const root = mount() | ||
| const list = root.find((node) => String(node.type) === 'SectionList') | ||
| const notice = (node: { props: { children?: unknown } }) => | ||
| typeof node.props.children === 'string' && node.props.children.startsWith('Source ') | ||
|
|
||
| expect(root.findAll(notice)).toHaveLength(500) | ||
| expect(list.findAll(notice)).toHaveLength(500) | ||
| expect(list.findAll((node) => node.props.children === state.sessions[0]?.title)).toHaveLength(1) | ||
| expect(list.props.style).toEqual(styles.listViewport) | ||
| expect( | ||
| list.findAll((node) => node.props.accessibilityLabel === 'Refresh agent sessions') | ||
| ).toEqual([]) | ||
| expect(list.findAll((node) => String(node.type) === 'TextInput')).toEqual([]) | ||
|
|
||
| const refresh = root.find((node) => node.props.accessibilityLabel === 'Refresh agent sessions') | ||
| act(() => refresh.props.onPress()) | ||
| expect(state.refresh).toHaveBeenCalledOnce() | ||
| }) | ||
|
|
||
| it('keeps the empty state and pull-to-refresh reachable below a long notice list', () => { | ||
| const root = mount() | ||
| const list = root.find((node) => String(node.type) === 'SectionList') | ||
|
|
||
| expect(list.props.contentContainerStyle).toContain(styles.emptyList) | ||
| expect(list.findAll((node) => node.props.children === 'No agent sessions')).toHaveLength(1) | ||
| expect(list.findAll((node) => node.props.children === state.issues.at(-1)?.message)).toHaveLength( | ||
| 1 | ||
| ) | ||
| act(() => list.props.refreshControl.props.onRefresh()) | ||
| expect(state.refresh).toHaveBeenCalledOnce() | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issuesis parsed with a plainz.array(...), so a single row missingagent/pathor carrying a non-stringmessagefails the wholeagentHistorySessionScanSchema.agentHistorySessionScanusesrequire-result-or-throw-message, so that failure throws anduse-mobile-agent-history-state.ts:138-144replaces the entire screen with{ kind: 'error' }, discarding every readable session because one issue row was malformed.Session rows deliberately stay
z.unknown()for exactly this forward-compat reason, so the issue array should salvage per-row instead. This requires addingsalvagingArrayto the../../../src/shared/zod-salvageimport.Technical details