mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-12-03 03:29:51 +00:00
test: deflake the Sessions drawer and TUI startup tests (#1432)
Some checks failed
CI / semgrep (push) Waiting to run
macOS Menubar CI / test (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (22.13.0) (push) Waiting to run
Tests / test (24) (push) Waiting to run
Tests / test (26) (push) Waiting to run
Tests / test-platforms (macos-latest) (push) Waiting to run
Tests / test-platforms (windows-latest) (push) Waiting to run
Tests / desktop (push) Waiting to run
Windows Menubar CI / check (ubuntu-latest) (push) Has been cancelled
Windows Menubar CI / check (windows-latest) (push) Has been cancelled
Some checks failed
CI / semgrep (push) Waiting to run
macOS Menubar CI / test (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (22.13.0) (push) Waiting to run
Tests / test (24) (push) Waiting to run
Tests / test (26) (push) Waiting to run
Tests / test-platforms (macos-latest) (push) Waiting to run
Tests / test-platforms (windows-latest) (push) Waiting to run
Tests / desktop (push) Waiting to run
Windows Menubar CI / check (ubuntu-latest) (push) Has been cancelled
Windows Menubar CI / check (windows-latest) (push) Has been cancelled
* test: wait for the drawer close callback and give the TUI frame wait a time budget * test(dashboard): await the indexing settle callback instead of polling frames
This commit is contained in:
parent
bdf7ecb3e3
commit
e0da54c90f
3 changed files with 19 additions and 24 deletions
|
|
@ -255,7 +255,7 @@ describe('Sessions', () => {
|
|||
getSessions.mockResolvedValue(rows.slice(1))
|
||||
view.rerender(<Sessions period="30days" provider="all" refreshToken={1} openSessionId={openKey} onSessionClose={onSessionClose} />)
|
||||
await screen.findByText(/5 sessions · \$13\.52/)
|
||||
expect(onSessionClose).toHaveBeenCalled()
|
||||
await waitFor(() => expect(onSessionClose).toHaveBeenCalled())
|
||||
})
|
||||
|
||||
it('shows the selection chips, per-row contributions, and the separately-labeled full cost', async () => {
|
||||
|
|
|
|||
|
|
@ -1560,7 +1560,7 @@ function ScrollableViewport({ children, width, lineScroll = true }: { children:
|
|||
)
|
||||
}
|
||||
|
||||
export function InteractiveDashboard({ initialProjects, initialDailyHistoryProjects, initialPeriod, initialProvider, initialPlanUsages, initialDurable, refreshSeconds, projectFilter, excludeFilter, customRange, customRangeLabel, initialDay, windowColumns, initialIndexPendingFiles, initialHistoryIndexing = false, initialCacheWasCold = false, initialHistoryIndex, autoFallbackFromEmptyToday = false, terminateProcess }: {
|
||||
export function InteractiveDashboard({ initialProjects, initialDailyHistoryProjects, initialPeriod, initialProvider, initialPlanUsages, initialDurable, refreshSeconds, projectFilter, excludeFilter, customRange, customRangeLabel, initialDay, windowColumns, initialIndexPendingFiles, initialHistoryIndexing = false, initialCacheWasCold = false, initialHistoryIndex, autoFallbackFromEmptyToday = false, terminateProcess, onHistoryIndexed }: {
|
||||
initialProjects: ProjectSummary[]
|
||||
initialDailyHistoryProjects?: ProjectSummary[]
|
||||
initialPeriod: Period
|
||||
|
|
@ -1581,6 +1581,7 @@ export function InteractiveDashboard({ initialProjects, initialDailyHistoryProje
|
|||
initialCacheWasCold?: boolean
|
||||
initialHistoryIndex?: DashboardHistoryIndex
|
||||
autoFallbackFromEmptyToday?: boolean
|
||||
onHistoryIndexed?: () => void
|
||||
/// CLI-only hard stop after Ink has been asked to restore the terminal.
|
||||
/// Component tests and embedders omit it and receive ordinary Ink exit.
|
||||
terminateProcess?: (exitCode: number) => void
|
||||
|
|
@ -1618,6 +1619,8 @@ export function InteractiveDashboard({ initialProjects, initialDailyHistoryProje
|
|||
const [indexPhase, setIndexPhase] = useState<DashboardIndexPhase>(initialCacheWasCold ? 'week' : 'cached')
|
||||
const historyIndexRef = useRef<DashboardHistoryIndex | null>(initialHistoryIndex ?? null)
|
||||
const autoFallbackAppliedRef = useRef(false)
|
||||
const onHistoryIndexedRef = useRef(onHistoryIndexed)
|
||||
onHistoryIndexedRef.current = onHistoryIndexed
|
||||
const quitArmedRef = useRef(false)
|
||||
// #1143: first q during the cold-start fill arms a confirmation so the user
|
||||
// sees feedback instead of a silent ~16.5s drain. The second q (or any
|
||||
|
|
@ -1867,7 +1870,9 @@ export function InteractiveDashboard({ initialProjects, initialDailyHistoryProje
|
|||
if (!cancelled) console.error(error)
|
||||
}).finally(() => {
|
||||
clearInterval(progressId)
|
||||
if (!cancelled) setIndexing(false)
|
||||
if (cancelled) return
|
||||
setIndexing(false)
|
||||
onHistoryIndexedRef.current?.()
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
|
|
|
|||
|
|
@ -102,6 +102,8 @@ async function renderAutoPeriodDashboard(initialProjects: ProjectSummary[], init
|
|||
stdout.rows = 50
|
||||
const frames: string[] = []
|
||||
stdout.on('data', chunk => frames.push(stripAnsi(String(chunk))))
|
||||
let indexed!: () => void
|
||||
const settled = new Promise<void>(resolve => { indexed = resolve })
|
||||
const app = render(React.createElement(InteractiveDashboard, {
|
||||
initialProjects,
|
||||
initialPeriod: 'today',
|
||||
|
|
@ -112,19 +114,15 @@ async function renderAutoPeriodDashboard(initialProjects: ProjectSummary[], init
|
|||
initialHistoryIndexing: true,
|
||||
initialCacheWasCold: true,
|
||||
autoFallbackFromEmptyToday: true,
|
||||
onHistoryIndexed: indexed,
|
||||
}), { stdin, stdout, debug: true, interactive: true, patchConsole: false })
|
||||
onTestFinished(() => app.unmount())
|
||||
return { app, frames }
|
||||
}
|
||||
|
||||
async function waitForFrame(app: ReturnType<typeof render>, frames: string[], predicate: (frame: string) => boolean): Promise<string> {
|
||||
for (let attempt = 0; attempt < 200; attempt++) {
|
||||
const settledFrame = async (): Promise<string> => {
|
||||
await settled
|
||||
await app.waitUntilRenderFlush()
|
||||
const frame = frames.filter(value => value.trim()).at(-1) ?? ''
|
||||
if (predicate(frame)) return frame
|
||||
await new Promise(resolve => setTimeout(resolve, 20))
|
||||
return frames.filter(value => value.trim()).at(-1) ?? ''
|
||||
}
|
||||
return frames.filter(value => value.trim()).at(-1) ?? ''
|
||||
return { app, frames, settledFrame }
|
||||
}
|
||||
|
||||
describe('interactive dashboard progressive startup', () => {
|
||||
|
|
@ -135,17 +133,13 @@ describe('interactive dashboard progressive startup', () => {
|
|||
)
|
||||
expect(paint.result.filteredProjects).toEqual([])
|
||||
|
||||
const { app, frames } = await renderAutoPeriodDashboard(
|
||||
const { app, frames, settledFrame } = await renderAutoPeriodDashboard(
|
||||
paint.result.filteredProjects,
|
||||
paint.result.initialDurable,
|
||||
)
|
||||
await app.waitUntilRenderFlush()
|
||||
expect(frames.filter(value => value.trim()).at(-1)).toContain('[ Today ]')
|
||||
const frame = await waitForFrame(
|
||||
app,
|
||||
frames,
|
||||
value => value.includes('[ 7 Days ]') && !value.includes('indexing'),
|
||||
)
|
||||
const frame = await settledFrame()
|
||||
|
||||
expect(frame).toContain('[ 7 Days ]')
|
||||
expect(frame).toContain('proj')
|
||||
|
|
@ -159,17 +153,13 @@ describe('interactive dashboard progressive startup', () => {
|
|||
)
|
||||
expect(paint.result.filteredProjects).toHaveLength(1)
|
||||
|
||||
const { app, frames } = await renderAutoPeriodDashboard(
|
||||
const { app, frames, settledFrame } = await renderAutoPeriodDashboard(
|
||||
paint.result.filteredProjects,
|
||||
paint.result.initialDurable,
|
||||
)
|
||||
await app.waitUntilRenderFlush()
|
||||
expect(frames.filter(value => value.trim()).at(-1)).toContain('[ Today ]')
|
||||
const frame = await waitForFrame(
|
||||
app,
|
||||
frames,
|
||||
value => value.includes('[ Today ]') && !value.includes('indexing'),
|
||||
)
|
||||
const frame = await settledFrame()
|
||||
|
||||
expect(frame).toContain('[ Today ]')
|
||||
expect(frame).not.toContain('[ 7 Days ]')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue