mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 11:54:46 +00:00
Repair mobile project grouping verification
This commit is contained in:
@@ -31,6 +31,7 @@ on:
|
||||
- 'config/scripts/run-mobile-ci-tests.mjs'
|
||||
# Mobile typechecks run through the root compiler selection.
|
||||
- 'config/scripts/run-typecheck-projects-in-parallel.mjs'
|
||||
- 'config/tsconfig.test.mobile-project-controls.json'
|
||||
- 'config/scripts/tsrs-typecheck-compiler.mjs'
|
||||
- 'config/scripts/pinned-bun-executable.mjs'
|
||||
- 'config/oxlint-code-quality-native-plugins.json'
|
||||
@@ -77,6 +78,7 @@ on:
|
||||
- 'config/mobile-ci.vitest.config.mjs'
|
||||
- 'config/scripts/run-mobile-ci-tests.mjs'
|
||||
- 'config/scripts/run-typecheck-projects-in-parallel.mjs'
|
||||
- 'config/tsconfig.test.mobile-project-controls.json'
|
||||
- 'config/scripts/tsrs-typecheck-compiler.mjs'
|
||||
- 'config/scripts/pinned-bun-executable.mjs'
|
||||
- 'config/.bun-version'
|
||||
@@ -192,7 +194,7 @@ jobs:
|
||||
- name: Typecheck
|
||||
id: production-types
|
||||
background: true
|
||||
run: node ../config/scripts/run-typecheck-projects-in-parallel.mjs --compiler=bun --bun-threads=2 --project=mobile/tsconfig.json
|
||||
run: node ../config/scripts/run-typecheck-projects-in-parallel.mjs --compiler=bun --bun-threads=2 --project=mobile/tsconfig.json --project=config/tsconfig.test.mobile-project-controls.json
|
||||
|
||||
# Why a ratchet and not the raw typecheck: mobile/tsconfig.json excludes test files, so until
|
||||
# tsconfig.test.json existed nothing checked them, and at introduction 127 of the 632 had
|
||||
@@ -340,7 +342,7 @@ jobs:
|
||||
- name: Typecheck
|
||||
id: production-types
|
||||
background: true
|
||||
run: node ../config/scripts/run-typecheck-projects-in-parallel.mjs --compiler=bun --bun-threads=2 --project=mobile/tsconfig.json
|
||||
run: node ../config/scripts/run-typecheck-projects-in-parallel.mjs --compiler=bun --bun-threads=2 --project=mobile/tsconfig.json --project=config/tsconfig.test.mobile-project-controls.json
|
||||
|
||||
- name: Typecheck tests (ratchet)
|
||||
id: test-types
|
||||
|
||||
@@ -3,6 +3,8 @@ import original from '../mobile/vitest.config.ts'
|
||||
|
||||
// Keep real process, native, and runtime-specific contracts on Node.
|
||||
const nodeFiles = [
|
||||
'src/mobile-web-shell/mobile-web-shell-project-controls.test.ts',
|
||||
'src/mobile-web-shell/mobile-web-shell-nested-project-filter.test.ts',
|
||||
'src/components/WorktreeAgentList.runtime-lineage.test.tsx',
|
||||
'scripts/check-tests-typecheck-incremental-cache.test.ts',
|
||||
'src/tasks/mobile-agent-launch-architecture.test.ts',
|
||||
|
||||
@@ -23,7 +23,8 @@ export const TYPECHECK_PROJECTS = [
|
||||
// Selected only by --project: mobile is a separate install that root checks cannot assume.
|
||||
export const MOBILE_TYPECHECK_PROJECTS = [
|
||||
{ config: 'mobile/tsconfig.json', heapGib: 2 },
|
||||
{ config: 'mobile/tsconfig.test.json', heapGib: 3 }
|
||||
{ config: 'mobile/tsconfig.test.json', heapGib: 3 },
|
||||
{ config: 'config/tsconfig.test.mobile-project-controls.json', heapGib: 7 }
|
||||
]
|
||||
|
||||
// The OS, node itself, and the runner agent need their share; the rest is what tsc may hold.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"extends": ["../mobile/tsconfig.json", "./tsconfig.test.pane-launch.json"],
|
||||
"include": [
|
||||
"../mobile/src/mobile-web-shell/mobile-web-shell-project-controls.test.ts",
|
||||
"../mobile/src/mobile-web-shell/mobile-web-shell-nested-project-filter.test.ts",
|
||||
"../src/renderer/src/env.d.ts",
|
||||
"../src/types/**/*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"@renderer/*": ["../src/renderer/src/*"],
|
||||
"@/*": ["../src/renderer/src/*"],
|
||||
"@noble/hashes/*": ["../mobile/node_modules/@noble/hashes/*"],
|
||||
"tweetnacl": ["../mobile/node_modules/tweetnacl"],
|
||||
"ws": ["../mobile/node_modules/@types/ws"],
|
||||
"zod": ["../mobile/node_modules/zod"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,14 @@ const ERROR_LINE = /^(\S.*?)\(\d+,\d+\): error TS\d+:/
|
||||
|
||||
// Require every on-disk test in program except these explicit exclusions: error-only diff cannot see excluded/shadowed tests.
|
||||
export const TESTS_OUTSIDE_PROGRAM = new Map([
|
||||
[
|
||||
'src/mobile-web-shell/mobile-web-shell-project-controls.test.ts',
|
||||
'Node-side: real persistence/socket/bridge joins; checked by config/tsconfig.test.mobile-project-controls.json after both installs and executed by the Mobile CI Node role'
|
||||
],
|
||||
[
|
||||
'src/mobile-web-shell/mobile-web-shell-nested-project-filter.test.ts',
|
||||
'Node-side: normal publisher/persistence/socket join; checked by config/tsconfig.test.mobile-project-controls.json after both installs and executed by the Mobile CI Node role'
|
||||
],
|
||||
[
|
||||
'src/worktree/project-sections-owner-recovery.test.ts',
|
||||
'Node-side: imports the desktop runtime and RPC handlers; checked by config/tsconfig.node.json against Node libraries'
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createElement, useEffect, type ComponentProps } from 'react'
|
||||
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { RpcClient } from '../transport/rpc-client'
|
||||
import { FakeSession } from '../transport/mobile-endpoint-supervisor-test-fakes'
|
||||
import { HostProtocolGate } from './HostProtocolGate'
|
||||
import { useHostProtocolGates } from './host-protocol-gates-context'
|
||||
import { findAllByHostType } from '../test-support/react-test-renderer-host-nodes'
|
||||
@@ -11,7 +12,20 @@ const nativeTestState = vi.hoisted(() => ({
|
||||
platform: { OS: 'ios' as 'ios' | 'android' }
|
||||
}))
|
||||
|
||||
const appStateListeners = vi.hoisted(() => new Set<(state: string) => void>())
|
||||
|
||||
vi.mock('react-native', () => ({
|
||||
AppState: {
|
||||
currentState: 'active',
|
||||
addEventListener: (_type: string, listener: (state: string) => void) => {
|
||||
appStateListeners.add(listener)
|
||||
return {
|
||||
remove: () => {
|
||||
appStateListeners.delete(listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ActivityIndicator: 'ActivityIndicator',
|
||||
Linking: { openURL: nativeTestState.openUrl },
|
||||
Platform: nativeTestState.platform,
|
||||
@@ -44,8 +58,16 @@ vi.mock('../transport/host-descriptor-recorder', () => ({
|
||||
recordHostDescriptorFromStatus: vi.fn()
|
||||
}))
|
||||
|
||||
function clientWithStatus(result: Record<string, unknown>): RpcClient {
|
||||
return { sendRequest: vi.fn().mockResolvedValue({ ok: true, result }) } as unknown as RpcClient
|
||||
function withLifecycle(overrides: Pick<RpcClient, 'sendRequest'>): FakeSession {
|
||||
return Object.assign(new FakeSession('connected'), overrides)
|
||||
}
|
||||
|
||||
function clientWithStatus(result: Record<string, unknown>): FakeSession {
|
||||
return withLifecycle({
|
||||
sendRequest: vi
|
||||
.fn<RpcClient['sendRequest']>()
|
||||
.mockResolvedValue({ id: 'status', ok: true, result })
|
||||
})
|
||||
}
|
||||
|
||||
function GateConsumer() {
|
||||
@@ -100,6 +122,7 @@ describe('HostProtocolGate', () => {
|
||||
afterEach(() => {
|
||||
act(() => renderer?.unmount())
|
||||
renderer = null
|
||||
expect(appStateListeners.size).toBe(0)
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
@@ -176,9 +199,9 @@ describe('HostProtocolGate', () => {
|
||||
})
|
||||
|
||||
it('does not mount host routes before a connected host passes the compatibility probe', async () => {
|
||||
const client = {
|
||||
sendRequest: vi.fn().mockReturnValue(new Promise(() => {}))
|
||||
} as unknown as RpcClient
|
||||
const client = withLifecycle({
|
||||
sendRequest: vi.fn<RpcClient['sendRequest']>().mockReturnValue(new Promise(() => {}))
|
||||
})
|
||||
hostClient.current = { client, state: 'connected' }
|
||||
renderer = await renderGate()
|
||||
const output = renderedText(renderer)
|
||||
@@ -194,9 +217,9 @@ describe('HostProtocolGate', () => {
|
||||
expect(renderedText(renderer)).toContain('HostContent')
|
||||
expect(probeMounts.count).toBe(1)
|
||||
|
||||
const client = {
|
||||
sendRequest: vi.fn().mockReturnValue(new Promise(() => {}))
|
||||
} as unknown as RpcClient
|
||||
const client = withLifecycle({
|
||||
sendRequest: vi.fn<RpcClient['sendRequest']>().mockReturnValue(new Promise(() => {}))
|
||||
})
|
||||
await act(async () => {
|
||||
hostClient.current = { client, state: 'connected' }
|
||||
renderer?.update(gateElement())
|
||||
@@ -235,24 +258,27 @@ describe('HostProtocolGate', () => {
|
||||
})
|
||||
|
||||
it('keeps an already-validated host route mounted while reconnect status is pending', async () => {
|
||||
const client = {
|
||||
const client = withLifecycle({
|
||||
sendRequest: vi
|
||||
.fn()
|
||||
.fn<RpcClient['sendRequest']>()
|
||||
.mockResolvedValueOnce({
|
||||
id: 'status',
|
||||
ok: true,
|
||||
result: { protocolVersion: 5, minCompatibleMobileVersion: 0 }
|
||||
})
|
||||
.mockReturnValueOnce(new Promise(() => {}))
|
||||
} as unknown as RpcClient
|
||||
})
|
||||
hostClient.current = { client, state: 'connected' }
|
||||
renderer = await renderGate()
|
||||
|
||||
await act(async () => {
|
||||
hostClient.current = { client, state: 'disconnected' }
|
||||
client.publishState('disconnected')
|
||||
renderer?.update(gateElement())
|
||||
})
|
||||
await act(async () => {
|
||||
hostClient.current = { client, state: 'connected' }
|
||||
client.publishState('connected')
|
||||
renderer?.update(gateElement())
|
||||
await Promise.resolve()
|
||||
})
|
||||
@@ -266,9 +292,13 @@ describe('HostProtocolGate', () => {
|
||||
|
||||
it('fails open when a connected host cannot answer the status probe', async () => {
|
||||
hostClient.current = {
|
||||
client: {
|
||||
sendRequest: vi.fn().mockResolvedValue({ ok: false, error: { message: 'unavailable' } })
|
||||
} as unknown as RpcClient,
|
||||
client: withLifecycle({
|
||||
sendRequest: vi.fn<RpcClient['sendRequest']>().mockResolvedValue({
|
||||
id: 'status',
|
||||
ok: false,
|
||||
error: { code: 'unavailable', message: 'unavailable' }
|
||||
})
|
||||
}),
|
||||
state: 'connected'
|
||||
}
|
||||
renderer = await renderGate()
|
||||
|
||||
@@ -93,6 +93,8 @@ vi.mock('./BottomDrawer', () => ({
|
||||
vi.mock('./bottom-drawer-modal-host', () => ({
|
||||
BottomDrawerModalHost: ({ children }: { children: ReactNode }) => children
|
||||
}))
|
||||
vi.mock('./AutoHeight', () => ({ AutoHeight: 'AutoHeight' }))
|
||||
vi.mock('./MobileSwitch', () => ({ MobileSwitch: 'MobileSwitch' }))
|
||||
vi.mock('./MobileAgentIcon', () => ({ MobileAgentIcon: 'MobileAgentIcon' }))
|
||||
vi.mock('./TaskProviderLogo', () => ({ TaskProviderLogo: 'TaskProviderLogo' }))
|
||||
vi.mock('expo-router', () => ({
|
||||
|
||||
@@ -2,8 +2,20 @@ import { createElement } from 'react'
|
||||
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const appStateListeners = vi.hoisted(() => new Set<(state: string) => void>())
|
||||
|
||||
vi.mock('react-native', () => ({
|
||||
AppState: { currentState: 'active' },
|
||||
AppState: {
|
||||
currentState: 'active',
|
||||
addEventListener: (_type: string, listener: (state: string) => void) => {
|
||||
appStateListeners.add(listener)
|
||||
return {
|
||||
remove: () => {
|
||||
appStateListeners.delete(listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Linking: { openURL: vi.fn() },
|
||||
Platform: { OS: 'ios', select: (options: { ios?: unknown }) => options.ios },
|
||||
Pressable: 'Pressable',
|
||||
@@ -36,6 +48,7 @@ let renderer: ReactTestRenderer | null = null
|
||||
afterEach(() => {
|
||||
act(() => renderer?.unmount())
|
||||
renderer = null
|
||||
expect(appStateListeners.size).toBe(0)
|
||||
})
|
||||
|
||||
async function renderSheet(row: Partial<Worktree>) {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Released raw Project page; unchanged source slice for mixed-page contract tests.
|
||||
// Released raw Project selection logic with current list presentation for mixed-page contracts.
|
||||
import { useState } from 'react'
|
||||
import { View } from 'react-native'
|
||||
import { MobileSearchField } from '../components/MobileSearchField'
|
||||
import { useMobileColorScheme } from '../theme/use-mobile-color-scheme'
|
||||
import { hostScreenStyles as styles } from './host-screen-styles'
|
||||
import { CheckRow, OptionRowList } from './workspace-option-rows'
|
||||
import { CheckRow } from './workspace-option-rows'
|
||||
import { ListGroup } from '../components/list/ListGroup'
|
||||
import { useMobileTranslation } from '../i18n/use-mobile-translation'
|
||||
import type { WorkspaceOptionProps } from './workspace-option-controls'
|
||||
export function ProjectsPage({ controller }: WorkspaceOptionProps) {
|
||||
@@ -18,7 +19,7 @@ export function ProjectsPage({ controller }: WorkspaceOptionProps) {
|
||||
(repo) => !needle || repo.name.toLowerCase().includes(needle)
|
||||
)
|
||||
return (
|
||||
<View style={styles.filterGroup}>
|
||||
<View style={styles.optionGroup}>
|
||||
<View style={styles.optionSearch}>
|
||||
<MobileSearchField
|
||||
value={query}
|
||||
@@ -33,7 +34,7 @@ export function ProjectsPage({ controller }: WorkspaceOptionProps) {
|
||||
)}
|
||||
/>
|
||||
</View>
|
||||
<OptionRowList>
|
||||
<ListGroup>
|
||||
{[
|
||||
<CheckRow
|
||||
key="all"
|
||||
@@ -51,7 +52,7 @@ export function ProjectsPage({ controller }: WorkspaceOptionProps) {
|
||||
/>
|
||||
))
|
||||
]}
|
||||
</OptionRowList>
|
||||
</ListGroup>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export function useHostViewSettings(args: {
|
||||
const support =
|
||||
gates?.projectRepoFilterSupport ??
|
||||
(gates?.statusReadable ? (gates.exactProjectRepoFilters ? 'exact' : 'legacy') : 'unknown')
|
||||
const projectRepoFilterMeaning =
|
||||
const projectRepoFilterMeaning: 'exact' | 'legacy' =
|
||||
support === 'exact' || gates?.exactProjectRepoFilters === true ? 'exact' : 'legacy'
|
||||
const pendingViewChanges = useHostPendingViewChanges(client, support, gates?.statusGeneration)
|
||||
const pendingChanges =
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../src/main/persistence/applying-settings/mobile-project-controls-host.test-fixture'
|
||||
import { HOST_ID } from './mobile-web-shell-route-test-fixtures'
|
||||
import {
|
||||
adoptEndpointRepo,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../src/main/persistence/applying-settings/mobile-project-controls-host.test-fixture'
|
||||
import { doubles } from './mobile-web-shell-protocol-test-fixtures'
|
||||
import {
|
||||
type Mounted,
|
||||
|
||||
@@ -5,9 +5,7 @@ import type * as RpcOperationModule from '../transport/rpc-operation'
|
||||
|
||||
import { vi } from 'vitest'
|
||||
|
||||
import { testState } from '../../../src/main/persistence/persistence-test-harness'
|
||||
|
||||
// Exercise the real hook/store over in-memory disk; stub network and native modules.
|
||||
// Mobile protocol doubles; host-backed joins own their disk and Electron seams.
|
||||
export type Doubles = {
|
||||
connection: { client: object | null; state: string }
|
||||
gates: {
|
||||
@@ -90,10 +88,7 @@ vi.mock('../transport/host-app-version-store', () => ({ recordHostAppVersion: as
|
||||
vi.mock('../transport/host-descriptor-recorder', () => ({
|
||||
recordHostDescriptorFromStatus: () => {}
|
||||
}))
|
||||
vi.mock('electron', () => ({
|
||||
app: { getPath: () => testState.dir },
|
||||
safeStorage: { isEncryptionAvailable: () => false }
|
||||
}))
|
||||
vi.mock('../../../src/main/telemetry/client', () => ({ track: vi.fn() }))
|
||||
vi.mock('../components/AutoHeight', () => ({ AutoHeight: 'AutoHeight' }))
|
||||
vi.mock('../components/MobileSwitch', () => ({ MobileSwitch: 'MobileSwitch' }))
|
||||
|
||||
export { doubles }
|
||||
|
||||
@@ -29,8 +29,20 @@ vi.mock('expo-router', () => ({
|
||||
return null
|
||||
}
|
||||
}))
|
||||
const appStateListeners = vi.hoisted(() => new Set<(state: string) => void>())
|
||||
|
||||
vi.mock('react-native', () => ({
|
||||
AppState: { currentState: 'active' },
|
||||
AppState: {
|
||||
currentState: 'active',
|
||||
addEventListener: (_type: string, listener: (state: string) => void) => {
|
||||
appStateListeners.add(listener)
|
||||
return {
|
||||
remove: () => {
|
||||
appStateListeners.delete(listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
StyleSheet: { create: (styles: unknown) => styles },
|
||||
View: 'View',
|
||||
Text: 'Text',
|
||||
@@ -165,6 +177,7 @@ afterEach(async () => {
|
||||
await pair.flush()
|
||||
pair.host.dispose()
|
||||
}
|
||||
expect(appStateListeners.size).toBe(0)
|
||||
})
|
||||
|
||||
async function render(element: ReactElement, gates: HostStatusGates): Promise<ReactTestRenderer> {
|
||||
|
||||
@@ -19,6 +19,22 @@ import type { RpcClient } from './rpc-client'
|
||||
import type { RpcResponse } from './types'
|
||||
import { stubRpcClient } from './rpc-client-test-stub'
|
||||
|
||||
const appStateListeners = vi.hoisted(() => new Set<(state: string) => void>())
|
||||
|
||||
vi.mock('react-native', () => ({
|
||||
AppState: {
|
||||
currentState: 'active',
|
||||
addEventListener: (_type: string, listener: (state: string) => void) => {
|
||||
appStateListeners.add(listener)
|
||||
return {
|
||||
remove: () => {
|
||||
appStateListeners.delete(listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
const recordHostAppVersionMock = vi.hoisted(() => vi.fn().mockResolvedValue(undefined))
|
||||
|
||||
vi.mock('./host-app-version-store', () => ({
|
||||
@@ -76,7 +92,8 @@ async function renderGates(client: RpcClient): Promise<HostStatusGates> {
|
||||
await Promise.resolve()
|
||||
})
|
||||
} finally {
|
||||
mount.renderer?.unmount()
|
||||
await act(async () => mount.renderer?.unmount())
|
||||
expect(appStateListeners.size).toBe(0)
|
||||
}
|
||||
if (!mount.gates) {
|
||||
throw new Error('the gate hook never rendered')
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { useSyncExternalStore } from 'react'
|
||||
import { act, cleanup, renderHook } from '@testing-library/react'
|
||||
import { createElement, useSyncExternalStore } from 'react'
|
||||
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
|
||||
import { afterEach, expect, it, vi } from 'vitest'
|
||||
import { getProjectSectionsResource } from './project-sections-resource'
|
||||
import { stubRpcClient } from '../transport/rpc-client-test-stub'
|
||||
@@ -93,7 +92,6 @@ const flush = async () => {
|
||||
}
|
||||
const catalog = { repos: [], projects: [], setups: [], projectOrderBy: 'manual' }
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
@@ -200,49 +198,71 @@ it('shares the production subscription across consumers and skips renders for eq
|
||||
const o = owner()
|
||||
let renders = 0
|
||||
const subscribe = (listener: () => void) => o.resource.subscribe(listener, o.appState)
|
||||
const hook = renderHook(() => {
|
||||
renders++
|
||||
return useSyncExternalStore(subscribe, o.resource.getSnapshot)
|
||||
})
|
||||
const otherHook = renderHook(() => useSyncExternalStore(subscribe, o.resource.getSnapshot))
|
||||
await act(flush)
|
||||
expect(o.sent).toHaveLength(1)
|
||||
await act(async () => {
|
||||
o.answer({ catalog })
|
||||
await flush()
|
||||
})
|
||||
const settled = renders
|
||||
await act(async () => {
|
||||
o.wake('unrelatedSettings')
|
||||
await flush()
|
||||
})
|
||||
expect(renders).toBe(settled)
|
||||
const other = owner()
|
||||
const stop = other.resource.subscribe(vi.fn(), other.appState)
|
||||
await act(async () => {
|
||||
await flush()
|
||||
other.answer({ catalog: null })
|
||||
await flush()
|
||||
})
|
||||
expect(renders).toBe(settled)
|
||||
await act(async () => {
|
||||
o.wake('ready')
|
||||
await flush()
|
||||
o.answer({ catalog: structuredClone(catalog) })
|
||||
await flush()
|
||||
})
|
||||
expect(renders).toBe(settled)
|
||||
await act(async () => {
|
||||
o.wake('reposChanged')
|
||||
await flush()
|
||||
o.answer({ catalog: { ...catalog, projectOrderBy: 'recent' } })
|
||||
await flush()
|
||||
})
|
||||
expect(renders).toBe(settled + 1)
|
||||
expect(hook.result.current).toEqual(otherHook.result.current)
|
||||
hook.unmount()
|
||||
otherHook.unmount()
|
||||
stop()
|
||||
const observed: {
|
||||
current?: ReturnType<typeof o.resource.getSnapshot>
|
||||
other?: ReturnType<typeof o.resource.getSnapshot>
|
||||
} = {}
|
||||
function Probe({ primary }: { primary: boolean }): null {
|
||||
const snapshot = useSyncExternalStore(subscribe, o.resource.getSnapshot)
|
||||
if (primary) {
|
||||
renders++
|
||||
observed.current = snapshot
|
||||
} else {
|
||||
observed.other = snapshot
|
||||
}
|
||||
return null
|
||||
}
|
||||
let hook: ReactTestRenderer | undefined
|
||||
let otherHook: ReactTestRenderer | undefined
|
||||
let stop: (() => void) | undefined
|
||||
try {
|
||||
await act(async () => {
|
||||
hook = create(createElement(Probe, { primary: true }))
|
||||
otherHook = create(createElement(Probe, { primary: false }))
|
||||
await flush()
|
||||
})
|
||||
expect(o.sent).toHaveLength(1)
|
||||
await act(async () => {
|
||||
o.answer({ catalog })
|
||||
await flush()
|
||||
})
|
||||
expect(observed.current).toEqual({ kind: 'answered', value: catalog })
|
||||
const settled = renders
|
||||
await act(async () => {
|
||||
o.wake('unrelatedSettings')
|
||||
await flush()
|
||||
})
|
||||
expect(renders).toBe(settled)
|
||||
const other = owner()
|
||||
stop = other.resource.subscribe(vi.fn(), other.appState)
|
||||
await act(async () => {
|
||||
await flush()
|
||||
other.answer({ catalog: null })
|
||||
await flush()
|
||||
})
|
||||
expect(renders).toBe(settled)
|
||||
await act(async () => {
|
||||
o.wake('ready')
|
||||
await flush()
|
||||
o.answer({ catalog: structuredClone(catalog) })
|
||||
await flush()
|
||||
})
|
||||
expect(renders).toBe(settled)
|
||||
await act(async () => {
|
||||
o.wake('reposChanged')
|
||||
await flush()
|
||||
o.answer({ catalog: { ...catalog, projectOrderBy: 'recent' } })
|
||||
await flush()
|
||||
})
|
||||
expect(renders).toBe(settled + 1)
|
||||
expect(observed.current).toEqual(observed.other)
|
||||
} finally {
|
||||
await act(async () => {
|
||||
hook?.unmount()
|
||||
otherHook?.unmount()
|
||||
})
|
||||
stop?.()
|
||||
}
|
||||
})
|
||||
|
||||
it('settles the initial subscription-ready race and a rejected read through a legitimate wake', async () => {
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
"src/session/mobile-native-command-discovery.test.tsx",
|
||||
"src/tasks/agent-launch-mobile-replay.test.ts",
|
||||
"src/worktree/project-sections-owner-recovery.test.ts",
|
||||
"src/mobile-web-shell/mobile-web-shell-project-controls.test.ts",
|
||||
"src/mobile-web-shell/mobile-web-shell-nested-project-filter.test.ts",
|
||||
"src/test-support/rpc-recording/recorded-request-params.test.ts",
|
||||
"src/tasks/mobile-agent-launch-architecture.test.ts",
|
||||
"src/transport/mobile-relay-browser-cancel-budget.test.ts",
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { vi } from 'vitest'
|
||||
import { testState } from '../persistence-test-harness'
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: { getPath: () => testState.dir },
|
||||
safeStorage: { isEncryptionAvailable: () => false }
|
||||
}))
|
||||
vi.mock('../../telemetry/client', () => ({ track: vi.fn() }))
|
||||
@@ -14,19 +14,19 @@ import { ProjectSectionCatalogSchema } from '../../../shared/project-section-cat
|
||||
import { publishMobileProjectSections } from '../../runtime/mobile-project-sections-snapshot'
|
||||
import { MOBILE_PROJECT_SECTIONS_METHODS } from '../../runtime/rpc/methods/mobile-project-sections'
|
||||
import { getDefaultPersistedState } from '../../../shared/constants'
|
||||
import { writeDataFile } from '../persistence-test-harness'
|
||||
import '../../runtime/rpc/unused-default-rpc-methods.test-fixture'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import { mkdtempSync, rmSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import {
|
||||
writeDataFile,
|
||||
closeTestStores,
|
||||
createStore,
|
||||
readDataFile,
|
||||
readPersistedState,
|
||||
testState
|
||||
} from '../persistence-test-harness'
|
||||
import '../../runtime/rpc/unused-default-rpc-methods.test-fixture'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import { mkdtempSync, rmSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { RpcDispatcher } from '../../runtime/rpc/dispatcher'
|
||||
import { CLIENT_UI_METHODS } from '../../runtime/rpc/methods/client-ui'
|
||||
import { RUNTIME_CLIENT_CAPABILITY_METHODS } from '../../runtime/rpc/methods/runtime-client-capabilities'
|
||||
|
||||
@@ -92,12 +92,22 @@ it.each(['web', 'mobile', 'old'] as const)(
|
||||
>()
|
||||
close = vi.fn<WebSocket['close']>()
|
||||
}
|
||||
type DispatchSocketEvents = { close: [code: number, reason: Buffer]; error: [error: Error] }
|
||||
// Dispatch ignores fluent returns; keep its WebSocket event arguments and the fixture's return.
|
||||
type DispatchSocketListeners = Record<
|
||||
'on' | 'once' | 'off',
|
||||
<Event extends keyof DispatchSocketEvents>(
|
||||
event: Event,
|
||||
listener: (this: WebSocket, ...args: DispatchSocketEvents[Event]) => void
|
||||
) => Socket
|
||||
>
|
||||
const Q = 'runtime:server\0same'
|
||||
try {
|
||||
const socket = new Socket() satisfies Pick<
|
||||
WebSocket,
|
||||
'OPEN' | 'readyState' | 'bufferedAmount' | 'send' | 'close' | 'on' | 'once' | 'off'
|
||||
>
|
||||
'OPEN' | 'readyState' | 'bufferedAmount' | 'send' | 'close'
|
||||
> &
|
||||
DispatchSocketListeners
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: checked consumed EventEmitter/readiness/send/close port crosses the transport library's full WebSocket handle; unused WebSocket members are not implemented.
|
||||
const ws = socket as unknown as WebSocket
|
||||
const phone = generateKeyPair()
|
||||
|
||||
Reference in New Issue
Block a user