From ffa4676a34851d667acbf8a460321ff93310b7ba Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Thu, 23 Jul 2026 21:01:05 +0200 Subject: cli: flag-driven interface (short+long); -u maximal blip-proof harvest Replace the today/date/show/compare/update subcommands with a single flag-driven interface like the Python predecessor: lectio [DATE] -a/-b/-c/-r/-w/-R/-o/-l/-g/-u, short and long names bound to the same variable, DATE (YYYY-MM-DD) extracted from any position in the args. Fix Harvest's "-u" to walk to the true maximal horizon without a transient network error being mistaken for it: a fetch failure now retries a few times with backoff and, if it still fails, is reported as an error (after saving partial progress via writeSigla), while a Parse failure (the real unpublished-horizon placeholder) still stops cleanly with a nil error. --- internal/liturgy/store_test.go | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'internal/liturgy/store_test.go') diff --git a/internal/liturgy/store_test.go b/internal/liturgy/store_test.go index 08fd1a1..1bf8343 100644 --- a/internal/liturgy/store_test.go +++ b/internal/liturgy/store_test.go @@ -6,6 +6,7 @@ import ( "os" "strings" "testing" + "time" ) func TestHarvestAndOffline(t *testing.T) { @@ -47,3 +48,53 @@ func TestHarvestAndOffline(t *testing.T) { t.Error("offline first czytanie PartID missing") } } + +// TestHarvestFetchErrorSavesPartialProgress exercises the transient-error +// path: a genuine network/transport failure on a date must NOT be mistaken +// for the unpublished horizon (that is Parse's job, on a "Przykro nam" page +// -- see TestHarvestAndOffline above, which stays nil-error). It must +// instead surface as a returned error, after writeSigla has still saved +// whatever was harvested before the failing date. +func TestHarvestFetchErrorSavesPartialProgress(t *testing.T) { + html, _ := os.ReadFile("testdata/2026-07-22.html") + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if strings.Contains(r.URL.Path, "2026-07-22") { + w.Write(html) + return + } + // Simulate a network/transport error (not a "Przykro nam" horizon + // page) by hijacking the connection and closing it without a + // response, so the client sees a read/EOF error. + hj, ok := w.(http.Hijacker) + if !ok { + t.Fatal("test server ResponseWriter does not support hijacking") + } + conn, _, err := hj.Hijack() + if err != nil { + t.Fatal(err) + } + conn.Close() + })) + defer srv.Close() + t.Setenv("XDG_CACHE_HOME", t.TempDir()) + t.Setenv("XDG_DATA_HOME", t.TempDir()) + baseURL = srv.URL + "/liturgia/%s/Ewangelia" + + origRetries, origDelay := harvestRetries, harvestRetryDelay + harvestRetries, harvestRetryDelay = 2, time.Millisecond + defer func() { harvestRetries, harvestRetryDelay = origRetries, origDelay }() + + added, furthest, err := Harvest("2026-07-22", 0) + if err == nil { + t.Fatal("harvest: want error on a fetch failure, got nil") + } + if added != 1 || furthest != "2026-07-22" { + t.Errorf("harvest: added=%d furthest=%q, want added=1 furthest=2026-07-22 (only the one date fetched before the network error)", added, furthest) + } + + // Progress made before the failing date must still be on disk. + secs, offErr := LoadOffline("2026-07-22") + if offErr != nil || len(secs) == 0 { + t.Errorf("harvest: partial progress not saved: offErr=%v secs=%v", offErr, secs) + } +} -- cgit v1.3