Owner notices: the stall, one webhook path from env to Discord (#171)

Rollout note: the owner_notices table starts empty, so the first pass after deploy sends for conditions already true — correct per one-row-per-episode; say so rather than have it reported as a bug. Prod step: create the webhook, set DISCORD_WEBHOOK_URL on the deployment, redeploy — unset is silent by design, and without that step the feature ships dark. Security invariants preserved: the webhook address is a secret in the class of TOKEN_KEY (never logged, never on a config-printing line), and the owner gate is unchanged.
This commit is contained in:
2026-08-23 00:06:39 +07:00
parent 5a32943528
commit 7b22460f5e
13 changed files with 785 additions and 18 deletions
+20 -5
View File
@@ -21,10 +21,17 @@ func TestLoadLatestPollDefaults(t *testing.T) {
}
}
func TestLoadConfigReadsCoverDirectory(t *testing.T) {
t.Setenv("COVER_DIR", "/covers")
if got := loadConfig().CoverDir; got != "/covers" {
t.Fatalf("CoverDir = %q, want /covers", got)
func TestLoadConfigReadsDiscordWebhook(t *testing.T) {
// The address is read, never defaulted: unset stays empty (the whole
// path is off), set flows into the Config for the poller's notifier.
const url = "https://discord.com/api/webhooks/000000/secret"
t.Setenv("DISCORD_WEBHOOK_URL", url)
if got := loadConfig().DiscordWebhookURL; got != url {
t.Fatalf("DiscordWebhookURL = %q, want %q", got, url)
}
t.Setenv("DISCORD_WEBHOOK_URL", "")
if got := loadConfig().DiscordWebhookURL; got != "" {
t.Fatalf("DiscordWebhookURL = %q, want empty when unset", got)
}
}
@@ -51,7 +58,8 @@ func TestLoadLatestPollEnabledParsing(t *testing.T) {
// nothing here sizes a cooldown any more.
func TestNewLatestPollerWiresFetchers(t *testing.T) {
tls := &latest.TLSFetcher{}
p := newLatestPoller(nil, LatestPoll{Enabled: true}, tls, nil)
notifier := &stubNotifier{}
p := newLatestPoller(nil, LatestPoll{Enabled: true}, tls, nil, notifier)
if p.Fetch != tls {
t.Fatalf("Fetch not wired")
}
@@ -67,8 +75,15 @@ func TestNewLatestPollerWiresFetchers(t *testing.T) {
if p.Now == nil {
t.Fatalf("Now = nil, want the live clock")
}
if p.Notify != notifier {
t.Fatalf("Notify = %v, want the configured notifier", p.Notify)
}
}
// stubNotifier satisfies latest.Notifier so newLatestPoller's wiring can be
// asserted; it is never called.
type stubNotifier struct{ latest.Notifier }
func TestPutStatusValidation(t *testing.T) {
cases := []struct {
name string