Skip to content

Commit e581b9f

Browse files
authored
test(store): drop double-close on raw sqlite handle in legacy-shape test (#68)
* test(store): remove double-close on raw sqlite handle in legacy-shape test The previous patch (#67) used both `defer db.Close()` and an explicit `db.Close()` to release the writer before opening the reader. That double-closes the handle and can mask the inner-Close error. Drop the defer; the explicit close is required (and now error-checked) so the reader sees a quiesced file. Per Copilot review on #67 (landed after merge). * test(store): t.Cleanup as failure-path Close safety net
1 parent 5a92624 commit e581b9f

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

internal/store/reader_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,13 @@ func TestReader_ListReceipts_OutputStatusMismatch_LegacyShape(t *testing.T) {
556556
if err != nil {
557557
t.Fatalf("open raw sqlite: %v", err)
558558
}
559-
defer db.Close()
559+
// Failure-path safety net: if any t.Fatalf below short-circuits the
560+
// explicit Close, t.Cleanup still releases the handle. database/sql's
561+
// DB.Close is idempotent (sets a `closed` flag, subsequent calls return
562+
// nil), so this is a no-op on the happy path. The explicit Close before
563+
// OpenReadOnly is the load-bearing one — it surfaces errors and quiesces
564+
// the file before the reader opens it.
565+
t.Cleanup(func() { _ = db.Close() })
560566

561567
const legacyReceiptJSON = `{
562568
"@context":["https://www.w3.org/ns/credentials/v2","https://agentreceipts.ai/context/v1"],
@@ -591,7 +597,9 @@ func TestReader_ListReceipts_OutputStatusMismatch_LegacyShape(t *testing.T) {
591597
); err != nil {
592598
t.Fatalf("insert legacy receipt: %v", err)
593599
}
594-
db.Close()
600+
if err := db.Close(); err != nil {
601+
t.Fatalf("close raw sqlite: %v", err)
602+
}
595603

596604
reader, err := OpenReadOnly(dbPath)
597605
if err != nil {

0 commit comments

Comments
 (0)