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): survive redraws and retain Esc close reason [N26,C7]

Corey Olson113f2107408a
diff --git a/src/cockpit.js b/src/cockpit.js
index e49146ff..02670155 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -2322,6 +2322,8 @@ $('q').addEventListener('keydown', (event) => {
$('find-results').addEventListener('mousedown', (event) => { const hit = event.target.closest('[data-find]'); if (hit) { event.preventDefault(); openFound(hit.dataset.find); } });
$('q').addEventListener('blur', () => {
clearTimeout(closingFound);
+ // Esc and opening a result already close explicitly; their blur must keep that reason.
+ if ($('find-results').hidden) return;
closingFound = setTimeout(() => hideFound('left the field'), 120);
});
// "/" goes to the search from anywhere but a field.
diff --git a/test/cockpit/search.test.js b/test/cockpit/search.test.js
index fe36f966..7d0515d4 100644
--- a/test/cockpit/search.test.js
+++ b/test/cockpit/search.test.js
@@ -248,3 +248,38 @@ test('the search step names its state on timeout [N26]', { timeout: 60_000 }, as
await view.stop();
}
});
+
+
+test('search keeps focus through Esc [N26,C7]', { timeout: 120_000 }, async (t) => {
+ const executable = chromeExecutable();
+ if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for search-focus checks.');
+ const box = machine(), demo = project(box, 'search-focus');
+ box.run(demo.repo, 'add', 'web', 'Greeting focus proof', '--specs', 'G1', '--criterion', 'visible');
+ const view = await startView(box);
+ let chrome;
+ try {
+ chrome = await openSnapshotChrome(executable, view.link.href, join(box.dir, 'search-focus-chrome'));
+ await chrome.waitFor('data?.project?.items?.length === 1');
+ await chrome.stable(`(() => {
+ window.__searchFocus = [];
+ document.querySelector('#q').addEventListener('keydown', event => {
+ if (event.key === 'Escape') window.__searchFocus.push({ focused: document.activeElement.id, window: document.hasFocus(), key: event.key });
+ }, { capture: true });
+ })()`);
+ for (const width of [1280, 375]) {
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width, height: 900, deviceScaleFactor: 1, mobile: false });
+ await searchFor(chrome, 'Greeting');
+ assert.equal(await chrome.stable('document.activeElement.id'), 'q', `${width}: typing and settling results retain the search field's focus`);
+ for (const type of ['keyDown', 'keyUp']) await chrome.send('Input.dispatchKeyEvent', { type, key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 });
+ // budget: 120ms is the page's declared blur-close delay; observe after that callback can run.
+ await chrome.stable('new Promise(resolve => setTimeout(resolve, 120))');
+ const result = await chrome.stable(`({ focus: window.__searchFocus.at(-1), value: document.querySelector('#q').value, hidden: document.querySelector('#find-results').hidden, why: document.querySelector('#find-results').dataset.why })`);
+ assert.equal(result.focus?.focused, 'q', `${width}: Escape is actually delivered while the search field is focused`);
+ assert.equal(result.focus?.key, 'Escape');
+ assert.deepEqual([result.value, result.hidden, result.why], ['', true, 'escape'], `${width}: Escape's own blur does not replace its close reason`);
+ }
+ } finally {
+ if (chrome) await closeSnapshotChrome(chrome);
+ await view.stop();
+ }
+});
diff --git a/test/cockpit/shared-wait.test.js b/test/cockpit/shared-wait.test.js
index f5921ac6..0d15919c 100644
--- a/test/cockpit/shared-wait.test.js
+++ b/test/cockpit/shared-wait.test.js
@@ -163,3 +163,47 @@ test('real Chrome retains reduced motion and jumps both detail panes without ani
await view.stop();
}
});
+
+
+test('the shared wait survives a redrawn element [N26,C7]', { timeout: 120_000 }, async (t) => {
+ const executable = chromeExecutable();
+ if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for redraw checks.');
+ const box = machine();
+ project(box, 'redrawn-target');
+ const view = await startView(box);
+ let chrome;
+ try {
+ chrome = await openSnapshotChrome(executable, view.link.href, join(box.dir, 'redrawn-chrome'));
+ await chrome.waitFor('!!data?.project');
+ await chrome.stable(`(() => {
+ const button = document.createElement('button'); button.id = 'redrawn-proof'; button.textContent = 'Redrawn target';
+ button.style.cssText = 'position:fixed;top:180px;left:20px;width:160px;height:44px'; document.body.append(button);
+ window.__redrawSamples = 0; window.__redrawGap = false;
+ })()`);
+ // Resolve the real target each frame. The first sample detaches it; the second sees the same
+ // null.closest gap as macOS CI, before the replacement is inserted on the following frame.
+ const find = `(() => {
+ const node = document.querySelector('#redrawn-proof'); window.__redrawSamples++;
+ if (window.__redrawSamples === 1) {
+ node.remove();
+ requestAnimationFrame(() => requestAnimationFrame(() => {
+ const replacement = node.cloneNode(true); replacement.dataset.replaced = 'yes'; document.body.append(replacement);
+ }));
+ }
+ if (!node) window.__redrawGap = true;
+ return node.closest('button');
+ })()`;
+ await assert.doesNotReject(() => waitForStableBoxes(chrome, find), 'a disappearing selector is sampled again until its replacement settles');
+ assert.deepEqual(await chrome.stable(`[window.__redrawGap, document.querySelector('#redrawn-proof').dataset.replaced, window.__redrawSamples >= 4]`), [true, 'yes', true]);
+ const missing = `document.querySelector('#never-redrawn-proof').closest('button')`;
+ // budget: this deliberately missing target's short deadline bounds the diagnostic control.
+ await assert.rejects(() => waitForStableBoxes(chrome, missing, 100), error => {
+ assert.match(error.message, /never-redrawn-proof/, 'the timeout names the selector');
+ assert.match(error.message, /last saw.*(?:TypeError|closest|null)/i, 'the timeout retains the last failed sample');
+ return true;
+ });
+ } finally {
+ if (chrome) await closeSnapshotChrome(chrome);
+ await view.stop();
+ }
+});
diff --git a/test/cockpit/stable.js b/test/cockpit/stable.js
index 85d25197..b890266f 100644
--- a/test/cockpit/stable.js
+++ b/test/cockpit/stable.js
@@ -23,20 +23,24 @@ export async function waitForStableBoxes(chrome, find = 'document.documentElemen
const visible = element => { const style = getComputedStyle(element), box = element.getBoundingClientRect(); return !element.closest('[hidden]') && style.display !== 'none' && style.visibility !== 'hidden' && box.width > 0 && box.height > 0; };
/** Compare exact layout geometry without tolerances that hide movement. */
const box = element => { const rect = element.getBoundingClientRect(); return [rect.x, rect.y, rect.width, rect.height]; };
+ let lastSeen = 'no frame sampled';
/** Capture required targets, descendants and page extents in one layout sample. */
const sample = () => {
const required = targets();
- if (!required.length || !required.every(element => element.isConnected && visible(element))) return null;
+ lastSeen = required.length ? JSON.stringify(required.map(element => element instanceof Element
+ ? { tag: element.tagName, id: element.id, connected: element.isConnected, hidden: !!element.closest('[hidden]'), box: box(element) }
+ : { target: String(element) })) : 'no matching target';
+ if (!required.length || !required.every(element => element instanceof Element && element.isConnected && visible(element))) return null;
const elements = [...document.querySelectorAll('body, body *')].filter(visible);
return { targets: required.map(box), page: [scrollX, scrollY, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.scrollHeight, ...elements.map(box)] };
};
return await new Promise((resolve, reject) => {
let previous = '', unchanged = 0, frameId = 0;
- const timer = setTimeout(() => { cancelAnimationFrame(frameId); reject(Error('shared wait: target missing, zero-sized or moving: ' + ${JSON.stringify(find)})); }, ${timeoutMs});
+ const timer = setTimeout(() => { cancelAnimationFrame(frameId); reject(Error('shared wait: target missing, zero-sized or moving: ' + ${JSON.stringify(find)} + '; last saw ' + lastSeen)); }, ${timeoutMs});
/** Resolve only after two complete frame intervals have unchanged nonzero geometry. */
const frame = () => {
let current;
- try { current = sample(); } catch (error) { clearTimeout(timer); reject(error); return; }
+ try { current = sample(); } catch (error) { current = null; lastSeen = error.name + ': ' + error.message; }
const signature = current ? JSON.stringify(current) : '';
unchanged = signature && signature === previous ? unchanged + 1 : 0;
previous = signature;