oficina / alta Public

Resolve the canonical host through its domain claim

Production preflight refused all six apps with instance-missing and
artifact-mismatch: observe looked for a record whose host or
public_host was <app>.oficina.works, but on the platform that name is a
domain claim (GET /domains, what `carlos domains list` reads) routed to
the record <app>.bds.oncarlos.com. artifact-mismatch followed from the
empty snapshot: no probe ran, so the header was "".

- carlosop.Domains reads the app's claims; the route admits Publish and
  Instance, so Admin, with no new authority. The list is required and
  non-null, rows need a host, and errors are fixed sentences.
- observe resolves exactly one claim for CanonicalHost(app) (catch-all
  rows are not claims), then exactly one record at its route, refusing
  domain-missing, domain-ambiguous or instance-missing. A claim that is
  not live is domain-not-live, with no probe; nothing is guessed.
- public_host is the platform's display name under the apps domain,
  never a custom domain, so it is no longer read or matched.
- Identity binds the claim (Domain, Route); a re-pointed domain is
  identity-alias in every fresh comparison. RestartCanonical requires
  the claim to route to the record it restarts.
- rollbackDrift treats a lost binding as identity-changed and goes on
  past a claim that is merely not live.
- The fake serves GET /domains; fixtures use production's shape.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev b809fd40bf04206670eb5168e7ad960989b82f37 parent a9bdc5f
18 files changed, +632 −139
  • adopt/delivery_test.go +9 −0
  • adopt/deliverycheck_test.go +2 −2
  • adopt/gate_adverse_test.go +10 −3
  • adopt/observer_test.go +3 −3
  • adopt/rehearsal_test.go +6 −5
  • adopt/restart.go +3 −3
  • adopt/restart_test.go +16 −13
  • adopt/snapshot.go +84 −25
  • adopt/snapshot_test.go +180 −17
  • adopt/store_test.go +1 −1
  • adopt/types.go +19 −12
  • adopt/types_test.go +14 −8
  • adopt/write.go +19 −4
  • adopt/write_test.go +72 −27
  • carlosop/client.go +56 −6
  • carlosop/client_test.go +73 −2
  • carlosop/fakecarlos/fakecarlos.go +52 −2
  • cmd/alta-adopt/main_test.go +13 −6

CI passed — run details

CI log
=== vet ===
go vet ./...
=== fmt ===
=== test ===
CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/alta/adopt	16.691s
ok  	amadan.net/oficina/alta/carlosop	0.045s
?   	amadan.net/oficina/alta/carlosop/fakecarlos	[no test files]
ok  	amadan.net/oficina/alta/cmd/alta	0.180s
ok  	amadan.net/oficina/alta/cmd/alta-adopt	21.982s
ok  	amadan.net/oficina/alta/console	0.003s
?   	amadan.net/oficina/alta/console/fakeconsole	[no test files]
ok  	amadan.net/oficina/alta/homeop	0.003s
ok  	amadan.net/oficina/alta/homeop/fakehome	0.045s
ok  	amadan.net/oficina/alta/internal/web	0.112s
ok  	amadan.net/oficina/alta/provision	11.361s
=== compat ===
cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/home/altacompat	0.541s
diff --git a/adopt/delivery_test.go b/adopt/delivery_test.go
index 8aa145d..1f0ee5e 100644
--- a/adopt/delivery_test.go
+++ b/adopt/delivery_test.go
@@ -5,6 +5,7 @@ import (
"net/http"
"net/http/httptest"
"strings"
+ "sync/atomic"
"testing"
"amadan.net/oficina/alta/provision"
@@ -17,11 +18,19 @@ type site struct {
health int
ops func(w http.ResponseWriter)
redirectVersion bool
+ versionHost atomic.Value // the Host the last /api/version asked
+}
+
+// lastHost is the host the last version probe was addressed to.
+func (s *site) lastHost() string {
+ h, _ := s.versionHost.Load().(string)
+ return h
}
func (s *site) handler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/api/version", func(w http.ResponseWriter, r *http.Request) {
+ s.versionHost.Store(r.Host)
if s.redirectVersion {
http.Redirect(w, r, "/elsewhere", http.StatusFound)
return
diff --git a/adopt/deliverycheck_test.go b/adopt/deliverycheck_test.go
index faecdb5..485b689 100644
--- a/adopt/deliverycheck_test.go
+++ b/adopt/deliverycheck_test.go
@@ -201,7 +201,7 @@ func TestDeliveryCheckRefusesIdentityChangedSinceAfter(t *testing.T) {
t.Run(name, func(t *testing.T) {
w := newCheckFixture(t, "docs")
in := carlosop.Instance{
- Host: CanonicalHost(w.app), App: "docs", Slug: "s-docs", Channel: "stable", Region: "eu",
+ Host: routeOf(w.app), App: "docs", Slug: "s-docs", Channel: "stable", Region: "eu",
CreatedAt: w.after.Identity.CreatedAt, RecordSeq: w.after.Identity.RecordSeq,
ReplicaAssignment: []byte(w.after.Identity.ReplicaAssignment),
}
@@ -247,7 +247,7 @@ func TestDeliveryCheckRefusesConfigChangedSinceAfter(t *testing.T) {
w.f.Unset("docs", "", "DOCS_ORIGIN")
}, []string{"gone:DOCS_ORIGIN", "layer:default"}},
"overlay moved": {func(w *checkFixture) {
- w.f.SetOverlay("docs", "docs.oficina.works", "DOCS_ORIGIN", "https://elsewhere.example")
+ w.f.SetOverlay("docs", docsRoute, "DOCS_ORIGIN", "https://elsewhere.example")
}, []string{"from:DOCS_ORIGIN", "layer:overlay"}},
}
for name, tc := range cases {
diff --git a/adopt/gate_adverse_test.go b/adopt/gate_adverse_test.go
index 013768d..bdfb09d 100644
--- a/adopt/gate_adverse_test.go
+++ b/adopt/gate_adverse_test.go
@@ -389,7 +389,7 @@ func TestAdversePlanCWaitsOnPlanB(t *testing.T) {
// ---- Changed identity ----
func instanceOf(x *observerFixture) carlosop.Instance {
- return carlosop.Instance{Host: CanonicalHost(x.app), App: x.app.Slug, Slug: "s-" + x.app.Slug, Channel: "stable", Region: "eu",
+ return carlosop.Instance{Host: routeOf(x.app), App: x.app.Slug, Slug: "s-" + x.app.Slug, Channel: "stable", Region: "eu",
CreatedAt: time.Date(2026, 3, 1, 0, 0, 0, 0, time.UTC), RecordSeq: 4, ReplicaAssignment: json.RawMessage(`{"boxes":["b1"]}`)}
}
@@ -407,7 +407,14 @@ func TestAdverseChangedIdentity(t *testing.T) {
{name: "replica assignment", edit: changed(func(in *carlosop.Instance) { in.ReplicaAssignment = json.RawMessage(`{"boxes":["b2"]}`) }),
want: []string{"identity-storage"}},
{name: "seed", edit: changed(func(in *carlosop.Instance) { in.Seed = json.RawMessage(`{"from":"another"}`) }), want: []string{"identity-storage"}},
- {name: "public alias", edit: changed(func(in *carlosop.Instance) { in.PublicHost = "alias.oficina.works" }), want: []string{"identity-alias"}},
+ // The canonical domain re-pointed at another record: the
+ // evidence was bound to the old route.
+ {name: "domain re-pointed", edit: func(t *testing.T, x *observerFixture) {
+ in := instanceOf(x)
+ in.Host = "calendar-2.bds.oncarlos.com"
+ x.f.AddInstance(in)
+ x.f.AttachDomain(x.app.Slug, CanonicalHost(x.app), in.Host, "live")
+ }, want: []string{"identity-alias", "identity-instance"}},
{name: "channel", edit: changed(func(in *carlosop.Instance) { in.Channel = "beta" }), want: []string{"identity-channel"}},
{name: "region", edit: changed(func(in *carlosop.Instance) { in.Region = "us" }), want: []string{"identity-region"}},
{name: "moving", edit: changed(func(in *carlosop.Instance) { in.Move = json.RawMessage(`{"to":"us"}`) }), want: []string{"identity-moving"}},
@@ -465,7 +472,7 @@ func TestAdverseChangedConfig(t *testing.T) {
}, want: []string{"agent-key-CALENDAR_AGENT_ISSUER"}},
{name: "overlay shadows an agent key", edit: func(t *testing.T, x *observerFixture) {
// The same value, so the same digest: only its source differs.
- x.f.SetOverlay("calendar", CanonicalHost(x.app), "CALENDAR_AGENT_ISSUER", Issuer)
+ x.f.SetOverlay("calendar", routeOf(x.app), "CALENDAR_AGENT_ISSUER", Issuer)
}, want: []string{"agent-key-CALENDAR_AGENT_ISSUER"}},
{name: "one agent key unset", edit: func(t *testing.T, x *observerFixture) {
x.f.Unset("calendar", "", "CALENDAR_AGENT_TEAM")
diff --git a/adopt/observer_test.go b/adopt/observer_test.go
index 2415f3a..621b6b8 100644
--- a/adopt/observer_test.go
+++ b/adopt/observer_test.go
@@ -147,7 +147,7 @@ func (x *observerFixture) rejournal(t *testing.T, edit func(e *evidence)) {
func TestObserverHappyPathEvidenceTokens(t *testing.T) {
x := newObserverFixture(t, "calendar")
ctx := context.Background()
- host := CanonicalHost(x.app)
+ host := routeOf(x.app)
puts, restarts := x.puts(), x.f.RestartCount(host)
obs, err := x.observe()
@@ -284,7 +284,7 @@ func TestObserverRefusals(t *testing.T) {
x.rejournal(t, func(e *evidence) { e.write.Sent[AgentKeys(x.app)[0]] = "https://elsewhere.example" })
}, want: []string{"issuer-mismatch"}, exact: true},
{name: "identity changed", edit: func(t *testing.T, x *observerFixture) {
- x.f.AddInstance(carlosop.Instance{Host: CanonicalHost(x.app), App: "calendar", Slug: "s-calendar", Channel: "stable", Region: "us",
+ x.f.AddInstance(carlosop.Instance{Host: routeOf(x.app), App: "calendar", Slug: "s-calendar", Channel: "stable", Region: "us",
CreatedAt: time.Date(2026, 3, 1, 0, 0, 0, 0, time.UTC), RecordSeq: 4, ReplicaAssignment: json.RawMessage(`{"boxes":["b1"]}`)})
}, want: []string{"identity-region"}},
{name: "baseline identity differs", edit: func(t *testing.T, x *observerFixture) {
@@ -324,7 +324,7 @@ func TestObserverRefusals(t *testing.T) {
}, want: []string{"agent-key-CALENDAR_AGENT_TEAM"}},
{name: "overlay shadows an agent key", edit: func(t *testing.T, x *observerFixture) {
// The same value, so the same digest: only its source differs.
- x.f.SetOverlay("calendar", CanonicalHost(x.app), "CALENDAR_AGENT_ISSUER", Issuer)
+ x.f.SetOverlay("calendar", routeOf(x.app), "CALENDAR_AGENT_ISSUER", Issuer)
}, want: []string{"agent-key-CALENDAR_AGENT_ISSUER"}},
{name: "unhealthy", edit: func(t *testing.T, x *observerFixture) { x.site.health = 503 },
want: []string{"not-delivered"}, exact: true},
diff --git a/adopt/rehearsal_test.go b/adopt/rehearsal_test.go
index c5fe9d0..51403ec 100644
--- a/adopt/rehearsal_test.go
+++ b/adopt/rehearsal_test.go
@@ -160,10 +160,11 @@ func newRehearsal(t *testing.T) *rehearsal {
r.carlos.SetSecret(a.Slug, "", p+"_INSTANCE_KEY")
r.carlos.SetSecret(a.Slug, "", p+"_DB_KEY")
r.carlos.AddInstance(carlosop.Instance{
- Host: CanonicalHost(a), App: a.Slug, Slug: "s-" + a.Slug, Channel: "stable", Region: "eu",
+ Host: routeOf(a), App: a.Slug, Slug: "s-" + a.Slug, Channel: "stable", Region: "eu",
CreatedAt: time.Date(2026, 3, 1, 0, 0, 0, 0, time.UTC), RecordSeq: 4,
ReplicaAssignment: json.RawMessage(`{"boxes":["b1"]}`),
})
+ attachCanonical(r.carlos, a)
// A neighbour on its own owned environment: it shares no layer
// with the canonical host, so it never sees the keys, and it is
// never restarted.
@@ -277,7 +278,7 @@ func (r *rehearsal) serving(slug string) bool {
}
s.mu.Lock()
defer s.mu.Unlock()
- if n := r.carlos.RestartCount(CanonicalHost(a)); n != s.seen {
+ if n := r.carlos.RestartCount(routeOf(a)); n != s.seen {
vars, _, _ := r.carlos.Layer(slug, "")
keys := AgentKeys(a)
_, i := vars[keys[0]]
@@ -820,8 +821,8 @@ func (r *rehearsal) adopted() {
if n := r.carlos.RestartCount(neighbourHost(a.Slug)); n != 0 {
t.Fatalf("%s restarted %d times", neighbourHost(a.Slug), n)
}
- if n := r.carlos.RestartCount(CanonicalHost(a)); n < 1 || n > 2 {
- t.Fatalf("%s restarted %d times", CanonicalHost(a), n)
+ if n := r.carlos.RestartCount(routeOf(a)); n < 1 || n > 2 {
+ t.Fatalf("%s restarted %d times", routeOf(a), n)
}
}
if n := r.carlos.AppWideRestarts(); n != 0 {
@@ -876,7 +877,7 @@ func TestRehearsalFullRun(t *testing.T) {
if n := r.putsOf(a.Slug); n != 1 {
t.Fatalf("%s: %d PUTs, want one", a.Slug, n)
}
- if n := r.carlos.RestartCount(CanonicalHost(a)); n != 1 {
+ if n := r.carlos.RestartCount(routeOf(a)); n != 1 {
t.Fatalf("%s: %d restarts, want one", a.Slug, n)
}
}
diff --git a/adopt/restart.go b/adopt/restart.go
index af41341..5d47ab3 100644
--- a/adopt/restart.go
+++ b/adopt/restart.go
@@ -24,8 +24,8 @@ var (
// restart adoption makes, a rollback's included, comes through here; it
// is the only caller of carlosop.RestartHost.
//
-// id must be app's canonical record: its app, and the canonical host as
-// its record host or public alias. The restart door is first asked for a
+// id must be app's canonical record: its app, and the canonical domain
+// claimed for its record host. The restart door is first asked for a
// dry run, which must resolve exactly [id.RecordHost]; anything else is
// "restart-scope-<n>", n the number of routes it resolved, and nothing is
// restarted. A route the dry run reports as hibernating is accepted: it
@@ -42,7 +42,7 @@ func RestartCanonical(ctx context.Context, c *carlosop.Client, app provision.App
return errors.New("adopt: no console client")
case id.App != app.Slug:
return errors.New("adopt: the identity is another app's")
- case id.RecordHost == "" || id.RecordHost != host && id.PublicHost != host:
+ case id.RecordHost == "" || id.Domain != host || id.Route != id.RecordHost:
return errors.New("adopt: the identity is not the canonical host's")
}
routes, err := c.RestartHost(ctx, app.Slug, id.RecordHost, true)
diff --git a/adopt/restart_test.go b/adopt/restart_test.go
index 40dc388..9825e89 100644
--- a/adopt/restart_test.go
+++ b/adopt/restart_test.go
@@ -112,7 +112,7 @@ func TestRestartCanonicalLeavesOtherInstancesUntouched(t *testing.T) {
if err := RestartCanonical(context.Background(), x.c, x.app, id, true); err != nil {
t.Fatalf("RestartCanonical: %v", err)
}
- if n := x.f.RestartCount("docs.oficina.works"); n != 1 {
+ if n := x.f.RestartCount(docsRoute); n != 1 {
t.Fatalf("canonical host restarted %d times, want 1", n)
}
x.noRestarts(t, "staging.docs.example", "bare.docs.example")
@@ -134,7 +134,7 @@ func TestRestartCanonicalDryRunRestartsNothing(t *testing.T) {
if err := RestartCanonical(context.Background(), x.c, x.app, id, false); err != nil {
t.Fatalf("RestartCanonical dry run: %v", err)
}
- x.noRestarts(t, "docs.oficina.works")
+ x.noRestarts(t, docsRoute)
}
func TestRestartCanonicalRefusesWiderDryRun(t *testing.T) {
@@ -160,7 +160,7 @@ func TestRestartCanonicalRefusesWiderDryRun(t *testing.T) {
if err == nil || err.Error() != tc.code {
t.Fatalf("err = %v, want %s", err, tc.code)
}
- x.noRestarts(t, "docs.oficina.works", "staging.docs.example")
+ x.noRestarts(t, docsRoute, "staging.docs.example")
})
}
}
@@ -177,7 +177,7 @@ func TestRestartCanonicalAcceptsHibernatingRoute(t *testing.T) {
if err := RestartCanonical(context.Background(), x.c, x.app, id, true); err != nil {
t.Fatalf("RestartCanonical: %v", err)
}
- if n := x.f.RestartCount("docs.oficina.works"); n != 1 {
+ if n := x.f.RestartCount(docsRoute); n != 1 {
t.Fatalf("restarted %d times", n)
}
}
@@ -191,7 +191,7 @@ func TestRestartCanonicalFailsClosedOnOldConsole(t *testing.T) {
if !errors.Is(err, carlosop.ErrNoScopedRestart) {
t.Fatalf("err = %v, want ErrNoScopedRestart", err)
}
- x.noRestarts(t, "docs.oficina.works", "staging.docs.example")
+ x.noRestarts(t, docsRoute, "staging.docs.example")
for _, r := range x.f.Requests() {
if strings.HasSuffix(r, " /restart") {
t.Fatalf("fell back to the app-wide door: %q", r)
@@ -208,16 +208,19 @@ func TestRestartCanonicalStopsOnUnavailableRegistry(t *testing.T) {
if !errors.As(err, &se) || se.Code != http.StatusServiceUnavailable {
t.Fatalf("err = %v, want a 503 status error", err)
}
- x.noRestarts(t, "docs.oficina.works")
+ x.noRestarts(t, docsRoute)
}
func TestRestartCanonicalRefusesAnotherAppsIdentity(t *testing.T) {
x := newCarlosFixture(t, "docs")
id := x.identity(t)
cases := map[string]func(*Identity){
- "no host": func(i *Identity) { i.RecordHost, i.PublicHost = "", "" },
- "other host": func(i *Identity) { i.RecordHost, i.PublicHost = "staging.docs.example", "" },
- "other app": func(i *Identity) { i.App = "sheets" },
+ "no host": func(i *Identity) { i.RecordHost, i.Route = "", "" },
+ "other host": func(i *Identity) { i.RecordHost = "staging.docs.example" },
+ // The canonical domain's claim, but for another record.
+ "other route": func(i *Identity) { i.Route = "staging.docs.example" },
+ "other domain": func(i *Identity) { i.Domain = "staging.docs.oficina.works" },
+ "other app": func(i *Identity) { i.App = "sheets" },
}
for name, mutate := range cases {
t.Run(name, func(t *testing.T) {
@@ -228,7 +231,7 @@ func TestRestartCanonicalRefusesAnotherAppsIdentity(t *testing.T) {
}
})
}
- x.noRestarts(t, "docs.oficina.works")
+ x.noRestarts(t, docsRoute)
for _, r := range x.f.Requests() {
if strings.Contains(r, "restart") {
t.Fatalf("sent %q for a refused identity", r)
@@ -255,7 +258,7 @@ func TestRestartAndWaitReturnsOnceUntilPasses(t *testing.T) {
if calls != 3 || d.Version != valueVersion || d.Health != 200 {
t.Fatalf("calls %d delivery %+v", calls, d.Health)
}
- if n := x.f.RestartCount("docs.oficina.works"); n != 1 {
+ if n := x.f.RestartCount(docsRoute); n != 1 {
t.Fatalf("restarted %d times", n)
}
}
@@ -281,7 +284,7 @@ func TestRestartAndWaitTimesOut(t *testing.T) {
if el := time.Since(start); el > 2*time.Second {
t.Fatalf("waited %v past a 120ms limit", el)
}
- if n := x.f.RestartCount("docs.oficina.works"); n != 1 {
+ if n := x.f.RestartCount(docsRoute); n != 1 {
t.Fatalf("restarted %d times, want 1", n)
}
}
@@ -388,7 +391,7 @@ func TestRestartAndWaitDryRunRestartsAndWaitsForNothing(t *testing.T) {
if called || d.Version != valueVersion {
t.Fatalf("dry run evaluated until (%v) or did not probe", called)
}
- x.noRestarts(t, "docs.oficina.works")
+ x.noRestarts(t, docsRoute)
}
func TestRestartAndWaitDoesNotWaitWhenRestartRefused(t *testing.T) {
diff --git a/adopt/snapshot.go b/adopt/snapshot.go
index 541662b..e260d4d 100644
--- a/adopt/snapshot.go
+++ b/adopt/snapshot.go
@@ -57,45 +57,102 @@ func plainValue(l carlosop.Layer, ev *carlosop.EffectiveVar) string {
return ""
}
-// observe reads one snapshot of app's canonical host, and the app's
-// instance list it found that host in. The codes are the refusals that
-// leave no snapshot to check: instance-missing, layer-overlay, and
-// home-issuer-mismatch when the host has no Home issuer to locate the
-// write layer by. With h nil it makes no delivery probe, and the
-// snapshot's Delivery is empty: the config and identity alone.
-func observe(ctx context.Context, c *carlosop.Client, h *http.Client, app provision.App) (Snapshot, []carlosop.Instance, []string, error) {
- host := CanonicalHost(app)
- all, err := c.Instances(ctx, app.Slug)
- if err != nil {
- return Snapshot{}, nil, nil, err
+// canonicalRecord resolves app's canonical host as the platform routes
+// it: the canonical name is a domain claim, routed to one instance
+// record. It answers exactly one claim on the app whose host is host, and
+// exactly one record whose host is that claim's route, or the code that
+// refuses: domain-missing (no claim), domain-ambiguous (more than one),
+// instance-missing (no record at the route). A name a catch-all derives
+// (Via) and a catch-all's own row are not claims. Nothing else is tried:
+// a record whose own host is the canonical one, with no claim, is not
+// read as the canonical record.
+func canonicalRecord(host string, ds []carlosop.Domain, all []carlosop.Instance) (carlosop.Domain, *carlosop.Instance, string, error) {
+ var claims []carlosop.Domain
+ for _, d := range ds {
+ if d.Host == host && d.Via == "" && !d.Instances {
+ claims = append(claims, d)
+ }
}
- // The canonical host is the record's own host or its public alias.
+ switch len(claims) {
+ case 0:
+ return carlosop.Domain{}, nil, "domain-missing", nil
+ case 1:
+ default:
+ return carlosop.Domain{}, nil, "domain-ambiguous", nil
+ }
+ d := claims[0]
var rec *carlosop.Instance
for i := range all {
- if all[i].Host == host || all[i].PublicHost == host {
+ if d.Route != "" && all[i].Host == d.Route {
if rec != nil {
- return Snapshot{}, nil, nil, errors.New("adopt: more than one instance record answers for the canonical host")
+ return carlosop.Domain{}, nil, "", errors.New("adopt: more than one instance record answers for the canonical domain's route")
}
rec = &all[i]
}
}
if rec == nil {
- return Snapshot{}, all, []string{"instance-missing"}, nil
+ return carlosop.Domain{}, nil, "instance-missing", nil
}
- eff, err := c.Effective(ctx, app.Slug, rec.Host)
+ return d, rec, "", nil
+}
+
+// observe reads one snapshot of app's canonical host, and the app's
+// instance list it found that host's record in. The codes are the
+// refusals that leave no snapshot to check: domain-missing,
+// domain-ambiguous, instance-missing, layer-overlay, and
+// home-issuer-mismatch when the host has no Home issuer to locate the
+// write layer by. domain-not-live, a claim that is not live, comes with
+// the complete snapshot but no delivery probe: the binding is known, and
+// a probe of a name not served would say nothing. With h nil it makes no
+// delivery probe, and the snapshot's Delivery is empty: the config and
+// identity alone.
+func observe(ctx context.Context, c *carlosop.Client, h *http.Client, app provision.App) (Snapshot, []carlosop.Instance, []string, error) {
+ ds, err := c.Domains(ctx, app.Slug)
if err != nil {
return Snapshot{}, nil, nil, err
}
- snap := Snapshot{Identity: IdentityOf(*rec, eff), Layers: map[string]string{}, Vars: eff.Vars, At: time.Now().UTC()}
+ all, err := c.Instances(ctx, app.Slug)
+ if err != nil {
+ return Snapshot{}, nil, nil, err
+ }
+ d, rec, code, err := canonicalRecord(CanonicalHost(app), ds, all)
+ switch {
+ case err != nil:
+ return Snapshot{}, nil, nil, err
+ case code != "":
+ return Snapshot{}, all, []string{code}, nil
+ }
+ live := d.State == "live"
+ if !live {
+ h = nil
+ }
+ snap, codes, err := observeRecord(ctx, c, h, app, d, *rec)
+ if err != nil {
+ return Snapshot{}, nil, nil, err
+ }
+ if !live {
+ codes = sortedSet(append(codes, "domain-not-live"))
+ }
+ return snap, all, codes, nil
+}
+
+// observeRecord is observe once the canonical record is resolved: rec,
+// served at d.
+func observeRecord(ctx context.Context, c *carlosop.Client, h *http.Client, app provision.App, d carlosop.Domain, rec carlosop.Instance) (Snapshot, []string, error) {
+ eff, err := c.Effective(ctx, app.Slug, rec.Host)
+ if err != nil {
+ return Snapshot{}, nil, err
+ }
+ snap := Snapshot{Identity: IdentityOf(d, rec, eff), Layers: map[string]string{}, Vars: eff.Vars, At: time.Now().UTC()}
for k, v := range eff.Layers {
snap.Layers[k] = v
}
iss := findVar(eff.Vars, app.Prefix+"_HOME_ISSUER")
switch {
case iss == nil:
- return snap, all, []string{"home-issuer-mismatch"}, nil
+ return snap, []string{"home-issuer-mismatch"}, nil
case iss.From == "overlay":
- return snap, all, []string{"layer-overlay"}, nil
+ return snap, []string{"layer-overlay"}, nil
case iss.From == "environment":
snap.WriteLayer = eff.Environment
}
@@ -116,7 +173,7 @@ func observe(ctx context.Context, c *carlosop.Client, h *http.Client, app provis
return l, nil
}
if snap.Layer, err = read(layerName(snap.WriteLayer)); err != nil {
- return Snapshot{}, nil, nil, err
+ return Snapshot{}, nil, err
}
snap.HomeIssuer = plainValue(snap.Layer, iss)
// The overlay's plain values are not readable, so a consumer ID that
@@ -125,18 +182,18 @@ func observe(ctx context.Context, c *carlosop.Client, h *http.Client, app provis
src := snap.Layer
if cons.From != layerName(snap.WriteLayer) {
if src, err = read(cons.From); err != nil {
- return Snapshot{}, nil, nil, err
+ return Snapshot{}, nil, err
}
}
snap.HomeConsumer = plainValue(src, cons)
}
if h == nil {
- return snap, all, nil, nil
+ return snap, nil, nil
}
if snap.Delivery, err = Probe(ctx, h, provision.PublicOrigin(provision.AdoptionLabel, app.Slug)); err != nil {
- return Snapshot{}, nil, nil, err
+ return Snapshot{}, nil, err
}
- return snap, all, nil, nil
+ return snap, nil, nil
}
// Observe reads one snapshot of app's canonical host: its instance
@@ -198,7 +255,9 @@ func inherits(eff carlosop.Effective, writeLayer string, keys [2]string) bool {
// Preflight observes app and lists every reason its configuration may
// not be written, as fixed codes carrying key names and hosts only:
//
-// - instance-missing, instance-moving, owned-environment, layer-overlay;
+// - domain-missing, domain-ambiguous, domain-not-live, instance-missing
+// (the canonical domain is not one live claim routed to a record);
+// - instance-moving, owned-environment, layer-overlay;
// - home-issuer-mismatch, home-consumer-mismatch;
// - team-mode-<KEY>;
// - agent-keys-present, unless each present key is a plain var in the
diff --git a/adopt/snapshot_test.go b/adopt/snapshot_test.go
index d4a0bba..2a1c469 100644
--- a/adopt/snapshot_test.go
+++ b/adopt/snapshot_test.go
@@ -43,11 +43,25 @@ func appNamed(t *testing.T, slug string) provision.App {
return a
}
+// routeOf is the host of app's canonical record, as production has it:
+// the route the canonical domain (CanonicalHost) is claimed for, never
+// the domain itself.
+func routeOf(app provision.App) string { return app.Slug + "." + fixtureAccount + ".oncarlos.com" }
+
+// docsRoute is routeOf(docs).
+const docsRoute = "docs.bds.oncarlos.com"
+
+// attachCanonical claims app's canonical domain on f for its route, live,
+// as `carlos domains list` shows it in production.
+func attachCanonical(f *fakecarlos.Fake, app provision.App) {
+ f.AttachDomain(app.Slug, CanonicalHost(app), routeOf(app), "live")
+}
+
// fixtureInstance is the canonical host's instance record as the
// fixture first stores it.
func fixtureInstance(app provision.App) carlosop.Instance {
return carlosop.Instance{
- Host: CanonicalHost(app), App: app.Slug, Slug: "s-" + app.Slug, Channel: "stable", Region: "eu",
+ Host: routeOf(app), App: app.Slug, Slug: "s-" + app.Slug, Channel: "stable", Region: "eu",
CreatedAt: time.Date(2026, 3, 1, 0, 0, 0, 0, time.UTC), RecordSeq: 4,
ReplicaAssignment: json.RawMessage(`{"boxes":["b1"]}`),
}
@@ -64,6 +78,7 @@ func newCarlosFixture(t *testing.T, slug string) *carlosFixture {
f.SetVar(app.Slug, "", p+"_ORIGIN", valueOrigin)
f.SetSecret(app.Slug, "", p+"_INSTANCE_KEY")
f.AddInstance(fixtureInstance(app))
+ attachCanonical(f, app)
c := carlosop.New(f.URL(), fixtureAccount, f.Token())
t.Cleanup(c.Close)
@@ -106,7 +121,8 @@ func TestPreflightPassesCleanApp(t *testing.T) {
if snap.WriteLayer != "" || snap.Layer.Bundle != "default" || snap.HomeIssuer != HomeIssuerOrigin || snap.HomeConsumer != "docs" {
t.Fatalf("snapshot write layer %q bundle %q", snap.WriteLayer, snap.Layer.Bundle)
}
- if snap.Identity.RecordHost != "docs.oficina.works" || snap.Delivery.Version != valueVersion || snap.At.IsZero() {
+ if snap.Identity.RecordHost != docsRoute || snap.Identity.Domain != "docs.oficina.works" || snap.Identity.Route != docsRoute ||
+ snap.Delivery.Version != valueVersion || snap.At.IsZero() {
t.Fatalf("snapshot identity/delivery not recorded")
}
if len(snap.Vars) != 4 || len(snap.Layers) != 2 {
@@ -114,21 +130,166 @@ func TestPreflightPassesCleanApp(t *testing.T) {
}
}
-func TestPreflightFindsCanonicalAlias(t *testing.T) {
+// productionShape is docs as production has it (carlos domains list and
+// instances list, 2026-11-17): the canonical domain claimed, live, for
+// docs.bds.oncarlos.com; a lagged domain for a lagged record on the same
+// channel; and canary records with no domain of their own, one of them on
+// an owned environment.
+func productionShape(t *testing.T) *carlosFixture {
+ t.Helper()
x := newCarlosFixture(t, "docs")
x.f = fakecarlos.New(fixtureAccount)
t.Cleanup(x.f.Close)
x.f.SetVar("docs", "", "DOCS_HOME_ISSUER", HomeIssuerOrigin)
x.f.SetVar("docs", "", "DOCS_HOME_CONSUMER_ID", "docs")
- x.f.AddInstance(carlosop.Instance{Host: "docs-1.carlos.run", PublicHost: "docs.oficina.works", App: "docs", Slug: "s", Channel: "stable"})
- x.f.AddInstance(carlosop.Instance{Host: "other.carlos.run", App: "docs", Slug: "o", Environment: "o", Channel: "stable"})
- x.f.Own("docs", "o", "alta")
+ x.f.AddInstance(fixtureInstance(x.app))
+ x.f.AttachDomain("docs", "docs.oficina.works", docsRoute, "live")
+ for _, env := range []string{"lagged", "overnight-release", "contract-demo", "google-import"} {
+ x.f.SetVar("docs", env, "DOCS_HOME_ISSUER", HomeIssuerOrigin)
+ x.f.AddInstance(carlosop.Instance{Host: env + "-docs.bds.oncarlos.com", App: "docs", Slug: "s-" + env, Environment: env,
+ Channel: "stable", Region: "eu", CreatedAt: time.Date(2026, 10, 27, 0, 0, 0, 0, time.UTC)})
+ }
+ x.f.Own("docs", "google-import", "alta")
+ x.f.AttachDomain("docs", "lagged.docs.oficina.works", "lagged-docs.bds.oncarlos.com", "live")
x.c = carlosop.New(x.f.URL(), fixtureAccount, x.f.Token())
t.Cleanup(x.c.Close)
+ return x
+}
+
+// The canonical name is a domain claim, and the record is the one its
+// route names. The other records, with a domain of their own or none, are
+// neighbours: each that folds in the default would inherit the keys.
+func TestPreflightResolvesCanonicalDomainInProductionShape(t *testing.T) {
+ x := productionShape(t)
snap, codes := x.preflight(t, nil)
+ wantCodes(t, codes, "inherits-contract-demo-docs.bds.oncarlos.com", "inherits-lagged-docs.bds.oncarlos.com",
+ "inherits-overnight-release-docs.bds.oncarlos.com")
+ id := snap.Identity
+ if id.RecordHost != docsRoute || id.Domain != "docs.oficina.works" || id.Route != docsRoute || id.Slug != "s-docs" {
+ t.Fatalf("identity %+v", id)
+ }
+ if snap.WriteLayer != "" || snap.Delivery.Header != valueVersion {
+ t.Fatalf("write layer %q, delivery header %q", snap.WriteLayer, snap.Delivery.Header)
+ }
+ if code := ReviewedRelease(snap.Delivery, sha256Hex(valueVersion)); code != "" {
+ t.Fatalf("the reviewed release read %s from the canonical domain", code)
+ }
+ if got := x.site.lastHost(); got != "docs.oficina.works" {
+ t.Fatalf("the probe asked %q, not the canonical domain", got)
+ }
+}
+
+// Each lookalike of the canonical binding refuses with its own code and
+// no delivery probe; nothing falls back to a guess.
+func TestPreflightRefusesCanonicalDomainLookalikes(t *testing.T) {
+ cases := map[string]struct {
+ edit func(x *carlosFixture)
+ want string
+ }{
+ "no claim": {func(x *carlosFixture) { x.f.DetachDomain("docs", "docs.oficina.works") }, "domain-missing"},
+ // The canonical name as a record's own host is not a claim.
+ "record named like the domain": {func(x *carlosFixture) {
+ x.f.DetachDomain("docs", "docs.oficina.works")
+ x.f.AddInstance(carlosop.Instance{Host: "docs.oficina.works", App: "docs", Slug: "s-docs", Channel: "stable"})
+ }, "domain-missing"},
+ "claim pending DNS": {func(x *carlosFixture) { x.f.AttachDomain("docs", "docs.oficina.works", docsRoute, "pending-dns") }, "domain-not-live"},
+ "claim unverified": {func(x *carlosFixture) { x.f.AttachDomain("docs", "docs.oficina.works", docsRoute, "unverified") }, "domain-not-live"},
+ "claim with no state": {func(x *carlosFixture) { x.f.AttachDomain("docs", "docs.oficina.works", docsRoute, "") }, "domain-not-live"},
+ "route to a missing record": {func(x *carlosFixture) {
+ x.f.AttachDomain("docs", "docs.oficina.works", "gone-docs.bds.oncarlos.com", "live")
+ }, "instance-missing"},
+ "claim with no route": {func(x *carlosFixture) { x.f.AttachDomain("docs", "docs.oficina.works", "", "live") }, "instance-missing"},
+ }
+ for name, c := range cases {
+ t.Run(name, func(t *testing.T) {
+ x := productionShape(t)
+ c.edit(x)
+ snap, codes := x.preflight(t, nil)
+ wantCodes(t, codes, c.want)
+ if snap.Delivery != (Delivery{}) || x.site.lastHost() != "" {
+ t.Fatalf("a refused binding was probed")
+ }
+ if _, err := Observe(context.Background(), x.c, x.h, x.app); err == nil || !strings.Contains(err.Error(), c.want) {
+ t.Fatalf("Observe: %v, want %s", err, c.want)
+ }
+ })
+ }
+}
+
+// Two claims answering for the canonical name are ambiguous: neither is
+// picked. A name a catch-all derives is not a claim, beside one or alone.
+func TestCanonicalRecordRefusesTwoClaims(t *testing.T) {
+ x := productionShape(t)
+ all, err := x.c.Instances(context.Background(), "docs")
+ if err != nil {
+ t.Fatalf("Instances: %v", err)
+ }
+ canon := carlosop.Domain{Host: "docs.oficina.works", Route: docsRoute, State: "live"}
+ other := carlosop.Domain{Host: "docs.oficina.works", Route: "lagged-docs.bds.oncarlos.com", State: "live"}
+ if _, rec, code, err := canonicalRecord("docs.oficina.works", []carlosop.Domain{canon, other}, all); err != nil || rec != nil || code != "domain-ambiguous" {
+ t.Fatalf("two claims: %v %v %q", rec, err, code)
+ }
+ derived := other
+ derived.Via = "*.oficina.works"
+ if d, rec, code, err := canonicalRecord("docs.oficina.works", []carlosop.Domain{canon, derived}, all); err != nil || code != "" || rec.Host != docsRoute || d != canon {
+ t.Fatalf("a claim beside a derived name: %v %q", err, code)
+ }
+ if _, _, code, _ := canonicalRecord("docs.oficina.works", []carlosop.Domain{derived}, all); code != "domain-missing" {
+ t.Fatalf("a derived name alone was read as the claim: %q", code)
+ }
+ // The console's own answer with two rows for the name refuses
+ // Preflight before any config is read.
+ var reads []string
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ reads = append(reads, r.URL.Path)
+ w.Header().Set("Content-Type", "application/json")
+ switch r.URL.Path {
+ case "/api/cli/apps/bds/docs/domains":
+ _, _ = io.WriteString(w, `{"domains":[`+
+ `{"host":"docs.oficina.works","route":"docs.bds.oncarlos.com","state":"live"},`+
+ `{"host":"docs.oficina.works","route":"lagged-docs.bds.oncarlos.com","state":"live"}]}`)
+ case "/api/cli/apps/bds/docs/instances":
+ _, _ = io.WriteString(w, `{"instances":[{"host":"docs.bds.oncarlos.com","app":"docs","account":"bds"},`+
+ `{"host":"lagged-docs.bds.oncarlos.com","app":"docs","account":"bds"}],"truncated":false}`)
+ default:
+ w.WriteHeader(http.StatusNotFound)
+ }
+ }))
+ t.Cleanup(srv.Close)
+ c := carlosop.New(srv.URL, fixtureAccount, []byte("svc_token"))
+ t.Cleanup(c.Close)
+ _, codes, err := Preflight(context.Background(), c, x.h, x.app, nil)
+ if err != nil {
+ t.Fatalf("Preflight: %v", err)
+ }
+ wantCodes(t, codes, "domain-ambiguous")
+ if len(reads) != 2 || x.site.lastHost() != "" {
+ t.Fatalf("an ambiguous claim went on to read %v, or probed", reads)
+ }
+}
+
+// The domain re-pointed at another record between two observations
+// changes the identity, though neither record changed.
+func TestRepointedDomainChangesIdentity(t *testing.T) {
+ x := productionShape(t)
+ before, err := Observe(context.Background(), x.c, x.h, x.app)
+ if err != nil {
+ t.Fatalf("Observe: %v", err)
+ }
+ x.f.AttachDomain("docs", "docs.oficina.works", "lagged-docs.bds.oncarlos.com", "live")
+ after, _, codes, err := observe(context.Background(), x.c, nil, x.app)
+ if err != nil {
+ t.Fatalf("observe: %v", err)
+ }
wantCodes(t, codes)
- if snap.Identity.RecordHost != "docs-1.carlos.run" || snap.Identity.PublicHost != "docs.oficina.works" {
- t.Fatalf("record %q alias %q", snap.Identity.RecordHost, snap.Identity.PublicHost)
+ if got := SameIdentity(before.Identity, after.Identity); !reflect.DeepEqual(got, []string{"alias", "environment", "instance", "record", "storage"}) {
+ t.Fatalf("SameIdentity = %v", got)
+ }
+ // The claim's route alone moving is the alias.
+ moved := before.Identity
+ moved.Route = "lagged-docs.bds.oncarlos.com"
+ if got := SameIdentity(before.Identity, moved); !reflect.DeepEqual(got, []string{"alias"}) {
+ t.Fatalf("SameIdentity = %v", got)
}
}
@@ -183,7 +344,8 @@ func TestPreflightNamedWriteLayerInheritance(t *testing.T) {
x.f.SetVar("docs", "prod", "DOCS_HOME_ISSUER", HomeIssuerOrigin)
x.f.SetVar("docs", "prod", "DOCS_HOME_CONSUMER_ID", "docs")
x.f.SetVar("docs", "other", "DOCS_ORIGIN", "x")
- x.f.AddInstance(carlosop.Instance{Host: "docs.oficina.works", App: "docs", Slug: "s", Environment: "prod", Channel: "stable"})
+ x.f.AddInstance(carlosop.Instance{Host: docsRoute, App: "docs", Slug: "s", Environment: "prod", Channel: "stable"})
+ attachCanonical(x.f, x.app)
x.f.AddInstance(carlosop.Instance{Host: "other.docs.example", App: "docs", Slug: "o", Environment: "other", Channel: "stable"})
x.f.AddInstance(carlosop.Instance{Host: "bare.docs.example", App: "docs", Slug: "b", Channel: "stable"})
x.c = carlosop.New(x.f.URL(), fixtureAccount, x.f.Token())
@@ -247,14 +409,14 @@ func TestPreflightRefusesForeignAgentKeys(t *testing.T) {
// Our value, but from a layer above the write layer: not ours either.
y := newCarlosFixture(t, "docs")
- y.f.SetOverlay("docs", "docs.oficina.works", "DOCS_AGENT_ISSUER", Issuer)
+ y.f.SetOverlay("docs", docsRoute, "DOCS_AGENT_ISSUER", Issuer)
_, codes = y.preflight(t, mine)
wantCodes(t, codes, "agent-keys-present")
}
func TestPreflightRefusesMovingInstance(t *testing.T) {
x := newCarlosFixture(t, "docs")
- x.f.AddInstance(carlosop.Instance{Host: "docs.oficina.works", App: "docs", Slug: "s-docs", Channel: "stable", Region: "eu",
+ x.f.AddInstance(carlosop.Instance{Host: docsRoute, App: "docs", Slug: "s-docs", Channel: "stable", Region: "eu",
Move: json.RawMessage(`{"to":"us"}`)})
_, codes := x.preflight(t, nil)
wantCodes(t, codes, "instance-moving")
@@ -269,10 +431,11 @@ func TestPreflightRefusesEachConfigCode(t *testing.T) {
x.f = fakecarlos.New(fixtureAccount)
x.f.SetVar("docs", "", "DOCS_HOME_ISSUER", HomeIssuerOrigin)
x.f.AddInstance(carlosop.Instance{Host: "elsewhere.docs.example", App: "docs", Slug: "e", Channel: "stable"})
+ attachCanonical(x.f, x.app)
x.c = carlosop.New(x.f.URL(), fixtureAccount, x.f.Token())
}, []string{"instance-missing"}},
"layer-overlay": {func(x *carlosFixture) {
- x.f.SetOverlay("docs", "docs.oficina.works", "DOCS_HOME_ISSUER", HomeIssuerOrigin)
+ x.f.SetOverlay("docs", docsRoute, "DOCS_HOME_ISSUER", HomeIssuerOrigin)
}, []string{"layer-overlay"}},
"home-issuer-absent": {func(x *carlosFixture) {
x.f.Unset("docs", "", "DOCS_HOME_ISSUER")
@@ -290,10 +453,10 @@ func TestPreflightRefusesEachConfigCode(t *testing.T) {
x.f.Unset("docs", "", "DOCS_HOME_CONSUMER_ID")
}, []string{"home-consumer-mismatch"}},
"home-consumer-overlay": {func(x *carlosFixture) {
- x.f.SetOverlay("docs", "docs.oficina.works", "DOCS_HOME_CONSUMER_ID", "docs")
+ x.f.SetOverlay("docs", docsRoute, "DOCS_HOME_CONSUMER_ID", "docs")
}, []string{"home-consumer-mismatch"}},
"owned-environment": {func(x *carlosFixture) {
- x.f.AddInstance(carlosop.Instance{Host: "docs.oficina.works", App: "docs", Slug: "s-docs", Environment: "mine", Channel: "stable"})
+ x.f.AddInstance(carlosop.Instance{Host: docsRoute, App: "docs", Slug: "s-docs", Environment: "mine", Channel: "stable"})
x.f.SetVar("docs", "mine", "DOCS_HOME_ISSUER", HomeIssuerOrigin)
x.f.SetVar("docs", "mine", "DOCS_HOME_CONSUMER_ID", "docs")
x.f.Own("docs", "mine", "alta")
@@ -383,7 +546,7 @@ func TestPreflightErrorsOnUnreadableNeighbour(t *testing.T) {
func TestObserveRefusesWithoutWriteLayer(t *testing.T) {
x := newCarlosFixture(t, "docs")
- x.f.SetOverlay("docs", "docs.oficina.works", "DOCS_HOME_ISSUER", HomeIssuerOrigin)
+ x.f.SetOverlay("docs", docsRoute, "DOCS_HOME_ISSUER", HomeIssuerOrigin)
if _, err := Observe(context.Background(), x.c, x.h, x.app); err == nil || !strings.Contains(err.Error(), "layer-overlay") {
t.Fatalf("Observe = %v", err)
}
@@ -417,7 +580,7 @@ func TestPreflightOutputHasNoValuesOrDigests(t *testing.T) {
}
}
// And the errors: an Observe that refuses names codes only.
- x.f.SetOverlay("docs", "docs.oficina.works", "DOCS_HOME_ISSUER", "https://overlay-value.example")
+ x.f.SetOverlay("docs", docsRoute, "DOCS_HOME_ISSUER", "https://overlay-value.example")
_, err = Observe(context.Background(), x.c, x.h, x.app)
if err == nil {
t.Fatal("Observe passed an overlay issuer")
@@ -447,7 +610,7 @@ var added = [2]string{"DOCS_AGENT_ISSUER", "DOCS_AGENT_TEAM"}
func beforeSnap() Snapshot {
id, eff := inst()
return Snapshot{
- Identity: IdentityOf(id, eff),
+ Identity: IdentityOf(dom(), id, eff),
WriteLayer: "",
Layer: carlosop.Layer{Bundle: "default", Version: vA, Vars: []carlosop.Var{
{Key: "DOCS_HOME_ISSUER", Kind: "env", Digest: dA},
diff --git a/adopt/store_test.go b/adopt/store_test.go
index bda6618..7afea89 100644
--- a/adopt/store_test.go
+++ b/adopt/store_test.go
@@ -58,7 +58,7 @@ func snapshot(app, version, digest string) Snapshot {
id, eff := inst()
id.App = app
return Snapshot{
- Identity: IdentityOf(id, eff),
+ Identity: IdentityOf(dom(), id, eff),
WriteLayer: "env1",
Layer: carlosop.Layer{Bundle: "env1", Version: version, Vars: []carlosop.Var{
{Key: "DOCS_TITLE", Kind: "env", Value: valueCanary, Digest: digest},
diff --git a/adopt/types.go b/adopt/types.go
index 1fdc813..bdf1476 100644
--- a/adopt/types.go
+++ b/adopt/types.go
@@ -31,20 +31,26 @@ func CanonicalHost(app provision.App) string {
// and Seed: recreating the instance or swapping its storage gives a new
// record or a new assignment, and a move changes Region and sets Move.
// ReplicaAssignment and Seed are canonical JSON ("" when absent).
+//
+// Domain and Route are the claim that makes RecordHost the canonical
+// one: the canonical domain, and the record host it routes to. A domain
+// re-pointed at another record is a changed identity even before the
+// record it left changes.
type Identity struct {
- Account, App, RecordHost, PublicHost, Slug, Environment, Channel, Region string
- Owned, Moving bool
- CreatedAt time.Time
- RecordSeq uint64
- ReplicaAssignment, Seed string
+ Account, App, RecordHost, Slug, Environment, Channel, Region string
+ Domain, Route string
+ Owned, Moving bool
+ CreatedAt time.Time
+ RecordSeq uint64
+ ReplicaAssignment, Seed string
}
-// IdentityOf describes an instance record with its effective view. It
-// never errors: JSON it cannot canonicalise is kept as its raw bytes, so a
-// change still shows.
-func IdentityOf(in carlosop.Instance, eff carlosop.Effective) Identity {
+// IdentityOf describes an instance record, the domain claim routed to it
+// and its effective view. It never errors: JSON it cannot canonicalise is
+// kept as its raw bytes, so a change still shows.
+func IdentityOf(d carlosop.Domain, in carlosop.Instance, eff carlosop.Effective) Identity {
return Identity{
- Account: in.Account, App: in.App, RecordHost: in.Host, PublicHost: in.PublicHost,
+ Account: in.Account, App: in.App, RecordHost: in.Host, Domain: d.Host, Route: d.Route,
Slug: in.Slug, Environment: in.Environment, Channel: in.Channel, Region: in.Region,
Owned: eff.Owned, Moving: present(in.Move),
CreatedAt: in.CreatedAt, RecordSeq: in.RecordSeq,
@@ -77,7 +83,8 @@ func canonical(raw json.RawMessage) string {
// SameIdentity returns the sorted, distinct codes of what differs:
// storage (slug, created_at, replica, seed), instance (record host, and
-// account or app), alias (public host), environment, owned, channel,
+// account or app), alias (the canonical domain or the route it is
+// claimed for), environment, owned, channel,
// region, moving and record (the record's sequence).
//
// record stays in (Task 7 step 0, read at carlos/platform config-receipts-1
@@ -98,7 +105,7 @@ func SameIdentity(a, b Identity) []string {
flag(a.Slug != b.Slug || !a.CreatedAt.Equal(b.CreatedAt) ||
a.ReplicaAssignment != b.ReplicaAssignment || a.Seed != b.Seed, "storage")
flag(a.RecordHost != b.RecordHost || a.Account != b.Account || a.App != b.App, "instance")
- flag(a.PublicHost != b.PublicHost, "alias")
+ flag(a.Domain != b.Domain || a.Route != b.Route, "alias")
flag(a.Environment != b.Environment, "environment")
flag(a.Owned != b.Owned, "owned")
flag(a.Channel != b.Channel, "channel")
diff --git a/adopt/types_test.go b/adopt/types_test.go
index ec726fe..0d41098 100644
--- a/adopt/types_test.go
+++ b/adopt/types_test.go
@@ -29,7 +29,7 @@ func TestAgentKeysAndCanonicalHost(t *testing.T) {
func inst() (carlosop.Instance, carlosop.Effective) {
return carlosop.Instance{
- Host: "rec.example", PublicHost: "docs.oficina.works", Account: "bds", App: "docs", Slug: "s1",
+ Host: "rec.example", Account: "bds", App: "docs", Slug: "s1",
Environment: "env1", Channel: "stable", Region: "eu", RecordSeq: 7,
CreatedAt: time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC),
ReplicaAssignment: json.RawMessage(`{"b": 2, "a": 1}`), Seed: json.RawMessage(`{"x":[1, 2]}`),
@@ -37,10 +37,15 @@ func inst() (carlosop.Instance, carlosop.Effective) {
carlosop.Effective{Host: "rec.example", Environment: "env1", Owned: false}
}
+// dom is the canonical domain's claim, routed to inst's record.
+func dom() carlosop.Domain {
+ return carlosop.Domain{Host: "docs.oficina.works", Route: "rec.example", State: "live"}
+}
+
func TestIdentityOf(t *testing.T) {
in, eff := inst()
- id := IdentityOf(in, eff)
- if id.Account != "bds" || id.App != "docs" || id.RecordHost != "rec.example" || id.PublicHost != "docs.oficina.works" ||
+ id := IdentityOf(dom(), in, eff)
+ if id.Account != "bds" || id.App != "docs" || id.RecordHost != "rec.example" || id.Domain != "docs.oficina.works" || id.Route != "rec.example" ||
id.Slug != "s1" || id.Environment != "env1" || id.Channel != "stable" || id.Region != "eu" || id.RecordSeq != 7 {
t.Fatalf("identity = %+v", id)
}
@@ -52,16 +57,16 @@ func TestIdentityOf(t *testing.T) {
}
in.Move = json.RawMessage(`{"to":"us"}`)
eff.Owned = true
- id = IdentityOf(in, eff)
+ id = IdentityOf(dom(), in, eff)
if !id.Moving || !id.Owned {
t.Fatal("moving/owned not carried")
}
in.Move = json.RawMessage(`null`)
- if IdentityOf(in, eff).Moving {
+ if IdentityOf(dom(), in, eff).Moving {
t.Fatal("a JSON null move counts as moving")
}
in.ReplicaAssignment, in.Seed = nil, nil
- id = IdentityOf(in, eff)
+ id = IdentityOf(dom(), in, eff)
if id.ReplicaAssignment != "" || id.Seed != "" {
t.Fatal("absent should be empty")
}
@@ -69,7 +74,7 @@ func TestIdentityOf(t *testing.T) {
func TestSameIdentityFlagsEachField(t *testing.T) {
in, eff := inst()
- base := IdentityOf(in, eff)
+ base := IdentityOf(dom(), in, eff)
if got := SameIdentity(base, base); len(got) != 0 {
t.Fatalf("equal identities differ: %v", got)
}
@@ -82,7 +87,8 @@ func TestSameIdentityFlagsEachField(t *testing.T) {
{"replica", "storage", func(i *Identity) { i.ReplicaAssignment = `{"a":9}` }},
{"seed", "storage", func(i *Identity) { i.Seed = `{"x":[]}` }},
{"record-host", "instance", func(i *Identity) { i.RecordHost = "other.example" }},
- {"public-host", "alias", func(i *Identity) { i.PublicHost = "other.oficina.works" }},
+ {"domain", "alias", func(i *Identity) { i.Domain = "other.oficina.works" }},
+ {"route", "alias", func(i *Identity) { i.Route = "other.example" }},
{"environment", "environment", func(i *Identity) { i.Environment = "env2" }},
{"owned", "owned", func(i *Identity) { i.Owned = !i.Owned }},
{"channel", "channel", func(i *Identity) { i.Channel = "beta" }},
diff --git a/adopt/write.go b/adopt/write.go
index 8939f49..b7a1d07 100644
--- a/adopt/write.go
+++ b/adopt/write.go
@@ -706,9 +706,10 @@ func RollbackAgentKeys(ctx context.Context, c *carlosop.Client, h *http.Client,
// when anything differs, the stop code and what differs, by field and
// key name only:
//
-// - identity-changed: no record answers for the host any more, or its
-// instance, environment binding, storage or record is not the
-// baseline's (identity-<field>);
+// - identity-changed: the canonical domain is no longer one claim
+// routed to a record, or the record's instance, alias, environment
+// binding, storage or record is not the baseline's (identity-<field>);
+// a claim that is merely not live is not a change;
// - preserved-changed: any key of the baseline but the two agent keys
// changed, went, changed kind or moved layer, in the effective config
// or the write layer's stored vars, or a layer the write did not
@@ -716,10 +717,14 @@ func RollbackAgentKeys(ctx context.Context, c *carlosop.Client, h *http.Client,
// longer be located (observe's codes).
func rollbackDrift(ctx context.Context, c *carlosop.Client, app provision.App, base Snapshot) (carlosop.Layer, string, []string, error) {
fresh, _, codes, err := observe(ctx, c, nil, app)
+ // A claim that is not live still names the same record, which
+ // SameIdentity compares below: the rollback goes on, and its probe
+ // says whether the name is served.
+ codes = slices.DeleteFunc(codes, func(code string) bool { return code == "domain-not-live" })
switch {
case err != nil:
return carlosop.Layer{}, "", nil, err
- case slices.Contains(codes, "instance-missing"):
+ case slices.ContainsFunc(codes, unbound):
return carlosop.Layer{}, "identity-changed", codes, nil
case len(codes) > 0:
return carlosop.Layer{}, "preserved-changed", codes, nil
@@ -736,6 +741,16 @@ func rollbackDrift(ctx context.Context, c *carlosop.Client, app provision.App, b
return fresh.Layer, "", nil, nil
}
+// unbound reports whether an observe code says the canonical domain no
+// longer resolves to a record.
+func unbound(code string) bool {
+ switch code {
+ case "domain-missing", "domain-ambiguous", "instance-missing":
+ return true
+ }
+ return false
+}
+
// rollbackRestart restarts the canonical host and waits for Reverted
// against the baseline, then journals the rollback restarted. A failure
// journals it unset, code restart-failed, for a resume.
diff --git a/adopt/write_test.go b/adopt/write_test.go
index ade0183..088f84c 100644
--- a/adopt/write_test.go
+++ b/adopt/write_test.go
@@ -133,7 +133,7 @@ func noValues(t *testing.T, err error) {
// loaded at the current restart count with loaded as given.
func (x *carlosFixture) process(loaded bool) {
keys := AgentKeys(x.app)
- host := CanonicalHost(x.app)
+ host := routeOf(x.app)
var mu sync.Mutex
seen := x.f.RestartCount(host)
x.site.ops = func(w http.ResponseWriter) {
@@ -238,7 +238,7 @@ func TestConfigureCallsPreflightEvenWhenInvokedDirectly(t *testing.T) {
"home issuer": func(w *writeFixture) { w.f.SetVar("docs", "", "DOCS_HOME_ISSUER", "https://id.elsewhere.example") },
"healthz": func(w *writeFixture) { w.site.health = 503 },
"moving": func(w *writeFixture) {
- w.f.AddInstance(carlosop.Instance{Host: "docs.oficina.works", App: "docs", Slug: "s-docs", Channel: "stable", Region: "eu",
+ w.f.AddInstance(carlosop.Instance{Host: docsRoute, App: "docs", Slug: "s-docs", Channel: "stable", Region: "eu",
CreatedAt: time.Date(2026, 3, 1, 0, 0, 0, 0, time.UTC), RecordSeq: 4, Move: json.RawMessage(`{"to":"us"}`)})
},
}
@@ -354,7 +354,7 @@ func TestWriteSummaryNamesTheWriteLayer(t *testing.T) {
w := newWriteFixture(t, "docs")
w.f.SetVar("docs", "prod", "DOCS_HOME_ISSUER", HomeIssuerOrigin)
w.f.SetVar("docs", "prod", "DOCS_HOME_CONSUMER_ID", "docs")
- w.f.AddInstance(carlosop.Instance{Host: "docs.oficina.works", App: "docs", Slug: "s-docs", Environment: "prod", Channel: "stable", Region: "eu",
+ w.f.AddInstance(carlosop.Instance{Host: docsRoute, App: "docs", Slug: "s-docs", Environment: "prod", Channel: "stable", Region: "eu",
CreatedAt: time.Date(2026, 3, 1, 0, 0, 0, 0, time.UTC), RecordSeq: 4, ReplicaAssignment: json.RawMessage(`{"boxes":["b1"]}`)})
summary, err := w.configure(true)
if err != nil {
@@ -884,7 +884,7 @@ func TestWriteRefusesWhenBaselineNoLongerDescribesTheHost(t *testing.T) {
if err := w.s.SaveBaseline(ctx, "docs", snap); err != nil {
t.Fatal(err)
}
- w.f.AddInstance(carlosop.Instance{Host: "docs.oficina.works", App: "docs", Slug: "s-docs-new", Channel: "stable", Region: "eu",
+ w.f.AddInstance(carlosop.Instance{Host: docsRoute, App: "docs", Slug: "s-docs-new", Channel: "stable", Region: "eu",
CreatedAt: time.Date(2026, 11, 1, 0, 0, 0, 0, time.UTC), RecordSeq: 9})
_, err = w.configure(true)
if err == nil || !strings.Contains(err.Error(), "identity-storage") {
@@ -1062,7 +1062,7 @@ func TestAfterSnapshotRefusesSecretResealedBeforeCapture(t *testing.T) {
"agent key": func(w *writeFixture) { w.f.SetVar("docs", "", "DOCS_AGENT_TEAM", "tOther9") },
"agent gone": func(w *writeFixture) { w.f.Unset("docs", "", "DOCS_AGENT_ISSUER") },
"team mode": func(w *writeFixture) { w.f.SetVar("docs", "", "DOCS_TEAM_ID", "team-id-value") },
- "overlay": func(w *writeFixture) { w.f.SetOverlay("docs", "docs.oficina.works", "DOCS_ORIGIN", "x") },
+ "overlay": func(w *writeFixture) { w.f.SetOverlay("docs", docsRoute, "DOCS_ORIGIN", "x") },
}
for name, edit := range cases {
t.Run(name, func(t *testing.T) {
@@ -1153,7 +1153,7 @@ func (w *writeFixture) rollbackPuts(base int) int { return w.puts() - base }
func TestRollbackHappyPath(t *testing.T) {
w := newWriteFixture(t, "docs")
w.configured(t)
- p, r := w.puts(), w.f.RestartCount("docs.oficina.works")
+ p, r := w.puts(), w.f.RestartCount(docsRoute)
if err := w.rollback(true); err != nil {
t.Fatalf("RollbackAgentKeys: %v", err)
}
@@ -1167,7 +1167,7 @@ func TestRollbackHappyPath(t *testing.T) {
if !ok || rec.State != "restarted" || rec.Receipt == nil || rec.Code != "" {
t.Fatalf("rollback %v state %q code %q", ok, rec.State, rec.Code)
}
- if got := w.f.RestartCount("docs.oficina.works"); got != r+1 {
+ if got := w.f.RestartCount(docsRoute); got != r+1 {
t.Fatalf("restarts %d, want one more", got-r)
}
// Restarted is the end: a second call sends nothing.
@@ -1183,11 +1183,11 @@ func TestRollbackHappyPath(t *testing.T) {
func TestRollbackDryRunSendsNothing(t *testing.T) {
w := newWriteFixture(t, "docs")
w.configured(t)
- p, r := w.puts(), w.f.RestartCount("docs.oficina.works")
+ p, r := w.puts(), w.f.RestartCount(docsRoute)
if err := w.rollback(false); err != nil {
t.Fatalf("dry run: %v", err)
}
- if w.rollbackPuts(p) != 0 || w.f.RestartCount("docs.oficina.works") != r {
+ if w.rollbackPuts(p) != 0 || w.f.RestartCount(docsRoute) != r {
t.Fatal("a dry run wrote or restarted")
}
if _, ok := w.rollbackRecord(t); ok {
@@ -1248,7 +1248,7 @@ func TestRollbackStopsOnMalformedReceipts(t *testing.T) {
w := newWriteFixture(t, "docs")
w.configured(t)
w.putAnswerRewriter(t, edit)
- p, r := w.puts(), w.f.RestartCount("docs.oficina.works")
+ p, r := w.puts(), w.f.RestartCount(docsRoute)
err := w.rollback(true)
if !errors.Is(err, ErrStopConflict) {
t.Fatalf("err = %v, want ErrStopConflict", err)
@@ -1257,7 +1257,7 @@ func TestRollbackStopsOnMalformedReceipts(t *testing.T) {
if n := w.rollbackPuts(p); n != 1 {
t.Fatalf("rollback PUTs = %d", n)
}
- if w.f.RestartCount("docs.oficina.works") != r {
+ if w.f.RestartCount(docsRoute) != r {
t.Fatal("restarted after a malformed receipt")
}
rec, _ := w.rollbackRecord(t)
@@ -1285,7 +1285,7 @@ func TestRollbackRefusesForeignValue(t *testing.T) {
w := newWriteFixture(t, "docs")
w.configured(t)
edit(w)
- p, r := w.puts(), w.f.RestartCount("docs.oficina.works")
+ p, r := w.puts(), w.f.RestartCount(docsRoute)
for _, apply := range []bool{false, true} {
err := w.rollback(apply)
if !errors.Is(err, ErrStopForeign) {
@@ -1293,7 +1293,7 @@ func TestRollbackRefusesForeignValue(t *testing.T) {
}
noValues(t, err)
}
- if w.rollbackPuts(p) != 0 || w.f.RestartCount("docs.oficina.works") != r {
+ if w.rollbackPuts(p) != 0 || w.f.RestartCount(docsRoute) != r {
t.Fatal("a foreign value was unset or the app restarted")
}
rec, _ := w.rollbackRecord(t)
@@ -1310,7 +1310,7 @@ func TestRollbackStopsWhenPreservedKeyResealed(t *testing.T) {
w := newWriteFixture(t, "docs")
w.configured(t)
w.f.SetSecret("docs", "", "DOCS_INSTANCE_KEY")
- p, r := w.puts(), w.f.RestartCount("docs.oficina.works")
+ p, r := w.puts(), w.f.RestartCount(docsRoute)
for _, apply := range []bool{false, true} {
err := w.rollback(apply)
if !errors.Is(err, ErrStopPreserved) {
@@ -1318,7 +1318,7 @@ func TestRollbackStopsWhenPreservedKeyResealed(t *testing.T) {
}
noValues(t, err)
}
- if w.rollbackPuts(p) != 0 || w.f.RestartCount("docs.oficina.works") != r {
+ if w.rollbackPuts(p) != 0 || w.f.RestartCount(docsRoute) != r {
t.Fatal("the rollback unset or restarted past a changed preserved key")
}
if _, ours := w.stored(t); ours != [2]bool{true, true} {
@@ -1335,7 +1335,7 @@ func TestRollbackStopsWhenPreservedKeyResealed(t *testing.T) {
// nothing. The error names what differs (want), never a value.
func (w *writeFixture) rollbackRefused(t *testing.T, code, want string) {
t.Helper()
- p, r := w.puts(), w.f.RestartCount("docs.oficina.works")
+ p, r := w.puts(), w.f.RestartCount(docsRoute)
for _, apply := range []bool{false, true} {
err := w.rollback(apply)
if !errors.Is(err, ErrStopPreserved) {
@@ -1346,7 +1346,7 @@ func (w *writeFixture) rollbackRefused(t *testing.T, code, want string) {
}
noValues(t, err)
}
- if w.rollbackPuts(p) != 0 || w.f.RestartCount("docs.oficina.works") != r {
+ if w.rollbackPuts(p) != 0 || w.f.RestartCount(docsRoute) != r {
t.Fatal("the rollback unset or restarted past a change")
}
rec, _ := w.rollbackRecord(t)
@@ -1380,7 +1380,7 @@ func TestRollbackStopsWhenPreservedChangedInAnotherLayer(t *testing.T) {
"secret resealed in the environment": {func(w *writeFixture) { w.f.SetSecret("docs", "production", "DOCS_DEK") }, "changed:DOCS_DEK"},
"secret gone from the environment": {func(w *writeFixture) { w.f.Unset("docs", "production", "DOCS_DEK") }, "gone:DOCS_DEK"},
"overlay covers a preserved key": {func(w *writeFixture) {
- w.f.SetOverlay("docs", "docs.oficina.works", "DOCS_INSTANCE_KEY", "covered")
+ w.f.SetOverlay("docs", docsRoute, "DOCS_INSTANCE_KEY", "covered")
}, "from:DOCS_INSTANCE_KEY"},
}
for name, tc := range cases {
@@ -1431,6 +1431,51 @@ func TestRollbackStopsWhenIdentityChanged(t *testing.T) {
}
}
+// The canonical domain no longer resolving to the baseline's record stops
+// a rollback as a changed identity, with nothing unset.
+func TestRollbackStopsWhenCanonicalDomainMoves(t *testing.T) {
+ cases := map[string]struct {
+ edit func(w *writeFixture)
+ want string
+ }{
+ "claim detached": {func(w *writeFixture) { w.f.DetachDomain("docs", "docs.oficina.works") }, "domain-missing"},
+ "claim re-pointed": {func(w *writeFixture) {
+ in := fixtureInstance(w.app)
+ in.Host = "docs-2.bds.oncarlos.com"
+ w.f.AddInstance(in)
+ w.f.AttachDomain("docs", "docs.oficina.works", in.Host, "live")
+ }, "identity-alias"},
+ "route to a missing record": {func(w *writeFixture) {
+ w.f.AttachDomain("docs", "docs.oficina.works", "gone-docs.bds.oncarlos.com", "live")
+ }, "instance-missing"},
+ }
+ for name, tc := range cases {
+ t.Run(name, func(t *testing.T) {
+ w := newWriteFixture(t, "docs")
+ w.configured(t)
+ tc.edit(w)
+ w.rollbackRefused(t, "identity-changed", tc.want)
+ if _, ours := w.stored(t); ours != [2]bool{true, true} {
+ t.Fatal("the keys were removed")
+ }
+ })
+ }
+}
+
+// A claim that is merely not live still names the baseline's record: the
+// rollback goes on rather than stopping for good.
+func TestRollbackGoesOnWhenCanonicalDomainNotLive(t *testing.T) {
+ w := newWriteFixture(t, "docs")
+ w.configured(t)
+ w.f.AttachDomain("docs", "docs.oficina.works", docsRoute, "checking")
+ if err := w.rollback(true); err != nil {
+ t.Fatalf("RollbackAgentKeys: %v", err)
+ }
+ if present, _ := w.stored(t); present != [2]bool{} {
+ t.Fatalf("keys still present %v", present)
+ }
+}
+
// A change that lands while the unset is in flight, in a layer the unset
// does not touch, is caught before the restart: the unset succeeds, the
// restart never runs, and the rollback stops.
@@ -1452,7 +1497,7 @@ func TestRollbackStopsBeforeRestartOnChangeDuringUnset(t *testing.T) {
w.f.SetSecret("docs", "production", "DOCS_DEK")
w.bindTo("production")
w.configured(t)
- p, r := w.puts(), w.f.RestartCount("docs.oficina.works")
+ p, r := w.puts(), w.f.RestartCount(docsRoute)
w.f.BeforePut = once(func() { tc.edit(w) })
err := w.rollback(true)
if !errors.Is(err, ErrStopPreserved) || !strings.Contains(err.Error(), tc.want) {
@@ -1465,7 +1510,7 @@ func TestRollbackStopsBeforeRestartOnChangeDuringUnset(t *testing.T) {
if present, _ := w.stored(t); present != [2]bool{} {
t.Fatal("the unset did not land")
}
- if w.f.RestartCount("docs.oficina.works") != r {
+ if w.f.RestartCount(docsRoute) != r {
t.Fatal("restarted past a change made during the unset")
}
rec, _ := w.rollbackRecord(t)
@@ -1475,7 +1520,7 @@ func TestRollbackStopsBeforeRestartOnChangeDuringUnset(t *testing.T) {
if err := w.rollback(true); !errors.Is(err, ErrStopPreserved) {
t.Fatalf("resume: err = %v", err)
}
- if w.f.RestartCount("docs.oficina.works") != r {
+ if w.f.RestartCount(docsRoute) != r {
t.Fatal("a resume restarted")
}
})
@@ -1549,14 +1594,14 @@ func TestRollbackCrashAfterUnsetResumesToRestart(t *testing.T) {
if err := w.s.SaveRollback(ctx, RollbackRecord{App: "docs", State: "unset"}); err != nil {
t.Fatal(err)
}
- p, r := w.puts(), w.f.RestartCount("docs.oficina.works")
+ p, r := w.puts(), w.f.RestartCount(docsRoute)
if err := w.rollback(true); err != nil {
t.Fatalf("resume: %v", err)
}
if w.rollbackPuts(p) != 0 {
t.Fatal("the resume sent the unset again")
}
- if w.f.RestartCount("docs.oficina.works") != r+1 {
+ if w.f.RestartCount(docsRoute) != r+1 {
t.Fatal("the resume did not restart")
}
if rec, _ := w.rollbackRecord(t); rec.State != "restarted" {
@@ -1600,7 +1645,7 @@ func TestRollbackUsesScopedDryRun(t *testing.T) {
w.f.Own("docs", "acme-docs", "alta")
w.configured(t)
start := len(w.f.Requests())
- r := w.f.RestartCount("docs.oficina.works")
+ r := w.f.RestartCount(docsRoute)
if err := w.rollback(true); err != nil {
t.Fatalf("RollbackAgentKeys: %v", err)
}
@@ -1615,7 +1660,7 @@ func TestRollbackUsesScopedDryRun(t *testing.T) {
if strings.Join(doors, "|") != strings.Join(want, "|") {
t.Fatalf("doors %q, want %q", doors, want)
}
- if w.f.RestartCount("docs.oficina.works") != r+1 {
+ if w.f.RestartCount(docsRoute) != r+1 {
t.Fatal("the canonical host did not restart once")
}
w.noRestarts(t, "staging.docs.example")
@@ -1627,12 +1672,12 @@ func TestRollbackUsesScopedDryRun(t *testing.T) {
w2.dryRunRewriter(t, func(rt []map[string]any) []map[string]any {
return append(rt, map[string]any{"host": "staging.docs.example", "hibernate": false})
})
- r2 := w2.f.RestartCount("docs.oficina.works")
+ r2 := w2.f.RestartCount(docsRoute)
err := w2.rollback(true)
if err == nil || !strings.Contains(err.Error(), "restart-scope-2") {
t.Fatalf("err = %v, want restart-scope-2", err)
}
- if w2.f.RestartCount("docs.oficina.works") != r2 || w2.f.AppWideRestarts() != 0 {
+ if w2.f.RestartCount(docsRoute) != r2 || w2.f.AppWideRestarts() != 0 {
t.Fatal("restarted past a wider dry run")
}
if rec, _ := w2.rollbackRecord(t); rec.State != "unset" || rec.Code != "restart-failed" {
diff --git a/carlosop/client.go b/carlosop/client.go
index b656860..2ec9d98 100644
--- a/carlosop/client.go
+++ b/carlosop/client.go
@@ -114,11 +114,28 @@ type Receipt struct {
// Instance is the part of an instance record adoption compares. Move,
// ReplicaAssignment and Seed are the record's JSON as stored, nil when
// absent.
+//
+// The record's public_host is not read. It is the platform's display
+// name for the host under the apps domain (the account's namespace name
+// in place of its sqid, carlos/platform internal/console/canonical.go),
+// never a custom domain: an attached domain is a claim, read by Domains.
type Instance struct {
- Host, PublicHost, Account, App, Slug, Environment, Channel, Region string
- CreatedAt time.Time
- RecordSeq uint64
- Move, ReplicaAssignment, Seed json.RawMessage
+ Host, Account, App, Slug, Environment, Channel, Region string
+ CreatedAt time.Time
+ RecordSeq uint64
+ Move, ReplicaAssignment, Seed json.RawMessage
+}
+
+// Domain is one row of an app's hostname claims, as GET /domains lists
+// them (`carlos domains list`): Host is served by the instance record
+// whose host is Route. State is the console's derived lifecycle word,
+// "live" when the host points at the platform and is served over HTTPS
+// with a current certificate; "" from a console that predates it.
+// Instances marks an instance catch-all's own row, and Via names the
+// catch-all a derived row came from: neither is a claim of its own.
+type Domain struct {
+ Host, Route, State, Via string
+ Instances bool
}
// PutRequest is one conditional write. Set holds plain values only; the
@@ -530,7 +547,6 @@ func (c *Client) Put(ctx context.Context, app string, r PutRequest) (Receipt, er
type wireInstance struct {
Host string `json:"host"`
- PublicHost string `json:"public_host"`
Account string `json:"account"`
App string `json:"app"`
Slug string `json:"slug"`
@@ -555,7 +571,7 @@ func (c *Client) instance(door, app string, w wireInstance) (Instance, error) {
if w.Host == "" || w.App != app || w.Account != c.account {
return Instance{}, malformed(door, "a record of another app or account")
}
- return Instance{Host: w.Host, PublicHost: w.PublicHost, Account: w.Account, App: w.App, Slug: w.Slug,
+ return Instance{Host: w.Host, Account: w.Account, App: w.App, Slug: w.Slug,
Environment: w.Environment, Channel: w.Channel, Region: w.Region, CreatedAt: w.CreatedAt, RecordSeq: w.RecordSeq,
Move: rawOrNil(w.Move), ReplicaAssignment: rawOrNil(w.ReplicaAssignment), Seed: rawOrNil(w.Seed)}, nil
}
@@ -626,6 +642,40 @@ func (c *Client) Instance(ctx context.Context, app, host string) (Instance, erro
return c.instance(door, app, w)
}
+// Domains lists app's hostname claims through the door `carlos domains
+// list` reads (carlos/platform internal/console/apidomains.go,
+// handleAPIDomainList). Its route admits the Publish and Instance roles
+// and so, as every route does, Admin: the same credential that lists the
+// instances reads it. The door is one unpaged list; an answer with no
+// list, or a null one, is refused rather than read as "no domains", and
+// so is a row with no host.
+func (c *Client) Domains(ctx context.Context, app string) ([]Domain, error) {
+ const door = "GET /domains"
+ var w struct {
+ Domains *[]struct {
+ Host string `json:"host"`
+ Route string `json:"route"`
+ State string `json:"state"`
+ Via string `json:"via"`
+ Instances bool `json:"instances"`
+ } `json:"domains"`
+ }
+ if err := c.do(ctx, http.MethodGet, app, door, "/domains", nil, &w); err != nil {
+ return nil, as(err, notFound)
+ }
+ if w.Domains == nil {
+ return nil, malformed(door, "no domain list")
+ }
+ out := make([]Domain, 0, len(*w.Domains))
+ for _, d := range *w.Domains {
+ if d.Host == "" {
+ return nil, malformed(door, "a row with no host")
+ }
+ out = append(out, Domain{Host: d.Host, Route: d.Route, State: d.State, Via: d.Via, Instances: d.Instances})
+ }
+ return out, nil
+}
+
// RestartHost asks the narrowed restart door to cycle exactly host, or
// with dryRun to say what it would cycle. It never calls the app-wide
// door: a 404 is ErrNoScopedRestart (a console that predates the narrowed
diff --git a/carlosop/client_test.go b/carlosop/client_test.go
index b46ac1b..eb6a9d5 100644
--- a/carlosop/client_test.go
+++ b/carlosop/client_test.go
@@ -33,7 +33,7 @@ func newFake(t *testing.T) (*fakecarlos.Fake, *carlosop.Client) {
func canonical(f *fakecarlos.Fake, app string) string {
host := "oficina-" + app + "." + acct + ".oncarlos.com"
- f.AddInstance(carlosop.Instance{Host: host, PublicHost: app + ".oficina.works", Account: acct, App: app, Slug: "s-" + app,
+ f.AddInstance(carlosop.Instance{Host: host, Account: acct, App: app, Slug: "s-" + app,
Channel: "stable", Region: "eu", CreatedAt: time.Date(2026, 10, 1, 0, 0, 0, 0, time.UTC), RecordSeq: 3})
return host
}
@@ -289,6 +289,8 @@ func TestErrorsCarryNoTokenOrValue(t *testing.T) {
errs = append(errs, err)
_, err = c.RestartHost(ctx, "docs", "oficina-docs.bds.oncarlos.com", true)
errs = append(errs, err)
+ _, err = c.Domains(ctx, "docs")
+ errs = append(errs, err)
c.Close()
for i, err := range errs {
if err == nil {
@@ -309,6 +311,7 @@ func TestErrorsCarryNoTokenOrValue(t *testing.T) {
for i, call := range []func() error{
func() error { _, err := rc.Config(ctx, "docs", ""); return err },
func() error { _, err := rc.Instances(ctx, "docs"); return err },
+ func() error { _, err := rc.Domains(ctx, "docs"); return err },
func() error { _, err := rc.RestartHost(ctx, "docs", "oficina-docs.bds.oncarlos.com", true); return err },
} {
if err := call(); err == nil || strings.Contains(err.Error(), token) || strings.Contains(err.Error(), value) {
@@ -380,6 +383,7 @@ func TestReadsRefuseMalformedAnswers(t *testing.T) {
instances := func(c *carlosop.Client) error { _, err := c.Instances(ctx, "docs"); return err }
instance := func(c *carlosop.Client) error { _, err := c.Instance(ctx, "docs", host); return err }
restart := func(c *carlosop.Client) error { _, err := c.RestartHost(ctx, "docs", host, true); return err }
+ domains := func(c *carlosop.Client) error { _, err := c.Domains(ctx, "docs"); return err }
put := func(c *carlosop.Client) error {
_, err := c.Put(ctx, "docs", carlosop.PutRequest{Set: map[string]string{"K": "v"}, IfVersion: v1})
return err
@@ -406,6 +410,10 @@ func TestReadsRefuseMalformedAnswers(t *testing.T) {
{"restart of the whole app", restart, map[string]any{"scope": map[string]any{"kind": "app", "value": ""}, "dry_run": true, "routes": []any{}}, nil},
{"instance list missing", instances, map[string]any{"total": 0}, nil},
{"instance list null", instances, map[string]any{"instances": nil, "total": 0}, nil},
+ {"domain list missing", domains, map[string]any{"deployment": map[string]any{}}, nil},
+ {"domain list null", domains, map[string]any{"domains": nil}, nil},
+ {"domain row with no host", domains, map[string]any{"domains": []any{map[string]any{"route": host, "state": "live"}}}, nil},
+ {"domain row with a non-string state", domains, map[string]any{"domains": []any{map[string]any{"host": "docs.oficina.works", "route": host, "state": 1}}}, nil},
{"put with no receipt", put, map[string]any{"result": "ok", "removed": 0}, layerAnswer},
{"put receipt for another bundle", put, map[string]any{"result": "ok", "receipt": func() map[string]any {
r := maps.Clone(receipt)
@@ -485,7 +493,7 @@ func TestInstancesFollowsCursor(t *testing.T) {
}
host := canonical(f, "docs")
in, err := c.Instance(ctx, "docs", host)
- if err != nil || in.Slug != "s-docs" || in.PublicHost != "docs.oficina.works" || in.RecordSeq != 3 || in.Move != nil {
+ if err != nil || in.Slug != "s-docs" || in.RecordSeq != 3 || in.Move != nil {
t.Fatalf("Instance not decoded: %v", err)
}
if _, err := c.Instance(ctx, "docs", "nope.bds.oncarlos.com"); !errors.Is(err, carlosop.ErrNotFound) {
@@ -493,6 +501,69 @@ func TestInstancesFollowsCursor(t *testing.T) {
}
}
+// GET /domains is the door `carlos domains list` reads: the app's claims,
+// each with the route it sends traffic to and the console's derived state.
+func TestDomainsListsClaimsWithRouteAndState(t *testing.T) {
+ f, c := newFake(t)
+ host := canonical(f, "docs")
+ f.AddInstance(carlosop.Instance{Host: "lagged-docs.bds.oncarlos.com", Account: acct, App: "docs", Environment: "lagged"})
+ f.AttachDomain("docs", "lagged.docs.oficina.works", "lagged-docs.bds.oncarlos.com", "live")
+ f.AttachDomain("docs", "docs.oficina.works", host, "live")
+ f.AttachDomain("docs", "www.docs.oficina.works", host, "pending-dns")
+ f.AddInstance(carlosop.Instance{Host: "x-sheets.bds.oncarlos.com", Account: acct, App: "sheets"})
+ f.AttachDomain("sheets", "sheets.oficina.works", "x-sheets.bds.oncarlos.com", "live")
+ got, err := c.Domains(ctx, "docs")
+ if err != nil {
+ t.Fatalf("Domains: %v", err)
+ }
+ want := []carlosop.Domain{
+ {Host: "docs.oficina.works", Route: host, State: "live"},
+ {Host: "lagged.docs.oficina.works", Route: "lagged-docs.bds.oncarlos.com", State: "live"},
+ {Host: "www.docs.oficina.works", Route: host, State: "pending-dns"},
+ }
+ if !slices.Equal(got, want) {
+ t.Fatalf("Domains = %+v, want %+v", got, want)
+ }
+ if r := f.Requests(); r[len(r)-1] != "GET /domains" {
+ t.Fatalf("Domains read %q", r[len(r)-1])
+ }
+ if _, err := c.Domains(ctx, "nope"); !errors.Is(err, carlosop.ErrNotFound) {
+ t.Fatalf("unknown app: want ErrNotFound, got %v", err)
+ }
+}
+
+// A catch-all's own row and the rows derived from it are reported as the
+// console marks them, so a caller can tell them from a claim.
+func TestDomainsKeepsCatchallMarks(t *testing.T) {
+ srv, log := rawConsole(t, func(w http.ResponseWriter, r *http.Request) {
+ writeJSON(w, 200, map[string]any{"domains": []any{
+ map[string]any{"host": "*.docs.example", "route": "", "state": "live", "instances": true, "verified": true},
+ map[string]any{"host": "a.docs.example", "route": "a-docs.bds.oncarlos.com", "state": "live", "via": "*.docs.example", "verified": true},
+ }, "deployment": map[string]any{"managed_domains": true}})
+ })
+ c := carlosop.New(srv.URL, acct, []byte("svc_token"))
+ defer c.Close()
+ got, err := c.Domains(ctx, "docs")
+ if err != nil || len(got) != 2 || !got[0].Instances || got[1].Via != "*.docs.example" {
+ t.Fatalf("Domains = %+v, %v", got, err)
+ }
+ if l := *log; len(l) != 1 || l[0].Method != http.MethodGet || l[0].Path != "/api/cli/apps/bds/docs/domains" || l[0].Query != "" {
+ t.Fatalf("Domains sent %+v", l)
+ }
+}
+
+func TestDomainsAcceptsAnEmptyList(t *testing.T) {
+ srv, _ := rawConsole(t, func(w http.ResponseWriter, r *http.Request) {
+ writeJSON(w, 200, map[string]any{"domains": []any{}})
+ })
+ c := carlosop.New(srv.URL, acct, []byte("svc_token"))
+ defer c.Close()
+ got, err := c.Domains(ctx, "docs")
+ if err != nil || got == nil || len(got) != 0 {
+ t.Fatalf("an empty list: %v, %v", got, err)
+ }
+}
+
func TestFakeLostAnswerLandsAndResealMovesDigest(t *testing.T) {
f, c := newFake(t)
f.SetSecret("docs", "", "DOCS_DEK")
diff --git a/carlosop/fakecarlos/fakecarlos.go b/carlosop/fakecarlos/fakecarlos.go
index cde85f2..b90e40b 100644
--- a/carlosop/fakecarlos/fakecarlos.go
+++ b/carlosop/fakecarlos/fakecarlos.go
@@ -13,6 +13,10 @@
// owned environment never folds the default in. Instance records are the
// routes the restart door resolves.
//
+// Hostname claims (AttachDomain) are listed as GET /domains lists them:
+// the canonical name of an app is a claim routed to one of its records,
+// never a field of the record.
+//
// Hooks for adverse tests: BeforePut, LoseNextAnswer, SetSecret,
// PlatformWrite, NoConditional, FailRestart, NoScopedRestart, and the
// counters RestartCount and AppWideRestarts.
@@ -59,8 +63,12 @@ type app struct {
envs map[string][]byte // name -> stored bytes
overlays map[string][]byte // host -> stored bytes
recs map[string]carlosop.Instance
+ domains map[string]domain // host -> claim
}
+// domain is one hostname claim: host served by the record at route.
+type domain struct{ route, state string }
+
// Fake is the console.
type Fake struct {
mu sync.Mutex
@@ -104,7 +112,7 @@ func (f *Fake) Token() []byte { return []byte(f.token) }
func (f *Fake) app(name string) *app {
a := f.apps[name]
if a == nil {
- a = &app{envs: map[string][]byte{}, overlays: map[string][]byte{}, recs: map[string]carlosop.Instance{}}
+ a = &app{envs: map[string][]byte{}, overlays: map[string][]byte{}, recs: map[string]carlosop.Instance{}, domains: map[string]domain{}}
f.apps[name] = a
}
return a
@@ -233,6 +241,24 @@ func (f *Fake) AddInstance(in carlosop.Instance) {
f.app(in.App).recs[in.Host] = in
}
+// AttachDomain claims host for appName, served by the record at route,
+// in state (the console's derived word: "live", "pending-dns",
+// "unverified" and so on). Claims are keyed by host, as the platform's
+// are: attaching host again re-points it. Nothing checks that route is
+// a record, since the platform's list does not either.
+func (f *Fake) AttachDomain(appName, host, route, state string) {
+ f.mu.Lock()
+ defer f.mu.Unlock()
+ f.app(appName).domains[host] = domain{route: route, state: state}
+}
+
+// DetachDomain drops appName's claim on host.
+func (f *Fake) DetachDomain(appName, host string) {
+ f.mu.Lock()
+ defer f.mu.Unlock()
+ delete(f.app(appName).domains, host)
+}
+
// Layer is a copy of a bundle's vars and its version; ok is false when the
// bundle is absent.
func (f *Fake) Layer(appName, env string) (map[string]Var, string, bool) {
@@ -330,6 +356,8 @@ func (f *Fake) serve(w http.ResponseWriter, r *http.Request) {
f.putConfig(w, r, appName, a, raw)
case r.Method == http.MethodGet && rest == "/instances":
f.list(w, r, a)
+ case r.Method == http.MethodGet && rest == "/domains":
+ f.domainList(w, a)
case r.Method == http.MethodGet && strings.HasPrefix(rest, "/instances/"):
in, ok := a.recs[strings.TrimPrefix(rest, "/instances/")]
if !ok {
@@ -352,7 +380,7 @@ func (f *Fake) serve(w http.ResponseWriter, r *http.Request) {
func record(in carlosop.Instance) map[string]any {
out := map[string]any{"schema": 1, "host": in.Host, "slug": in.Slug, "app": in.App, "account": in.Account,
"channel": in.Channel, "created_at": in.CreatedAt, "gated": false}
- for k, v := range map[string]string{"public_host": in.PublicHost, "environment": in.Environment, "region": in.Region} {
+ for k, v := range map[string]string{"environment": in.Environment, "region": in.Region} {
if v != "" {
out[k] = v
}
@@ -605,6 +633,28 @@ func (f *Fake) list(w http.ResponseWriter, r *http.Request, a *app) {
writeJSON(w, 200, map[string]any{"instances": rows, "truncated": false, "total": len(hosts), "next_cursor": next})
}
+// domainList is handleAPIDomainList's answer for plain claims: host
+// sorted, each with the fields the platform always sends, and the
+// self-describing deployment block.
+func (f *Fake) domainList(w http.ResponseWriter, a *app) {
+ hosts := make([]string, 0, len(a.domains))
+ for h := range a.domains {
+ hosts = append(hosts, h)
+ }
+ sort.Strings(hosts)
+ rows := make([]map[string]any, 0, len(hosts))
+ for _, h := range hosts {
+ d := a.domains[h]
+ status := "pending"
+ if d.state == "live" {
+ status = "live"
+ }
+ rows = append(rows, map[string]any{"host": h, "route": d.route, "status": status, "state": d.state,
+ "wildcard": false, "catchall": false, "verified": d.state != "unverified"})
+ }
+ writeJSON(w, 200, map[string]any{"domains": rows, "deployment": map[string]any{"managed_domains": true}})
+}
+
func (f *Fake) restartScope(w http.ResponseWriter, r *http.Request, appName string, a *app, raw []byte) {
if f.noScope {
http.NotFound(w, r)
diff --git a/cmd/alta-adopt/main_test.go b/cmd/alta-adopt/main_test.go
index 0401a23..c5e6989 100644
--- a/cmd/alta-adopt/main_test.go
+++ b/cmd/alta-adopt/main_test.go
@@ -103,10 +103,13 @@ func newRig(t *testing.T) *rig {
r.carlos.SetVar(a.Slug, "", p+"_ORIGIN", plainCanary+a.Slug)
r.carlos.SetSecret(a.Slug, "", p+"_INSTANCE_KEY")
r.carlos.AddInstance(carlosop.Instance{
- Host: adopt.CanonicalHost(a), App: a.Slug, Slug: "s-" + a.Slug, Channel: "stable", Region: "eu",
+ Host: routeOf(a), App: a.Slug, Slug: "s-" + a.Slug, Channel: "stable", Region: "eu",
CreatedAt: time.Date(2026, 3, 1, 0, 0, 0, 0, time.UTC), RecordSeq: 4,
ReplicaAssignment: json.RawMessage(`{"boxes":["b1"]}`),
})
+ // The canonical name is a domain claimed for the record, as in
+ // production.
+ r.carlos.AttachDomain(a.Slug, adopt.CanonicalHost(a), routeOf(a), "live")
}
site := httptest.NewTLSServer(http.HandlerFunc(r.site))
@@ -182,6 +185,10 @@ func (r *rig) tick(d time.Duration) {
// site is the six apps' origins. An app answers agent-access's challenge
// only once a restart has loaded both of its agent keys.
+// routeOf is the host of a's canonical record: the route its canonical
+// domain is claimed for.
+func routeOf(a provision.App) string { return a.Slug + "." + account + ".oncarlos.com" }
+
func (r *rig) site(w http.ResponseWriter, req *http.Request) {
host, _, err := net.SplitHostPort(req.Host)
if err != nil {
@@ -223,7 +230,7 @@ func (r *rig) serving(slug string) bool {
if !ok {
return false
}
- if n := r.carlos.RestartCount(adopt.CanonicalHost(a)); n != r.seen[slug] {
+ if n := r.carlos.RestartCount(routeOf(a)); n != r.seen[slug] {
vars, _, _ := r.carlos.Layer(slug, "")
keys := adopt.AgentKeys(a)
_, i := vars[keys[0]]
@@ -307,7 +314,7 @@ func (r *rig) writes() writes {
}
}
for _, a := range provision.Apps {
- w.restarts += int64(r.carlos.RestartCount(adopt.CanonicalHost(a)))
+ w.restarts += int64(r.carlos.RestartCount(routeOf(a)))
}
w.rows, w.exists = r.rows()
return w
@@ -564,7 +571,7 @@ func TestWritesNeedApply(t *testing.T) {
t.Fatal("the app-wide restart was called")
}
for _, a := range provision.Apps {
- if a.Slug != adopt.CanaryApp && r.carlos.RestartCount(adopt.CanonicalHost(a)) != 0 {
+ if a.Slug != adopt.CanaryApp && r.carlos.RestartCount(routeOf(a)) != 0 {
t.Fatalf("%s restarted", a.Slug)
}
}
@@ -815,9 +822,9 @@ func TestConfigureResumesDeliveryCheck(t *testing.T) {
t.Fatal("setup: the check is still there")
}
docs, _ := provision.AppBySlug("docs")
- puts, restarts := r.writes().puts, r.carlos.RestartCount(adopt.CanonicalHost(docs))
+ puts, restarts := r.writes().puts, r.carlos.RestartCount(routeOf(docs))
r.configured("docs")
- if r.writes().puts != puts || r.carlos.RestartCount(adopt.CanonicalHost(docs)) != restarts {
+ if r.writes().puts != puts || r.carlos.RestartCount(routeOf(docs)) != restarts {
t.Fatal("the resume wrote or restarted again")
}
}