Merge branch 'adopt-approved-redeploy' into main
Merge adopt-approved-redeploy: re-check an app after an approved redeploy configure can record a fresh delivery check, without writing or restarting, when the app moved to a release Paul approved. Paul approved the design amendment 2026-11-19; Astra reviewed; CI passed.
8 files changed,
+668
−10
adopt/binding.go+9 −2adopt/delivery.go+7 −0adopt/deliverycheck.go+48 −1adopt/observer.go+5 −2adopt/redeploy.go+135 −0adopt/redeploy_test.go+336 −0adopt/types.go+26 −0cmd/alta-adopt/main_test.go+102 −5
CI passed — run details
CI log
=== vet === go vet ./... === fmt === === test === CGO_ENABLED=0 go test ./... ok amadan.net/oficina/alta/adopt 19.412s ok amadan.net/oficina/alta/carlosop (cached) ? amadan.net/oficina/alta/carlosop/fakecarlos [no test files] ok amadan.net/oficina/alta/cmd/alta (cached) ok amadan.net/oficina/alta/cmd/alta-adopt 36.945s ok amadan.net/oficina/alta/console (cached) ? amadan.net/oficina/alta/console/fakeconsole [no test files] ok amadan.net/oficina/alta/homeop (cached) ok amadan.net/oficina/alta/homeop/fakehome (cached) ok amadan.net/oficina/alta/internal/web (cached) ok amadan.net/oficina/alta/provision (cached) === compat === cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./... ok amadan.net/oficina/home/altacompat 0.566s
diff --git a/adopt/binding.go b/adopt/binding.go| index c01ea02..3e04d69 100644 |
| --- a/adopt/binding.go |
| +++ b/adopt/binding.go |
| @@ -37,7 +37,8 @@ type BindingInput struct { |
| // 5. the team SQID, the issuer, the artifact SHA-256 and the version; |
| // 6. the before, after and now delivery observations; |
| // 7. the delivery check: [app, identity, delivery, after version, |
| -// time]. |
| +// time], with the redeploy (from, to, artifact, reason) as a sixth |
| +// element only when the check records an approved redeploy. |
| // |
| // That is the spec's list (Home implementation/existing-team-adoption.md, |
| // "Compute environment_binding") plus the delivery check, which the 522 |
| @@ -51,6 +52,12 @@ type BindingInput struct { |
| // digests it covers: it is never printed or logged. |
| func EnvironmentBinding(in BindingInput) string { |
| c := in.Check |
| + check := []any{c.App, c.Identity, c.Delivery, c.AfterVersion, c.At} |
| + if c.Redeploy != nil { |
| + // A check on a redeployed release commits to the redeploy too; |
| + // one on the baseline's release binds exactly as before. |
| + check = append(check, c.Redeploy) |
| + } |
| parts := []any{ |
| bindingContext, |
| in.Before, in.After, |
| @@ -58,7 +65,7 @@ func EnvironmentBinding(in BindingInput) string { |
| layers(in.BeforeLayers), layers(in.AfterLayers), |
| in.TeamSQID, in.Issuer, in.ArtifactSHA256, in.Version, |
| in.BeforeDelivery, in.AfterDelivery, in.NowDelivery, |
| - []any{c.App, c.Identity, c.Delivery, c.AfterVersion, c.At}, |
| + check, |
| } |
| // Every part is a string, a time, a map of strings or a struct of |
| // those: Marshal cannot fail on them. |
diff --git a/adopt/delivery.go b/adopt/delivery.go| index a44394e..a26bcde 100644 |
| --- a/adopt/delivery.go |
| +++ b/adopt/delivery.go |
| @@ -257,6 +257,13 @@ func Delivered(app provision.App, before, now Delivery) error { |
| if err := sameServing(before, now); err != nil { |
| return err |
| } |
| + return opsMoved(app, before, now) |
| +} |
| + |
| +// opsMoved is Delivered's operations-door rule: the door answered before |
| +// as BaselineOps(app) says, and now gives agent-access's own answer as |
| +// app's must. |
| +func opsMoved(app provision.App, before, now Delivery) error { |
| if before.Ops != BaselineOps(app) { |
| return errors.New("adopt: the operations door did not answer before the change as this app's does") |
| } |
diff --git a/adopt/deliverycheck.go b/adopt/deliverycheck.go| index 621be89..b151749 100644 |
| --- a/adopt/deliverycheck.go |
| +++ b/adopt/deliverycheck.go |
| @@ -47,6 +47,22 @@ import ( |
| // The reviewed release is checked before anything is written too: |
| // configure's write refuses it (WriteAgentKeys), so this check only |
| // catches a release that changed after the write. |
| +// |
| +// One release change is not refused: a redeploy Paul approved, after the |
| +// write landed and the after snapshot was captured (Home |
| +// existing-team-adoption.md, "Approved redeploy after configure"). When |
| +// the served release (X-Carlos-Version) is no longer the baseline's, the |
| +// check is made against the new release instead, and passes only if |
| +// redeployCodes finds nothing: the release is the approved artifact, the |
| +// body and header name it, /healthz is 200 and the operations door gives |
| +// agent-access's answer; the write landed and both agent keys hold its |
| +// sent values in the write layer; everything else is preserved from the |
| +// baseline and equals the after snapshot; the identity is unchanged. |
| +// The check it records carries Redeploy, from the baseline's release to |
| +// the new one, which the gate holds it to. Any code refuses with today's |
| +// check-not-delivered refusal, the codes after it, and records nothing. |
| +// This path reads only: like every check, it writes nothing to CARLOS |
| +// and restarts nothing. |
| func CheckDelivery(ctx context.Context, s *Store, c *carlosop.Client, h *http.Client, app provision.App, artifact string) error { |
| if s == nil { |
| return errors.New("adopt: no adoption journal") |
| @@ -73,7 +89,10 @@ func CheckDelivery(ctx context.Context, s *Store, c *carlosop.Client, h *http.Cl |
| return err |
| } |
| if err := Delivered(app, base.Delivery, fresh.Delivery); err != nil { |
| - return fmt.Errorf("adopt: check-not-delivered: %w", err) |
| + if !releaseChanged(base.Delivery, fresh.Delivery) { |
| + return fmt.Errorf("adopt: check-not-delivered: %w", err) |
| + } |
| + return checkRedeploy(ctx, s, app, base, after, fresh, artifact, err) |
| } |
| if code := ReviewedRelease(fresh.Delivery, artifact); code != "" { |
| return errors.New("adopt: check-" + code) |
| @@ -98,6 +117,34 @@ func CheckDelivery(ctx context.Context, s *Store, c *carlosop.Client, h *http.Cl |
| }) |
| } |
| +// checkRedeploy is CheckDelivery's approved-redeploy path, for a fresh |
| +// observation whose release is not the baseline's. refused is Delivered's |
| +// error, today's refusal, which leads any refusal here. |
| +func checkRedeploy(ctx context.Context, s *Store, app provision.App, base, after, fresh Snapshot, artifact string, refused error) error { |
| + w, landed, err := s.Write(ctx, app.Slug) |
| + if err != nil { |
| + return err |
| + } |
| + if codes := redeployCodes(app, base, after, fresh, w, landed, artifact); len(codes) > 0 { |
| + for i, code := range codes { |
| + codes[i] = "redeploy-" + code |
| + } |
| + return fmt.Errorf("adopt: check-not-delivered: %w (%s)", refused, strings.Join(codes, ", ")) |
| + } |
| + return s.SaveDeliveryCheck(ctx, DeliveryCheck{ |
| + App: app.Slug, |
| + Identity: fresh.Identity, Delivery: fresh.Delivery, |
| + AfterVersion: after.Layer.Version, |
| + At: time.Now().UTC(), |
| + Redeploy: &Redeploy{ |
| + From: Release{base.Delivery.Version, base.Delivery.Header}, |
| + To: Release{fresh.Delivery.Version, fresh.Delivery.Header}, |
| + Artifact: artifact, |
| + Reason: RedeployApproved, |
| + }, |
| + }) |
| +} |
| + |
| // ReviewedRelease is "" when d serves the reviewed release: artifact is |
| // 64 lowercase hex (artifact-unreviewed otherwise) and the SHA-256 of |
| // d's X-Carlos-Version is artifact (artifact-mismatch otherwise). It is |
diff --git a/adopt/observer.go b/adopt/observer.go| index f6d0465..46148bb 100644 |
| --- a/adopt/observer.go |
| +++ b/adopt/observer.go |
| @@ -91,7 +91,10 @@ func (o *Observer) now() time.Time { |
| // write layer's, and its delivered version and header are the fresh |
| // ones (delivery-check-superseded). There is no wall-clock limit; |
| // - delivery: the fresh probe passes Delivered against the baseline |
| -// (not-delivered), the version body and X-Carlos-Version name the |
| +// (not-delivered); or, when the delivery check records an approved |
| +// redeploy, it is that redeploy, from the baseline's release to the |
| +// check's, under the approved artifact, and the fresh probe passes |
| +// redelivered (not-delivered: checkDelivered); the version body and X-Carlos-Version name the |
| // same release, SameRelease (version-header-mismatch), and Home |
| // admits the body |
| // (version-unacceptable); |
| @@ -151,7 +154,7 @@ func (o *Observer) Observe(ctx context.Context, app, teamSQID string) (provision |
| add("delivery-check-superseded") |
| } |
| d := fresh.Delivery |
| - if Delivered(a, ev.base.Delivery, d) != nil { |
| + if checkDelivered(a, ev.base.Delivery, chk, ev.artifact, d) != nil { |
| add("not-delivered") |
| } |
| if !SameRelease(d.Version, d.Header) { |
diff --git a/adopt/redeploy.go b/adopt/redeploy.go| new file mode 100644 |
| index 0000000..c3281e0 |
| --- /dev/null |
| +++ b/adopt/redeploy.go |
| @@ -0,0 +1,135 @@ |
| +// This file is the delivery check's approved-redeploy path: an app |
| +// redeployed, after its write landed and its after snapshot was captured, |
| +// to a release Paul approved. configure, run again, records a fresh |
| +// delivery check bound to the new release, writing and restarting |
| +// nothing, only when the redeploy changed the release and nothing else. |
| +// Home implementation/existing-team-adoption.md, "Approved redeploy after |
| +// configure" (amendment, 2026-11-19). |
| +package adopt |
| + |
| +import ( |
| + "errors" |
| + "net/http" |
| + |
| + "amadan.net/oficina/alta/carlosop" |
| + "amadan.net/oficina/alta/provision" |
| +) |
| + |
| +// releaseChanged reports whether now serves another release than base: |
| +// X-Carlos-Version, the served release name, is present and not the |
| +// baseline's. Only then is the approved-redeploy path taken; a check on |
| +// an unchanged release is Delivered's alone. |
| +func releaseChanged(base, now Delivery) bool { |
| + return now.Header != "" && now.Header != base.Header |
| +} |
| + |
| +// redelivered lists, as fixed codes, how now fails to be app's delivery |
| +// on a release other than base's that artifact approves: |
| +// |
| +// - release-unchanged: the baseline names no release, or the body or |
| +// header is still the baseline's; |
| +// - redirected, healthz (not 200), version-header-mismatch (the body |
| +// and header do not name one release, SameRelease); |
| +// - artifact-unreviewed, artifact-mismatch (ReviewedRelease); |
| +// - operations-<shape>: the operations door does not give agent-access's |
| +// answer as app's must, by the strict classifier (opsMoved), or |
| +// operations-baseline when the baseline did not answer as app's does. |
| +// |
| +// It is Delivered with the release allowed to move to the approved one, |
| +// and nothing else relaxed. |
| +func redelivered(app provision.App, base, now Delivery, artifact string) []string { |
| + var codes []string |
| + add := func(c string) { codes = append(codes, c) } |
| + if base.Version == "" || base.Header == "" || now.Version == base.Version || now.Header == base.Header { |
| + add("release-unchanged") |
| + } |
| + if now.Redirected { |
| + add("redirected") |
| + } |
| + if now.Health != http.StatusOK { |
| + add("healthz") |
| + } |
| + if now.Version == "" || now.Header == "" || !SameRelease(now.Version, now.Header) { |
| + add("version-header-mismatch") |
| + } |
| + if code := ReviewedRelease(now, artifact); code != "" { |
| + add(code) |
| + } |
| + switch { |
| + case base.Ops != BaselineOps(app): |
| + add("operations-baseline") |
| + case opsMoved(app, base, now) != nil: |
| + add("operations-" + string(now.Ops)) |
| + } |
| + return sortedSet(codes) |
| +} |
| + |
| +// redeployCodes lists every reason fresh is not app redeployed to the |
| +// release artifact approves and otherwise exactly as configure left it. |
| +// Empty admits it. Beyond redelivered: |
| +// |
| +// - write-not-landed: the journal's write is not landed with the two |
| +// agent keys; |
| +// - agent-key-<KEY>: a key is not the journal's sent value, a plain var |
| +// from the write layer, in the effective config (as Preflight admits |
| +// on a resume; sameConfig holds the stored layer to the after |
| +// snapshot); |
| +// - drift-<code>: Preserved(baseline, fresh), every other key, untouched |
| +// layer and the identity as the baseline had them; |
| +// - identity-<code>: SameIdentity with the baseline and the after |
| +// snapshot: the same record, environment, storage and domain-to-route |
| +// binding (a redeploy keeps the instance record); |
| +// - config-<code>: sameConfig(after, fresh), so a config change a |
| +// redeploy made, a new key included, is refused, as the check always |
| +// refused it; |
| +// - team-mode-<KEY>, home-issuer-mismatch, home-consumer-mismatch. |
| +func redeployCodes(app provision.App, base, after, fresh Snapshot, w WriteRecord, landed bool, artifact string) []string { |
| + codes := redelivered(app, base.Delivery, fresh.Delivery, artifact) |
| + add := func(prefix string, cs ...string) { |
| + for _, c := range cs { |
| + codes = append(codes, prefix+c) |
| + } |
| + } |
| + keys := AgentKeys(app) |
| + if !landed || w.State != "landed" || len(w.Sent) != 2 || w.Sent[keys[0]] == "" || w.Sent[keys[1]] == "" { |
| + add("", "write-not-landed") |
| + } |
| + for _, k := range keys { |
| + v := findVar(fresh.Vars, k) |
| + if v == nil || v.Kind != "env" || v.From != layerName(base.WriteLayer) || v.Digest != carlosop.EnvDigest(w.Sent[k]) { |
| + add("agent-key-", k) |
| + } |
| + } |
| + add("drift-", Preserved(base, fresh, keys)...) |
| + add("identity-", SameIdentity(base.Identity, fresh.Identity)...) |
| + add("identity-", SameIdentity(after.Identity, fresh.Identity)...) |
| + add("config-", sameConfig(after, fresh)...) |
| + add("team-mode-", TeamModeKeys(app, fresh.Vars)...) |
| + add("", homeCodes(app, fresh)...) |
| + return sortedSet(codes) |
| +} |
| + |
| +// checkDelivered is the gate's delivery rule for chk. A check that |
| +// records no redeploy holds now to Delivered against the baseline, as it |
| +// always did. One that does holds it to the redeploy it recorded: made |
| +// from the baseline's release, to the release chk observed, for the |
| +// approved reason, under the artifact the config approves now; and now |
| +// must pass redelivered against the baseline. The gate's freshness rule |
| +// (delivery-check-superseded) separately holds now to chk's release. |
| +func checkDelivered(app provision.App, base Delivery, chk DeliveryCheck, artifact string, now Delivery) error { |
| + r := chk.Redeploy |
| + if r == nil { |
| + return Delivered(app, base, now) |
| + } |
| + switch { |
| + case r.Reason != RedeployApproved, |
| + r.From != (Release{base.Version, base.Header}), |
| + r.To != (Release{chk.Delivery.Version, chk.Delivery.Header}), |
| + r.Artifact != artifact: |
| + return errors.New("adopt: the delivery check's redeploy is not this one") |
| + } |
| + if len(redelivered(app, base, now, artifact)) > 0 { |
| + return errors.New("adopt: the redeployed release is not delivered") |
| + } |
| + return nil |
| +} |
diff --git a/adopt/redeploy_test.go b/adopt/redeploy_test.go| new file mode 100644 |
| index 0000000..a09cf66 |
| --- /dev/null |
| +++ b/adopt/redeploy_test.go |
| @@ -0,0 +1,336 @@ |
| +package adopt |
| + |
| +import ( |
| + "context" |
| + "crypto/sha256" |
| + "encoding/base64" |
| + "net/http" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// redeployed serves release (body version, header header) from x's app, |
| +// as a redeploy Paul approved leaves it: the config's artifact for the app |
| +// is the new release's, and nothing else moved. It answers the artifact. |
| +func (x *observerFixture) redeployed(version, header string) string { |
| + x.site.version, x.site.header = version, header |
| + art := sha256Hex(header) |
| + x.o.Artifacts[x.app.Slug] = art |
| + return art |
| +} |
| + |
| +func (x *observerFixture) recheck(artifact string) error { |
| + return CheckDelivery(context.Background(), x.s, x.c, x.h, x.app, artifact) |
| +} |
| + |
| +func (x *observerFixture) check(t *testing.T) DeliveryCheck { |
| + t.Helper() |
| + c, ok, err := x.s.DeliveryCheck(context.Background(), x.app.Slug) |
| + if err != nil || !ok { |
| + t.Fatalf("no delivery check (ok %v, err %v)", ok, err) |
| + } |
| + return c |
| +} |
| + |
| +// A redeploy to an approved release, after the write landed, is checked |
| +// again by configure's resume with nothing written or restarted, and the |
| +// check says why: the release changed from the baseline's to the |
| +// approved one. The gate then admits the app on the new release. |
| +func TestApprovedRedeployRecordsCheckAndActivates(t *testing.T) { |
| + cases := map[string]struct{ app, version, header string }{ |
| + "same names": {"calendar", "v1.5.0", "v1.5.0"}, |
| + "describe name": {"calendar", "v1.4.0-3-gabcdef1", "abcdef1"}, |
| + "app 401 first": {"slides", "v1.5.0", "v1.5.0"}, |
| + } |
| + for name, tc := range cases { |
| + t.Run(name, func(t *testing.T) { |
| + x := newObserverFixture(t, tc.app) |
| + if tc.app != CanaryApp { |
| + canaryActive(t, x.s) |
| + } |
| + host := routeOf(x.app) |
| + puts, restarts := x.puts(), x.f.RestartCount(host) |
| + before := x.check(t) |
| + art := x.redeployed(tc.version, tc.header) |
| + |
| + // Today's refusal, before the check is made again. |
| + x.refused(t, "delivery-check-superseded", "not-delivered") |
| + |
| + if err := x.recheck(art); err != nil { |
| + t.Fatalf("CheckDelivery after an approved redeploy: %v", err) |
| + } |
| + got := x.check(t) |
| + r := got.Redeploy |
| + if r == nil { |
| + t.Fatal("the check does not record the redeploy") |
| + } |
| + if r.Reason != RedeployApproved || r.Artifact != art || |
| + r.From != (Release{valueVersion, valueVersion}) || r.To != (Release{tc.version, tc.header}) { |
| + t.Fatalf("redeploy recorded as %+v", *r) |
| + } |
| + if got.Delivery.Version != tc.version || got.Delivery.Header != tc.header { |
| + t.Fatal("the check is not bound to the new served release") |
| + } |
| + if got.AfterVersion != before.AfterVersion || len(SameIdentity(got.Identity, before.Identity)) > 0 { |
| + t.Fatal("the check moved off the after snapshot") |
| + } |
| + if x.puts() != puts || x.f.RestartCount(host) != restarts || x.f.AppWideRestarts() != 0 { |
| + t.Fatal("the redeploy check wrote or restarted") |
| + } |
| + |
| + obs, err := x.observe() |
| + if err != nil { |
| + t.Fatalf("Observe after the redeploy check: %v", err) |
| + } |
| + sum := sha256.Sum256([]byte(tc.header)) |
| + if obs.AppVersion != tc.version || obs.ArtifactDigest != base64.RawURLEncoding.EncodeToString(sum[:]) { |
| + t.Fatal("the observation is not of the new release") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// A check made with the release unchanged records no redeploy. |
| +func TestDeliveryCheckOnUnchangedReleaseRecordsNoRedeploy(t *testing.T) { |
| + x := newObserverFixture(t, "calendar") |
| + if x.check(t).Redeploy != nil { |
| + t.Fatal("a check on the baseline's release records a redeploy") |
| + } |
| + setupOK(t, x.recheck(sha256Hex(valueVersion))) |
| + if x.check(t).Redeploy != nil { |
| + t.Fatal("a repeated check on the baseline's release records a redeploy") |
| + } |
| +} |
| + |
| +// Every guard of the redeploy check refuses on its own, with today's |
| +// refusal first and the check left as it was. |
| +func TestApprovedRedeployRefusals(t *testing.T) { |
| + const next = "v1.5.0" |
| + cases := map[string]struct { |
| + app string |
| + edit func(t *testing.T, x *observerFixture) string // answers the artifact |
| + want []string |
| + }{ |
| + "unapproved release": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.redeployed(next, next) |
| + return sha256Hex(valueVersion) |
| + }, want: []string{"redeploy-artifact-mismatch"}}, |
| + "another approved release": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.redeployed(next, next) |
| + return sha256Hex("v1.6.0") |
| + }, want: []string{"redeploy-artifact-mismatch"}}, |
| + "config changed": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.f.PlatformWrite(x.app.Slug, "", x.app.Prefix+"_PLATFORM_NOTE", "n") |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-config-added:" + "CALENDAR_PLATFORM_NOTE"}}, |
| + "preserved key changed": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.f.SetVar(x.app.Slug, "", x.app.Prefix+"_ORIGIN", "https://elsewhere.example") |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-drift-changed:CALENDAR_ORIGIN", "redeploy-config-changed:CALENDAR_ORIGIN"}}, |
| + "identity changed": {edit: func(t *testing.T, x *observerFixture) string { |
| + in := fixtureInstance(x.app) |
| + in.RecordSeq++ |
| + x.f.AddInstance(in) |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-identity-record"}}, |
| + "storage changed": {edit: func(t *testing.T, x *observerFixture) string { |
| + in := fixtureInstance(x.app) |
| + in.Slug = "s-recreated" |
| + x.f.AddInstance(in) |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-identity-storage"}}, |
| + "domain re-pointed": {edit: func(t *testing.T, x *observerFixture) string { |
| + in := fixtureInstance(x.app) |
| + in.Host = "calendar-2.bds.oncarlos.com" |
| + x.f.AddInstance(in) |
| + x.f.AttachDomain(x.app.Slug, CanonicalHost(x.app), in.Host, "live") |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-identity-alias", "redeploy-identity-instance"}}, |
| + "operations absent": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.site.ops = nil |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-operations-absent"}}, |
| + "operations lookalike": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.site.ops = respond(200, map[string]string{"Content-Type": "application/json"}, `{"operations":[]}`) |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-operations-other"}}, |
| + "operations app 401": {app: "slides", edit: func(t *testing.T, x *observerFixture) string { |
| + x.site.ops = app401 |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-operations-app-401"}}, |
| + "keys dropped": {edit: func(t *testing.T, x *observerFixture) string { |
| + keys := AgentKeys(x.app) |
| + x.f.Unset(x.app.Slug, "", keys[0]) |
| + x.f.Unset(x.app.Slug, "", keys[1]) |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-agent-key-CALENDAR_AGENT_ISSUER", "redeploy-agent-key-CALENDAR_AGENT_TEAM"}}, |
| + "key rewritten": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.f.SetVar(x.app.Slug, "", AgentKeys(x.app)[1], "tm_other") |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-agent-key-CALENDAR_AGENT_TEAM"}}, |
| + "write not landed": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.rejournal(t, func(e *evidence) { e.write.State = "sent" }) |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-write-not-landed"}}, |
| + "body and header disagree": {edit: func(t *testing.T, x *observerFixture) string { |
| + art := x.redeployed(next, "v1.5.1") |
| + return art |
| + }, want: []string{"redeploy-version-header-mismatch"}}, |
| + "body unchanged": {edit: func(t *testing.T, x *observerFixture) string { |
| + return x.redeployed(valueVersion, next) |
| + }, want: []string{"redeploy-release-unchanged"}}, |
| + "redirect": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.site.ops = respond(http.StatusFound, map[string]string{"Location": "/elsewhere"}, "") |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-redirected"}}, |
| + "team mode": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.f.SetVar(x.app.Slug, "", x.app.Prefix+"_TEAM_MODE", "on") |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-team-mode-CALENDAR_TEAM_MODE"}}, |
| + "home issuer": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.f.SetVar(x.app.Slug, "", x.app.Prefix+"_HOME_ISSUER", "https://elsewhere.example") |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-home-issuer-mismatch"}}, |
| + "unhealthy": {edit: func(t *testing.T, x *observerFixture) string { |
| + x.site.health = 503 |
| + return x.redeployed(next, next) |
| + }, want: []string{"redeploy-healthz"}}, |
| + } |
| + for name, tc := range cases { |
| + t.Run(name, func(t *testing.T) { |
| + app := tc.app |
| + if app == "" { |
| + app = "calendar" |
| + } |
| + x := newObserverFixture(t, app) |
| + before := x.check(t) |
| + art := tc.edit(t, x) |
| + err := x.recheck(art) |
| + if err == nil { |
| + t.Fatal("the redeploy check passed") |
| + } |
| + noValues(t, err) |
| + msg := err.Error() |
| + if !strings.HasPrefix(msg, "adopt: check-not-delivered: adopt: the ") { |
| + t.Fatalf("err = %v, want today's refusal first", err) |
| + } |
| + for _, code := range tc.want { |
| + if !strings.Contains(msg, code) { |
| + t.Fatalf("err = %v, want %s", err, code) |
| + } |
| + } |
| + after := x.check(t) |
| + if after.Redeploy != nil || after.Delivery != before.Delivery || !after.At.Equal(before.At) { |
| + t.Fatal("a refused redeploy check replaced the check") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// A release that did not change is refused as it always was: no redeploy |
| +// guard is consulted and the refusal is today's, word for word. |
| +func TestRedeployPathOnlyWhenReleaseChanged(t *testing.T) { |
| + cases := map[string]struct { |
| + edit func(x *observerFixture) |
| + want string |
| + }{ |
| + "operations absent": {func(x *observerFixture) { x.site.ops = nil }, "adopt: check-not-delivered: adopt: the delegated-access door is not answering"}, |
| + "unhealthy": {func(x *observerFixture) { x.site.health = 503 }, "adopt: check-not-delivered: adopt: the app is not healthy"}, |
| + "header only": {func(x *observerFixture) { x.site.version = "v1.5.0" }, "adopt: check-not-delivered: adopt: the served version changed"}, |
| + } |
| + for name, tc := range cases { |
| + t.Run(name, func(t *testing.T) { |
| + x := newObserverFixture(t, "calendar") |
| + tc.edit(x) |
| + if err := x.recheck(sha256Hex(x.site.header)); err == nil || err.Error() != tc.want { |
| + t.Fatalf("err = %v, want %q", err, tc.want) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// The gate holds a redeploy check to the release it recorded and to the |
| +// baseline it was measured from; a plain check never covers a release |
| +// change. |
| +func TestGateHoldsRedeployCheck(t *testing.T) { |
| + const next = "v1.5.0" |
| + staged := func(t *testing.T) *observerFixture { |
| + t.Helper() |
| + x := newObserverFixture(t, "calendar") |
| + setupOK(t, x.recheck(x.redeployed(next, next))) |
| + if _, err := x.observe(); err != nil { |
| + t.Fatalf("setup: Observe: %v", err) |
| + } |
| + return x |
| + } |
| + t.Run("redeployed again", func(t *testing.T) { |
| + x := staged(t) |
| + x.redeployed("v1.6.0", "v1.6.0") |
| + x.refused(t, "delivery-check-superseded") |
| + }) |
| + t.Run("back on the baseline's release", func(t *testing.T) { |
| + x := staged(t) |
| + x.redeployed(valueVersion, valueVersion) |
| + x.refused(t, "delivery-check-superseded", "not-delivered") |
| + }) |
| + t.Run("approval withdrawn", func(t *testing.T) { |
| + x := staged(t) |
| + x.o.Artifacts[x.app.Slug] = sha256Hex(valueVersion) |
| + x.refused(t, "artifact-mismatch", "not-delivered") |
| + }) |
| + t.Run("operations stopped answering", func(t *testing.T) { |
| + x := staged(t) |
| + x.site.ops = nil |
| + wantCodes(t, x.refused(t), "not-delivered") |
| + }) |
| + t.Run("keys dropped", func(t *testing.T) { |
| + x := staged(t) |
| + keys := AgentKeys(x.app) |
| + x.f.Unset(x.app.Slug, "", keys[0]) |
| + x.f.Unset(x.app.Slug, "", keys[1]) |
| + x.refused(t, "agent-key-CALENDAR_AGENT_ISSUER", "agent-key-CALENDAR_AGENT_TEAM") |
| + }) |
| + edits := map[string]func(c *DeliveryCheck){ |
| + "from another baseline": func(c *DeliveryCheck) { c.Redeploy.From.Version = "v1.3.0" }, |
| + "to another release": func(c *DeliveryCheck) { c.Redeploy.To.Header = "v1.5.1" }, |
| + "another artifact": func(c *DeliveryCheck) { c.Redeploy.Artifact = sha256Hex("v1.5.1") }, |
| + "another reason": func(c *DeliveryCheck) { c.Redeploy.Reason = "operator" }, |
| + "no redeploy recorded": func(c *DeliveryCheck) { c.Redeploy = nil }, |
| + } |
| + for name, edit := range edits { |
| + t.Run(name, func(t *testing.T) { |
| + x := staged(t) |
| + x.rejournal(t, func(e *evidence) { edit(e.check) }) |
| + wantCodes(t, x.refused(t), "not-delivered") |
| + }) |
| + } |
| +} |
| + |
| +// The binding commits to the redeploy a check records, and is unchanged |
| +// for a check that records none. |
| +func TestBindingCommitsToRedeploy(t *testing.T) { |
| + in := bindingInput() |
| + plain := EnvironmentBinding(in) |
| + in.Check.Redeploy = &Redeploy{From: Release{"v1.4.0", "v1.4.0"}, To: Release{"v1.5.0", "v1.5.0"}, Artifact: hex64("e"), Reason: RedeployApproved} |
| + with := EnvironmentBinding(in) |
| + if with == plain { |
| + t.Fatal("the binding does not commit to the redeploy") |
| + } |
| + edits := map[string]func(r *Redeploy){ |
| + "from version": func(r *Redeploy) { r.From.Version = "v1.3.0" }, |
| + "from header": func(r *Redeploy) { r.From.Header = "v1.3.0" }, |
| + "to version": func(r *Redeploy) { r.To.Version = "v1.5.1" }, |
| + "to header": func(r *Redeploy) { r.To.Header = "v1.5.1" }, |
| + "artifact": func(r *Redeploy) { r.Artifact = hex64("d") }, |
| + "reason": func(r *Redeploy) { r.Reason = "operator" }, |
| + } |
| + for name, edit := range edits { |
| + e := in |
| + r := *in.Check.Redeploy |
| + edit(&r) |
| + e.Check.Redeploy = &r |
| + if EnvironmentBinding(e) == with { |
| + t.Fatalf("the binding does not commit to the redeploy's %s", name) |
| + } |
| + } |
| +} |
diff --git a/adopt/types.go b/adopt/types.go| index bdf1476..519904e 100644 |
| --- a/adopt/types.go |
| +++ b/adopt/types.go |
| @@ -139,12 +139,38 @@ type Snapshot struct { |
| // 2026-11-17, Home discussion 103). It is bound to what was observed: |
| // AfterVersion is the after snapshot's write-layer version, sealed, and |
| // any change in Identity, Delivery or the config voids it. |
| +// |
| +// Redeploy is nil for a check on the baseline's release. It is set only |
| +// for a check made on another release, after the write landed and the |
| +// after snapshot was captured, because the app was redeployed to a |
| +// release Paul approved (CheckDelivery's approved-redeploy path): it is |
| +// the journal's record of why the release moved. |
| type DeliveryCheck struct { |
| App string |
| Identity Identity |
| Delivery Delivery |
| AfterVersion string |
| At time.Time |
| + Redeploy *Redeploy `json:",omitempty"` |
| +} |
| + |
| +// Release is a served release: the /api/version body and |
| +// X-Carlos-Version. |
| +type Release struct{ Version, Header string } |
| + |
| +// RedeployApproved is the one reason a delivery check is made on a |
| +// release other than the baseline's: Paul approved the redeploy, and the |
| +// config's artifact for the app is the new release's. |
| +const RedeployApproved = "approved-redeploy" |
| + |
| +// Redeploy is why a delivery check was made on another release than the |
| +// baseline's: the release changed From the baseline's To the checked |
| +// one, whose SHA-256 is Artifact, the config's approved artifact, for |
| +// Reason (RedeployApproved). |
| +type Redeploy struct { |
| + From, To Release |
| + Artifact string |
| + Reason string |
| } |
| // HomePreflight is Home's state before a phase, from signed inspects and |
diff --git a/cmd/alta-adopt/main_test.go b/cmd/alta-adopt/main_test.go| index c38af91..5c30b29 100644 |
| --- a/cmd/alta-adopt/main_test.go |
| +++ b/cmd/alta-adopt/main_test.go |
| @@ -56,9 +56,10 @@ type rig struct { |
| carlos *fakecarlos.Fake |
| public *http.Client |
| - siteMu sync.Mutex |
| - seen map[string]int |
| - loaded map[string]bool |
| + siteMu sync.Mutex |
| + seen map[string]int |
| + loaded map[string]bool |
| + releases map[string]string // an app's served release, when not served |
| dir, cfgPath, state string |
| dek, opKey, pre string |
| @@ -197,8 +198,9 @@ func (r *rig) site(w http.ResponseWriter, req *http.Request) { |
| slug := strings.TrimSuffix(host, ".oficina.works") |
| switch req.URL.Path { |
| case "/api/version": |
| - w.Header().Set("X-Carlos-Version", served) |
| - _, _ = io.WriteString(w, served) |
| + release := r.release(slug) |
| + w.Header().Set("X-Carlos-Version", release) |
| + _, _ = io.WriteString(w, release) |
| case "/healthz": |
| w.WriteHeader(http.StatusOK) |
| case "/api/v1/operations": |
| @@ -223,6 +225,35 @@ func (r *rig) site(w http.ResponseWriter, req *http.Request) { |
| } |
| } |
| +// release is the release slug's origin serves. |
| +func (r *rig) release(slug string) string { |
| + r.siteMu.Lock() |
| + defer r.siteMu.Unlock() |
| + if v, ok := r.releases[slug]; ok { |
| + return v |
| + } |
| + return served |
| +} |
| + |
| +// redeploy serves release from slug's origin, as a deploy does: the |
| +// running process changes and its config and instance record do not. |
| +// approved also makes release the config's reviewed artifact for slug, |
| +// as Paul's approval of the redeploy did. |
| +func (r *rig) redeploy(slug, release string, approved bool) { |
| + r.t.Helper() |
| + r.siteMu.Lock() |
| + if r.releases == nil { |
| + r.releases = map[string]string{} |
| + } |
| + r.releases[slug] = release |
| + r.siteMu.Unlock() |
| + if approved { |
| + sum := sha256.Sum256([]byte(release)) |
| + r.cfg["artifacts"].(map[string]string)[slug] = hex.EncodeToString(sum[:]) |
| + r.writeConfig() |
| + } |
| +} |
| + |
| func (r *rig) serving(slug string) bool { |
| r.siteMu.Lock() |
| defer r.siteMu.Unlock() |
| @@ -900,6 +931,72 @@ func TestConfigureRefusesUnreviewedReleaseBeforeWriting(t *testing.T) { |
| r.refused("activate-refused", "", true, "activate", "--apps", adopt.CanaryApp) |
| } |
| +// Docs, slides, calls and memoria were redeployed to releases Paul |
| +// approved after configure had landed their writes and recorded their |
| +// delivery checks (2026-11-19). Activation refuses the stale checks; |
| +// configure, run again, checks each app on its new release, writing and |
| +// restarting nothing, and activation then goes through. |
| +func TestConfigureRechecksApprovedRedeploy(t *testing.T) { |
| + t.Parallel() |
| + r := newRig(t) |
| + r.throughPlanA() |
| + r.configured(adopt.CanaryApp) |
| + r.applied("", true, "activate", "--apps", adopt.CanaryApp) |
| + r.confirm(homeop.KindAddApps) |
| + r.ok("", true, "advance", "--run", r.latestRun(), "--apply") |
| + r.runState("done") |
| + r.tick(homeop.WindowLifetime * time.Second) |
| + apps := []string{"docs", "slides", "calls", "memoria"} |
| + for _, a := range apps { |
| + r.configured(a) |
| + } |
| + for _, a := range apps { |
| + r.redeploy(a, "v1.5.0-2-gabcdef1", true) |
| + } |
| + list := strings.Join(apps, ",") |
| + if out := r.refused("activate-refused", "", true, "activate", "--apps", list); !strings.Contains(out, "delivery-check-superseded") || !strings.Contains(out, "not-delivered") { |
| + t.Fatalf("activate did not refuse the stale checks as production did\n%s", out) |
| + } |
| + |
| + before := r.writes() |
| + for _, a := range apps { |
| + r.configured(a) |
| + } |
| + after := r.writes() |
| + if after.puts != before.puts || after.restarts != before.restarts || after.appWide != before.appWide || after.plans != before.plans || after.ops != before.ops { |
| + t.Fatalf("the re-check wrote or restarted: %+v %+v", before, after) |
| + } |
| + |
| + r.applied("", true, "activate", "--apps", list) |
| + r.confirm(homeop.KindAddApps) |
| + r.ok("", true, "advance", "--run", r.latestRun(), "--apply") |
| + r.runState("done") |
| + for _, a := range apps { |
| + if st := r.home.InstanceState(a); st != "live" { |
| + t.Fatalf("%s is %q at Home", a, st) |
| + } |
| + } |
| +} |
| + |
| +// A redeploy to a release Paul did not approve keeps today's refusal: |
| +// configure records no check, and activation stays refused. |
| +func TestConfigureRefusesUnapprovedRedeploy(t *testing.T) { |
| + t.Parallel() |
| + r := newRig(t) |
| + r.throughPlanA() |
| + r.configured(adopt.CanaryApp) |
| + r.redeploy(adopt.CanaryApp, "v1.5.0", false) |
| + before := r.writes() |
| + out := r.refused("check-not-delivered", "", true, "configure", "--app", adopt.CanaryApp, "--apply") |
| + if !strings.Contains(out, "adopt: the served version changed") || !strings.Contains(out, "redeploy-artifact-mismatch") { |
| + t.Fatalf("configure did not refuse the unapproved release\n%s", out) |
| + } |
| + if after := r.writes(); after != before { |
| + t.Fatalf("a refused re-check wrote: %+v %+v", before, after) |
| + } |
| + r.refused("activate-refused", "", true, "activate", "--apps", adopt.CanaryApp) |
| +} |
| + |
| // The witness and the live checks are gone (Paul, 2026-11-17): their |
| // commands are unknown, and nothing is opened or written. |
| func TestRemovedCommandsAreUnknown(t *testing.T) { |