Files
hermes-agent/apps/desktop/src/lib/async-report.test.ts
Teknium f6a4a5adde fix: keep multiline delegation goals out of Desktop report bodies
Recognize the full producer task header when a batch goal spans lines,
so the next task goal and preceding transcript footer cannot become part
of the displayed result. Extend the existing invariant and real SQLite
producer probe with that case.

Make the live probe artifact path explicit, run Chromium headlessly, and
document its synthetic fixtures and integration fidelity limits.
2026-09-07 05:06:39 -07:00

49 lines
2.0 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { toChatMessages } from '@/lib/chat-messages/hydration'
import { toRuntimeMessage } from '@/lib/chat-runtime'
const report = '# Report\n\n**Conclusion:** ready\n\n| Task | Status |\n|---|---|\n| probe | ok |'
const envelope = (body: string) =>
`[ASYNC DELEGATION COMPLETE — probe]\nPrivate instructions\nOriginal goal: private goal\nRole: leaf\n--- RESULT ---\n${body}`
function hydrate(content: string) {
return toRuntimeMessage(
toChatMessages([
{
role: 'user',
content,
display_kind: 'async_delegation_complete',
display_metadata: { delegation_id: 'probe', task_count: 1 }
}
])[0]
)
}
describe('async report hydration', () => {
it('keeps only result bodies beside compact system metadata across current and legacy deliveries', () => {
for (const input of [
envelope(report),
envelope(
`Cron job 'probe' (id) finished its manual run.\nResult: ok\nDelivery target: local\n--- JOB OUTPUT ---\n${report}`
),
report
]) {
const message = hydrate(input)
expect(message.role).toBe('system')
expect(message.content).toEqual([{ type: 'text', text: '1 background agent finished' }])
expect(message.metadata.custom.asyncResult).toBe(report)
}
})
it('separates batch result blocks without leaking preambles or transcript plumbing', () => {
const content = `[ASYNC DELEGATION BATCH COMPLETE — batch]\nPrivate instructions\nRole: leaf\n\n--- ✓ TASK 1/2: private goal (status=completed) ---\n${report}\nFull live transcript (complete tool/assistant trace): /private/path\n\n--- ✓ TASK 2/2: private goal\nprivate continuation (status=completed) ---\nPlain result`
expect(hydrate(content).metadata.custom.asyncResult).toBe(`${report}\n\nPlain result`)
expect(
hydrate('[ASYNC DELEGATION COMPLETE — malformed]\nPrivate instructions').metadata.custom.asyncResult
).toBeUndefined()
expect(hydrate('').metadata.custom.asyncResult).toBeUndefined()
})
})