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.

fix(view): capture boxes above targets by layout [N26,C7]

Corey Olsond6c6991d1bb6
diff --git a/test/cockpit/demo.test.js b/test/cockpit/demo.test.js
index 3f14a11e..3a48ef4a 100644
--- a/test/cockpit/demo.test.js
+++ b/test/cockpit/demo.test.js
@@ -345,11 +345,21 @@ async function armLaneReleaseCapture(chrome, selector, stableRoot = "document.qu
entry.transitions++;
if (!entry.types.includes(type)) entry.types.push(type);
};
- /** Compare every preceding element, including hidden panels that could become visible in a refresh. */
+ /** Select by rendered position; retain earlier observations when a box moves below the target. */
+ const observedNodes = target => {
+ if (!target) return [];
+ const targetTop = target.getBoundingClientRect().top;
+ return [...document.body.querySelectorAll('*')].filter(node => {
+ if (node === target) return true;
+ if (node.contains(target)) return false;
+ const rect = node.getBoundingClientRect();
+ return prior.has(name(node).node) || (rect.width > 0 && rect.height > 0 && rect.top < targetTop);
+ });
+ };
+ /** Compare boxes above the target, including hidden panels that could become visible in a refresh. */
const sample = (type, point = null) => {
const target = document.querySelector(${JSON.stringify(selector)}), targetBox = target ? box(target) : null;
- const nodes = target ? [...document.body.querySelectorAll('*')].filter(node => node === target
- || (!node.contains(target) && !!(node.compareDocumentPosition(target) & Node.DOCUMENT_POSITION_FOLLOWING))) : [];
+ const nodes = observedNodes(target);
if (nodes.length > 2000) dropped.nodeLimit += nodes.length - 2000;
for (const node of nodes.slice(0, 2000)) {
const now = box(node), old = prior.get(now.node);
@@ -370,9 +380,7 @@ async function armLaneReleaseCapture(chrome, selector, stableRoot = "document.qu
append(events, { type, at: performance.now(), scrollX, scrollY, target: targetBox,
point, activeElement: name(document.activeElement) }, 160, 'eventLimit');
};
- const initial = [...document.body.querySelectorAll('*')].filter(node => node === target
- || (!node.contains(target) && !!(node.compareDocumentPosition(target) & Node.DOCUMENT_POSITION_FOLLOWING)))
- .slice(0, 2000).map(box);
+ const initial = observedNodes(target).slice(0, 2000).map(box);
for (const entry of initial) prior.set(entry.node, entry);
/** Observe native pointer boundaries before the shared press rechecks its aimed point. */
const listener = event => sample(event.type, Number.isFinite(event.clientX)
@@ -1167,3 +1175,98 @@ test('a removed lane-release target still cleans up its capture [N26,C7]', {
rmSync(profile, { recursive: true, force: true });
}
});
+
+test('a moved press target names a rendered-above box later in DOM order [N26,C7]', {
+ timeout: 120_000, // budget: hang-only ceiling for real Chrome startup and one deterministic pointer-movement capture.
+}, async (t) => {
+ const executable = chromeExecutable();
+ if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for the moved-press capture.');
+
+ const box = machine();
+ project(box, 'moved-press-capture');
+ const view = await startView(box);
+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-moved-press-'));
+ let chrome;
+ try {
+ chrome = await openSnapshotChrome(executable, view.link.href, profile);
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 375, height: 900, deviceScaleFactor: 1, mobile: false });
+ await chrome.waitFor("innerWidth === 375 && document.readyState === 'complete' && !!document.querySelector('#lanes')");
+ await chrome.stable(`(() => {
+ const standIn = document.createElement('div');
+ standIn.id = 'press-move-stand-in';
+ standIn.style.cssText = 'height:18px;background:#ddd;overflow-anchor:none';
+ const target = document.createElement('button');
+ target.id = 'press-move-target';
+ target.type = 'button';
+ target.textContent = 'Press target';
+ target.style.cssText = 'display:block;height:44px;overflow-anchor:auto';
+ const spacer = document.createElement('div');
+ spacer.style.cssText = 'height:1100px;overflow-anchor:none';
+ const group = document.createElement('div');
+ group.style.cssText = 'display:flex;flex-direction:column;overflow-anchor:auto';
+ standIn.style.order = '-1';
+ target.style.order = '0';
+ group.append(target, standIn);
+ document.body.prepend(spacer, group);
+ let grew = false;
+ const growAboveTarget = event => {
+ if (!grew && event.target === target) {
+ grew = true;
+ standIn.style.height = '98px';
+ }
+ };
+ document.addEventListener('pointermove', growAboveTarget, true);
+ window.__pressMoveFixture = { grew: () => grew, cleanup() {
+ document.removeEventListener('pointermove', growAboveTarget, true);
+ spacer.remove(); group.remove(); delete window.__pressMoveFixture;
+ } };
+ return { standIn: standIn.id, target: target.id };
+ })()`);
+ const order = JSON.parse(await chrome.stable(`JSON.stringify((() => {
+ const above = document.querySelector('#press-move-stand-in');
+ const target = document.querySelector('#press-move-target');
+ return { above: above.getBoundingClientRect().bottom <= target.getBoundingClientRect().top,
+ later: Boolean(target.compareDocumentPosition(above) & Node.DOCUMENT_POSITION_FOLLOWING) };
+ })())`));
+ assert.deepEqual(order, { above: true, later: true }, 'the box renders above the target despite following it in DOM order');
+ const captureSetup = await armLaneReleaseCapture(chrome, '#press-move-target', 'document.documentElement');
+ assert.equal(captureSetup.armed, true, `the named stand-in target is present before the shared press: ${JSON.stringify({ armed: captureSetup.armed, error: captureSetup.error ?? null })}`);
+ let pressError = null;
+ try { await press(chrome, "document.querySelector('#press-move-target')"); }
+ catch (error) { pressError = error; }
+ const capture = await finishLaneReleaseCapture(chrome, captureSetup);
+ const fixture = JSON.parse(await chrome.stable('JSON.stringify({ grew: window.__pressMoveFixture?.grew() ?? false })'));
+ const changed = capture.page?.changedNodes ?? [];
+ const moved = changed.find(node => node.node?.id === 'press-move-stand-in');
+ const captureDetail = { capture, captureError: null };
+ if (pressError) includeLaneReleaseCapture(pressError, captureDetail);
+ const failureText = `${pressError?.message ?? 'shared press unexpectedly completed without an error'}; lane-release capture: ${JSON.stringify(captureDetail)}`;
+ assert.ok(fixture.grew, 'the stand-in box grows during the shared press pointer movement');
+ assert.ok(pressError, 'the unchanged shared press refuses the moved target instead of clicking it');
+ assert.equal(pressError.code, 'ERR_ASSERTION', `the shared press keeps its native assertion failure: ${pressError.message}`);
+ assert.match(pressError.message, /shared press: target stays under the pointer/,
+ `the refusal comes from the shared press geometry guard: ${pressError.message}`);
+ assert.equal(capture.pageError, null, `the page capture finishes without a probe error: ${failureText}`);
+ assert.equal(capture.page?.armed, true, `the capture returns its completed page observations: ${failureText}`);
+ assert.ok(moved, `the failure capture names the changed box and its old/new geometry: ${failureText}`);
+ assert.equal(moved.first.id, 'press-move-stand-in', `the captured old box is the named stand-in: ${failureText}`);
+ assert.ok([moved.first.top, moved.first.height, moved.last.top, moved.last.height].every(Number.isFinite),
+ `the named box has finite old/new top and height measurements: ${failureText}`);
+ assert.notEqual(moved.first.height, moved.last.height, `the captured stand-in height changed: ${failureText}`);
+ assert.ok(capture.page.changedNodes.length <= 10 && Number.isInteger(capture.page.truncated.remainingChangedNodes),
+ `the failure capture caps box details at ten and counts the remainder: ${failureText}`);
+ assert.ok(Number.isFinite(capture.page.scrollY.before) && Number.isFinite(capture.page.scrollY.after),
+ `the failure capture records scroll positions even when flex layout moves the target without scrolling: ${failureText}`);
+ assert.match(pressError.message, /lane-release capture: .*press-move-stand-in.*scrollY.*before.*after/s,
+ `the failed press message carries the changed box and scroll positions: ${failureText}`);
+ assert.match(pressError.message, /remainingChangedNodes/, `the failure message reports the count of other changed boxes: ${failureText}`);
+ assert.ok(Object.hasOwn(capture.page, 'scrollAnchoring'), `the capture records whether Chromium reported an anchor: ${failureText}`);
+ } finally {
+ if (chrome) {
+ await chrome.stable('window.__pressMoveFixture?.cleanup()').catch(() => undefined);
+ await closeSnapshotChrome(chrome);
+ }
+ await view.stop();
+ rmSync(profile, { recursive: true, force: true });
+ }
+});