graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Test the shutdown-fixture timeout drill, not just its helpers
Cursor Agent0f63037d0b18
diff --git a/apps/native/electron/smoke-server-lifecycle.cjs b/apps/native/electron/smoke-server-lifecycle.cjsindex 67418bce..0ec4b3de 100644--- a/apps/native/electron/smoke-server-lifecycle.cjs+++ b/apps/native/electron/smoke-server-lifecycle.cjs@@ -18,31 +18,13 @@ exports.run = async ({win, backend}) => {// next stall names where the prompt stopped instead of dying as a generic// "Test deadline exceeded" under SIGKILL.const outer = timeouts.outerMs(), startedAt = Date.now();- const dumpTimeout = async (label, waitedMs) => {- phase(`timed out: ${label}`);- const record = { label, waitedMs, outerMs: outer, at: new Date().toISOString() };- try { record.guiText = await js('document.body.innerText'); } catch (error) { record.guiText = `<unreadable: ${error.message}>`; }- try {- record.backend = await (async () => {- const response = await fetch(`${backend.origin}/api/acp`, { signal: AbortSignal.timeout(5000) });- const body = await response.json();- return `sessions=${body.sessions ?? '?'} ok=${body.ok ?? response.ok}`;- })();- } catch (error) { record.backend = `<unreachable: ${error.message}>`; }- record.workers = timeouts.collectWorkerState(workspace);- record.model = timeouts.collectModelState(output);- const file = timeouts.slug(label);- try { fs.writeFileSync(path.join(output, `timeout-${file}.json`), JSON.stringify(record, null, 2)); } catch {}- try { fs.writeFileSync(path.join(output, 'timeout-gui-text.txt'), record.guiText.slice(0, 20000)); } catch {}- try { fs.writeFileSync(path.join(output, 'timeout.png'), (await win.webContents.capturePage()).toPNG()); } catch {}- console.log(timeouts.formatTimeoutSummary({ label, elapsedMs: waitedMs, outerMs: outer,- backend: record.backend, workers: record.workers, model: record.model, guiChars: record.guiText.length }));- };const until = async (condition, label) => {const ms = timeouts.phaseBudget(label, outer, Date.now() - startedAt);const end = Date.now() + ms;while (Date.now() < end) { if (await condition()) return; await sleep(50); }- await dumpTimeout(label, ms);+ await timeouts.dumpTimeout({ label, waitedMs: ms, outer, output, workspace, js,+ capturePage: () => win.webContents.capturePage().then(page => page.toPNG()),+ backendOrigin: backend.origin, writePhase: phase });throw Error(`Shutdown fixture timed out: ${label}`);};await until(() => js(`!!document.querySelector('[data-workspace-ready="true"] textarea[aria-label="Prompt"]')`), 'composer');diff --git a/apps/native/electron/smoke-timeout.cjs b/apps/native/electron/smoke-timeout.cjsindex 50b20cf1..7b4b3184 100644--- a/apps/native/electron/smoke-timeout.cjs+++ b/apps/native/electron/smoke-timeout.cjs@@ -86,6 +86,31 @@ function collectModelState(outputDir) {return state;}+/** The timeout path itself, with Electron I/O injected so the failure drill is+// a unit test, not a hope: `js` runs renderer snippets, `capturePage` returns+// a PNG buffer, `backendOrigin` is the UI server root (or null to skip the+// health probe). Every capture is best-effort; the dump never masks the+// timeout error it documents. */+async function dumpTimeout({ label, waitedMs, outer, output, workspace, js, capturePage, backendOrigin, writePhase }) {+ writePhase(`timed out: ${label}`);+ const record = { label, waitedMs, outerMs: outer, at: new Date().toISOString() };+ try { record.guiText = await js('document.body.innerText'); } catch (error) { record.guiText = `<unreadable: ${error.message}>`; }+ try {+ const response = await fetch(`${backendOrigin}/api/acp`, { signal: AbortSignal.timeout(5000) });+ const body = await response.json();+ record.backend = `sessions=${body.sessions ?? '?'} ok=${body.ok ?? response.ok}`;+ } catch (error) { record.backend = `<unreachable: ${error.message}>`; }+ record.workers = collectWorkerState(workspace);+ record.model = collectModelState(output);+ const file = slug(label);+ try { fs.writeFileSync(path.join(output, `timeout-${file}.json`), JSON.stringify(record, null, 2)); } catch {}+ try { fs.writeFileSync(path.join(output, 'timeout-gui-text.txt'), record.guiText.slice(0, 20000)); } catch {}+ try { fs.writeFileSync(path.join(output, 'timeout.png'), await capturePage()); } catch {}+ console.log(formatTimeoutSummary({ label, elapsedMs: waitedMs, outerMs: outer,+ backend: record.backend, workers: record.workers, model: record.model, guiChars: record.guiText.length }));+ return record;+}+/** One compact block for the CI log; the full record goes to timeout-*.json. */function formatTimeoutSummary({ label, elapsedMs, outerMs: outer, backend, workers, model, guiChars }) {const workerLine = workers.error ? `workers=<${workers.error}>`@@ -98,4 +123,4 @@ function formatTimeoutSummary({ label, elapsedMs, outerMs: outer, backend, worke].join('\n');}-module.exports = { outerMs, phaseBudget, slug, tailText, collectWorkerState, collectModelState, formatTimeoutSummary };+module.exports = { outerMs, phaseBudget, slug, tailText, collectWorkerState, collectModelState, formatTimeoutSummary, dumpTimeout };diff --git a/apps/native/electron/smoke-timeout.test.cjs b/apps/native/electron/smoke-timeout.test.cjsindex 0263f984..17eeb84f 100644--- a/apps/native/electron/smoke-timeout.test.cjs+++ b/apps/native/electron/smoke-timeout.test.cjs@@ -1,7 +1,7 @@const { test } = require('node:test');const assert = require('node:assert/strict');-const fs = require('node:fs'), os = require('node:os'), path = require('node:path');-const { outerMs, phaseBudget, slug, tailText, collectWorkerState, collectModelState, formatTimeoutSummary } = require('./smoke-timeout.cjs');+const fs = require('node:fs'), http = require('node:http'), os = require('node:os'), path = require('node:path');+const { outerMs, phaseBudget, slug, tailText, collectWorkerState, collectModelState, formatTimeoutSummary, dumpTimeout } = require('./smoke-timeout.cjs');test('outer budget mirrors the spawner validation, defaulting hand runs', () => {assert.equal(outerMs({ GRAFF_TEST_TIMEOUT_MS: '180000' }), 180000);@@ -94,6 +94,51 @@ test('model state marks an absent requests file', () => {}});+test('the timeout drill captures renderer, backend, model, and workers', async () => {+ const { root, workspace, output } = fixture();+ const server = http.createServer((req, res) => {+ res.writeHead(200, { 'content-type': 'application/json' });+ res.end(JSON.stringify({ ok: true, sessions: 3 }));+ });+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));+ const phases = [];+ try {+ const record = await dumpTimeout({ label: 'agent completion', waitedMs: 150000, outer: 180000,+ output, workspace, js: async () => 'typed prompt, no reply yet',+ capturePage: async () => Buffer.from('png-bytes'),+ backendOrigin: `http://127.0.0.1:${server.address().port}`, writePhase: name => phases.push(name) });+ assert.equal(record.backend, 'sessions=3 ok=true');+ assert.equal(record.guiText, 'typed prompt, no reply yet');+ assert.equal(record.workers.count, 2);+ assert.equal(record.model.requests.count, 2);+ assert.deepEqual(phases, ['timed out: agent completion']);+ assert.equal(JSON.parse(fs.readFileSync(path.join(output, 'timeout-agent-completion.json'), 'utf8')).label, 'agent completion');+ assert.equal(fs.readFileSync(path.join(output, 'timeout-gui-text.txt'), 'utf8'), 'typed prompt, no reply yet');+ assert.equal(fs.readFileSync(path.join(output, 'timeout.png'), 'utf8'), 'png-bytes');+ } finally {+ server.close();+ fs.rmSync(root, { recursive: true, force: true });+ }+});++test('the timeout drill degrades when every capture fails', async () => {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'graff-smoke-timeout-'));+ const output = path.join(root, 'output');+ fs.mkdirSync(output, { recursive: true });+ try {+ const record = await dumpTimeout({ label: 'agent completion', waitedMs: 150000, outer: 180000,+ output, workspace: path.join(root, 'missing'), js: async () => { throw new Error('renderer gone'); },+ capturePage: async () => { throw new Error('no frame'); },+ backendOrigin: 'http://127.0.0.1:1', writePhase: () => {} });+ assert.match(record.guiText, /renderer gone/);+ assert.match(record.backend, /unreachable/);+ assert.match(record.workers.error, /ENOENT/);+ assert.equal(record.model.requests.present, false);+ } finally {+ fs.rmSync(root, { recursive: true, force: true });+ }+});+test('the console summary fits the stall on two lines', () => {const summary = formatTimeoutSummary({ label: 'agent completion', elapsedMs: 150000, outerMs: 180000,backend: 'sessions=1', workers: { count: 1, runs: [{ run: 'aabbccdd', lastKind: 'recipe', finished: null }] },