Skip to content

Commit ad579e0

Browse files
committed
fix(snapshot): key ref minting on the producer that owns its refs, not the platform
snapshotRefMinting asked whether a capture came from the web channel, but a channel is not a producer: the provenance table itself says several producers can feed one channel with different guarantees, and only agent-browser resolves actions against refs of its own. Any second adapter that lands on the web channel — a webdriver- or CDP-backed one — mints no refs and needs dense positional numbering, which the channel check would have taken away silently, making half its tree unaddressable. The mode now asks the owning question of the producer, and the parameter is the whole provenance pair rather than a partial one so no caller can hand over a channel and leave it to guess who acquired the tree. Behavior is unchanged for every producer that exists today; the table is what the next producer has to reason about.
1 parent 0c4af43 commit ad579e0

2 files changed

Lines changed: 62 additions & 6 deletions

File tree

‎packages/kernel/src/snapshot-attach-refs.test.ts‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
snapshotRefBodies,
66
snapshotRefMinting,
77
type RawSnapshotNode,
8+
type SnapshotProvenance,
89
} from './snapshot.ts';
910

1011
const node = (index: number, extra: Partial<RawSnapshotNode> = {}): RawSnapshotNode => ({
@@ -55,16 +56,54 @@ describe('attachRefs', () => {
5556
});
5657

5758
describe('snapshotRefMinting', () => {
58-
test('a web capture owns its ref namespace', () => {
59+
test('the producer that owns its ref namespace gets backend-issued minting', () => {
5960
expect(snapshotRefMinting({ backend: 'web', producer: 'agent-browser' })).toBe(
6061
'backend-issued',
6162
);
6263
});
6364

64-
test('every other producer is minted positionally, and a capture with no provenance too', () => {
65-
expect(snapshotRefMinting({ backend: 'xctest', producer: 'apple-runner' })).toBe('dense');
66-
expect(snapshotRefMinting({ backend: 'android', producer: 'appium-source' })).toBe('dense');
65+
// The mode keys on the producer, never on the platform channel: several producers can feed one
66+
// channel (`xctest` alone has four) and only some of them mint refs of their own. A web adapter
67+
// added later — a webdriver- or CDP-backed one — would arrive on the `web` channel minting
68+
// nothing, and would need dense numbering to keep every node addressable as it does today.
69+
test.each([
70+
{ backend: 'xctest', producer: 'apple-runner' },
71+
{ backend: 'xctest', producer: 'simulator-ax-bridge' },
72+
{ backend: 'xctest', producer: 'appium-source' },
73+
{ backend: 'xctest', producer: 'limrun-ios-tree' },
74+
{ backend: 'android', producer: 'android-uiautomator' },
75+
{ backend: 'android', producer: 'appium-source' },
76+
{ backend: 'harmonyos-arkui', producer: 'harmonyos-uitest' },
77+
{ backend: 'macos-helper', producer: 'macos-helper' },
78+
{ backend: 'linux-atspi', producer: 'linux-atspi' },
79+
] satisfies readonly SnapshotProvenance[])(
80+
'$backend/$producer is minted positionally',
81+
(provenance) => {
82+
expect(snapshotRefMinting(provenance)).toBe('dense');
83+
},
84+
);
85+
86+
test('a capture with no provenance is minted positionally', () => {
6787
expect(snapshotRefMinting(undefined)).toBe('dense');
88+
expect(snapshotRefMinting({})).toBe('dense');
89+
// Type-level half of the producer-keyed decision: a channel cannot be handed over on its own,
90+
// so this function never has to guess which producer published a tree. `pnpm typecheck` fails
91+
// the moment the parameter widens back to a partial pair.
92+
// @ts-expect-error the minting mode needs the whole provenance pair, not the channel alone
93+
snapshotRefMinting({ backend: 'web' });
94+
});
95+
96+
test('a second producer on the web channel keeps dense numbering', () => {
97+
// Forward-looking regression for the axis itself, not for a pair the table admits today: the
98+
// provenance table has exactly one web producer, so a webdriver- or CDP-backed adapter is not
99+
// expressible yet and has to be widened through here. When it lands, `agent-browser` is the
100+
// entry that owns its refs and nothing else on the channel does — the case a channel check
101+
// would get wrong by handing it `backend-issued` and stripping every ref in its tree.
102+
const secondWebAdapter = {
103+
backend: 'web',
104+
producer: 'webdriver-source',
105+
} as unknown as SnapshotProvenance;
106+
expect(snapshotRefMinting(secondWebAdapter)).toBe('dense');
68107
});
69108
});
70109

‎packages/kernel/src/snapshot.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,17 +820,34 @@ export function snapshotRefBodies(nodes: readonly SnapshotNode[]): string[] {
820820
return nodes.flatMap((node) => (node.ref === undefined ? [] : [node.ref]));
821821
}
822822

823+
/**
824+
* The one producer that resolves actions against refs of its own, and so owns the ref namespace of
825+
* every tree it publishes. A producer that mints nothing belongs nowhere in this list: it keeps
826+
* dense positional numbering. Adding a second producer that mints its own refs means adding it here.
827+
*/
828+
const REF_NAMESPACE_OWNERS: readonly SnapshotProvenance['producer'][] = ['agent-browser'];
829+
823830
/**
824831
* The ref-minting mode of a capture, from the pair that produced it. This is the one place that
825832
* knows which producers own their ref namespace, so the projection that publishes a tree and the
826833
* projection that later re-attaches refs to it cannot disagree.
834+
*
835+
* It reads the producer and not the platform channel, per the rule the provenance table states:
836+
* several producers can feed one channel with different guarantees, and a second web adapter
837+
* (webdriver-backed, or anything else that lands on this channel) mints no refs of its own — it
838+
* needs dense numbering, which a channel-keyed check would silently take away from it. The
839+
* parameter is the whole pair or nothing, so a caller cannot present a channel and leave this to
840+
* guess who acquired the tree.
827841
*/
828842
export function snapshotRefMinting(
829-
provenance: Partial<SnapshotProvenance> | undefined,
843+
provenance: SnapshotCaptureProvenance | undefined,
830844
): SnapshotRefMinting {
831845
// agent-browser resolves click/fill/hover against refs it minted itself, in tree order and not
832846
// densely (#2283). A ref minted beside it would either name a different element or nothing.
833-
return provenance?.backend === 'web' ? 'backend-issued' : 'dense';
847+
const producer = provenance?.producer;
848+
return producer !== undefined && REF_NAMESPACE_OWNERS.includes(producer)
849+
? 'backend-issued'
850+
: 'dense';
834851
}
835852

836853
/**

0 commit comments

Comments
 (0)