Add the TUI.
A table with one row per URL, a level-colored log pane and a status bar. New alerts flash their row and ring the bell. Keys pause, force checks, open the product page or cart link, and reload the config, which is validated first and applied in place, keeping each URL's timing. Headless mode and the TUI now share one watcher. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f0eda5d4d
commit
a19e6fa711
14 files changed
+1359
-105
No files matched your search
@@ -179,3 +179,45 @@ func TestDuplicateURLs(t *testing.T) {
|
||||
|
||||
if _, _, err := New(context.Background(), cfg, host, nil, ratelimit.New(nil)); err == nil { t.Error("two spellings of one product were accepted") }
|
||||
}
|
||||
|
||||
func TestReload(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
clk := &clock{now: time.Date(2026, 10, 14, 12, 0, 0, 0, time.UTC)}
|
||||
|
||||
limiter := ratelimit.New(nil, ratelimit.WithClock(clk))
|
||||
|
||||
host, err := plugin.NewHost(nil, plugin.DefaultLimits(), slog.New(slog.NewTextHandler(io.Discard, nil)))
|
||||
if err != nil { t.Fatal(err) }
|
||||
defer host.Close()
|
||||
|
||||
f := &fetcher{limiter: limiter, clock: clk, requests: map[string][]time.Time{}, hosts: map[string][]time.Time{}}
|
||||
|
||||
s, _, err := New(ctx, &config.Config{Items: []config.Item{
|
||||
item("metro", ratelimit.URLFloor, "https://www.amazon.de/dp/B0HMX2FSTF", "https://www.amazon.co.uk/dp/B0HM497GJJ"),
|
||||
item("cable", ratelimit.URLFloor, "https://www.amazon.de/dp/B0DK51S84Z"),
|
||||
}}, host, f, limiter)
|
||||
if err != nil { t.Fatal(err) }
|
||||
|
||||
for _, tg := range s.due() { s.check(ctx, tg) }
|
||||
s.Pause("metro", true)
|
||||
|
||||
before := map[string]Status{}
|
||||
for _, st := range s.Statuses() { before[st.URL] = st }
|
||||
|
||||
// The DE URL stays under a new spelling, the UK one goes, cable is
|
||||
// renamed and a new item comes in.
|
||||
_, err = s.Reload(ctx, &config.Config{Items: []config.Item{
|
||||
item("metro", ratelimit.URLFloor, "https://www.amazon.de/dp/B0HMX2FSTF?th=1"),
|
||||
item("cable2", ratelimit.URLFloor, "https://www.amazon.de/dp/B0DK51S84Z"),
|
||||
item("disk", ratelimit.URLFloor, "https://www.amazon.de/dp/B076WS2WJ6"),
|
||||
}}, host)
|
||||
if err != nil { t.Fatal(err) }
|
||||
|
||||
got := s.Statuses()
|
||||
if len(got) != 3 { t.Fatalf("%d URLs after reload, want 3", len(got)) }
|
||||
|
||||
metro, cable, disk := got[0], got[1], got[2]
|
||||
if !metro.Paused || !metro.Last.Equal(before["https://www.amazon.de/dp/B0HMX2FSTF"].Last) { t.Errorf("metro lost its state: %+v", metro) }
|
||||
if cable.Item != "cable2" || !cable.Next.Equal(before["https://www.amazon.de/dp/B0DK51S84Z"].Next) { t.Errorf("cable lost its state: %+v", cable) }
|
||||
if disk.Paused || !disk.Last.IsZero() { t.Errorf("new item has old state: %+v", disk) }
|
||||
}
|
||||
Reference in new issue
Block a user