Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Verify conversation titles in the packaged desktop

justrach97ce4c7dd696
diff --git a/.github/workflows/desktop.yml b/.github/workflows/desktop.yml
index 59654dc8..c3a9dcce 100644
--- a/.github/workflows/desktop.yml
+++ b/.github/workflows/desktop.yml
@@ -103,6 +103,13 @@ jobs:
run: bun run test:cli
env:
GRAFF_FRONTEND_OUTPUT: ../../zig-out/cli-test
+ - name: Packaged conversation title creation and recovery
+ if: ${{ !cancelled() && steps.worker.conclusion == 'success' }}
+ run: |
+ GRAFF_REUSE_ENGINE=1 bun run electron:build
+ bun run test:packaged-titles
+ env:
+ GRAFF_PACKAGED_OUTPUT: ../../zig-out/packaged-titles
- name: Bounded mixed split and memory stress
if: ${{ !cancelled() && steps.worker.conclusion == 'success' }}
run: bun run test:split-stress
@@ -123,6 +130,7 @@ jobs:
zig-out/native-tests/native-results.json
zig-out/frontend-tests/
zig-out/narrow-navigation/
+ zig-out/packaged-titles/
zig-out/split-stress/
zig-out/native-tab-drag/
zig-out/visual-tests/test-run.json
diff --git a/apps/native/electron/smoke-launch.cjs b/apps/native/electron/smoke-launch.cjs
index f4c45491..728ce096 100644
--- a/apps/native/electron/smoke-launch.cjs
+++ b/apps/native/electron/smoke-launch.cjs
@@ -26,8 +26,9 @@ async function run({ win, backend, browser, token }) {
const version = execFileSync(path.join(resources, 'graff'), ['--version'], { encoding: 'utf8', timeout: 10000 }).trim().split('\n')[0];
assert.match(version, /graff/i);
if (process.env.GRAFF_SMOKE_HTML_TOOL) await require('./smoke-html.cjs').run({ win, backend, token });
- const report = { passed: ['bundled server', 'production composer', 'empty browser lifecycle', 'request authentication', 'native module ABI', 'bundled engine executable', 'packaged executable'], version };
+ if (process.env.GRAFF_SMOKE_TITLES) await require('./smoke-titles.cjs').run({ win, backend });
+ const report = { appVersion: app.getVersion(), passed: ['bundled server', 'production composer', 'empty browser lifecycle', 'request authentication', 'native module ABI', 'bundled engine executable', 'packaged executable'], version };
fs.writeFileSync(process.env.GRAFF_ELECTRON_SMOKE, JSON.stringify(report, null, 2));
- console.log(process.env.GRAFF_SMOKE_HTML_TOOL ? 'Packaged launch and offline HTML tool checks passed.' : 'Packaged launch checks passed. No prompt sent or coding setting changed.');
+ console.log(process.env.GRAFF_SMOKE_TITLES ? 'Packaged title checks passed.' : process.env.GRAFF_SMOKE_HTML_TOOL ? 'Packaged launch and offline HTML tool checks passed.' : 'Packaged launch checks passed. No prompt sent or coding setting changed.');
}
module.exports = { run };
diff --git a/apps/native/electron/smoke-titles.cjs b/apps/native/electron/smoke-titles.cjs
new file mode 100644
index 00000000..d57b97f1
--- /dev/null
+++ b/apps/native/electron/smoke-titles.cjs
@@ -0,0 +1,60 @@
+const fs = require('node:fs'), path = require('node:path'), assert = require('node:assert/strict');
+const { nativeImage } = require('electron');
+const desktop = require('./test-desktop.cjs');
+async function run({win, backend}) {
+ const wc=win.webContents, js=code=>wc.executeJavaScript(code), output=process.env.GRAFF_PACKAGED_OUTPUT;
+ const root=fs.realpathSync(process.env.GRAFF_CWD), directory=path.join(root,'.graff/sessions');
+ const until=async (condition,label)=>{const end=Date.now()+25000;while(Date.now()<end){if(await condition())return;await new Promise(r=>setTimeout(r,50));}fs.writeFileSync(path.join(output,'title-failure.txt'),await js('document.body.innerText'));fs.writeFileSync(path.join(output,'title-failure.png'),(await wc.capturePage()).toPNG());throw Error('Packaged title check: '+label);};
+ const click=async selector=>{
+ let point;
+ await until(async()=>{point=await js(`(()=>{const e=document.querySelector(${JSON.stringify(selector)});if(!e)return null;e.scrollIntoView({block:'center',behavior:'instant'});const r=e.getBoundingClientRect(),x=Math.round(r.x+r.width/2),y=Math.round(r.y+r.height/2);return{x,y,hit:e.contains(document.elementFromPoint(x,y))}})()`);return point?.hit;},'pointer target '+selector);
+ for(const type of ['mouseDown','mouseUp'])await desktop.testInput(wc,{type,x:point.x,y:point.y,button:'left',clickCount:1});
+ };
+ const send=async text=>{await click('textarea[aria-label="Prompt"]');for(const keyCode of text)await desktop.testInput(wc,{type:'char',keyCode});await click('[aria-label="Send"]');};
+ const shot=async name=>{await js(`new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r)))`);await new Promise(r=>setTimeout(r,150));fs.writeFileSync(path.join(output,name),(await wc.capturePage()).toPNG());};
+ await until(()=>js(`!!document.querySelector('[data-workspace-ready="true"] textarea')`),'workspace ready');
+ if(await js(`!!document.querySelector('[aria-label="Close browser"]')`))await click('[aria-label="Close browser"]');
+ const phase=process.env.GRAFF_SMOKE_TITLES, report={phase,passed:[]};
+ if(phase==='create') {
+ const catalog=await js(`fetch('/api/models').then(r=>r.json())`);assert.match(JSON.stringify(catalog.result.current),/lmstudio/i);
+ await send('Write retained work to proof.txt.');
+ await until(()=>js(`document.body.textContent.includes('Retained work is saved.') && !document.querySelector('article[aria-busy="true"]')`),'text conversation complete');
+ assert.equal(fs.readFileSync(path.join(root,'proof.txt'),'utf8'),'retained work');
+ const saved=()=>fs.readdirSync(directory).filter(n=>n.endsWith('.session.json')).map(name=>({name,data:JSON.parse(fs.readFileSync(path.join(directory,name),'utf8'))}));
+ await until(()=>saved().some(row=>typeof row.data.title==='string' && /retained work/i.test(row.data.title)),'meaningful title saved');
+ const text=saved().find(row=>typeof row.data.title==='string' && /retained work/i.test(row.data.title));
+ fs.writeFileSync(path.join(output,'text-session.json'),JSON.stringify(text.data,null,2));
+ await shot('packaged-text-title.png');
+ await click('[title="New chat (⌘T)"]');
+ await send('/model lmstudio mock-vision');
+ await until(()=>js(`document.body.textContent.includes('mock-vision') && !document.querySelector('article[aria-busy="true"]')`),'image model selected');
+ const png=nativeImage.createFromBitmap(Buffer.alloc(48*32*4,180),{width:48,height:32}).toPNG().toString('base64');
+ await click('textarea[aria-label="Prompt"]');
+ await js(`(()=>{const data=new DataTransfer();data.items.add(new File([Uint8Array.from(atob(${JSON.stringify(png)}),c=>c.charCodeAt(0))],'title-image.png',{type:'image/png'}));document.querySelector('textarea[aria-label="Prompt"]').dispatchEvent(new ClipboardEvent('paste',{clipboardData:data,bubbles:true,cancelable:true}));})()`);
+ await until(()=>js(`!!document.querySelector('[aria-label="Preview title-image.png"]')`),'image uploaded');
+ await send('Review this image of retained work.');
+ await until(()=>js(`document.body.textContent.includes('The image of retained work is visible.') && !document.querySelector('article[aria-busy="true"]')`),'image conversation complete');
+ await until(()=>saved().some(row=>row.name!==text.name && typeof row.data.title==='string' && /retained work/i.test(row.data.title)),'image title persisted');
+ assert.ok(fs.readFileSync(path.join(process.env.HOME,'requests.json'),'utf8').includes(png),'actual bundled harness sends pasted pixels');
+ await shot('packaged-image-title.png');
+ // Build historical and explicitly named fixtures from a real saved state.
+ const legacy=structuredClone(text.data);legacy.title='Untitled session';
+ const user=legacy.messages.find(message=>message.role==='user');assert.ok(user);
+ user.content=[{type:'input_text',text:'Recover a legacy conversation title'}];
+ fs.writeFileSync(path.join(directory,'legacy-title.session.json'),JSON.stringify(legacy));
+ const named=structuredClone(legacy);named.title='My explicit project title';
+ fs.writeFileSync(path.join(directory,'named-title.session.json'),JSON.stringify(named));
+ report.passed.push('packaged GUI text prompt creates real file and meaningful saved title','image-bearing prompt reaches bundled harness as pixels and saves meaningful title');
+ } else {
+ await until(()=>js(`document.querySelector('#sidebar-chat-list')?.textContent.includes('Recover a legacy conversation title') && document.querySelector('#sidebar-chat-list')?.textContent.includes('My explicit project title')`),'fresh packaged process recovers legacy and preserves explicit titles');
+ assert.equal(await js(`document.querySelector('#sidebar-chat-list').textContent.includes('Untitled session')`),false);
+ await js(`Array.from(document.querySelectorAll('#sidebar-chat-list button[data-row]')).find(e=>e.textContent.includes('Recover a legacy conversation title')).setAttribute('data-title-recovery','true')`);
+ await click('[data-title-recovery="true"]');
+ await until(()=>js(`document.querySelector('[data-tab-id] button[aria-pressed=\"true\"]')?.textContent.includes('Recover a legacy')`),'legacy snapshot opens');
+ await until(()=>js(`document.querySelector('[data-chat][data-focused=\"true\"]')?.textContent.includes('Recover a legacy conversation title')`),'recovered transcript renders');
+ await shot('packaged-recovered-titles.png');
+ report.passed.push('fresh packaged process recovers saved input_text placeholder title','explicit saved title remains unchanged','recovered saved conversation opens through real sidebar');
+ }
+ report.desktop=desktop.assertSafe();fs.writeFileSync(path.join(output,`titles-${phase}.json`),JSON.stringify(report,null,2));
+}
+module.exports={run};
diff --git a/apps/native/package.json b/apps/native/package.json
index 4f303624..dbe5e051 100644
--- a/apps/native/package.json
+++ b/apps/native/package.json
@@ -48,7 +48,8 @@
"test:cli": "GRAFF_CLI_TEST=1 bun scripts/test-frontend.mjs",
"install:cli": "bun scripts/install-cli.mjs",
"test:packaged-html": "bun scripts/test-packaged-html.mjs",
- "test:narrow-navigation": "GRAFF_NARROW_NAV_TEST=1 bun scripts/test-frontend.mjs"
+ "test:narrow-navigation": "GRAFF_NARROW_NAV_TEST=1 bun scripts/test-frontend.mjs",
+ "test:packaged-titles": "bun scripts/test-packaged-titles.mjs"
},
"dependencies": {
"@streamdown/code": "^1.1.1",
diff --git a/apps/native/scripts/test-packaged-titles.mjs b/apps/native/scripts/test-packaged-titles.mjs
new file mode 100644
index 00000000..7be3e2e7
--- /dev/null
+++ b/apps/native/scripts/test-packaged-titles.mjs
@@ -0,0 +1,48 @@
+import { spawn } from 'node:child_process';
+import { createRequire } from 'node:module';
+import { mkdtempSync, mkdirSync, writeFileSync, openSync, closeSync, readFileSync, rmSync, cpSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { runDesktopProcess } from './test-electron.mjs';
+import assert from 'node:assert/strict';
+const require=createRequire(import.meta.url), repo=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'../../..');
+const bundle=path.resolve(process.argv[2]||path.join(repo,'zig-out/electron/Codegraff.app'));
+const output=path.resolve(process.env.GRAFF_PACKAGED_OUTPUT||path.join(repo,'zig-out/packaged-titles'));
+const temp=mkdtempSync(path.join(tmpdir(),'graff-packaged-titles-')), workspace=path.join(temp,'project');
+mkdirSync(workspace);mkdirSync(path.join(temp,"scratch"));mkdirSync(output,{recursive:true});
+const launcher=path.join(temp,'codegraff'), quote=value=>"'"+value.replaceAll("'","'\\''")+"'";
+writeFileSync(launcher,require('../electron/cli-launcher.cjs').launcherSource(bundle).replace('>/dev/null 2>&1',`>>${quote(path.join(output,'app.log'))} 2>&1`),{mode:0o755});
+const script=path.join(temp,'replies.json');writeFileSync(script,JSON.stringify([
+ {tool:'bash',arguments:{command:"printf 'retained work' > proof.txt"}},
+ {text:'Retained work is saved.'},
+ {text:'The image of retained work is visible.'},
+]));
+const mcp=path.join(temp,'mcp.json');writeFileSync(mcp,'{"mcpServers":{}}');
+const env=Object.fromEntries(['PATH','TMPDIR','LANG','USER','LOGNAME','SHELL'].filter(key=>process.env[key]).map(key=>[key,process.env[key]]));
+Object.assign(env,{HOME:temp,TMPDIR:path.join(temp,"scratch"),LMSTUDIO_API_KEY:'local',GRAFF_NO_TELEMETRY:'1',GRAFF_FLEET:'off',GRAFF_YOLO:'1',GRAFF_NO_SMOLIFY:'1',GRAFF_NO_CODEDB_GUARD:'1',NEXT_TELEMETRY_DISABLED:'1',GRAFF_MCP_CONFIG:mcp,
+ GRAFF_ELECTRON_SMOKE:path.join(output,'launch-results.json'),GRAFF_SMOKE_LAUNCH_ONLY:'1',GRAFF_SMOKE_PROFILE:path.join(temp,'profile'),GRAFF_PACKAGED_OUTPUT:output});
+const log=path.join(output,'model.log'), fd=openSync(log,'w');
+const model=spawn('python3',[path.join(repo,'scripts/eval/frontend_model.py'),'--script',script,'--requests',path.join(temp,'requests.json')],{env,stdio:['ignore',fd,fd]});closeSync(fd);
+let modelError;model.on('error',error=>{modelError=error;});
+try {
+ const end=Date.now()+10000;
+ while(!readFileSync(log,'utf8').includes('scripted model on')) {
+ if(modelError||model.exitCode!==null||Date.now()>end)throw modelError||Error('Offline model failed to start');
+ await new Promise(resolve=>setTimeout(resolve,50));
+ }
+ process.env.GRAFF_TEST_TIMEOUT_MS='120000';
+ for(const phase of ['create','reopen']) {
+ env.GRAFF_SMOKE_TITLES=phase;
+ const code=await runDesktopProcess('/bin/sh',['-c','launcher=$1; shift; . "$launcher"; wait "$!"','codegraff-test',launcher,workspace],env);
+ if(code!==0)throw Error(readFileSync(path.join(output,'app.log'),'utf8').slice(-7000));
+ const report=JSON.parse(readFileSync(path.join(output,`titles-${phase}.json`),'utf8'));
+ assert.ok(report.passed.length>=2);assert.equal(report.desktop.violations.length,0);
+ }
+ console.log('Packaged title creation, image prompt, process restart, legacy recovery and explicit names passed.');
+} finally {
+ for(const [source,target] of [[path.join(workspace,'.graff'),path.join(output,'saved-evidence')],[path.join(temp,'requests.json'),path.join(output,'requests.json')],[path.join(temp,'scratch/graff-native-attachments'),path.join(output,'images')]]) {
+ try {cpSync(source,target,{recursive:true});}catch{}
+ }
+ model.kill('SIGTERM');rmSync(temp,{recursive:true,force:true});
+}