Files
docker-agent/pkg/sqliteutil
Arnaud Héritier 31593b26d8 fix(tui): close SQLite stores deterministically so Windows can delete t.TempDir
The windows-tests CI job flakes with:

    TempDir RemoveAll cleanup: unlinkat ...\data\tui_state.db (or session.db):
    The process cannot access the file because it is being used by another process.

Windows refuses to delete a file while a handle is open, and Go's testing
package retries for only 2s. Two things kept SQLite handles alive past
that window in the tuitest-driven e2e/tui tests:

- tui_state.db was closed only by the detached goroutine armed in
  contextShutdownCmd, gated on ctx.Done() and never joined. tuitest's
  cleanup quit the program but never released the model's resources, so
  the close (WAL checkpoint + fsync on a slow runner) raced t.TempDir.
- sql.DB.Close only closes idle connections; one checked out by an
  in-flight persistence write (token usage, title) is released after
  Close has already returned, unobserved by the test.

Add sqliteutil.CloseDB, which closes and then waits (bounded) for every
connection to be released, and use it from the tuistate and session
stores. Export Shutdown on the TUI model and have tuitest.New call it
after the program stops, so every driver-based test closes tui_state.db
synchronously before rt.Close, store.Close and t.TempDir run.
2026-09-09 10:10:52 +00:00
..