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

+3 -3
View File
@@ -36,13 +36,13 @@ func newSubscribers(cfg *config.Config, logger *slog.Logger, syncState func(*os.
if len(subs) == 0 {
return nil, nil
}
dir := cfg.Ntfy.StateDir
dir := cfg.State.Dir
if err := os.MkdirAll(dir, 0o700); err != nil {
return nil, fmt.Errorf("config ntfy.state_dir: %w", err)
return nil, fmt.Errorf("config state.dir: %w", err)
}
probe, err := os.CreateTemp(dir, ".write-check-*")
if err != nil {
return nil, fmt.Errorf("config ntfy.state_dir: %s cannot be written: %w", dir, err)
return nil, fmt.Errorf("config state.dir: %s cannot be written: %w", dir, err)
}
_ = probe.Close()
_ = os.Remove(probe.Name())
+14 -12
View File
@@ -34,7 +34,7 @@ func skipSync(*os.File) error { return nil }
// TestServeWithSubscription runs the daemon with a subscription to a fake
// ntfy server: a message on the stream prints, /healthz lists the
// subscription as connected without changing its status code, and the
// state is saved at shutdown.
// state is saved in state.dir at shutdown.
func TestServeWithSubscription(t *testing.T) {
printer := startFakePrinter(t)
var auth sync.Map
@@ -67,8 +67,8 @@ address = "127.0.0.1"
port = %d
[log]
level = "error"
[ntfy]
state_dir = %q
[state]
dir = %q
[[ntfy.subscriptions]]
name = "home"
server = %q
@@ -138,28 +138,30 @@ token_file = %q
}
}
// The daemon refuses to start with a credentials file it cannot read, or
// one that is empty.
// The daemon refuses to start with a state directory it cannot create, or
// with a credentials file it cannot read or that is empty.
func TestNewSubscribersErrors(t *testing.T) {
dir := t.TempDir()
empty := filepath.Join(dir, "empty")
if err := os.WriteFile(empty, []byte(" \n"), 0o600); err != nil {
t.Fatal(err)
}
cfg := config.Default()
cfg.Ntfy.StateDir = filepath.Join(dir, "state")
state := filepath.Join(dir, "state")
sub := config.DefaultSubscription()
sub.Name, sub.Server, sub.Topics = "home", "https://ntfy.sh", []string{"alerts"}
for _, tt := range []struct {
file, want string
stateDir, tokenFile, want string
}{
{filepath.Join(dir, "missing"), "ntfy.subscriptions[0].token_file"},
{empty, "is empty"},
{empty, "", "config state.dir"},
{state, filepath.Join(dir, "missing"), "ntfy.subscriptions[0].token_file"},
{state, empty, "is empty"},
} {
sub.TokenFile = tt.file
cfg := config.Default()
cfg.State.Dir = tt.stateDir
sub.TokenFile = tt.tokenFile
cfg.Ntfy.Subscriptions = []config.NtfySubscription{sub}
if _, err := newSubscribers(&cfg, slog.New(slog.DiscardHandler), skipSync); err == nil || !strings.Contains(err.Error(), tt.want) {
t.Errorf("token_file %s: err = %v, want %q", tt.file, err, tt.want)
t.Errorf("state.dir %s, token_file %s: err = %v, want %q", tt.stateDir, tt.tokenFile, err, tt.want)
}
}
}