Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/ui/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ func TestComposeSuggestions_MultiRecipientInsert(t *testing.T) {
// Sending must persist user-typed "Name <addr>" recipients into the contacts
// store so autocomplete knows them next time (no contacts file needed).
func TestHarvestTypedRecipients(t *testing.T) {
s := contacts.Load(filepath.Join(t.TempDir(), "contacts"))
cachePath := filepath.Join(t.TempDir(), "contacts")
s := contacts.Load(cachePath)
m := Model{contacts: s}
m.harvestTypedRecipients(
"Max Muster <max@muster.example>, bare@x.io",
Expand All @@ -109,4 +110,8 @@ func TestHarvestTypedRecipients(t *testing.T) {
// Nil store: must be a no-op, not a panic.
nilModel := Model{}
nilModel.harvestTypedRecipients("A <a@b.io>")

// harvestTypedRecipients persists via safeGo(SaveIfDirty) — wait for
// the write before TempDir cleanup runs.
waitForFile(t, cachePath)
}
25 changes: 25 additions & 0 deletions internal/ui/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ui

import (
"os"
"testing"
"time"
)

// waitForFile blocks until path exists on disk. Tests that trigger async
// persistence (safeGo → Save) into a t.TempDir must call this before
// returning: the test's TempDir cleanup otherwise races the goroutine and
// fails with "unlinkat … directory not empty" (flaky under -count / -race).
func waitForFile(t *testing.T, path string) {
t.Helper()
deadline := time.Now().Add(2 * time.Second)
for {
if _, err := os.Stat(path); err == nil {
return
}
if !time.Now().Before(deadline) {
t.Fatalf("%s never landed on disk", path)
}
time.Sleep(2 * time.Millisecond)
}
}
3 changes: 3 additions & 0 deletions internal/ui/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,9 @@ func TestApplySenderRules_PersistsMatches(t *testing.T) {
if n := m.applySenderRules(emails); n != 1 {
t.Errorf("applySenderRules = %d, want 1", n)
}
// applySenderRules persists via safeGo(store.Save) — wait for the
// write before TempDir cleanup runs.
waitForFile(t, path)
if title, ok := s.TitleOf("<new1>"); !ok || title != "Bounces" {
t.Errorf("<new1> should now belong to Bounces, got %q %v", title, ok)
}
Expand Down