Skip to content

The agent that grows with you

test(desktop): isolate Markdown ingress and real code-copy probe

Tekniumd599865a5379
diff --git a/evals/desktop_bug_campaign/markdown-README.md b/evals/desktop_bug_campaign/markdown-README.md
index 59fe9499afb..63719d3430b 100644
--- a/evals/desktop_bug_campaign/markdown-README.md
+++ b/evals/desktop_bug_campaign/markdown-README.md
@@ -1,26 +1,29 @@
-# Markdown rendering probe
+# Markdown whitespace live probe
-This uses the production Desktop components in a real Chromium renderer, without
-starting an agent or making a model request. It is not a native Electron/backend
-transport E2E test.
+This fixture now runs Markdown ONLY: no producer.json, hydration, SystemMessage,
+backend, model request, or notification delivery. The separate async-report lane
+owns #101078. Historical combined producer harness: commit 07a4da338bc, files
+navigation-markdown-{probe.tsx,live.mjs}; markdown-producer.py is unchanged.
-From the worktree root, with the campaign's locked dependencies and Xvfb ready:
+From the worktree root (locked workspace dependencies installed):
```sh
-.venv/bin/python evals/desktop_bug_campaign/markdown-producer.py /home/teknium/.hermes/cache/desktop-bugs-74848ed3/navigation-markdown/producer.json
node evals/desktop_bug_campaign/navigation-vite.mjs
-# In another terminal:
-DISPLAY=:208 PLAYWRIGHT_BROWSERS_PATH=/home/teknium/.hermes/cache/desktop-bugs-74848ed3/navigation-markdown/browsers node evals/desktop_bug_campaign/navigation-markdown-live.mjs after
+PLAYWRIGHT_BROWSERS_PATH=/home/teknium/.hermes/cache/desktop-bugs-74848ed3/navigation-markdown/browsers node evals/desktop_bug_campaign/navigation-markdown-live.mjs after
```
-The producer isolates both HOME and HERMES_HOME, saves a deterministic report via
-`save_job_output`, formats it through the cron completion and process-notification
-producers, persists an actual delivery row, and reads it back from SQLite. It does
-not execute the scheduled job. The browser feeds that row through hydration,
-runtime conversion, and `SystemMessage`, independently of the assistant Markdown
-samples. JSON receipts and screenshots go to the campaign artifact directory.
+Vite requires owned port 18160 (strictPort); verify the HTML references this
+worktree's probe entry. Chromium is headless; no Xvfb/native Electron needed.
+NAVIGATION_ARTIFACT_DIR overrides the default campaign receipt directory.
-The browser is a receipt collector: compare `hardBr`, `softBr`, `breaks`, `outputs`,
-`errors`, and `producer.dom`. Hard-break samples should emit a `br`; the soft-break
-control should not. The separate async report loss (#101078) is not repaired by
-the whitespace fix (#97117).
+The harness asserts 30 cases: five actual ingress functions, each with hard/soft
+breaks, first-line indented code, unfinished fence with terminal spaces, closed
+code with a final-space line, and leading/trailing blank lines. It waits for real
+Shiki, reads code textContent, clicks the code-card Copy control, and reads the
+real browser clipboard. Code expectations include the Markdown parser's final LF;
+we preserve its raw payload rather than arbitrarily trimming it. Nonzero exit
+means a failed assertion or page error. JSON and screenshot are retained.
+
+Unit invariants live in src/lib/markdown-whitespace.test.ts (exactly two tests).
+Run all verification under campaign tests.lock. This is production-component
+Chromium proof, NOT native Electron/backend/transport or macOS proof.
diff --git a/evals/desktop_bug_campaign/navigation-markdown-live.mjs b/evals/desktop_bug_campaign/navigation-markdown-live.mjs
index 1b9443188c7..a71abe93822 100644
--- a/evals/desktop_bug_campaign/navigation-markdown-live.mjs
+++ b/evals/desktop_bug_campaign/navigation-markdown-live.mjs
@@ -1,23 +1,33 @@
import { chromium } from '../../node_modules/playwright/index.mjs'
import fs from 'node:fs'
import { execFileSync } from 'node:child_process'
-const a='/home/teknium/.hermes/cache/desktop-bugs-74848ed3/navigation-markdown'
-const tag=process.argv[2]??'before'
-const browser=await chromium.launch({headless:false,args:['--no-sandbox']})
-const page=await browser.newPage({viewport:{width:1400,height:1000}})
-const errors=[];page.on('pageerror',e=>errors.push(String(e)))
-await page.goto('http://127.0.0.1:18160/navigation-markdown-probe.html',{waitUntil:'domcontentloaded',timeout:120000})
-await page.waitForSelector('#hard p',{timeout:90000})
-await page.waitForTimeout(6000)
-await page.waitForSelector('#hard p',{timeout:90000})
-const result=await page.evaluate(()=>({inputs:window.probeInputs,outputs:window.probeOutputs,ingress:window.ingress,hardBr:document.querySelectorAll('#hard br').length,softBr:document.querySelectorAll('#soft br').length,breaks:Object.fromEntries(Object.keys(window.ingress).map(k=>[k,document.querySelectorAll(`#${k} br`).length])),text:document.body.innerText,html:document.querySelector('main').innerHTML}))
-const producer = JSON.parse(fs.readFileSync(`${a}/producer.json`, 'utf8'))
-result.producer = await page.evaluate(rows => window.renderProducer(rows), producer.rows)
-await page.waitForSelector('#producer [data-role="system"]')
-result.producer.dom = await page.locator('#producer').evaluate(el=>({text:el.textContent,headings:el.querySelectorAll('h1').length,tables:el.querySelectorAll('table').length,html:el.innerHTML}))
-result.errors=errors
-result.sourceSha=execFileSync('git', ['rev-parse', 'HEAD'], {encoding:'utf8'}).trim()
-result.codeText=await page.locator('#code code').textContent()
-await page.screenshot({path:`${a}/markdown-${tag}.png`,fullPage:true})
-fs.writeFileSync(`${a}/markdown-${tag}.json`,JSON.stringify(result,null,2));console.log(JSON.stringify(result,null,2))
+const artifact = process.env.NAVIGATION_ARTIFACT_DIR ?? '/home/teknium/.hermes/cache/desktop-bugs-74848ed3/navigation-markdown'
+const tag = process.argv[2] ?? 'after'
+const browser = await chromium.launch({headless: true, args: ['--no-sandbox']})
+const context = await browser.newContext({permissions: ['clipboard-read', 'clipboard-write']})
+const page = await context.newPage()
+const errors = []
+page.on('pageerror', error => errors.push(String(error)))
+await page.goto('http://127.0.0.1:18160/navigation-markdown-probe.html', {waitUntil: 'networkidle', timeout:120000})
+await page.waitForSelector('#assistant-code .shiki')
+const cases = await page.evaluate(() => window.markdownCases)
+const results = {}
+for (const [id, sample] of Object.entries(cases)) {
+ const section = page.locator(`#${id}`)
+ const dom = await section.evaluate(el => ({breaks: el.querySelectorAll('br').length, code: el.querySelector('code')?.textContent ?? null, highlighted: !!el.querySelector('.shiki')}))
+ let copy = null
+ if (await section.locator('[data-slot="code-card"] button').count()) {
+ await section.locator('[data-slot="code-card"] button').first().click({force:true})
+ copy = await page.evaluate(() => navigator.clipboard.readText())
+ }
+ const expectedCode = {indented:'value = 1\n', unfinished:'value = 1 \n', code:'value = 1 \nvalue = 2 \n', blanks:'\nvalue = 1 \n\n\n'}[sample.kind]
+ const passed = expectedCode === undefined ? dom.breaks === (sample.kind === 'hard' ? 1 : 0) : dom.code === expectedCode && copy === expectedCode
+ results[id] = {...sample, ...dom, copy, expectedCode, passed}
+}
+const result = {sourceSha:execFileSync('git', ['rev-parse','HEAD'], {encoding:'utf8'}).trim(), results, errors, passed:Object.values(results).every(row => row.passed) && errors.length === 0}
+fs.mkdirSync(artifact, {recursive:true})
+fs.writeFileSync(`${artifact}/markdown-${tag}.json`, JSON.stringify(result,null,2))
+await page.screenshot({path:`${artifact}/markdown-${tag}.png`, fullPage:true})
+console.log(JSON.stringify(result,null,2))
await browser.close()
+process.exitCode = result.passed ? 0 : 1
diff --git a/evals/desktop_bug_campaign/navigation-markdown-probe.tsx b/evals/desktop_bug_campaign/navigation-markdown-probe.tsx
index 8c5721c6e1d..22979b2af01 100644
--- a/evals/desktop_bug_campaign/navigation-markdown-probe.tsx
+++ b/evals/desktop_bug_campaign/navigation-markdown-probe.tsx
@@ -1,47 +1,35 @@
import { createRoot } from 'react-dom/client'
-import { AssistantRuntimeProvider, ThreadPrimitive, useExternalStoreRuntime, type ThreadMessage } from '@assistant-ui/react'
import type { ReactNode } from 'react'
-import type { SessionMessage } from '@/types/hermes'
import { QueryClientProvider } from '@tanstack/react-query'
import { queryClient } from '@/lib/query-client'
import { I18nProvider } from '@/i18n'
import { ThemeProvider } from '@/themes/context'
import { RootTooltipProvider } from '@/components/ui/tooltip'
import { MarkdownTextContent } from '@/components/assistant-ui/markdown-text'
-import { SystemMessage } from '@/components/assistant-ui/thread/system-message'
import { preprocessMarkdown } from '@/lib/markdown-preprocess'
-import { toChatMessages } from '@/lib/chat-messages/hydration'
-import { toRuntimeMessage } from '@/lib/chat-runtime'
import { assistantTextPart, renderMediaTags } from '@/lib/chat-messages/parts'
import { stripGeneratedImageEchoes } from '@/lib/generated-images'
import { extractEmbeddedImages } from '@/lib/embedded-images'
import { stripPreviewTargets } from '@/lib/preview-targets'
-const hard = 'First line \nSecond line'
-const soft = 'Soft first\nSoft second'
-const code = '```python\nvalue = 1 \nvalue = 2 \n```'
-const corpus = hard + '\n\n' + code
+const samples = {
+ hard: 'First line \nSecond line',
+ soft: 'Soft first\nSoft second',
+ indented: ' value = 1\n\n',
+ unfinished: '```python\nvalue = 1 ',
+ code: '```python\nvalue = 1 \nvalue = 2 \n```',
+ blanks: '```python\n\nvalue = 1 \n\n\n```'
+}
const image = 'data:image/png;base64,' + 'A'.repeat(64)
-const assistant = assistantTextPart(corpus)
const ingress = {
- assistant: assistant.type === 'text' ? assistant.text : '',
- media: renderMediaTags(corpus + '\n\nMEDIA: /tmp/image.png'),
- preview: stripPreviewTargets(corpus + '\n\n[Preview: x](#preview:test)'),
- embedded: extractEmbeddedImages(corpus + '\n\n' + image).cleanedText,
- generated: stripGeneratedImageEchoes(corpus + '\n\n![result](/tmp/image.png)', ['/tmp/image.png'])
+ assistant: (text: string) => { const part = assistantTextPart(text); return part.type === 'text' ? part.text : '' },
+ media: (text: string) => renderMediaTags('MEDIA: /tmp/image.png\n\n' + text),
+ preview: (text: string) => stripPreviewTargets('[Preview: x](#preview:test)\n\n' + text),
+ embedded: (text: string) => extractEmbeddedImages(image + '\n\n' + text).cleanedText,
+ generated: (text: string) => stripGeneratedImageEchoes('![result](/tmp/image.png)\n\n' + text, ['/tmp/image.png'])
}
-Object.assign(window, {probeInputs:{hard,soft,code}, probeOutputs:{hard:preprocessMarkdown(hard),soft:preprocessMarkdown(soft),code:preprocessMarkdown(code)}, ingress})
+const cases = Object.fromEntries(Object.entries(ingress).flatMap(([name, apply]) => Object.entries(samples).map(([kind, input]) => [`${name}-${kind}`, {kind, input, text: apply(input)}])))
+Object.assign(window, {markdownCases: cases, preprocessMarkdown})
function Providers({children}: {children: ReactNode}) {
return <QueryClientProvider client={queryClient}><I18nProvider><ThemeProvider><RootTooltipProvider>{children}</RootTooltipProvider></ThemeProvider></I18nProvider></QueryClientProvider>
}
-function Delivery({messages}: {messages: ThreadMessage[]}) {
- const runtime = useExternalStoreRuntime<ThreadMessage>({messages, isRunning:false, onNew:async()=>{}})
- return <AssistantRuntimeProvider runtime={runtime}><ThreadPrimitive.Root><ThreadPrimitive.Messages components={{Message: SystemMessage}}/></ThreadPrimitive.Root></AssistantRuntimeProvider>
-}
-Object.assign(window, {renderProducer(rows: SessionMessage[]) {
- const hydrated = toChatMessages(rows)
- const runtime = hydrated.map(toRuntimeMessage)
- const mount = document.createElement('section'); mount.id = 'producer'; document.body.append(mount)
- createRoot(mount).render(<Providers><Delivery messages={runtime}/></Providers>)
- return {hydrated,runtime}
-}})
-createRoot(document.getElementById('root')!).render(<Providers><main style={{padding:40}}><h1>Production Markdown renderer probe</h1>{Object.entries({hard,soft,code,...ingress}).map(([id,text])=><section id={id} key={id}><h2>{id}</h2><MarkdownTextContent text={text} isRunning={false}/></section>)}</main></Providers>)
+createRoot(document.getElementById('root')!).render(<Providers><main style={{padding:40}}><h1>Production Markdown renderer probe</h1>{Object.entries(cases).map(([id, {text}]) => <section id={id} key={id}><h2>{id}</h2><MarkdownTextContent text={text} isRunning={false}/></section>)}</main></Providers>)