diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index 588c95beb..f814669f3 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -529,10 +529,12 @@ const bindingDispatchBatchLimit = 100 // pair, and dispatchOneBinding treats that as a normal "another cycle // raced us" outcome rather than an error. // -// Nil Bindings disables the loop (legacy behaviour: daemons built -// before t2db.4 Phase E had no playbook bindings). +// Nil Bindings, BindingDispatcher or BindingTaskCreator disables the +// loop (legacy behaviour: daemons built before t2db.4 Phase E had no +// playbook bindings, and each field's own doc comment promises this +// degrade-not-panic contract independently). func (d *Daemon) dispatchBindings(ctx context.Context) { - if d.Bindings == nil { + if d.Bindings == nil || d.BindingDispatcher == nil || d.BindingTaskCreator == nil { return } diff --git a/internal/daemon/dispatch_bindings_test.go b/internal/daemon/dispatch_bindings_test.go index 32994f344..e55951eaa 100644 --- a/internal/daemon/dispatch_bindings_test.go +++ b/internal/daemon/dispatch_bindings_test.go @@ -216,6 +216,30 @@ func TestDispatchBindingsNilBindingsIsNoOp(t *testing.T) { d.dispatchBindings(t.Context()) } +// TestDispatchBindingsNilDispatcherIsNoOp exercises the composition +// gap the daemon field comments claim is safe: Bindings is set (so an +// armed binding + a matching capture exist) but BindingDispatcher is +// nil. Both fields are documented "optional: nil disables the +// dispatch loop", so this must degrade silently rather than panic on +// the nil-interface call to ListUndispatchedCaptures. +func TestDispatchBindingsNilDispatcherIsNoOp(t *testing.T) { + s := openDispatchTestStore(t) + mappingID := seedMapping(t, s, "sentry", mapping.Field{Name: "title", Path: "title", Type: mapping.TypeString}) + seedArmedBinding(t, s, "sentry", mappingID) + seedCapture(t, s, "sentry", true, `{"title":"hello"}`) + + d := &Daemon{ + Cfg: config.NewHolder(config.Config{Repos: []config.Repo{{Owner: "acme", Name: "widget"}}}), + Store: s, + Mappings: s, + Bindings: s, + // BindingDispatcher and BindingTaskCreator intentionally nil. + Log: slog.New(slog.NewTextHandler(os.Stderr, nil)), + } + // Should not panic. + d.dispatchBindings(t.Context()) +} + // ── helpers ────────────────────────────────────────────────────── // openDispatchTestStore creates a fresh in-memory SQLite store for