Implements spec #137 (spec 4 of 4 from wayfinder map #114). Closes #137. Tickets: #164, #165, #166, #167, #168, #169, #170, #171, #172, #173 — all closed, landed on this branch. ## Summary - #164/#168: sixth outcome word `not_found`; per-Site completed marker predicate. - #165/#169: `poll_failures` row is the failure state; the pass remembers a Site-reported completion. - #166/#171: two new admin filters (`failing`, `unverified`); outbound owner notification + stall condition. - #167/#170: a failure names itself on the Series page; the completion hint reaches the owner and decides nothing. - #172: the other three fault conditions (no-browser-route, sidecar-down, adapter-broken) feeding the notifier. - #173: the landing verdict line shares the same `latest.FaultsFrom` judgement the notifier uses, so the page and the push cannot disagree. `cd backend && go test ./...` green on the merged branch (8 packages). Reviewed-on: #174 Co-authored-by: Sulthan Zaki <sultankiki05@gmail.com> Co-committed-by: Sulthan Zaki <sultankiki05@gmail.com>
This commit was merged in pull request #174.
This commit is contained in:
+469
-27
@@ -918,7 +918,7 @@ func TestLanesRenderFromSeededRowsAfterRestart(t *testing.T) {
|
||||
seedPass(t, st, store.LanePass{Site: "asura", RanAt: now.Add(-time.Minute).UnixMilli(), Due: 5, Checked: 5, GapMS: 20_000})
|
||||
|
||||
body := lanesBody(t, router, st)
|
||||
if !strings.Contains(body, `class="c-site">asura</span>`) {
|
||||
if !strings.Contains(body, `<a class="c-site" href="/admin/series?filter=failing&site=asura">asura</a>`) {
|
||||
t.Fatalf("asura row missing from a restart-read database:\n%s", body)
|
||||
}
|
||||
// The fragment carries its own single timer and answers the swap it asked
|
||||
@@ -953,22 +953,32 @@ func TestSkipReasonIsNotAStall(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The five outcome counts render named — the page never prints the word
|
||||
// "failures" — and a Site with none observed says so rather than drawing a
|
||||
// blank cell.
|
||||
// The six outcome counts render named — the page never prints the word
|
||||
// "failures" — in the taxonomy's fixed order, not found beside the word it
|
||||
// split out of. A Site with none observed says so rather than drawing a
|
||||
// blank cell, and a zero not_found renders no chip of its own.
|
||||
func TestNamedOutcomeChips(t *testing.T) {
|
||||
router, st := newWebTestServer(t, lanesConfig())
|
||||
now := time.Now()
|
||||
seedPass(t, st, store.LanePass{Site: "asura", RanAt: now.UnixMilli(), Refused: 5, NoChapter: 2, Errors: 1})
|
||||
seedPass(t, st, store.LanePass{Site: "demonic", RanAt: now.UnixMilli(), Unreachable: 3, Unfetchable: 4})
|
||||
seedPass(t, st, store.LanePass{Site: "asura", RanAt: now.UnixMilli(), Refused: 5, Unreachable: 3, NoChapter: 2, Unfetchable: 4, NotFound: 6, Errors: 1})
|
||||
seedPass(t, st, store.LanePass{Site: "demonic", RanAt: now.UnixMilli(), Unreachable: 7, Unfetchable: 8})
|
||||
seedPass(t, st, store.LanePass{Site: "comix", RanAt: now.UnixMilli()})
|
||||
|
||||
body := lanesBody(t, router, st)
|
||||
for _, want := range []string{"refused 5", "no chapter 2", "errors 1", "unreachable 3", "unfetchable 4"} {
|
||||
for _, want := range []string{"refused 5", "unreachable 3", "no chapter 2", "unfetchable 4", "not found 6", "errors 1"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("lane chips lack %q:\n%s", want, body)
|
||||
}
|
||||
}
|
||||
wantSeq := `<span class="mark">refused 5</span><span class="mark-faint"> · </span><span class="mark">unreachable 3</span><span class="mark-faint"> · </span><span class="mark">no chapter 2</span><span class="mark-faint"> · </span><span class="mark">unfetchable 4</span><span class="mark-faint"> · </span><span class="mark">not found 6</span><span class="mark-faint"> · </span><span class="mark">errors 1</span>`
|
||||
if !strings.Contains(body, wantSeq) {
|
||||
t.Errorf("chips do not render in the fixed order (… unfetchable, not found, errors …):\n%s", body)
|
||||
}
|
||||
// demonic has outcomes but no not_found: exactly one "not found" in the
|
||||
// whole fragment — asura's — so a zero count renders none.
|
||||
if got := strings.Count(body, "not found"); got != 1 {
|
||||
t.Errorf("the word \"not found\" appears %d times, want exactly the one seeded chip", got)
|
||||
}
|
||||
if strings.Contains(body, "failures") {
|
||||
t.Errorf("the page prints the forbidden word \"failures\":\n%s", body)
|
||||
}
|
||||
@@ -979,6 +989,31 @@ func TestNamedOutcomeChips(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Each Site row on the Lanes page carries one plain navigation link to that
|
||||
// Site's failing Series — a navigation, not a number: the outcome chips
|
||||
// beside it stay unlinked permanently, so the row offers one click and one
|
||||
// answer. The clean Site links too, into an empty list (issue #167).
|
||||
func TestLaneSiteLinksToFailingSeriesAndChipsStayUnlinked(t *testing.T) {
|
||||
router, st := newWebTestServer(t, lanesConfig())
|
||||
now := time.Now()
|
||||
seedPass(t, st, store.LanePass{Site: "asura", RanAt: now.UnixMilli(), NotFound: 6})
|
||||
seedPass(t, st, store.LanePass{Site: "demonic", RanAt: now.UnixMilli()})
|
||||
|
||||
body := lanesBody(t, router, st)
|
||||
if !strings.Contains(body, `<a class="c-site" href="/admin/series?filter=failing&site=asura">asura</a>`) {
|
||||
t.Errorf("the failing Site's name is not a link to its failing Series:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, `<a class="c-site" href="/admin/series?filter=failing&site=demonic">demonic</a>`) {
|
||||
t.Errorf("the clean Site's name is not a link to its (empty) failing Series:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, `<span class="mark">not found 6</span>`) {
|
||||
t.Errorf("the outcome chip no longer renders beside the link:\n%s", body)
|
||||
}
|
||||
if got := strings.Count(body, `<a class="c-site"`); got != 2 {
|
||||
t.Errorf("Site anchor count = %d, want exactly 2 (only the two Site names navigate):\n%s", got, body)
|
||||
}
|
||||
}
|
||||
|
||||
// Browser configuration is a deployment fact and reachability is derived from
|
||||
// the latest browser-Site passes inside the refusal backoff — no poller in any
|
||||
// of the three.
|
||||
@@ -2177,14 +2212,15 @@ func TestNovelNewTabFallsBackToAll(t *testing.T) {
|
||||
// cannot produce an orphan series or a Reader-raised Latest Chapter — the
|
||||
// same reason the store's admin tests seed this way.
|
||||
type seriesRowSeed struct {
|
||||
key string
|
||||
kind string
|
||||
url string
|
||||
cover string // cover_address
|
||||
checkedAt int64
|
||||
latestNum *float64
|
||||
bookmarks int // readers that hold it; 0 = orphan
|
||||
raisedBy bool // a Reader's report is attributed as the raiser
|
||||
key string
|
||||
kind string
|
||||
url string
|
||||
cover string // cover_address
|
||||
checkedAt int64
|
||||
latestNum *float64
|
||||
bookmarks int // readers that hold it; 0 = orphan
|
||||
raisedBy bool // a Reader's report is attributed as the raiser
|
||||
siteCompletedAt int64 // the Site's own marker (issue #168), 0 = not set
|
||||
}
|
||||
|
||||
// seedSeriesRow inserts one series row and its bookmarks (owner first, then
|
||||
@@ -2204,10 +2240,10 @@ func seedSeriesRow(t *testing.T, st *store.Store, db *sql.DB, seed seriesRowSeed
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
INSERT INTO series (site, series_id, title, kind, series_url, cover_address,
|
||||
latest_checked_at, latest_chapter, latest_chapter_num)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
|
||||
latest_checked_at, latest_chapter, latest_chapter_num, site_completed_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`,
|
||||
site, seriesID, "Title of "+seed.key, seed.kind, seed.url, seed.cover,
|
||||
seed.checkedAt, latestChapter, seed.latestNum); err != nil {
|
||||
seed.checkedAt, latestChapter, seed.latestNum, seed.siteCompletedAt); err != nil {
|
||||
t.Fatalf("seed series %q: %v", seed.key, err)
|
||||
}
|
||||
for i := range seed.bookmarks {
|
||||
@@ -2343,6 +2379,46 @@ func TestSeriesListFinishedFilterOption(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The site-completed filter is in the select's vocabulary like any other,
|
||||
// and the list it opens shows exactly the hinted Series — the Site's marker
|
||||
// with no owner's Finish, because a retired Series is not work a Poll is
|
||||
// coming to do (issue #170).
|
||||
func TestSeriesListSiteCompletedFilterOption(t *testing.T) {
|
||||
st, dsn := newTestStoreURL(t)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("open %s: %v", dsn, err)
|
||||
}
|
||||
defer db.Close()
|
||||
hinted := time.Now().Add(-72 * time.Hour).UnixMilli()
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:hinted", url: "u", cover: "c", checkedAt: time.Now().UnixMilli(), latestNum: floatPtr(10), bookmarks: 1, siteCompletedAt: hinted})
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:plain", url: "u", cover: "c", checkedAt: time.Now().UnixMilli(), latestNum: floatPtr(1), bookmarks: 1})
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:retired", url: "u", cover: "c", checkedAt: time.Now().UnixMilli(), latestNum: floatPtr(2), bookmarks: 1, siteCompletedAt: hinted})
|
||||
if err := st.SetSeriesFinished("asura", "retired", time.Now().UnixMilli()); err != nil {
|
||||
t.Fatalf("finish asura:retired: %v", err)
|
||||
}
|
||||
srv := newRouter(st, testConfig())
|
||||
|
||||
body := adminSeriesPage(t, srv, st, "?filter=site_completed")
|
||||
if !strings.Contains(body, "Title of asura:hinted") {
|
||||
t.Errorf("site-completed list misses its row:\n%s", body)
|
||||
}
|
||||
for _, banned := range []string{"Title of asura:plain", "Title of asura:retired"} {
|
||||
if strings.Contains(body, banned) {
|
||||
t.Errorf("site-completed list renders %q:\n%s", banned, body)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(body, "1 series") {
|
||||
t.Errorf("site-completed heading lacks the count:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, `Site says completed (1)`) {
|
||||
t.Errorf("the site-completed option lacks its count:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, `<option value="site_completed" selected>`) {
|
||||
t.Errorf("the site-completed option is not selected:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
// ?filter=stale&site=kagane&kind=manga narrows on all three at once: only the
|
||||
// kagane manga stale row renders, and every link the page emits carries the
|
||||
// filter and Site so the narrowing survives in the URL.
|
||||
@@ -2619,6 +2695,44 @@ func TestSeriesListRowShape(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The row's fact line names the standing failure and how long it has stood,
|
||||
// through one format for every age: a one-hour-old failure and a
|
||||
// three-month-old one both render as "<word> · <checkedAge>", and a Series
|
||||
// with no failure row renders no marker at all. The marker is its own field,
|
||||
// never a Notes chip — the chips cap at two plus a tail, so the failure
|
||||
// would be the fact most likely to be truncated away (issue #167).
|
||||
func TestSeriesListFailureMarkerAges(t *testing.T) {
|
||||
st, dsn := newTestStoreURL(t)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("open %s: %v", dsn, err)
|
||||
}
|
||||
defer db.Close()
|
||||
now := time.Now()
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:hour", url: "u", cover: "c", checkedAt: now.UnixMilli(), latestNum: floatPtr(1), bookmarks: 1})
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:months", url: "u", cover: "c", checkedAt: now.UnixMilli(), latestNum: floatPtr(1), bookmarks: 1})
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:fine", url: "u", cover: "c", checkedAt: now.UnixMilli(), latestNum: floatPtr(1), bookmarks: 1})
|
||||
if err := st.RecordSeriesFailure("asura", "hour", "not_found", now.Add(-time.Hour).UnixMilli()); err != nil {
|
||||
t.Fatalf("seed failure row on hour: %v", err)
|
||||
}
|
||||
if err := st.RecordSeriesFailure("asura", "months", "no_chapter", now.Add(-90*24*time.Hour).UnixMilli()); err != nil {
|
||||
t.Fatalf("seed failure row on months: %v", err)
|
||||
}
|
||||
|
||||
body := adminSeriesPage(t, newRouter(st, testConfig()), st, "")
|
||||
if !strings.Contains(body, `<span class="mark">not found · 1h ago</span>`) {
|
||||
t.Errorf("the one-hour failure lacks its marker:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, `<span class="mark">no chapter · 90d ago</span>`) {
|
||||
t.Errorf("the three-month failure lacks its marker:\n%s", body)
|
||||
}
|
||||
// The clean row carries none, and neither word leaks anywhere else on
|
||||
// the page: exactly one marker per failing row.
|
||||
if strings.Count(body, "not found") != 1 || strings.Count(body, "no chapter") != 1 {
|
||||
t.Errorf("failure words appear more than once, or on a clean row:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
// The per-Series page renders every Series-level fact the admin read model
|
||||
// holds for the key the list row already shows: title, the composite key with
|
||||
// Site and kind, the Latest Chapter, the check age and the anonymous Reader
|
||||
@@ -2758,6 +2872,57 @@ func TestAdminSeriesDetailRendersMarks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The detail page adds one sentence beside the Latest Chapter correction
|
||||
// control only while the number came from a Reader and the failure row has
|
||||
// stood past the owner window: a Reader-attributed failing Series carries it,
|
||||
// a machine-read failing Series does not, and neither does a
|
||||
// Reader-attributed Series whose failure is still inside the window. The
|
||||
// sentence names no Reader (issue #167).
|
||||
func TestAdminSeriesDetailUnverifiedSentence(t *testing.T) {
|
||||
st, dsn := newTestStoreURL(t)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("open %s: %v", dsn, err)
|
||||
}
|
||||
defer db.Close()
|
||||
now := time.Now()
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:reader-fail", url: "u", cover: "c", checkedAt: now.UnixMilli(), latestNum: floatPtr(2), bookmarks: 1, raisedBy: true})
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:machine-fail", url: "u", cover: "c", checkedAt: now.UnixMilli(), latestNum: floatPtr(1), bookmarks: 1})
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:reader-recent", url: "u", cover: "c", checkedAt: now.UnixMilli(), latestNum: floatPtr(3), bookmarks: 1, raisedBy: true})
|
||||
if err := st.RecordSeriesFailure("asura", "reader-fail", "not_found", now.Add(-24*time.Hour).UnixMilli()); err != nil {
|
||||
t.Fatalf("seed failure row on reader-fail: %v", err)
|
||||
}
|
||||
if err := st.RecordSeriesFailure("asura", "machine-fail", "not_found", now.Add(-24*time.Hour).UnixMilli()); err != nil {
|
||||
t.Fatalf("seed failure row on machine-fail: %v", err)
|
||||
}
|
||||
if err := st.RecordSeriesFailure("asura", "reader-recent", "not_found", now.Add(-time.Hour).UnixMilli()); err != nil {
|
||||
t.Fatalf("seed failure row on reader-recent: %v", err)
|
||||
}
|
||||
srv := newRouter(st, testConfig())
|
||||
|
||||
want := "Unverified Reader number: the page has been failing for over 12h, so this Reader-reported chapter is unconfirmed."
|
||||
fetch := func(key string) string {
|
||||
t.Helper()
|
||||
req := httptest.NewRequest(http.MethodGet, "/admin/series/"+key, nil)
|
||||
req.AddCookie(sessionCookie(t, st))
|
||||
rr := httptest.NewRecorder()
|
||||
srv.ServeHTTP(rr, req)
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Fatalf("GET /admin/series/%s status = %d, want 200", key, rr.Code)
|
||||
}
|
||||
return rr.Body.String()
|
||||
}
|
||||
if body := fetch("asura:reader-fail"); !strings.Contains(body, want) {
|
||||
t.Errorf("a Reader-attributed failing Series lacks the unverified sentence:\n%s", body)
|
||||
}
|
||||
if body := fetch("asura:machine-fail"); strings.Contains(body, want) {
|
||||
t.Errorf("a machine-read failing Series carries the unverified sentence:\n%s", body)
|
||||
}
|
||||
if body := fetch("asura:reader-recent"); strings.Contains(body, want) {
|
||||
t.Errorf("a Reader-attributed Series failing inside the window carries the sentence:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
// The provenance line beside the chapter names the actor class behind the
|
||||
// value — "machine read" for a checked Series, "correction" for the owner's
|
||||
// stamp, "sighting" for a Reader-raised one — and appears nowhere in the
|
||||
@@ -2934,7 +3099,7 @@ func TestOverviewVerdictThreeStates(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("lanes need a look", func(t *testing.T) {
|
||||
seedPass(t, st, store.LanePass{Site: "demonic", RanAt: now.UnixMilli(), Skip: latest.SkipRefusing})
|
||||
seedPass(t, st, store.LanePass{Site: "demonic", RanAt: now.UnixMilli(), Due: 1, Checked: 0, Skip: "", Refused: 0})
|
||||
body := overviewBody(t, router, st)
|
||||
if !strings.Contains(body, "1 lane needs a look") {
|
||||
t.Errorf("attention verdict missing:\n%s", body)
|
||||
@@ -2953,6 +3118,96 @@ func TestOverviewVerdictThreeStates(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// TestOverviewVerdictFromFaults mirrors the four fault inputs the notifier judges
|
||||
// (stall, no-browser-route, sidecar-down, adapter-broken); plus healthy and
|
||||
// virgin. Each seeds the durable rows the page reads, with no poller running.
|
||||
func TestOverviewVerdictFromFaults(t *testing.T) {
|
||||
t.Run("stall is a fault", func(t *testing.T) {
|
||||
router, st := newWebTestServer(t, testConfig())
|
||||
now := time.Now()
|
||||
seedPass(t, st, store.LanePass{Site: "asura", RanAt: now.UnixMilli(), Due: 3, Checked: 0, Skip: "", Refused: 0})
|
||||
body := overviewBody(t, router, st)
|
||||
if !strings.Contains(body, "1 lane needs a look") {
|
||||
t.Errorf("stall fault verdict missing:\n%s", body)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("no-browser-route is a fault on plain TLS site", func(t *testing.T) {
|
||||
router, st := newWebTestServer(t, testConfig())
|
||||
old := time.Now().Add(-13 * time.Hour).UnixMilli()
|
||||
seedPass(t, st, store.LanePass{Site: "asura", RanAt: old, Skip: latest.SkipRefusing})
|
||||
body := overviewBody(t, router, st)
|
||||
if !strings.Contains(body, "1 lane needs a look") {
|
||||
t.Errorf("no-browser-route fault verdict missing:\n%s", body)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("sidecar-down is one fault even though every browser lane is down", func(t *testing.T) {
|
||||
router, st := newWebTestServer(t, testConfig())
|
||||
now := time.Now().UnixMilli()
|
||||
for _, site := range []string{"comix", "kagane", "novelfull"} {
|
||||
seedPass(t, st, store.LanePass{Site: site, RanAt: now, Skip: latest.SkipSidecarDown})
|
||||
}
|
||||
body := overviewBody(t, router, st)
|
||||
if !strings.Contains(body, "1 lane needs a look") {
|
||||
t.Errorf("sidecar-down fault should count as one, want %q:\n%s", "1 lane needs a look", body)
|
||||
}
|
||||
if strings.Contains(body, "3 lanes need a look") {
|
||||
t.Errorf("sidecar-down fault must not count lanes, got 3:\n%s", body)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("adapter-broken is a fault over half no_chapter", func(t *testing.T) {
|
||||
st, dsn := newTestStoreURL(t)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("open %s: %v", dsn, err)
|
||||
}
|
||||
defer db.Close()
|
||||
router := newRouter(st, testConfig())
|
||||
// Four series of the same site; three hold an old no_chapter row (>12h).
|
||||
now := time.Now()
|
||||
old := now.Add(-13 * time.Hour).UnixMilli()
|
||||
for i := 1; i <= 4; i++ {
|
||||
key := fmt.Sprintf("asura:a%d", i)
|
||||
url := fmt.Sprintf("https://asurascans.com/comics/a%d", i)
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: key, url: url, cover: "aaa", checkedAt: now.UnixMilli(), latestNum: floatPtr(1), bookmarks: 1})
|
||||
}
|
||||
for i := 1; i <= 3; i++ {
|
||||
if err := st.RecordSeriesFailure("asura", fmt.Sprintf("a%d", i), "no_chapter", old); err != nil {
|
||||
t.Fatalf("seed no_chapter failure: %v", err)
|
||||
}
|
||||
}
|
||||
seedPass(t, st, store.LanePass{Site: "asura", RanAt: now.UnixMilli(), Due: 1, Checked: 1})
|
||||
body := overviewBody(t, router, st)
|
||||
if !strings.Contains(body, "1 lane needs a look") {
|
||||
t.Errorf("adapter-broken fault verdict missing:\n%s", body)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("healthy when no fault holds", func(t *testing.T) {
|
||||
router, st := newWebTestServer(t, testConfig())
|
||||
now := time.Now()
|
||||
seedPass(t, st, store.LanePass{Site: "asura", RanAt: now.UnixMilli(), Due: 1, Checked: 1})
|
||||
seedPass(t, st, store.LanePass{Site: "kagane", RanAt: now.UnixMilli(), Skip: latest.SkipAsleep, Due: 1})
|
||||
body := overviewBody(t, router, st)
|
||||
if !strings.Contains(body, "all lanes healthy") {
|
||||
t.Errorf("healthy verdict missing:\n%s", body)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("virgin still draws no figures", func(t *testing.T) {
|
||||
virgin, fresh := newWebTestServer(t, testConfig())
|
||||
body := overviewBody(t, virgin, fresh)
|
||||
if !strings.Contains(body, "no Lane has reported yet") {
|
||||
t.Errorf("virgin verdict missing:\n%s", body)
|
||||
}
|
||||
if strings.Contains(body, "all lanes healthy") || strings.Contains(body, "series waiting") {
|
||||
t.Errorf("virgin verdict draws confident zeroes:\n%s", body)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// The Overview never refreshes itself: the Lane rest is an hour, so a timer
|
||||
// would re-run a cross-Series join to redraw identical rows. Only the Lanes
|
||||
// block carries a refresh attribute.
|
||||
@@ -3027,10 +3282,11 @@ func TestOverviewZeroIsAnUnlinkedDigit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The finished figure rides last in the Hygiene block: seriesFilterOrder
|
||||
// appends it at the tail, the block renders order[1:], and the count comes
|
||||
// from the same aggregate the select is numbered from. Asserting on the body
|
||||
// order catches a render that merely shows the figure somewhere.
|
||||
// The finished figure and the site-completed hint ride last in the Hygiene
|
||||
// block: seriesFilterOrder appends the pair at the tail, the block renders
|
||||
// order[1:], and each count comes from the same aggregate the select is
|
||||
// numbered from. Asserting on the body order catches a render that merely
|
||||
// shows a figure somewhere.
|
||||
func TestOverviewFinishedFigureRidesLast(t *testing.T) {
|
||||
st, dsn := newTestStoreURL(t)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
@@ -3055,17 +3311,69 @@ func TestOverviewFinishedFigureRidesLast(t *testing.T) {
|
||||
}
|
||||
labels = append(labels, m[1])
|
||||
}
|
||||
if len(labels) != 8 {
|
||||
t.Fatalf("hygiene block renders %d figures, want 8 (seven problems + finished):\n%s", len(labels), body)
|
||||
if len(labels) != 11 {
|
||||
t.Fatalf("hygiene block renders %d figures, want 11 (nine problems + finished + site completed):\n%s", len(labels), body)
|
||||
}
|
||||
if labels[len(labels)-1] != "Finished" {
|
||||
t.Errorf("finished figure does not ride last; hygiene order = %v:\n%s", labels, body)
|
||||
if labels[len(labels)-2] != "Finished" || labels[len(labels)-1] != "Site says completed" {
|
||||
t.Errorf("the informational tail does not ride last; hygiene order = %v:\n%s", labels, body)
|
||||
}
|
||||
if !strings.Contains(body, `href="/admin/series?filter=finished">1</a>`) {
|
||||
t.Errorf("the finished figure lacks its count and door:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
// The site-completed figure is a door into the list that counts it, and the
|
||||
// figure agrees with the list's own heading: both come from the same
|
||||
// aggregate, so they cannot drift apart.
|
||||
func TestOverviewSiteCompletedFigureAgreesWithListHeading(t *testing.T) {
|
||||
st, dsn := newTestStoreURL(t)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("open %s: %v", dsn, err)
|
||||
}
|
||||
defer db.Close()
|
||||
hinted := time.Now().Add(-72 * time.Hour).UnixMilli()
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:hinted", url: "https://asurascans.com/comics/hinted", cover: "aaa", checkedAt: time.Now().UnixMilli(), latestNum: floatPtr(10), bookmarks: 1, siteCompletedAt: hinted})
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:plain", url: "https://asurascans.com/comics/plain", cover: "bbb", checkedAt: time.Now().UnixMilli(), latestNum: floatPtr(1), bookmarks: 1})
|
||||
srv := newRouter(st, testConfig())
|
||||
body := overviewBody(t, srv, st)
|
||||
|
||||
fig := regexp.MustCompile(`href="/admin/series\?filter=site_completed">(\d+)</a>`).FindStringSubmatch(body)
|
||||
if fig == nil {
|
||||
t.Fatalf("overview has no site-completed figure:\n%s", body)
|
||||
}
|
||||
list := adminSeriesPage(t, srv, st, "?filter=site_completed")
|
||||
heading := regexp.MustCompile(`(\d+) series <span`).FindStringSubmatch(list)
|
||||
if heading == nil {
|
||||
t.Fatalf("site-completed list has no heading count:\n%s", list)
|
||||
}
|
||||
if fig[1] != heading[1] {
|
||||
t.Errorf("the overview says %s, the list it links to says %s", fig[1], heading[1])
|
||||
}
|
||||
}
|
||||
|
||||
// A measured zero site-completed count stays on the page as a muted digit,
|
||||
// never a link: following it would land on an empty list, exactly like every
|
||||
// other zero figure.
|
||||
func TestOverviewSiteCompletedZeroIsAnUnlinkedDigit(t *testing.T) {
|
||||
st, dsn := newTestStoreURL(t)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("open %s: %v", dsn, err)
|
||||
}
|
||||
defer db.Close()
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:one", url: "https://asurascans.com/comics/one", cover: "aaa", checkedAt: time.Now().UnixMilli(), latestNum: floatPtr(1), bookmarks: 1})
|
||||
srv := newRouter(st, testConfig())
|
||||
body := overviewBody(t, srv, st)
|
||||
|
||||
if !strings.Contains(body, `Site says completed</span><span class="fig zero">0</span>`) {
|
||||
t.Errorf("a zero site-completed figure does not render as a muted digit:\n%s", body)
|
||||
}
|
||||
if strings.Contains(body, `href="/admin/series?filter=site_completed"`) {
|
||||
t.Errorf("a zero site-completed figure is still a link:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
// A measured zero finished count stays on the page as a muted digit, never a
|
||||
// link: following it would land on an empty list, exactly like every other
|
||||
// zero figure.
|
||||
@@ -3574,6 +3882,94 @@ func TestAdminSeriesDetailFinishControl(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The hint line rides the Finish control: present for a Series the Site
|
||||
// marked completed, with its age, absent while the Site has said nothing
|
||||
// (zero stamp) and gone once the owner finishes — the Site's stamp keeps
|
||||
// standing after retirement, so the hint is suppressed by the same
|
||||
// finished_at guard the clock-driven filters carry (issue #170).
|
||||
func TestAdminSeriesDetailSiteCompletedHint(t *testing.T) {
|
||||
st, dsn := newTestStoreURL(t)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("open %s: %v", dsn, err)
|
||||
}
|
||||
defer db.Close()
|
||||
hinted := time.Now().Add(-72 * time.Hour).UnixMilli()
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:hinted", url: "u", cover: "c", checkedAt: time.Now().UnixMilli(), latestNum: floatPtr(1), bookmarks: 1, siteCompletedAt: hinted})
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:plain", url: "u", cover: "c", checkedAt: time.Now().UnixMilli(), latestNum: floatPtr(1), bookmarks: 1})
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:retired", url: "u", cover: "c", checkedAt: time.Now().UnixMilli(), latestNum: floatPtr(1), bookmarks: 1, siteCompletedAt: hinted})
|
||||
if err := st.SetSeriesFinished("asura", "retired", time.Now().UnixMilli()); err != nil {
|
||||
t.Fatalf("finish asura:retired: %v", err)
|
||||
}
|
||||
srv := newRouter(st, testConfig())
|
||||
|
||||
body := seriesDetailPage(t, srv, st, "asura:hinted")
|
||||
if !strings.Contains(body, "the site says this work is completed (since 3d ago)") {
|
||||
t.Errorf("hinted Series lacks the hint with its age:\n%s", body)
|
||||
}
|
||||
// The hint sits between the Finish opener and the confirm row — a line
|
||||
// beside the control, not the control itself.
|
||||
opener := strings.Index(body, "document.getElementById('confirm-finish').hidden = false")
|
||||
hintAt := strings.Index(body, "the site says this work is completed")
|
||||
confirmAt := strings.Index(body, `id="confirm-finish"`)
|
||||
if opener < 0 || hintAt < 0 || confirmAt < 0 || hintAt < opener || confirmAt < hintAt {
|
||||
t.Errorf("the hint is not a line beside the Finish control (opener %d, hint %d, row %d):\n%s", opener, hintAt, confirmAt, body)
|
||||
}
|
||||
if strings.Contains(seriesDetailPage(t, srv, st, "asura:plain"), "the site says this work is completed") {
|
||||
t.Errorf("an unmarked Series renders the hint:\n%s", body)
|
||||
}
|
||||
if strings.Contains(seriesDetailPage(t, srv, st, "asura:retired"), "the site says this work is completed") {
|
||||
t.Errorf("a finished Series renders the hint:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
// The hint is a line of text, never a control: with and without a hint, the
|
||||
// Finish control's markup is byte-identical (AC4). Two stores seed the same
|
||||
// key so the hx-post URLs match byte for byte; only the hint line differs,
|
||||
// and it sits outside the confirm row.
|
||||
func TestAdminSeriesDetailFinishControlUnchangedWithHint(t *testing.T) {
|
||||
hinted := time.Now().Add(-72 * time.Hour).UnixMilli()
|
||||
var bodies [2]string
|
||||
for i, sc := range []int64{hinted, 0} {
|
||||
st, dsn := newTestStoreURL(t)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("open %s: %v", dsn, err)
|
||||
}
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:solo", url: "u", cover: "c", checkedAt: time.Now().UnixMilli(), latestNum: floatPtr(1), bookmarks: 1, siteCompletedAt: sc})
|
||||
db.Close()
|
||||
srv := newRouter(st, testConfig())
|
||||
bodies[i] = seriesDetailPage(t, srv, st, "asura:solo")
|
||||
}
|
||||
withHint, without := bodies[0], bodies[1]
|
||||
if !strings.Contains(withHint, "the site says this work is completed") {
|
||||
t.Fatalf("the hinted store did not render a hint:\n%s", withHint)
|
||||
}
|
||||
if strings.Contains(without, "the site says this work is completed") {
|
||||
t.Fatalf("the plain store rendered a hint:\n%s", without)
|
||||
}
|
||||
if got, want := confirmRowMarkup(t, withHint), confirmRowMarkup(t, without); got != want {
|
||||
t.Errorf("the Finish control's markup changed with a hint present:\nwith hint: %s\nwithout: %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// confirmRowMarkup returns the confirm-finish row's HTML, byte for byte —
|
||||
// the Finish control AC4 says must not change with a hint present. The row
|
||||
// is the outer div (the span plus the inner button pair), with no nested
|
||||
// divs beyond that, so the first two </div> closes end it.
|
||||
func confirmRowMarkup(t *testing.T, body string) string {
|
||||
t.Helper()
|
||||
start := strings.Index(body, `<div class="confirm-row calm" id="confirm-finish"`)
|
||||
if start < 0 {
|
||||
t.Fatalf("no confirm-finish row in:\n%s", body)
|
||||
}
|
||||
open := strings.Index(body[start:], ">") + start + 1
|
||||
inner := strings.Index(body[open:], "</div>")
|
||||
outer := strings.Index(body[open+inner+len("</div>"):], "</div>")
|
||||
end := open + inner + len("</div>") + outer + len("</div>")
|
||||
return body[start:end]
|
||||
}
|
||||
|
||||
// The finish route is the owner's one writer: a finish press stamps
|
||||
// finished_at and answers with the swapped detail-meta fragment carrying the
|
||||
// "finished <age> ago" mark, and an un-finish press writes zero and answers
|
||||
@@ -4035,3 +4431,49 @@ func TestRemoveRejectsBadKeysAndCapsBody(t *testing.T) {
|
||||
t.Errorf("an oversized body still removed the row:\n%s", list)
|
||||
}
|
||||
}
|
||||
|
||||
// The failing pair render in the stats block from the same aggregate the
|
||||
// select is numbered from: failing over 12h counts every Series with a
|
||||
// failure row older than the cutoff, unverified the Reader-attributed
|
||||
// subset, and a measured zero stays a muted digit — never a door.
|
||||
func TestOverviewFailingAndUnverifiedFigures(t *testing.T) {
|
||||
st, dsn := newTestStoreURL(t)
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("open %s: %v", dsn, err)
|
||||
}
|
||||
defer db.Close()
|
||||
now := time.Now().UnixMilli()
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:broken", url: "u", cover: "c", checkedAt: now, latestNum: floatPtr(1), bookmarks: 1})
|
||||
seedSeriesRow(t, st, db, seriesRowSeed{key: "asura:reader", url: "u", cover: "c", checkedAt: now, latestNum: floatPtr(2), bookmarks: 1, raisedBy: true})
|
||||
if err := st.RecordSeriesFailure("asura", "broken", "not_found", now-24*3600*1000); err != nil {
|
||||
t.Fatalf("seed failure row on broken: %v", err)
|
||||
}
|
||||
if err := st.RecordSeriesFailure("asura", "reader", "not_found", now-24*3600*1000); err != nil {
|
||||
t.Fatalf("seed failure row on reader: %v", err)
|
||||
}
|
||||
srv := newRouter(st, testConfig())
|
||||
body := overviewBody(t, srv, st)
|
||||
|
||||
if !strings.Contains(body, `href="/admin/series?filter=failing">2</a>`) {
|
||||
t.Errorf("the failing figure lacks its count and door:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, `href="/admin/series?filter=unverified">1</a>`) {
|
||||
t.Errorf("the unverified figure lacks its count and door:\n%s", body)
|
||||
}
|
||||
|
||||
empty, emptySt := newWebTestServer(t, testConfig())
|
||||
body = overviewBody(t, empty, emptySt)
|
||||
if !strings.Contains(body, `Failing over 12h</span><span class="fig zero">0</span>`) {
|
||||
t.Errorf("a zero failing figure does not render as a muted digit:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, `Unverified Reader number</span><span class="fig zero">0</span>`) {
|
||||
t.Errorf("a zero unverified figure does not render as a muted digit:\n%s", body)
|
||||
}
|
||||
if strings.Contains(body, `href="/admin/series?filter=failing"`) {
|
||||
t.Errorf("a zero failing figure is still a link:\n%s", body)
|
||||
}
|
||||
if strings.Contains(body, `href="/admin/series?filter=unverified"`) {
|
||||
t.Errorf("a zero unverified figure is still a link:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user