fix(cache): stop a drag when a look-alike joins an end while it waits (ENG-1556)

The guard on a drag's ends counted only drops in an end's visible
look-alikes, and only for an end its point picked out of a group. A
same-named control that mounted under the recorded point while the drag
waited for the other end, beside a unique end or a group that grew, was
picked by the point on the last look. The guard now also counts a unique
end found while the drag waits, and stops on any change in the count, so
a visible unique end that gains a look-alike stops as a hidden one does.

Review: kdy1 on #2395 (thread 4734170548).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
michal-e2e
2026-12-01 15:32:20 +01:00
co-authored by Claude Opus 5.5
parent f3710af533
commit 726913e1cb
6 changed files with 61 additions and 32 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
'@e2e-dev/core': patch
---
Cached taps, hovers, and drags at a point recorded inside a control wait until the point lands inside that control on screen, so a drag waits for a late or hidden drop target, and a drag whose point alone tells an end apart from same-named controls stops if one of them leaves the visible area meanwhile.
Cached taps, hovers, and drags at a point recorded inside a control wait until the point lands inside that control on screen, so a drag waits for a late or hidden drop target, and a drag that waits for one end stops if a control named like the other end appears on screen or leaves it meanwhile.
+2 -2
View File
@@ -140,8 +140,8 @@ model calls:
ID, and surrounding context. e2e waits for controls to appear and stops
if a match is ambiguous. A tap, hover, or drag at a point recorded inside
a control waits until the point lands inside that control on screen, and
a drag whose point alone tells an end apart from same-named controls
stops if one of them leaves the visible area meanwhile.
a drag that waits for one end stops if a control named like the other
end appears on screen or leaves it meanwhile.
3. **Check the end state** (final route plus the controls that appeared,
disappeared, or changed state).
4. **Finish with zero model calls**, or hand off to the live agent with a
+25 -21
View File
@@ -510,22 +510,19 @@ interface Ends {
* before its point can be placed (mounted hidden, with no box yet, or
* outside the viewport) is still loading, whichever look it turns up on,
* and is waited for like one that is not listed. An endpoint its point picks
* out of look-alikes can wait for the other end. If its group loses a candidate
* during the wait, or it is re-found where its point
* cannot be placed, the drag stops.
* out of look-alikes, or that is unique, can wait for the other end. If its
* group gains or loses a candidate during the wait, or it is re-found where
* its point cannot be placed, the drag stops.
*
* That guard is a count of the endpoint's visible look-alikes, compared with
* the look before, as the `twinLeft` refusal is a count: an engine may
* renumber its nodes between looks, so nothing else tells them apart. It
* stops on purpose when the group grows and drops back (2, 3, 2) and when
* a twin stays listed but goes hidden: a control left, and it may have been
* the source. It cannot see a source and a twin that swap places at the
* same count; the recorded point then picks the twin, as it does among
* look-alikes on a single look (`placeWithin`). Nor does it stop when the
* group grows and stays grown: a same-named control that mounts under the
* recorded point while the drag waits, beside a unique visible end or a
* group of look-alikes, is picked by the point on the last look the same
* way.
* renumber its nodes between looks, so nothing else tells them apart. A
* control that joins the group may sit under the recorded point, where the
* point would pick it; one that leaves may have been the end. So it stops on
* purpose when a look-alike mounts anywhere on screen, and when a twin stays
* listed but goes hidden. It cannot see a source and a twin that swap places
* at the same count; the recorded point then picks the twin, as it does among
* look-alikes on a single look (`placeWithin`).
* Returns the last look judged; nothing when no look could be read.
*/
async function relocateEnds(
@@ -588,20 +585,27 @@ async function relocateEnds(
function pointGroupGuard(descriptor: TraceTargetDescriptor | undefined, places: ((relocated: Relocated) => boolean) | undefined) {
let countGroup: ReturnType<typeof relocationGroupCounter>;
let previousCount = 0;
let placeable: (node: RedactedNode | undefined) => boolean = () => false;
return (screen: SemanticScreen, end: Relocated | undefined, unplaced: boolean, waiting: boolean): boolean => {
if (countGroup === undefined && waiting && descriptor !== undefined && descriptor.position === undefined
&& end?.kind === 'failed' && end.failure === 'target-ambiguous' && places?.(end)) {
countGroup = relocationGroupCounter(descriptor, screen.nodes);
}
if (countGroup === undefined) return false;
const count = countGroup(screen.nodes, (node) => {
placeable = (node) => {
const box = visibleBox(node);
if (box === undefined) return false;
// The first whole pixel inside the box must still be available in this viewport.
const first = { x: Math.ceil(box.x), y: Math.ceil(box.y) };
return containsPoint(box, clampToViewport(first, screen.viewport));
});
const lost = unplaced || count < previousCount;
};
// A unique end found while the other loads counts too: a look-alike that joins it is the same risk as one that joins a group.
const picked = end?.kind === 'found' || (end?.kind === 'failed' && end.failure === 'target-ambiguous');
if (countGroup === undefined && waiting && descriptor !== undefined && descriptor.position === undefined
&& picked && places?.(end)) {
countGroup = relocationGroupCounter(descriptor, screen.nodes);
if (countGroup === undefined) return false;
previousCount = countGroup(screen.nodes, placeable);
return unplaced;
}
if (countGroup === undefined) return false;
const count = countGroup(screen.nodes, placeable);
const lost = unplaced || count !== previousCount;
previousCount = count;
return lost;
};
@@ -517,8 +517,33 @@ describe('replayTrace: bare-point drags', () => {
dragsFrom: { x: 100, y: 50 },
},
{
label: 'stops when the source group grows to three and drops back to two',
looks: [[card, twin], [card, twin, third], [moved, twin, lane]],
label: 'stops when the source group grows to three',
looks: [[card, twin], [card, twin, third]],
stops: 'target-ambiguous',
},
{
label: 'stops when a unique source gains a look-alike under the recorded point and moves away while the destination loads',
looks: [[card], [at(card, 700), twinInPlace, lane]],
stops: 'target-ambiguous',
},
{
label: 'stops on the look that look-alike shows, before the destination does',
looks: [[card], [at(card, 700), twinInPlace]],
stops: 'target-ambiguous',
},
{
label: 'stops when a unique source gains a look-alike anywhere while the destination loads, as nothing tells the two apart',
looks: [[card], [card, twin, lane]],
stops: 'target-ambiguous',
},
{
label: 'stops when the source group grows to three with the newcomer under the recorded point',
looks: [[card, twin], [at(card, 700), twin, as(card, 'new'), lane]],
stops: 'target-ambiguous',
},
{
label: 'stops when a visible drop target gains a look-alike under its recorded point while the source loads',
looks: [[hidden(card), lane], [card, at(lane, 900), as(lane, 'other')]],
stops: 'target-ambiguous',
},
{
+3 -3
View File
@@ -239,9 +239,9 @@ takes over from the current screen when the app no longer matches.
- A step that changes nothing on screen or in the route records nothing
and runs live every run.
- A cached tap, hover, or drag at a point recorded inside a control waits
until the point lands inside that control on screen, and a drag whose
point alone tells an end apart from same-named controls stops if one of
them leaves the visible area meanwhile.
until the point lands inside that control on screen, and a drag that
waits for one end stops if a control named like the other end appears on
screen or leaves it meanwhile.
- While you fix a test, keep the cache on so confirmed goals replay (topic
`debugging`, "Rerunning a test while you fix it"). Use `--no-cache` to
rule out a stale replay (topic `debugging`, "Tools") and for one live run
+3 -3
View File
@@ -239,9 +239,9 @@ takes over from the current screen when the app no longer matches.
- A step that changes nothing on screen or in the route records nothing
and runs live every run.
- A cached tap, hover, or drag at a point recorded inside a control waits
until the point lands inside that control on screen, and a drag whose
point alone tells an end apart from same-named controls stops if one of
them leaves the visible area meanwhile.
until the point lands inside that control on screen, and a drag that
waits for one end stops if a control named like the other end appears on
screen or leaves it meanwhile.
- While you fix a test, keep the cache on so confirmed goals replay (topic
`debugging`, "Rerunning a test while you fix it"). Use `--no-cache` to
rule out a stale replay (topic `debugging`, "Tools") and for one live run