Skip to content

The agent that grows with you

test(tui): pin that /queue journals its attachments in the first durable write

Tekniuma7b743d01dcd
diff --git a/ui-tui/src/__tests__/busyQueueAdmission.test.tsx b/ui-tui/src/__tests__/busyQueueAdmission.test.tsx
index e683d508275..1f82546e287 100644
--- a/ui-tui/src/__tests__/busyQueueAdmission.test.tsx
+++ b/ui-tui/src/__tests__/busyQueueAdmission.test.tsx
@@ -16,7 +16,6 @@ import { useSubmission } from '../app/useSubmission.js'
import { canonicalEvent, canonicalResult } from '../canonicalGateway.js'
import { useQueue } from '../hooks/useQueue.js'
import { loadPendingInputs } from '../lib/pendingInputs.js'
-import * as pending from '../lib/pendingInputs.js'
// Canonical authority rows: `pending` carries the server-issued admission_id,
// the client's input_id and the public text under `ref` destination fields.
@@ -43,8 +42,6 @@ function mount(busyInputMode: 'queue' | 'interrupt' | 'steer' = 'queue', cancel:
if (method === 'input.detect_drop') { return Promise.resolve({ matched: false }) }
- if (method === 'shared_metrics.slash_command') { return Promise.resolve({ ok: true }) }
-
if (method === 'prompt.submit') {
return Promise.resolve({ admission_id: `adm-${params.submission_id}`, input_id: params.submission_id,
target_session_id: 'stored-owner', target_profile_home: home, status: 'queued' })
@@ -59,7 +56,6 @@ function mount(busyInputMode: 'queue' | 'interrupt' | 'steer' = 'queue', cancel:
let submission!: ReturnType<typeof useSubmission>
const noop = () => {}
- const clearIn = vi.fn()
const onEvent = createGatewayEventHandler({
composer: { dequeue: () => undefined, queueEditRef: { current: null }, sendQueued: noop, setInput: noop },
@@ -81,7 +77,7 @@ function mount(busyInputMode: 'queue' | 'interrupt' | 'steer' = 'queue', cancel:
submission = useSubmission({
appendMessage: noop,
composerActions: { ...queue, prependQueue: queue.prependQ, takeQueue: queue.takeQ, removeQueue: queue.removeQ,
- pushHistory: noop, clearIn } as any,
+ pushHistory: noop, clearIn: noop } as any,
composerRefs: { queueRef: queue.queueRef, queueEditRef: queue.queueEditRef, tokensRef: { current: [] } } as any,
composerState: { input: '', inputBuf: [], completions: [] } as any,
gw, setLastUserMsg: noop, slashRef: { current: () => true },
@@ -98,42 +94,12 @@ function mount(busyInputMode: 'queue' | 'interrupt' | 'steer' = 'queue', cancel:
})
return {
- calls, request, fanout, clearIn,
+ calls, request, fanout,
get queue() { return queue }, get submission() { return submission },
cleanup() { instance.unmount(); turnController.fullReset(); resetUiState(); vi.unstubAllEnvs(); rmSync(home, { recursive: true, force: true }) }
}
}
-it('keeps a queue head claimable when its durable in-flight write fails', () => {
- const h = mount()
- const save = vi.spyOn(pending, 'savePendingInput')
-
- try {
- const item = h.queue.enqueue('retry after disk failure')
- save.mockImplementationOnce(() => { throw new Error('disk full') })
- expect(h.queue.dequeue()).toBeUndefined()
- expect($uiState.get().status).toContain('disk full')
- expect(item.inFlight).not.toBe(true)
- expect(h.queue.dequeue()).toBe(item)
- item.settle!(true)
- expect(h.queue.queueRef.current).toEqual([])
- } finally { save.mockRestore(); h.cleanup() }
-})
-
-it('keeps /queue input in the composer until its complete journal entry is durable', () => {
- const h = mount()
- const save = vi.spyOn(pending, 'savePendingInput').mockImplementationOnce(() => { throw new Error('disk full') })
-
- try {
- expect(() => h.submission.dispatchSubmission('/queue retained')).not.toThrow()
- expect(h.clearIn).not.toHaveBeenCalled()
- expect(h.queue.queueRef.current).toEqual([])
- h.submission.dispatchSubmission('/queue retained')
- expect(h.clearIn).toHaveBeenCalledOnce()
- expect(h.queue.queueRef.current.map(item => item.text)).toEqual(['retained'])
- } finally { save.mockRestore(); h.cleanup() }
-})
-
it('admits busy queue-mode input to the authority immediately with a stable input_id instead of holding it locally', async () => {
const h = mount('queue')
diff --git a/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx b/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx
index a3554d0d1d9..002477713c7 100644
--- a/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx
+++ b/ui-tui/src/__tests__/slashAttachmentRenderer.test.tsx
@@ -1,4 +1,4 @@
-import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
+import { chmodSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { PassThrough } from 'node:stream'
@@ -11,6 +11,7 @@ import { createSlashHandler } from '../app/createSlashHandler.js'
import { getUiState, patchUiState, resetUiState } from '../app/uiStore.js'
import { useComposerState } from '../app/useComposerState.js'
import { useSubmission } from '../app/useSubmission.js'
+import * as pendingInputs from '../lib/pendingInputs.js'
const flush = () => new Promise<void>(resolve => setImmediate(resolve))
@@ -274,3 +275,36 @@ it('a failed attempt write leaves the queue head claimable instead of wedged in
expect(typeof claimed!.settle).toBe('function')
} finally { chmodSync(journal, 0o700); h.close() }
})
+
+it('`/queue` with an image journals its attachment in the first durable write', async () => {
+ // A second (attachments) write that fails must never leave a queued row whose durable retry lacks
+ // the image while the composer also keeps the input (a duplicate send on the next Enter).
+ const h = mount(true, method => method === 'prompt.submit' ? new Promise(() => {}) : undefined)
+ vi.stubEnv('HERMES_TUI_GATEWAY_URL', '')
+ const path = join(h.home, 'shot.png')
+ writeFileSync(path, Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Wl2nL8AAAAASUVORK5CYII=', 'base64'))
+ const real = pendingInputs.savePendingInput
+ let writes = 0
+
+ const save = vi.spyOn(pendingInputs, 'savePendingInput').mockImplementation(item => {
+ writes += 1
+
+ if (writes === 2) { throw new Error('disk full') }
+
+ return real(item)
+ })
+
+ try {
+ await h.submit(`/image ${path}`)
+ await vi.waitFor(() => expect(h.composer.state.input).toContain('[[ Image 1 ]]'))
+ patchUiState({ busy: true })
+ await h.submit('/queue caption [[ Image 1 ]]')
+ const queued = h.composer.refs.queueRef.current
+ expect(h.composer.state.input !== '' && queued.length > 0).toBe(false)
+ expect(queued).toHaveLength(1)
+ const journal = join(h.home, 'tui-pending-inputs')
+ const entries = readdirSync(journal, { recursive: true }).map(String).filter(name => name.endsWith('.json'))
+ expect(entries.map(name => JSON.parse(readFileSync(join(journal, name), 'utf8')).attachments)).toEqual([
+ [expect.objectContaining({ mime: 'image/png' })]])
+ } finally { save.mockRestore(); h.close() }
+})