feat(apply): per-record selection + deletes-before-updates ordering

RecordDiff.Key() gives a stable normalized identifier ("TYPE name.") for
every diff kind, exposed as recordView.Key. ApplyRequest now takes
Updates/Prunes key lists instead of two booleans, so callers can apply a
subset of records. service.Apply builds the applied set with selected
prunes (Delete) added before selected updates (Add/Update) — an
invariant, not an option — since the provider rejects an Add/Update
whose name still conflicts with an existing record (e.g. a CNAME cannot
be created while an A on the same name still exists).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BwxdSt4reTm7Dj1oxRvpP3
This commit is contained in:
2026-07-05 15:10:01 +07:00
parent fc19678727
commit 0b26923586
7 changed files with 110 additions and 38 deletions
+9 -6
View File
@@ -84,12 +84,15 @@ func TestCheckEndpoint(t *testing.T) {
}
}
func TestApplyDefaultsPruneFalse(t *testing.T) {
// TestApplySendsSelectedKeys covers the per-record selection request shape:
// POST /apply with only "prunes" set must reach the service with that key in
// Prunes and an empty Updates.
func TestApplySendsSelectedKeys(t *testing.T) {
a, m := newTestAPI()
router := NewRouter(a)
did := uuid.New().String()
body := `{"applyUpdates":true}` // applyPrunes отсутствует → false
body := `{"prunes":["A gitlocator.com."]}`
req := requestWithSessionCookie(http.MethodPost,
"/api/v1/projects/00000000-0000-0000-0000-000000000002/domains/"+did+"/apply",
strings.NewReader(body))
@@ -99,7 +102,7 @@ func TestApplyDefaultsPruneFalse(t *testing.T) {
if w.Code != http.StatusOK {
t.Fatalf("status %d body %s", w.Code, w.Body.String())
}
if m.lastReq.ApplyPrunes != false || m.lastReq.ApplyUpdates != true {
if len(m.lastReq.Prunes) != 1 || m.lastReq.Prunes[0] != "A gitlocator.com." || len(m.lastReq.Updates) != 0 {
t.Fatalf("apply request mismatch: %+v", m.lastReq)
}
}
@@ -117,8 +120,8 @@ func TestApplyEmptyBodyOK(t *testing.T) {
if w.Code != http.StatusOK {
t.Fatalf("status %d body %s", w.Code, w.Body.String())
}
if m.lastReq.ApplyPrunes != false {
t.Fatalf("expected ApplyPrunes=false for empty body, got %+v", m.lastReq)
if len(m.lastReq.Updates) != 0 || len(m.lastReq.Prunes) != 0 {
t.Fatalf("expected empty Updates/Prunes for empty body, got %+v", m.lastReq)
}
}
@@ -127,7 +130,7 @@ func TestApplyMalformedBody(t *testing.T) {
router := NewRouter(a)
did := uuid.New().String()
body := `{"applyUpdates":`
body := `{"updates":`
req := requestWithSessionCookie(http.MethodPost,
"/api/v1/projects/00000000-0000-0000-0000-000000000002/domains/"+did+"/apply",
strings.NewReader(body))