Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

test(view): settle scrolling before prerequisite clicks [N26]

Corey Olsone80c04a84a28
diff --git a/test/cockpit.test.js b/test/cockpit.test.js
index f776d4a6..4db7547b 100644
--- a/test/cockpit.test.js
+++ b/test/cockpit.test.js
@@ -3065,25 +3065,67 @@ test('wait references stay on one line and link to every prerequisite at phone a
let chrome;
try {
chrome = await openSnapshotChrome(executable, view.link.href, join(box.dir, 'waits-chrome'));
- /** Click a rendered prerequisite link through the same Chrome input path as a person. */
+ /** Pick a visible click target only after scrolling and its hit-test position have settled. */
const click = async (selector) => {
- await chrome.waitFor(`(() => {
+ const point = JSON.parse(await chrome.evaluate(`(async () => {
const element=document.querySelector(${JSON.stringify(selector)});
- if (!element) return false;
+ if (!element) throw Error('missing '+${JSON.stringify(selector)});
+ const visible=()=>{const style=getComputedStyle(element),rect=element.getBoundingClientRect();return style.display!=='none'&&style.visibility!=='hidden'&&rect.width>0&&rect.height>0&&!element.closest('[hidden]');};
+ if(!visible())throw Error('target is not visible: '+${JSON.stringify(selector)});
element.scrollIntoView({block:'center'});
- const rect=element.getBoundingClientRect();
- const hit=document.elementFromPoint(rect.x+rect.width/2,rect.y+rect.height/2);
- return rect.width > 0 && rect.height > 0 && !!hit && (hit === element || element.contains(hit));
- })()`);
- const point = JSON.parse(await chrome.evaluate(`(() => {
- const element=document.querySelector(${JSON.stringify(selector)});
- element.scrollIntoView({block:'center'});
- const rect=element.getBoundingClientRect();
- return JSON.stringify({x:rect.x+rect.width/2,y:rect.y+rect.height/2});
+ const point=()=>{const currentElement=document.querySelector(${JSON.stringify(selector)});if(!currentElement)return null;const style=getComputedStyle(currentElement),rect=currentElement.getBoundingClientRect();if(style.display==='none'||style.visibility==='hidden'||rect.width<=0||rect.height<=0||currentElement.closest('[hidden]'))return null;const x=rect.x+rect.width/2,y=rect.y+rect.height/2,hit=document.elementFromPoint(x,y);return {x,y,scrollX,scrollY,rect:{x:rect.x,y:rect.y,width:rect.width,height:rect.height},hit:!!hit&&(hit===currentElement||currentElement.contains(hit))};};
+ const targets=[window,document,...(()=>{const nodes=[];for(let node=element.parentElement;node;node=node.parentElement)if(node.scrollHeight>node.clientHeight||node.scrollWidth>node.clientWidth)nodes.push(node);return nodes;})()];
+ let scrolled=false,scrollEnded=false;
+ const onScroll=()=>{scrolled=true;};
+ const onScrollEnd=()=>{scrollEnded=true;};
+ targets.forEach(target=>{target.addEventListener('scroll',onScroll,{passive:true});target.addEventListener('scrollend',onScrollEnd);});
+ try {
+ return JSON.stringify(await new Promise((resolve,reject)=>{
+ let previous=null,stable=0,frameId=0,finished=false;
+ const timeout=setTimeout(()=>{finished=true;cancelAnimationFrame(frameId);reject(Error('scroll did not settle for '+${JSON.stringify(selector)}+': '+JSON.stringify(previous)));},5000);
+ const frame=()=>{
+ if(finished)return;
+ const current=point();
+ if(!current){previous=null;stable=0;frameId=requestAnimationFrame(frame);return;}
+ const same=previous&&Math.abs(current.scrollX-previous.scrollX)<=.1&&Math.abs(current.scrollY-previous.scrollY)<=.1&&Math.abs(current.rect.x-previous.rect.x)<=.1&&Math.abs(current.rect.y-previous.rect.y)<=.1&&Math.abs(current.rect.width-previous.rect.width)<=.1&&Math.abs(current.rect.height-previous.rect.height)<=.1;
+ stable=same?stable+1:0;previous=current;
+ if(stable>=3&&current.hit&&(!scrolled||scrollEnded||stable>=12)){finished=true;clearTimeout(timeout);resolve(current);return;}
+ frameId=requestAnimationFrame(frame);
+ };
+ frameId=requestAnimationFrame(frame);
+ }));
+ } finally { targets.forEach(target=>{target.removeEventListener('scroll',onScroll);target.removeEventListener('scrollend',onScrollEnd);}); }
})()`));
- await chrome.send('Input.dispatchMouseEvent', { type: 'mouseMoved', ...point });
- await chrome.send('Input.dispatchMouseEvent', { type: 'mousePressed', ...point, button: 'left', clickCount: 1 });
- await chrome.send('Input.dispatchMouseEvent', { type: 'mouseReleased', ...point, button: 'left', clickCount: 1 });
+ const deadline = Date.now() + 5000;
+ let ready;
+ let settled = false;
+ while (Date.now() < deadline) {
+ ready = JSON.parse(await chrome.evaluate(`(async()=>{
+ const sample=()=>{const element=document.querySelector(${JSON.stringify(selector)});if(!element)return null;const style=getComputedStyle(element),rect=element.getBoundingClientRect();if(style.display==='none'||style.visibility==='hidden'||rect.width<=0||rect.height<=0||element.closest('[hidden]'))return null;const x=rect.x+rect.width/2,y=rect.y+rect.height/2,hit=document.elementFromPoint(x,y);return {x,y,scrollX,scrollY,rect:{x:rect.x,y:rect.y,width:rect.width,height:rect.height},hit:!!hit&&(hit===element||element.contains(hit))};};
+ let previous=null,stable=0,current=null,frameId=0,finished=false;
+ await new Promise((resolve,reject)=>{const timeout=setTimeout(()=>{finished=true;cancelAnimationFrame(frameId);reject(Error('pointer target did not stabilize for '+${JSON.stringify(selector)}));},1500);const frame=()=>{if(finished)return;current=sample();const same=current&&previous&&Math.abs(current.scrollX-previous.scrollX)<=.1&&Math.abs(current.scrollY-previous.scrollY)<=.1&&Math.abs(current.rect.x-previous.rect.x)<=.1&&Math.abs(current.rect.y-previous.rect.y)<=.1&&Math.abs(current.rect.width-previous.rect.width)<=.1&&Math.abs(current.rect.height-previous.rect.height)<=.1;stable=same?stable+1:0;previous=current;if(stable>=2&&current.hit){finished=true;clearTimeout(timeout);resolve();}else frameId=requestAnimationFrame(frame);};frameId=requestAnimationFrame(frame);});
+ return JSON.stringify(current);
+ })()`));
+ await chrome.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: ready.x, y: ready.y });
+ const underPointer = JSON.parse(await chrome.evaluate(`(async()=>{
+ const sample=()=>{const element=document.querySelector(${JSON.stringify(selector)});if(!element)return null;const rect=element.getBoundingClientRect(),hit=document.elementFromPoint(${ready.x},${ready.y});return {scrollX,scrollY,rect:{x:rect.x,y:rect.y,width:rect.width,height:rect.height},hit:!!hit&&(hit===element||element.contains(hit))};};
+ let previous=null,stable=0,current=null,frameId=0,finished=false;
+ await new Promise((resolve,reject)=>{const timeout=setTimeout(()=>{finished=true;cancelAnimationFrame(frameId);reject(Error('pointer target did not stabilize for '+${JSON.stringify(selector)}));},1000);const frame=()=>{if(finished)return;current=sample();const same=current&&previous&&Math.abs(current.scrollX-previous.scrollX)<=.1&&Math.abs(current.scrollY-previous.scrollY)<=.1&&Math.abs(current.rect.x-previous.rect.x)<=.1&&Math.abs(current.rect.y-previous.rect.y)<=.1&&Math.abs(current.rect.width-previous.rect.width)<=.1&&Math.abs(current.rect.height-previous.rect.height)<=.1;stable=same?stable+1:0;previous=current;if(stable>=2&&current.hit){finished=true;clearTimeout(timeout);resolve();}else frameId=requestAnimationFrame(frame);};frameId=requestAnimationFrame(frame);});return JSON.stringify({current,stable});
+ })()`));
+ if (underPointer?.current?.hit && underPointer.stable >= 2 && Math.abs(underPointer.current.scrollX-ready.scrollX)<=.1 && Math.abs(underPointer.current.scrollY-ready.scrollY)<=.1 && Math.abs(underPointer.current.rect.x-ready.rect.x)<=.1 && Math.abs(underPointer.current.rect.y-ready.rect.y)<=.1 && Math.abs(underPointer.current.rect.width-ready.rect.width)<=.1 && Math.abs(underPointer.current.rect.height-ready.rect.height)<=.1) {
+ point.x = ready.x;
+ point.y = ready.y;
+ point.scrollX = ready.scrollX;
+ point.scrollY = ready.scrollY;
+ point.rect = ready.rect;
+ settled = true;
+ break;
+ }
+ }
+ assert.ok(settled && ready && point.x === ready.x && point.y === ready.y,
+ `${selector}: scroll and target geometry settle under the pointer before press: ${JSON.stringify({ point, ready })}`);
+ await chrome.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: point.x, y: point.y, button: 'left', clickCount: 1 });
+ await chrome.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: point.x, y: point.y, button: 'left', clickCount: 1 });
};
for (const width of [375, 1280]) {
await chrome.send('Emulation.setDeviceMetricsOverride', { width, height: 900, deviceScaleFactor: 1, mobile: false });