fix(tui): save live transcript from slash command

This commit is contained in:
helix4u 2026-04-25 15:45:13 -06:00 committed by Teknium
parent 8bbeaea6c7
commit 1b8ca9254f
2 changed files with 108 additions and 0 deletions

View file

@ -1,3 +1,5 @@
import { existsSync, readFileSync, unlinkSync } from 'node:fs'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createSlashHandler } from '../app/createSlashHandler.js'
@ -287,6 +289,58 @@ describe('createSlashHandler', () => {
expect(ctx.transcript.page).not.toHaveBeenCalled()
expect(ctx.transcript.sys).toHaveBeenCalledWith('no conversation yet')
})
it('/save writes the current TUI transcript without using the slash worker', () => {
vi.useFakeTimers()
vi.setSystemTime(new Date(2026, 3, 25, 15, 4, 5))
const filename = 'hermes_conversation_20260425_150405.json'
try {
if (existsSync(filename)) {
unlinkSync(filename)
}
const ctx = buildCtx({
local: {
...buildLocal(),
getHistoryItems: vi.fn(() => [
{ role: 'system', text: 'intro' },
{ role: 'user', text: 'hello' },
{ role: 'assistant', text: 'hi there', tools: ['read_file'] },
{ role: 'tool', text: 'tool output' }
])
}
})
createSlashHandler(ctx)('/save')
expect(ctx.gateway.gw.request).not.toHaveBeenCalled()
expect(ctx.transcript.sys).toHaveBeenCalledWith(`conversation saved to: ${filename}`)
const saved = JSON.parse(readFileSync(filename, 'utf8'))
expect(saved.messages).toEqual([
{ role: 'user', text: 'hello' },
{ role: 'assistant', text: 'hi there', tools: ['read_file'] },
{ role: 'tool', text: 'tool output' }
])
} finally {
if (existsSync(filename)) {
unlinkSync(filename)
}
vi.useRealTimers()
}
})
it('/save reports empty state without touching the slash worker', () => {
const ctx = buildCtx()
createSlashHandler(ctx)('/save')
expect(ctx.gateway.gw.request).not.toHaveBeenCalled()
expect(ctx.transcript.sys).toHaveBeenCalledWith('no conversation yet')
})
})
const buildCtx = (overrides: Partial<Ctx> = {}): Ctx => ({