// 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-: 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-: 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-: Preserved(baseline, fresh), every other key, untouched // layer and the identity as the baseline had them; // - identity-: 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-: sameConfig(after, fresh), so a config change a // redeploy made, a new key included, is refused, as the check always // refused it; // - team-mode-, 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 }