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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(view): a search straight after Esc keeps its results [N26]
Corey Olsonc6d85dbefd2c
diff --git a/src/cockpit.js b/src/cockpit.jsindex f747e72f..2b755999 100644--- a/src/cockpit.js+++ b/src/cockpit.js@@ -1692,11 +1692,18 @@ function showFound() {+ list.slice(0, 5).map((hit) => '<button class="find-hit' + (n++ === view.foundAt ? ' on' : '') + '" data-find="' + esc(hit.go) + '" type="button" role="option"><code>' + esc(hit.id) + '</code><span>' + esc(hit.text) + '</span><small>' + esc(hit.note) + '</small></button>').join('')).join(''): '<div class="find-empty">Nothing on this board matches “' + esc(words.trim()) + '”.</div>';box.hidden = !words.trim();+ box.dataset.why = box.hidden ? 'no words' : '';+}++/** Put the search's results away, and say why on the box, so whoever finds them gone can name what closed them. */+function hideFound(why) {+ $('find-results').hidden = true;+ $('find-results').dataset.why = why;}/** Open what a result names, and put the results away. */function openFound(target) {- $('find-results').hidden = true;+ hideFound('opened');$('q').blur();go(target);}@@ -2115,16 +2122,22 @@ $('theme').addEventListener('click', () => {theme(next);});$('q').addEventListener('input', () => { search(); view.foundAt = 0; showFound(); });-$('q').addEventListener('focus', () => { if ($('q').value.trim()) showFound(); });+// Leaving the field closes the results a moment later, so a press on a result lands first; coming back to the field+// before then keeps them, or a search begun straight after Esc would lose its new results to the old close.+let closingFound = 0;+$('q').addEventListener('focus', () => { clearTimeout(closingFound); if ($('q').value.trim()) showFound(); });$('q').addEventListener('keydown', (event) => {- if (event.key === 'Escape') { $('q').value = ''; search(); $('find-results').hidden = true; $('q').blur(); return; }+ if (event.key === 'Escape') { $('q').value = ''; search(); hideFound('escape'); $('q').blur(); return; }if (!view.found?.length || $('find-results').hidden) return;if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { event.preventDefault(); view.foundAt = (view.foundAt + (event.key === 'ArrowDown' ? 1 : view.found.length - 1)) % view.found.length; showFound(); }else if (event.key === 'Enter') { event.preventDefault(); openFound(view.found[view.foundAt].go); }});// A press on a result opens it before the field loses focus and the results close.$('find-results').addEventListener('mousedown', (event) => { const hit = event.target.closest('[data-find]'); if (hit) { event.preventDefault(); openFound(hit.dataset.find); } });-$('q').addEventListener('blur', () => setTimeout(() => { $('find-results').hidden = true; }, 120));+$('q').addEventListener('blur', () => {+ clearTimeout(closingFound);+ closingFound = setTimeout(() => hideFound('left the field'), 120);+});// "/" goes to the search from anywhere but a field.document.addEventListener('keydown', (event) => {if (event.key !== '/' || event.metaKey || event.ctrlKey || event.altKey || event.target.closest('input, textarea, select, [contenteditable]')) return;diff --git a/test/cockpit.test.js b/test/cockpit.test.jsindex 109ef605..16af858c 100644--- a/test/cockpit.test.js+++ b/test/cockpit.test.js@@ -7573,6 +7573,25 @@ test("a waiting ask's who and when stay on one line with wide fonts [N26]", { ti}});+/**+ * Type words into the view's top-bar search as a keyboard does, from an empty field, and wait for their results. On a+ * timeout it names the stage it stopped at: the field's value, what has focus, whether the page has window focus, and+ * whether the results are hidden and what closed them (#394).+ */+async function searchFor(chrome, words, timeoutMs) {+ await chrome.evaluate("document.querySelector('#q').focus(); document.querySelector('#q').select()");+ await chrome.send('Input.insertText', { text: words });+ try {+ await chrome.waitFor(`document.querySelector('#q').value === ${JSON.stringify(words)} && !document.querySelector('#find-results').hidden`, timeoutMs);+ } catch (error) {+ const state = await chrome.evaluate(`JSON.stringify((() => {+ const q = document.querySelector('#q'), results = document.querySelector('#find-results'), at = document.activeElement;+ return { value: q.value, focused: at ? (at.id ? '#' + at.id : at.tagName.toLowerCase()) : null, windowFocus: document.hasFocus(), resultsHidden: results.hidden, closedBy: results.dataset.why || null };+ })())`);+ throw new Error(`the search for ${JSON.stringify(words)} did not show its results: ${state}`, { cause: error });+ }+}+test('search in the top bar finds anything on the board [N26]', { timeout: 150_000 }, async (t) => {const executable = chromeExecutable();if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for search checks.');@@ -7611,12 +7630,7 @@ test('search in the top bar finds anything on the board [N26]', { timeout: 150_0const point = JSON.parse(await chrome.evaluate(`(() => { const r = document.querySelector(${JSON.stringify(selector)}).getBoundingClientRect(); return JSON.stringify({ x: r.x + r.width / 2, y: r.y + r.height / 2 }); })()`));for (const type of ['mousePressed', 'mouseReleased']) await chrome.send('Input.dispatchMouseEvent', { type, ...point, button: 'left', clickCount: 1 });};- /** Type the words into the search as a keyboard does, from an empty field. */- const search = async (words) => {- await chrome.evaluate("document.querySelector('#q').focus(); document.querySelector('#q').select()");- await chrome.send('Input.insertText', { text: words });- await chrome.waitFor(`document.querySelector('#q').value === ${JSON.stringify(words)} && !document.querySelector('#find-results').hidden`);- };+ const search = (words) => searchFor(chrome, words);try {chrome = await openSnapshotChrome(executable, view.link.href, profile);await chrome.waitFor("typeof data === 'object' && data?.project?.items?.length === 8 && data.project.shouts.length >= 2");@@ -7652,6 +7666,19 @@ test('search in the top bar finds anything on the board [N26]', { timeout: 150_0}}+ // A search begun straight after Esc keeps its results: leaving the field closes them a moment later, and coming back+ // before then must not let that close take the new ones (CI lost them this way between searches, #394).+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });+ await chrome.waitFor('innerWidth === 1280');+ await search('greeting');+ await key('Escape', 'Escape', 27);+ await search('greeting');+ await chrome.evaluate('new Promise((done) => setTimeout(done, 250))');+ const kept = JSON.parse(await chrome.evaluate("JSON.stringify([document.querySelector('#q').value, document.activeElement.id, document.querySelector('#find-results').hidden])"));+ assert.deepEqual(kept, ['greeting', 'q', false], `a search straight after Esc keeps its results (words, focus, results hidden): ${JSON.stringify(kept)}`);+ await key('Escape', 'Escape', 27);+ assert.equal(await chrome.evaluate("document.querySelector('#find-results').dataset.why"), 'escape', 'Esc closes the results and says so');+// The arrows move the highlight and Enter opens it: here the third item, the third newest.await chrome.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });await chrome.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: 'light' }] });@@ -7874,3 +7901,38 @@ test('shout cards fit beside a classic scrollbar [N26]', { timeout: 120_000 }, aawait view.stop();}});++test('the search step names its state on timeout [N26]', { timeout: 60_000 }, async (t) => {+ const executable = chromeExecutable();+ if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for search checks.');+ const box = machine();+ const alpha = project(box, 'stalled-search');+ box.run(alpha.repo, 'add', 'web', 'Greeting', '--specs', 'G1', '--criterion', 'greets');+ const view = await startView(box);+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-stalled-search-chrome-'));+ let chrome;+ /** The record a timed-out search step carries, read from its message. */+ const record = (error) => JSON.parse(error.message.slice(error.message.indexOf('{')));+ try {+ chrome = await openSnapshotChrome(executable, view.link.href, profile);+ await chrome.waitFor("typeof data === 'object' && data?.project?.items?.length === 1");+ // A field that takes no typing: the step times out, and its message says how far the search got.+ await chrome.evaluate("document.querySelector('#q').disabled = true");+ let stalled;+ await assert.rejects(searchFor(chrome, 'greeting', 1_500), (error) => { stalled = error; return true; });+ assert.match(stalled.message, /^the search for "greeting" did not show its results: \{/, 'the step says which search stalled');+ assert.deepEqual(Object.keys(record(stalled)), ['value', 'focused', 'windowFocus', 'resultsHidden', 'closedBy'], 'it records the value, the focus, the window focus, and the results with what closed them');+ assert.deepEqual([record(stalled).value, record(stalled).focused, typeof record(stalled).windowFocus, record(stalled).resultsHidden], ['', 'body', 'boolean', true], `no words reached the field, which never had focus: ${stalled.message}`);+ // Results that showed and were then closed say what closed them: here, leaving the field.+ await chrome.evaluate("document.querySelector('#q').disabled = false");+ await searchFor(chrome, 'greeting');+ await chrome.evaluate("document.querySelector('#q').blur()");+ await chrome.waitFor("document.querySelector('#find-results').hidden");+ assert.equal(await chrome.evaluate("document.querySelector('#find-results').dataset.why"), 'left the field', 'leaving the field closes the results and says so');+ assert.deepEqual(chrome.exceptions, [], 'the page raises no uncaught exception');+ } finally {+ if (chrome) await closeSnapshotChrome(chrome);+ rmSync(profile, { recursive: true, force: true });+ await view.stop();+ }+});