Skip to content

Commit bfdbd9b

Browse files
fix(ios): a scoped rotation needs one established lit panel
Review of callstack#4440: readLitPanel filtered the parsed panels for a single lit one, so a table with a second lit integrated entry that lacked identity or geometry (which the parser drops) still produced a reading. The rotation then confirmed, or dispatched compensation, without one established lit panel. display-inventory now owns the strict selection (establishedLitPanel): a resolved multi-panel table that parsed every integrated entry, and so named an active display, with exactly one lit panel, which is that display. appleLitPanel and the scoped rotation both select through it; the incomplete-table capture refusal is unchanged and picker calibration stays in the foldable module. Regression: an interactor test with two activeOn integrated entries, one without geometry, for a target the parsed panel already shows and for another target: no dispatch, no confirmation, orientation-unverified- scoped-set. On c75affa it returned success in both cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c75affa commit bfdbd9b

4 files changed

Lines changed: 109 additions & 12 deletions

File tree

‎packages/platform-apple/src/core/__tests__/display-inventory.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ vi.mock('@agent-device/host-kit/host-file', async (importOriginal) => {
3333
});
3434

3535
import {
36+
appleLitPanel,
3637
appleSimulatorDisplayArgvFragment,
38+
establishedLitPanel,
3739
buildInventory,
3840
parseCoreDeviceDisplays,
3941
readPanelPower,
@@ -375,6 +377,56 @@ describe('panelContentRotation', () => {
375377
});
376378
});
377379

380+
describe('establishedLitPanel', () => {
381+
beforeEach(() => {
382+
mockReadHostTextFile.mockReset();
383+
mockReadHostTextFile.mockResolvedValue('');
384+
});
385+
386+
function duoTable(mapEntry: (entry: Record<string, unknown>) => Record<string, unknown>) {
387+
return JSON.stringify({
388+
result: { displays: IPHONE_DUO_CLOSED.result.displays.map(mapEntry) },
389+
});
390+
}
391+
392+
test('a complete table with one lit panel establishes that panel for both selectors', () => {
393+
const inventory = buildInventory([outerPanel, innerPanel]);
394+
assert.equal(establishedLitPanel(inventory), outerPanel);
395+
assert.deepEqual(appleLitPanel(inventory), { displayId: 1, widthPt: 466, heightPt: 678 });
396+
});
397+
398+
test('two lit panels establish none', () => {
399+
const inventory = buildInventory([outerPanel, { ...innerPanel, power: 'lit' }]);
400+
assert.equal(establishedLitPanel(inventory), undefined);
401+
assert.equal(appleLitPanel(inventory), undefined);
402+
});
403+
404+
test('an incomplete table establishes no panel even when one parsed panel is the only lit one', async () => {
405+
// Two activeOn integrated entries; the inner one has no geometry and does not parse.
406+
mockReadHostTextFile.mockResolvedValue(
407+
duoTable((entry) => {
408+
const lit: Record<string, unknown> = { ...entry, backlightState: 'activeOn' };
409+
if (entry.name !== 'LCD-1') return lit;
410+
const { nativeSize: _nativeSize, ...withoutGeometry } = lit;
411+
return withoutGeometry;
412+
}),
413+
);
414+
const inventory = await queryAppleDisplayInventory(IOS_TEST_SIMULATOR, {});
415+
assert.equal(inventory.multiScreen, true);
416+
assert.equal(inventory.displays.filter((display) => display.power === 'lit').length, 1);
417+
assert.equal(establishedLitPanel(inventory), undefined);
418+
assert.equal(appleLitPanel(inventory), undefined);
419+
});
420+
421+
test('a single-panel or unresolved table establishes no foldable panel', () => {
422+
assert.equal(establishedLitPanel(buildInventory([outerPanel])), undefined);
423+
assert.equal(
424+
establishedLitPanel({ displays: [], multiScreen: false, ambiguous: false, unresolved: true }),
425+
undefined,
426+
);
427+
});
428+
});
429+
378430
describe('resolveAppleCaptureTarget', () => {
379431
beforeEach(() => {
380432
mockRunXcrun.mockClear();

‎packages/platform-apple/src/core/display-inventory.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,30 @@ function warnWhenPrimaryPanelIsNotTheSmallest(panels: AppleDeviceDisplay[]): voi
411411
}
412412

413413
/**
414-
* The panel a runner request names, only when panel power decided exactly one panel. Unlike a
415-
* capture, a surface request does not fall back to the `primary` panel: it can keep the runner's
416-
* historic route instead of guessing. Display 0 is the runtime's "no display" identity.
414+
* The one panel the panel table establishes as lit, or nothing. It takes a resolved multi-panel
415+
* table that parsed every integrated entry, and so named an active display, with exactly one lit
416+
* panel, which is that active display. A table with an integrated entry missing its identity or
417+
* geometry establishes no panel, even when the panels that did parse show a single lit one: the
418+
* entry that did not parse may be lit too. Runner routing (`appleLitPanel`) and the foldable
419+
* rotation controller select through this one rule.
417420
*/
418-
export function appleLitPanel(inventory: AppleDisplayInventory): RunnerCommand['litPanel'] {
421+
export function establishedLitPanel(
422+
inventory: AppleDisplayInventory,
423+
): AppleDeviceDisplay | undefined {
419424
if (!inventory.multiScreen || inventory.unresolved || !inventory.activeDisplay) return undefined;
420425
const litPanels = inventory.displays.filter((display) => display.power === 'lit');
421-
const panel = litPanels.length === 1 ? litPanels[0]! : undefined;
426+
if (litPanels.length !== 1 || litPanels[0] !== inventory.activeDisplay) return undefined;
427+
return litPanels[0];
428+
}
429+
430+
/**
431+
* The panel a runner request names, only when the panel table establishes one lit panel (see
432+
* {@link establishedLitPanel}). Unlike a capture, a surface request does not fall back to the
433+
* `primary` panel: it can keep the runner's historic route instead of guessing. Display 0 is the
434+
* runtime's "no display" identity.
435+
*/
436+
export function appleLitPanel(inventory: AppleDisplayInventory): RunnerCommand['litPanel'] {
437+
const panel = establishedLitPanel(inventory);
422438
if (!panel || panel.displayId <= 0) return undefined;
423439
return {
424440
displayId: panel.displayId,

‎packages/platform-apple/src/foldable/orientation.test.ts‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ function fakeScopedDuo(
196196
bothLitFromRead?: number;
197197
/** How many panel reads after a picker event still show the panel as it was before it. */
198198
hidLagReads?: number;
199+
/** A panel the table reports lit (activeOn) but without geometry: an incomplete table. */
200+
incompleteLitPanel?: DuoPanel;
199201
},
200202
) {
201203
const helpers: string[][] = [];
@@ -218,13 +220,14 @@ function fakeScopedDuo(
218220
};
219221
show(lit);
220222
const panel = (kind: DuoPanel, bothLit: boolean) => {
221-
const isLit = bothLit || kind === lit;
223+
const incomplete = options.incompleteLitPanel === kind;
224+
const isLit = bothLit || kind === lit || incomplete;
222225
return {
223226
backlightState: isLit ? 'activeOn' : 'off',
224227
currentOrientation: isLit ? `rot${shown[kind]}` : 'rot180',
225228
displayId: kind === 'outer' ? 1 : 3,
226229
name: kind === 'outer' ? 'LCD' : 'LCD-1',
227-
nativeSize: kind === 'outer' ? [1398, 2034] : [2007, 2853],
230+
...(incomplete ? {} : { nativeSize: kind === 'outer' ? [1398, 2034] : [2007, 2853] }),
228231
pointScale: 3,
229232
primary: kind === 'outer',
230233
type: { integrated: {} },
@@ -474,6 +477,32 @@ test('a scoped rotation to the orientation already showing dispatches nothing',
474477
expect(sim.rotations()).toEqual([]);
475478
});
476479

480+
test.each([
481+
['the parsed panel already shows the target', 'landscape-left'],
482+
['the parsed panel shows another rotation', 'landscape-right'],
483+
] as const)(
484+
'an incomplete panel table never confirms or dispatches (%s)',
485+
async (_case, target) => {
486+
const scoped = simulator({ simulatorSetPath: '/tmp/scoped-set' });
487+
// Two activeOn integrated entries; the inner one has no geometry, so it does not parse. The
488+
// outer panel that did parse is the only lit one left, but no single lit panel is established.
489+
const sim = fakeScopedDuo(scoped, {
490+
lit: 'outer',
491+
picker: 'landscape-left',
492+
incompleteLitPanel: 'inner',
493+
});
494+
expect(sim.litScreen()).toBe('rot270');
495+
const outcome = await rotateScoped(sim, target);
496+
expect(outcome).toMatchObject({
497+
code: 'COMMAND_FAILED',
498+
details: { reason: 'orientation-unverified-scoped-set', requestedOrientation: target },
499+
});
500+
expect((outcome as AppError).details).not.toHaveProperty('observedOrientation');
501+
expect(sim.rotations()).toEqual([]);
502+
expect(sim.devicectl).toEqual([]);
503+
},
504+
);
505+
477506
test('a reading taken before the dispatch lands teaches nothing and is not followed by another dispatch', async () => {
478507
const scoped = simulator({ simulatorSetPath: '/tmp/scoped-set' });
479508
// The first two panel reads after each picker event still show the panel as it was before it.

‎packages/platform-apple/src/foldable/orientation.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../core/config.ts';
1414
import { readAppleDeviceOrientation } from '../core/device-orientation.ts';
1515
import {
16+
establishedLitPanel,
1617
panelContentRotation,
1718
queryAppleDisplayInventory,
1819
type AppleDeviceDisplay,
@@ -291,8 +292,9 @@ function scopedUnverifiedError(
291292
}
292293

293294
/**
294-
* The one lit panel and the rotation it shows, from one fresh panel-table read. Anything
295-
* less decided — an unreadable table, no lit panel, an unrecognized `rotN` — is no reading:
295+
* The one lit panel and the rotation it shows, from one fresh panel-table read, selected by the
296+
* display inventory's {@link establishedLitPanel}. Anything less decided — an unreadable table,
297+
* an incomplete one, no lit panel or several, an unrecognized `rotN` — is no reading:
296298
* the rotation loop must not confirm, compensate or dispatch from a panel that is not showing.
297299
* On iPhone Duo the table reports both panels lit for a few seconds after a pose change in either
298300
* direction, so the first reads after a fold or an unfold are no reading by design.
@@ -309,9 +311,7 @@ async function readLitPanel(
309311
if (signal?.aborted) throw error;
310312
return undefined;
311313
}
312-
if (inventory.unresolved || !inventory.multiScreen) return undefined;
313-
const litPanels = inventory.displays.filter((display) => display.power === 'lit');
314-
const panel = litPanels.length === 1 ? litPanels[0]! : undefined;
314+
const panel = establishedLitPanel(inventory);
315315
if (!panel) return undefined;
316316
const rotation = panelContentRotation(panel.currentOrientation);
317317
return rotation === undefined ? undefined : { panel, rotation };

0 commit comments

Comments
 (0)