Replace ntfy.state_dir with a top-level [state] dir
Security / Vulnerability check (push) Successful in 45s
Test / Lint and test (push) Successful in 2m1s

The job store is to keep its database in the directory that holds the
ntfy subscriptions' state files, so the directory moves to a section
of its own: [state] dir, or UBERBRINGER_STATE_DIR, in place of
[ntfy] state_dir. For now only the subscriptions use it. It still has
no default and is still required with a subscription, and the checks
at start name state.dir in their errors.

install.sh writes [state] dir into new configs, and the Docker image
sets UBERBRINGER_STATE_DIR. ntfy.state_dir has never been in a
release, so its CHANGELOG entry changes in place and there is no
fallback: a config that still sets it fails to load with an unknown
key until the line moves to [state].

The image itself was not built, since the workstation has no Docker.

Part of stage 1b of docs/plans/job-store.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-12-01 12:21:29 -06:00
1 parent f0b5bf020e
commit 66531e7314
16 files changed
+92 -68

No files matched your search

+17 -11
View File
@@ -11,8 +11,9 @@ import (
"uberbringer/internal/pkg/config"
)
// base is a config with the required settings and a state directory.
const base = "[api]\nsecret = \"" + validSecret + "\"\n[printer]\naddress = \"p\"\n[ntfy]\nstate_dir = \"state\"\n"
// base is a config with the required settings and a state directory, which
// ends in the [ntfy] table, so that keys appended to it set ntfy keys.
const base = "[api]\nsecret = \"" + validSecret + "\"\n[printer]\naddress = \"p\"\n[state]\ndir = \"state\"\n[ntfy]\n"
func TestLoadSubscriptions(t *testing.T) {
cfg, err := config.Load(writeConfig(t, base+`
@@ -53,6 +54,9 @@ topics = ["long-random-topic-name"]
if err != nil {
t.Fatal(err)
}
if cfg.State.Dir != "state" {
t.Errorf("state.dir = %q, want state", cfg.State.Dir)
}
subs := cfg.Ntfy.Subscriptions
if len(subs) != 3 {
t.Fatalf("%d subscriptions, want 3", len(subs))
@@ -98,8 +102,8 @@ func TestSubscriptionDefaults(t *testing.T) {
if q.Start != "22:00" || q.End != "07:00" || len(q.Days) != 7 || q.Timezone != "" || q.MinPriority != 5 || q.Action != "digest" {
t.Errorf("quiet defaults %+v", q)
}
if cfg := config.Default(); cfg.Ntfy.StateDir != "" || cfg.Ntfy.Subscriptions != nil || cfg.Ntfy.Format.Updates != "print" {
t.Errorf("ntfy defaults %+v", cfg.Ntfy)
if cfg := config.Default(); cfg.State.Dir != "" || cfg.Ntfy.Subscriptions != nil || cfg.Ntfy.Format.Updates != "print" {
t.Errorf("state defaults %+v, ntfy defaults %+v", cfg.State, cfg.Ntfy)
}
}
@@ -151,7 +155,9 @@ func TestLoadSubscriptionErrors(t *testing.T) {
tests := []struct {
name, body, wantErr string
}{
{"no state dir", strings.Replace(base, "state_dir = \"state\"", "", 1) + sub, "ntfy.state_dir is required"},
{"no state dir", strings.Replace(base, "dir = \"state\"", "", 1) + sub, "state.dir is required"},
{"blank state dir", strings.Replace(base, "dir = \"state\"", "dir = \" \"", 1) + sub, "state.dir is required"},
{"state dir under ntfy", "state_dir = \"state\"\n", "unknown keys: ntfy.state_dir"},
{"unknown key", sub + "topic = \"x\"\n", "unknown keys: ntfy.subscriptions[0].topic"},
{"unknown quiet key", quiet + "begin = \"22:00\"\n", "unknown keys: ntfy.subscriptions[0].quiet.begin"},
{"keys that differ in case", sub + "Name = \"x\"\n", "keys that differ only in case: ntfy.subscriptions[0].Name and ntfy.subscriptions[0].name"},
@@ -226,7 +232,7 @@ func TestLoadSubscriptionErrorHidesSecrets(t *testing.T) {
func TestLoadSubscriptionsHaveNoVariable(t *testing.T) {
t.Setenv("UBERBRINGER_API_SECRET", validSecret)
t.Setenv("UBERBRINGER_PRINTER_ADDRESS", "p")
t.Setenv("UBERBRINGER_NTFY_STATE_DIR", "/var/lib/uberbringer")
t.Setenv("UBERBRINGER_STATE_DIR", "/var/lib/uberbringer")
t.Setenv("UBERBRINGER_NTFY_SUBSCRIPTIONS", "home")
t.Setenv("UBERBRINGER_NTFY_SUBSCRIPTIONS_NAME", "home")
t.Setenv("UBERBRINGER_LOG_LEVEL", "loud")
@@ -243,17 +249,17 @@ func TestLoadSubscriptionsHaveNoVariable(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if cfg.Ntfy.StateDir != "/var/lib/uberbringer" || len(cfg.Ntfy.Subscriptions) != 0 {
t.Errorf("ntfy = %+v", cfg.Ntfy)
if cfg.State.Dir != "/var/lib/uberbringer" || len(cfg.Ntfy.Subscriptions) != 0 {
t.Errorf("state = %+v, ntfy = %+v", cfg.State, cfg.Ntfy)
}
}
func TestValueOfSubscriptions(t *testing.T) {
cfg := config.Default()
cfg.Ntfy.StateDir = "/var/lib/uberbringer"
cfg.State.Dir = "/var/lib/uberbringer"
cfg.Ntfy.Subscriptions = []config.NtfySubscription{{Name: "home", Token: "tk_secret"}}
if got, err := cfg.Value("ntfy.state_dir"); err != nil || got != "/var/lib/uberbringer" {
t.Errorf("state_dir = %q, %v", got, err)
if got, err := cfg.Value("state.dir"); err != nil || got != "/var/lib/uberbringer" {
t.Errorf("state.dir = %q, %v", got, err)
}
if got, err := cfg.Value("ntfy.format.updates"); err != nil || got != "print" {
t.Errorf("updates = %q, %v", got, err)