mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-18 03:27:08 +00:00
Adds an opt-in content search over session messages, alongside the existing metadata search. An FTS5 index covers visible user and assistant prose; the sidebar gains a scope toggle, and selecting a result opens the matching message rather than the session tail. Search scope is a two-state toggle rather than a dropdown: a 48x48 target matching the clear endcap, distinct glyphs for session details vs message text, tooltips naming the real scopes, and the active mode kept on the collapsed chip (tiann/hapi#2081). Dogfooded on a live 1178-session fleet. The scope toggle and reading forward from a search result were both click-tested on that install — the latter walking six bounded pages through a 1,507-message session and stopping correctly at the session head. The per-commit history does not survive this squash; the review trail — including which commit closed which finding — is on the PR threads. Fixes #1554 Fixes #2081
60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { describe, expect, it } from 'bun:test'
|
|
import type { Database } from 'bun:sqlite'
|
|
import { Store } from '../src/store'
|
|
import { deleteSessions } from './cleanup-sessions'
|
|
|
|
function makeSession(store: Store, tag: string) {
|
|
return store.sessions.getOrCreateSession(tag, { path: `/tmp/${tag}` }, null, 'default')
|
|
}
|
|
|
|
function failSessionDelete(store: Store): void {
|
|
const db = (store as unknown as { db: Database }).db
|
|
db.exec(`
|
|
CREATE TRIGGER fail_session_delete
|
|
BEFORE DELETE ON sessions
|
|
BEGIN
|
|
SELECT RAISE(ABORT, 'forced session delete failure');
|
|
END
|
|
`)
|
|
}
|
|
|
|
describe('cleanup session bulk deletion', () => {
|
|
it('removes derived content rows with the deleted sessions', () => {
|
|
const store = new Store(':memory:')
|
|
const first = makeSession(store, 'cleanup-script-first')
|
|
const second = makeSession(store, 'cleanup-script-second')
|
|
for (const session of [first, second]) {
|
|
store.messages.addMessage(session.id, {
|
|
role: 'user',
|
|
content: { type: 'text', text: 'cleanup script phrase' }
|
|
})
|
|
}
|
|
|
|
const db = (store as unknown as { db: Database }).db
|
|
expect(deleteSessions(db, [first.id, second.id])).toBe(2)
|
|
expect(store.messages.searchContent('cleanup script phrase', 'default')).toEqual([])
|
|
expect(store.sessions.getSession(first.id)).toBeNull()
|
|
expect(store.sessions.getSession(second.id)).toBeNull()
|
|
})
|
|
|
|
it('rolls back derived cleanup when canonical session deletion fails', () => {
|
|
const store = new Store(':memory:')
|
|
const first = makeSession(store, 'cleanup-script-rollback-first')
|
|
const second = makeSession(store, 'cleanup-script-rollback-second')
|
|
for (const session of [first, second]) {
|
|
store.messages.addMessage(session.id, {
|
|
role: 'user',
|
|
content: { type: 'text', text: 'cleanup rollback phrase' }
|
|
})
|
|
}
|
|
failSessionDelete(store)
|
|
|
|
const db = (store as unknown as { db: Database }).db
|
|
expect(() => deleteSessions(db, [first.id, second.id]))
|
|
.toThrow('forced session delete failure')
|
|
expect(store.messages.searchContent('cleanup rollback phrase', 'default')).toHaveLength(2)
|
|
expect(store.sessions.getSession(first.id)).not.toBeNull()
|
|
expect(store.sessions.getSession(second.id)).not.toBeNull()
|
|
})
|
|
})
|