A multi-session build turning Pete's read-only web UI into something people return to. Five phases, signed-in features keyed off the OIDC subject; anonymous visitors keep the reverse-chron feed and localStorage-only state. Phase 1 — per-user read + bookmark state: user_story_state table + storage/userstate.go; auth-gated /api/read, /api/bookmark, /api/state and a /bookmarks page; reader.js syncs state server-side for signed-in users. Also hides the Matrix-posting UI when posting.enabled=false (web-only mode). Phase 2 — outbound feeds: storage.ListForFeed + web/feed.go hand-build RSS 2.0 (content:encoded) and JSON Feed 1.1 (no new dep); /feed.xml, /feed.json and per-channel variants; <link rel=alternate> discovery tags. Phase 3 — "For you" + related: storage/rank.go scores recent unread candidates by channel/source affinity + recency decay; RelatedStories via FTS5. ForYou rail + /for-you page; public /api/related feeds the reader's "You might also like". Phase 4 — source-health dashboard: source_health table + storage/sourcehealth.go (RecordPollResult, ListSourceHealth, SourceContentStats), written by the poller; admin-gated /status page behind web.admin_subs. Phase 5 — PWA + offline reader + Web Push: root-scoped manifest.webmanifest and sw.js (app-shell precache, /api/article runtime cache for offline reading, offline fallback, push/notificationclick handlers); PNG icons from pete.avif; pwa.js registers the SW and drives a notifications toggle. Web Push adds webpush-go, a [web.push] config block (pete -genvapid mints VAPID keys), a push_subscriptions table, auth-gated subscribe/unsubscribe endpoints, and a digest sender that pings each subscriber "N new stories" past their watermark, honoring disabled-sources and pruning gone endpoints. Tests added beside each new storage/web file; go test ./... and go vet clean.
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package web
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"pete/internal/config"
|
|
)
|
|
|
|
func TestStatusTemplateExecutes(t *testing.T) {
|
|
s, err := New(config.WebConfig{SiteTitle: "Pete", ListenAddr: ":0"}, nil, true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
data := statusPage{
|
|
pageData: pageData{SiteTitle: "Pete", Channels: channels},
|
|
DegradedCnt: 1,
|
|
Sources: []sourceStatus{
|
|
{Name: "Broken Feed", Channel: "tech", Failures: 3, LastError: "dial tcp: timeout",
|
|
LastPollAt: time.Now(), NeverRun: false, Healthy: false, Total: 4, Paywalled: 2, PaywallRate: 50},
|
|
{Name: "Good Feed", Channel: "eu", Healthy: true, LastPollAt: time.Now(),
|
|
LastSuccessAt: time.Now(), LastItemCount: 12, Total: 30, Classified: 28,
|
|
LastSeenAt: time.Now(), LastPostedAt: time.Now()},
|
|
{Name: "Idle Feed", Channel: "music", NeverRun: true},
|
|
},
|
|
}
|
|
var b strings.Builder
|
|
if err := s.tpls["status"].ExecuteTemplate(&b, "layout", data); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out := b.String()
|
|
for _, want := range []string{"Broken Feed", "Good Feed", "dial tcp: timeout", "1 degraded", "Source health"} {
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("rendered status page missing %q", want)
|
|
}
|
|
}
|
|
}
|