2026-10-24 10:37:46 +02:00
|
|
|
package test
|
|
|
|
|
|
2026-10-24 11:15:35 +02:00
|
|
|
// Process-boundary test for the quiet-hours toast: quiet_mode = toast during
|
|
|
|
|
// active quiet hours fires a desktop notification — here a fake notify-send
|
|
|
|
|
// in the daemon's PATH that logs its arguments.
|
2026-10-24 10:37:46 +02:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"runtime"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2026-10-24 11:15:35 +02:00
|
|
|
func TestQuietHoursToastShowsNotification(t *testing.T) {
|
2026-10-24 10:37:46 +02:00
|
|
|
if runtime.GOOS != "linux" {
|
2026-10-24 11:15:35 +02:00
|
|
|
t.Skip("the fake notify-send exists only on Linux")
|
2026-10-24 10:37:46 +02:00
|
|
|
}
|
|
|
|
|
root := t.TempDir()
|
|
|
|
|
bin := filepath.Join(root, "bin")
|
|
|
|
|
if err := os.MkdirAll(bin, 0o755); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
seen := filepath.Join(root, "seen.txt")
|
|
|
|
|
script := "#!/bin/sh\nprintf '%s\\n' \"$@\" > \"" + seen + "\"\n"
|
|
|
|
|
if err := os.WriteFile(filepath.Join(bin, "notify-send"), []byte(script), 0o755); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
fake := newFakeProvider(t, 0)
|
|
|
|
|
d := startDaemon(t, root, fake.srv.URL, map[string]string{
|
2026-10-24 11:15:35 +02:00
|
|
|
"TALK_QUIET_HOURS": windowAround(),
|
2026-10-24 10:37:46 +02:00
|
|
|
"TALK_QUIET_MODE": "toast",
|
|
|
|
|
"PATH": bin + string(os.PathListSeparator) + os.Getenv("PATH"),
|
|
|
|
|
})
|
|
|
|
|
|
2026-10-24 11:15:35 +02:00
|
|
|
code, m := speak(t, d, `{"text":"Build done, please review"}`)
|
2026-10-24 10:37:46 +02:00
|
|
|
if code != 202 || m["discarded"] != "quiet_hours" || m["toast"] != true {
|
2026-10-24 11:15:35 +02:00
|
|
|
t.Fatalf("speak during quiet hours (toast): %d %v", code, m)
|
2026-10-24 10:37:46 +02:00
|
|
|
}
|
|
|
|
|
deadline := time.Now().Add(3 * time.Second)
|
|
|
|
|
for {
|
|
|
|
|
if b, err := os.ReadFile(seen); err == nil {
|
2026-10-24 11:15:35 +02:00
|
|
|
if !strings.Contains(string(b), "Build done, please review") || !strings.Contains(string(b), "talk") {
|
|
|
|
|
t.Errorf("notify-send arguments = %q", b)
|
2026-10-24 10:37:46 +02:00
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
if time.Now().After(deadline) {
|
2026-10-24 11:15:35 +02:00
|
|
|
t.Fatalf("notify-send was not called — daemon log:\n%s", d.stderr.String())
|
2026-10-24 10:37:46 +02:00
|
|
|
}
|
|
|
|
|
time.Sleep(25 * time.Millisecond)
|
|
|
|
|
}
|
|
|
|
|
fake.assertNoHits(t, 200*time.Millisecond)
|
|
|
|
|
}
|