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.
This commit is contained in:
sam committed 2026-09-03 04:38:45 +10:00
1 parent 4a62df09f2
commit 7705fda777
8 files changed
+274 -29

No files matched your search

+56
View File
@@ -102,6 +102,62 @@ func TestHandleBindingCreateAndGet(t *testing.T) {
}
}
// TestHandleBindingCreateAndUpdateRoundTripsOwnerRepo covers the
// multi-repo fix at the API layer: a create/update request carrying
// owner/repo persists them, and they're visible in the response
// (they're not secret, unlike Secret).
func TestHandleBindingCreateAndUpdateRoundTripsOwnerRepo(t *testing.T) {
srv := bindingTestServer(t)
mappingID := seedMapping(t, srv, "m")
req := validBindingRequest("a", "sentry", mappingID)
req["owner"] = "acme"
req["repo"] = "widget"
w := doJSON(t, srv, http.MethodPost, "/api/bindings", req)
if w.Code != http.StatusCreated {
t.Fatalf("create status = %d, want %d; body = %s", w.Code, http.StatusCreated, w.Body.String())
}
var created binding.Binding
if err := json.Unmarshal(w.Body.Bytes(), &created); err != nil {
t.Fatalf("unmarshal created: %v", err)
}
if created.Owner != "acme" || created.Repo != "widget" {
t.Fatalf("created owner/repo = %q/%q, want acme/widget; body = %s", created.Owner, created.Repo, w.Body.String())
}
updateReq := validBindingRequest("a", "sentry", mappingID)
updateReq["owner"] = "other-org"
updateReq["repo"] = "other-repo"
w = doJSON(t, srv, http.MethodPatch, "/api/bindings/"+strconv.FormatInt(created.ID, 10), updateReq)
if w.Code != http.StatusOK {
t.Fatalf("update status = %d, want %d; body = %s", w.Code, http.StatusOK, w.Body.String())
}
var updated binding.Binding
if err := json.Unmarshal(w.Body.Bytes(), &updated); err != nil {
t.Fatalf("unmarshal updated: %v", err)
}
if updated.Owner != "other-org" || updated.Repo != "other-repo" {
t.Fatalf("updated owner/repo = %q/%q, want other-org/other-repo; body = %s", updated.Owner, updated.Repo, w.Body.String())
}
}
// TestHandleBindingCreateRejectsPartialOwnerRepo confirms the domain
// validation (owner and repo must both be set or both empty) is
// actually reached from the HTTP layer, not just unit-tested in
// isolation.
func TestHandleBindingCreateRejectsPartialOwnerRepo(t *testing.T) {
srv := bindingTestServer(t)
mappingID := seedMapping(t, srv, "m")
req := validBindingRequest("a", "sentry", mappingID)
req["owner"] = "acme"
// repo deliberately omitted
w := doJSON(t, srv, http.MethodPost, "/api/bindings", req)
if w.Code != http.StatusBadRequest {
t.Fatalf("create status = %d, want %d (partial owner/repo pin); body = %s", w.Code, http.StatusBadRequest, w.Body.String())
}
}
func TestHandleBindingsListStripsSecrets(t *testing.T) {
srv := bindingTestServer(t)
mappingID := seedMapping(t, srv, "m")