adopt: bind the spec's list and the witness only; strict test setup
environment_binding no longer includes the Home preflight time; the array is the spec's list plus the witness, and the test pins it. The artifact check cites the controller amendment and Alta's scheme. Test setup writes and journal reads now fail the test on error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+72
−52
adopt/binding.go+6 −7adopt/binding_test.go+23 −26adopt/observer.go+8 −5adopt/observer_test.go+35 −14
diff --git a/adopt/binding.go b/adopt/binding.go| index ffd7c89..3cea0e0 100644 |
| --- a/adopt/binding.go |
| +++ b/adopt/binding.go |
| @@ -7,7 +7,6 @@ import ( |
| "encoding/base64" |
| "encoding/json" |
| "sort" |
| - "time" |
| "amadan.net/oficina/alta/carlosop" |
| ) |
| @@ -18,8 +17,7 @@ const bindingContext = "oficina/existing-app-observation/v1" |
| // BindingInput is everything one adopted app's binding commits to. |
| // ArtifactSHA256 is the reviewed artifact's SHA-256 as 64 lowercase hex; |
| -// Version is the delivered version; HomePreflightAt is when the |
| -// pre-plan-a Home preflight was attested. |
| +// Version is the delivered version. |
| type BindingInput struct { |
| Before, After Identity |
| BeforeVars, AfterVars []carlosop.EffectiveVar |
| @@ -27,7 +25,6 @@ type BindingInput struct { |
| TeamSQID, Issuer, ArtifactSHA256, Version string |
| BeforeDelivery, AfterDelivery, NowDelivery Delivery |
| Witness Witness |
| - HomePreflightAt time.Time |
| } |
| // EnvironmentBinding is base64url(SHA-256) of the JSON array, in order: |
| @@ -40,8 +37,11 @@ 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 witness: [app, sentence, identity, delivery, after version, |
| -// time]; |
| -// 8. the pre-plan-a Home preflight's attestation time. |
| +// time]. |
| +// |
| +// That is the spec's list (Home implementation/existing-team-adoption.md, |
| +// "Compute environment_binding") plus the witness, which the 522 Plan 2 |
| +// waiver puts in the signed observation; nothing else is bound. |
| // |
| // Paul's witness and the delivery observations are inside the binding, |
| // so Home's signed activation commits to them. The result is as |
| @@ -56,7 +56,6 @@ func EnvironmentBinding(in BindingInput) string { |
| in.TeamSQID, in.Issuer, in.ArtifactSHA256, in.Version, |
| in.BeforeDelivery, in.AfterDelivery, in.NowDelivery, |
| []any{w.App, w.Typed, w.Identity, w.Delivery, w.AfterVersion, w.At}, |
| - in.HomePreflightAt, |
| } |
| // 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/binding_test.go b/adopt/binding_test.go| index a17d27b..abd0c7b 100644 |
| --- a/adopt/binding_test.go |
| +++ b/adopt/binding_test.go |
| @@ -35,7 +35,6 @@ func bindingInput() BindingInput { |
| BeforeDelivery: d(OpsAbsent, 0), AfterDelivery: d(OpsAgent401, 5), NowDelivery: d(OpsAgent401, 60), |
| Witness: Witness{App: "docs", Typed: "I signed in to docs.oficina.works and it works as before", |
| Identity: id, Delivery: d(OpsAgent401, 10), AfterVersion: "cv1:" + hex64("2"), At: at.Add(10 * time.Minute)}, |
| - HomePreflightAt: at.Add(-24 * time.Hour), |
| } |
| } |
| @@ -69,7 +68,6 @@ func TestBindingIncludesWitnessAndDelivery(t *testing.T) { |
| in.TeamSQID, in.Issuer, in.ArtifactSHA256, in.Version, |
| in.BeforeDelivery, in.AfterDelivery, in.NowDelivery, |
| []any{in.Witness.App, in.Witness.Typed, in.Witness.Identity, in.Witness.Delivery, in.Witness.AfterVersion, in.Witness.At}, |
| - in.HomePreflightAt, |
| } |
| js, err := json.Marshal(parts) |
| if err != nil { |
| @@ -82,30 +80,29 @@ func TestBindingIncludesWitnessAndDelivery(t *testing.T) { |
| // Every part moves it, the witness and the three deliveries above all. |
| edits := map[string]func(*BindingInput){ |
| - "witness app": func(in *BindingInput) { in.Witness.App = "sheets" }, |
| - "witness sentence": func(in *BindingInput) { in.Witness.Typed += "." }, |
| - "witness identity": func(in *BindingInput) { in.Witness.Identity.RecordSeq++ }, |
| - "witness delivery": func(in *BindingInput) { in.Witness.Delivery.Header = "v1.4.1" }, |
| - "witness delivery ops": func(in *BindingInput) { in.Witness.Delivery.Ops = OpsAgent200 }, |
| - "witness after version": func(in *BindingInput) { in.Witness.AfterVersion = "cv1:" + hex64("3") }, |
| - "witness time": func(in *BindingInput) { in.Witness.At = in.Witness.At.Add(time.Second) }, |
| - "before delivery": func(in *BindingInput) { in.BeforeDelivery.Ops = OpsApp401 }, |
| - "after delivery": func(in *BindingInput) { in.AfterDelivery.Version = "v1.4.1" }, |
| - "after delivery health": func(in *BindingInput) { in.AfterDelivery.Health = 503 }, |
| - "now delivery": func(in *BindingInput) { in.NowDelivery.Redirected = true }, |
| - "now delivery time": func(in *BindingInput) { in.NowDelivery.At = in.NowDelivery.At.Add(time.Hour) }, |
| - "before identity": func(in *BindingInput) { in.Before.Region = "us" }, |
| - "after identity": func(in *BindingInput) { in.After.Seed = `{"s":1}` }, |
| - "before var gone": func(in *BindingInput) { in.BeforeVars = []carlosop.EffectiveVar{in.BeforeVars[0]} }, |
| - "before var digest": func(in *BindingInput) { in.BeforeVars = withDigest(in.BeforeVars, 1, "vd1:"+hex64("9")) }, |
| - "after var source": func(in *BindingInput) { in.AfterVars = withFrom(in.AfterVars, 0, "environment") }, |
| - "before layers": func(in *BindingInput) { in.BeforeLayers = map[string]string{"default": "none"} }, |
| - "after layers": func(in *BindingInput) { in.AfterLayers = map[string]string{"default": "none"} }, |
| - "team": func(in *BindingInput) { in.TeamSQID = "other" }, |
| - "issuer": func(in *BindingInput) { in.Issuer = "https://elsewhere.example" }, |
| - "artifact": func(in *BindingInput) { in.ArtifactSHA256 = hex64("f") }, |
| - "version": func(in *BindingInput) { in.Version = "v1.4.1" }, |
| - "home preflight attested": func(in *BindingInput) { in.HomePreflightAt = in.HomePreflightAt.Add(time.Second) }, |
| + "witness app": func(in *BindingInput) { in.Witness.App = "sheets" }, |
| + "witness sentence": func(in *BindingInput) { in.Witness.Typed += "." }, |
| + "witness identity": func(in *BindingInput) { in.Witness.Identity.RecordSeq++ }, |
| + "witness delivery": func(in *BindingInput) { in.Witness.Delivery.Header = "v1.4.1" }, |
| + "witness delivery ops": func(in *BindingInput) { in.Witness.Delivery.Ops = OpsAgent200 }, |
| + "witness after version": func(in *BindingInput) { in.Witness.AfterVersion = "cv1:" + hex64("3") }, |
| + "witness time": func(in *BindingInput) { in.Witness.At = in.Witness.At.Add(time.Second) }, |
| + "before delivery": func(in *BindingInput) { in.BeforeDelivery.Ops = OpsApp401 }, |
| + "after delivery": func(in *BindingInput) { in.AfterDelivery.Version = "v1.4.1" }, |
| + "after delivery health": func(in *BindingInput) { in.AfterDelivery.Health = 503 }, |
| + "now delivery": func(in *BindingInput) { in.NowDelivery.Redirected = true }, |
| + "now delivery time": func(in *BindingInput) { in.NowDelivery.At = in.NowDelivery.At.Add(time.Hour) }, |
| + "before identity": func(in *BindingInput) { in.Before.Region = "us" }, |
| + "after identity": func(in *BindingInput) { in.After.Seed = `{"s":1}` }, |
| + "before var gone": func(in *BindingInput) { in.BeforeVars = []carlosop.EffectiveVar{in.BeforeVars[0]} }, |
| + "before var digest": func(in *BindingInput) { in.BeforeVars = withDigest(in.BeforeVars, 1, "vd1:"+hex64("9")) }, |
| + "after var source": func(in *BindingInput) { in.AfterVars = withFrom(in.AfterVars, 0, "environment") }, |
| + "before layers": func(in *BindingInput) { in.BeforeLayers = map[string]string{"default": "none"} }, |
| + "after layers": func(in *BindingInput) { in.AfterLayers = map[string]string{"default": "none"} }, |
| + "team": func(in *BindingInput) { in.TeamSQID = "other" }, |
| + "issuer": func(in *BindingInput) { in.Issuer = "https://elsewhere.example" }, |
| + "artifact": func(in *BindingInput) { in.ArtifactSHA256 = hex64("f") }, |
| + "version": func(in *BindingInput) { in.Version = "v1.4.1" }, |
| } |
| for name, edit := range edits { |
| t.Run(name, func(t *testing.T) { |
diff --git a/adopt/observer.go b/adopt/observer.go| index c3c6a9e..20ed829 100644 |
| --- a/adopt/observer.go |
| +++ b/adopt/observer.go |
| @@ -151,7 +151,11 @@ func (o *Observer) Observe(ctx context.Context, app, teamSQID string) (provision |
| add("version-unacceptable") |
| } |
| // The served release name is X-Carlos-Version, the release the edge |
| - // served from: Alta's artifact scheme hashes that name. |
| + // served from. Controller amendment (Task 3 ruling, 2026-11-16): |
| + // ChannelDigest is dropped and artifact_digest is Alta's existing |
| + // scheme, base64url SHA-256 of the served release name, as ordinary |
| + // activation sends it (provision/steps.go:700 records serving, :780 artifactDigest hashes |
| + // it, :816 stepActivate sends it). |
| sum := sha256.Sum256([]byte(d.Header)) |
| artifact := hex.EncodeToString(sum[:]) |
| if artifact != ev.artifact { |
| @@ -170,14 +174,13 @@ func (o *Observer) Observe(ctx context.Context, app, teamSQID string) (provision |
| BeforeLayers: ev.base.Layers, AfterLayers: ev.after.Layers, |
| TeamSQID: teamSQID, Issuer: Issuer, ArtifactSHA256: artifact, Version: d.Version, |
| BeforeDelivery: ev.base.Delivery, AfterDelivery: ev.after.Delivery, NowDelivery: d, |
| - Witness: w, HomePreflightAt: ev.home.AttestedAt, |
| + Witness: w, |
| }), |
| }, nil |
| } |
| // gateEvidence is the journal's records for one app's activation. |
| type gateEvidence struct { |
| - home HomePreflight |
| base, after Snapshot |
| write WriteRecord |
| witness Witness |
| @@ -195,7 +198,7 @@ func (o *Observer) evidence(ctx context.Context, a provision.App, teamSQID strin |
| } |
| return err |
| } |
| - home, ok, err := o.S.HomePreflight(ctx, PhasePrePlanA) |
| + _, ok, err := o.S.HomePreflight(ctx, PhasePrePlanA) |
| if err := have(ok, err, "home-preflight"); err != nil { |
| return ev, err |
| } |
| @@ -244,5 +247,5 @@ func (o *Observer) evidence(ctx context.Context, a provision.App, teamSQID strin |
| if !artifactShape.MatchString(artifact) { |
| return ev, refuse("artifact-unreviewed") |
| } |
| - return gateEvidence{home: home, base: base, after: after, write: write, witness: witness, artifact: artifact}, nil |
| + return gateEvidence{base: base, after: after, write: write, witness: witness, artifact: artifact}, nil |
| } |
diff --git a/adopt/observer_test.go b/adopt/observer_test.go| index 9edab56..5c9d370 100644 |
| --- a/adopt/observer_test.go |
| +++ b/adopt/observer_test.go |
| @@ -93,19 +93,29 @@ func (x *observerFixture) rejournal(t *testing.T, edit func(e *evidence)) { |
| t.Helper() |
| ctx := context.Background() |
| var e evidence |
| - if r, ok, _ := x.s.HomePreflight(ctx, PhasePrePlanA); ok { |
| + if r, ok, err := x.s.HomePreflight(ctx, PhasePrePlanA); err != nil { |
| + t.Fatal(err) |
| + } else if ok { |
| e.home = &r |
| } |
| - if r, ok, _ := x.s.Baseline(ctx, x.app.Slug); ok { |
| + if r, ok, err := x.s.Baseline(ctx, x.app.Slug); err != nil { |
| + t.Fatal(err) |
| + } else if ok { |
| e.base = &r |
| } |
| - if r, ok, _ := x.s.Write(ctx, x.app.Slug); ok { |
| + if r, ok, err := x.s.Write(ctx, x.app.Slug); err != nil { |
| + t.Fatal(err) |
| + } else if ok { |
| e.write = &r |
| } |
| - if r, ok, _ := x.s.After(ctx, x.app.Slug); ok { |
| + if r, ok, err := x.s.After(ctx, x.app.Slug); err != nil { |
| + t.Fatal(err) |
| + } else if ok { |
| e.after = &r |
| } |
| - if r, ok, _ := x.s.Witness(ctx, x.app.Slug); ok { |
| + if r, ok, err := x.s.Witness(ctx, x.app.Slug); err != nil { |
| + t.Fatal(err) |
| + } else if ok { |
| e.witness = &r |
| } |
| edit(&e) |
| @@ -153,10 +163,12 @@ func TestObserverHappyPathEvidenceTokens(t *testing.T) { |
| } |
| // The binding is over the journal's evidence and this observation. |
| - base, _, _ := x.s.Baseline(ctx, "calendar") |
| - after, _, _ := x.s.After(ctx, "calendar") |
| - wit, _, _ := x.s.Witness(ctx, "calendar") |
| - home, _, _ := x.s.HomePreflight(ctx, PhasePrePlanA) |
| + base, ok1, err1 := x.s.Baseline(ctx, "calendar") |
| + after, ok2, err2 := x.s.After(ctx, "calendar") |
| + wit, ok3, err3 := x.s.Witness(ctx, "calendar") |
| + if err := errors.Join(err1, err2, err3); err != nil || !ok1 || !ok2 || !ok3 { |
| + t.Fatalf("the journal lacks the evidence: %v", err) |
| + } |
| now := x.site.delivery(t, x.carlosFixture) |
| now.At = x.now |
| want := EnvironmentBinding(BindingInput{ |
| @@ -165,7 +177,7 @@ func TestObserverHappyPathEvidenceTokens(t *testing.T) { |
| BeforeLayers: base.Layers, AfterLayers: after.Layers, |
| TeamSQID: fixtureSQID, Issuer: Issuer, ArtifactSHA256: hex.EncodeToString(sum[:]), Version: valueVersion, |
| BeforeDelivery: base.Delivery, AfterDelivery: after.Delivery, NowDelivery: now, |
| - Witness: wit, HomePreflightAt: home.AttestedAt, |
| + Witness: wit, |
| }) |
| if obs.EnvironmentBinding != want { |
| t.Fatal("environment_binding is not the binding of the journal's evidence and the fresh delivery") |
| @@ -239,7 +251,7 @@ func TestObserverRefusals(t *testing.T) { |
| }{ |
| {name: "no pre-plan-a preflight", edit: func(t *testing.T, x *observerFixture) { |
| x.rejournal(t, func(e *evidence) { e.home = nil }) |
| - _ = x.s.SaveHomePreflight(ctx, HomePreflight{Phase: PhasePreInitialize}) |
| + setupOK(t, x.s.SaveHomePreflight(ctx, HomePreflight{Phase: PhasePreInitialize})) |
| }, want: []string{"missing-home-preflight"}, exact: true}, |
| {name: "no baseline", edit: func(t *testing.T, x *observerFixture) { x.rejournal(t, func(e *evidence) { e.base = nil }) }, |
| want: []string{"missing-baseline"}, exact: true}, |
| @@ -250,14 +262,14 @@ func TestObserverRefusals(t *testing.T) { |
| {name: "no witness", edit: func(t *testing.T, x *observerFixture) { x.rejournal(t, func(e *evidence) { e.witness = nil }) }, |
| want: []string{"missing-witness"}, exact: true}, |
| {name: "rollback recorded", edit: func(t *testing.T, x *observerFixture) { |
| - _ = x.s.SaveRollback(ctx, RollbackRecord{App: x.app.Slug, State: "sent"}) |
| + setupOK(t, x.s.SaveRollback(ctx, RollbackRecord{App: x.app.Slug, State: "sent"})) |
| }, want: []string{"rollback-recorded"}, exact: true}, |
| {name: "live checks missing", app: "docs", want: []string{"live-checks-missing"}, exact: true}, |
| {name: "live check failed", app: "docs", edit: func(t *testing.T, x *observerFixture) { |
| for _, c := range RequiredLiveChecks { |
| - _ = x.s.SaveCheck(ctx, c, "passed") |
| + setupOK(t, x.s.SaveCheck(ctx, c, "passed")) |
| } |
| - _ = x.s.SaveCheck(ctx, "member-no-local-permission-refused", "failed") |
| + setupOK(t, x.s.SaveCheck(ctx, "member-no-local-permission-refused", "failed")) |
| }, want: []string{"live-checks-missing"}, exact: true}, |
| {name: "artifact not reviewed", edit: func(t *testing.T, x *observerFixture) { x.o.Artifacts = nil }, |
| want: []string{"artifact-unreviewed"}, exact: true}, |
| @@ -381,3 +393,12 @@ func TestObserverPassesNonCanaryWithLiveChecks(t *testing.T) { |
| t.Fatalf("Observe: %v", err) |
| } |
| } |
| + |
| +// setupOK fails the test on a setup write that did not succeed, so a case |
| +// never passes without the state it means to stage. |
| +func setupOK(t *testing.T, err error) { |
| + t.Helper() |
| + if err != nil { |
| + t.Fatalf("setup: %v", err) |
| + } |
| +} |