Skip to content

Commit 250f84d

Browse files
committed
refactor(snapshot): own the sibling-sized chrome rule in its own module
Move the #2996 rule and its sibling index out of `snapshot-occlusion.ts` into `snapshot-sibling-sized-chrome.ts` with the matching test file, and single-source the chrome-kind question in `snapshot-chrome-kind.ts` so both occlusion exemptions read one classification. The new modules stay beside their caller: layering policy R73 owns `capture-kit/src/snapshot/` for the presentation runtime.
1 parent b3eceda commit 250f84d

8 files changed

Lines changed: 620 additions & 653 deletions
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { isViewportChromeNode, VIEWPORT_CHROME_KIND_FRAGMENTS } from './snapshot-chrome-kind.ts';
3+
4+
describe('isViewportChromeNode', () => {
5+
it.each(VIEWPORT_CHROME_KIND_FRAGMENTS)(
6+
'reads the %s kind from each published field',
7+
(fragment) => {
8+
const className = `UI${fragment}`;
9+
expect(isViewportChromeNode({ type: 'Other', role: className, subrole: undefined })).toBe(
10+
true,
11+
);
12+
expect(isViewportChromeNode({ type: className, role: undefined, subrole: undefined })).toBe(
13+
true,
14+
);
15+
expect(isViewportChromeNode({ type: 'Other', role: undefined, subrole: className })).toBe(
16+
true,
17+
);
18+
},
19+
);
20+
21+
it.each([
22+
{ type: 'Dialog', role: 'UIAlertControllerView' },
23+
{ type: 'Sheet' },
24+
{ type: 'Other', role: 'RCTRootContentView' },
25+
{ type: 'Other', role: 'BottomBackgroundView' },
26+
])('leaves non-chrome presentation out: $type/$role', (node) => {
27+
expect(isViewportChromeNode({ ...node, subrole: undefined })).toBe(false);
28+
});
29+
30+
it('never joins separate fields into a chrome fragment', () => {
31+
// `type: 'Tab'` + `role: 'Bar'` normalizes to `tab bar`, which must not satisfy `tabbar`.
32+
expect(isViewportChromeNode({ type: 'Tab', role: 'Bar', subrole: undefined })).toBe(false);
33+
});
34+
35+
it('tolerates missing fields', () => {
36+
expect(isViewportChromeNode({ type: undefined, role: 'UIToolbar', subrole: undefined })).toBe(
37+
true,
38+
);
39+
expect(isViewportChromeNode({ type: undefined, role: undefined, subrole: undefined })).toBe(
40+
false,
41+
);
42+
});
43+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { RawSnapshotNode } from '@agent-device/kernel/snapshot';
2+
import { normalizeType } from '@agent-device/contracts/snapshot';
3+
4+
/** Normalized `type`/`role`/`subrole` fragments naming persistent viewport chrome. */
5+
export const VIEWPORT_CHROME_KIND_FRAGMENTS = ['tabbar', 'toolbar', 'navigationbar'];
6+
7+
/**
8+
* Whether a node is published as persistent viewport chrome rather than floating overlay chrome
9+
* (`dialog`/`sheet`/`alert` stay out). Both occlusion exemptions key on this one classification: a
10+
* container sized to the viewport and one sized to a sibling are the same host-not-surface verdict
11+
* reached against different references, so they must agree on what counts as chrome.
12+
*
13+
* Kind is read from the joined normalized fields, never a single field: the Apple AX bridge names the
14+
* UIKit class in `role`, while the runner path publishes only `type: 'Toolbar'`.
15+
*/
16+
export function isViewportChromeNode(
17+
node: Pick<RawSnapshotNode, 'type' | 'role' | 'subrole'>,
18+
): boolean {
19+
const kind = [node.type, node.role, node.subrole]
20+
.map((value) => normalizeType(value ?? ''))
21+
.join(' ');
22+
return VIEWPORT_CHROME_KIND_FRAGMENTS.some((fragment) => kind.includes(fragment));
23+
}

0 commit comments

Comments
 (0)