graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Expect and confirm the tab-close dialog in GUI harnesses
Cursor Agentb44db928c128
diff --git a/apps/native/electron/attachment-lifetime-frontend.cjs b/apps/native/electron/attachment-lifetime-frontend.cjsindex aec09f54..d8a0f23b 100644--- a/apps/native/electron/attachment-lifetime-frontend.cjs+++ b/apps/native/electron/attachment-lifetime-frontend.cjs@@ -2,6 +2,7 @@const assert = require('node:assert/strict');const fs = require('node:fs'), path = require('node:path');const { nativeImage } = require('electron');+const { confirmCloseDialog } = require('./close-confirm-harness.cjs');async function runAttachments({win,origin,temp,output,requests,workspace,send,click,until,report}) {const wc = win.webContents, js = code => wc.executeJavaScript(code);if(await js(`!!document.querySelector('[aria-label="Close browser"]')`))await click('[aria-label="Close browser"]');@@ -121,6 +122,8 @@ async function runAttachments({win,origin,temp,output,requests,workspace,send,classert.ok(fs.readFileSync(archivedTranscript,'utf8').includes(path.basename(aged)),'Archived replay must retain its image reference');assert.ok(fs.existsSync(path.join(savedDirectory,'archived',archiveName+'.session.json')));await click('[data-tab-id]:has(button[aria-pressed="true"]) [aria-label="Close tab"]');+ // The image turn's worker is still enrolled, so the close asks first.+ await confirmCloseDialog({ js, click, until });if(await js(`!!document.querySelector('[aria-label="Expand sidebar"]')?.checkVisibility()`))await click('[aria-label="Expand sidebar"]');else if(await js(`!!document.querySelector('[aria-label="Open navigation"]')?.checkVisibility()`))await click('[aria-label="Open navigation"]');const savedRow = '#sidebar-chat-list button[data-session-name=' + JSON.stringify(savedName.replace(/\.session\.json$/, '')) + ']';diff --git a/apps/native/electron/close-confirm-harness.cjs b/apps/native/electron/close-confirm-harness.cjsnew file mode 100644index 00000000..7b125f7a--- /dev/null+++ b/apps/native/electron/close-confirm-harness.cjs@@ -0,0 +1,50 @@+// Closing a tab that owns a live `graff acp` worker opens CloseConfirmDialog+// ("Close tab" / "Close N tabs") instead of closing. GUI harnesses must expect+// the dialog and confirm it; asserting it appears doubles as feature coverage.+const assert = require('node:assert/strict');++// No other dialog labels itself "Close …", so this names the confirmation.+const DIALOG = '[role="dialog"][aria-label^="Close "]';++// The confirm button's text is the dialog's own title ("Close tab" or+// "Close N tabs"); Cancel reads "Cancel" and the header X has no text.+const CONFIRM_FINDER = `(dialog => {+ const confirm = Array.from(dialog.querySelectorAll('button'))+ .find(button => (button.textContent || '').trim() === dialog.getAttribute('aria-label'));+ return confirm || null;+})`;++async function expectCloseDialog(js, until) {+ await until(() => js(`!!document.querySelector(${JSON.stringify(DIALOG)})`), 'close confirmation dialog');+ const label = await js(`document.querySelector(${JSON.stringify(DIALOG)}).getAttribute('aria-label')`);+ assert.match(label, /^Close (tab|\d+ tabs)$/, 'Confirmation names the tabs it closes');+ return label;+}++// Expect the dialog, confirm it through the real pointer path, wait for dismissal.+async function confirmCloseDialog({ js, click, until }) {+ await expectCloseDialog(js, until);+ const tagged = await js(`(() => {+ const dialog = document.querySelector(${JSON.stringify(DIALOG)});+ const confirm = dialog && (${CONFIRM_FINDER})(dialog);+ if (!confirm) return false;+ confirm.setAttribute('data-close-confirm', 'true');+ return true;+ })()`);+ assert.equal(tagged, true, 'Confirmation owns a confirm button');+ await click('[data-close-confirm="true"]');+ await until(() => js(`!document.querySelector('[role="dialog"]')`), 'close confirmation dismissed');+}++// Benchmark variant: that suite has no pointer helper and already clicks in-page.+async function confirmCloseDialogIfOpen(js) {+ return js(`(() => {+ const dialog = document.querySelector(${JSON.stringify(DIALOG)});+ const confirm = dialog && (${CONFIRM_FINDER})(dialog);+ if (!confirm) return false;+ confirm.click();+ return true;+ })()`);+}++module.exports = { CLOSE_DIALOG: DIALOG, expectCloseDialog, confirmCloseDialog, confirmCloseDialogIfOpen };diff --git a/apps/native/electron/close-confirm-harness.test.cjs b/apps/native/electron/close-confirm-harness.test.cjsnew file mode 100644index 00000000..6e34918c--- /dev/null+++ b/apps/native/electron/close-confirm-harness.test.cjs@@ -0,0 +1,102 @@+const { test } = require('node:test');+const assert = require('node:assert/strict');+const { CLOSE_DIALOG, expectCloseDialog, confirmCloseDialog, confirmCloseDialogIfOpen } = require('./close-confirm-harness.cjs');++// The harness's in-page snippets only touch querySelector, querySelectorAll,+// textContent, getAttribute, setAttribute and click, so a small double runs+// the exact strings the renderer would run.+function button(text, attrs = {}) {+ return {+ textContent: text, attrs: { ...attrs }, clicked: false,+ getAttribute(key) { return this.attrs[key] ?? null; },+ setAttribute(key, value) { this.attrs[key] = value; },+ click() { this.clicked = true; },+ };+}++function dialog(label, buttons) {+ return {+ label, buttons,+ getAttribute(key) { return key === 'aria-label' ? this.label : key === 'role' ? 'dialog' : null; },+ querySelectorAll(selector) { assert.equal(selector, 'button'); return this.buttons; },+ };+}++function setup(label = 'Close tab', buttons = null) {+ const state = {+ dialog: dialog(label, buttons ?? [button('', { 'aria-label': 'Close' }), button('Cancel'), button(label)]),+ };+ state.document = {+ querySelector(selector) {+ if (selector === CLOSE_DIALOG || selector === '[role="dialog"]') {+ return state.dialog && state.dialog.label.startsWith('Close ') ? state.dialog : null;+ }+ if (selector === '[data-close-confirm="true"]') {+ return state.dialog?.buttons.find(item => item.getAttribute('data-close-confirm') === 'true') ?? null;+ }+ throw new Error(`unexpected selector: ${selector}`);+ },+ };+ state.js = code => new Function('document', `return (${code});`)(state.document);+ state.until = async (condition, label) => {+ for (let i = 0; i < 3 && !await condition(); i++) {}+ assert.equal(await condition(), true, `timed out: ${label}`);+ };+ return state;+}++test('the handshake tags and clicks the confirm button, never Cancel or the header X', async () => {+ const state = setup();+ const buttons = state.dialog.buttons;+ let clicked = null;+ const click = async selector => {+ clicked = selector;+ const target = state.document.querySelector(selector);+ assert.equal(target, buttons[2]);+ target.click();+ state.dialog = null; // The renderer closes the dialog and the tab.+ };+ await confirmCloseDialog({ js: state.js, click, until: state.until });+ assert.equal(clicked, '[data-close-confirm="true"]');+ assert.deepEqual(buttons.map(item => item.clicked), [false, false, true]);+});++test('a plural title confirms the same way', async () => {+ const state = setup('Close 3 tabs');+ assert.equal(await expectCloseDialog(state.js, state.until), 'Close 3 tabs');+ const buttons = state.dialog.buttons;+ await confirmCloseDialog({+ js: state.js,+ click: async selector => {+ const target = state.document.querySelector(selector);+ assert.equal(target?.textContent, 'Close 3 tabs');+ target.click();+ state.dialog = null;+ },+ until: state.until,+ });+ assert.deepEqual(buttons.map(item => item.clicked), [false, false, true]);+});++test('no dialog reads as absent instead of throwing', async () => {+ const state = setup();+ state.dialog = null;+ assert.equal(await confirmCloseDialogIfOpen(state.js), false);+ await assert.rejects(() => expectCloseDialog(state.js, state.until), /close confirmation dialog/);+});++test('an unrelated dialog does not satisfy the expectation', async () => {+ const state = setup('Update settings');+ assert.equal(await confirmCloseDialogIfOpen(state.js), false);+ await assert.rejects(() => confirmCloseDialog({ js: state.js, click: () => {}, until: state.until }), /close confirmation dialog/);+});++test('a Close-prefixed dialog with an unexpected title is rejected', async () => {+ const state = setup('Close everything');+ await assert.rejects(() => expectCloseDialog(state.js, state.until), /names the tabs/);+});++test('a confirmation without a matching button fails loudly instead of clicking Cancel', async () => {+ const state = setup('Close tab', [button('', { 'aria-label': 'Close' }), button('Cancel')]);+ await assert.rejects(() => confirmCloseDialog({ js: state.js, click: () => {}, until: state.until }), /owns a confirm button/);+});diff --git a/apps/native/electron/frontend-runtime.cjs b/apps/native/electron/frontend-runtime.cjsindex ed5197bb..bc9e7acd 100644--- a/apps/native/electron/frontend-runtime.cjs+++ b/apps/native/electron/frontend-runtime.cjs@@ -130,6 +130,8 @@ app.whenReady().then(async () => {// This suite does not download releases or open external browser pages.ipcMain.handle('updates', () => ({ status: 'unavailable', automatic: false, interactive: false }));const wc = win.webContents, js = code => wc.executeJavaScript(code);+ // Name the next renderer throw in CI; executeJavaScript otherwise hides it.+ wc.on('console-message', event => { if (/Error|error|Illegal/.test(event.message || '')) console.error('Front-end renderer:', event.message); });await wc.loadURL(origin); desktop.present(win);if (desktop.foreground) await until(() => win.isFocused(), 'foreground window focus');await until(() => js(`!!document.querySelector('[data-workspace-ready="true"] textarea[aria-label="Prompt"]')`), 'workspace and composer ready');diff --git a/apps/native/electron/narrow-navigation-frontend.cjs b/apps/native/electron/narrow-navigation-frontend.cjsindex 9b58092f..6b6105ca 100644--- a/apps/native/electron/narrow-navigation-frontend.cjs+++ b/apps/native/electron/narrow-navigation-frontend.cjs@@ -1,6 +1,7 @@const assert = require('node:assert/strict');const fs = require('node:fs'), path = require('node:path');const desktop = require('./test-desktop.cjs');+const { confirmCloseDialog } = require('./close-confirm-harness.cjs');async function runNarrowNavigation({win, output, click, until, report}) {const wc = win.webContents, js = code => wc.executeJavaScript(code);const escape = async () => {@@ -18,6 +19,8 @@ async function runNarrowNavigation({win, output, click, until, report}) {await click('[aria-label="Open navigation"]');// Open conversations live in the session list; closing moves the saved one to History.await click('[data-session-navigation="sidebar"] [data-tab-id]:has(button[aria-pressed="true"]) [aria-label="Close tab"]');+ // The completed turns' worker is still enrolled, so the close asks first.+ await confirmCloseDialog({ js, click, until });await until(() => js(`!!document.querySelector('#sidebar-chat-list button[data-row]')`), 'closed saved conversation available in History');await js(`document.querySelector('#sidebar-chat-list button[data-row]').parentElement.querySelector('button[aria-label^="Actions for "]').setAttribute('data-narrow-actions','true')`);await click('[data-narrow-actions="true"]');diff --git a/apps/native/electron/performance-benchmark.cjs b/apps/native/electron/performance-benchmark.cjsindex 9558b92c..3791379c 100644--- a/apps/native/electron/performance-benchmark.cjs+++ b/apps/native/electron/performance-benchmark.cjs@@ -10,6 +10,7 @@ const os = require('node:os');const net = require('node:net');const assert = require('node:assert/strict');const { installGalleryFixture } = require('./gallery-fixture.cjs');+const { confirmCloseDialogIfOpen } = require('./close-confirm-harness.cjs');const { installPerformanceWorkload, frameRecorder, summarizeFrames } = require('./performance-workload.cjs');const { treeSample } = require('./process-metrics.cjs');const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));@@ -155,9 +156,16 @@ app.whenReady().then(async () => {}// Closing the only chat must release renderer content; global caches remain observable.// Saved history opens a second tab; release it and the warm-up conversation.+ // Closes while the confirmation is open are swallowed, so confirm each dialog.+ let sawCloseDialog = false;for (let i = 0; i < 10 && await js(`!!document.querySelector('article')`); i++) {wc.send('desktop-action', 'close'); await sleep(150);+ if (await confirmCloseDialogIfOpen(js)) {+ sawCloseDialog = true;+ await wait(`!document.querySelector('[role="dialog"]')`);+ }}+ assert.ok(sawCloseDialog, 'Closing worker-backed tabs must ask for confirmation');await wait(`!document.querySelector('article')`); await sleep(1500);report.afterClose = await memory();report.unexpectedApiRequests = unexpected;