alta-adopt: runner's delivery check replaces witness; drop live checks
Paul's ruling of 2026-11-17 (Home discussion 103). - configure now records an automated delivery check after the restart and after snapshot: same /api/version body and X-Carlos-Version, the reviewed artifact, no redirect, /healthz 200, operations door moved from 404 (or Slides' and Calls' own 401) to agent-access's answer, identity and config equal to the after snapshot. No typed sentence. A resumed configure redoes the check without writing or restarting. The witness command is gone; the check takes its place in the journal (same table and purpose, no migration) and in environment_binding. - Delivered now requires the before shape to be absent or app-401. - Plan C is gated only on Plan B: Store.CanaryGate (calendar activated, not rolled back, not disabled) replaces LiveGate in activate and the Observer. The live command, adopt/live.go, its tests, the live words and the agent-access dependency are removed. - Changed words are marked PENDING COPY REVIEW; README runbook updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 files changed,
+896
−3,095
Makefile+1 −1README.md+39 −41adopt/binding.go+12 −9adopt/binding_test.go+11 −11adopt/delivery.go+4 −3adopt/delivery_test.go+16 −0adopt/{witness.go => deliverycheck.go}+41 −35adopt/deliverycheck_test.go+319 −0adopt/gate_adverse_test.go+67 −90adopt/live.go+0 −642adopt/live_test.go+0 −1,215adopt/observer.go+18 −18adopt/observer_test.go+51 −48adopt/rehearsal_test.go+28 −57adopt/store.go+37 −92adopt/store_test.go+46 −131adopt/types.go+7 −12adopt/types_test.go+0 −9adopt/witness_test.go+0 −299adopt/words.go+19 −79cmd/alta-adopt/main.go+22 −101cmd/alta-adopt/main_test.go+147 −79go.mod+0 −14go.sum+0 −42homecompat/go.mod+0 −14homecompat/go.sum+0 −42provision/adopt_adverse_test.go+7 −7provision/adopt_test.go+4 −4
CI passed — run details
CI log
=== vet === go vet ./... === fmt === === test === CGO_ENABLED=0 go test ./... ok amadan.net/oficina/alta/adopt 16.632s ok amadan.net/oficina/alta/carlosop 0.037s ? amadan.net/oficina/alta/carlosop/fakecarlos [no test files] ok amadan.net/oficina/alta/cmd/alta 0.179s ok amadan.net/oficina/alta/cmd/alta-adopt 27.030s ok amadan.net/oficina/alta/console 0.003s ? amadan.net/oficina/alta/console/fakeconsole [no test files] ok amadan.net/oficina/alta/homeop 0.004s ok amadan.net/oficina/alta/homeop/fakehome 0.051s ok amadan.net/oficina/alta/internal/web 0.122s ok amadan.net/oficina/alta/provision 12.419s === compat === cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./... ok amadan.net/oficina/home/altacompat 0.597s
diff --git a/Makefile b/Makefile| index cb4d41d..db1996a 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -1,5 +1,5 @@ |
| export GOTOOLCHAIN := go1.26.5 |
| -export GOPRIVATE := $(GOPRIVATE),amadan.net/oficina/estilo.git,amadan.net/oficina/agent-access.git |
| +export GOPRIVATE := $(GOPRIVATE),amadan.net/oficina/estilo.git |
| APP := alta |
diff --git a/README.md b/README.md| index 162abeb..51f6abd 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -266,16 +266,14 @@ config file carries. |
| - **The state database** is the run's journal and Alta's operator stream. |
| Back it up after each session. Never edit, replace or delete it by hand. |
| - Gated on CARLOS 522 Plan 1 (conditional writes and |
| - `restart/scope`) being on the production console, and, for the live |
| - checks, on oficina-connect being live with |
| - `HOME_AGENT_DIRECTORY_TOKEN_SHA256` set. |
| + `restart/scope`) being on the production console. |
| ### Phases |
| Phases may fall in separate sessions on separate days. Home's plan windows |
| last 15 minutes and are never extended, so each plan is its own short |
| -session. A witness has no age limit: it stays valid until the instance, |
| -the served version or the config it observed changes. |
| +session. A delivery check has no age limit: it stays valid until the |
| +instance, the served version or the config it observed changes. |
| | Phase | Command | What happens | |
| |---|---|---| |
| @@ -283,10 +281,9 @@ the served version or the config it observed changes. |
| | 0b | `preflight` | Per app, read-only: the config's layers, any other instance that would inherit the keys (`inherits-<host>` stops the run), team-mode keys, identity, delivery. | |
| | 1 | `initialize` | Directory `initialize`, after Paul types the §12 attestation. | |
| | 2 | `home-preflight --phase pre-plan-a`, then `plan-a` | Owner-seed, seed-team, then provision and register (verify only) for all six. | |
| -| 3 | `configure --app <a>`, `witness --app <a>` | Per app: one conditional `PUT /config`, one restart of the canonical host only, the after snapshot, Paul's witnessed sign-in. | |
| +| 3 | `configure --app <a>` | Per app: one conditional `PUT /config`, one restart of the canonical host only, the after snapshot, and the runner's delivery check. | |
| | 4 | `activate --apps calendar` | Plan B: calendar, the canary, is re-observed and activated. | |
| -| 5 | `live --event <id>` | Revocation and permission checks against connect, for calendar. | |
| -| 6 | `activate --apps docs,sheets,slides,calls,memoria` | Plan C. Refused unless every live check passed. | |
| +| 5 | `activate --apps docs,sheets,slides,calls,memoria` | Plan C. Refused until Plan B has activated calendar. | |
| `initialize`, `plan-a` and `activate` open a plan. After Paul confirms it |
| on Home, `advance --run <id> --apply` takes the run as far as it can go; |
| @@ -329,31 +326,21 @@ run it again if it stops (`status` shows where every run is). |
| hosts, "Oficina" and the same 8-hex prefix. Then `advance`. |
| 9. **Configure.** For each app, `configure --app <a>` (dry run) and then |
| with `--apply`: one config write and one restart, of that host only. |
| - `configure` waits until the app serves agent-access's challenge, then |
| - records the after snapshot. |
| -10. **Witness.** Sign in at `https://<app>.oficina.works` in the system |
| - browser, check it works as before, then run `witness --app <a> --apply` |
| - and type the sentence it prints. |
| -11. **Plan B.** Run `activate --apps calendar --apply`, confirm on both |
| + `configure` waits until the app serves agent-access's challenge, |
| + records the after snapshot, then checks the delivery itself and |
| + records the check. The app must serve the same release as before, the |
| + reviewed one, in both the `/api/version` body and `X-Carlos-Version`, |
| + with no redirect; `/healthz` must answer 200; and |
| + `/api/v1/operations` must now give agent-access's answer where it gave |
| + a 404 (or, for Slides and Calls, their own 401). There is nothing to |
| + sign in to and nothing to type. |
| +10. **Plan B.** Run `activate --apps calendar --apply`, confirm on both |
| pages, then `advance`. |
| -12. **Test account.** Create a throwaway Oficina ID account. It must |
| - already belong to some team other than Oficina: connect refuses to |
| - authorize a person with no team (403 `access_denied`), and the |
| - browser sign-in then hangs until cancelled. Sign it in to |
| - calendar.oficina.works once. Pick one of Paul's own calendar events |
| - and note its id for `--event`. |
| -13. **Live checks.** Run `live --event <id> --apply` and follow its |
| - prompts: sign the test account in to connect; add it to the Oficina |
| - team on the Team page, and remove it again; witness both local |
| - sign-ins; connect Paul's own account. **Remove the member within 5 |
| - minutes of adding it:** the check replays the member's request after |
| - removal, and a token older than its 5-minute life proves nothing (the |
| - check is inconclusive and Plan C stays refused). The runner revokes |
| - every connection it makes, whatever happens. |
| -14. **Plan C.** Run `activate --apps docs,sheets,slides,calls,memoria |
| - --apply`, confirm on both pages, then `advance`. |
| -15. **Clean up.** `carlos services delete oficina-adoption`, back up the |
| - state database, and delete the test account if Paul wishes. |
| +11. **Plan C.** Once Plan B's run is done, run `activate --apps |
| + docs,sheets,slides,calls,memoria --apply`, confirm on both pages, then |
| + `advance`. |
| +12. **Clean up.** `carlos services delete oficina-adoption`, and back up |
| + the state database. |
| ### When a step stops |
| @@ -371,21 +358,33 @@ run it again if it stops (`status` shows where every run is). |
| - **A process dies mid-configure** (closed laptop, lost network). Run the |
| same `configure --app <a> --apply` again. It rereads the console and |
| continues from the journal: a write that landed is found, never sent |
| - twice; the baseline is never retaken. A restart may be repeated. |
| + twice; the baseline is never retaken. A restart may be repeated. If |
| + the process died after the restart, the delivery check is made again |
| + with no second write or restart. |
| +- **The delivery check is refused** (`check-<code>`). Nothing is |
| + recorded, and activation stays refused for that app. The code names |
| + what is wrong: `check-not-delivered` (version, header, redirect, health |
| + or the operations answer), `check-artifact-mismatch` or |
| + `check-artifact-unreviewed` (the served release is not the reviewed |
| + one in `artifacts`), `check-identity-<field>` or `check-config-<key>` |
| + (the instance or its config moved since the after snapshot). Find out |
| + why before going on. Once it is put right, the same `configure --app |
| + <a> --apply` checks again. |
| - **A stop** (`preserved-changed`, `identity-changed`, |
| `agent-keys-conflict`, `agent-keys-foreign`, `receipt-mismatch`, |
| `receipt-malformed`) is final for that app: every resume refuses again, |
| and the runner never unsets a value it did not write. Look at the |
| console first. |
| -- **Failed and stopped states stay closed.** A failed run, a stopped write |
| - or rollback and a failed live check are never cleared by the runner. |
| - Going past one needs a reviewed procedure first. |
| -- **A live check fails.** Plan C stays refused for good: a failure means |
| - revocation or membership is not enforced. Investigate before anything |
| - else. |
| +- **Failed and stopped states stay closed.** A failed run and a stopped |
| + write or rollback are never cleared by the runner. Going past one needs |
| + a reviewed procedure first. |
| +- **Plan C is refused with `canary-not-active`.** Plan B has not yet |
| + activated calendar, or calendar has since been rolled back or |
| + disabled. Finish Plan B first. After a calendar rollback or disable, |
| + Plan C stays refused: going past that needs a reviewed procedure. |
| - **Activation parks with `observe-<codes>`.** The re-observation just |
| before activation no longer matches the journal; the codes name what |
| - moved (`witness-superseded`, `config-<key>`, `identity-<field>`, |
| + moved (`delivery-check-superseded`, `config-<key>`, `identity-<field>`, |
| `artifact-mismatch`, …). Nothing was activated. Find out what changed |
| before going on. |
| @@ -403,7 +402,6 @@ run it again if it stops (`status` shows where every run is). |
| | 8 | `POST …/restart/scope {"host"}` after its dry run, one per app | CARLOS, that host only | Restart again after the rollback. | |
| | 9 | `directory.verify-consumer` per app | Home directory | Expires after 600 s. | |
| | 10 | `directory.activate-consumer` per app | Home directory | Immediately: row 7's rollback, which stops delegated access at the app. Then `disable`. A revoke at connect also works. | |
| -| 11 | Test connections at connect, and the member's add and remove (Paul) | connect, Home directory | The runner always revokes its connections. Paul removes the member. | |
| From row 4 onward, keep Home on an adoption-capable build: **never |
| downgrade it, restore an older snapshot, or delete rows.** |
diff --git a/adopt/binding.go b/adopt/binding.go| index 3cea0e0..c01ea02 100644 |
| --- a/adopt/binding.go |
| +++ b/adopt/binding.go |
| @@ -24,7 +24,7 @@ type BindingInput struct { |
| BeforeLayers, AfterLayers map[string]string |
| TeamSQID, Issuer, ArtifactSHA256, Version string |
| BeforeDelivery, AfterDelivery, NowDelivery Delivery |
| - Witness Witness |
| + Check DeliveryCheck |
| } |
| // EnvironmentBinding is base64url(SHA-256) of the JSON array, in order: |
| @@ -36,18 +36,21 @@ type BindingInput struct { |
| // 4. the before and after layer versions (JSON objects, keys sorted); |
| // 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, |
| +// 7. the delivery check: [app, identity, delivery, after version, |
| // 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. |
| +// "Compute environment_binding") plus the delivery check, which the 522 |
| +// Plan 2 waiver puts in the signed observation; nothing else is bound. |
| +// The check holds the place Paul's witness held until his ruling of |
| +// 2026-11-17 (Home discussion 103); no binding with a witness was ever |
| +// signed. |
| // |
| -// Paul's witness and the delivery observations are inside the binding, |
| -// so Home's signed activation commits to them. The result is as |
| -// sensitive as the digests it covers: it is never printed or logged. |
| +// The delivery check and observations are inside the binding, so Home's |
| +// signed activation commits to them. The result is as sensitive as the |
| +// digests it covers: it is never printed or logged. |
| func EnvironmentBinding(in BindingInput) string { |
| - w := in.Witness |
| + c := in.Check |
| parts := []any{ |
| bindingContext, |
| in.Before, in.After, |
| @@ -55,7 +58,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{w.App, w.Typed, w.Identity, w.Delivery, w.AfterVersion, w.At}, |
| + []any{c.App, c.Identity, c.Delivery, c.AfterVersion, c.At}, |
| } |
| // 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 abd0c7b..cc50192 100644 |
| --- a/adopt/binding_test.go |
| +++ b/adopt/binding_test.go |
| @@ -33,7 +33,7 @@ func bindingInput() BindingInput { |
| AfterLayers: map[string]string{"default": "cv1:" + hex64("2"), "overlay": "none"}, |
| TeamSQID: fixtureSQID, Issuer: Issuer, ArtifactSHA256: hex64("e"), Version: "v1.4.0", |
| 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", |
| + Check: DeliveryCheck{App: "docs", |
| Identity: id, Delivery: d(OpsAgent401, 10), AfterVersion: "cv1:" + hex64("2"), At: at.Add(10 * time.Minute)}, |
| } |
| } |
| @@ -46,7 +46,7 @@ func hex64(c string) string { |
| return out |
| } |
| -func TestBindingIncludesWitnessAndDelivery(t *testing.T) { |
| +func TestBindingIncludesDeliveryCheck(t *testing.T) { |
| in := bindingInput() |
| b := EnvironmentBinding(in) |
| raw, err := base64.RawURLEncoding.DecodeString(b) |
| @@ -67,7 +67,7 @@ func TestBindingIncludesWitnessAndDelivery(t *testing.T) { |
| in.BeforeLayers, in.AfterLayers, |
| 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}, |
| + []any{in.Check.App, in.Check.Identity, in.Check.Delivery, in.Check.AfterVersion, in.Check.At}, |
| } |
| js, err := json.Marshal(parts) |
| if err != nil { |
| @@ -78,15 +78,15 @@ func TestBindingIncludesWitnessAndDelivery(t *testing.T) { |
| t.Fatalf("the binding is not base64url(sha256) of the documented array") |
| } |
| - // Every part moves it, the witness and the three deliveries above all. |
| + // Every part moves it, the delivery check 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) }, |
| + "check app": func(in *BindingInput) { in.Check.App = "sheets" }, |
| + "check identity": func(in *BindingInput) { in.Check.Identity.RecordSeq++ }, |
| + "check delivery": func(in *BindingInput) { in.Check.Delivery.Header = "v1.4.1" }, |
| + "check delivery ops": func(in *BindingInput) { in.Check.Delivery.Ops = OpsAgent200 }, |
| + "check after version": func(in *BindingInput) { in.Check.AfterVersion = "cv1:" + hex64("3") }, |
| + "check time": func(in *BindingInput) { in.Check.At = in.Check.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 }, |
diff --git a/adopt/delivery.go b/adopt/delivery.go| index bffd511..73cf239 100644 |
| --- a/adopt/delivery.go |
| +++ b/adopt/delivery.go |
| @@ -174,13 +174,14 @@ func sameServing(before, now Delivery) error { |
| // Delivered says the restart delivered the new configuration: the same |
| // version and header, no redirect, health 200, and the operations door |
| -// now agent-shaped where it was not. |
| +// now agent-shaped where it was a 404 or, for Slides and Calls, the app's |
| +// own 401. Any other shape before proves nothing about the change. |
| func Delivered(before, now Delivery) error { |
| if err := sameServing(before, now); err != nil { |
| return err |
| } |
| - if before.Ops.agentShaped() { |
| - return errors.New("adopt: the delegated-access door answered before the change") |
| + if before.Ops != OpsAbsent && before.Ops != OpsApp401 { |
| + return errors.New("adopt: the operations door was neither absent nor the app's own before the change") |
| } |
| if !now.Ops.agentShaped() { |
| return errors.New("adopt: the delegated-access door is not answering") |
diff --git a/adopt/delivery_test.go b/adopt/delivery_test.go| index 6b215c2..c746a0e 100644 |
| --- a/adopt/delivery_test.go |
| +++ b/adopt/delivery_test.go |
| @@ -220,6 +220,22 @@ func TestDeliveredRefusesVersionOrHeaderChange(t *testing.T) { |
| } |
| } |
| +// The operations door must move from a 404, or from Slides' and Calls' |
| +// own 401, to agent-access's answer (Paul, 2026-11-17): any other before |
| +// shape proves nothing about what the restart changed. |
| +func TestDeliveredNeedsAbsentOrApp401Before(t *testing.T) { |
| + for _, ops := range []OpsShape{OpsAbsent, OpsApp401} { |
| + if err := Delivered(dl("v1", "v1", 200, ops), dl("v1", "v1", 200, OpsAgent401)); err != nil { |
| + t.Errorf("before %s: refused: %v", ops, err) |
| + } |
| + } |
| + for _, ops := range []OpsShape{OpsOther, OpsAgent200, OpsAgent401, ""} { |
| + if err := Delivered(dl("v1", "v1", 200, ops), dl("v1", "v1", 200, OpsAgent401)); err == nil { |
| + t.Errorf("before %q: accepted", ops) |
| + } |
| + } |
| +} |
| + |
| func TestRevertedRequiresBeforeShape(t *testing.T) { |
| before := dl("v1", "v1", 200, "app-401") |
| if err := Reverted(before, dl("v1", "v1", 200, "app-401")); err != nil { |
diff --git a/adopt/witness.go b/adopt/deliverycheck.go| similarity index 58% |
| rename from adopt/witness.go |
| rename to adopt/deliverycheck.go |
| index c1b5b0e..1173fc3 100644 |
| --- a/adopt/witness.go |
| +++ b/adopt/deliverycheck.go |
| @@ -1,9 +1,12 @@ |
| -// This file records Paul's witnessed check of one app after its restart: |
| -// the spec's manual delivery evidence, in place of 522 Plan 2. |
| +// This file is the runner's delivery check of one app after its restart: |
| +// the delivery evidence recorded in place of 522 Plan 2 (Paul, |
| +// 2026-11-17, Home discussion 103, replacing his witnessed sign-in). |
| package adopt |
| import ( |
| "context" |
| + "crypto/sha256" |
| + "encoding/hex" |
| "errors" |
| "fmt" |
| "net/http" |
| @@ -14,75 +17,78 @@ import ( |
| "amadan.net/oficina/alta/provision" |
| ) |
| -// RecordWitness records Paul's witness for app. It refuses unless all of |
| -// these hold: |
| +// CheckDelivery checks that app's restart delivered its new configuration |
| +// and records the check. artifact is the app's reviewed artifact SHA-256, |
| +// 64 lowercase hex (the config's artifacts). It refuses, recording |
| +// nothing, unless all of these hold: |
| // |
| -// - typed is WitnessSentence(app), surrounding space aside |
| -// (witness-sentence-mismatch), checked before anything is read; |
| -// - the after snapshot exists (witness-after-missing), and the baseline |
| -// it is measured against (witness-baseline-missing); |
| +// - artifact is a reviewed SHA-256 (check-artifact-unreviewed), the |
| +// after snapshot exists (check-after-missing), and so does the |
| +// baseline it is measured against (check-baseline-missing): all |
| +// checked before anything is read; |
| // - a fresh observation's probe passes Delivered against the baseline |
| -// (witness-not-delivered); |
| +// (check-not-delivered): the canonical HTTPS /api/version body and |
| +// X-Carlos-Version unchanged, no redirect, /healthz 200, and GET |
| +// /api/v1/operations now agent-access's answer where it was a 404 or |
| +// the app's own 401; |
| +// - the served release, X-Carlos-Version, hashes to artifact |
| +// (check-artifact-mismatch); |
| // - the fresh identity equals the after snapshot's |
| -// (witness-identity-<code>, one per SameIdentity code); |
| +// (check-identity-<code>, one per SameIdentity code); |
| // - the fresh config equals the after snapshot's, every key's digest, |
| // kind and source and every layer's version |
| -// (witness-config-<code>, one per sameConfig code). |
| +// (check-config-<code>, one per sameConfig code). |
| // |
| -// The witness stores the sentence, the fresh identity and delivery, and |
| -// the after snapshot's write-layer version: it is bound to what was |
| -// observed, not to the clock, and a later change in any of them voids it. |
| -// |
| -// Without apply, it asks for no sentence and stores nothing; it observes |
| -// and refuses as it would with apply. |
| -func RecordWitness(ctx context.Context, s *Store, c *carlosop.Client, h *http.Client, app provision.App, typed string, apply bool) error { |
| +// The check stores the fresh identity and delivery and the after |
| +// snapshot's write-layer version: it is bound to what was observed, not |
| +// to the clock, and a later change in any of them voids it. Run again on |
| +// an unchanged app, it records the check again. |
| +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") |
| } |
| - sentence := WitnessSentence(app) |
| - // Only leading and trailing space is dropped (a terminal line ends in |
| - // a newline); case, inner spacing and punctuation must match exactly. |
| - if apply && strings.TrimSpace(typed) != sentence { |
| - return errors.New("adopt: witness-sentence-mismatch") |
| + if !artifactShape.MatchString(artifact) { |
| + return errors.New("adopt: check-artifact-unreviewed") |
| } |
| after, ok, err := s.After(ctx, app.Slug) |
| if err != nil { |
| return err |
| } |
| if !ok { |
| - return errors.New("adopt: witness-after-missing") |
| + return errors.New("adopt: check-after-missing") |
| } |
| base, ok, err := s.Baseline(ctx, app.Slug) |
| if err != nil { |
| return err |
| } |
| if !ok { |
| - return errors.New("adopt: witness-baseline-missing") |
| + return errors.New("adopt: check-baseline-missing") |
| } |
| fresh, err := Observe(ctx, c, h, app) |
| if err != nil { |
| return err |
| } |
| if err := Delivered(base.Delivery, fresh.Delivery); err != nil { |
| - return fmt.Errorf("adopt: witness-not-delivered: %w", err) |
| + return fmt.Errorf("adopt: check-not-delivered: %w", err) |
| + } |
| + sum := sha256.Sum256([]byte(fresh.Delivery.Header)) |
| + if hex.EncodeToString(sum[:]) != artifact { |
| + return errors.New("adopt: check-artifact-mismatch") |
| } |
| if codes := SameIdentity(after.Identity, fresh.Identity); len(codes) > 0 { |
| for i, code := range codes { |
| - codes[i] = "witness-identity-" + code |
| + codes[i] = "check-identity-" + code |
| } |
| return errors.New("adopt: " + strings.Join(codes, ", ")) |
| } |
| if codes := sameConfig(after, fresh); len(codes) > 0 { |
| for i, code := range codes { |
| - codes[i] = "witness-config-" + code |
| + codes[i] = "check-config-" + code |
| } |
| return errors.New("adopt: " + strings.Join(codes, ", ")) |
| } |
| - if !apply { |
| - return nil |
| - } |
| - return s.SaveWitness(ctx, Witness{ |
| - App: app.Slug, Typed: sentence, |
| + return s.SaveDeliveryCheck(ctx, DeliveryCheck{ |
| + App: app.Slug, |
| Identity: fresh.Identity, Delivery: fresh.Delivery, |
| AfterVersion: after.Layer.Version, |
| At: time.Now().UTC(), |
| @@ -95,8 +101,8 @@ func RecordWitness(ctx context.Context, s *Store, c *carlosop.Client, h *http.Cl |
| // effective config and the write layer's stored vars; layer:<name> for |
| // any layer whose version moved, appeared or went (the write layer's |
| // stored version included); write-layer when the write layer itself |
| -// differs. Unlike Preserved, no key is exempt: the witness describes |
| -// the after snapshot's config exactly. |
| +// differs. Unlike Preserved, no key is exempt: the delivery check |
| +// describes the after snapshot's config exactly. |
| func sameConfig(a, b Snapshot) []string { |
| var out []string |
| if a.WriteLayer != b.WriteLayer || a.Layer.Bundle != b.Layer.Bundle { |
diff --git a/adopt/deliverycheck_test.go b/adopt/deliverycheck_test.go| new file mode 100644 |
| index 0000000..faecdb5 |
| --- /dev/null |
| +++ b/adopt/deliverycheck_test.go |
| @@ -0,0 +1,319 @@ |
| +package adopt |
| + |
| +import ( |
| + "context" |
| + "net/http" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/alta/carlosop" |
| +) |
| + |
| +// checkFixture is an app configured and restarted: its baseline taken |
| +// with the operations door absent, the agent keys stored, the door now |
| +// answering agent-access's challenge, and the after snapshot recorded. |
| +// artifact is the reviewed artifact SHA-256 of the release it serves. |
| +type checkFixture struct { |
| + *carlosFixture |
| + s *Store |
| + after Snapshot |
| + artifact string |
| +} |
| + |
| +func newCheckFixture(t *testing.T, slug string) *checkFixture { |
| + t.Helper() |
| + x := newCarlosFixture(t, slug) |
| + s := newJournal(t) |
| + ctx := context.Background() |
| + base, err := Observe(ctx, x.c, x.h, x.app) |
| + if err != nil { |
| + t.Fatalf("Observe baseline: %v", err) |
| + } |
| + if err := s.SaveBaseline(ctx, x.app.Slug, base); err != nil { |
| + t.Fatal(err) |
| + } |
| + keys := AgentKeys(x.app) |
| + x.f.SetVar(x.app.Slug, "", keys[0], Issuer) |
| + x.f.SetVar(x.app.Slug, "", keys[1], "tm_fixture_sqid") |
| + x.site.ops = agent401 |
| + after, err := Observe(ctx, x.c, x.h, x.app) |
| + if err != nil { |
| + t.Fatalf("Observe after: %v", err) |
| + } |
| + if err := s.SaveAfter(ctx, x.app.Slug, after); err != nil { |
| + t.Fatal(err) |
| + } |
| + return &checkFixture{carlosFixture: x, s: s, after: after, artifact: sha256Hex(valueVersion)} |
| +} |
| + |
| +func (w *checkFixture) check() error { |
| + return CheckDelivery(context.Background(), w.s, w.c, w.h, w.app, w.artifact) |
| +} |
| + |
| +func (w *checkFixture) noCheck(t *testing.T) { |
| + t.Helper() |
| + if _, ok, err := w.s.DeliveryCheck(context.Background(), w.app.Slug); err != nil || ok { |
| + t.Fatalf("a delivery check was recorded (ok %v, err %v)", ok, err) |
| + } |
| +} |
| + |
| +// The check asks Paul for nothing: it observes, compares and records. |
| +func TestDeliveryCheckRecordsBoundObservation(t *testing.T) { |
| + w := newCheckFixture(t, "docs") |
| + if err := w.check(); err != nil { |
| + t.Fatalf("CheckDelivery: %v", err) |
| + } |
| + got, ok, err := w.s.DeliveryCheck(context.Background(), "docs") |
| + if err != nil || !ok { |
| + t.Fatalf("no delivery check (ok %v, err %v)", ok, err) |
| + } |
| + if got.App != "docs" || got.At.IsZero() { |
| + t.Fatalf("delivery check app %q at %v", got.App, got.At) |
| + } |
| + if codes := SameIdentity(got.Identity, w.after.Identity); len(codes) > 0 { |
| + t.Fatalf("check identity differs from the after snapshot's: %v", codes) |
| + } |
| + if got.AfterVersion == "" || got.AfterVersion != w.after.Layer.Version { |
| + t.Fatal("the check is not bound to the after snapshot's write-layer version") |
| + } |
| + if got.Delivery.Ops != OpsAgent401 || got.Delivery.Version != valueVersion || got.Delivery.Header != valueVersion || got.Delivery.Health != 200 || got.Delivery.Redirected { |
| + t.Fatalf("check delivery ops %q health %d", got.Delivery.Ops, got.Delivery.Health) |
| + } |
| +} |
| + |
| +// Slides and Calls answer their own 401 before the change: only |
| +// agent-access's challenge after it counts. |
| +func TestDeliveryCheckAcceptsApp401BecomingAgentChallenge(t *testing.T) { |
| + x := newCarlosFixture(t, "slides") |
| + x.site.ops = app401 |
| + s := newJournal(t) |
| + ctx := context.Background() |
| + base, err := Observe(ctx, x.c, x.h, x.app) |
| + if err != nil || base.Delivery.Ops != OpsApp401 { |
| + t.Fatalf("baseline ops %q, %v", base.Delivery.Ops, err) |
| + } |
| + setupOK(t, s.SaveBaseline(ctx, "slides", base)) |
| + keys := AgentKeys(x.app) |
| + x.f.SetVar("slides", "", keys[0], Issuer) |
| + x.f.SetVar("slides", "", keys[1], "tm_fixture_sqid") |
| + x.site.ops = agent401 |
| + after, err := Observe(ctx, x.c, x.h, x.app) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + setupOK(t, s.SaveAfter(ctx, "slides", after)) |
| + w := &checkFixture{carlosFixture: x, s: s, after: after, artifact: sha256Hex(valueVersion)} |
| + // Still the app's own 401: nothing was delivered. |
| + x.site.ops = app401 |
| + if err := w.check(); err == nil || !strings.HasPrefix(err.Error(), "adopt: check-not-delivered") { |
| + t.Fatalf("app 401 after the restart: err = %v", err) |
| + } |
| + w.noCheck(t) |
| + x.site.ops = agent401 |
| + if err := w.check(); err != nil { |
| + t.Fatalf("agent challenge after the restart: %v", err) |
| + } |
| +} |
| + |
| +func TestDeliveryCheckRefusesWithoutAfterSnapshot(t *testing.T) { |
| + x := newCarlosFixture(t, "docs") |
| + s := newJournal(t) |
| + base, err := Observe(context.Background(), x.c, x.h, x.app) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := s.SaveBaseline(context.Background(), "docs", base); err != nil { |
| + t.Fatal(err) |
| + } |
| + x.site.ops = agent401 |
| + err = CheckDelivery(context.Background(), s, x.c, x.h, x.app, sha256Hex(valueVersion)) |
| + if err == nil || err.Error() != "adopt: check-after-missing" { |
| + t.Fatalf("err = %v", err) |
| + } |
| + if _, ok, _ := s.DeliveryCheck(context.Background(), "docs"); ok { |
| + t.Fatal("recorded a delivery check without an after snapshot") |
| + } |
| +} |
| + |
| +func TestDeliveryCheckRefusesWithoutBaseline(t *testing.T) { |
| + w := newCheckFixture(t, "docs") |
| + s := newJournal(t) |
| + setupOK(t, s.SaveAfter(context.Background(), "docs", w.after)) |
| + w.s = s |
| + if err := w.check(); err == nil || err.Error() != "adopt: check-baseline-missing" { |
| + t.Fatalf("err = %v", err) |
| + } |
| + w.noCheck(t) |
| +} |
| + |
| +// The reviewed artifact is checked before anything is read, and the |
| +// served release must be it. |
| +func TestDeliveryCheckRefusesUnreviewedOrOtherArtifact(t *testing.T) { |
| + for _, artifact := range []string{"", "nothex", strings.ToUpper(sha256Hex(valueVersion))} { |
| + w := newCheckFixture(t, "docs") |
| + w.artifact = artifact |
| + n := len(w.f.Requests()) |
| + if err := w.check(); err == nil || err.Error() != "adopt: check-artifact-unreviewed" { |
| + t.Fatalf("artifact %q: err = %v", artifact, err) |
| + } |
| + if got := w.f.Requests(); len(got) != n { |
| + t.Fatalf("read the console for an unreviewed artifact: %q", got[n:]) |
| + } |
| + w.noCheck(t) |
| + } |
| + w := newCheckFixture(t, "docs") |
| + w.artifact = sha256Hex("v1.3.9") |
| + if err := w.check(); err == nil || err.Error() != "adopt: check-artifact-mismatch" { |
| + t.Fatalf("other artifact: err = %v", err) |
| + } |
| + w.noCheck(t) |
| +} |
| + |
| +func TestDeliveryCheckRefusesWithoutAgentShape(t *testing.T) { |
| + cases := map[string]func(w *checkFixture){ |
| + "absent": func(w *checkFixture) { w.site.ops = nil }, |
| + "app-401": func(w *checkFixture) { w.site.ops = app401 }, |
| + "unhealthy": func(w *checkFixture) { w.site.health = 503 }, |
| + "version moved": func(w *checkFixture) { |
| + w.site.version, w.site.header = "v1.5.0", "v1.5.0" |
| + }, |
| + "redirect": func(w *checkFixture) { w.site.redirectVersion = true }, |
| + } |
| + for name, change := range cases { |
| + t.Run(name, func(t *testing.T) { |
| + w := newCheckFixture(t, "docs") |
| + change(w) |
| + if err := w.check(); err == nil || !strings.HasPrefix(err.Error(), "adopt: check-not-delivered") { |
| + t.Fatalf("err = %v, want check-not-delivered", err) |
| + } |
| + w.noCheck(t) |
| + }) |
| + } |
| +} |
| + |
| +func TestDeliveryCheckRefusesIdentityChangedSinceAfter(t *testing.T) { |
| + cases := map[string]func(in *carlosop.Instance){ |
| + "record": func(in *carlosop.Instance) { in.RecordSeq++ }, |
| + "storage": func(in *carlosop.Instance) { in.Slug = "s-docs-recreated" }, |
| + "region": func(in *carlosop.Instance) { in.Region = "us" }, |
| + } |
| + for name, change := range cases { |
| + 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", |
| + CreatedAt: w.after.Identity.CreatedAt, RecordSeq: w.after.Identity.RecordSeq, |
| + ReplicaAssignment: []byte(w.after.Identity.ReplicaAssignment), |
| + } |
| + change(&in) |
| + w.f.AddInstance(in) |
| + err := w.check() |
| + if err == nil || err.Error() != "adopt: check-identity-"+name { |
| + t.Fatalf("err = %v, want check-identity-%s", err, name) |
| + } |
| + w.noCheck(t) |
| + }) |
| + } |
| +} |
| + |
| +// A check run again on an unchanged app records it again: configure's |
| +// resume and re-check. |
| +func TestDeliveryCheckRepeats(t *testing.T) { |
| + w := newCheckFixture(t, "docs") |
| + setupOK(t, w.check()) |
| + setupOK(t, w.check()) |
| + if _, ok, err := w.s.DeliveryCheck(context.Background(), "docs"); err != nil || !ok { |
| + t.Fatalf("no delivery check after a repeat (ok %v, err %v)", ok, err) |
| + } |
| +} |
| + |
| +// The check is bound to the after snapshot's config: any change since, |
| +// in any key's digest, kind or source, or any layer's version, refuses. |
| +func TestDeliveryCheckRefusesConfigChangedSinceAfter(t *testing.T) { |
| + cases := map[string]struct { |
| + change func(w *checkFixture) |
| + codes []string |
| + }{ |
| + "unrelated key added": {func(w *checkFixture) { |
| + w.f.SetVar("docs", "", "DOCS_EXTRA", "x") |
| + }, []string{"added:DOCS_EXTRA", "layer:default"}}, |
| + "secret resealed": {func(w *checkFixture) { |
| + w.f.SetSecret("docs", "", "DOCS_INSTANCE_KEY") |
| + }, []string{"changed:DOCS_INSTANCE_KEY", "layer:default"}}, |
| + "agent key rewritten": {func(w *checkFixture) { |
| + w.f.SetVar("docs", "", "DOCS_AGENT_TEAM", "tm_other") |
| + }, []string{"changed:DOCS_AGENT_TEAM", "layer:default"}}, |
| + "key unset": {func(w *checkFixture) { |
| + 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") |
| + }, []string{"from:DOCS_ORIGIN", "layer:overlay"}}, |
| + } |
| + for name, tc := range cases { |
| + t.Run(name, func(t *testing.T) { |
| + w := newCheckFixture(t, "docs") |
| + tc.change(w) |
| + err := w.check() |
| + if err == nil || !strings.HasPrefix(err.Error(), "adopt: check-config-") { |
| + t.Fatalf("err = %v, want check-config-<code>", err) |
| + } |
| + for _, code := range tc.codes { |
| + if !strings.Contains(err.Error(), "check-config-"+code) { |
| + t.Fatalf("err = %v, want it to name %s", err, code) |
| + } |
| + } |
| + for _, leak := range []string{"vd1:", "cv1:", "tm_other", "elsewhere"} { |
| + if strings.Contains(err.Error(), leak) { |
| + t.Fatalf("err = %v carries a value", err) |
| + } |
| + } |
| + w.noCheck(t) |
| + }) |
| + } |
| +} |
| + |
| +// app401 is the operations answer Slides and Calls give before adoption: |
| +// their own middleware's 401, not agent-access's challenge. |
| +func app401(rw http.ResponseWriter) { |
| + rw.WriteHeader(401) |
| + _, _ = rw.Write([]byte(`{"error":"unauthorized"}`)) |
| +} |
| + |
| +func TestSameConfigComparesEveryPart(t *testing.T) { |
| + a := afterSnap() |
| + if codes := sameConfig(a, afterSnap()); len(codes) > 0 { |
| + t.Fatalf("identical snapshots differ: %v", codes) |
| + } |
| + cases := map[string]struct { |
| + change func(s *Snapshot) |
| + want string |
| + }{ |
| + "effective digest": {func(s *Snapshot) { s.Vars[0].Digest = "vd1:other" }, "changed:" + a.Vars[0].Key}, |
| + "effective kind": {func(s *Snapshot) { s.Vars[0].Kind = "secret" }, "kind:" + a.Vars[0].Key}, |
| + "effective from": {func(s *Snapshot) { s.Vars[0].From = "environment" }, "from:" + a.Vars[0].Key}, |
| + "effective gone": {func(s *Snapshot) { s.Vars = s.Vars[1:] }, "gone:" + a.Vars[0].Key}, |
| + "stored digest": {func(s *Snapshot) { s.Layer.Vars[0].Digest = "vd1:other" }, "changed:" + a.Layer.Vars[0].Key}, |
| + "stored added": {func(s *Snapshot) { |
| + s.Layer.Vars = append(s.Layer.Vars, carlosop.Var{Key: "DOCS_NEW", Kind: "env", Digest: "vd1:x"}) |
| + }, "added:DOCS_NEW"}, |
| + "write layer version": {func(s *Snapshot) { s.Layer.Version = "cv1:other" }, "layer:default"}, |
| + "write layer": {func(s *Snapshot) { s.WriteLayer = "staging" }, "write-layer"}, |
| + "other layer": {func(s *Snapshot) { s.Layers["environment"] = "cv1:other" }, "layer:environment"}, |
| + "layer gone": {func(s *Snapshot) { delete(s.Layers, "overlay") }, "layer:overlay"}, |
| + } |
| + for name, tc := range cases { |
| + t.Run(name, func(t *testing.T) { |
| + b := afterSnap() |
| + tc.change(&b) |
| + codes := sameConfig(a, b) |
| + found := false |
| + for _, c := range codes { |
| + found = found || c == tc.want |
| + } |
| + if !found { |
| + t.Fatalf("codes = %q, want %q among them", codes, tc.want) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/adopt/gate_adverse_test.go b/adopt/gate_adverse_test.go| index a816f14..50f3474 100644 |
| --- a/adopt/gate_adverse_test.go |
| +++ b/adopt/gate_adverse_test.go |
| @@ -31,11 +31,14 @@ import ( |
| const gateOwner = "owner@adverse.test" |
| // gate is an initialized Home with Plan A done for the six canonical apps. |
| +// js is the adoption journal over the engine's own store, as alta-adopt |
| +// opens it: Plan C's gate reads the engine's steps through it. |
| type gate struct { |
| t *testing.T |
| now time.Time |
| home *fakehome.Home |
| store *provision.Store |
| + js *Store |
| cfg provision.Config |
| team string |
| } |
| @@ -120,10 +123,13 @@ func newGate(t *testing.T) *gate { |
| t.Fatal(err) |
| } |
| t.Cleanup(func() { db.Close() }) |
| - g.store, err = provision.NewStore(context.Background(), db, bytes.Repeat([]byte{4}, 32), g.clock) |
| + g.store, err = provision.NewStore(context.Background(), db, bytes.Repeat([]byte{4}, 32), g.clock, Schema) |
| if err != nil { |
| t.Fatal(err) |
| } |
| + if g.js, err = NewStore(g.store); err != nil { |
| + t.Fatal(err) |
| + } |
| net := &http.Client{Transport: offlineNet{}} |
| g.cfg = provision.Config{ |
| Store: g.store, Home: &homeop.Client{Key: key, Prefilter: pre, Roles: roles, Now: g.clock}, |
| @@ -209,11 +215,12 @@ func (g *gate) refused(app string, obs provision.Observer, want ...string) []str |
| } |
| // gateFixture is an app through configure, as newObserverFixture builds |
| -// it, but for the team Home seeded. |
| +// it, but for the team Home seeded and on the gate's own journal. |
| func (g *gate) fixture(slug string, before ...func(*writeFixture)) *observerFixture { |
| g.t.Helper() |
| t := g.t |
| w := newWriteFixture(t, slug) |
| + w.s = g.js |
| for _, f := range before { |
| f(w) |
| } |
| @@ -228,7 +235,7 @@ func (g *gate) fixture(slug string, before ...func(*writeFixture)) *observerFixt |
| } |
| // finish restarts until delivered, captures the after snapshot and |
| -// records the witness and the pre-plan-a preflight. |
| +// records the delivery check and the pre-plan-a preflight. |
| func (g *gate) finish(w *writeFixture) { |
| g.t.Helper() |
| ctx := context.Background() |
| @@ -239,8 +246,8 @@ func (g *gate) finish(w *writeFixture) { |
| if _, err := CaptureAfter(ctx, w.c, w.h, w.s, w.app); err != nil { |
| g.t.Fatalf("CaptureAfter: %v", err) |
| } |
| - if err := RecordWitness(ctx, w.s, w.c, w.h, w.app, WitnessSentence(w.app), true); err != nil { |
| - g.t.Fatalf("RecordWitness: %v", err) |
| + if err := CheckDelivery(ctx, w.s, w.c, w.h, w.app, sha256Hex(w.site.header)); err != nil { |
| + g.t.Fatalf("CheckDelivery: %v", err) |
| } |
| if err := w.s.SaveHomePreflight(ctx, HomePreflight{Phase: PhasePrePlanA, ProposedID: 1, ProposedSQID: g.team, AttestedAt: at.Add(-time.Hour)}); err != nil { |
| g.t.Fatal(err) |
| @@ -253,14 +260,6 @@ func (g *gate) observer(w *writeFixture) *observerFixture { |
| return x |
| } |
| -// passLiveChecks records every required live check as passed. |
| -func passLiveChecks(t *testing.T, s *Store) { |
| - t.Helper() |
| - for _, c := range RequiredLiveChecks { |
| - setupOK(t, s.SaveCheck(context.Background(), Issuer, c, "passed")) |
| - } |
| -} |
| - |
| // ---- The control: the harness reaches activation when nothing is wrong ---- |
| func TestAdverseControlActivatesWhenEverythingHolds(t *testing.T) { |
| @@ -305,7 +304,7 @@ func (c adverse) run(t *testing.T) { |
| } |
| x := g.fixture(app, before...) |
| if app != CanaryApp { |
| - passLiveChecks(t, x.s) |
| + canaryActive(t, x.s) |
| } |
| if c.edit != nil { |
| c.edit(t, x) |
| @@ -337,8 +336,8 @@ func TestAdverseMissingEvidence(t *testing.T) { |
| }, want: []string{"missing-write"}}, |
| {name: "no after snapshot", edit: func(t *testing.T, x *observerFixture) { x.rejournal(t, func(e *evidence) { e.after = nil }) }, |
| want: []string{"missing-after"}}, |
| - {name: "no witness", edit: func(t *testing.T, x *observerFixture) { x.rejournal(t, func(e *evidence) { e.witness = nil }) }, |
| - want: []string{"missing-witness"}}, |
| + {name: "no delivery check", edit: func(t *testing.T, x *observerFixture) { x.rejournal(t, func(e *evidence) { e.check = nil }) }, |
| + want: []string{"missing-delivery-check"}}, |
| {name: "rolled back", edit: func(t *testing.T, x *observerFixture) { |
| setupOK(t, x.s.SaveRollback(ctx, RollbackRecord{App: x.app.Slug, State: "sent"})) |
| }, want: []string{"rollback-recorded"}}, |
| @@ -347,64 +346,42 @@ func TestAdverseMissingEvidence(t *testing.T) { |
| }) |
| } |
| -// A non-canary app is refused until every live check has passed, and a |
| -// failure refuses it for good. |
| -func TestAdversePlanCRefusedWithoutLiveSuccess(t *testing.T) { |
| - cases := []struct { |
| - name string |
| - checks func(t *testing.T, s *Store) |
| - }{ |
| - {name: "none recorded", checks: func(*testing.T, *Store) {}}, |
| - {name: "one missing", checks: func(t *testing.T, s *Store) { |
| - for _, c := range RequiredLiveChecks[1:] { |
| - setupOK(t, s.SaveCheck(context.Background(), Issuer, c, "passed")) |
| - } |
| - }}, |
| - {name: "one inconclusive", checks: func(t *testing.T, s *Store) { |
| - const unsure = "owner-local-access-kept" |
| - for _, c := range RequiredLiveChecks { |
| - outcome := "passed" |
| - if c == unsure { |
| - outcome = "inconclusive" |
| - } |
| - setupOK(t, s.SaveCheck(context.Background(), Issuer, c, outcome)) |
| - } |
| - }}, |
| - {name: "all inconclusive", checks: func(t *testing.T, s *Store) { |
| - for _, c := range RequiredLiveChecks { |
| - setupOK(t, s.SaveCheck(context.Background(), Issuer, c, "inconclusive")) |
| - } |
| - }}, |
| - {name: "one failed", checks: func(t *testing.T, s *Store) { |
| - passLiveChecks(t, s) |
| - setupOK(t, s.SaveCheck(context.Background(), Issuer, "revoked-membership-refused", "failed:allowed")) |
| - }}, |
| - {name: "failed, then passed again", checks: func(t *testing.T, s *Store) { |
| - setupOK(t, s.SaveCheck(context.Background(), Issuer, "owner-allowed", "failed:denied")) |
| - passLiveChecks(t, s) |
| - }}, |
| - {name: "local permission check failed", checks: func(t *testing.T, s *Store) { |
| - passLiveChecks(t, s) |
| - setupOK(t, s.SaveCheck(context.Background(), Issuer, "member-no-local-permission-refused", "failed:allowed")) |
| - }}, |
| - {name: "local permission check failed, rest passed after", checks: func(t *testing.T, s *Store) { |
| - setupOK(t, s.SaveCheck(context.Background(), Issuer, "member-no-local-permission-refused", "failed:allowed")) |
| - passLiveChecks(t, s) |
| - }}, |
| - } |
| - for _, tc := range cases { |
| - t.Run(tc.name, func(t *testing.T) { |
| - g := newGate(t) |
| - x := g.fixture("docs") |
| - tc.checks(t, x.s) |
| - g.refused("docs", x.o, "live-checks-missing") |
| - }) |
| - } |
| - t.Run("canary needs none", func(t *testing.T) { |
| +// Plan C waits on Plan B alone (Paul, 2026-11-17), through the real |
| +// engine and Home: a non-canary app is refused until Plan B has activated |
| +// the canary, then activates with no live check recorded; a canary |
| +// rolled back since closes the gate again. |
| +func TestAdversePlanCWaitsOnPlanB(t *testing.T) { |
| + t.Run("before Plan B", func(t *testing.T) { |
| + g := newGate(t) |
| + g.fixture("calendar") |
| + x := g.fixture("docs") |
| + g.refused("docs", x.o, "canary-not-active") |
| + }) |
| + t.Run("after Plan B", func(t *testing.T) { |
| + g := newGate(t) |
| + cal := g.fixture("calendar") |
| + docs := g.fixture("docs") |
| + if r := g.attempt("calendar", cal.o); r.State != "done" || g.home.InstanceState("calendar") != "live" { |
| + t.Fatalf("Plan B: run %s %q", r.State, r.Code) |
| + } |
| + if r := g.attempt("docs", docs.o); r.State != "done" || g.home.InstanceState("docs") != "live" { |
| + t.Fatalf("Plan C: run %s %q, docs %q", r.State, r.Code, g.home.InstanceState("docs")) |
| + } |
| + }) |
| + t.Run("canary rolled back after Plan B", func(t *testing.T) { |
| g := newGate(t) |
| - x := g.fixture("calendar") |
| - if r := g.attempt("calendar", x.o); r.State != "done" { |
| - t.Fatalf("run %s %q", r.State, r.Code) |
| + cal := g.fixture("calendar") |
| + docs := g.fixture("docs") |
| + if r := g.attempt("calendar", cal.o); r.State != "done" { |
| + t.Fatalf("Plan B: run %s %q", r.State, r.Code) |
| + } |
| + setupOK(t, g.js.SaveRollback(context.Background(), RollbackRecord{App: CanaryApp, State: "restarted"})) |
| + r := g.attempt("docs", docs.o) |
| + if r.State != "parked" || !strings.Contains(r.Code, "canary-not-active") { |
| + t.Fatalf("Plan C after a canary rollback: run %s %q", r.State, r.Code) |
| + } |
| + if g.home.InstanceState("docs") == "live" { |
| + t.Fatal("docs was activated") |
| } |
| }) |
| } |
| @@ -438,15 +415,15 @@ func TestAdverseChangedIdentity(t *testing.T) { |
| // A second record answering for the host is an error in the read |
| // (never a silent pick), so the record host is staged in the journal. |
| {name: "record host", edit: func(t *testing.T, x *observerFixture) { |
| - x.rejournal(t, func(e *evidence) { e.witness.Identity.RecordHost = "calendar-record.example.test" }) |
| + x.rejournal(t, func(e *evidence) { e.check.Identity.RecordHost = "calendar-record.example.test" }) |
| }, want: []string{"identity-instance"}}, |
| // The journal's own records describe another environment or |
| // ownership than the one the host now serves. |
| {name: "environment", edit: func(t *testing.T, x *observerFixture) { |
| - x.rejournal(t, func(e *evidence) { e.witness.Identity.Environment = "another" }) |
| + x.rejournal(t, func(e *evidence) { e.check.Identity.Environment = "another" }) |
| }, want: []string{"identity-environment"}}, |
| {name: "owned", edit: func(t *testing.T, x *observerFixture) { |
| - x.rejournal(t, func(e *evidence) { e.witness.Identity.Owned = true }) |
| + x.rejournal(t, func(e *evidence) { e.check.Identity.Owned = true }) |
| }, want: []string{"identity-owned"}}, |
| {name: "baseline's owner differs", edit: func(t *testing.T, x *observerFixture) { |
| x.rejournal(t, func(e *evidence) { e.base.Identity.Owned = true }) |
| @@ -510,30 +487,30 @@ func appNamedStatic(slug string) provision.App { |
| return a |
| } |
| -// ---- Superseded witness ---- |
| +// ---- Superseded delivery check ---- |
| -func TestAdverseSupersededWitness(t *testing.T) { |
| +func TestAdverseSupersededDeliveryCheck(t *testing.T) { |
| runAdverse(t, []adverse{ |
| {name: "after version changed", edit: func(t *testing.T, x *observerFixture) { |
| // A platform writer adds a key and the after snapshot is |
| - // taken again: the witness saw the earlier version. |
| + // taken again: the check saw the earlier version. |
| x.f.PlatformWrite("calendar", "", "CALENDAR_PLATFORM_NOTE", "n") |
| if _, err := CaptureAfter(context.Background(), x.c, x.h, x.s, x.app); err != nil { |
| t.Fatalf("CaptureAfter: %v", err) |
| } |
| - }, want: []string{"witness-superseded"}}, |
| - {name: "witness saw another after version", edit: func(t *testing.T, x *observerFixture) { |
| - x.rejournal(t, func(e *evidence) { e.witness.AfterVersion = "cv1:" + hex64("9") }) |
| - }, want: []string{"witness-superseded"}}, |
| + }, want: []string{"delivery-check-superseded"}}, |
| + {name: "check saw another after version", edit: func(t *testing.T, x *observerFixture) { |
| + x.rejournal(t, func(e *evidence) { e.check.AfterVersion = "cv1:" + hex64("9") }) |
| + }, want: []string{"delivery-check-superseded"}}, |
| {name: "delivered version changed", edit: func(t *testing.T, x *observerFixture) { |
| - x.rejournal(t, func(e *evidence) { e.witness.Delivery.Version = "v1.3.9" }) |
| - }, want: []string{"witness-superseded"}}, |
| + x.rejournal(t, func(e *evidence) { e.check.Delivery.Version = "v1.3.9" }) |
| + }, want: []string{"delivery-check-superseded"}}, |
| {name: "delivered header changed", edit: func(t *testing.T, x *observerFixture) { |
| - x.rejournal(t, func(e *evidence) { e.witness.Delivery.Header = "v1.3.9" }) |
| - }, want: []string{"witness-superseded"}}, |
| + x.rejournal(t, func(e *evidence) { e.check.Delivery.Header = "v1.3.9" }) |
| + }, want: []string{"delivery-check-superseded"}}, |
| {name: "redeployed since", edit: func(t *testing.T, x *observerFixture) { |
| x.site.version, x.site.header = "v1.5.0", "v1.5.0" |
| - }, want: []string{"witness-superseded"}}, |
| + }, want: []string{"delivery-check-superseded"}}, |
| }) |
| } |
| @@ -542,9 +519,9 @@ func TestAdverseSupersededWitness(t *testing.T) { |
| func TestAdverseChangedDelivery(t *testing.T) { |
| runAdverse(t, []adverse{ |
| {name: "version body", edit: func(t *testing.T, x *observerFixture) { x.site.version = "v9.9.9" }, |
| - want: []string{"not-delivered", "version-header-mismatch", "witness-superseded"}}, |
| + want: []string{"not-delivered", "version-header-mismatch", "delivery-check-superseded"}}, |
| {name: "header", edit: func(t *testing.T, x *observerFixture) { x.site.header = "v9.9.9" }, |
| - want: []string{"not-delivered", "version-header-mismatch", "witness-superseded"}}, |
| + want: []string{"not-delivered", "version-header-mismatch", "delivery-check-superseded"}}, |
| {name: "redirect", edit: func(t *testing.T, x *observerFixture) { x.site.redirectVersion = true }, want: []string{"not-delivered"}}, |
| {name: "healthz 503", edit: func(t *testing.T, x *observerFixture) { x.site.health = 503 }, want: []string{"not-delivered"}}, |
| {name: "operations reverted to app-401", edit: func(t *testing.T, x *observerFixture) { |
diff --git a/adopt/live.go b/adopt/live.go| deleted file mode 100644 |
| index 08d5fcc..0000000 |
| --- a/adopt/live.go |
| +++ /dev/null |
| @@ -1,642 +0,0 @@ |
| -// This file runs the live checks: against oficina-connect, with a |
| -// throwaway test account and Paul's own, it proves that a non-member is |
| -// refused, that a member lacking local permission is refused, and that |
| -// removing a member or revoking a connection refuses the very request |
| -// that worked before, while local access stays. Plan C waits on them. |
| -package adopt |
| - |
| -import ( |
| - "bytes" |
| - "context" |
| - "encoding/json" |
| - "errors" |
| - "fmt" |
| - "io" |
| - "net/http" |
| - "net/url" |
| - "os" |
| - "regexp" |
| - "slices" |
| - "strconv" |
| - "strings" |
| - "sync" |
| - "time" |
| - |
| - access "amadan.net/oficina/agent-access.git" |
| - "amadan.net/oficina/agent-access.git/client" |
| -) |
| - |
| -// Variables only so tests can reach the fake connect and move the clock. |
| -var ( |
| - liveTransport http.RoundTripper // nil: http.DefaultTransport |
| - liveNow = time.Now |
| - liveOwnerAttempts = 3 |
| -) |
| - |
| -// The live checks' outcomes as SaveCheck records them. |
| -const ( |
| - livePassed = "passed" |
| - liveInconclusive = "inconclusive" |
| -) |
| - |
| -// liveScope is the one scope the checks ask connect for. |
| -const liveScope = "calendar:read" |
| - |
| -// Prompter asks Paul to type sentence once he has done what it says. It |
| -// returns nil only when he typed it exactly. |
| -type Prompter interface { |
| - Ask(ctx context.Context, sentence string) error |
| -} |
| - |
| -// MemoryStore is a client.Store that keeps one connection's credentials |
| -// in memory only: nothing is written to disk or to a keyring. Load and |
| -// Save copy the token, so the store's own copy is never shared. |
| -type MemoryStore struct { |
| - mu sync.Mutex |
| - creds client.Credentials |
| - ok bool |
| -} |
| - |
| -func copyCreds(c client.Credentials) client.Credentials { |
| - if c.Token != nil { |
| - t := *c.Token |
| - c.Token = &t |
| - } |
| - return c |
| -} |
| - |
| -// Load returns a copy of the stored credentials. |
| -func (m *MemoryStore) Load() (client.Credentials, error) { |
| - m.mu.Lock() |
| - defer m.mu.Unlock() |
| - if !m.ok { |
| - return client.Credentials{}, errors.New("adopt: not connected") |
| - } |
| - return copyCreds(m.creds), nil |
| -} |
| - |
| -// Save keeps a copy of c. |
| -func (m *MemoryStore) Save(c client.Credentials) error { |
| - m.mu.Lock() |
| - defer m.mu.Unlock() |
| - m.creds, m.ok = copyCreds(c), true |
| - return nil |
| -} |
| - |
| -// Delete forgets the credentials. |
| -func (m *MemoryStore) Delete() error { |
| - m.mu.Lock() |
| - defer m.mu.Unlock() |
| - m.creds, m.ok = client.Credentials{}, false |
| - return nil |
| -} |
| - |
| -// expiry is the stored access token's expiry, zero when there is none. |
| -func (m *MemoryStore) expiry() time.Time { |
| - m.mu.Lock() |
| - defer m.mu.Unlock() |
| - if !m.ok || m.creds.Token == nil { |
| - return time.Time{} |
| - } |
| - return m.creds.Token.Expiry |
| -} |
| - |
| -// savedRequest is one authenticated operations request exactly as it was |
| -// sent, kept to be replayed, and the expiry of its bearer. |
| -type savedRequest struct { |
| - method, url string |
| - body []byte |
| - bearer []byte |
| - expiry time.Time |
| -} |
| - |
| -// zero overwrites the saved body and bearer. |
| -func (r *savedRequest) zero() { |
| - if r == nil { |
| - return |
| - } |
| - clear(r.body) |
| - clear(r.bearer) |
| - *r = savedRequest{} |
| -} |
| - |
| -// exchange is one operations call: the request as sent, and the answer |
| -// (status 0 when none came). |
| -type exchange struct { |
| - req savedRequest |
| - status int |
| - header http.Header |
| - body []byte |
| -} |
| - |
| -// recorder sits under a client's HTTP and keeps every operations request |
| -// it sent and the answer, so a request can be replayed byte for byte and |
| -// every captured bearer and body zeroed at the end. last is the newest. |
| -type recorder struct { |
| - base http.RoundTripper |
| - last *exchange |
| - all []*exchange |
| -} |
| - |
| -// zero overwrites every captured request and answer body. |
| -func (r *recorder) zero() { |
| - for _, ex := range r.all { |
| - ex.req.zero() |
| - clear(ex.body) |
| - ex.body, ex.header = nil, nil |
| - } |
| - r.all, r.last = nil, nil |
| -} |
| - |
| -func (r *recorder) RoundTrip(req *http.Request) (*http.Response, error) { |
| - if req.Method != http.MethodPost || !strings.HasPrefix(req.URL.Path, "/api/v1/operations/") { |
| - return r.base.RoundTrip(req) |
| - } |
| - ex := &exchange{req: savedRequest{method: req.Method, url: req.URL.String()}} |
| - if req.GetBody != nil { |
| - b, err := req.GetBody() |
| - if err != nil { |
| - return nil, errors.New("adopt: live request unreadable") |
| - } |
| - ex.req.body, err = io.ReadAll(b) |
| - b.Close() |
| - if err != nil { |
| - return nil, errors.New("adopt: live request unreadable") |
| - } |
| - } |
| - bearer, ok := strings.CutPrefix(req.Header.Get("Authorization"), "Bearer ") |
| - if !ok || bearer == "" || len(req.Header.Values("Authorization")) != 1 { |
| - return nil, errors.New("adopt: live request not authenticated") |
| - } |
| - ex.req.bearer = []byte(bearer) |
| - r.last = ex |
| - r.all = append(r.all, ex) |
| - resp, err := r.base.RoundTrip(req) |
| - if err != nil { |
| - return nil, err |
| - } |
| - body, err := io.ReadAll(io.LimitReader(resp.Body, client.MaxResponse+1)) |
| - resp.Body.Close() |
| - if err != nil { |
| - return nil, errors.New("adopt: live answer unreadable") |
| - } |
| - ex.status, ex.header, ex.body = resp.StatusCode, resp.Header.Clone(), body |
| - resp.Body = io.NopCloser(bytes.NewReader(body)) |
| - return resp, nil |
| -} |
| - |
| -// liveConn is one connection to connect: a client over a MemoryStore, |
| -// with the recorder under it. |
| -type liveConn struct { |
| - c *client.Client |
| - store *MemoryStore |
| - rec *recorder |
| - out bool // signed out: connect revoked it and the store is empty |
| -} |
| - |
| -func liveBase() http.RoundTripper { |
| - if liveTransport != nil { |
| - return liveTransport |
| - } |
| - return http.DefaultTransport |
| -} |
| - |
| -func newLiveConn() *liveConn { |
| - store := &MemoryStore{} |
| - rec := &recorder{base: liveBase()} |
| - c := client.New(store) |
| - c.HTTP = &http.Client{Transport: rec, Timeout: 30 * time.Second, |
| - CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }} |
| - return &liveConn{c: c, store: store, rec: rec} |
| -} |
| - |
| -// call makes one operation call and returns the exchange, nil when no |
| -// request was sent, and the client's own error: a success it could not |
| -// read or decode (oversized, invalid JSON) is an error there. The |
| -// bearer's expiry is taken from the store as the call left it. |
| -func (l *liveConn) call(ctx context.Context, op string, input []byte) (*exchange, error) { |
| - l.rec.last = nil |
| - _, err := l.c.Call(ctx, op, input) |
| - ex := l.rec.last |
| - l.rec.last = nil |
| - if ex != nil { |
| - ex.req.expiry = l.store.expiry() |
| - } |
| - return ex, err |
| -} |
| - |
| -// succeeded is the answer to a call that must succeed: a 2xx counts only |
| -// when the client read and decoded it; a malformed or oversized success |
| -// proves nothing and is ansOther. |
| -func succeeded(ex *exchange, callErr error) string { |
| - answer := answerOfExchange(ex) |
| - if answer == ansAllowed && callErr != nil { |
| - return ansOther |
| - } |
| - return answer |
| -} |
| - |
| -// The answers a check can see, as fixed codes. |
| -const ( |
| - ansAllowed = "allowed" // 2xx |
| - ansUnauthenticated = "unauthenticated" // 401 with agent-access's challenge |
| - ansForbidden = "forbidden" // 403 with agent-access's forbidden body |
| - ansNotFound = "not_found" // 404 with agent-access's not_found body |
| - ansOther = "other" // anything else: no answer, 3xx, 5xx, another 4xx or body |
| -) |
| - |
| -// answerOf classifies a status, header and body. A refusal counts only in |
| -// agent-access's own shape: the 401 is the Bearer challenge Probe calls |
| -// agent-401, and a 403 or 404 carries {"error":{"code":…}} with the |
| -// matching code. |
| -func answerOf(status int, h http.Header, body []byte) string { |
| - switch { |
| - case status >= 200 && status < 300: |
| - return ansAllowed |
| - case status == http.StatusUnauthorized: |
| - if shape(status, h, body) == OpsAgent401 { |
| - return ansUnauthenticated |
| - } |
| - case status == http.StatusForbidden: |
| - if agentCode(body) == "forbidden" { |
| - return ansForbidden |
| - } |
| - case status == http.StatusNotFound: |
| - if agentCode(body) == "not_found" { |
| - return ansNotFound |
| - } |
| - } |
| - return ansOther |
| -} |
| - |
| -func agentCode(body []byte) string { |
| - var b struct { |
| - Error struct { |
| - Code string `json:"code"` |
| - } `json:"error"` |
| - } |
| - if access.DecodeJSON(body, &b) != nil { |
| - return "" |
| - } |
| - return b.Error.Code |
| -} |
| - |
| -func answerOfExchange(ex *exchange) string { |
| - if ex == nil || ex.status == 0 { |
| - return ansOther |
| - } |
| - return answerOf(ex.status, ex.header, ex.body) |
| -} |
| - |
| -// mustRefuse is the outcome of a call that must be refused: passed on one |
| -// of refusals, failed:allowed on success, inconclusive otherwise. |
| -func mustRefuse(answer string, refusals ...string) string { |
| - switch { |
| - case answer == ansAllowed: |
| - return "failed:" + ansAllowed |
| - case slices.Contains(refusals, answer): |
| - return livePassed |
| - } |
| - return liveInconclusive |
| -} |
| - |
| -// mustSucceed is the outcome of a call that must succeed: passed on |
| -// success, failed:<code> on an agent-access refusal, inconclusive when |
| -// nothing was proved either way. |
| -func mustSucceed(answer string) string { |
| - switch answer { |
| - case ansAllowed: |
| - return livePassed |
| - case ansUnauthenticated, ansForbidden, ansNotFound: |
| - return "failed:" + answer |
| - } |
| - return liveInconclusive |
| -} |
| - |
| -// liveOutcome is what SaveCheck accepts: passed, inconclusive, or |
| -// failed:<code> with a fixed lower-case code. |
| -var liveOutcome = regexp.MustCompile(`^(passed|inconclusive|failed:[a-z][a-z_-]*)$`) |
| - |
| -// httpsOrigin reports whether s is exactly a plain https origin, |
| -// https://host[:port], and nothing more. |
| -func httpsOrigin(s string) bool { |
| - u, err := url.Parse(s) |
| - return err == nil && u.Scheme == "https" && u.Host != "" && s == u.Scheme+"://"+u.Host |
| -} |
| - |
| -// errLiveSignOut is a connection connect did not revoke. |
| -var errLiveSignOut = errors.New("adopt: live-sign-out-failed") |
| - |
| -// RunLive runs the live checks against connect at server for the team |
| -// sqid, recording each outcome with SaveCheck, with server's origin: |
| -// passed, failed:<code> or inconclusive. server must be Issuer, the |
| -// origin the apps were told to trust; any other is refused before |
| -// anything is contacted. It stops at the first check that does not pass; a |
| -// failure keeps Plan C refused for good, an inconclusive check only until |
| -// it passes on a later run. Only the owner's revocation check repeats on |
| -// its own, with a fresh connection, up to liveOwnerAttempts times. |
| -// |
| -// The test account must have signed in to calendar.oficina.works once, |
| -// and foreignEventID names one of Paul's own events it cannot see. |
| -// |
| -// Every connection RunLive makes is signed out (connect revokes it) |
| -// before it returns, whatever happened, and the saved requests and |
| -// tokens are zeroed. Without apply it prints the steps and contacts |
| -// nothing: no browser, no prompt, no request, no record. Everything it |
| -// says goes to out (os.Stdout when nil). |
| -func RunLive(ctx context.Context, out io.Writer, server, sqid string, p Prompter, s *Store, open func(string) error, foreignEventID string, apply bool) (err error) { |
| - u, perr := url.Parse(server) |
| - switch { |
| - case perr != nil || u.Scheme != "https" || u.Host == "" || u.User != nil || u.RawQuery != "" || u.Fragment != "" || u.Path != "" && u.Path != "/": |
| - return errors.New("adopt: " + LiveNeedOrigin) |
| - case u.Scheme+"://"+u.Host != Issuer: |
| - // Plan C trusts these checks for the apps that trust Issuer: |
| - // checks against any other deployment prove nothing about it. |
| - return errors.New("adopt: " + LiveNeedIssuer) |
| - case sqid == "": |
| - return errors.New("adopt: " + LiveNeedTeam) |
| - } |
| - event, perr := strconv.ParseInt(foreignEventID, 10, 64) |
| - if perr != nil || event < 1 || strconv.FormatInt(event, 10) != foreignEventID { |
| - return errors.New("adopt: " + LiveNeedEvent) |
| - } |
| - if out == nil { |
| - out = os.Stdout |
| - } |
| - if !apply { |
| - for _, line := range LiveSteps { |
| - fmt.Fprintln(out, line) |
| - } |
| - return nil |
| - } |
| - if s == nil || p == nil || open == nil { |
| - return errors.New("adopt: " + LiveNeedRunners) |
| - } |
| - r := &liveRun{out: out, server: u.Scheme + "://" + u.Host, sqid: sqid, event: event, p: p, s: s, open: open} |
| - defer func() { err = errors.Join(err, r.close()) }() |
| - return r.run(ctx) |
| -} |
| - |
| -type liveRun struct { |
| - out io.Writer |
| - server, sqid string |
| - event int64 |
| - p Prompter |
| - s *Store |
| - open func(string) error |
| - conns []*liveConn |
| - saved []*savedRequest |
| -} |
| - |
| -func (r *liveRun) say(line string) { fmt.Fprintln(r.out, line) } |
| - |
| -// record saves name's outcome. Anything but passed stops the run, with an |
| -// error naming the check and the outcome only. |
| -func (r *liveRun) record(ctx context.Context, name, outcome string) error { |
| - if err := r.s.SaveCheck(ctx, r.server, name, outcome); err != nil { |
| - return err |
| - } |
| - if outcome != livePassed { |
| - return errors.New("adopt: live-" + name + " " + outcome) |
| - } |
| - return nil |
| -} |
| - |
| -// connect signs a new connection in through the browser, asking connect |
| -// for liveScope alone. It is kept for close whatever happens. |
| -func (r *liveRun) connect(ctx context.Context) (*liveConn, error) { |
| - l := newLiveConn() |
| - r.conns = append(r.conns, l) |
| - if err := l.c.Login(ctx, r.server, []string{liveScope}, r.open); err != nil { |
| - return nil, errors.New("adopt: live-sign-in-failed") |
| - } |
| - return l, nil |
| -} |
| - |
| -// teamed reports whether l's connection lists the team; ok is false when |
| -// connect did not answer. |
| -func (r *liveRun) teamed(ctx context.Context, l *liveConn) (in, ok bool) { |
| - info, err := l.c.Connection(ctx) |
| - if err != nil { |
| - return false, false |
| - } |
| - return slices.Contains(info.Teams, r.sqid), true |
| -} |
| - |
| -// signOut has connect revoke l and empties its store. |
| -func (r *liveRun) signOut(ctx context.Context, l *liveConn) error { |
| - if l.out { |
| - return nil |
| - } |
| - if err := l.c.Logout(ctx); err != nil { |
| - return errLiveSignOut |
| - } |
| - l.out = true |
| - return nil |
| -} |
| - |
| -// keep saves ex's request for replay and for zeroing. |
| -func (r *liveRun) keep(ex *exchange) *savedRequest { |
| - c := ex.req |
| - r.saved = append(r.saved, &c) |
| - ex.req = savedRequest{} |
| - return &c |
| -} |
| - |
| -func (r *liveRun) busyInput() []byte { |
| - start := liveNow().UTC().Truncate(time.Minute) |
| - b, _ := json.Marshal(map[string]string{ |
| - "team": r.sqid, "start": start.Format(time.RFC3339), "end": start.Add(7 * 24 * time.Hour).Format(time.RFC3339), |
| - }) |
| - return b |
| -} |
| - |
| -func (r *liveRun) eventInput() []byte { |
| - b, _ := json.Marshal(map[string]any{"team": r.sqid, "id": r.event}) |
| - return b |
| -} |
| - |
| -// replay sends c again exactly, with a plain client that follows no |
| -// redirect, and requires an authorization refusal: agent-access's 401 |
| -// challenge or its 403. A bearer that had expired before the answer came |
| -// back proves nothing, and is inconclusive without being sent if it |
| -// already had. |
| -func (r *liveRun) replay(ctx context.Context, c *savedRequest) string { |
| - if c.expiry.IsZero() || !liveNow().Before(c.expiry) { |
| - return liveInconclusive |
| - } |
| - req, err := http.NewRequestWithContext(ctx, c.method, c.url, bytes.NewReader(c.body)) |
| - if err != nil { |
| - return liveInconclusive |
| - } |
| - req.Header.Set("Authorization", "Bearer "+string(c.bearer)) |
| - req.Header.Set("Content-Type", "application/json") |
| - h := &http.Client{Transport: liveBase(), Timeout: 30 * time.Second, |
| - CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }} |
| - resp, err := h.Do(req) |
| - if err != nil { |
| - return liveInconclusive |
| - } |
| - body, err := io.ReadAll(io.LimitReader(resp.Body, client.MaxResponse+1)) |
| - resp.Body.Close() |
| - if err != nil || !liveNow().Before(c.expiry) { |
| - return liveInconclusive |
| - } |
| - return mustRefuse(answerOf(resp.StatusCode, resp.Header, body), ansUnauthenticated, ansForbidden) |
| -} |
| - |
| -func (r *liveRun) run(ctx context.Context) error { |
| - // 1. non-member-refused: the test account, not yet a member, is |
| - // refused a call to the team. |
| - r.say(LiveSayTestSignIn) |
| - a, err := r.connect(ctx) |
| - if err != nil { |
| - return errors.Join(err, r.record(ctx, "non-member-refused", liveInconclusive)) |
| - } |
| - if in, ok := r.teamed(ctx, a); !ok || in { |
| - return r.record(ctx, "non-member-refused", liveInconclusive) |
| - } |
| - // A success, however malformed, is a non-member let through. |
| - ex, _ := a.call(ctx, "calendar_free_busy", r.busyInput()) |
| - if err := r.record(ctx, "non-member-refused", mustRefuse(answerOfExchange(ex), ansUnauthenticated, ansForbidden, ansNotFound)); err != nil { |
| - return err |
| - } |
| - if err := r.signOut(ctx, a); err != nil { |
| - return err |
| - } |
| - |
| - // 2. Paul adds the member; the test account connects again and |
| - // ticks the team. |
| - if err := r.p.Ask(ctx, LiveAddedMember); err != nil { |
| - return err |
| - } |
| - r.say(LiveSayTestTeam) |
| - b, err := r.connect(ctx) |
| - if err != nil { |
| - return errors.Join(err, r.record(ctx, "member-allowed", liveInconclusive)) |
| - } |
| - if in, ok := r.teamed(ctx, b); !ok || !in { |
| - return r.record(ctx, "member-allowed", liveInconclusive) |
| - } |
| - |
| - // 3. member-allowed: the member's call succeeds, and is kept. |
| - ex, callErr := b.call(ctx, "calendar_free_busy", r.busyInput()) |
| - if err := r.record(ctx, "member-allowed", mustSucceed(succeeded(ex, callErr))); err != nil { |
| - return err |
| - } |
| - c := r.keep(ex) |
| - |
| - // 4. member-no-local-permission-refused: membership grants no local |
| - // permission, so Paul's event stays out of reach. |
| - ex, _ = b.call(ctx, "calendar_get_event", r.eventInput()) |
| - if err := r.record(ctx, "member-no-local-permission-refused", mustRefuse(answerOfExchange(ex), ansForbidden, ansNotFound)); err != nil { |
| - return err |
| - } |
| - |
| - // 5. revoked-membership-refused: once Paul removes the member, the |
| - // same request, the same bearer, is refused. |
| - if err := r.p.Ask(ctx, LiveRemovedMember); err != nil { |
| - return err |
| - } |
| - if err := r.record(ctx, "revoked-membership-refused", r.replay(ctx, c)); err != nil { |
| - return err |
| - } |
| - if err := r.signOut(ctx, b); err != nil { |
| - return err |
| - } |
| - |
| - // 6. local-access-kept. |
| - if err := r.p.Ask(ctx, LiveLocalAccessKept); err != nil { |
| - return err |
| - } |
| - if err := r.record(ctx, "local-access-kept", livePassed); err != nil { |
| - return err |
| - } |
| - |
| - // 7. owner-allowed and owner-revoked-refused, repeated with a fresh |
| - // connection while the answer proves nothing either way. |
| - for attempt := 1; ; attempt++ { |
| - outcome, err := r.owner(ctx) |
| - if err != nil { |
| - return err |
| - } |
| - if outcome == livePassed { |
| - break |
| - } |
| - if !strings.HasPrefix(outcome, "failed:") && attempt < liveOwnerAttempts { |
| - continue |
| - } |
| - return errors.New("adopt: live-owner-revoked-refused " + outcome) |
| - } |
| - |
| - // owner-local-access-kept. |
| - if err := r.p.Ask(ctx, LiveOwnerLocalAccessKept); err != nil { |
| - return err |
| - } |
| - return r.record(ctx, "owner-local-access-kept", livePassed) |
| -} |
| - |
| -// owner is one attempt at step 7. It returns owner-revoked-refused's |
| -// outcome once recorded, or an error when the attempt stopped before it: |
| -// owner-allowed did not pass, or connect would not revoke. |
| -func (r *liveRun) owner(ctx context.Context) (string, error) { |
| - r.say(LiveSayOwnerSignIn) |
| - o, err := r.connect(ctx) |
| - if err != nil { |
| - return "", errors.Join(err, r.record(ctx, "owner-allowed", liveInconclusive)) |
| - } |
| - if in, ok := r.teamed(ctx, o); !ok || !in { |
| - return "", r.record(ctx, "owner-allowed", liveInconclusive) |
| - } |
| - ex, callErr := o.call(ctx, "calendar_free_busy", r.busyInput()) |
| - if err := r.record(ctx, "owner-allowed", mustSucceed(succeeded(ex, callErr))); err != nil { |
| - return "", err |
| - } |
| - c := r.keep(ex) |
| - // At e4ea914 Logout revokes at connect, then deletes the store. |
| - if err := r.signOut(ctx, o); err != nil { |
| - return "", err |
| - } |
| - outcome := r.replay(ctx, c) |
| - if err := r.s.SaveCheck(ctx, r.server, "owner-revoked-refused", outcome); err != nil { |
| - return "", err |
| - } |
| - return outcome, nil |
| -} |
| - |
| -// close signs out every connection still open, on a context of its own so |
| -// a cancelled run still revokes, then zeroes every saved request and |
| -// token. A connection connect would not revoke is errLiveSignOut. |
| -func (r *liveRun) close() error { |
| - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| - defer cancel() |
| - var failed bool |
| - for _, l := range r.conns { |
| - if l.out { |
| - continue |
| - } |
| - if _, err := l.store.Load(); err != nil { |
| - // Never connected: nothing to revoke. |
| - l.out = true |
| - continue |
| - } |
| - if r.signOut(ctx, l) != nil { |
| - failed = true |
| - } |
| - l.store.Delete() |
| - } |
| - for _, c := range r.saved { |
| - c.zero() |
| - } |
| - for _, l := range r.conns { |
| - l.rec.zero() |
| - l.store.Delete() |
| - } |
| - r.conns, r.saved = nil, nil |
| - if failed { |
| - return errLiveSignOut |
| - } |
| - return nil |
| -} |
| - |
| -var _ client.Store = (*MemoryStore)(nil) |
diff --git a/adopt/live_test.go b/adopt/live_test.go| deleted file mode 100644 |
| index a947f40..0000000 |
| --- a/adopt/live_test.go |
| +++ /dev/null |
| @@ -1,1215 +0,0 @@ |
| -package adopt |
| - |
| -import ( |
| - "bytes" |
| - "context" |
| - "crypto/rand" |
| - "encoding/hex" |
| - "encoding/json" |
| - "errors" |
| - "io" |
| - "net" |
| - "net/http" |
| - "net/http/httptest" |
| - "net/url" |
| - "regexp" |
| - "slices" |
| - "strconv" |
| - "strings" |
| - "sync" |
| - "sync/atomic" |
| - "testing" |
| - "time" |
| - |
| - "amadan.net/oficina/agent-access.git/client" |
| - "golang.org/x/oauth2" |
| -) |
| - |
| -const ( |
| - liveSQID = "tsqidcanary7x" |
| - liveEvent = "424242" |
| - subjTest = "test-account" |
| - subjOwner = "owner" |
| - freeBusy = "calendar_free_busy" |
| - getEvent = "calendar_get_event" |
| -) |
| - |
| -// liveOp is one operations request as the fake connect received it. |
| -type liveOp struct { |
| - name, method, path, bearer string |
| - body []byte |
| - token int // index of the bearer in issued, -1 unknown |
| -} |
| - |
| -type fakeToken struct { |
| - index int |
| - subject string |
| - teams []string |
| - revoked bool |
| -} |
| - |
| -// fakeConnect is oficina-connect as the live checks meet it: OAuth |
| -// metadata, the token and revoke endpoints, the connection and the |
| -// operations, and membership of the one team, changed by Paul's prompts. |
| -type fakeConnect struct { |
| - t *testing.T |
| - srv *httptest.Server |
| - mu sync.Mutex |
| - // origin is the origin the fake answers as: production connect, the |
| - // agent issuer, reached through transport. |
| - origin string |
| - |
| - team string // the adopted team's SQID: liveSQID unless set |
| - members map[string]bool |
| - logins []string // who signs in at each successive browser open |
| - codes map[string]string |
| - tokens map[string]*fakeToken |
| - issued []string |
| - ops []liveOp |
| - events []string |
| - paths []string |
| - skew atomic.Int64 |
| - |
| - // Breaks. |
| - nonMemberAllowed, foreignReadable, membershipNotEnforced, revokeNotEnforced, memberRefused bool |
| - // answer, when it returns a status, answers an operation instead |
| - // with that status and agent-access error code. It runs under mu. |
| - answer func(op liveOp) (int, string) |
| - onRevoke func(index int) |
| - onToken func(index int, subject string) |
| - revokeOK func(index int) bool |
| -} |
| - |
| -func newFakeConnect(t *testing.T) *fakeConnect { |
| - f := &fakeConnect{ |
| - t: t, |
| - team: liveSQID, |
| - members: map[string]bool{subjOwner: true}, |
| - logins: []string{subjTest, subjTest, subjOwner}, |
| - codes: map[string]string{}, |
| - tokens: map[string]*fakeToken{}, |
| - origin: Issuer, |
| - } |
| - f.srv = httptest.NewTLSServer(f) |
| - t.Cleanup(f.srv.Close) |
| - return f |
| -} |
| - |
| -// transport reaches the fake for every https origin, whatever its name: |
| -// the live checks name production connect, and land here. |
| -func (f *fakeConnect) transport() http.RoundTripper { |
| - tr := f.srv.Client().Transport.(*http.Transport).Clone() |
| - addr := f.srv.Listener.Addr().String() |
| - tr.DialContext = func(ctx context.Context, network, _ string) (net.Conn, error) { |
| - var d net.Dialer |
| - return d.DialContext(ctx, network, addr) |
| - } |
| - tr.TLSClientConfig.ServerName = "example.com" |
| - return tr |
| -} |
| - |
| -func randHex() string { |
| - var b [16]byte |
| - if _, err := rand.Read(b[:]); err != nil { |
| - panic(err) |
| - } |
| - return hex.EncodeToString(b[:]) |
| -} |
| - |
| -func writeJSONTest(w http.ResponseWriter, status int, v any) { |
| - w.Header().Set("Content-Type", "application/json") |
| - w.WriteHeader(status) |
| - _ = json.NewEncoder(w).Encode(v) |
| -} |
| - |
| -// agentFail answers as agent-access does: no-store, the Bearer challenge |
| -// on a 401, and {"error":{"code":…}}. |
| -func (f *fakeConnect) agentFail(w http.ResponseWriter, status int, code string) { |
| - w.Header().Set("Cache-Control", "no-store") |
| - if status == http.StatusUnauthorized { |
| - w.Header().Set("WWW-Authenticate", `Bearer resource_metadata="`+f.origin+`/.well-known/oauth-protected-resource"`) |
| - } |
| - writeJSONTest(w, status, map[string]any{"error": map[string]string{"code": code, "message": "message-canary"}}) |
| -} |
| - |
| -func (f *fakeConnect) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| - f.mu.Lock() |
| - defer f.mu.Unlock() |
| - f.paths = append(f.paths, r.Method+" "+r.URL.Path) |
| - switch { |
| - case r.Method == "GET" && r.URL.Path == "/.well-known/oauth-authorization-server": |
| - writeJSONTest(w, 200, map[string]any{ |
| - "issuer": f.origin, "authorization_endpoint": f.origin + "/oauth/authorize", |
| - "token_endpoint": f.origin + "/oauth/token", "code_challenge_methods_supported": []string{"S256"}, |
| - "scopes_supported": []string{"calendar:read", "docs:read"}, |
| - }) |
| - case r.Method == "POST" && r.URL.Path == "/oauth/token": |
| - _ = r.ParseForm() |
| - subject, ok := f.codes[r.PostForm.Get("code")] |
| - delete(f.codes, r.PostForm.Get("code")) |
| - if !ok || r.PostForm.Get("code_verifier") == "" { |
| - writeJSONTest(w, 400, map[string]string{"error": "invalid_grant"}) |
| - return |
| - } |
| - teams := []string{"team-other"} |
| - if f.members[subject] { |
| - teams = append(teams, f.team) |
| - } |
| - tok := "bearer-canary-" + randHex() |
| - ft := &fakeToken{index: len(f.issued), subject: subject, teams: teams} |
| - f.tokens[tok] = ft |
| - f.issued = append(f.issued, tok) |
| - f.events = append(f.events, "token:"+subject) |
| - if f.onToken != nil { |
| - f.onToken(ft.index, subject) |
| - } |
| - writeJSONTest(w, 200, map[string]any{"access_token": tok, "token_type": "Bearer", "expires_in": 300, "scope": "calendar:read"}) |
| - case r.Method == "POST" && r.URL.Path == "/oauth/revoke": |
| - _ = r.ParseForm() |
| - ft := f.tokens[r.PostForm.Get("token")] |
| - if ft == nil || r.PostForm.Get("client_id") != "oficina-cli" { |
| - writeJSONTest(w, 400, map[string]string{"error": "invalid_request"}) |
| - return |
| - } |
| - if f.revokeOK != nil && !f.revokeOK(ft.index) { |
| - writeJSONTest(w, 503, map[string]string{"error": "temporarily_unavailable"}) |
| - return |
| - } |
| - ft.revoked = true |
| - f.events = append(f.events, "revoke:"+strconv.Itoa(ft.index)) |
| - if f.onRevoke != nil { |
| - f.onRevoke(ft.index) |
| - } |
| - w.WriteHeader(200) |
| - case r.Method == "GET" && r.URL.Path == "/api/v1/connection": |
| - p := f.verify(w, r) |
| - if p == nil { |
| - return |
| - } |
| - writeJSONTest(w, 200, map[string]any{"teams": f.teamsOf(p), "scopes": []string{"calendar:read"}}) |
| - case r.Method == "POST" && strings.HasPrefix(r.URL.Path, "/api/v1/operations/"): |
| - body, _ := io.ReadAll(r.Body) |
| - op := liveOp{name: strings.TrimPrefix(r.URL.Path, "/api/v1/operations/"), method: r.Method, path: r.URL.String(), |
| - bearer: r.Header.Get("Authorization"), body: body, token: -1} |
| - if ft := f.tokens[strings.TrimPrefix(op.bearer, "Bearer ")]; ft != nil { |
| - op.token = ft.index |
| - } |
| - f.ops = append(f.ops, op) |
| - f.events = append(f.events, "op:"+op.name+":"+strconv.Itoa(op.token)) |
| - if f.answer != nil { |
| - if status, code := f.answer(op); status != 0 { |
| - switch { |
| - case status >= 300 && status < 400: |
| - w.Header().Set("Location", f.origin+"/followed") |
| - w.WriteHeader(status) |
| - case status == 200 && code == "malformed": |
| - w.Header().Set("Content-Type", "application/json") |
| - io.WriteString(w, `{"tz":`) |
| - case status == 200 && code == "oversized": |
| - w.Header().Set("Content-Type", "application/json") |
| - io.WriteString(w, `"`+strings.Repeat("a", client.MaxResponse)+`"`) |
| - case code == "plain": |
| - // An app's own refusal: no challenge, no agent body. |
| - w.WriteHeader(status) |
| - io.WriteString(w, "Unauthorized\n") |
| - default: |
| - f.agentFail(w, status, code) |
| - } |
| - return |
| - } |
| - } |
| - p := f.verify(w, r) |
| - if p == nil { |
| - return |
| - } |
| - var in struct { |
| - Team string `json:"team"` |
| - ID json.Number |
| - } |
| - if json.Unmarshal(body, &in) != nil || r.Header.Get("Content-Type") != "application/json" { |
| - f.agentFail(w, 422, "invalid") |
| - return |
| - } |
| - if !slices.Contains(f.teamsOf(p), in.Team) && !f.nonMemberAllowed { |
| - f.agentFail(w, 403, "forbidden") |
| - return |
| - } |
| - switch op.name { |
| - case freeBusy: |
| - if f.memberRefused && p.subject == subjTest { |
| - f.agentFail(w, 403, "forbidden") |
| - return |
| - } |
| - writeJSONTest(w, 200, map[string]any{"tz": "tz-canary", "busy": []any{}}) |
| - case getEvent: |
| - if in.ID.String() == liveEvent && !f.foreignReadable { |
| - f.agentFail(w, 404, "not_found") |
| - return |
| - } |
| - writeJSONTest(w, 200, map[string]any{"id": in.ID, "title": "title-canary"}) |
| - default: |
| - f.agentFail(w, 404, "not_found") |
| - } |
| - default: |
| - http.NotFound(w, r) |
| - } |
| -} |
| - |
| -// verify is connect's grant check: a known, unrevoked bearer whose |
| -// person still belongs to one of the teams it ticked. |
| -func (f *fakeConnect) verify(w http.ResponseWriter, r *http.Request) *fakeToken { |
| - ft := f.tokens[strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")] |
| - if ft == nil || ft.revoked && !f.revokeNotEnforced || len(f.teamsOf(ft)) == 0 { |
| - f.agentFail(w, 401, "unauthenticated") |
| - return nil |
| - } |
| - return ft |
| -} |
| - |
| -func (f *fakeConnect) teamsOf(ft *fakeToken) []string { |
| - out := []string{} |
| - for _, team := range ft.teams { |
| - if team == f.team && !f.members[ft.subject] && !f.membershipNotEnforced { |
| - continue |
| - } |
| - out = append(out, team) |
| - } |
| - return out |
| -} |
| - |
| -// open is the system browser: whoever the script says signs in, ticks |
| -// every team they belong to, and is sent back to the CLI's callback. |
| -func (f *fakeConnect) open(raw string) error { |
| - u, err := url.Parse(raw) |
| - if err != nil { |
| - return err |
| - } |
| - q := u.Query() |
| - f.mu.Lock() |
| - if len(f.logins) == 0 { |
| - f.mu.Unlock() |
| - f.t.Errorf("unscripted sign-in") |
| - return errors.New("no one to sign in") |
| - } |
| - subject := f.logins[0] |
| - f.logins = f.logins[1:] |
| - code := randHex() |
| - f.codes[code] = subject |
| - f.events = append(f.events, "login:"+subject) |
| - f.mu.Unlock() |
| - if q.Get("code_challenge") == "" || q.Get("scope") != "calendar:read" { |
| - f.t.Errorf("sign-in asked for %q without PKCE or with other scopes", q.Get("scope")) |
| - } |
| - cb := q.Get("redirect_uri") + "?" + url.Values{"code": {code}, "state": {q.Get("state")}, "iss": {f.origin}}.Encode() |
| - resp, err := http.Get(cb) |
| - if err != nil { |
| - return err |
| - } |
| - resp.Body.Close() |
| - if resp.StatusCode != 200 { |
| - return errors.New("callback refused") |
| - } |
| - return nil |
| -} |
| - |
| -func (f *fakeConnect) setMember(subject string, in bool) { |
| - f.mu.Lock() |
| - defer f.mu.Unlock() |
| - f.members[subject] = in |
| - f.events = append(f.events, "member:"+subject+":"+map[bool]string{true: "added", false: "removed"}[in]) |
| -} |
| - |
| -// state copies what the fake saw. |
| -func (f *fakeConnect) state() (ops []liveOp, events, issued, paths []string, revoked map[int]bool) { |
| - f.mu.Lock() |
| - defer f.mu.Unlock() |
| - revoked = map[int]bool{} |
| - for _, ft := range f.tokens { |
| - if ft.revoked { |
| - revoked[ft.index] = true |
| - } |
| - } |
| - return slices.Clone(f.ops), slices.Clone(f.events), slices.Clone(f.issued), slices.Clone(f.paths), revoked |
| -} |
| - |
| -type fakePrompter struct { |
| - f *fakeConnect |
| - asked []string |
| - failOn string |
| - cancel context.CancelFunc |
| - onAsk func(string) |
| -} |
| - |
| -func (p *fakePrompter) Ask(ctx context.Context, sentence string) error { |
| - p.asked = append(p.asked, sentence) |
| - if sentence == p.failOn { |
| - if p.cancel != nil { |
| - p.cancel() |
| - return ctx.Err() |
| - } |
| - return errors.New("declined") |
| - } |
| - switch sentence { |
| - case LiveAddedMember: |
| - p.f.setMember(subjTest, true) |
| - case LiveRemovedMember: |
| - p.f.setMember(subjTest, false) |
| - } |
| - if p.onAsk != nil { |
| - p.onAsk(sentence) |
| - } |
| - return nil |
| -} |
| - |
| -type liveFixture struct { |
| - f *fakeConnect |
| - p *fakePrompter |
| - s *Store |
| - out *bytes.Buffer |
| -} |
| - |
| -func newLive(t *testing.T) *liveFixture { |
| - t.Helper() |
| - f := newFakeConnect(t) |
| - x := &liveFixture{f: f, p: &fakePrompter{f: f}, s: newJournal(t), out: &bytes.Buffer{}} |
| - oldT, oldNow := liveTransport, liveNow |
| - liveTransport = f.transport() |
| - liveNow = func() time.Time { return time.Now().Add(time.Duration(f.skew.Load())) } |
| - t.Cleanup(func() { liveTransport, liveNow = oldT, oldNow }) |
| - return x |
| -} |
| - |
| -func (x *liveFixture) run(t *testing.T) error { |
| - t.Helper() |
| - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| - defer cancel() |
| - x.p.cancel = nil |
| - return RunLive(ctx, x.out, x.f.origin, liveSQID, x.p, x.s, x.f.open, liveEvent, true) |
| -} |
| - |
| -// checks lists the journal's live checks in the order recorded. |
| -func checks(t *testing.T, s *Store) []string { |
| - t.Helper() |
| - rows, err := s.db.QueryContext(context.Background(), "SELECT name, outcome FROM adopt_checks ORDER BY id") |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - defer rows.Close() |
| - var out []string |
| - for rows.Next() { |
| - var n, o string |
| - if err := rows.Scan(&n, &o); err != nil { |
| - t.Fatal(err) |
| - } |
| - out = append(out, n+"="+o) |
| - } |
| - return out |
| -} |
| - |
| -func wantChecks(t *testing.T, s *Store, want ...string) { |
| - t.Helper() |
| - if got := checks(t, s); !slices.Equal(got, want) { |
| - t.Fatalf("checks:\n got %q\nwant %q", got, want) |
| - } |
| -} |
| - |
| -// allRevoked fails unless connect revoked every bearer it issued. |
| -func allRevoked(t *testing.T, f *fakeConnect) { |
| - t.Helper() |
| - _, _, issued, _, revoked := f.state() |
| - if len(issued) == 0 { |
| - t.Fatal("no connection was made") |
| - } |
| - for i := range issued { |
| - if !revoked[i] { |
| - t.Fatalf("connection %d of %d left connected", i+1, len(issued)) |
| - } |
| - } |
| -} |
| - |
| -func gateClosed(t *testing.T, s *Store) { |
| - t.Helper() |
| - if err := s.LiveGate(context.Background(), "docs"); !errors.Is(err, ErrLiveChecksMissing) { |
| - t.Fatalf("Plan C gate open: %v", err) |
| - } |
| -} |
| - |
| -var everyCheckPassed = []string{ |
| - "non-member-refused=passed", "member-allowed=passed", "member-no-local-permission-refused=passed", |
| - "revoked-membership-refused=passed", "local-access-kept=passed", "owner-allowed=passed", |
| - "owner-revoked-refused=passed", "owner-local-access-kept=passed", |
| -} |
| - |
| -func TestLivePassesEveryCheck(t *testing.T) { |
| - x := newLive(t) |
| - if err := x.run(t); err != nil { |
| - t.Fatal(err) |
| - } |
| - wantChecks(t, x.s, everyCheckPassed...) |
| - if err := x.s.LiveGate(context.Background(), "docs"); err != nil { |
| - t.Fatalf("gate after every check passed: %v", err) |
| - } |
| - want := []string{LiveAddedMember, LiveRemovedMember, LiveLocalAccessKept, LiveOwnerLocalAccessKept} |
| - if !slices.Equal(x.p.asked, want) { |
| - t.Fatalf("asked %q, want %q", x.p.asked, want) |
| - } |
| - allRevoked(t, x.f) |
| -} |
| - |
| -func TestLiveFailsWhenNonMemberSucceeds(t *testing.T) { |
| - x := newLive(t) |
| - x.f.nonMemberAllowed = true |
| - if err := x.run(t); err == nil { |
| - t.Fatal("a non-member's call succeeded and the run went on") |
| - } |
| - wantChecks(t, x.s, "non-member-refused=failed:allowed") |
| - if len(x.p.asked) != 0 { |
| - t.Fatalf("asked %q after the failure", x.p.asked) |
| - } |
| - gateClosed(t, x.s) |
| - allRevoked(t, x.f) |
| -} |
| - |
| -func TestLiveRefusesNonMemberCheckWhenAlreadyMember(t *testing.T) { |
| - x := newLive(t) |
| - x.f.members[subjTest] = true |
| - if err := x.run(t); err == nil { |
| - t.Fatal("the non-member check ran on a member") |
| - } |
| - wantChecks(t, x.s, "non-member-refused=inconclusive") |
| - ops, _, _, _, _ := x.f.state() |
| - if len(ops) != 0 { |
| - t.Fatalf("a member's call was made as the non-member check: %d", len(ops)) |
| - } |
| - allRevoked(t, x.f) |
| -} |
| - |
| -func TestLiveFailsWhenMemberCannotCallBeforeRemoval(t *testing.T) { |
| - x := newLive(t) |
| - x.f.memberRefused = true |
| - if err := x.run(t); err == nil { |
| - t.Fatal("the member's refused call was not a failure") |
| - } |
| - wantChecks(t, x.s, "non-member-refused=passed", "member-allowed=failed:forbidden") |
| - if !slices.Equal(x.p.asked, []string{LiveAddedMember}) { |
| - t.Fatalf("later steps ran: asked %q", x.p.asked) |
| - } |
| - ops, _, _, _, _ := x.f.state() |
| - for _, op := range ops[2:] { |
| - t.Fatalf("a later step called %s", op.name) |
| - } |
| - gateClosed(t, x.s) |
| - allRevoked(t, x.f) |
| -} |
| - |
| -func TestLiveFailsWhenForeignEventReadable(t *testing.T) { |
| - x := newLive(t) |
| - x.f.foreignReadable = true |
| - if err := x.run(t); err == nil { |
| - t.Fatal("a readable foreign event was not a failure") |
| - } |
| - wantChecks(t, x.s, "non-member-refused=passed", "member-allowed=passed", "member-no-local-permission-refused=failed:allowed") |
| - if slices.Contains(x.p.asked, LiveRemovedMember) { |
| - t.Fatal("went on to the removal") |
| - } |
| - gateClosed(t, x.s) |
| - allRevoked(t, x.f) |
| -} |
| - |
| -// Only forbidden or not_found, in agent-access's own body, proves the |
| -// event refused; anything else is inconclusive and stops the run. |
| -func TestLiveForeignEventRefusalCodes(t *testing.T) { |
| - for _, tc := range []struct { |
| - status int |
| - code, want string |
| - }{ |
| - {403, "forbidden", "passed"}, {404, "not_found", "passed"}, |
| - {403, "invalid", "inconclusive"}, {401, "unauthenticated", "inconclusive"}, |
| - {503, "unavailable", "inconclusive"}, {422, "invalid", "inconclusive"}, |
| - } { |
| - t.Run(strconv.Itoa(tc.status)+"-"+tc.code, func(t *testing.T) { |
| - x := newLive(t) |
| - x.f.answer = func(op liveOp) (int, string) { |
| - if op.name == getEvent { |
| - return tc.status, tc.code |
| - } |
| - return 0, "" |
| - } |
| - err := x.run(t) |
| - got := checks(t, x.s) |
| - if len(got) < 3 || got[2] != "member-no-local-permission-refused="+tc.want { |
| - t.Fatalf("recorded %q, want %s", got, tc.want) |
| - } |
| - if tc.want == "passed" && err != nil { |
| - t.Fatal(err) |
| - } |
| - if tc.want != "passed" && (err == nil || len(got) != 3) { |
| - t.Fatalf("an inconclusive check did not stop the run: %v %q", err, got) |
| - } |
| - allRevoked(t, x.f) |
| - }) |
| - } |
| -} |
| - |
| -func TestLiveFailsWhenRevocationNotEnforced(t *testing.T) { |
| - x := newLive(t) |
| - x.f.membershipNotEnforced = true |
| - if err := x.run(t); err == nil { |
| - t.Fatal("a removed member's connection still worked and the run went on") |
| - } |
| - wantChecks(t, x.s, "non-member-refused=passed", "member-allowed=passed", |
| - "member-no-local-permission-refused=passed", "revoked-membership-refused=failed:allowed") |
| - if slices.Contains(x.p.asked, LiveLocalAccessKept) { |
| - t.Fatal("went on to the local access sentence") |
| - } |
| - gateClosed(t, x.s) |
| - allRevoked(t, x.f) |
| -} |
| - |
| -// The membership check replays the member's own request, the same bearer |
| -// and body, after the removal; the owner check does the same after the |
| -// revoke. |
| -func TestLiveRepeatsExactRequest(t *testing.T) { |
| - x := newLive(t) |
| - if err := x.run(t); err != nil { |
| - t.Fatal(err) |
| - } |
| - ops, events, issued, _, _ := x.f.state() |
| - if len(issued) != 3 { |
| - t.Fatalf("%d connections, want 3", len(issued)) |
| - } |
| - for _, tok := range []int{1, 2} { |
| - var same []liveOp |
| - for _, op := range ops { |
| - if op.token == tok && op.name == freeBusy { |
| - same = append(same, op) |
| - } |
| - } |
| - if len(same) != 2 { |
| - t.Fatalf("connection %d: %d free/busy calls, want the call and its replay", tok, len(same)) |
| - } |
| - a, b := same[0], same[1] |
| - if a.method != b.method || a.path != b.path || a.bearer != b.bearer || !bytes.Equal(a.body, b.body) { |
| - t.Fatalf("connection %d: the replay differs from the call", tok) |
| - } |
| - if a.bearer != "Bearer "+issued[tok] { |
| - t.Fatalf("connection %d: the call was not made with its own bearer", tok) |
| - } |
| - var in map[string]any |
| - if json.Unmarshal(a.body, &in) != nil || in["team"] != liveSQID || in["start"] == nil || in["end"] == nil { |
| - t.Fatalf("connection %d: the call is not the team's free/busy", tok) |
| - } |
| - } |
| - // The member's replay follows the removal. |
| - removed := slices.Index(events, "member:"+subjTest+":removed") |
| - var calls []int |
| - for i, e := range events { |
| - if e == "op:"+freeBusy+":1" { |
| - calls = append(calls, i) |
| - } |
| - } |
| - if removed < 0 || len(calls) != 2 || !(calls[0] < removed && removed < calls[1]) { |
| - t.Fatalf("the member's replay is not after the removal: %q", events) |
| - } |
| -} |
| - |
| -func TestLiveOwnerRevokeReplaysSavedRequest(t *testing.T) { |
| - x := newLive(t) |
| - // The first replay is redirected; the runner must not follow it, and |
| - // repeats with a fresh connection. |
| - x.f.answer = func(op liveOp) (int, string) { |
| - if op.token == 2 && slices.Contains(x.f.events, "revoke:2") { |
| - return http.StatusFound, "" |
| - } |
| - return 0, "" |
| - } |
| - x.f.logins = append(x.f.logins, subjOwner) |
| - if err := x.run(t); err != nil { |
| - t.Fatal(err) |
| - } |
| - wantChecks(t, x.s, append(everyCheckPassed[:6:6], |
| - "owner-revoked-refused=inconclusive", "owner-allowed=passed", |
| - "owner-revoked-refused=passed", "owner-local-access-kept=passed")...) |
| - _, events, _, paths, _ := x.f.state() |
| - if slices.Contains(paths, "GET /followed") || slices.Contains(paths, "POST /followed") { |
| - t.Fatal("the replay followed a redirect") |
| - } |
| - // Each owner connection: its call, then the revoke, then the replay. |
| - for _, tok := range []string{"2", "3"} { |
| - i := slices.Index(events, "op:"+freeBusy+":"+tok) |
| - r := slices.Index(events, "revoke:"+tok) |
| - j := slices.Index(events[i+1:], "op:"+freeBusy+":"+tok) |
| - if i < 0 || r < i || j < 0 || i+1+j < r { |
| - t.Fatalf("owner connection %s: call, revoke and replay out of order: %q", tok, events) |
| - } |
| - } |
| - allRevoked(t, x.f) |
| -} |
| - |
| -func TestLiveFailsWhenRevokeLeavesAccessValid(t *testing.T) { |
| - x := newLive(t) |
| - x.f.revokeNotEnforced = true |
| - if err := x.run(t); err == nil { |
| - t.Fatal("a revoked connection still worked and the run went on") |
| - } |
| - wantChecks(t, x.s, append(everyCheckPassed[:6:6], "owner-revoked-refused=failed:allowed")...) |
| - if slices.Contains(x.p.asked, LiveOwnerLocalAccessKept) { |
| - t.Fatal("went on to the owner's local access sentence") |
| - } |
| - gateClosed(t, x.s) |
| -} |
| - |
| -// A replay made after the bearer expired proves nothing: it is |
| -// inconclusive, and the owner's step repeats with a fresh connection. |
| -func TestLiveReplayAfterExpiryIsInconclusive(t *testing.T) { |
| - t.Run("owner", func(t *testing.T) { |
| - x := newLive(t) |
| - x.f.logins = append(x.f.logins, subjOwner) |
| - x.f.onRevoke = func(i int) { |
| - if i == 2 { |
| - x.f.skew.Store(int64(time.Hour)) |
| - } |
| - } |
| - x.f.onToken = func(i int, _ string) { |
| - if i == 3 { |
| - x.f.skew.Store(0) |
| - } |
| - } |
| - if err := x.run(t); err != nil { |
| - t.Fatal(err) |
| - } |
| - wantChecks(t, x.s, append(everyCheckPassed[:6:6], |
| - "owner-revoked-refused=inconclusive", "owner-allowed=passed", |
| - "owner-revoked-refused=passed", "owner-local-access-kept=passed")...) |
| - ops, _, _, _, _ := x.f.state() |
| - n := 0 |
| - for _, op := range ops { |
| - if op.token == 2 { |
| - n++ |
| - } |
| - } |
| - if n != 1 { |
| - t.Fatalf("the expired bearer was replayed: %d calls", n) |
| - } |
| - allRevoked(t, x.f) |
| - }) |
| - t.Run("member", func(t *testing.T) { |
| - x := newLive(t) |
| - x.p.onAsk = func(s string) { |
| - if s == LiveRemovedMember { |
| - x.f.skew.Store(int64(time.Hour)) |
| - } |
| - } |
| - if err := x.run(t); err == nil { |
| - t.Fatal("an expired replay did not stop the run") |
| - } |
| - wantChecks(t, x.s, "non-member-refused=passed", "member-allowed=passed", |
| - "member-no-local-permission-refused=passed", "revoked-membership-refused=inconclusive") |
| - ops, _, _, _, _ := x.f.state() |
| - n := 0 |
| - for _, op := range ops { |
| - if op.token == 1 && op.name == freeBusy { |
| - n++ |
| - } |
| - } |
| - if n != 1 { |
| - t.Fatalf("the expired bearer was replayed: %d calls", n) |
| - } |
| - gateClosed(t, x.s) |
| - allRevoked(t, x.f) |
| - }) |
| - t.Run("unavailable", func(t *testing.T) { |
| - x := newLive(t) |
| - x.f.logins = append(x.f.logins, subjOwner) |
| - x.f.answer = func(op liveOp) (int, string) { |
| - if op.token == 2 && x.f.tokens[strings.TrimPrefix(op.bearer, "Bearer ")].revoked { |
| - return 503, "unavailable" |
| - } |
| - return 0, "" |
| - } |
| - if err := x.run(t); err != nil { |
| - t.Fatal(err) |
| - } |
| - wantChecks(t, x.s, append(everyCheckPassed[:6:6], |
| - "owner-revoked-refused=inconclusive", "owner-allowed=passed", |
| - "owner-revoked-refused=passed", "owner-local-access-kept=passed")...) |
| - }) |
| - t.Run("bounded", func(t *testing.T) { |
| - x := newLive(t) |
| - for range liveOwnerAttempts { |
| - x.f.logins = append(x.f.logins, subjOwner) |
| - } |
| - x.f.answer = func(op liveOp) (int, string) { |
| - if op.token >= 2 && x.f.tokens[strings.TrimPrefix(op.bearer, "Bearer ")].revoked { |
| - return 503, "unavailable" |
| - } |
| - return 0, "" |
| - } |
| - if err := x.run(t); err == nil { |
| - t.Fatal("the owner step repeated without end") |
| - } |
| - got := checks(t, x.s) |
| - n := 0 |
| - for _, c := range got { |
| - if c == "owner-revoked-refused=inconclusive" { |
| - n++ |
| - } |
| - } |
| - if n != liveOwnerAttempts || slices.Contains(got, "owner-revoked-refused=passed") { |
| - t.Fatalf("checks %q", got) |
| - } |
| - _, _, issued, _, _ := x.f.state() |
| - if len(issued) != 2+liveOwnerAttempts { |
| - t.Fatalf("%d connections, want a fresh one per attempt", len(issued)) |
| - } |
| - gateClosed(t, x.s) |
| - allRevoked(t, x.f) |
| - }) |
| -} |
| - |
| -// The member's replay passes only on agent-access's own refusal: its 401 |
| -// challenge or its forbidden 403. A 2xx fails; anything else proves |
| -// nothing, and so does an answer that came back after the bearer expired. |
| -func TestLiveReplayRefusalShape(t *testing.T) { |
| - for _, tc := range []struct { |
| - name string |
| - status int |
| - code, want string |
| - expireDuring bool |
| - }{ |
| - {"challenge", 401, "unauthenticated", "passed", false}, |
| - {"forbidden", 403, "forbidden", "passed", false}, |
| - {"app 401", 401, "plain", "inconclusive", false}, |
| - {"401 other body", 401, "forbidden", "inconclusive", false}, |
| - {"403 other code", 403, "not_found", "inconclusive", false}, |
| - {"not found", 404, "not_found", "inconclusive", false}, |
| - {"unavailable", 503, "unavailable", "inconclusive", false}, |
| - {"expired while answering", 401, "unauthenticated", "inconclusive", true}, |
| - } { |
| - t.Run(tc.name, func(t *testing.T) { |
| - x := newLive(t) |
| - x.f.answer = func(op liveOp) (int, string) { |
| - if op.token == 1 && op.name == freeBusy && !x.f.members[subjTest] { |
| - if tc.expireDuring { |
| - x.f.skew.Store(int64(time.Hour)) |
| - } |
| - return tc.status, tc.code |
| - } |
| - return 0, "" |
| - } |
| - err := x.run(t) |
| - got := checks(t, x.s) |
| - if len(got) < 4 || got[3] != "revoked-membership-refused="+tc.want { |
| - t.Fatalf("recorded %q, want %s", got, tc.want) |
| - } |
| - if tc.want != "passed" && (err == nil || len(got) != 4) { |
| - t.Fatalf("an inconclusive replay did not stop the run: %v", err) |
| - } |
| - allRevoked(t, x.f) |
| - }) |
| - } |
| -} |
| - |
| -// close zeroes every saved request and forgets every token, signed out |
| -// or not. |
| -func TestLiveCloseZeroes(t *testing.T) { |
| - body, bearer := []byte("body-canary"), []byte("bearer-canary") |
| - c := &savedRequest{method: "POST", url: "https://connect.oficina.works/api/v1/operations/x", body: body, bearer: bearer, expiry: time.Now()} |
| - l := newLiveConn() |
| - l.out = true |
| - _ = l.store.Save(client.Credentials{Token: &oauth2.Token{AccessToken: "bearer-canary-2"}}) |
| - r := &liveRun{out: io.Discard, conns: []*liveConn{l}, saved: []*savedRequest{c}} |
| - if err := r.close(); err != nil { |
| - t.Fatal(err) |
| - } |
| - if !bytes.Equal(body, make([]byte, len(body))) || !bytes.Equal(bearer, make([]byte, len(bearer))) { |
| - t.Fatal("a saved request was not zeroed") |
| - } |
| - if c.method != "" || c.url != "" || !c.expiry.IsZero() { |
| - t.Fatal("a saved request kept its target") |
| - } |
| - if _, err := l.store.Load(); err == nil { |
| - t.Fatal("a token outlived the run") |
| - } |
| -} |
| - |
| -// Every request a run captured is zeroed by close, not only the two kept |
| -// for replay: the non-member's, the foreign event's, and a refused or |
| -// malformed call's too. |
| -func TestLiveCloseZeroesEveryCapturedRequest(t *testing.T) { |
| - for name, brk := range map[string]func(*liveFixture){ |
| - "pass": func(*liveFixture) {}, |
| - "foreign": func(x *liveFixture) { x.f.foreignReadable = true }, |
| - "member-refused": func(x *liveFixture) { x.f.memberRefused = true }, |
| - "owner-malformed": func(x *liveFixture) { |
| - x.f.answer = func(op liveOp) (int, string) { |
| - if op.token == 2 { |
| - return 200, "malformed" |
| - } |
| - return 0, "" |
| - } |
| - }, |
| - } { |
| - t.Run(name, func(t *testing.T) { |
| - x := newLive(t) |
| - brk(x) |
| - ev, _ := strconv.ParseInt(liveEvent, 10, 64) |
| - r := &liveRun{out: x.out, server: x.f.origin, sqid: liveSQID, event: ev, p: x.p, s: x.s, open: x.f.open} |
| - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| - defer cancel() |
| - _ = r.run(ctx) |
| - var held [][]byte |
| - bearers := 0 |
| - for _, l := range r.conns { |
| - for _, ex := range l.rec.all { |
| - if len(ex.req.bearer) > 0 { |
| - bearers++ |
| - } |
| - held = append(held, ex.req.bearer, ex.req.body, ex.body) |
| - } |
| - } |
| - for _, c := range r.saved { |
| - bearers++ |
| - held = append(held, c.bearer, c.body) |
| - } |
| - // Every call the clients made, the replays (sent again from |
| - // the saved bytes) aside. |
| - ops, _, _, _, _ := x.f.state() |
| - calls := map[string]bool{} |
| - for _, op := range ops { |
| - calls[op.name+":"+strconv.Itoa(op.token)] = true |
| - } |
| - if bearers != len(calls) { |
| - t.Fatalf("%d bearers held for %d calls made", bearers, len(calls)) |
| - } |
| - for _, b := range held { |
| - if len(b) > 0 && bytes.Equal(b, make([]byte, len(b))) { |
| - t.Fatal("zeroed before close") |
| - } |
| - } |
| - if err := r.close(); err != nil { |
| - t.Fatal(err) |
| - } |
| - for _, b := range held { |
| - if !bytes.Equal(b, make([]byte, len(b))) { |
| - t.Fatal("a captured request or answer outlived the run") |
| - } |
| - } |
| - allRevoked(t, x.f) |
| - }) |
| - } |
| -} |
| - |
| -// A success the client could not read or decode proves nothing for a |
| -// call that must succeed; for a call that must be refused it is still |
| -// access granted. |
| -func TestLiveMalformedSuccess(t *testing.T) { |
| - for _, code := range []string{"malformed", "oversized"} { |
| - t.Run("member "+code, func(t *testing.T) { |
| - x := newLive(t) |
| - x.f.answer = func(op liveOp) (int, string) { |
| - if op.token == 1 && op.name == freeBusy && x.f.members[subjTest] { |
| - return 200, code |
| - } |
| - return 0, "" |
| - } |
| - if err := x.run(t); err == nil { |
| - t.Fatal("a malformed success went on") |
| - } |
| - wantChecks(t, x.s, "non-member-refused=passed", "member-allowed=inconclusive") |
| - allRevoked(t, x.f) |
| - }) |
| - t.Run("owner "+code, func(t *testing.T) { |
| - x := newLive(t) |
| - x.f.answer = func(op liveOp) (int, string) { |
| - if op.token == 2 && op.name == freeBusy { |
| - return 200, code |
| - } |
| - return 0, "" |
| - } |
| - if err := x.run(t); err == nil { |
| - t.Fatal("a malformed success went on") |
| - } |
| - wantChecks(t, x.s, append(everyCheckPassed[:5:5], "owner-allowed=inconclusive")...) |
| - allRevoked(t, x.f) |
| - }) |
| - t.Run("non-member "+code, func(t *testing.T) { |
| - x := newLive(t) |
| - x.f.answer = func(op liveOp) (int, string) { |
| - if op.token == 0 { |
| - return 200, code |
| - } |
| - return 0, "" |
| - } |
| - if err := x.run(t); err == nil { |
| - t.Fatal("a non-member's success went on") |
| - } |
| - wantChecks(t, x.s, "non-member-refused=failed:allowed") |
| - }) |
| - } |
| -} |
| - |
| -var outcomeShape = regexp.MustCompile(`^(passed|inconclusive|failed:[a-z_-]+)$`) |
| - |
| -func TestLiveRecordsCodesOnly(t *testing.T) { |
| - for name, brk := range map[string]func(*fakeConnect){ |
| - "pass": func(*fakeConnect) {}, |
| - "non-member": func(f *fakeConnect) { f.nonMemberAllowed = true }, |
| - "member-refused": func(f *fakeConnect) { f.memberRefused = true }, |
| - "foreign": func(f *fakeConnect) { f.foreignReadable = true }, |
| - "membership": func(f *fakeConnect) { f.membershipNotEnforced = true }, |
| - "revoke": func(f *fakeConnect) { f.revokeNotEnforced = true }, |
| - } { |
| - t.Run(name, func(t *testing.T) { |
| - x := newLive(t) |
| - brk(x.f) |
| - err := x.run(t) |
| - var dump strings.Builder |
| - rows, qerr := x.s.db.Query("SELECT * FROM adopt_checks") |
| - if qerr != nil { |
| - t.Fatal(qerr) |
| - } |
| - cols, _ := rows.Columns() |
| - for rows.Next() { |
| - vals := make([]any, len(cols)) |
| - ptrs := make([]any, len(cols)) |
| - for i := range vals { |
| - ptrs[i] = &vals[i] |
| - } |
| - if err := rows.Scan(ptrs...); err != nil { |
| - t.Fatal(err) |
| - } |
| - for _, v := range vals { |
| - dump.WriteString(jsonAny(v) + " ") |
| - } |
| - } |
| - rows.Close() |
| - for _, c := range checks(t, x.s) { |
| - if !outcomeShape.MatchString(strings.SplitN(c, "=", 2)[1]) { |
| - t.Fatalf("outcome %q is not a fixed code", c) |
| - } |
| - } |
| - everything := dump.String() + x.out.String() |
| - if err != nil { |
| - everything += err.Error() |
| - } |
| - _, _, issued, _, _ := x.f.state() |
| - secrets := append([]string{liveSQID, liveEvent, x.f.srv.URL, "127.0.0.1", "bearer-canary", "message-canary", "tz-canary", "title-canary"}, issued...) |
| - for _, s := range secrets { |
| - if strings.Contains(everything, s) { |
| - t.Fatalf("recorded or printed %q", s) |
| - } |
| - } |
| - }) |
| - } |
| -} |
| - |
| -func jsonAny(v any) string { |
| - if b, ok := v.([]byte); ok { |
| - return string(b) |
| - } |
| - b, _ := json.Marshal(v) |
| - return string(b) |
| -} |
| - |
| -func TestLiveAlwaysLogsOut(t *testing.T) { |
| - t.Run("member refused", func(t *testing.T) { |
| - x := newLive(t) |
| - x.f.memberRefused = true |
| - _ = x.run(t) |
| - allRevoked(t, x.f) |
| - }) |
| - t.Run("removal declined", func(t *testing.T) { |
| - x := newLive(t) |
| - x.p.failOn = LiveRemovedMember |
| - if err := x.run(t); err == nil { |
| - t.Fatal("a declined prompt went on") |
| - } |
| - allRevoked(t, x.f) |
| - }) |
| - t.Run("cancelled at the removal", func(t *testing.T) { |
| - x := newLive(t) |
| - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| - defer cancel() |
| - x.p.failOn = LiveRemovedMember |
| - x.p.cancel = cancel |
| - if err := RunLive(ctx, x.out, x.f.origin, liveSQID, x.p, x.s, x.f.open, liveEvent, true); err == nil { |
| - t.Fatal("a cancelled run went on") |
| - } |
| - allRevoked(t, x.f) |
| - }) |
| - t.Run("revoke fails once", func(t *testing.T) { |
| - x := newLive(t) |
| - var refused atomic.Bool |
| - x.f.revokeOK = func(i int) bool { |
| - if i == 0 && !refused.Load() { |
| - refused.Store(true) |
| - return false |
| - } |
| - return true |
| - } |
| - if err := x.run(t); err == nil { |
| - t.Fatal("a failed revoke went unreported") |
| - } |
| - allRevoked(t, x.f) |
| - }) |
| - t.Run("revoke never succeeds", func(t *testing.T) { |
| - x := newLive(t) |
| - x.f.revokeOK = func(i int) bool { return i != 0 } |
| - err := x.run(t) |
| - if err == nil || !strings.Contains(err.Error(), "live-sign-out-failed") { |
| - t.Fatalf("an unrevoked connection was not reported: %v", err) |
| - } |
| - }) |
| -} |
| - |
| -func TestLiveDryRunContactsNothing(t *testing.T) { |
| - x := newLive(t) |
| - open := func(string) error { t.Fatal("dry run opened a browser"); return nil } |
| - p := askFunc(func(context.Context, string) error { t.Fatal("dry run asked Paul"); return nil }) |
| - if err := RunLive(context.Background(), x.out, x.f.origin, liveSQID, p, x.s, open, liveEvent, false); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := RunLive(context.Background(), x.out, x.f.origin, liveSQID, p, nil, open, liveEvent, false); err != nil { |
| - t.Fatalf("dry run needs the journal: %v", err) |
| - } |
| - _, _, _, paths, _ := x.f.state() |
| - if len(paths) != 0 { |
| - t.Fatalf("dry run contacted connect: %q", paths) |
| - } |
| - wantChecks(t, x.s) |
| - want := strings.Join(LiveSteps, "\n") + "\n" |
| - if x.out.String() != want+want { |
| - t.Fatalf("dry run printed %q", x.out.String()) |
| - } |
| -} |
| - |
| -type askFunc func(context.Context, string) error |
| - |
| -func (f askFunc) Ask(ctx context.Context, s string) error { return f(ctx, s) } |
| - |
| -func TestLiveRefusesBadInputs(t *testing.T) { |
| - x := newLive(t) |
| - open := func(string) error { t.Fatal("opened a browser"); return nil } |
| - for name, tc := range map[string]struct{ server, sqid, event string }{ |
| - "http server": {"http://connect.oficina.works", liveSQID, liveEvent}, |
| - "server path": {"https://connect.oficina.works/x", liveSQID, liveEvent}, |
| - "no server": {"", liveSQID, liveEvent}, |
| - "no sqid": {x.f.origin, "", liveEvent}, |
| - "event zero": {x.f.origin, liveSQID, "0"}, |
| - "event negative": {x.f.origin, liveSQID, "-4"}, |
| - "event text": {x.f.origin, liveSQID, "abc"}, |
| - "event spaced": {x.f.origin, liveSQID, " 4"}, |
| - } { |
| - for _, apply := range []bool{false, true} { |
| - if err := RunLive(context.Background(), x.out, tc.server, tc.sqid, x.p, x.s, open, tc.event, apply); err == nil { |
| - t.Fatalf("%s (apply %v) accepted", name, apply) |
| - } |
| - } |
| - } |
| - if err := RunLive(context.Background(), x.out, x.f.origin, liveSQID, nil, x.s, open, liveEvent, true); err == nil { |
| - t.Fatal("ran with no prompter") |
| - } |
| - if err := RunLive(context.Background(), x.out, x.f.origin, liveSQID, x.p, nil, open, liveEvent, true); err == nil { |
| - t.Fatal("ran with no journal") |
| - } |
| - _, _, _, paths, _ := x.f.state() |
| - if len(paths) != 0 || x.out.Len() != 0 { |
| - t.Fatalf("a refused run contacted connect or printed: %q %q", paths, x.out.String()) |
| - } |
| -} |
| - |
| -// The live checks run against production connect only: the origin the |
| -// apps are told to trust, Issuer. Another https origin, even one that |
| -// answers as connect does, is refused before anything is contacted or |
| -// recorded, in a dry run too. |
| -func TestLiveRefusesAnotherConnectOrigin(t *testing.T) { |
| - x := newLive(t) |
| - open := func(string) error { t.Fatal("opened a browser"); return nil } |
| - for _, server := range []string{ |
| - "https://connect.staging.oficina.works", |
| - "https://connect.oficina.works.example", |
| - "https://connect.oficina.works:8443", |
| - "https://oficina.works", |
| - } { |
| - for _, apply := range []bool{false, true} { |
| - err := RunLive(context.Background(), x.out, server, liveSQID, x.p, x.s, open, liveEvent, apply) |
| - if err == nil || !strings.Contains(err.Error(), LiveNeedIssuer) { |
| - t.Fatalf("%s (apply %v): err = %v", server, apply, err) |
| - } |
| - } |
| - } |
| - _, _, _, paths, _ := x.f.state() |
| - if len(paths) != 0 || x.out.Len() != 0 { |
| - t.Fatalf("a refused run contacted connect or printed: %q %q", paths, x.out.String()) |
| - } |
| - wantChecks(t, x.s) |
| - // The issuer itself, with or without its trailing slash, is accepted. |
| - for _, server := range []string{Issuer, Issuer + "/"} { |
| - if err := RunLive(context.Background(), io.Discard, server, liveSQID, x.p, x.s, open, liveEvent, false); err != nil { |
| - t.Fatalf("%s: %v", server, err) |
| - } |
| - } |
| -} |
| - |
| -// Each check is recorded with the origin it was made against. |
| -func TestLiveRecordsTheOriginOfEachCheck(t *testing.T) { |
| - x := newLive(t) |
| - if err := x.run(t); err != nil { |
| - t.Fatal(err) |
| - } |
| - rows, err := x.s.db.Query("SELECT name, origin FROM adopt_checks") |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - defer rows.Close() |
| - n := 0 |
| - for rows.Next() { |
| - var name string |
| - var sealed []byte |
| - if err := rows.Scan(&name, &sealed); err != nil { |
| - t.Fatal(err) |
| - } |
| - if bytes.Contains(sealed, []byte(Issuer)) { |
| - t.Fatalf("%s: the origin is in the clear", name) |
| - } |
| - if got := x.s.checkOrigin(name, sealed); got != Issuer { |
| - t.Fatalf("%s: origin %q", name, got) |
| - } |
| - n++ |
| - } |
| - if n != len(RequiredLiveChecks) { |
| - t.Fatalf("%d checks recorded", n) |
| - } |
| - if err := x.s.LiveGate(context.Background(), "docs"); err != nil { |
| - t.Fatalf("gate after a passing run: %v", err) |
| - } |
| -} |
| - |
| -// MemoryStore keeps the credentials in memory only, hands out copies, |
| -// and forgets them on Delete. |
| -func TestLiveMemoryStore(t *testing.T) { |
| - var m MemoryStore |
| - if _, err := m.Load(); err == nil { |
| - t.Fatal("an empty store loaded") |
| - } |
| - tok := &oauth2.Token{AccessToken: "bearer-canary-store", Expiry: time.Now().Add(time.Minute)} |
| - if err := m.Save(client.Credentials{Server: "https://connect.oficina.works", Token: tok}); err != nil { |
| - t.Fatal(err) |
| - } |
| - tok.AccessToken = "changed after save" |
| - got, err := m.Load() |
| - if err != nil || got.Token == nil || got.Token.AccessToken != "bearer-canary-store" { |
| - t.Fatalf("load %v %v", got.Token, err) |
| - } |
| - got.Token.AccessToken = "changed after load" |
| - if again, _ := m.Load(); again.Token.AccessToken != "bearer-canary-store" { |
| - t.Fatal("a loaded copy shares the stored token") |
| - } |
| - if err := m.Delete(); err != nil { |
| - t.Fatal(err) |
| - } |
| - if _, err := m.Load(); err == nil { |
| - t.Fatal("loaded after Delete") |
| - } |
| -} |
diff --git a/adopt/observer.go b/adopt/observer.go| index f65cc7b..27dc77d 100644 |
| --- a/adopt/observer.go |
| +++ b/adopt/observer.go |
| @@ -68,15 +68,15 @@ func (o *Observer) now() time.Time { |
| // (a *Refusal) unless every one of these holds: |
| // |
| // - evidence: the pre-plan-a Home preflight, the baseline, a landed |
| -// write, the after snapshot and the witness (missing-<x>); no |
| +// write, the after snapshot and the delivery check (missing-<x>); no |
| // rollback (rollback-recorded); |
| // - the write sent Issuer and teamSQID (issuer-mismatch, |
| // team-mismatch); |
| -// - live checks: S.LiveGate passes (live-checks-missing); |
| +// - Plan C: S.CanaryGate passes (canary-not-active); |
| // - the app's reviewed artifact SHA-256 is configured |
| // (artifact-unreviewed); |
| // - identity: a fresh read's equals the baseline's, the after |
| -// snapshot's and the witness's (identity-<code>); |
| +// snapshot's and the delivery check's (identity-<code>); |
| // - preservation: Preserved(baseline, after) is empty |
| // (after-not-preserved), and so is Preserved(baseline, fresh) |
| // (drift-<code>); |
| @@ -85,9 +85,9 @@ func (o *Observer) now() time.Time { |
| // (config-<code>); no team-mode key (team-mode-<KEY>); both agent |
| // keys are plain vars from the write layer carrying the sent |
| // digests (agent-key-<KEY>); |
| -// - the witness is current: its after version is the fresh write |
| -// layer's, and its delivered version and header are the fresh ones |
| -// (witness-superseded). There is no wall-clock limit; |
| +// - the delivery check is current: its after version is the fresh |
| +// 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 equals X-Carlos-Version |
| // (version-header-mismatch) and Home admits it |
| @@ -129,7 +129,7 @@ func (o *Observer) Observe(ctx context.Context, app, teamSQID string) (provision |
| keys := AgentKeys(a) |
| addAll("identity-", SameIdentity(ev.base.Identity, fresh.Identity)...) |
| addAll("identity-", SameIdentity(ev.after.Identity, fresh.Identity)...) |
| - addAll("identity-", SameIdentity(ev.witness.Identity, fresh.Identity)...) |
| + addAll("identity-", SameIdentity(ev.check.Identity, fresh.Identity)...) |
| if len(Preserved(ev.base, ev.after, keys)) > 0 { |
| add("after-not-preserved") |
| } |
| @@ -142,9 +142,9 @@ func (o *Observer) Observe(ctx context.Context, app, teamSQID string) (provision |
| add("agent-key-" + k) |
| } |
| } |
| - w := ev.witness |
| - if w.AfterVersion != fresh.Layer.Version || w.Delivery.Version != fresh.Delivery.Version || w.Delivery.Header != fresh.Delivery.Header { |
| - add("witness-superseded") |
| + chk := ev.check |
| + if chk.AfterVersion != fresh.Layer.Version || chk.Delivery.Version != fresh.Delivery.Version || chk.Delivery.Header != fresh.Delivery.Header { |
| + add("delivery-check-superseded") |
| } |
| d := fresh.Delivery |
| if Delivered(ev.base.Delivery, d) != nil { |
| @@ -180,7 +180,7 @@ 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, |
| + Check: chk, |
| }), |
| }, nil |
| } |
| @@ -189,7 +189,7 @@ func (o *Observer) Observe(ctx context.Context, app, teamSQID string) (provision |
| type gateEvidence struct { |
| base, after Snapshot |
| write WriteRecord |
| - witness Witness |
| + check DeliveryCheck |
| artifact string |
| } |
| @@ -220,8 +220,8 @@ func (o *Observer) evidence(ctx context.Context, a provision.App, teamSQID strin |
| if err := have(ok, err, "after"); err != nil { |
| return ev, err |
| } |
| - witness, ok, err := o.S.Witness(ctx, a.Slug) |
| - if err := have(ok, err, "witness"); err != nil { |
| + check, ok, err := o.S.DeliveryCheck(ctx, a.Slug) |
| + if err := have(ok, err, "delivery-check"); err != nil { |
| return ev, err |
| } |
| if len(missing) > 0 { |
| @@ -243,9 +243,9 @@ func (o *Observer) evidence(ctx context.Context, a provision.App, teamSQID strin |
| if len(codes) > 0 { |
| return ev, refuse(codes...) |
| } |
| - if err := o.S.LiveGate(ctx, a.Slug); err != nil { |
| - if errors.Is(err, ErrLiveChecksMissing) { |
| - return ev, refuse("live-checks-missing") |
| + if err := o.S.CanaryGate(ctx, a.Slug); err != nil { |
| + if errors.Is(err, ErrCanaryNotActive) { |
| + return ev, refuse("canary-not-active") |
| } |
| return ev, err |
| } |
| @@ -253,5 +253,5 @@ func (o *Observer) evidence(ctx context.Context, a provision.App, teamSQID strin |
| if !artifactShape.MatchString(artifact) { |
| return ev, refuse("artifact-unreviewed") |
| } |
| - return gateEvidence{base: base, after: after, write: write, witness: witness, artifact: artifact}, nil |
| + return gateEvidence{base: base, after: after, write: write, check: check, artifact: artifact}, nil |
| } |
diff --git a/adopt/observer_test.go b/adopt/observer_test.go| index 611acd5..2415f3a 100644 |
| --- a/adopt/observer_test.go |
| +++ b/adopt/observer_test.go |
| @@ -16,7 +16,7 @@ import ( |
| ) |
| // observerFixture is an app through configure: written, restarted until |
| -// delivered, its after snapshot captured and witnessed, with the |
| +// delivered, its after snapshot captured and its delivery checked, with the |
| // pre-plan-a Home preflight recorded and its served release reviewed. |
| type observerFixture struct { |
| *writeFixture |
| @@ -37,8 +37,8 @@ func newObserverFixture(t *testing.T, slug string, before ...func(*writeFixture) |
| } |
| w.configured(t) |
| ctx := context.Background() |
| - if err := RecordWitness(ctx, w.s, w.c, w.h, w.app, WitnessSentence(w.app), true); err != nil { |
| - t.Fatalf("RecordWitness: %v", err) |
| + if err := CheckDelivery(ctx, w.s, w.c, w.h, w.app, sha256Hex(w.site.header)); err != nil { |
| + t.Fatalf("CheckDelivery: %v", err) |
| } |
| if err := w.s.SaveHomePreflight(ctx, HomePreflight{Phase: PhasePrePlanA, ProposedID: 1, ProposedSQID: fixtureSQID, AttestedAt: at.Add(-time.Hour)}); err != nil { |
| t.Fatal(err) |
| @@ -79,11 +79,11 @@ func (x *observerFixture) refused(t *testing.T, want ...string) []string { |
| // evidence is the journal's records the gate reads; nil is absent. |
| type evidence struct { |
| - home *HomePreflight |
| - base *Snapshot |
| - write *WriteRecord |
| - after *Snapshot |
| - witness *Witness |
| + home *HomePreflight |
| + base *Snapshot |
| + write *WriteRecord |
| + after *Snapshot |
| + check *DeliveryCheck |
| } |
| // rejournal moves the observer onto a new journal holding the current |
| @@ -113,10 +113,10 @@ func (x *observerFixture) rejournal(t *testing.T, edit func(e *evidence)) { |
| } else if ok { |
| e.after = &r |
| } |
| - if r, ok, err := x.s.Witness(ctx, x.app.Slug); err != nil { |
| + if r, ok, err := x.s.DeliveryCheck(ctx, x.app.Slug); err != nil { |
| t.Fatal(err) |
| } else if ok { |
| - e.witness = &r |
| + e.check = &r |
| } |
| edit(&e) |
| s := newJournal(t) |
| @@ -138,8 +138,8 @@ func (x *observerFixture) rejournal(t *testing.T, edit func(e *evidence)) { |
| if e.after != nil { |
| must(s.SaveAfter(ctx, x.app.Slug, *e.after)) |
| } |
| - if e.witness != nil { |
| - must(s.SaveWitness(ctx, *e.witness)) |
| + if e.check != nil { |
| + must(s.SaveDeliveryCheck(ctx, *e.check)) |
| } |
| x.s, x.o.S = s, s |
| } |
| @@ -165,7 +165,7 @@ func TestObserverHappyPathEvidenceTokens(t *testing.T) { |
| // The binding is over the journal's evidence and this observation. |
| base, ok1, err1 := x.s.Baseline(ctx, "calendar") |
| after, ok2, err2 := x.s.After(ctx, "calendar") |
| - wit, ok3, err3 := x.s.Witness(ctx, "calendar") |
| + chk, ok3, err3 := x.s.DeliveryCheck(ctx, "calendar") |
| if err := errors.Join(err1, err2, err3); err != nil || !ok1 || !ok2 || !ok3 { |
| t.Fatalf("the journal lacks the evidence: %v", err) |
| } |
| @@ -177,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, |
| + Check: chk, |
| }) |
| if obs.EnvironmentBinding != want { |
| t.Fatal("environment_binding is not the binding of the journal's evidence and the fresh delivery") |
| @@ -189,9 +189,9 @@ func TestObserverHappyPathEvidenceTokens(t *testing.T) { |
| } |
| } |
| -// The witness has no age limit: a later session, days on, with nothing |
| -// else changed, still passes. |
| -func TestObserverAcceptsWitnessFromEarlierSession(t *testing.T) { |
| +// The delivery check has no age limit: a later session, days on, with |
| +// nothing else changed, still passes. |
| +func TestObserverAcceptsDeliveryCheckFromEarlierSession(t *testing.T) { |
| x := newObserverFixture(t, "calendar") |
| first, err := x.observe() |
| if err != nil { |
| @@ -208,33 +208,33 @@ func TestObserverAcceptsWitnessFromEarlierSession(t *testing.T) { |
| } |
| } |
| -func TestObserverRefusesSupersededWitness(t *testing.T) { |
| +func TestObserverRefusesSupersededDeliveryCheck(t *testing.T) { |
| t.Run("after snapshot retaken", func(t *testing.T) { |
| x := newObserverFixture(t, "calendar") |
| // A platform writer adds a key (reported, not fatal) and the after |
| - // snapshot is taken again: the witness saw the earlier version. |
| + // snapshot is taken again: the check saw the earlier version. |
| x.f.PlatformWrite("calendar", "", x.app.Prefix+"_PLATFORM_NOTE", "n") |
| if _, err := CaptureAfter(context.Background(), x.c, x.h, x.s, x.app); err != nil { |
| t.Fatalf("CaptureAfter: %v", err) |
| } |
| - wantCodes(t, x.refused(t), "witness-superseded") |
| + wantCodes(t, x.refused(t), "delivery-check-superseded") |
| }) |
| - edits := map[string]func(w *Witness){ |
| - "after version": func(w *Witness) { w.AfterVersion = "cv1:" + hex64("9") }, |
| - "delivered version": func(w *Witness) { w.Delivery.Version = "v1.3.9" }, |
| - "delivered header": func(w *Witness) { w.Delivery.Header = "v1.3.9" }, |
| + edits := map[string]func(c *DeliveryCheck){ |
| + "after version": func(c *DeliveryCheck) { c.AfterVersion = "cv1:" + hex64("9") }, |
| + "delivered version": func(c *DeliveryCheck) { c.Delivery.Version = "v1.3.9" }, |
| + "delivered header": func(c *DeliveryCheck) { c.Delivery.Header = "v1.3.9" }, |
| } |
| for name, edit := range edits { |
| t.Run(name, func(t *testing.T) { |
| x := newObserverFixture(t, "calendar") |
| - x.rejournal(t, func(e *evidence) { edit(e.witness) }) |
| - wantCodes(t, x.refused(t), "witness-superseded") |
| + x.rejournal(t, func(e *evidence) { edit(e.check) }) |
| + wantCodes(t, x.refused(t), "delivery-check-superseded") |
| }) |
| } |
| t.Run("redeployed", func(t *testing.T) { |
| x := newObserverFixture(t, "calendar") |
| x.site.version, x.site.header = "v1.5.0", "v1.5.0" |
| - x.refused(t, "witness-superseded") |
| + x.refused(t, "delivery-check-superseded") |
| }) |
| } |
| @@ -259,18 +259,16 @@ func TestObserverRefusals(t *testing.T) { |
| want: []string{"missing-write"}, exact: true}, |
| {name: "no after", edit: func(t *testing.T, x *observerFixture) { x.rejournal(t, func(e *evidence) { e.after = nil }) }, |
| want: []string{"missing-after"}, exact: true}, |
| - {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: "no delivery check", edit: func(t *testing.T, x *observerFixture) { x.rejournal(t, func(e *evidence) { e.check = nil }) }, |
| + want: []string{"missing-delivery-check"}, exact: true}, |
| {name: "rollback recorded", edit: func(t *testing.T, x *observerFixture) { |
| 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 { |
| - setupOK(t, x.s.SaveCheck(ctx, Issuer, c, "passed")) |
| - } |
| - setupOK(t, x.s.SaveCheck(ctx, Issuer, "member-no-local-permission-refused", "failed:allowed")) |
| - }, want: []string{"live-checks-missing"}, exact: true}, |
| + {name: "canary not active", app: "docs", want: []string{"canary-not-active"}, exact: true}, |
| + {name: "canary rolled back since", app: "docs", edit: func(t *testing.T, x *observerFixture) { |
| + canaryActive(t, x.s) |
| + setupOK(t, x.s.SaveRollback(ctx, RollbackRecord{App: CanaryApp, State: "restarted"})) |
| + }, want: []string{"canary-not-active"}, exact: true}, |
| {name: "artifact not reviewed", edit: func(t *testing.T, x *observerFixture) { x.o.Artifacts = nil }, |
| want: []string{"artifact-unreviewed"}, exact: true}, |
| {name: "artifact not lowercase hex", edit: func(t *testing.T, x *observerFixture) { |
| @@ -295,8 +293,8 @@ func TestObserverRefusals(t *testing.T) { |
| {name: "after identity differs", edit: func(t *testing.T, x *observerFixture) { |
| x.rejournal(t, func(e *evidence) { e.after.Identity.Region = "us" }) |
| }, want: []string{"after-not-preserved", "identity-region"}, exact: true}, |
| - {name: "witness identity differs", edit: func(t *testing.T, x *observerFixture) { |
| - x.rejournal(t, func(e *evidence) { e.witness.Identity.Channel = "beta" }) |
| + {name: "delivery check identity differs", edit: func(t *testing.T, x *observerFixture) { |
| + x.rejournal(t, func(e *evidence) { e.check.Identity.Channel = "beta" }) |
| }, want: []string{"identity-channel"}, exact: true}, |
| {name: "after not preserved", edit: func(t *testing.T, x *observerFixture) { |
| // A hand-written after row in which a preserved secret was |
| @@ -338,7 +336,7 @@ func TestObserverRefusals(t *testing.T) { |
| x.site.header = "rel-2026" |
| x.o.Artifacts = map[string]string{"calendar": sha256Hex("rel-2026")} |
| x.rejournal(t, func(e *evidence) { |
| - e.base.Delivery.Header, e.after.Delivery.Header, e.witness.Delivery.Header = "rel-2026", "rel-2026", "rel-2026" |
| + e.base.Delivery.Header, e.after.Delivery.Header, e.check.Delivery.Header = "rel-2026", "rel-2026", "rel-2026" |
| }) |
| }, want: []string{"version-header-mismatch"}, exact: true}, |
| } |
| @@ -382,18 +380,23 @@ func TestObserverRefusesUnknownAppAndBadTeam(t *testing.T) { |
| } |
| } |
| -func TestObserverPassesNonCanaryWithLiveChecks(t *testing.T) { |
| +// Plan C needs Plan B alone: with the canary active, a non-canary app |
| +// passes, with no live check recorded. |
| +func TestObserverPassesNonCanaryOnceCanaryActive(t *testing.T) { |
| x := newObserverFixture(t, "docs") |
| - for _, c := range RequiredLiveChecks { |
| - if err := x.s.SaveCheck(context.Background(), Issuer, c, "passed"); err != nil { |
| - t.Fatal(err) |
| - } |
| - } |
| + canaryActive(t, x.s) |
| if _, err := x.observe(); err != nil { |
| t.Fatalf("Observe: %v", err) |
| } |
| } |
| +// canaryActive records Plan B's activation of the canary in s's engine |
| +// steps, as the engine does when Home has activated it. |
| +func canaryActive(t *testing.T, s *Store) { |
| + t.Helper() |
| + setupOK(t, s.ps.SetStep(context.Background(), provision.AdoptionLabel, CanaryApp, provision.StepActivate, "done", "", nil)) |
| +} |
| + |
| // 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) { |
| @@ -406,17 +409,17 @@ func setupOK(t *testing.T, err error) { |
| // provision's engine parks an activation with the gate's own codes: it |
| // reads them through provision.ObserverRefusal, as a copy. |
| func TestObserverRefusalReachesTheEngine(t *testing.T) { |
| - err := error(refuse("witness-superseded", "missing-witness")) |
| + err := error(refuse("delivery-check-superseded", "missing-delivery-check")) |
| var r provision.ObserverRefusal |
| if !errors.As(err, &r) { |
| t.Fatal("a refusal is not a provision.ObserverRefusal") |
| } |
| codes := r.RefusalCodes() |
| - if !slices.Equal(codes, []string{"missing-witness", "witness-superseded"}) { |
| + if !slices.Equal(codes, []string{"delivery-check-superseded", "missing-delivery-check"}) { |
| t.Fatalf("codes %v", codes) |
| } |
| codes[0] = "edited" |
| - if r.RefusalCodes()[0] != "missing-witness" { |
| + if r.RefusalCodes()[0] != "delivery-check-superseded" { |
| t.Fatal("the engine can edit the refusal's codes") |
| } |
| } |
diff --git a/adopt/rehearsal_test.go b/adopt/rehearsal_test.go| index 9774931..1050776 100644 |
| --- a/adopt/rehearsal_test.go |
| +++ b/adopt/rehearsal_test.go |
| @@ -1,11 +1,11 @@ |
| package adopt |
| // The rehearsal: the whole adoption in the order Paul runs it, against |
| -// the in-memory Home, the fake console, the six apps' origins and a fake |
| -// connect. Home preflights, CARLOS preflight, initialize, Plan A, |
| -// configure and witness for each app, Plan B for the canary, the live |
| -// checks, Plan C. Then the same run killed at every act, Home's and |
| -// CARLOS's, and resumed by a fresh process. |
| +// the in-memory Home, the fake console and the six apps' origins. Home |
| +// preflights, CARLOS preflight, initialize, Plan A, configure (with its |
| +// delivery check) for each app, Plan B for the canary, Plan C. Then the |
| +// same run killed at every act, Home's and CARLOS's, and resumed by a |
| +// fresh process. |
| import ( |
| "bytes" |
| @@ -59,11 +59,10 @@ type rehearsal struct { |
| mu sync.Mutex |
| now time.Time |
| - home *fakehome.Home |
| - hc *homeop.Client |
| - carlos *fakecarlos.Fake |
| - h *http.Client // the apps' origins |
| - connect *fakeConnect |
| + home *fakehome.Home |
| + hc *homeop.Client |
| + carlos *fakecarlos.Fake |
| + h *http.Client // the apps' origins |
| path string // the state database |
| ps *provision.Store |
| @@ -188,12 +187,6 @@ func newRehearsal(t *testing.T) *rehearsal { |
| tr.TLSClientConfig.ServerName = "example.com" |
| r.h = &http.Client{Transport: tr, Timeout: 10 * time.Second} |
| - r.connect = newFakeConnect(t) |
| - oldT, oldNow := liveTransport, liveNow |
| - liveTransport = r.connect.transport() |
| - liveNow = time.Now |
| - t.Cleanup(func() { liveTransport, liveNow = oldT, oldNow }) |
| - |
| r.path = filepath.Join(t.TempDir(), "alta.db") |
| r.ps, r.js = r.journal() |
| r.cfg = provision.Config{ |
| @@ -395,7 +388,6 @@ func (r *rehearsal) planA() { |
| r.t.Fatalf("no seeded team: %v", err) |
| } |
| r.sqid = team.TeamSQID |
| - r.connect.team = r.sqid |
| } |
| // observer is the activation gate as alta-adopt builds it, over a fresh |
| @@ -639,23 +631,26 @@ func (r *rehearsal) checkBaselines() { |
| // configure is alta-adopt configure --app --apply: the write, then, unless |
| // the after snapshot is already taken, the restart until delivered and |
| -// the after snapshot. |
| +// the after snapshot, then the delivery check. |
| func configureApp(ctx context.Context, c *carlosop.Client, h *http.Client, js *Store, a provision.App, sqid string) error { |
| if _, err := WriteAgentKeys(ctx, c, h, js, a, sqid, true); err != nil { |
| return err |
| } |
| - if _, ok, err := js.After(ctx, a.Slug); err != nil || ok { |
| - return err |
| - } |
| - base, ok, err := js.Baseline(ctx, a.Slug) |
| - if err != nil || !ok { |
| - return fmt.Errorf("no baseline: %v", err) |
| - } |
| - if _, err := RestartAndWait(ctx, c, h, a, base.Identity, func(d Delivery) error { return Delivered(base.Delivery, d) }, true); err != nil { |
| + if _, ok, err := js.After(ctx, a.Slug); err != nil { |
| return err |
| + } else if !ok { |
| + base, ok, err := js.Baseline(ctx, a.Slug) |
| + if err != nil || !ok { |
| + return fmt.Errorf("no baseline: %v", err) |
| + } |
| + if _, err := RestartAndWait(ctx, c, h, a, base.Identity, func(d Delivery) error { return Delivered(base.Delivery, d) }, true); err != nil { |
| + return err |
| + } |
| + if _, err := CaptureAfter(ctx, c, h, js, a); err != nil { |
| + return err |
| + } |
| } |
| - _, err = CaptureAfter(ctx, c, h, js, a) |
| - return err |
| + return CheckDelivery(ctx, js, c, h, a, sha256Hex(valueVersion)) |
| } |
| func (r *rehearsal) configure(a provision.App, point crashPoint) int { |
| @@ -667,13 +662,6 @@ func (r *rehearsal) configure(a provision.App, point crashPoint) int { |
| return deaths |
| } |
| -func (r *rehearsal) witness(a provision.App) { |
| - r.t.Helper() |
| - r.step(a.Slug, noCrash, func(ctx context.Context, c *carlosop.Client, js *Store) error { |
| - return RecordWitness(ctx, js, c, r.h, a, WitnessSentence(a), true) |
| - }) |
| -} |
| - |
| func (r *rehearsal) rollback(a provision.App, point crashPoint) int { |
| r.t.Helper() |
| return r.step(a.Slug, point, func(ctx context.Context, c *carlosop.Client, js *Store) error { |
| @@ -693,18 +681,6 @@ func (r *rehearsal) carlosPreflight() { |
| } |
| } |
| -// live is alta-adopt live --apply, Paul at the prompts. |
| -func (r *rehearsal) live() { |
| - r.t.Helper() |
| - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| - defer cancel() |
| - p := &fakePrompter{f: r.connect} |
| - if err := RunLive(ctx, io.Discard, r.connect.origin, r.sqid, p, r.js, r.connect.open, liveEvent, true); err != nil { |
| - r.t.Fatalf("live: %v", err) |
| - } |
| - allRevoked(r.t, r.connect) |
| -} |
| - |
| // ---- the run ---- |
| // options bends one run: where a CARLOS process dies, and a hook on every |
| @@ -736,11 +712,7 @@ func (r *rehearsal) run(o options) { |
| r.t.Fatalf("%s: died %d times at %s", a.Slug, deaths, o.configure) |
| } |
| } |
| - for _, a := range provision.Apps { |
| - r.witness(a) |
| - } |
| r.activate(CanaryApp) |
| - r.live() |
| var rest []string |
| for _, s := range provision.Slugs() { |
| if s != CanaryApp { |
| @@ -975,15 +947,14 @@ func TestRehearsalCrashAfterEveryAct(t *testing.T) { |
| } |
| }) |
| - // Mid-rollback: every app configured and witnessed, then rolled back, |
| - // each killed once at the point. |
| + // Mid-rollback: every app configured and its delivery checked, then |
| + // rolled back, each killed once at the point. |
| for _, point := range []crashPoint{beforePut, afterPut, afterRestart} { |
| t.Run("rollback-"+string(point), func(t *testing.T) { |
| r := newRehearsal(t) |
| r.untilPlanA() |
| for _, a := range provision.Apps { |
| r.configure(a, noCrash) |
| - r.witness(a) |
| } |
| r.crashed = map[string]bool{} |
| for _, a := range provision.Apps { |
| @@ -1069,7 +1040,7 @@ func TestRehearsalDeadProcessTouchesNothing(t *testing.T) { |
| return errors.New("the PUT was answered") |
| } |
| // Whatever a dead process would do next. |
| - return js.SaveCheck(context.Background(), Issuer, RequiredLiveChecks[0], "passed") |
| + return js.SaveDeliveryCheck(context.Background(), DeliveryCheck{App: "docs"}) |
| }) |
| if died, err := x.await(); !died { |
| t.Fatalf("the process finished (%v) instead of dying in its PUT", err) |
| @@ -1083,8 +1054,8 @@ func TestRehearsalDeadProcessTouchesNothing(t *testing.T) { |
| t.Fatal("the dead process was not cut off") |
| } |
| var n int |
| - if err := r.ps.DB().QueryRow("SELECT count(*) FROM adopt_checks").Scan(&n); err != nil || n != 0 { |
| - t.Fatalf("journal checks %d (%v)", n, err) |
| + if err := r.ps.DB().QueryRow("SELECT count(*) FROM adopt_witnesses").Scan(&n); err != nil || n != 0 { |
| + t.Fatalf("journal delivery checks %d (%v)", n, err) |
| } |
| if n := r.putsOf("docs"); n != 0 { |
| t.Fatalf("%d PUTs reached the console", n) |
diff --git a/adopt/store.go b/adopt/store.go| index 259b377..7672aa9 100644 |
| --- a/adopt/store.go |
| +++ b/adopt/store.go |
| @@ -32,9 +32,10 @@ var ( |
| // ErrBaselineExists is a second baseline for an app: a baseline is |
| // captured once and never rebaselined. |
| ErrBaselineExists = errors.New("adopt: the app already has its baseline") |
| - // ErrLiveChecksMissing is the live-check gate closed: a check |
| - // RequiredLiveChecks names has not passed, or one has failed. |
| - ErrLiveChecksMissing = errors.New("live-checks-missing") |
| + // ErrCanaryNotActive is Plan C's gate closed: Plan B has not |
| + // activated the canary, or the canary has since been rolled back or |
| + // disabled. |
| + ErrCanaryNotActive = errors.New("canary-not-active") |
| ) |
| // Home preflight phases. |
| @@ -43,7 +44,7 @@ const ( |
| PhasePrePlanA = "pre-plan-a" |
| ) |
| -// CanaryApp is the app Plan B activates before the live checks run. |
| +// CanaryApp is the app Plan B activates alone, before Plan C. |
| const CanaryApp = "calendar" |
| // Store is the adoption journal over Alta's provision store. |
| @@ -85,8 +86,11 @@ const ( |
| tWrites = "adopt_writes" |
| tRollbacks = "adopt_rollbacks" |
| tAfters = "adopt_afters" |
| - tWitnesses = "adopt_witnesses" |
| - tChecks = "adopt_checks" |
| + // The delivery check takes the place, and the table, of Paul's |
| + // witness (Home discussion 103, 2026-11-17): the payload changed |
| + // shape, the purpose did not. adopt_checks, the live checks' table, |
| + // is no longer written or read. |
| + tWitnesses = "adopt_witnesses" |
| ) |
| func purpose(table, key string) string { return "alta/adopt/" + table + "/" + key } |
| @@ -277,108 +281,49 @@ func (s *Store) After(ctx context.Context, app string) (Snapshot, bool, error) { |
| return snap, ok, err |
| } |
| -// SaveWitness records Paul's witness for w.App, replacing a voided one. |
| -func (s *Store) SaveWitness(ctx context.Context, w Witness) error { |
| - if err := knownApp(w.App); err != nil { |
| +// SaveDeliveryCheck records c.App's delivery check, replacing an |
| +// earlier one. |
| +func (s *Store) SaveDeliveryCheck(ctx context.Context, c DeliveryCheck) error { |
| + if err := knownApp(c.App); err != nil { |
| return err |
| } |
| - return s.put(ctx, tWitnesses, "app", w.App, w) |
| + return s.put(ctx, tWitnesses, "app", c.App, c) |
| } |
| -// Witness reads app's witness. |
| -func (s *Store) Witness(ctx context.Context, app string) (Witness, bool, error) { |
| - var w Witness |
| - ok, err := s.get(ctx, tWitnesses, "app", app, &w) |
| - return w, ok, err |
| +// DeliveryCheck reads app's delivery check. |
| +func (s *Store) DeliveryCheck(ctx context.Context, app string) (DeliveryCheck, bool, error) { |
| + var c DeliveryCheck |
| + ok, err := s.get(ctx, tWitnesses, "app", app, &c) |
| + return c, ok, err |
| } |
| -// SaveCheck appends one live check's outcome, with the connect origin it |
| -// was made against (a plain https origin): "passed", "inconclusive", or |
| -// "failed:<code>" with a fixed lower-case code. Every outcome is kept: a |
| -// failure is never overwritten by a later pass. |
| -func (s *Store) SaveCheck(ctx context.Context, origin, name, outcome string) error { |
| - if !slices.Contains(RequiredLiveChecks, name) { |
| - return errors.New("adopt: not a live check") |
| - } |
| - if !liveOutcome.MatchString(outcome) { |
| - return errors.New("adopt: not a live check outcome") |
| +// CanaryGate is Plan C's gate, the one implementation of it (Paul, |
| +// 2026-11-17: Plan C waits on Plan B alone). The canary is never gated. |
| +// Every other app is admitted only once Plan B's activation of the |
| +// canary is done in the engine's steps, and only while the canary has |
| +// neither a rollback in the journal (in any state) nor a done disable; |
| +// otherwise ErrCanaryNotActive. |
| +func (s *Store) CanaryGate(ctx context.Context, app string) error { |
| + if app == CanaryApp { |
| + return nil |
| } |
| - if !httpsOrigin(origin) { |
| - return errors.New("adopt: not a connect origin") |
| + if knownApp(app) != nil { |
| + return ErrCanaryNotActive |
| } |
| - sealed, err := s.sealed(tChecks, name, origin) |
| + _, active, err := s.ps.Done(ctx, provision.AdoptionLabel, CanaryApp, provision.StepActivate) |
| if err != nil { |
| return err |
| } |
| - _, err = s.exec(ctx, "INSERT INTO adopt_checks(origin,name,outcome) VALUES(?,?,?)", sealed, name, outcome) |
| - return err |
| -} |
| - |
| -// checkOrigin opens a check's sealed origin; "" when it has none or it |
| -// does not open. |
| -func (s *Store) checkOrigin(name string, sealed []byte) string { |
| - if len(sealed) == 0 { |
| - return "" |
| - } |
| - b, err := s.ps.OpenAdoption(purpose(tChecks, name), sealed) |
| - if err != nil { |
| - return "" |
| - } |
| - var origin string |
| - if json.Unmarshal(b, &origin) != nil { |
| - return "" |
| - } |
| - return origin |
| -} |
| - |
| -// LiveGate is the live-check rule, the one implementation of it. The |
| -// canary app activates before the checks run, so it is never gated. |
| -// Every other app is admitted only when each of RequiredLiveChecks has |
| -// passed and no check has ever failed; otherwise ErrLiveChecksMissing. |
| -// An inconclusive outcome neither passes nor fails; any outcome not |
| -// known here counts as a failure. Only checks made against production |
| -// connect, the agent issuer the apps were told to trust (Issuer), count: |
| -// a check recorded against any other origin, or none, or one whose |
| -// origin does not open, closes the gate. |
| -func (s *Store) LiveGate(ctx context.Context, app string) error { |
| - if app == CanaryApp { |
| - return nil |
| - } |
| - rows, err := s.db.QueryContext(ctx, "SELECT origin,name,outcome FROM adopt_checks") |
| + _, disabled, err := s.ps.Done(ctx, provision.AdoptionLabel, CanaryApp, provision.StepDisable) |
| if err != nil { |
| return err |
| } |
| - defer rows.Close() |
| - passed := map[string]bool{} |
| - failed := false |
| - for rows.Next() { |
| - var sealed []byte |
| - var name, outcome string |
| - if err := rows.Scan(&sealed, &name, &outcome); err != nil { |
| - return err |
| - } |
| - if s.checkOrigin(name, sealed) != Issuer { |
| - failed = true |
| - continue |
| - } |
| - switch outcome { |
| - case livePassed: |
| - passed[name] = true |
| - case liveInconclusive: |
| - default: |
| - failed = true |
| - } |
| - } |
| - if err := rows.Err(); err != nil { |
| + _, rolledBack, err := s.Rollback(ctx, CanaryApp) |
| + if err != nil { |
| return err |
| } |
| - if failed || knownApp(app) != nil { |
| - return ErrLiveChecksMissing |
| - } |
| - for _, name := range RequiredLiveChecks { |
| - if !passed[name] { |
| - return ErrLiveChecksMissing |
| - } |
| + if !active || disabled || rolledBack { |
| + return ErrCanaryNotActive |
| } |
| return nil |
| } |
diff --git a/adopt/store_test.go b/adopt/store_test.go| index dbb408b..bda6618 100644 |
| --- a/adopt/store_test.go |
| +++ b/adopt/store_test.go |
| @@ -213,7 +213,7 @@ func TestJournalRoundTrips(t *testing.T) { |
| if got, ok, err := s.Write(ctx, "docs"); err != nil || !ok || !reflect.DeepEqual(got, w) { |
| t.Fatalf("write %v %v\n%+v", ok, err, got) |
| } |
| - r := RollbackRecord{App: "docs", State: "unset", Receipt: receipt(), Code: "witness-refused"} |
| + r := RollbackRecord{App: "docs", State: "unset", Receipt: receipt(), Code: "restart-failed"} |
| if err := s.SaveRollback(ctx, r); err != nil { |
| t.Fatal(err) |
| } |
| @@ -227,18 +227,18 @@ func TestJournalRoundTrips(t *testing.T) { |
| if got, ok, err := s.After(ctx, "docs"); err != nil || !ok || !reflect.DeepEqual(got, after) { |
| t.Fatalf("after %v %v\n%+v", ok, err, got) |
| } |
| - wit := Witness{App: "docs", Typed: "docs", Identity: after.Identity, Delivery: after.Delivery, AfterVersion: versionB, At: at} |
| - if err := s.SaveWitness(ctx, wit); err != nil { |
| + chk := DeliveryCheck{App: "docs", Identity: after.Identity, Delivery: after.Delivery, AfterVersion: versionB, At: at} |
| + if err := s.SaveDeliveryCheck(ctx, chk); err != nil { |
| t.Fatal(err) |
| } |
| - if got, ok, err := s.Witness(ctx, "docs"); err != nil || !ok || !reflect.DeepEqual(got, wit) { |
| - t.Fatalf("witness %v %v\n%+v", ok, err, got) |
| + if got, ok, err := s.DeliveryCheck(ctx, "docs"); err != nil || !ok || !reflect.DeepEqual(got, chk) { |
| + t.Fatalf("delivery check %v %v\n%+v", ok, err, got) |
| } |
| for name, f := range map[string]func() (bool, error){ |
| "write": func() (bool, error) { _, ok, err := s.Write(ctx, "sheets"); return ok, err }, |
| "rollback": func() (bool, error) { _, ok, err := s.Rollback(ctx, "sheets"); return ok, err }, |
| "after": func() (bool, error) { _, ok, err := s.After(ctx, "sheets"); return ok, err }, |
| - "witness": func() (bool, error) { _, ok, err := s.Witness(ctx, "sheets"); return ok, err }, |
| + "check": func() (bool, error) { _, ok, err := s.DeliveryCheck(ctx, "sheets"); return ok, err }, |
| } { |
| if ok, err := f(); ok || err != nil { |
| t.Fatalf("%s for an app with none: %v %v", name, ok, err) |
| @@ -269,148 +269,64 @@ func TestJournalRefusesUnknownAppsAndStates(t *testing.T) { |
| if err := s.SaveAfter(ctx, app, Snapshot{}); err == nil { |
| t.Fatalf("after for %q", app) |
| } |
| - if err := s.SaveWitness(ctx, Witness{App: app}); err == nil { |
| - t.Fatalf("witness for %q", app) |
| + if err := s.SaveDeliveryCheck(ctx, DeliveryCheck{App: app}); err == nil { |
| + t.Fatalf("delivery check for %q", app) |
| } |
| } |
| } |
| -func TestLiveGateCanaryAndRest(t *testing.T) { |
| +// Plan C waits on Plan B alone (Paul, 2026-11-17): every app but the |
| +// canary is refused until calendar's activation is done, and again once |
| +// calendar has been rolled back or disabled. |
| +func TestCanaryGate(t *testing.T) { |
| ctx := context.Background() |
| - s := newJournal(t) |
| - if err := s.LiveGate(ctx, "calendar"); err != nil { |
| + ps, s := journal(t, filepath.Join(t.TempDir(), "alta.db")) |
| + if err := s.CanaryGate(ctx, CanaryApp); err != nil { |
| t.Fatalf("canary gated: %v", err) |
| } |
| rest := []string{"docs", "sheets", "slides", "calls", "memoria"} |
| gated := func(why string) { |
| t.Helper() |
| for _, app := range append(rest, "", "mail") { |
| - err := s.LiveGate(ctx, app) |
| - if !errors.Is(err, ErrLiveChecksMissing) || err.Error() != "live-checks-missing" { |
| + err := s.CanaryGate(ctx, app) |
| + if !errors.Is(err, ErrCanaryNotActive) || err.Error() != "canary-not-active" { |
| t.Fatalf("%s: %q gate %v", why, app, err) |
| } |
| } |
| } |
| - gated("none recorded") |
| - for _, name := range RequiredLiveChecks[:len(RequiredLiveChecks)-1] { |
| - if err := s.SaveCheck(ctx, Issuer, name, "passed"); err != nil { |
| - t.Fatal(err) |
| - } |
| - } |
| - gated("one missing") |
| - last := RequiredLiveChecks[len(RequiredLiveChecks)-1] |
| - if err := s.SaveCheck(ctx, Issuer, last, "passed"); err != nil { |
| - t.Fatal(err) |
| - } |
| + gated("nothing recorded") |
| + step := func(app, name, state string) { |
| + t.Helper() |
| + setupOK(t, ps.SetStep(ctx, provision.AdoptionLabel, app, name, state, "", nil)) |
| + } |
| + step(CanaryApp, provision.StepActivate, "parked") |
| + gated("canary parked") |
| + // Another label's calendar is not the canary. |
| + setupOK(t, ps.SetStep(ctx, "other", CanaryApp, provision.StepActivate, "done", "", nil)) |
| + gated("another team's calendar") |
| + // Another app's activation is not the canary's. |
| + step("docs", provision.StepActivate, "done") |
| + gated("docs active, calendar not") |
| + step(CanaryApp, provision.StepActivate, "done") |
| for _, app := range rest { |
| - if err := s.LiveGate(ctx, app); err != nil { |
| - t.Fatalf("%s gated with every check passed: %v", app, err) |
| + if err := s.CanaryGate(ctx, app); err != nil { |
| + t.Fatalf("%s gated with the canary active: %v", app, err) |
| } |
| } |
| - if err := s.LiveGate(ctx, "calendar"); err != nil { |
| - t.Fatal(err) |
| - } |
| - // A failure stays on the record: passing again later does not open |
| - // the gate. |
| - if err := s.SaveCheck(ctx, Issuer, "owner-revoked-refused", "failed:allowed"); err != nil { |
| - t.Fatal(err) |
| - } |
| - gated("one failed") |
| - if err := s.SaveCheck(ctx, Issuer, "owner-revoked-refused", "passed"); err != nil { |
| - t.Fatal(err) |
| - } |
| - gated("failed then passed") |
| - if err := s.LiveGate(ctx, "calendar"); err != nil { |
| - t.Fatalf("canary gated by the rest's checks: %v", err) |
| - } |
| - if err := s.SaveCheck(ctx, Issuer, "made-up", "passed"); err == nil { |
| - t.Fatal("unknown check recorded") |
| + if err := s.CanaryGate(ctx, "mail"); !errors.Is(err, ErrCanaryNotActive) { |
| + t.Fatalf("an unknown app passed: %v", err) |
| } |
| - for _, outcome := range []string{"", "pass", "skipped", "failed", "failed:", "failed:Allowed", "failed:a b", "failed:allowed\n", "inconclusive:x"} { |
| - if err := s.SaveCheck(ctx, Issuer, "member-allowed", outcome); err == nil { |
| - t.Fatalf("outcome %q recorded", outcome) |
| - } |
| - } |
| -} |
| -// An inconclusive check neither passes nor fails: it leaves the gate as |
| -// it was, and a later pass of the same check still counts. |
| -// The gate counts checks made against production connect only, the |
| -// origin the apps trust (Issuer). A check recorded against any other |
| -// origin, or against none (a row older than the origin), closes it. |
| -func TestLiveGateRefusesChecksFromAnotherOrigin(t *testing.T) { |
| - ctx := context.Background() |
| - const other = "https://connect.staging.oficina.works" |
| - passAll := func(s *Store, origin string) { |
| - t.Helper() |
| - for _, name := range RequiredLiveChecks { |
| - if err := s.SaveCheck(ctx, origin, name, "passed"); err != nil { |
| - t.Fatal(err) |
| - } |
| - } |
| - } |
| - s := newJournal(t) |
| - passAll(s, Issuer) |
| - if err := s.LiveGate(ctx, "docs"); err != nil { |
| - t.Fatalf("every check passed against connect: %v", err) |
| - } |
| - if err := s.SaveCheck(ctx, other, "member-allowed", "passed"); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := s.LiveGate(ctx, "docs"); !errors.Is(err, ErrLiveChecksMissing) { |
| - t.Fatalf("a check against another origin: gate %v", err) |
| - } |
| - |
| - s = newJournal(t) |
| - passAll(s, other) |
| - if err := s.LiveGate(ctx, "docs"); !errors.Is(err, ErrLiveChecksMissing) { |
| - t.Fatalf("every check passed against another origin: gate %v", err) |
| - } |
| - |
| - s = newJournal(t) |
| - passAll(s, Issuer) |
| - if _, err := s.db.ExecContext(ctx, "INSERT INTO adopt_checks(name,outcome) VALUES('member-allowed','passed')"); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := s.LiveGate(ctx, "docs"); !errors.Is(err, ErrLiveChecksMissing) { |
| - t.Fatalf("a check with no origin: gate %v", err) |
| - } |
| - |
| - for _, bad := range []string{"", "connect.oficina.works", "http://connect.oficina.works", "https://connect.oficina.works/x", "https://user@connect.oficina.works", "https://connect.oficina.works?x=1"} { |
| - if err := s.SaveCheck(ctx, bad, "member-allowed", "passed"); err == nil { |
| - t.Fatalf("origin %q accepted", bad) |
| - } |
| - } |
| -} |
| - |
| -func TestLiveGateInconclusive(t *testing.T) { |
| - ctx := context.Background() |
| - s := newJournal(t) |
| - for _, name := range RequiredLiveChecks { |
| - if err := s.SaveCheck(ctx, Issuer, name, "inconclusive"); err != nil { |
| - t.Fatal(err) |
| - } |
| - } |
| - if err := s.LiveGate(ctx, "docs"); !errors.Is(err, ErrLiveChecksMissing) { |
| - t.Fatalf("inconclusive checks opened the gate: %v", err) |
| - } |
| - for _, name := range RequiredLiveChecks { |
| - if err := s.SaveCheck(ctx, Issuer, name, "passed"); err != nil { |
| - t.Fatal(err) |
| - } |
| - } |
| - if err := s.SaveCheck(ctx, Issuer, "owner-revoked-refused", "inconclusive"); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := s.LiveGate(ctx, "docs"); err != nil { |
| - t.Fatalf("an inconclusive repeat closed the gate: %v", err) |
| - } |
| - if err := s.SaveCheck(ctx, Issuer, "member-allowed", "failed:forbidden"); err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := s.LiveGate(ctx, "docs"); !errors.Is(err, ErrLiveChecksMissing) { |
| - t.Fatalf("a failed:<code> check left the gate open: %v", err) |
| - } |
| + // Disabled since: closed again. |
| + step(CanaryApp, provision.StepDisable, "done") |
| + gated("canary disabled") |
| + setupOK(t, ps.SetStep(ctx, provision.AdoptionLabel, CanaryApp, provision.StepDisable, "parked", "", nil)) |
| + if err := s.CanaryGate(ctx, "docs"); err != nil { |
| + t.Fatalf("a disable not done closed the gate: %v", err) |
| + } |
| + // Any rollback of the canary, even one only sent: closed for good. |
| + setupOK(t, s.SaveRollback(ctx, RollbackRecord{App: CanaryApp, State: "sent"})) |
| + gated("canary rolled back") |
| } |
| // A sealed row opens only under its own table and key. |
| @@ -429,7 +345,7 @@ func TestAdoptRowsBoundToTheirKey(t *testing.T) { |
| if _, err := s.db.Exec("INSERT INTO adopt_witnesses(app,sealed) SELECT 'docs',sealed FROM adopt_writes WHERE app='docs'"); err != nil { |
| t.Fatal(err) |
| } |
| - if _, _, err := s.Witness(ctx, "docs"); err == nil { |
| + if _, _, err := s.DeliveryCheck(ctx, "docs"); err == nil { |
| t.Fatal("a row copied to another table opened") |
| } |
| } |
| @@ -448,8 +364,7 @@ func TestAdoptRowsAreSealed(t *testing.T) { |
| s.SaveWrite(ctx, WriteRecord{App: "docs", State: "landed", Sent: map[string]string{"DOCS_AGENT_ISSUER": Issuer, "DOCS_AGENT_TEAM": valueCanary}, Receipt: receipt()}), |
| s.SaveRollback(ctx, RollbackRecord{App: "docs", State: "sent", Receipt: receipt()}), |
| s.SaveAfter(ctx, "docs", after), |
| - s.SaveWitness(ctx, Witness{App: "docs", Typed: "docs", Identity: after.Identity, Delivery: after.Delivery, AfterVersion: versionB, At: at}), |
| - s.SaveCheck(ctx, Issuer, "member-allowed", "passed"), |
| + s.SaveDeliveryCheck(ctx, DeliveryCheck{App: "docs", Identity: after.Identity, Delivery: after.Delivery, AfterVersion: versionB, At: at}), |
| } |
| for i, err := range steps { |
| if err != nil { |
diff --git a/adopt/types.go b/adopt/types.go| index f5e5ee4..1fdc813 100644 |
| --- a/adopt/types.go |
| +++ b/adopt/types.go |
| @@ -127,11 +127,13 @@ type Snapshot struct { |
| At time.Time |
| } |
| -// Witness is Paul's recorded confirmation for one app, bound to what he |
| -// observed. AfterVersion is the after snapshot's write-layer version, |
| -// sealed. Any change in Identity, Delivery or the config voids it. |
| -type Witness struct { |
| - App, Typed string |
| +// DeliveryCheck is the runner's own check that one app's restart |
| +// delivered the new configuration, recorded in place of 522 Plan 2 (Paul, |
| +// 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. |
| +type DeliveryCheck struct { |
| + App string |
| Identity Identity |
| Delivery Delivery |
| AfterVersion string |
| @@ -168,10 +170,3 @@ type RollbackRecord struct { |
| Receipt *carlosop.Receipt |
| Code string |
| } |
| - |
| -// RequiredLiveChecks are the checks recorded as passed before Plan C. |
| -var RequiredLiveChecks = []string{ |
| - "non-member-refused", "member-allowed", "member-no-local-permission-refused", |
| - "revoked-membership-refused", "local-access-kept", "owner-allowed", |
| - "owner-revoked-refused", "owner-local-access-kept", |
| -} |
diff --git a/adopt/types_test.go b/adopt/types_test.go| index baa4c3f..ec726fe 100644 |
| --- a/adopt/types_test.go |
| +++ b/adopt/types_test.go |
| @@ -108,12 +108,3 @@ func TestSameIdentityFlagsEachField(t *testing.T) { |
| } |
| }) |
| } |
| - |
| -func TestRequiredLiveChecksFixed(t *testing.T) { |
| - want := []string{"non-member-refused", "member-allowed", "member-no-local-permission-refused", |
| - "revoked-membership-refused", "local-access-kept", "owner-allowed", |
| - "owner-revoked-refused", "owner-local-access-kept"} |
| - if !reflect.DeepEqual(RequiredLiveChecks, want) { |
| - t.Fatalf("live checks = %v", RequiredLiveChecks) |
| - } |
| -} |
diff --git a/adopt/witness_test.go b/adopt/witness_test.go| deleted file mode 100644 |
| index 0bc7a4f..0000000 |
| --- a/adopt/witness_test.go |
| +++ /dev/null |
| @@ -1,299 +0,0 @@ |
| -package adopt |
| - |
| -import ( |
| - "context" |
| - "net/http" |
| - "strings" |
| - "testing" |
| - |
| - "amadan.net/oficina/alta/carlosop" |
| - "amadan.net/oficina/alta/provision" |
| -) |
| - |
| -// witnessFixture is an app configured and restarted: its baseline taken |
| -// with the operations door absent, the agent keys stored, the door now |
| -// answering agent-access's challenge, and the after snapshot recorded. |
| -type witnessFixture struct { |
| - *carlosFixture |
| - s *Store |
| - after Snapshot |
| -} |
| - |
| -func newWitnessFixture(t *testing.T, slug string) *witnessFixture { |
| - t.Helper() |
| - x := newCarlosFixture(t, slug) |
| - s := newJournal(t) |
| - ctx := context.Background() |
| - base, err := Observe(ctx, x.c, x.h, x.app) |
| - if err != nil { |
| - t.Fatalf("Observe baseline: %v", err) |
| - } |
| - if err := s.SaveBaseline(ctx, x.app.Slug, base); err != nil { |
| - t.Fatal(err) |
| - } |
| - keys := AgentKeys(x.app) |
| - x.f.SetVar(x.app.Slug, "", keys[0], Issuer) |
| - x.f.SetVar(x.app.Slug, "", keys[1], "tm_fixture_sqid") |
| - x.site.ops = agent401 |
| - after, err := Observe(ctx, x.c, x.h, x.app) |
| - if err != nil { |
| - t.Fatalf("Observe after: %v", err) |
| - } |
| - if err := s.SaveAfter(ctx, x.app.Slug, after); err != nil { |
| - t.Fatal(err) |
| - } |
| - return &witnessFixture{carlosFixture: x, s: s, after: after} |
| -} |
| - |
| -func (w *witnessFixture) record(typed string, apply bool) error { |
| - return RecordWitness(context.Background(), w.s, w.c, w.h, w.app, typed, apply) |
| -} |
| - |
| -func (w *witnessFixture) noWitness(t *testing.T) { |
| - t.Helper() |
| - if _, ok, err := w.s.Witness(context.Background(), w.app.Slug); err != nil || ok { |
| - t.Fatalf("a witness was recorded (ok %v, err %v)", ok, err) |
| - } |
| -} |
| - |
| -func TestWitnessSentenceNamesTheApp(t *testing.T) { |
| - seen := map[string]string{} |
| - for _, a := range provision.Apps { |
| - s := WitnessSentence(a) |
| - if !strings.Contains(s, CanonicalHost(a)) { |
| - t.Fatalf("%s's sentence does not name its host: %q", a.Slug, s) |
| - } |
| - if other, dup := seen[s]; dup { |
| - t.Fatalf("%s and %s share a sentence", a.Slug, other) |
| - } |
| - seen[s] = a.Slug |
| - } |
| -} |
| - |
| -func TestWitnessRecordsBoundObservation(t *testing.T) { |
| - w := newWitnessFixture(t, "docs") |
| - if err := w.record(" "+WitnessSentence(w.app)+"\n", true); err != nil { |
| - t.Fatalf("RecordWitness: %v", err) |
| - } |
| - got, ok, err := w.s.Witness(context.Background(), "docs") |
| - if err != nil || !ok { |
| - t.Fatalf("no witness (ok %v, err %v)", ok, err) |
| - } |
| - if got.App != "docs" || got.Typed != WitnessSentence(w.app) || got.At.IsZero() { |
| - t.Fatalf("witness app %q typed %q", got.App, got.Typed) |
| - } |
| - if codes := SameIdentity(got.Identity, w.after.Identity); len(codes) > 0 { |
| - t.Fatalf("witness identity differs from the after snapshot's: %v", codes) |
| - } |
| - if got.AfterVersion == "" || got.AfterVersion != w.after.Layer.Version { |
| - t.Fatal("witness is not bound to the after snapshot's write-layer version") |
| - } |
| - if got.Delivery.Ops != OpsAgent401 || got.Delivery.Version != valueVersion || got.Delivery.Header != valueVersion || got.Delivery.Health != 200 { |
| - t.Fatalf("witness delivery ops %q health %d", got.Delivery.Ops, got.Delivery.Health) |
| - } |
| -} |
| - |
| -func TestWitnessRefusesWrongAppSentence(t *testing.T) { |
| - w := newWitnessFixture(t, "docs") |
| - for _, typed := range []string{ |
| - WitnessSentence(appNamed(t, "sheets")), |
| - "", |
| - strings.ToUpper(WitnessSentence(w.app)), |
| - WitnessSentence(w.app) + " too", |
| - } { |
| - err := w.record(typed, true) |
| - if err == nil || err.Error() != "adopt: witness-sentence-mismatch" { |
| - t.Fatalf("typed %q: err = %v", typed, err) |
| - } |
| - } |
| - w.noWitness(t) |
| -} |
| - |
| -// The sentence is checked before anything is read. |
| -func TestWitnessChecksSentenceBeforeReading(t *testing.T) { |
| - w := newWitnessFixture(t, "docs") |
| - n := len(w.f.Requests()) |
| - if err := w.record("no", true); err == nil { |
| - t.Fatal("accepted a wrong sentence") |
| - } |
| - if got := w.f.Requests(); len(got) != n { |
| - t.Fatalf("read the console for a wrong sentence: %q", got[n:]) |
| - } |
| -} |
| - |
| -func TestWitnessRefusesWithoutAfterSnapshot(t *testing.T) { |
| - x := newCarlosFixture(t, "docs") |
| - s := newJournal(t) |
| - base, err := Observe(context.Background(), x.c, x.h, x.app) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - if err := s.SaveBaseline(context.Background(), "docs", base); err != nil { |
| - t.Fatal(err) |
| - } |
| - x.site.ops = agent401 |
| - err = RecordWitness(context.Background(), s, x.c, x.h, x.app, WitnessSentence(x.app), true) |
| - if err == nil || err.Error() != "adopt: witness-after-missing" { |
| - t.Fatalf("err = %v", err) |
| - } |
| - if _, ok, _ := s.Witness(context.Background(), "docs"); ok { |
| - t.Fatal("recorded a witness without an after snapshot") |
| - } |
| -} |
| - |
| -func TestWitnessRefusesWithoutAgentShape(t *testing.T) { |
| - cases := map[string]func(w *witnessFixture){ |
| - "absent": func(w *witnessFixture) { w.site.ops = nil }, |
| - "app-401": func(w *witnessFixture) { |
| - w.site.ops = func(rw http.ResponseWriter) { |
| - rw.WriteHeader(401) |
| - _, _ = rw.Write([]byte(`{"error":"unauthorized"}`)) |
| - } |
| - }, |
| - "unhealthy": func(w *witnessFixture) { |
| - w.site.health = 503 |
| - }, |
| - "version moved": func(w *witnessFixture) { |
| - w.site.version, w.site.header = "v1.5.0", "v1.5.0" |
| - }, |
| - "redirect": func(w *witnessFixture) { w.site.redirectVersion = true }, |
| - } |
| - for name, change := range cases { |
| - t.Run(name, func(t *testing.T) { |
| - w := newWitnessFixture(t, "docs") |
| - change(w) |
| - if err := w.record(WitnessSentence(w.app), true); err == nil { |
| - t.Fatal("recorded a witness the running app does not bear out") |
| - } |
| - w.noWitness(t) |
| - }) |
| - } |
| -} |
| - |
| -func TestWitnessRefusesIdentityChangedSinceAfter(t *testing.T) { |
| - cases := map[string]func(in *carlosop.Instance){ |
| - "record": func(in *carlosop.Instance) { in.RecordSeq++ }, |
| - "storage": func(in *carlosop.Instance) { in.Slug = "s-docs-recreated" }, |
| - "region": func(in *carlosop.Instance) { in.Region = "us" }, |
| - } |
| - for name, change := range cases { |
| - t.Run(name, func(t *testing.T) { |
| - w := newWitnessFixture(t, "docs") |
| - in := carlosop.Instance{ |
| - Host: CanonicalHost(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), |
| - } |
| - change(&in) |
| - w.f.AddInstance(in) |
| - err := w.record(WitnessSentence(w.app), true) |
| - if err == nil || err.Error() != "adopt: witness-identity-"+name { |
| - t.Fatalf("err = %v, want witness-identity-%s", err, name) |
| - } |
| - w.noWitness(t) |
| - }) |
| - } |
| -} |
| - |
| -func TestWitnessDryRunRecordsNothing(t *testing.T) { |
| - w := newWitnessFixture(t, "docs") |
| - // A dry run asks for no sentence, so none is checked. |
| - if err := w.record("", false); err != nil { |
| - t.Fatalf("dry run: %v", err) |
| - } |
| - w.noWitness(t) |
| - // It still observes, and refuses what apply would refuse. |
| - w.site.ops = nil |
| - if err := w.record("", false); err == nil { |
| - t.Fatal("dry run passed an app the witness would refuse") |
| - } |
| - w.noWitness(t) |
| -} |
| - |
| -// The witness is bound to the after snapshot's config: any change since, |
| -// in any key's digest, kind or source, or any layer's version, refuses. |
| -func TestWitnessRefusesConfigChangedSinceAfter(t *testing.T) { |
| - cases := map[string]struct { |
| - change func(w *witnessFixture) |
| - codes []string |
| - }{ |
| - "unrelated key added": {func(w *witnessFixture) { |
| - w.f.SetVar("docs", "", "DOCS_EXTRA", "x") |
| - }, []string{"added:DOCS_EXTRA", "layer:default"}}, |
| - "secret resealed": {func(w *witnessFixture) { |
| - w.f.SetSecret("docs", "", "DOCS_INSTANCE_KEY") |
| - }, []string{"changed:DOCS_INSTANCE_KEY", "layer:default"}}, |
| - "agent key rewritten": {func(w *witnessFixture) { |
| - w.f.SetVar("docs", "", "DOCS_AGENT_TEAM", "tm_other") |
| - }, []string{"changed:DOCS_AGENT_TEAM", "layer:default"}}, |
| - "key unset": {func(w *witnessFixture) { |
| - w.f.Unset("docs", "", "DOCS_ORIGIN") |
| - }, []string{"gone:DOCS_ORIGIN", "layer:default"}}, |
| - "overlay moved": {func(w *witnessFixture) { |
| - w.f.SetOverlay("docs", "docs.oficina.works", "DOCS_ORIGIN", "https://elsewhere.example") |
| - }, []string{"from:DOCS_ORIGIN", "layer:overlay"}}, |
| - } |
| - for name, tc := range cases { |
| - t.Run(name, func(t *testing.T) { |
| - w := newWitnessFixture(t, "docs") |
| - tc.change(w) |
| - err := w.record(WitnessSentence(w.app), true) |
| - if err == nil || !strings.HasPrefix(err.Error(), "adopt: witness-config-") { |
| - t.Fatalf("err = %v, want witness-config-<code>", err) |
| - } |
| - for _, code := range tc.codes { |
| - if !strings.Contains(err.Error(), "witness-config-"+code) { |
| - t.Fatalf("err = %v, want it to name %s", err, code) |
| - } |
| - } |
| - for _, leak := range []string{"vd1:", "cv1:", "tm_other", "elsewhere"} { |
| - if strings.Contains(err.Error(), leak) { |
| - t.Fatalf("err = %v carries a value", err) |
| - } |
| - } |
| - w.noWitness(t) |
| - // A dry run refuses it too. |
| - if err := w.record("", false); err == nil { |
| - t.Fatal("dry run passed a changed config") |
| - } |
| - }) |
| - } |
| -} |
| - |
| -func TestSameConfigComparesEveryPart(t *testing.T) { |
| - a := afterSnap() |
| - if codes := sameConfig(a, afterSnap()); len(codes) > 0 { |
| - t.Fatalf("identical snapshots differ: %v", codes) |
| - } |
| - cases := map[string]struct { |
| - change func(s *Snapshot) |
| - want string |
| - }{ |
| - "effective digest": {func(s *Snapshot) { s.Vars[0].Digest = "vd1:other" }, "changed:" + a.Vars[0].Key}, |
| - "effective kind": {func(s *Snapshot) { s.Vars[0].Kind = "secret" }, "kind:" + a.Vars[0].Key}, |
| - "effective from": {func(s *Snapshot) { s.Vars[0].From = "environment" }, "from:" + a.Vars[0].Key}, |
| - "effective gone": {func(s *Snapshot) { s.Vars = s.Vars[1:] }, "gone:" + a.Vars[0].Key}, |
| - "stored digest": {func(s *Snapshot) { s.Layer.Vars[0].Digest = "vd1:other" }, "changed:" + a.Layer.Vars[0].Key}, |
| - "stored added": {func(s *Snapshot) { |
| - s.Layer.Vars = append(s.Layer.Vars, carlosop.Var{Key: "DOCS_NEW", Kind: "env", Digest: "vd1:x"}) |
| - }, "added:DOCS_NEW"}, |
| - "write layer version": {func(s *Snapshot) { s.Layer.Version = "cv1:other" }, "layer:default"}, |
| - "write layer": {func(s *Snapshot) { s.WriteLayer = "staging" }, "write-layer"}, |
| - "other layer": {func(s *Snapshot) { s.Layers["environment"] = "cv1:other" }, "layer:environment"}, |
| - "layer gone": {func(s *Snapshot) { delete(s.Layers, "overlay") }, "layer:overlay"}, |
| - } |
| - for name, tc := range cases { |
| - t.Run(name, func(t *testing.T) { |
| - b := afterSnap() |
| - tc.change(&b) |
| - codes := sameConfig(a, b) |
| - found := false |
| - for _, c := range codes { |
| - found = found || c == tc.want |
| - } |
| - if !found { |
| - t.Fatalf("codes = %q, want %q among them", codes, tc.want) |
| - } |
| - }) |
| - } |
| -} |
diff --git a/adopt/words.go b/adopt/words.go| index e08efd3..01647ad 100644 |
| --- a/adopt/words.go |
| +++ b/adopt/words.go |
| @@ -4,73 +4,30 @@ |
| // |
| // Approved by Paul, 2026-11-16, verbatim: copy review |
| // 2y3evbm7avhwx5sy6ubygyewae (every string in this file) and the README |
| -// runbook in copy review si53b27d3tasj7si7ubqovkqw4. |
| +// runbook in copy review si53b27d3tasj7si7ubqovkqw4. A string marked |
| +// PENDING COPY REVIEW was changed for Paul's ruling of 2026-11-17 (Home |
| +// discussion 103: the delivery check replaces the witness, and the live |
| +// checks are dropped) and is not approved yet. |
| package adopt |
| import ( |
| "fmt" |
| "strings" |
| - |
| - "amadan.net/oficina/alta/provision" |
| ) |
| -// WitnessSentence is what Paul types to witness app after its restart, |
| -// once he has signed in at its canonical host in his own browser. It |
| -// names the host, so a sentence typed for one app never records another. |
| -func WitnessSentence(app provision.App) string { |
| - return "I signed in to " + CanonicalHost(app) + " and it works as before" |
| -} |
| - |
| // WriteSummary is configure's dry-run description of the write: the two |
| // keys and the bundle they are written to, never their values. |
| func WriteSummary(keys [2]string, bundle string) string { |
| return "set " + keys[0] + ", " + keys[1] + " on " + bundle |
| } |
| -// The live checks' sentences. Paul types each one, exactly, once he has |
| -// done what it says. None names a team, an address or an event. |
| -const ( |
| - LiveAddedMember = "I added the test account to the Oficina team" |
| - LiveRemovedMember = "I removed the test account from the Oficina team" |
| - LiveLocalAccessKept = "The test account still signs in to calendar.oficina.works and sees its own events" |
| - LiveOwnerLocalAccessKept = "I still sign in to calendar.oficina.works and see my own events" |
| -) |
| - |
| -// What the live checks say before each sign-in to connect, so Paul knows |
| -// which account the browser should be signed in as. |
| -const ( |
| - LiveSayTestSignIn = "Sign in to connect as the test account." |
| - LiveSayTestTeam = "Sign in to connect as the test account again, and tick the Oficina team." |
| - LiveSayOwnerSignIn = "Sign in to connect as yourself, and tick the Oficina team." |
| -) |
| - |
| -// LiveSteps is what the live checks print without --apply: every step, |
| -// in order, and nothing contacted. |
| -var LiveSteps = []string{ |
| - "1. The test account signs in to connect; a call to the team is refused (non-member-refused).", |
| - "2. You add the test account to the team; it signs in again and ticks the team.", |
| - "3. Its free/busy call to the team succeeds (member-allowed).", |
| - "4. It cannot read your chosen event (member-no-local-permission-refused).", |
| - "5. You remove it from the team; the same call, repeated, is refused (revoked-membership-refused).", |
| - "6. You confirm the test account still uses calendar directly (local-access-kept).", |
| - "7. You connect, call and disconnect; your call, repeated, is refused (owner-allowed, owner-revoked-refused).", |
| - "8. You confirm you still use calendar directly (owner-local-access-kept).", |
| - "Every connection made is disconnected at the end.", |
| -} |
| - |
| -// What RunLive says when it refuses to start, after "adopt: ". |
| -const ( |
| - LiveNeedOrigin = "the live checks need connect's https origin" |
| - LiveNeedIssuer = "the live checks run only against the connect the apps trust" |
| - LiveNeedTeam = "the live checks need the team" |
| - LiveNeedEvent = "the foreign event is not an event id" |
| - LiveNeedRunners = "the live checks need the journal, a prompter and a browser" |
| -) |
| - |
| // ---- the alta-adopt command ---- |
| // Usage is alta-adopt's help: what it prints with no command, with help, |
| // or with a command it does not know. |
| +// |
| +// PENDING COPY REVIEW: the witness and live lines are gone, and the |
| +// --carlos-token-fd line no longer names witness. |
| const Usage = `alta-adopt adopts the six Oficina apps into the Oficina team at Home. |
| Usage: |
| @@ -89,9 +46,7 @@ Commands, in the order of a run: |
| advance --run <id> take a run as far as it can go now |
| configure --app <app> write the app's two agent keys, restart it and |
| check it |
| - witness --app <app> record that you checked the app yourself |
| activate --apps <list> open Plan B (calendar) or Plan C (the other five) |
| - live --event <id> run the live checks against connect |
| rollback-config --app <app> |
| remove the app's two agent keys and restart it |
| disable --app <app> disable the app's team binding at Home |
| @@ -101,9 +56,9 @@ Commands, in the order of a run: |
| Flags: |
| --config <file> the configuration file: mode 0600, owned by you |
| --carlos-token-fd <n> read the CARLOS Admin token from file |
| - descriptor n (3 or above); configure, witness, |
| - activate, rollback-config, preflight and the |
| - advance of Plans B and C need it |
| + descriptor n (3 or above); configure, activate, |
| + rollback-config, preflight and the advance of |
| + Plans B and C need it |
| --apply do it |
| ` |
| @@ -124,13 +79,6 @@ const ( |
| SayAdvanceWould = "With --apply this takes the run as far as it can go now." |
| - SayWitnessObserved = "The app is serving as configured." |
| - SayWitnessWould = "With --apply you will be asked to type this sentence:" |
| - SayWitnessRecorded = "Witness recorded." |
| - |
| - SayLiveOpen = "Open this address in your browser:" |
| - SayLiveType = "Type this sentence, exactly, once it is true:" |
| - |
| SayDisableAsk = "With --apply you will be asked to type the team's label." |
| ) |
| @@ -166,18 +114,15 @@ func SayConfirm(id int64, roles []string) string { |
| } |
| // SayConfigureWould is configure's dry run after the write's summary. |
| +// PENDING COPY REVIEW. |
| func SayConfigureWould(host string) string { |
| - return "Then it restarts " + host + " alone and waits for it to serve the new configuration." |
| -} |
| - |
| -// SayConfigured is a finished configure. |
| -func SayConfigured(host, app string) string { |
| - return host + " restarted on the new configuration, and nothing else changed. Sign in to it yourself, then run:\n alta-adopt witness --app " + app + " --apply" |
| + return "Then it restarts " + host + " alone, waits for it to serve the new configuration, and checks that it still serves the reviewed release." |
| } |
| -// SayWitnessAsk is the witness prompt. |
| -func SayWitnessAsk(host string) string { |
| - return "Sign in to https://" + host + " in your own browser and check it works as before. Then type this sentence:" |
| +// SayConfigured is a finished configure, its delivery check recorded. |
| +// PENDING COPY REVIEW. |
| +func SayConfigured(host string) string { |
| + return host + " restarted on the new configuration, and nothing else changed. It still serves the reviewed release and now answers agent requests. Delivery check recorded." |
| } |
| // SayActivateApp is one app's readiness for activation. |
| @@ -250,13 +195,9 @@ func SayStatusApp(app string, parts []string) string { |
| // SayStatusNothing is an app with no step and no journal yet. |
| const SayStatusNothing = "not started" |
| -// SayStatusLive is the live-check gate's state. |
| -func SayStatusLive(open bool) string { |
| - if open { |
| - return "Live checks: passed" |
| - } |
| - return "Live checks: not passed" |
| -} |
| +// SayStatusDeliveryCheck is an app's journal part once its delivery check |
| +// is recorded. PENDING COPY REVIEW. |
| +const SayStatusDeliveryCheck = "delivery-check" |
| // The command's refusals before it reaches anything: its flags, its |
| // config file and the token's descriptor. They name fields and flags, |
| @@ -291,5 +232,4 @@ const ( |
| HintPrePlanA = "Run alta-adopt home-preflight --phase pre-plan-a --apply first." |
| HintToken = "This command reads CARLOS: pass the Admin token with --carlos-token-fd." |
| HintCanary = "Activate calendar first: alta-adopt activate --apps calendar --apply." |
| - HintLive = "Run the live checks first: alta-adopt live --event <id> --apply." |
| ) |
diff --git a/cmd/alta-adopt/main.go b/cmd/alta-adopt/main.go| index e8daeb4..f86308f 100644 |
| --- a/cmd/alta-adopt/main.go |
| +++ b/cmd/alta-adopt/main.go |
| @@ -7,7 +7,7 @@ |
| // stream and journal; CARLOS's half is package adopt, over an Admin |
| // credential that lives in this process's memory only. Without --apply, |
| // every command shows what it would do and writes nothing anywhere: not |
| -// Home, not CARLOS, not connect, not the adoption journal. |
| +// Home, not CARLOS, not the adoption journal. |
| package main |
| import ( |
| @@ -73,8 +73,6 @@ type opts struct { |
| app string |
| apps string |
| run int64 |
| - event string |
| - connect string |
| } |
| var commands = map[string]command{ |
| @@ -90,14 +88,9 @@ var commands = map[string]command{ |
| fs.Int64Var(&o.run, "run", 0, "") |
| }, do: (*runner).advance}, |
| "configure": {writes: true, flags: appFlag, do: (*runner).configure}, |
| - "witness": {writes: true, flags: appFlag, do: (*runner).witness}, |
| "activate": {writes: true, flags: func(fs *flag.FlagSet, o *opts) { |
| fs.StringVar(&o.apps, "apps", "", "") |
| }, do: (*runner).activate}, |
| - "live": {writes: true, flags: func(fs *flag.FlagSet, o *opts) { |
| - fs.StringVar(&o.event, "event", "", "") |
| - fs.StringVar(&o.connect, "connect", adopt.Issuer, "") |
| - }, do: (*runner).live}, |
| "rollback-config": {writes: true, flags: appFlag, do: (*runner).rollback}, |
| "disable": {writes: true, flags: appFlag, do: (*runner).disable}, |
| "status": {do: (*runner).status}, |
| @@ -170,9 +163,6 @@ func hintFor(err error) string { |
| if errors.As(err, &r) { |
| return r.hint |
| } |
| - if errors.Is(err, adopt.ErrLiveChecksMissing) { |
| - return adopt.HintLive |
| - } |
| return "" |
| } |
| @@ -639,9 +629,12 @@ func (r *runner) advance(ctx context.Context) error { |
| } |
| // configure writes app's two agent keys, restarts its canonical host |
| -// until it serves them, and captures the after snapshot (Task 9's order). |
| -// A resume continues from the journal; an app already captured is not |
| -// restarted again. |
| +// until it serves them, captures the after snapshot (Task 9's order) and |
| +// records the delivery check (Paul, 2026-11-17: the runner's check in |
| +// place of his witnessed sign-in). A resume continues from the journal: |
| +// an app already captured is not restarted again, and its delivery check |
| +// is made again, so a lost or voided check is redone by running |
| +// configure again. |
| func (r *runner) configure(ctx context.Context) error { |
| a, err := r.app() |
| if err != nil { |
| @@ -692,7 +685,10 @@ func (r *runner) configure(ctx context.Context) error { |
| return err |
| } |
| } |
| - r.say(adopt.SayConfigured(host, a.Slug)) |
| + if err := adopt.CheckDelivery(ctx, r.js, c, r.public, a, r.cfg.artifacts[a.Slug]); err != nil { |
| + return err |
| + } |
| + r.say(adopt.SayConfigured(host)) |
| return nil |
| } |
| @@ -706,43 +702,10 @@ func (r *runner) identity(ctx context.Context, c *carlosop.Client, a provision.A |
| return snap.Identity, err |
| } |
| -// witness records Paul's witnessed check. It observes first, so he is |
| -// asked to sign in only to an app that is serving as configured; without |
| -// --apply it asks for nothing. |
| -func (r *runner) witness(ctx context.Context) error { |
| - a, err := r.app() |
| - if err != nil { |
| - return err |
| - } |
| - c, err := r.needCarlos() |
| - if err != nil { |
| - return err |
| - } |
| - if err := adopt.RecordWitness(ctx, r.js, c, r.public, a, "", false); err != nil { |
| - return err |
| - } |
| - r.say(adopt.SayWitnessObserved) |
| - sentence := adopt.WitnessSentence(a) |
| - if !r.o.apply { |
| - r.say(adopt.SayWitnessWould, sentence, adopt.SayDryRun) |
| - return nil |
| - } |
| - r.say(adopt.SayWitnessAsk(adopt.CanonicalHost(a)), sentence) |
| - typed, err := r.ask("> ") |
| - if err != nil { |
| - return err |
| - } |
| - if err := adopt.RecordWitness(ctx, r.js, c, r.public, a, typed, true); err != nil { |
| - return err |
| - } |
| - r.say(adopt.SayWitnessRecorded) |
| - return nil |
| -} |
| - |
| -// activate opens Plan B or C. Every app but the canary must pass the |
| -// live-check gate (Store.LiveGate, the Observer's own rule), and every |
| -// app must pass the Observer now, before a window is asked for; the |
| -// engine observes again, at activation. |
| +// activate opens Plan B or C. Every app but the canary must pass Plan |
| +// C's gate, the canary activated by Plan B (Store.CanaryGate, the |
| +// Observer's own rule), and every app must pass the Observer now, before |
| +// a window is asked for; the engine observes again, at activation. |
| func (r *runner) activate(ctx context.Context) error { |
| var apps []string |
| for _, a := range strings.Split(r.o.apps, ",") { |
| @@ -755,8 +718,10 @@ func (r *runner) activate(ctx context.Context) error { |
| return refuse("unknown-app", "") |
| } |
| for _, a := range sorted { |
| - if err := r.js.LiveGate(ctx, a); err != nil { |
| - return refuse(adopt.ErrLiveChecksMissing.Error(), adopt.HintLive) |
| + if err := r.js.CanaryGate(ctx, a); errors.Is(err, adopt.ErrCanaryNotActive) { |
| + return refuse(err.Error(), adopt.HintCanary) |
| + } else if err != nil { |
| + return err |
| } |
| } |
| obs, err := r.observer() |
| @@ -795,49 +760,6 @@ func (r *runner) activate(ctx context.Context) error { |
| return nil |
| } |
| -// prompter asks Paul, on the terminal, to type a live check's sentence. |
| -type prompter struct{ r *runner } |
| - |
| -func (p prompter) Ask(_ context.Context, sentence string) error { |
| - p.r.say(adopt.SayLiveType, sentence) |
| - typed, err := p.r.ask("> ") |
| - if err != nil { |
| - return err |
| - } |
| - if strings.TrimSpace(typed) != sentence { |
| - return refuse("sentence-mismatch", "") |
| - } |
| - return nil |
| -} |
| - |
| -// live runs the live checks against connect, once the canary is active: |
| -// a check run against an app Home has not activated would fail, and a |
| -// failure keeps Plan C refused for good. |
| -func (r *runner) live(ctx context.Context) error { |
| - sqid, err := r.team(ctx) |
| - if err != nil { |
| - return err |
| - } |
| - if _, ok, err := r.ps.Done(ctx, provision.AdoptionLabel, adopt.CanaryApp, provision.StepActivate); err != nil { |
| - return err |
| - } else if !ok { |
| - return refuse("canary-not-active", adopt.HintCanary) |
| - } |
| - open := func(u string) error { |
| - r.say(adopt.SayLiveOpen, u) |
| - return nil |
| - } |
| - if err := adopt.RunLive(ctx, r.e.stdout, r.o.connect, sqid, prompter{r}, r.js, open, r.o.event, r.o.apply); err != nil { |
| - return err |
| - } |
| - if !r.o.apply { |
| - r.say(adopt.SayDryRun) |
| - return nil |
| - } |
| - r.say(adopt.SayDone) |
| - return nil |
| -} |
| - |
| // rollback removes the two agent keys configure wrote and restarts the |
| // app on its baseline. |
| func (r *runner) rollback(ctx context.Context) error { |
| @@ -931,7 +853,7 @@ func (r *runner) disable(ctx context.Context) error { |
| } |
| // status shows where the adoption is: Home's preflights, the team, the |
| -// runs, each app's Home steps and journal, and the live-check gate. |
| +// runs, and each app's Home steps and journal. |
| func (r *runner) status(ctx context.Context) error { |
| for _, phase := range []string{adopt.PhasePreInitialize, adopt.PhasePrePlanA} { |
| _, ok, err := r.js.HomePreflight(ctx, phase) |
| @@ -979,7 +901,6 @@ func (r *runner) status(ctx context.Context) error { |
| } |
| r.say(adopt.SayStatusApp(a, parts)) |
| } |
| - r.say(adopt.SayStatusLive(r.js.LiveGate(ctx, "docs") == nil)) |
| return nil |
| } |
| @@ -1001,10 +922,10 @@ func (r *runner) journal(ctx context.Context, app string) ([]string, error) { |
| } else if ok { |
| out = append(out, "after") |
| } |
| - if _, ok, err := r.js.Witness(ctx, app); err != nil { |
| + if _, ok, err := r.js.DeliveryCheck(ctx, app); err != nil { |
| return nil, err |
| } else if ok { |
| - out = append(out, "witness") |
| + out = append(out, adopt.SayStatusDeliveryCheck) |
| } |
| if rb, ok, err := r.js.Rollback(ctx, app); err != nil { |
| return nil, err |
diff --git a/cmd/alta-adopt/main_test.go b/cmd/alta-adopt/main_test.go| index 30715ff..73ce23c 100644 |
| --- a/cmd/alta-adopt/main_test.go |
| +++ b/cmd/alta-adopt/main_test.go |
| @@ -43,20 +43,18 @@ const ( |
| ) |
| // rig is everything alta-adopt reaches, faked: Home's two roles, the |
| -// CARLOS console, the six apps' origins and connect. |
| +// CARLOS console and the six apps' origins. |
| type rig struct { |
| t *testing.T |
| mu sync.Mutex |
| now time.Time |
| - home *fakehome.Home |
| - plans atomic.Int64 // POST /operator/v1/plan on either role |
| - homeURL map[string]string |
| - carlos *fakecarlos.Fake |
| - public *http.Client |
| - connect *httptest.Server |
| - connectHit atomic.Int64 |
| + home *fakehome.Home |
| + plans atomic.Int64 // POST /operator/v1/plan on either role |
| + homeURL map[string]string |
| + carlos *fakecarlos.Fake |
| + public *http.Client |
| siteMu sync.Mutex |
| seen map[string]int |
| @@ -64,7 +62,8 @@ type rig struct { |
| dir, cfgPath, state string |
| dek, opKey, pre string |
| - tokens [][]byte // every token buffer the command read |
| + cfg map[string]any // what writeConfig writes |
| + tokens [][]byte // every token buffer the command read |
| out bytes.Buffer |
| } |
| @@ -122,12 +121,6 @@ func newRig(t *testing.T) *rig { |
| tr.TLSClientConfig.ServerName = "example.com" |
| r.public = &http.Client{Transport: tr, Timeout: 10 * time.Second} |
| - r.connect = httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| - r.connectHit.Add(1) |
| - w.WriteHeader(http.StatusTeapot) |
| - })) |
| - t.Cleanup(r.connect.Close) |
| - |
| raw, err := family.MarshalKeypair(key) |
| if err != nil { |
| t.Fatal(err) |
| @@ -146,7 +139,7 @@ func newRig(t *testing.T) *rig { |
| for _, a := range provision.Slugs() { |
| artifacts[a] = hex.EncodeToString(sum[:]) |
| } |
| - cfg := map[string]any{ |
| + r.cfg = map[string]any{ |
| "alta_dek": r.dek, |
| "operator_key": r.opKey, |
| "operator_prefilter": r.pre, |
| @@ -159,14 +152,20 @@ func newRig(t *testing.T) *rig { |
| "state": "adopt.db", |
| "artifacts": artifacts, |
| } |
| - b, err := json.Marshal(cfg) |
| + r.writeConfig() |
| + return r |
| +} |
| + |
| +// writeConfig writes r.cfg as the config file, mode 0600. |
| +func (r *rig) writeConfig() { |
| + r.t.Helper() |
| + b, err := json.Marshal(r.cfg) |
| if err != nil { |
| - t.Fatal(err) |
| + r.t.Fatal(err) |
| } |
| if err := os.WriteFile(r.cfgPath, b, 0o600); err != nil { |
| - t.Fatal(err) |
| + r.t.Fatal(err) |
| } |
| - return r |
| } |
| func (r *rig) clock() time.Time { |
| @@ -285,16 +284,16 @@ func (r *rig) refused(code string, stdin string, token bool, args ...string) str |
| } |
| // writes is everything a dry run must leave alone: Home's plans and |
| -// committed operations, the console's writes and restarts, connect, and |
| -// every row in the state database. |
| +// committed operations, the console's writes and restarts, and every row |
| +// in the state database. |
| type writes struct { |
| - plans, ops, puts, restarts, appWide, connect, rows int64 |
| - exists bool |
| + plans, ops, puts, restarts, appWide, rows int64 |
| + exists bool |
| } |
| func (r *rig) writes() writes { |
| r.t.Helper() |
| - w := writes{plans: r.plans.Load(), ops: int64(len(r.home.Requests())), appWide: int64(r.carlos.AppWideRestarts()), connect: r.connectHit.Load()} |
| + w := writes{plans: r.plans.Load(), ops: int64(len(r.home.Requests())), appWide: int64(r.carlos.AppWideRestarts())} |
| for _, q := range r.carlos.Requests() { |
| if strings.HasPrefix(q, "PUT ") { |
| w.puts++ |
| @@ -456,12 +455,29 @@ func (r *rig) throughPlanA() { |
| r.tick(homeop.WindowLifetime * time.Second) |
| } |
| -// configured writes app's keys and records Paul's witness. |
| +// configured writes app's keys, restarts it and records its delivery |
| +// check: configure alone, with nothing typed. |
| func (r *rig) configured(app string) { |
| r.t.Helper() |
| a, _ := provision.AppBySlug(app) |
| - r.ok("", true, "configure", "--app", app, "--apply") |
| - r.ok(adopt.WitnessSentence(a)+"\n", true, "witness", "--app", app, "--apply") |
| + if out := r.ok("", true, "configure", "--app", app, "--apply"); !strings.Contains(out, adopt.SayConfigured(adopt.CanonicalHost(a))) { |
| + r.t.Fatalf("configure did not finish\n%s", out) |
| + } |
| + if !r.checked(app) { |
| + r.t.Fatalf("configure recorded no delivery check for %s", app) |
| + } |
| +} |
| + |
| +// checked reports whether status shows app's delivery check. |
| +func (r *rig) checked(app string) bool { |
| + r.t.Helper() |
| + for _, line := range strings.Split(r.ok("", false, "status"), "\n") { |
| + if strings.HasPrefix(line, app+": ") { |
| + return strings.Contains(line, ", "+adopt.SayStatusDeliveryCheck) |
| + } |
| + } |
| + r.t.Fatalf("status has no line for %s", app) |
| + return false |
| } |
| // rehearse walks every subcommand of the table in order. Each runs first |
| @@ -502,8 +518,9 @@ func rehearse(t *testing.T) *rig { |
| r.dry("", true, "configure", "--app", adopt.CanaryApp) |
| r.applied("", true, "configure", "--app", adopt.CanaryApp) |
| - r.dry("", true, "witness", "--app", adopt.CanaryApp) |
| - r.applied(adopt.WitnessSentence(cal)+"\n", true, "witness", "--app", adopt.CanaryApp) |
| + if !r.checked(adopt.CanaryApp) { |
| + t.Fatal("configure recorded no delivery check") |
| + } |
| r.dry("", true, "activate", "--apps", adopt.CanaryApp) |
| r.applied("", true, "activate", "--apps", adopt.CanaryApp) |
| @@ -514,21 +531,6 @@ func rehearse(t *testing.T) *rig { |
| r.runState("done") |
| r.tick(homeop.WindowLifetime * time.Second) |
| - // The live checks' steps come through the command's own writer. |
| - if out := r.dry("", false, "live", "--event", "7"); !strings.Contains(out, strings.Join(adopt.LiveSteps, "\n")) { |
| - t.Fatalf("live without --apply did not list its steps\n%s", out) |
| - } |
| - // They run against production connect only, the issuer the apps |
| - // trust: another deployment is refused, applied or not, and never |
| - // contacted. |
| - for _, apply := range [][]string{nil, {"--apply"}} { |
| - before := r.writes() |
| - r.refused(adopt.LiveNeedIssuer, "", false, append([]string{"live", "--event", "7", "--connect", r.connect.URL}, apply...)...) |
| - if after := r.writes(); after != before { |
| - t.Fatalf("a refused live wrote or contacted connect: %+v %+v", before, after) |
| - } |
| - } |
| - |
| // The rollback's dry run names the keys it would remove, the bundle |
| // and the host it would restart. |
| keys, host := adopt.AgentKeys(cal), adopt.CanonicalHost(cal) |
| @@ -559,9 +561,6 @@ func TestWritesNeedApply(t *testing.T) { |
| t.Fatalf("%s restarted", a.Slug) |
| } |
| } |
| - if r.connectHit.Load() != 0 { |
| - t.Fatal("connect was called") |
| - } |
| } |
| // fileState is a file's bytes and mtime, or its absence. |
| @@ -674,14 +673,17 @@ func TestDryRunLeavesStateUntouched(t *testing.T) { |
| // Committed transactions still in the WAL, with another process |
| // holding the state open, are read too, and the WAL is untouched. |
| - r.saveChecks(func() { |
| + r.holdOpen(func(js *adopt.Store) { |
| + if err := js.SaveHomePreflight(context.Background(), adopt.HomePreflight{Phase: adopt.PhasePrePlanA}); err != nil { |
| + t.Fatal(err) |
| + } |
| before := r.files() |
| if !before["-wal"].exists { |
| t.Fatal("setup: no WAL") |
| } |
| out := r.readOnly() |
| r.untouched(before) |
| - if !strings.Contains(out, adopt.SayStatusLive(true)) { |
| + if !strings.Contains(out, adopt.SayStatusPreflight(adopt.PhasePrePlanA, true)) { |
| t.Fatalf("status did not read the WAL\n%s", out) |
| } |
| }) |
| @@ -719,9 +721,9 @@ func TestPlanARefusedWithoutHomePreflight(t *testing.T) { |
| r.applied(owner+"\n", false, "plan-a") |
| } |
| -// saveChecks records every live check as passed, as a run of live would, |
| -// then runs each of during while it still holds the state open. |
| -func (r *rig) saveChecks(during ...func()) { |
| +// holdOpen opens the state as another process would and runs during |
| +// while it holds it open. |
| +func (r *rig) holdOpen(during func(js *adopt.Store)) { |
| r.t.Helper() |
| db, err := provision.OpenDB(r.state) |
| if err != nil { |
| @@ -737,49 +739,115 @@ func (r *rig) saveChecks(during ...func()) { |
| if err != nil { |
| r.t.Fatal(err) |
| } |
| - for _, c := range adopt.RequiredLiveChecks { |
| - if err := js.SaveCheck(context.Background(), adopt.Issuer, c, "passed"); err != nil { |
| - r.t.Fatal(err) |
| + during(js) |
| +} |
| + |
| +// Plan C waits on Plan B alone (Paul, 2026-11-17): activate refuses every |
| +// app but the canary, before reading CARLOS, until calendar is active, |
| +// and says what comes first; then the same command opens Plan C with no |
| +// live check. |
| +func TestActivateNonCanaryRefusedBeforePlanB(t *testing.T) { |
| + t.Parallel() |
| + r := newRig(t) |
| + r.throughPlanA() |
| + r.configured("docs") |
| + r.configured(adopt.CanaryApp) |
| + refusedNow := func(why string) { |
| + t.Helper() |
| + before, reads := r.writes(), len(r.carlos.Requests()) |
| + for _, args := range [][]string{{"--apps", "docs", "--apply"}, {"--apps", "docs"}, {"--apps", "calendar,docs", "--apply"}} { |
| + out := r.refused("refused: canary-not-active", "", true, append([]string{"activate"}, args...)...) |
| + if !strings.Contains(out, adopt.HintCanary) { |
| + t.Fatalf("%s: activate %v: no hint\n%s", why, args, out) |
| + } |
| + } |
| + if after := r.writes(); after != before { |
| + t.Fatalf("%s: a refused activate wrote: %+v %+v", why, before, after) |
| + } |
| + if n := len(r.carlos.Requests()); n != reads { |
| + t.Fatalf("%s: a refused activate read CARLOS %d times", why, n-reads) |
| } |
| } |
| - for _, f := range during { |
| - f() |
| + refusedNow("before Plan B") |
| + |
| + // Plan B opened but not yet through: still refused. |
| + r.applied("", true, "activate", "--apps", adopt.CanaryApp) |
| + refusedNow("Plan B open") |
| + r.confirm(homeop.KindAddApps) |
| + r.ok("", true, "advance", "--run", r.latestRun(), "--apply") |
| + r.runState("done") |
| + r.tick(homeop.WindowLifetime * time.Second) |
| + |
| + r.applied("", true, "activate", "--apps", "docs") |
| + r.confirm(homeop.KindAddApps) |
| + r.ok("", true, "advance", "--run", r.latestRun(), "--apply") |
| + r.runState("done") |
| + if st := r.home.InstanceState("docs"); st != "live" { |
| + t.Fatalf("docs is %q at Home", st) |
| } |
| } |
| -func TestActivateNonCanaryRefusedWithoutLive(t *testing.T) { |
| +// A process that died after the after snapshot and before its delivery |
| +// check is resumed by configure alone: no second write or restart, and |
| +// the check recorded. |
| +func TestConfigureResumesDeliveryCheck(t *testing.T) { |
| t.Parallel() |
| r := newRig(t) |
| r.throughPlanA() |
| r.configured("docs") |
| - before, reads := r.writes(), len(r.carlos.Requests()) |
| - // Store.LiveGate refuses first, and says what comes first. |
| - for _, args := range [][]string{{"--apps", "docs", "--apply"}, {"--apps", "docs"}, {"--apps", "calendar,docs", "--apply"}} { |
| - out := r.refused("refused: live-checks-missing", "", true, append([]string{"activate"}, args...)...) |
| - if !strings.Contains(out, adopt.HintLive) { |
| - t.Fatalf("activate %v: no hint\n%s", args, out) |
| - } |
| + // The check lost, as if the process had died before saving it. |
| + db, err := sql.Open("sqlite", "file:"+r.state+"?_pragma=busy_timeout(5000)") |
| + if err != nil { |
| + t.Fatal(err) |
| } |
| - if after := r.writes(); after != before { |
| - t.Fatalf("a refused activate wrote: %+v %+v", before, after) |
| + if _, err := db.Exec("DELETE FROM adopt_witnesses WHERE app='docs'"); err != nil { |
| + t.Fatal(err) |
| } |
| - // The gate is the journal's: it refuses before CARLOS is read. |
| - if n := len(r.carlos.Requests()); n != reads { |
| - t.Fatalf("a refused activate read CARLOS %d times", n-reads) |
| + db.Close() |
| + if r.checked("docs") { |
| + t.Fatal("setup: the check is still there") |
| + } |
| + docs, _ := provision.AppBySlug("docs") |
| + puts, restarts := r.writes().puts, r.carlos.RestartCount(adopt.CanonicalHost(docs)) |
| + r.configured("docs") |
| + if r.writes().puts != puts || r.carlos.RestartCount(adopt.CanonicalHost(docs)) != restarts { |
| + t.Fatal("the resume wrote or restarted again") |
| } |
| - // With every live check passed, the same command opens Plan C. |
| - r.saveChecks() |
| - r.applied("", true, "activate", "--apps", "docs") |
| } |
| -func TestLiveRefusedBeforeCanaryActive(t *testing.T) { |
| +// The delivery check is the runner's alone: a served release that is not |
| +// the reviewed one is refused after the restart, nothing is recorded, and |
| +// activation stays refused. |
| +func TestConfigureRefusesUnreviewedRelease(t *testing.T) { |
| t.Parallel() |
| r := newRig(t) |
| r.throughPlanA() |
| - before := r.writes() |
| - r.refused("canary-not-active", "", false, "live", "--event", "7", "--apply") |
| - if after := r.writes(); after != before { |
| - t.Fatalf("a refused live wrote: %+v %+v", before, after) |
| + other := sha256.Sum256([]byte("v9.9.9")) |
| + r.cfg["artifacts"].(map[string]string)[adopt.CanaryApp] = hex.EncodeToString(other[:]) |
| + r.writeConfig() |
| + r.refused("check-artifact-mismatch", "", true, "configure", "--app", adopt.CanaryApp, "--apply") |
| + if r.checked(adopt.CanaryApp) { |
| + t.Fatal("a delivery check was recorded for an unreviewed release") |
| + } |
| + 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) { |
| + t.Parallel() |
| + r := newRig(t) |
| + for _, args := range [][]string{{"witness", "--app", "docs", "--apply"}, {"live", "--event", "7", "--apply"}} { |
| + code, out := r.cli("", true, args...) |
| + if code != 2 || !strings.Contains(out, adopt.Usage) { |
| + t.Fatalf("alta-adopt %s: exit %d\n%s", args[0], code, out) |
| + } |
| + if strings.Contains(adopt.Usage, " "+args[0]+" ") { |
| + t.Fatalf("the usage still lists %s", args[0]) |
| + } |
| + } |
| + if _, exists := r.rows(); exists { |
| + t.Fatal("an unknown command created the state") |
| } |
| } |
diff --git a/go.mod b/go.mod| index 5b41090..184c9d9 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -5,7 +5,6 @@ go 1.26 |
| toolchain go1.26.5 |
| require ( |
| - amadan.net/oficina/agent-access.git v0.0.0-20261101215226-e4ea91480ce6 |
| amadan.net/oficina/estilo.git v0.0.0-20261026221328-cca97df85b67 |
| amadan.net/oficina/home/connect v0.0.0-20261028092646-82d938882ed3 |
| amadan.net/oficina/home/handoff v0.0.0-20261028092646-82d938882ed3 |
| @@ -13,34 +12,21 @@ require ( |
| amadan.net/rastrillo/rastrillo v0.29.1-0.20261028004840-5bb38c0ab31b |
| github.com/go-chi/chi/v5 v5.3.2 |
| github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 |
| - golang.org/x/oauth2 v0.35.0 |
| modernc.org/sqlite v1.55.0 |
| ) |
| require ( |
| amadan.net/rastrillo/rastrillo/money v0.1.0 // indirect |
| github.com/carlosframework/rastrillo v0.23.0 // indirect |
| - github.com/danieljoos/wincred v1.2.3 // indirect |
| github.com/dustin/go-humanize v1.0.1 // indirect |
| - github.com/godbus/dbus/v5 v5.2.2 // indirect |
| - github.com/gofrs/flock v0.12.1 // indirect |
| - github.com/google/jsonschema-go v0.4.3 // indirect |
| github.com/google/uuid v1.6.0 // indirect |
| github.com/jinzhu/inflection v1.0.0 // indirect |
| github.com/jinzhu/now v1.1.5 // indirect |
| github.com/mattn/go-isatty v0.0.20 // indirect |
| - github.com/modelcontextprotocol/go-sdk v1.7.0 // indirect |
| github.com/ncruces/go-strftime v1.0.0 // indirect |
| github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect |
| - github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 // indirect |
| - github.com/segmentio/asm v1.1.3 // indirect |
| - github.com/segmentio/encoding v0.5.4 // indirect |
| - github.com/yosida95/uritemplate/v3 v3.0.2 // indirect |
| - github.com/zalando/go-keyring v0.2.8 // indirect |
| - golang.org/x/sync v0.21.0 // indirect |
| golang.org/x/sys v0.46.0 // indirect |
| golang.org/x/text v0.39.0 // indirect |
| - golang.org/x/time v0.15.0 // indirect |
| gorm.io/gorm v1.31.2 // indirect |
| gorm.io/plugin/dbresolver v1.6.2 // indirect |
| modernc.org/libc v1.74.1 // indirect |
diff --git a/go.sum b/go.sum| index bb78cfb..995fa6d 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -1,5 +1,3 @@ |
| -amadan.net/oficina/agent-access.git v0.0.0-20261101215226-e4ea91480ce6 h1:TsdiPHRgol+QhONgRWRlRc3dfn4ilnPJm5cmrWeXndA= |
| -amadan.net/oficina/agent-access.git v0.0.0-20261101215226-e4ea91480ce6/go.mod h1:IWNXkxXLhEbHocPN+qPD5z8ix4dT/wtHLR27Z5QPdRc= |
| amadan.net/oficina/estilo.git v0.0.0-20261026221328-cca97df85b67 h1:B0mReCGiVImozUwSVHhsvSYycEd8hxxAX8cU6nlEDWE= |
| amadan.net/oficina/estilo.git v0.0.0-20261026221328-cca97df85b67/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw= |
| amadan.net/oficina/home/connect v0.0.0-20261028092646-82d938882ed3 h1:ErD9M+ESc00+x8d8p3621bh4Ykoz9QWHvYiDtFPxGsQ= |
| @@ -20,12 +18,6 @@ github.com/chromedp/chromedp v0.14.2 h1:r3b/WtwM50RsBZHMUm9fsNhhzRStTHrKdr2zmwbZ |
| github.com/chromedp/chromedp v0.14.2/go.mod h1:rHzAv60xDE7VNy/MYtTUrYreSc0ujt2O1/C3bzctYBo= |
| github.com/chromedp/sysutil v1.1.0 h1:PUFNv5EcprjqXZD9nJb9b/c9ibAbxiYo4exNWZyipwM= |
| github.com/chromedp/sysutil v1.1.0/go.mod h1:WiThHUdltqCNKGc4gaU50XgYjwjYIhKWoHGPTUfWTJ8= |
| -github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ= |
| -github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs= |
| -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= |
| -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
| -github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= |
| -github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= |
| github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= |
| github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= |
| github.com/go-chi/chi/v5 v5.3.2 h1:5YQkICvTCSZ25hoRsyJazN0scjzKGiu4VAUc7H1o1nY= |
| @@ -40,16 +32,6 @@ github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= |
| github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= |
| github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs= |
| github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc= |
| -github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ= |
| -github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c= |
| -github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= |
| -github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= |
| -github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= |
| -github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= |
| -github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= |
| -github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= |
| -github.com/google/jsonschema-go v0.4.3 h1:/DBOLZTfDow7pe2GmaJNhltueGTtDKICi8V8p+DQPd0= |
| -github.com/google/jsonschema-go v0.4.3/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE= |
| github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs= |
| github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= |
| github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= |
| @@ -66,34 +48,14 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE |
| github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= |
| github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= |
| github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= |
| -github.com/modelcontextprotocol/go-sdk v1.7.0 h1:yqjY2dsbKAC0LSuWZVBMrHgiG8ukXv6NRo0JiALay44= |
| -github.com/modelcontextprotocol/go-sdk v1.7.0/go.mod h1:dL7u98E/zjJTGzEq+j30jQ8K2k1mb6LeAH4inEcSGts= |
| github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= |
| github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= |
| -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= |
| -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
| github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= |
| github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= |
| -github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 h1:1EYB5IzjZawrrnELUi78f9fPu57HuXjmddZPjrls/28= |
| -github.com/santhosh-tekuri/jsonschema/v6 v6.0.3/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= |
| -github.com/segmentio/asm v1.1.3 h1:WM03sfUOENvvKexOLp+pCqgb/WDjsi7EK8gIsICtzhc= |
| -github.com/segmentio/asm v1.1.3/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg= |
| -github.com/segmentio/encoding v0.5.4 h1:OW1VRern8Nw6ITAtwSZ7Idrl3MXCFwXHPgqESYfvNt0= |
| -github.com/segmentio/encoding v0.5.4/go.mod h1:HS1ZKa3kSN32ZHVZ7ZLPLXWvOVIiZtyJnO1gPH1sKt0= |
| github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= |
| github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= |
| -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= |
| -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= |
| -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= |
| -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= |
| -github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4= |
| -github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4= |
| -github.com/zalando/go-keyring v0.2.8 h1:6sD/Ucpl7jNq10rM2pgqTs0sZ9V3qMrqfIIy5YPccHs= |
| -github.com/zalando/go-keyring v0.2.8/go.mod h1:tsMo+VpRq5NGyKfxoBVjCuMrG47yj8cmakZDO5QGii0= |
| golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ= |
| golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0= |
| -golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ= |
| -golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= |
| golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM= |
| golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= |
| golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
| @@ -101,12 +63,8 @@ golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw= |
| golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= |
| golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus= |
| golang.org/x/text v0.39.0/go.mod h1:3UwRclnC2g0TU9x8PZiyfOajCd1zaUNHF9cvqcQZ+ZM= |
| -golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= |
| -golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= |
| golang.org/x/tools v0.47.0 h1:7Kn5x/d1svx/PzryTsqeoZN4TZwqeH5pGWjefhLi/1Q= |
| golang.org/x/tools v0.47.0/go.mod h1:dFHnyTvFWY212G+h7ZY4Vsp/K3U4/7W9TyVaAul8uCA= |
| -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= |
| -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
| gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo= |
| gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= |
| gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ= |
diff --git a/homecompat/go.mod b/homecompat/go.mod| index 46c425a..0078288 100644 |
| --- a/homecompat/go.mod |
| +++ b/homecompat/go.mod |
| @@ -19,31 +19,17 @@ require ( |
| require ( |
| amadan.net/carlos/platform.git/launchctx v0.0.0-20260911135504-fb577f96f7d1 // indirect |
| - amadan.net/oficina/agent-access.git v0.0.0-20261101215226-e4ea91480ce6 // indirect |
| - github.com/danieljoos/wincred v1.2.3 // indirect |
| github.com/dustin/go-humanize v1.0.1 // indirect |
| github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 // indirect |
| - github.com/godbus/dbus/v5 v5.2.2 // indirect |
| - github.com/gofrs/flock v0.12.1 // indirect |
| - github.com/google/jsonschema-go v0.4.3 // indirect |
| github.com/google/uuid v1.6.0 // indirect |
| github.com/jinzhu/inflection v1.0.0 // indirect |
| github.com/jinzhu/now v1.1.5 // indirect |
| github.com/mattn/go-isatty v0.0.20 // indirect |
| - github.com/modelcontextprotocol/go-sdk v1.7.0 // indirect |
| github.com/ncruces/go-strftime v1.0.0 // indirect |
| github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect |
| - github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 // indirect |
| - github.com/segmentio/asm v1.1.3 // indirect |
| - github.com/segmentio/encoding v0.5.4 // indirect |
| github.com/sqids/sqids-go v0.4.1 // indirect |
| - github.com/yosida95/uritemplate/v3 v3.0.2 // indirect |
| - github.com/zalando/go-keyring v0.2.8 // indirect |
| - golang.org/x/oauth2 v0.35.0 // indirect |
| - golang.org/x/sync v0.22.0 // indirect |
| golang.org/x/sys v0.47.0 // indirect |
| golang.org/x/text v0.41.0 // indirect |
| - golang.org/x/time v0.15.0 // indirect |
| gorm.io/gorm v1.31.2 // indirect |
| gorm.io/plugin/dbresolver v1.6.2 // indirect |
| modernc.org/libc v1.74.1 // indirect |
diff --git a/homecompat/go.sum b/homecompat/go.sum| index 68c47be..8fad547 100644 |
| --- a/homecompat/go.sum |
| +++ b/homecompat/go.sum |
| @@ -1,7 +1,5 @@ |
| amadan.net/carlos/platform.git/launchctx v0.0.0-20260911135504-fb577f96f7d1 h1:RxwIRojWcVtwSdNAjtdz7y1bxHLh3GUgqT1TrXVKpyM= |
| amadan.net/carlos/platform.git/launchctx v0.0.0-20260911135504-fb577f96f7d1/go.mod h1:6fBmMWgtESLFXZURzu/HyRXM0vyLuo4+XGGdKuZ+wao= |
| -amadan.net/oficina/agent-access.git v0.0.0-20261101215226-e4ea91480ce6 h1:TsdiPHRgol+QhONgRWRlRc3dfn4ilnPJm5cmrWeXndA= |
| -amadan.net/oficina/agent-access.git v0.0.0-20261101215226-e4ea91480ce6/go.mod h1:IWNXkxXLhEbHocPN+qPD5z8ix4dT/wtHLR27Z5QPdRc= |
| amadan.net/oficina/home v0.1.1-0.20261116154649-16da7bad9395 h1:5QEhaQTkxryVZSQlLpRehhmxJcjbfs7OK1yA2jiUUC8= |
| amadan.net/oficina/home v0.1.1-0.20261116154649-16da7bad9395/go.mod h1:YQrPsuTn0bga002nJQ9P+MN4Kjl6lZianRJINDJ8On4= |
| amadan.net/oficina/home/handoff v0.0.0-20261116154649-16da7bad9395 h1:r9TnQOObUFlvMqPn9e+fr8mwEU7ZS9RH26Fn6NSBUeE= |
| @@ -12,28 +10,12 @@ amadan.net/rastrillo/rastrillo v0.29.1-0.20261028004840-5bb38c0ab31b h1:7rApPVcE |
| amadan.net/rastrillo/rastrillo v0.29.1-0.20261028004840-5bb38c0ab31b/go.mod h1:jSSeydqEvlm/fU3hhWoXFnyEaDgroR8LPRZSo9ZhhIM= |
| amadan.net/rastrillo/rastrillo/money v0.1.0 h1:MxU4oqNrW8abxRTkgZBv24OYNpFnvonajNqeLIzmmaM= |
| amadan.net/rastrillo/rastrillo/money v0.1.0/go.mod h1:cmgkjBEIQh1pFSYvQk0UU6oPYS8kSDypdT9+t4Flx0U= |
| -github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ= |
| -github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs= |
| -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= |
| -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
| -github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= |
| -github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= |
| github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= |
| github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= |
| github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 h1:iizUGZ9pEquQS5jTGkh4AqeeHCMbfbjeb0zMt0aEFzs= |
| github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M= |
| github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= |
| github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= |
| -github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ= |
| -github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c= |
| -github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= |
| -github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= |
| -github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= |
| -github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= |
| -github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= |
| -github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= |
| -github.com/google/jsonschema-go v0.4.3 h1:/DBOLZTfDow7pe2GmaJNhltueGTtDKICi8V8p+DQPd0= |
| -github.com/google/jsonschema-go v0.4.3/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE= |
| github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs= |
| github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= |
| github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= |
| @@ -50,36 +32,16 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE |
| github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= |
| github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= |
| github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= |
| -github.com/modelcontextprotocol/go-sdk v1.7.0 h1:yqjY2dsbKAC0LSuWZVBMrHgiG8ukXv6NRo0JiALay44= |
| -github.com/modelcontextprotocol/go-sdk v1.7.0/go.mod h1:dL7u98E/zjJTGzEq+j30jQ8K2k1mb6LeAH4inEcSGts= |
| github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= |
| github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= |
| -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= |
| -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
| github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= |
| github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= |
| -github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 h1:1EYB5IzjZawrrnELUi78f9fPu57HuXjmddZPjrls/28= |
| -github.com/santhosh-tekuri/jsonschema/v6 v6.0.3/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= |
| -github.com/segmentio/asm v1.1.3 h1:WM03sfUOENvvKexOLp+pCqgb/WDjsi7EK8gIsICtzhc= |
| -github.com/segmentio/asm v1.1.3/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg= |
| -github.com/segmentio/encoding v0.5.4 h1:OW1VRern8Nw6ITAtwSZ7Idrl3MXCFwXHPgqESYfvNt0= |
| -github.com/segmentio/encoding v0.5.4/go.mod h1:HS1ZKa3kSN32ZHVZ7ZLPLXWvOVIiZtyJnO1gPH1sKt0= |
| github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= |
| github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= |
| github.com/sqids/sqids-go v0.4.1 h1:eQKYzmAZbLlRwHeHYPF35QhgxwZHLnlmVj9AkIj/rrw= |
| github.com/sqids/sqids-go v0.4.1/go.mod h1:EMwHuPQgSNFS0A49jESTfIQS+066XQTVhukrzEPScl8= |
| -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= |
| -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= |
| -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= |
| -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= |
| -github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4= |
| -github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4= |
| -github.com/zalando/go-keyring v0.2.8 h1:6sD/Ucpl7jNq10rM2pgqTs0sZ9V3qMrqfIIy5YPccHs= |
| -github.com/zalando/go-keyring v0.2.8/go.mod h1:tsMo+VpRq5NGyKfxoBVjCuMrG47yj8cmakZDO5QGii0= |
| golang.org/x/mod v0.38.0 h1:MECBjubtXD7yj4HrhIUcywNaGeNVUdfVnxmPajOk4yk= |
| golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40= |
| -golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ= |
| -golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= |
| golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek= |
| golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= |
| golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
| @@ -87,12 +49,8 @@ golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= |
| golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= |
| golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= |
| golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= |
| -golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= |
| -golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= |
| golang.org/x/tools v0.48.0 h1:3+hClM1aLL5mjMKm5ovokw9epgRXPuu2tILgismM6RE= |
| golang.org/x/tools v0.48.0/go.mod h1:08xX0orndb/F7jJxGDicx061tyd5pcMto75YMAXr6lk= |
| -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= |
| -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
| gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo= |
| gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= |
| gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ= |
diff --git a/provision/adopt_adverse_test.go b/provision/adopt_adverse_test.go| index b0fcec3..2973b0a 100644 |
| --- a/provision/adopt_adverse_test.go |
| +++ b/provision/adopt_adverse_test.go |
| @@ -36,13 +36,13 @@ func (a *adoptHarness) neverActivated() { |
| // field or key name after them. |
| var gateCodes = []string{ |
| "unknown-app", "team-not-sqid", |
| - "missing-home-preflight", "missing-baseline", "missing-write", "missing-after", "missing-witness", |
| - "rollback-recorded", "issuer-mismatch", "team-mismatch", "live-checks-missing", "artifact-unreviewed", |
| + "missing-home-preflight", "missing-baseline", "missing-write", "missing-after", "missing-delivery-check", |
| + "rollback-recorded", "issuer-mismatch", "team-mismatch", "canary-not-active", "artifact-unreviewed", |
| "identity-storage", "identity-instance", "identity-alias", "identity-environment", "identity-owned", |
| "identity-channel", "identity-region", "identity-moving", "identity-record", |
| "after-not-preserved", "drift-changed:X_KEY", "drift-gone:X_KEY", "config-added:X_KEY", |
| "team-mode-X_TEAM_ROSTER", "agent-key-X_AGENT_TEAM", "agent-key-X_AGENT_ISSUER", |
| - "witness-superseded", "not-delivered", "version-header-mismatch", "version-unacceptable", "artifact-mismatch", |
| + "delivery-check-superseded", "not-delivered", "version-header-mismatch", "version-unacceptable", "artifact-mismatch", |
| } |
| // Each code the gate can refuse with parks the activation under that |
| @@ -51,7 +51,7 @@ var gateCodes = []string{ |
| func TestAdverseActivationParksOnEveryGateCode(t *testing.T) { |
| for _, app := range []string{"calendar", "docs"} { |
| for _, code := range gateCodes { |
| - if app == "docs" && code != "live-checks-missing" { |
| + if app == "docs" && code != "canary-not-active" { |
| continue |
| } |
| t.Run(app+"/"+code, func(t *testing.T) { |
| @@ -82,11 +82,11 @@ func TestAdverseActivationParksOnEveryGateCode(t *testing.T) { |
| func TestAdverseActivationKeepsEveryRefusalCode(t *testing.T) { |
| a := newAdoption(t) |
| obs := newObserver() |
| - obs.set(&testRefusal{codes: []string{"after-not-preserved", "identity-storage", "witness-superseded"}}) |
| + obs.set(&testRefusal{codes: []string{"after-not-preserved", "delivery-check-superseded", "identity-storage"}}) |
| e := a.adopter(nil, obs) |
| a.planA(e) |
| run := a.activate(e, "calendar") |
| - if r := a.drive(e, run, 3); r.State != "parked" || r.Code != "observe-after-not-preserved,identity-storage,witness-superseded" { |
| + if r := a.drive(e, run, 3); r.State != "parked" || r.Code != "observe-after-not-preserved,delivery-check-superseded,identity-storage" { |
| t.Fatalf("run %s %q", r.State, r.Code) |
| } |
| a.neverActivated() |
| @@ -177,7 +177,7 @@ func TestAdverseActivationNeedsAnObserver(t *testing.T) { |
| func TestAdverseActivationLapsedAttemptNeverActivates(t *testing.T) { |
| a := newAdoption(t) |
| obs := newObserver() |
| - obs.set(&testRefusal{codes: []string{"missing-witness"}}) |
| + obs.set(&testRefusal{codes: []string{"missing-delivery-check"}}) |
| e := a.adopter(nil, obs) |
| a.planA(e) |
| run := a.activate(e, "calendar") |
diff --git a/provision/adopt_test.go b/provision/adopt_test.go| index 29580da..67194e6 100644 |
| --- a/provision/adopt_test.go |
| +++ b/provision/adopt_test.go |
| @@ -608,14 +608,14 @@ func TestActivateAdoptedWithoutObserverFails(t *testing.T) { |
| func TestActivateAdoptedParksOnObserverRefusal(t *testing.T) { |
| a := newAdoption(t) |
| obs := newObserver() |
| - obs.set(&testRefusal{codes: []string{"missing-witness", "witness-superseded"}}) |
| + obs.set(&testRefusal{codes: []string{"delivery-check-superseded", "missing-delivery-check"}}) |
| e := a.adopter(nil, obs) |
| a.planA(e) |
| run := a.activate(e, "calendar") |
| - if r := a.drive(e, run, 3); r.State != "parked" || r.Code != "observe-missing-witness,witness-superseded" { |
| + if r := a.drive(e, run, 3); r.State != "parked" || r.Code != "observe-delivery-check-superseded,missing-delivery-check" { |
| t.Fatalf("run %s %s", r.State, r.Code) |
| } |
| - if s := a.step("calendar", StepActivate); s.State != "parked" || s.Code != "observe-missing-witness,witness-superseded" { |
| + if s := a.step("calendar", StepActivate); s.State != "parked" || s.Code != "observe-delivery-check-superseded,missing-delivery-check" { |
| t.Fatalf("step %s %s", s.State, s.Code) |
| } |
| obs.set(errors.New("carlos unreachable")) |
| @@ -698,7 +698,7 @@ func TestActivateAdoptedStartedNotBeforeRecordedIssued(t *testing.T) { |
| func TestActivateAdoptedReverifiesLapsedAttempt(t *testing.T) { |
| a := newAdoption(t) |
| obs := newObserver() |
| - obs.set(&testRefusal{codes: []string{"missing-witness"}}) |
| + obs.set(&testRefusal{codes: []string{"missing-delivery-check"}}) |
| e := a.adopter(nil, obs) |
| a.planA(e) |
| run := a.activate(e, "calendar") |