Files
archie/internal/domain/binding/binding_test.go
T
sam ebd2b430dd fix(binding): add Owner/Repo pin, fixing multi-repo dispatch
Root-cause fix for the correctness gap named in archie-core-t2db.8:
resolveBindingRepo refused to dispatch with zero or multiple configured
repos, meaning a multi-repo deployment could never use bindings at all.

- binding.Binding gains optional Owner/Repo fields; Validate rejects
  setting only one (a pin is a complete pair or not a pin at all).
- Persisted as new owner/repo columns (NOT NULL DEFAULT '', additive --
  no migration needed since bindings is a CREATE TABLE IF NOT EXISTS
  with no existing deployment yet).
- resolveBindingRepo now takes the binding: a pinned binding dispatches
  to its own owner/repo unconditionally; an unpinned binding keeps
  today's single-configured-repo fallback (0 or 2+ repos still refuses,
  unchanged -- verified by a dedicated regression test, not just
  assumed preserved).
- Wired through the API request/response shape (create/update accept
  and return owner/repo); no repo-existence validation against config
  added -- smallest workable change, not the named bug.

Red-green throughout: 8 new tests across domain/store/daemon/webui
layers, each proven to fail before the corresponding implementation
step. Zero regressions in existing binding/dispatch test suites.
Dashboard UI to expose this (the other half of t2db.8) is unstarted --
this closes the backend correctness gap only.
2026-09-03 04:38:45 +10:00

59 lines
1.7 KiB
Go

package binding
import "testing"
func validBinding() Binding {
return Binding{
Name: "sentry alerts",
Matcher: Matcher{Source: "sentry"},
MappingID: 1,
Workflow: "implement",
Secret: "0123456789abcdef0123456789abcdef",
}
}
// TestValidateAcceptsNoRepoPin pins backward compatibility: a binding
// with neither Owner nor Repo set (today's only shape) must remain
// valid -- resolveBindingRepo's single-configured-repo fallback still
// applies to it.
func TestValidateAcceptsNoRepoPin(t *testing.T) {
b := validBinding()
if err := b.Validate(); err != nil {
t.Fatalf("Validate() = %v, want nil", err)
}
}
// TestValidateAcceptsBothOwnerAndRepo is the multi-repo fix: a binding
// naming a specific owner/repo must be accepted.
func TestValidateAcceptsBothOwnerAndRepo(t *testing.T) {
b := validBinding()
b.Owner, b.Repo = "acme", "widget"
if err := b.Validate(); err != nil {
t.Fatalf("Validate() = %v, want nil", err)
}
}
// TestValidateRejectsPartialRepoPin: Owner and Repo are a pair. A
// binding naming only one of them is ambiguous -- it isn't "no pin"
// (that's both empty) and it isn't a complete pin, so it must be
// rejected at validation time rather than silently guessing which
// half was meant.
func TestValidateRejectsPartialRepoPin(t *testing.T) {
tests := []struct {
name string
owner, repo string
}{
{"owner only", "acme", ""},
{"repo only", "", "widget"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b := validBinding()
b.Owner, b.Repo = tt.owner, tt.repo
if err := b.Validate(); err == nil {
t.Fatalf("Validate() = nil, want error for partial owner/repo pin (owner=%q repo=%q)", tt.owner, tt.repo)
}
})
}
}