Skip to content

Commit 4a2d30b

Browse files
fix(ios): a panel of unknown power blocks the established lit panel
Review of #4440 (cubic): establishedLitPanel counted only power 'lit', so a lit panel beside a sibling of unknown power (an unrecognized backlight state, which readPanelPower deliberately does not call dark) was still established, and the scoped rotation could confirm or dispatch from it. Any panel of unknown power now establishes none, for runner routing and the scoped rotation alike; the capture fallback is unchanged. Fail-first: on bfdbd9b the new selector test and both interactor cases (target already showing, another target) failed - the rotation returned success in both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent bfdbd9b commit 4a2d30b

4 files changed

Lines changed: 45 additions & 5 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,13 @@ describe('establishedLitPanel', () => {
401401
assert.equal(appleLitPanel(inventory), undefined);
402402
});
403403

404+
test('a lit panel beside a panel of unknown power establishes none', () => {
405+
// Unknown power may be showing content, so the lit panel is not the only one that may be lit.
406+
const inventory = buildInventory([outerPanel, { ...innerPanel, power: 'unknown' }]);
407+
assert.equal(establishedLitPanel(inventory), undefined);
408+
assert.equal(appleLitPanel(inventory), undefined);
409+
});
410+
404411
test('an incomplete table establishes no panel even when one parsed panel is the only lit one', async () => {
405412
// Two activeOn integrated entries; the inner one has no geometry and does not parse.
406413
mockReadHostTextFile.mockResolvedValue(

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,18 @@ function warnWhenPrimaryPanelIsNotTheSmallest(panels: AppleDeviceDisplay[]): voi
413413
/**
414414
* The one panel the panel table establishes as lit, or nothing. It takes a resolved multi-panel
415415
* 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
416+
* panel, which is that active display, and no panel of unknown power. A table with an integrated
417+
* entry missing its identity or geometry, or with a panel whose power is unknown, establishes no
418+
* panel, even when the others show a single lit one: that entry may be lit too. Runner routing (`appleLitPanel`) and the foldable
419419
* rotation controller select through this one rule.
420420
*/
421421
export function establishedLitPanel(
422422
inventory: AppleDisplayInventory,
423423
): AppleDeviceDisplay | undefined {
424424
if (!inventory.multiScreen || inventory.unresolved || !inventory.activeDisplay) return undefined;
425+
// Unknown power may be showing content (see readPanelPower), so beside it no lit panel is the
426+
// only one that may be lit.
427+
if (inventory.displays.some((display) => display.power === 'unknown')) return undefined;
425428
const litPanels = inventory.displays.filter((display) => display.power === 'lit');
426429
if (litPanels.length !== 1 || litPanels[0] !== inventory.activeDisplay) return undefined;
427430
return litPanels[0];

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ function fakeScopedDuo(
198198
hidLagReads?: number;
199199
/** A panel the table reports lit (activeOn) but without geometry: an incomplete table. */
200200
incompleteLitPanel?: DuoPanel;
201+
/** A panel whose backlight state the table reports in an unrecognized form: power unknown. */
202+
unknownPowerPanel?: DuoPanel;
201203
},
202204
) {
203205
const helpers: string[][] = [];
@@ -221,9 +223,10 @@ function fakeScopedDuo(
221223
show(lit);
222224
const panel = (kind: DuoPanel, bothLit: boolean) => {
223225
const incomplete = options.incompleteLitPanel === kind;
226+
const unknownPower = options.unknownPowerPanel === kind;
224227
const isLit = bothLit || kind === lit || incomplete;
225228
return {
226-
backlightState: isLit ? 'activeOn' : 'off',
229+
backlightState: unknownPower ? 'transitioning' : isLit ? 'activeOn' : 'off',
227230
currentOrientation: isLit ? `rot${shown[kind]}` : 'rot180',
228231
displayId: kind === 'outer' ? 1 : 3,
229232
name: kind === 'outer' ? 'LCD' : 'LCD-1',
@@ -503,6 +506,32 @@ test.each([
503506
},
504507
);
505508

509+
test.each([
510+
['the lit panel already shows the target', 'landscape-left'],
511+
['the lit panel shows another rotation', 'landscape-right'],
512+
] as const)(
513+
'a panel of unknown power beside the lit one never confirms or dispatches (%s)',
514+
async (_case, target) => {
515+
const scoped = simulator({ simulatorSetPath: '/tmp/scoped-set' });
516+
// The outer panel reads lit; the inner one reports a backlight state the parser does not
517+
// recognize, so its power is unknown and it may be lit too.
518+
const sim = fakeScopedDuo(scoped, {
519+
lit: 'outer',
520+
picker: 'landscape-left',
521+
unknownPowerPanel: 'inner',
522+
});
523+
expect(sim.litScreen()).toBe('rot270');
524+
const outcome = await rotateScoped(sim, target);
525+
expect(outcome).toMatchObject({
526+
code: 'COMMAND_FAILED',
527+
details: { reason: 'orientation-unverified-scoped-set', requestedOrientation: target },
528+
});
529+
expect((outcome as AppError).details).not.toHaveProperty('observedOrientation');
530+
expect(sim.rotations()).toEqual([]);
531+
expect(sim.devicectl).toEqual([]);
532+
},
533+
);
534+
506535
test('a reading taken before the dispatch lands teaches nothing and is not followed by another dispatch', async () => {
507536
const scoped = simulator({ simulatorSetPath: '/tmp/scoped-set' });
508537
// 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ function scopedUnverifiedError(
294294
/**
295295
* The one lit panel and the rotation it shows, from one fresh panel-table read, selected by the
296296
* 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:
297+
* an incomplete one, no lit panel or several, a panel of unknown power, an unrecognized `rotN` —
298+
* is no reading:
298299
* the rotation loop must not confirm, compensate or dispatch from a panel that is not showing.
299300
* On iPhone Duo the table reports both panels lit for a few seconds after a pose change in either
300301
* direction, so the first reads after a fold or an unfold are no reading by design.

0 commit comments

Comments
 (0)