Repository navigation
fix(ios): serialize status bar normalization around simulator captures #4136
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e6a411d
fix(ios): serialize status bar normalization around simulator captures
thymikee e6a97eb
fix(ios): keep plain captures out of the status bar window
thymikee b5fa69d
fix(ios): keep runner captures out of the status bar window
thymikee 6a8579c
test(ios): cover the runner fallback inside the status bar window
thymikee c69f231
fix(ios): let an aborted request finish a capture leg inside its window
thymikee e84c775
docs(ios): say the status bar hold keeps the request signal on the leg
thymikee 61a4a6a
fix(ios): keep status bar writers and capture restores in one order
thymikee b02d672
fix(ios): keep the cleared status bar answer when a restore clear fails
thymikee af11ed6
fix(ios): name the status bar window by the whole simulator address
thymikee 97a1090
fix(ios): bound the settings writes that hold the status bar window
thymikee 6d59c2b
test(ios): require the settings status bar command to carry its budget
thymikee 6f7b9ea
fix(ios): give one simulator one status bar identity across set-path …
thymikee 5ffe9ec
fix(ios): take the simulator default set from the host that runs simctl
thymikee f01442f
fix(ios): key status bar transactions by simulator UUID
thymikee be0846f
docs(ios): clarify status bar request and command timeouts
thymikee 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
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
175 changes: 175 additions & 0 deletions
175
packages/platform-apple/src/core/__tests__/fake-status-bar-simctl.ts
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,175 @@ | ||
| import type { FakeAppleToolResponse } from '../../__tests__/fake-apple-tool.ts'; | ||
|
|
||
| /** | ||
| * `simctl status_bar` with the simulator's own override state behind it. The production reader asks | ||
| * the tool what the status bar currently shows, so a test can only prove what a capture would | ||
| * restore to when the tool answers from state rather than from one fixed listing. | ||
| */ | ||
|
|
||
| export type StatusBarOverrideState = { | ||
| time?: string; | ||
| dataNetwork?: string; | ||
| wifiMode?: string; | ||
| wifiBars?: string; | ||
| cellularMode?: string; | ||
| cellularBars?: string; | ||
| operatorName?: string; | ||
| batteryState?: string; | ||
| batteryLevel?: string; | ||
| }; | ||
|
|
||
| export type FakeStatusBarSimctl = { | ||
| /** Acts as the `withFakeAppleTool` script. */ | ||
| script(args: string[]): FakeAppleToolResponse; | ||
| /** The override values the simulator holds now. */ | ||
| overrides(): StatusBarOverrideState; | ||
| /** The state each `list` served, in order: one entry per snapshot a capture took. */ | ||
| servedSnapshots(): StatusBarOverrideState[]; | ||
| }; | ||
|
|
||
| const DATA_NETWORK_CODE: Record<string, number> = { | ||
| hide: 0, | ||
| wifi: 1, | ||
| '3g': 6, | ||
| '4g': 7, | ||
| lte: 8, | ||
| 'lte-a': 9, | ||
| 'lte+': 10, | ||
| '5g': 11, | ||
| '5g+': 12, | ||
| '5g-uwb': 13, | ||
| '5g-uc': 14, | ||
| }; | ||
|
|
||
| const WIFI_MODE_CODE: Record<string, number> = { | ||
| searching: 1, | ||
| failed: 2, | ||
| active: 3, | ||
| }; | ||
|
|
||
| const CELLULAR_MODE_CODE: Record<string, number> = { | ||
| notSupported: 0, | ||
| searching: 1, | ||
| failed: 2, | ||
| active: 3, | ||
| }; | ||
|
|
||
| const OVERRIDE_OPTION_FIELDS = { | ||
| '--time': 'time', | ||
| '--dataNetwork': 'dataNetwork', | ||
| '--wifiMode': 'wifiMode', | ||
| '--wifiBars': 'wifiBars', | ||
| '--cellularMode': 'cellularMode', | ||
| '--cellularBars': 'cellularBars', | ||
| '--operatorName': 'operatorName', | ||
| '--batteryState': 'batteryState', | ||
| '--batteryLevel': 'batteryLevel', | ||
| } as const satisfies Record<string, keyof StatusBarOverrideState>; | ||
|
|
||
| function parseOverrideOptions(args: string[]): Record<string, string> { | ||
| const options: Record<string, string> = {}; | ||
| for (let index = 0; index < args.length; index += 2) { | ||
| const option = args[index]; | ||
| if (option === undefined) break; | ||
| options[option] = args[index + 1] ?? ''; | ||
| } | ||
| return options; | ||
| } | ||
|
|
||
| /** One `list` line, rendered from the state fields it reads, or nothing when the state omits them. */ | ||
| type StatusBarOverrideLine = { | ||
| reads: (keyof StatusBarOverrideState)[]; | ||
| render: (state: StatusBarOverrideState) => string; | ||
| }; | ||
|
|
||
| /** The listing code for one override value; an unmapped value is the fake's bug, not a silent `hide`. */ | ||
| function codeOf(codes: Record<string, number>, value: string | undefined, field: string): number { | ||
| if (value === undefined) return 0; | ||
| const code = codes[value]; | ||
| if (code === undefined) { | ||
| throw new Error(`fake simctl status_bar cannot list ${field}: ${value}`); | ||
| } | ||
| return code; | ||
| } | ||
|
|
||
| const STATUS_BAR_OVERRIDES_LISTING: StatusBarOverrideLine[] = [ | ||
| { | ||
| reads: ['time'], | ||
| render: (state) => `Time: ${state.time}`, | ||
| }, | ||
| { | ||
| reads: ['dataNetwork'], | ||
| render: (state) => | ||
| `DataNetworkType: ${codeOf(DATA_NETWORK_CODE, state.dataNetwork, 'dataNetwork')}`, | ||
| }, | ||
| { | ||
| reads: ['wifiMode', 'wifiBars'], | ||
| render: (state) => | ||
| `WiFi Mode: ${codeOf(WIFI_MODE_CODE, state.wifiMode, 'wifiMode')}, WiFi Bars: ${state.wifiBars ?? 0}`, | ||
| }, | ||
| { | ||
| reads: ['cellularMode', 'cellularBars'], | ||
| render: (state) => | ||
| `Cell Mode: ${codeOf(CELLULAR_MODE_CODE, state.cellularMode, 'cellularMode')}, Cell Bars: ${state.cellularBars ?? 0}`, | ||
| }, | ||
| { | ||
| reads: ['operatorName'], | ||
| render: (state) => `Operator Name: ${state.operatorName}`, | ||
| }, | ||
| { | ||
| reads: ['batteryState', 'batteryLevel'], | ||
| render: (state) => | ||
| `Battery State: ${state.batteryState ? Number(state.batteryState === 'unplugged') : 0}, Battery Level: ${state.batteryLevel ?? 100}, Not Charging: 0`, | ||
| }, | ||
| ]; | ||
|
|
||
| /** Renders state the way `simctl status_bar <udid> list` does, codes and all. */ | ||
| function renderStatusBarOverrides(state: StatusBarOverrideState): string { | ||
| const lines = ['Current Status Bar Overrides:', '=============================']; | ||
| for (const entry of STATUS_BAR_OVERRIDES_LISTING) { | ||
| if (entry.reads.every((field) => state[field] === undefined)) continue; | ||
| lines.push(entry.render(state)); | ||
| } | ||
| return lines.join('\n'); | ||
| } | ||
|
|
||
| export function createFakeStatusBarSimctl( | ||
| udid: string, | ||
| initialOverrides: StatusBarOverrideState, | ||
| ): FakeStatusBarSimctl { | ||
| let state: StatusBarOverrideState = { ...initialOverrides }; | ||
| const servedSnapshots: StatusBarOverrideState[] = []; | ||
|
|
||
| return { | ||
| script: (args): FakeAppleToolResponse => { | ||
| const unexpected = (detail: string): FakeAppleToolResponse => ({ | ||
| stderr: `unexpected status bar call: ${detail}`, | ||
| exitCode: 1, | ||
| }); | ||
| if (args[0] !== 'simctl' || args[1] !== 'status_bar' || args[2] !== udid) { | ||
| return unexpected(args.join(' ')); | ||
| } | ||
| const verb = args[3]; | ||
| if (verb === 'list') { | ||
| servedSnapshots.push({ ...state }); | ||
| return renderStatusBarOverrides(state); | ||
| } | ||
| if (verb === 'clear') { | ||
| state = {}; | ||
| return ''; | ||
| } | ||
| if (verb !== 'override') return unexpected(args.join(' ')); | ||
|
|
||
| const applied: StatusBarOverrideState = {}; | ||
| for (const [option, value] of Object.entries(parseOverrideOptions(args.slice(4)))) { | ||
| const field = OVERRIDE_OPTION_FIELDS[option as keyof typeof OVERRIDE_OPTION_FIELDS]; | ||
| if (field === undefined) return unexpected(`unknown option ${option}`); | ||
| applied[field] = value; | ||
| } | ||
| state = { ...state, ...applied }; | ||
| return ''; | ||
| }, | ||
| overrides: () => ({ ...state }), | ||
| servedSnapshots: () => servedSnapshots.map((snapshot) => ({ ...snapshot })), | ||
| }; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.