Files
hapi/web/src/router.hooks.test.ts
T
AnanovoandGitHub 82c5c00a38 feat(web,hub): add opt-in search for session message content (#1598)
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
2026-11-02 15:20:45 +00:00

34 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
/**
* SessionPage returns early while session data is still loading. A hook
* declared after that branch only runs once the data resolves, which changes
* the hook count between renders and makes React throw "Rendered more hooks
* than during the previous render" — breaking ordinary session opening, not
* just search deep links (tiann/hapi#1598 review).
*/
describe('SessionPage hook order', () => {
const source = readFileSync(resolve(__dirname, 'router.tsx'), 'utf8')
const lines = source.split('\n')
it('declares every hook before the session loading early return', () => {
const guardIndex = lines.findIndex((line) => line.trim() === 'if (!session) {')
expect(guardIndex).toBeGreaterThan(-1)
// Where SessionPage's body ends: the next top-level function.
const endIndex = lines.findIndex(
(line, index) => index > guardIndex && /^(function|const) \w+/.test(line)
)
const tail = lines.slice(guardIndex, endIndex === -1 ? undefined : endIndex)
const offenders = tail
.map((line, index) => ({ line: line.trim(), at: guardIndex + index + 1 }))
.filter(({ line }) => /^\s*const .*=\s*use(Callback|Memo|Effect|State|Ref|LayoutEffect)\(/.test(line)
|| /^\s*use(Effect|LayoutEffect)\(/.test(line))
expect(offenders).toEqual([])
})
})