oficina / alta Public

alta-adopt: check reviewed release and baseline shape before writing

Astra review of adopt-simplify (three Important findings, one Minor).

- The reviewed artifact is checked against the freshly served release
  before any write: preflight reports artifact-unreviewed or
  artifact-mismatch, and configure (dry run and --apply, and before a
  resumed resend) refuses with nothing journalled or sent. The
  post-restart delivery check keeps its own check.
- Preflight refuses an operations baseline Delivered could never move on
  (operations-<shape>): each app must answer as BaselineOps says, a 404,
  or for Slides and Calls their own 401. A resume whose own keys are
  stored and whose door already gives agent-access's answer still passes.
- The classifier matches agent-access f08bfc1 exactly: agent-401 and
  agent-200 need Cache-Control no-store and application/json, the 401 a
  single Bearer challenge and exactly {"error":{"code":"unauthenticated",
  "message":...}}, the 200 exactly {"operations":[...]}. Lookalikes are
  app-401 or other. Delivered holds each app to its transition: 404 to
  agent-401 or agent-200; Slides' and Calls' 401 to agent-401 only.
- store.go says why adopt_checks and adopt_witnesses remain.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 62bc8e49348411a540957cc880f5ca4f818ca70c parent 4b36e5b
15 files changed, +462 −101
  • README.md +16 −10
  • adopt/delivery.go +107 −27
  • adopt/delivery_test.go +130 −19
  • adopt/deliverycheck.go +24 −6
  • adopt/gate_adverse_test.go +3 −3
  • adopt/observer.go +1 −1
  • adopt/rehearsal_test.go +8 −5
  • adopt/restart_test.go +1 −1
  • adopt/snapshot.go +12 −1
  • adopt/snapshot_test.go +56 −1
  • adopt/store.go +3 −1
  • adopt/write.go +18 −9
  • adopt/write_test.go +56 −9
  • cmd/alta-adopt/main.go +6 −3
  • cmd/alta-adopt/main_test.go +21 −5

CI passed — run details

CI log
=== vet ===
go vet ./...
=== fmt ===
=== test ===
CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/alta/adopt	17.241s
ok  	amadan.net/oficina/alta/carlosop	(cached)
?   	amadan.net/oficina/alta/carlosop/fakecarlos	[no test files]
ok  	amadan.net/oficina/alta/cmd/alta	(cached)
ok  	amadan.net/oficina/alta/cmd/alta-adopt	21.932s
ok  	amadan.net/oficina/alta/console	(cached)
?   	amadan.net/oficina/alta/console/fakeconsole	[no test files]
ok  	amadan.net/oficina/alta/homeop	(cached)
ok  	amadan.net/oficina/alta/homeop/fakehome	(cached)
ok  	amadan.net/oficina/alta/internal/web	(cached)
ok  	amadan.net/oficina/alta/provision	(cached)
=== compat ===
cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/home/altacompat	0.608s
diff --git a/README.md b/README.md
index 51f6abd..cc713fb 100644
--- a/README.md
+++ b/README.md
@@ -305,7 +305,10 @@ run it again if it stops (`status` shows where every run is).
directory and paste the counts. Rerun with `--apply` to record them.
4. **CARLOS preflight.** Run `alta-adopt preflight`. Any code stops the
run; `inherits-<host>` means another instance shares the layer the keys
- would go to.
+ would go to. `artifact-mismatch` means the app is not serving the
+ release reviewed in `artifacts`. `operations-<shape>` means its
+ `/api/v1/operations` does not answer as it should before adoption: a
+ 404, or for Slides and Calls their own 401.
5. **Initialize.** Run `alta-adopt initialize --apply` and type the
attestation. Confirm on
[https://oficina.works/operator/confirm](https://oficina.works/operator/confirm)
@@ -326,14 +329,16 @@ 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,
- 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.
+ Before writing, `configure` refuses as preflight does, so nothing is
+ written for an app that is not serving its reviewed release. It then
+ 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, and agent-access's challenge
+ where Slides and Calls gave 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`.
11. **Plan C.** Once Plan B's run is done, run `activate --apps
@@ -366,7 +371,8 @@ run it again if it stops (`status` shows where every run is).
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>`
+ one in `artifacts`; checked before the write too, so this means it
+ changed since), `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.
diff --git a/adopt/delivery.go b/adopt/delivery.go
index 73cf239..2f0d28c 100644
--- a/adopt/delivery.go
+++ b/adopt/delivery.go
@@ -6,27 +6,44 @@ import (
"encoding/json"
"errors"
"io"
+ "mime"
"net"
"net/http"
"net/url"
"strings"
"time"
+
+ "amadan.net/oficina/alta/provision"
)
// OpsShape is what GET /api/v1/operations answers, reduced to the shapes
// adoption tells apart. Slides and Calls already answer their own 401 there
// (an app middleware, {"error":"unauthorized"}), so a bare 401 proves
-// nothing: only agent-access's own challenge counts.
+// nothing: only agent-access's own answer counts, in exactly the shape
+// agent-access writes it (agent-access f08bfc1, http.go Authenticate,
+// writeFailure and writeJSON).
type OpsShape string
const (
OpsAbsent OpsShape = "absent" // 404: the delegated-access code is not running
OpsApp401 OpsShape = "app-401" // a 401 that is not agent-access's challenge
OpsAgent401 OpsShape = "agent-401" // agent-access's challenge
- OpsAgent200 OpsShape = "agent-200"
- OpsOther OpsShape = "other"
+ OpsAgent200 OpsShape = "agent-200" // agent-access's operations list
+ OpsOther OpsShape = "other" // anything else, a lookalike 200 included
)
+// BaselineOps is what app's operations door answers before adoption
+// (Paul, 2026-11-17, Home discussion 103): Slides and Calls their own
+// middleware's 401, every other app a 404. Preflight refuses any other
+// baseline, and Delivered holds each app to its own transition.
+func BaselineOps(app provision.App) OpsShape {
+ switch app.Slug {
+ case "slides", "calls":
+ return OpsApp401
+ }
+ return OpsAbsent
+}
+
// Delivery is what one probe saw of a running app. It carries versions and
// status codes only, never a body beyond the version name.
type Delivery struct {
@@ -119,34 +136,92 @@ func get(ctx context.Context, c *http.Client, target string) (int, http.Header,
return resp.StatusCode, resp.Header, body, nil
}
-// shape classifies the operations answer. agent-401 is all of: status 401,
-// WWW-Authenticate beginning Bearer, Cache-Control no-store, and a body
-// {"error":{"code":"unauthenticated",…}}.
+// shape classifies the operations answer. agent-access answers every
+// request, before routing, with Cache-Control no-store, and every answer
+// it writes is application/json. Its two answers to GET
+// /api/v1/operations are:
+//
+// - agent-401: status 401, WWW-Authenticate "Bearer" or "Bearer
+// <params>", and a body that is exactly {"error":{"code":
+// "unauthenticated","message":<non-empty string>}};
+// - agent-200: status 200 and a body that is exactly {"operations":
+// [...]}, an array.
+//
+// A 401 short of agent-401 is app-401; a 200 short of agent-200 is other.
+// Keys are matched exactly, case included, and nothing may follow the
+// body's one JSON value.
func shape(status int, h http.Header, body []byte) OpsShape {
+ agent := hasToken(h.Get("Cache-Control"), "no-store") && jsonMedia(h.Get("Content-Type"))
switch status {
case http.StatusNotFound:
return OpsAbsent
case http.StatusOK:
- return OpsAgent200
- case http.StatusUnauthorized:
- if !strings.HasPrefix(h.Get("WWW-Authenticate"), "Bearer") ||
- !hasToken(h.Get("Cache-Control"), "no-store") {
- return OpsApp401
- }
- var b struct {
- Error struct {
- Code string `json:"code"`
- } `json:"error"`
+ if agent && operationsList(body) {
+ return OpsAgent200
}
- dec := json.NewDecoder(bytes.NewReader(body))
- if dec.Decode(&b) != nil || b.Error.Code != "unauthenticated" {
- return OpsApp401
+ return OpsOther
+ case http.StatusUnauthorized:
+ if agent && bearerChallenge(h) && unauthenticated(body) {
+ return OpsAgent401
}
- return OpsAgent401
+ return OpsApp401
}
return OpsOther
}
+func jsonMedia(v string) bool {
+ media, _, err := mime.ParseMediaType(v)
+ return err == nil && media == "application/json"
+}
+
+// bearerChallenge is one WWW-Authenticate, the Bearer scheme with or
+// without parameters.
+func bearerChallenge(h http.Header) bool {
+ vs := h.Values("WWW-Authenticate")
+ return len(vs) == 1 && (vs[0] == "Bearer" || strings.HasPrefix(vs[0], "Bearer "))
+}
+
+// object decodes body as exactly one JSON object holding exactly keys.
+func object(body []byte, keys ...string) (map[string]json.RawMessage, bool) {
+ dec := json.NewDecoder(bytes.NewReader(body))
+ var m map[string]json.RawMessage
+ if dec.Decode(&m) != nil || m == nil || len(m) != len(keys) {
+ return nil, false
+ }
+ if _, err := dec.Token(); err != io.EOF {
+ return nil, false
+ }
+ for _, k := range keys {
+ if _, ok := m[k]; !ok {
+ return nil, false
+ }
+ }
+ return m, true
+}
+
+func unauthenticated(body []byte) bool {
+ top, ok := object(body, "error")
+ if !ok {
+ return false
+ }
+ e, ok := object(top["error"], "code", "message")
+ if !ok {
+ return false
+ }
+ var code, message string
+ return json.Unmarshal(e["code"], &code) == nil && code == "unauthenticated" &&
+ json.Unmarshal(e["message"], &message) == nil && message != ""
+}
+
+func operationsList(body []byte) bool {
+ top, ok := object(body, "operations")
+ if !ok {
+ return false
+ }
+ var ops []json.RawMessage
+ return bytes.HasPrefix(bytes.TrimSpace(top["operations"]), []byte("[")) && json.Unmarshal(top["operations"], &ops) == nil
+}
+
func hasToken(header, want string) bool {
for _, t := range strings.Split(header, ",") {
if strings.EqualFold(strings.TrimSpace(t), want) {
@@ -172,18 +247,23 @@ func sameServing(before, now Delivery) error {
return nil
}
-// Delivered says the restart delivered the new configuration: the same
+// Delivered says app's restart delivered the new configuration: the same
// version and header, no redirect, health 200, and the operations door
-// 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 {
+// moved as app's must (Paul, 2026-11-17). Before, it answered as
+// BaselineOps(app) says; now, a 404 must have become agent-401 or
+// agent-200, and Slides' and Calls' own 401 must have become agent-401,
+// agent-access's challenge.
+func Delivered(app provision.App, before, now Delivery) error {
if err := sameServing(before, now); err != nil {
return err
}
- 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 before.Ops != BaselineOps(app) {
+ return errors.New("adopt: the operations door did not answer before the change as this app's does")
}
- if !now.Ops.agentShaped() {
+ switch {
+ case now.Ops == OpsAgent401:
+ case now.Ops == OpsAgent200 && before.Ops == OpsAbsent:
+ default:
return errors.New("adopt: the delegated-access door is not answering")
}
return nil
diff --git a/adopt/delivery_test.go b/adopt/delivery_test.go
index c746a0e..8aa145d 100644
--- a/adopt/delivery_test.go
+++ b/adopt/delivery_test.go
@@ -6,6 +6,8 @@ import (
"net/http/httptest"
"strings"
"testing"
+
+ "amadan.net/oficina/alta/provision"
)
// site is a fake app origin: version, header, healthz and operations are
@@ -46,6 +48,33 @@ func agent401(w http.ResponseWriter) {
_, _ = w.Write([]byte(`{"error":{"code":"unauthenticated","message":"x"}}`))
}
+// respond answers status with headers and body.
+func respond(status int, headers map[string]string, body string) func(w http.ResponseWriter) {
+ return func(w http.ResponseWriter) {
+ for k, v := range headers {
+ w.Header().Set(k, v)
+ }
+ w.WriteHeader(status)
+ _, _ = w.Write([]byte(body))
+ }
+}
+
+// agent200 is a 200 in agent-access's headers, with body.
+func agent200(body string) func(w http.ResponseWriter) {
+ return respond(200, map[string]string{"Cache-Control": "no-store", "Content-Type": "application/json"}, body)
+}
+
+// agent401Body is a 401 in agent-access's headers, with body. A
+// WWW-Authenticate already set is kept, as agent-access keeps it.
+func agent401Body(body string) func(w http.ResponseWriter) {
+ return func(w http.ResponseWriter) {
+ if w.Header().Get("WWW-Authenticate") == "" {
+ w.Header().Set("WWW-Authenticate", "Bearer")
+ }
+ respond(401, map[string]string{"Cache-Control": "no-store", "Content-Type": "application/json"}, body)(w)
+ }
+}
+
func probeOf(t *testing.T, s *site) Delivery {
t.Helper()
srv := httptest.NewServer(s.handler())
@@ -91,9 +120,60 @@ func TestOperationsShapeDistinguishesAppMiddleware(t *testing.T) {
w.WriteHeader(401)
_, _ = w.Write([]byte(`{"error":{"code":"other"}}`))
}, "app-401"},
- "agent-200": {func(w http.ResponseWriter) { w.WriteHeader(200); _, _ = w.Write([]byte(`{}`)) }, "agent-200"},
- "other": {func(w http.ResponseWriter) { w.WriteHeader(500) }, "other"},
+ "agent-200": {agent200(`{"operations":[]}` + "\n"), "agent-200"},
+ "agent-200-listed": {agent200(`{"operations":[{"name":"docs_read"}]}`), "agent-200"},
+ "other": {func(w http.ResponseWriter) { w.WriteHeader(500) }, "other"},
+ }
+ // Lookalike 200s: only agent-access's own list, in its own headers,
+ // counts.
+ for name, ops := range map[string]func(w http.ResponseWriter){
+ "200-empty-object": agent200(`{}`),
+ "200-html": respond(200, map[string]string{"Cache-Control": "no-store", "Content-Type": "text/html"}, `<!doctype html><p>app`),
+ "200-no-store-missing": respond(200, map[string]string{"Content-Type": "application/json"}, `{"operations":[]}`),
+ "200-json-missing": respond(200, map[string]string{"Cache-Control": "no-store"}, `{"operations":[]}`),
+ "200-null-list": agent200(`{"operations":null}`),
+ "200-object-list": agent200(`{"operations":{}}`),
+ "200-extra-key": agent200(`{"operations":[],"user":"x"}`),
+ "200-key-case": agent200(`{"Operations":[]}`),
+ "200-trailing": agent200(`{"operations":[]} {}`),
+ "200-bare-array": agent200(`[]`),
+ } {
+ cases[name] = struct {
+ ops func(w http.ResponseWriter)
+ want OpsShape
+ }{ops, "other"}
}
+ // Lookalike 401s: a Bearer challenge with no-store is not enough.
+ for name, ops := range map[string]func(w http.ResponseWriter){
+ "401-message-missing": agent401Body(`{"error":{"code":"unauthenticated"}}`),
+ "401-message-empty": agent401Body(`{"error":{"code":"unauthenticated","message":""}}`),
+ "401-extra-error-key": agent401Body(`{"error":{"code":"unauthenticated","message":"x","detail":"y"}}`),
+ "401-extra-top-key": agent401Body(`{"error":{"code":"unauthenticated","message":"x"},"login":"/signin"}`),
+ "401-key-case": agent401Body(`{"Error":{"Code":"unauthenticated","Message":"x"}}`),
+ "401-code-not-string": agent401Body(`{"error":{"code":401,"message":"x"}}`),
+ "401-other-code": agent401Body(`{"error":{"code":"forbidden","message":"x"}}`),
+ "401-trailing": agent401Body(`{"error":{"code":"unauthenticated","message":"x"}}x`),
+ "401-json-missing": respond(401, map[string]string{"WWW-Authenticate": "Bearer", "Cache-Control": "no-store"},
+ `{"error":{"code":"unauthenticated","message":"x"}}`),
+ "401-not-bearer-scheme": respond(401, map[string]string{"WWW-Authenticate": "Bearerish", "Cache-Control": "no-store", "Content-Type": "application/json"},
+ `{"error":{"code":"unauthenticated","message":"x"}}`),
+ "401-two-challenges": func(w http.ResponseWriter) {
+ w.Header().Add("WWW-Authenticate", "Bearer")
+ w.Header().Add("WWW-Authenticate", "Basic")
+ agent401Body(`{"error":{"code":"unauthenticated","message":"x"}}`)(w)
+ },
+ } {
+ cases[name] = struct {
+ ops func(w http.ResponseWriter)
+ want OpsShape
+ }{ops, "app-401"}
+ }
+ // agent-access's own variants of its challenge still count.
+ cases["agent-401-resource-metadata"] = struct {
+ ops func(w http.ResponseWriter)
+ want OpsShape
+ }{respond(401, map[string]string{"WWW-Authenticate": `Bearer resource_metadata="https://x.example/.well-known/oauth-protected-resource"`,
+ "Cache-Control": "no-store", "Content-Type": "application/json; charset=utf-8"}, `{"error":{"code":"unauthenticated","message":"Connect to Oficina first."}}`+"\n"), "agent-401"}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
d := probeOf(t, &site{version: "v1", header: "v1", health: 200, ops: c.ops})
@@ -124,7 +204,7 @@ func TestProbeRefusesRedirect(t *testing.T) {
}
before := Delivery{Version: "v1", Header: "v1", Health: 200, Ops: "absent"}
now := Delivery{Version: "v1", Header: "v1", Health: 200, Ops: "agent-401", Redirected: true}
- if err := Delivered(before, now); err == nil {
+ if err := Delivered(appNamedStatic("docs"), before, now); err == nil {
t.Fatal("Delivered accepted a redirect")
}
}
@@ -164,7 +244,7 @@ func TestProbeKeepsBodyExactly(t *testing.T) {
}
before := Delivery{Version: a.Version, Header: "v1", Health: 200, Ops: "absent"}
now := Delivery{Version: b.Version, Header: "v1", Health: 200, Ops: "agent-401"}
- if err := Delivered(before, now); err == nil {
+ if err := Delivered(appNamedStatic("docs"), before, now); err == nil {
t.Fatal("Delivered approved a whitespace-only change")
}
}
@@ -194,10 +274,11 @@ func dl(v, h string, health int, ops OpsShape) Delivery {
func TestDeliveredRefusesVersionOrHeaderChange(t *testing.T) {
before := dl("v1", "v1", 200, "absent")
- if err := Delivered(before, dl("v1", "v1", 200, "agent-401")); err != nil {
+ docs := appNamedStatic("docs")
+ if err := Delivered(docs, before, dl("v1", "v1", 200, "agent-401")); err != nil {
t.Fatalf("good delivery refused: %v", err)
}
- if err := Delivered(before, dl("v1", "v1", 200, "agent-200")); err != nil {
+ if err := Delivered(docs, before, dl("v1", "v1", 200, "agent-200")); err != nil {
t.Fatalf("agent-200 refused: %v", err)
}
bad := map[string]Delivery{
@@ -210,28 +291,58 @@ func TestDeliveredRefusesVersionOrHeaderChange(t *testing.T) {
"redirect": {Version: "v1", Header: "v1", Health: 200, Ops: "agent-401", Redirected: true},
}
for n, now := range bad {
- if err := Delivered(before, now); err == nil {
+ if err := Delivered(appNamedStatic("docs"), before, now); err == nil {
t.Errorf("%s: accepted", n)
}
}
// Before already agent-shaped: nothing was delivered by this run.
- if err := Delivered(dl("v1", "v1", 200, "agent-401"), dl("v1", "v1", 200, "agent-401")); err == nil {
+ if err := Delivered(docs, dl("v1", "v1", 200, "agent-401"), dl("v1", "v1", 200, "agent-401")); err == nil {
t.Error("an already agent-shaped before was accepted")
}
}
-// 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)
- }
+// The operations door must move as the app's must (Paul, 2026-11-17): for
+// four apps a 404 to agent-access's challenge or list, for Slides and
+// Calls their own 401 to agent-access's challenge, and nothing else.
+func TestDeliveredHoldsEachAppToItsTransition(t *testing.T) {
+ d := func(ops OpsShape) Delivery { return dl("v1", "v1", 200, ops) }
+ for _, a := range provision.Apps {
+ t.Run(a.Slug, func(t *testing.T) {
+ var good, bad [][2]OpsShape
+ if a.Slug == "slides" || a.Slug == "calls" {
+ good = [][2]OpsShape{{OpsApp401, OpsAgent401}}
+ bad = [][2]OpsShape{{OpsApp401, OpsAgent200}, {OpsApp401, OpsOther}, {OpsApp401, OpsApp401},
+ {OpsAbsent, OpsAgent401}, {OpsAbsent, OpsAgent200}}
+ } else {
+ good = [][2]OpsShape{{OpsAbsent, OpsAgent401}, {OpsAbsent, OpsAgent200}}
+ bad = [][2]OpsShape{{OpsAbsent, OpsOther}, {OpsAbsent, OpsApp401}, {OpsAbsent, OpsAbsent},
+ {OpsApp401, OpsAgent401}, {OpsApp401, OpsAgent200}}
+ }
+ for _, before := range []OpsShape{OpsOther, OpsAgent200, OpsAgent401, ""} {
+ bad = append(bad, [2]OpsShape{before, OpsAgent401})
+ }
+ for _, c := range good {
+ if err := Delivered(a, d(c[0]), d(c[1])); err != nil {
+ t.Errorf("%s -> %s refused: %v", c[0], c[1], err)
+ }
+ }
+ for _, c := range bad {
+ if err := Delivered(a, d(c[0]), d(c[1])); err == nil {
+ t.Errorf("%q -> %q accepted", c[0], c[1])
+ }
+ }
+ })
}
- 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 TestBaselineOps(t *testing.T) {
+ for _, a := range provision.Apps {
+ want := OpsAbsent
+ if a.Slug == "slides" || a.Slug == "calls" {
+ want = OpsApp401
+ }
+ if got := BaselineOps(a); got != want {
+ t.Fatalf("%s: %q, want %q", a.Slug, got, want)
}
}
}
diff --git a/adopt/deliverycheck.go b/adopt/deliverycheck.go
index 1173fc3..621be89 100644
--- a/adopt/deliverycheck.go
+++ b/adopt/deliverycheck.go
@@ -29,8 +29,8 @@ import (
// - a fresh observation's probe passes Delivered against the baseline
// (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;
+// /api/v1/operations moved as the app's must: a 404 to agent-access's
+// challenge or list, Slides' and Calls' own 401 to its challenge;
// - the served release, X-Carlos-Version, hashes to artifact
// (check-artifact-mismatch);
// - the fresh identity equals the after snapshot's
@@ -43,6 +43,10 @@ import (
// 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.
+//
+// The reviewed release is checked before anything is written too:
+// configure's write refuses it (WriteAgentKeys), so this check only
+// catches a release that changed after the write.
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")
@@ -68,12 +72,11 @@ func CheckDelivery(ctx context.Context, s *Store, c *carlosop.Client, h *http.Cl
if err != nil {
return err
}
- if err := Delivered(base.Delivery, fresh.Delivery); err != nil {
+ if err := Delivered(app, base.Delivery, fresh.Delivery); err != nil {
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 code := ReviewedRelease(fresh.Delivery, artifact); code != "" {
+ return errors.New("adopt: check-" + code)
}
if codes := SameIdentity(after.Identity, fresh.Identity); len(codes) > 0 {
for i, code := range codes {
@@ -95,6 +98,21 @@ func CheckDelivery(ctx context.Context, s *Store, c *carlosop.Client, h *http.Cl
})
}
+// ReviewedRelease is "" when d serves the reviewed release: artifact is
+// 64 lowercase hex (artifact-unreviewed otherwise) and the SHA-256 of
+// d's X-Carlos-Version is artifact (artifact-mismatch otherwise). It is
+// the one comparison of a served release with the config's artifacts.
+func ReviewedRelease(d Delivery, artifact string) string {
+ if !artifactShape.MatchString(artifact) {
+ return "artifact-unreviewed"
+ }
+ sum := sha256.Sum256([]byte(d.Header))
+ if hex.EncodeToString(sum[:]) != artifact {
+ return "artifact-mismatch"
+ }
+ return ""
+}
+
// sameConfig lists, sorted, how b's config differs from a's, with key
// and layer names only: added:<KEY>, gone:<KEY>, kind:<KEY>,
// changed:<KEY> (digest) and from:<KEY> (source layer) over both the
diff --git a/adopt/gate_adverse_test.go b/adopt/gate_adverse_test.go
index 50f3474..013768d 100644
--- a/adopt/gate_adverse_test.go
+++ b/adopt/gate_adverse_test.go
@@ -227,7 +227,7 @@ func (g *gate) fixture(slug string, before ...func(*writeFixture)) *observerFixt
fastPolls(t, 5*time.Millisecond, 2*time.Second)
w.process(false)
ctx := context.Background()
- if _, err := WriteAgentKeys(ctx, w.c, w.h, w.s, w.app, g.team, true); err != nil {
+ if _, err := WriteAgentKeys(ctx, w.c, w.h, w.s, w.app, g.team, sha256Hex(w.site.header), true); err != nil {
t.Fatalf("WriteAgentKeys: %v", err)
}
g.finish(w)
@@ -240,7 +240,7 @@ func (g *gate) finish(w *writeFixture) {
g.t.Helper()
ctx := context.Background()
base := w.baseline(g.t)
- if _, err := RestartAndWait(ctx, w.c, w.h, w.app, base.Identity, func(d Delivery) error { return Delivered(base.Delivery, d) }, true); err != nil {
+ if _, err := RestartAndWait(ctx, w.c, w.h, w.app, base.Identity, func(d Delivery) error { return Delivered(w.app, base.Delivery, d) }, true); err != nil {
g.t.Fatalf("RestartAndWait: %v", err)
}
if _, err := CaptureAfter(ctx, w.c, w.h, w.s, w.app); err != nil {
@@ -590,7 +590,7 @@ func TestAdverseMalformedReceipts(t *testing.T) {
fastPolls(t, 5*time.Millisecond, 2*time.Second)
w.process(false)
w.putRewriter(t, edit(w.app.Prefix))
- if _, err := WriteAgentKeys(context.Background(), w.c, w.h, w.s, w.app, g.team, true); !errors.Is(err, ErrStopConflict) {
+ if _, err := WriteAgentKeys(context.Background(), w.c, w.h, w.s, w.app, g.team, sha256Hex(w.site.header), true); !errors.Is(err, ErrStopConflict) {
t.Fatalf("err = %v, want ErrStopConflict", err)
}
rec, ok := w.writeRecord(t)
diff --git a/adopt/observer.go b/adopt/observer.go
index 27dc77d..68db52f 100644
--- a/adopt/observer.go
+++ b/adopt/observer.go
@@ -147,7 +147,7 @@ func (o *Observer) Observe(ctx context.Context, app, teamSQID string) (provision
add("delivery-check-superseded")
}
d := fresh.Delivery
- if Delivered(ev.base.Delivery, d) != nil {
+ if Delivered(a, ev.base.Delivery, d) != nil {
add("not-delivered")
}
if d.Version != d.Header {
diff --git a/adopt/rehearsal_test.go b/adopt/rehearsal_test.go
index 1050776..c5fe9d0 100644
--- a/adopt/rehearsal_test.go
+++ b/adopt/rehearsal_test.go
@@ -256,11 +256,14 @@ func (r *rehearsal) site(w http.ResponseWriter, req *http.Request) {
case "/healthz":
w.WriteHeader(http.StatusOK)
case "/api/v1/operations":
- if !r.serving(slug) {
+ switch a, _ := provision.AppBySlug(slug); {
+ case r.serving(slug):
+ agent401(w)
+ case BaselineOps(a) == OpsApp401:
+ app401(w)
+ default:
http.NotFound(w, req)
- return
}
- agent401(w)
default:
http.NotFound(w, req)
}
@@ -633,7 +636,7 @@ func (r *rehearsal) checkBaselines() {
// the after snapshot is already taken, the restart until delivered and
// 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 {
+ if _, err := WriteAgentKeys(ctx, c, h, js, a, sqid, sha256Hex(valueVersion), true); err != nil {
return err
}
if _, ok, err := js.After(ctx, a.Slug); err != nil {
@@ -643,7 +646,7 @@ func configureApp(ctx context.Context, c *carlosop.Client, h *http.Client, js *S
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 _, err := RestartAndWait(ctx, c, h, a, base.Identity, func(d Delivery) error { return Delivered(a, base.Delivery, d) }, true); err != nil {
return err
}
if _, err := CaptureAfter(ctx, c, h, js, a); err != nil {
diff --git a/adopt/restart_test.go b/adopt/restart_test.go
index 13582bc..40dc388 100644
--- a/adopt/restart_test.go
+++ b/adopt/restart_test.go
@@ -266,7 +266,7 @@ func TestRestartAndWaitTimesOut(t *testing.T) {
id := x.identity(t)
before := x.site.delivery(t, x)
// The operations door never becomes agent-shaped.
- until := func(d Delivery) error { return Delivered(before, d) }
+ until := func(d Delivery) error { return Delivered(x.app, before, d) }
start := time.Now()
_, err := RestartAndWait(context.Background(), x.c, x.h, x.app, id, until, true)
if err == nil || !strings.Contains(err.Error(), "restart-timeout") {
diff --git a/adopt/snapshot.go b/adopt/snapshot.go
index c57d52e..43a8cc1 100644
--- a/adopt/snapshot.go
+++ b/adopt/snapshot.go
@@ -205,7 +205,12 @@ func inherits(eff carlosop.Effective, writeLayer string, keys [2]string) bool {
// write layer whose digest is EnvDigest(mine[key]) (the journal's own
// sent values, on a resume);
// - inherits-<host>, for every other instance a write would reach;
-// - version-header-mismatch, healthz.
+// - version-header-mismatch, healthz;
+// - operations-<shape>, unless the operations door answers as
+// BaselineOps(app) says, or, on a resume, both agent keys are the
+// journal's own (as above) and the door gives agent-access's answer:
+// a baseline Delivered could never move on is refused before it is
+// journalled.
//
// An error is a read that failed; it is not a refusal to guess past.
func Preflight(ctx context.Context, c *carlosop.Client, h *http.Client, app provision.App, mine map[string]string) (Snapshot, []string, error) {
@@ -233,14 +238,17 @@ func Preflight(ctx context.Context, c *carlosop.Client, h *http.Client, app prov
add("team-mode-" + k)
}
keys := AgentKeys(app)
+ bothOurs := true
for _, k := range keys {
v := findVar(snap.Vars, k)
if v == nil {
+ bothOurs = false
continue
}
ours := mine[k] != "" && v.Kind == "env" && v.From == layerName(snap.WriteLayer) && v.Digest == carlosop.EnvDigest(mine[k])
if !ours {
add("agent-keys-present")
+ bothOurs = false
break
}
}
@@ -263,6 +271,9 @@ func Preflight(ctx context.Context, c *carlosop.Client, h *http.Client, app prov
if d.Health != http.StatusOK {
add("healthz")
}
+ if d.Ops != BaselineOps(app) && !(bothOurs && d.Ops.agentShaped()) {
+ add("operations-" + string(d.Ops))
+ }
return snap, sortedSet(codes), nil
}
diff --git a/adopt/snapshot_test.go b/adopt/snapshot_test.go
index f1a3e06..d4a0bba 100644
--- a/adopt/snapshot_test.go
+++ b/adopt/snapshot_test.go
@@ -68,6 +68,9 @@ func newCarlosFixture(t *testing.T, slug string) *carlosFixture {
t.Cleanup(c.Close)
s := &site{version: valueVersion, header: valueVersion, health: 200}
+ if BaselineOps(app) == OpsApp401 {
+ s.ops = app401
+ }
srv := httptest.NewTLSServer(s.handler())
t.Cleanup(srv.Close)
tr := srv.Client().Transport.(*http.Transport).Clone()
@@ -300,7 +303,7 @@ func TestPreflightRefusesEachConfigCode(t *testing.T) {
"version-redirect": {func(x *carlosFixture) { x.site.redirectVersion = true }, []string{"version-header-mismatch"}},
"ops-redirect": {func(x *carlosFixture) {
x.site.ops = func(w http.ResponseWriter) { w.Header().Set("Location", "/elsewhere"); w.WriteHeader(http.StatusFound) }
- }, []string{"version-header-mismatch"}},
+ }, []string{"operations-other", "version-header-mismatch"}},
"healthz": {func(x *carlosFixture) { x.site.health = 503 }, []string{"healthz"}},
}
for name, c := range cases {
@@ -315,6 +318,58 @@ func TestPreflightRefusesEachConfigCode(t *testing.T) {
}
}
+// A baseline Delivered could never move on is refused before anything is
+// journalled: each app's operations door must answer as BaselineOps says.
+func TestPreflightRefusesUnsupportedOperationsBaseline(t *testing.T) {
+ cases := []struct {
+ app string
+ ops func(w http.ResponseWriter)
+ want string // "" passes
+ }{
+ {"docs", nil, ""},
+ {"docs", app401, "operations-app-401"},
+ {"docs", func(w http.ResponseWriter) { w.WriteHeader(500) }, "operations-other"},
+ {"docs", agent200(`{"user":"x"}`), "operations-other"},
+ {"docs", agent401, "operations-agent-401"},
+ {"slides", app401, ""},
+ {"slides", nil, "operations-absent"},
+ {"calls", agent401, "operations-agent-401"},
+ {"calls", app401, ""},
+ }
+ for _, c := range cases {
+ x := newCarlosFixture(t, c.app)
+ x.site.ops = c.ops
+ _, codes := x.preflight(t, nil)
+ if c.want == "" {
+ wantCodes(t, codes)
+ continue
+ }
+ wantCodes(t, codes, c.want)
+ }
+}
+
+// On a resume, the journal's own keys stored and the door already giving
+// agent-access's answer (a restart came between) is not a refusal: an
+// already-sent write stays recoverable. The keys of anyone else are.
+func TestPreflightAdmitsAgentDoorBehindOwnKeysOnResume(t *testing.T) {
+ x := newCarlosFixture(t, "slides")
+ keys := AgentKeys(x.app)
+ mine := map[string]string{keys[0]: Issuer, keys[1]: fixtureSQID}
+ for k, v := range mine {
+ x.f.SetVar("slides", "", k, v)
+ }
+ x.site.ops = agent401
+ _, codes := x.preflight(t, mine)
+ wantCodes(t, codes)
+ // Not ours: refused, the door with it.
+ _, codes = x.preflight(t, nil)
+ wantCodes(t, codes, "agent-keys-present", "operations-agent-401")
+ // Ours, but the door a lookalike: refused.
+ x.site.ops = agent200(`{}`)
+ _, codes = x.preflight(t, mine)
+ wantCodes(t, codes, "operations-other")
+}
+
func TestPreflightErrorsOnUnreadableNeighbour(t *testing.T) {
x := newCarlosFixture(t, "docs")
// Bound to an environment that was never created: the console answers
diff --git a/adopt/store.go b/adopt/store.go
index 7672aa9..7d46216 100644
--- a/adopt/store.go
+++ b/adopt/store.go
@@ -89,7 +89,9 @@ const (
// 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.
+ // is no longer written or read. Both stay, by name, for compatibility:
+ // the production state already holds them, and a rename or drop is
+ // not an additive migration.
tWitnesses = "adopt_witnesses"
)
diff --git a/adopt/write.go b/adopt/write.go
index eeeb5a4..8939f49 100644
--- a/adopt/write.go
+++ b/adopt/write.go
@@ -297,7 +297,9 @@ func unsetReceiptOK(rc carlosop.Receipt, keys [2]string) bool {
// 1. A landed write is done: nothing is read or sent. A stopped one is
// refused again. Once a rollback is journalled, configure refuses.
// 2. Preflight runs on a fresh read, with mine set to the journal's sent
-// values; any code refuses it, with nothing written.
+// values, and the served release must be the reviewed one, artifact
+// (ReviewedRelease's codes); any code refuses it, with nothing
+// written.
// 3. The baseline comes from the journal, or is this preflight's
// snapshot, sealed and stored. A journalled baseline that no longer
// describes the host's identity or write layer refuses the write.
@@ -318,7 +320,7 @@ func unsetReceiptOK(rc carlosop.Receipt, keys [2]string) bool {
// A console that refuses if_version (carlosop.ErrNoConditional) stops the
// run with the record left at sent, code no-conditional. Without apply,
// it reads and refuses as it would, and stores and sends nothing.
-func WriteAgentKeys(ctx context.Context, c *carlosop.Client, h *http.Client, s *Store, app provision.App, sqid string, apply bool) (string, error) {
+func WriteAgentKeys(ctx context.Context, c *carlosop.Client, h *http.Client, s *Store, app provision.App, sqid, artifact string, apply bool) (string, error) {
switch {
case c == nil || h == nil || s == nil:
return "", errors.New("adopt: configure needs a console, a client and the journal")
@@ -366,7 +368,7 @@ func WriteAgentKeys(ctx context.Context, c *carlosop.Client, h *http.Client, s *
if ok {
against = &base
}
- fresh, codes, err := admit(ctx, c, h, app, mine, against)
+ fresh, codes, err := admit(ctx, c, h, app, mine, against, artifact)
if err != nil {
return "", err
}
@@ -449,7 +451,7 @@ func WriteAgentKeys(ctx context.Context, c *carlosop.Client, h *http.Client, s *
// Whatever moved the layer may be a refusal of its own (a
// team-mode key, a neighbour that would inherit): every preflight
// refusal is enforced again, on a fresh read, before the retry.
- fresh, codes, err := admit(ctx, c, h, app, nil, &base)
+ fresh, codes, err := admit(ctx, c, h, app, nil, &base, artifact)
if err != nil {
return "", err
}
@@ -476,13 +478,20 @@ func WriteAgentKeys(ctx context.Context, c *carlosop.Client, h *http.Client, s *
// admit runs Preflight on a fresh read and, given the journalled
// baseline, adds write-layer-moved when the write layer is no longer the
// baseline's and identity-<code> for each way the instance differs from
-// it. Any code refuses a write. Before a retry, mine is nil: the agent
-// keys were just read absent, so a present one is another writer's.
-func admit(ctx context.Context, c *carlosop.Client, h *http.Client, app provision.App, mine map[string]string, base *Snapshot) (Snapshot, []string, error) {
+// it, and ReviewedRelease's code when the served release is not
+// artifact. Any code refuses a write. Before a retry, mine is nil: the
+// agent keys were just read absent, so a present one is another writer's.
+func admit(ctx context.Context, c *carlosop.Client, h *http.Client, app provision.App, mine map[string]string, base *Snapshot, artifact string) (Snapshot, []string, error) {
fresh, codes, err := Preflight(ctx, c, h, app, mine)
- if err != nil || len(codes) > 0 || base == nil {
+ if err != nil {
return fresh, codes, err
}
+ if code := ReviewedRelease(fresh.Delivery, artifact); code != "" {
+ codes = sortedSet(append(codes, code))
+ }
+ if len(codes) > 0 || base == nil {
+ return fresh, codes, nil
+ }
if base.WriteLayer != fresh.WriteLayer || base.Layer.Bundle != fresh.Layer.Bundle {
codes = append(codes, "write-layer-moved")
}
@@ -542,7 +551,7 @@ func CaptureAfter(ctx context.Context, c *carlosop.Client, h *http.Client, s *St
if len(codes) > 0 {
return Snapshot{}, fmt.Errorf("%w: %s", ErrStopPreserved, strings.Join(sortedSet(codes), ", "))
}
- if err := Delivered(base.Delivery, after.Delivery); err != nil {
+ if err := Delivered(app, base.Delivery, after.Delivery); err != nil {
return Snapshot{}, fmt.Errorf("adopt: after-not-delivered: %w", err)
}
if err := s.SaveAfter(ctx, app.Slug, after); err != nil {
diff --git a/adopt/write_test.go b/adopt/write_test.go
index d0574d6..ade0183 100644
--- a/adopt/write_test.go
+++ b/adopt/write_test.go
@@ -34,7 +34,7 @@ func newWriteFixture(t *testing.T, slug string) *writeFixture {
}
func (w *writeFixture) configure(apply bool) (string, error) {
- return WriteAgentKeys(context.Background(), w.c, w.h, w.s, w.app, fixtureSQID, apply)
+ return WriteAgentKeys(context.Background(), w.c, w.h, w.s, w.app, fixtureSQID, sha256Hex(w.site.header), apply)
}
func (w *writeFixture) rollback(apply bool) error {
@@ -146,11 +146,14 @@ func (x *carlosFixture) process(loaded bool) {
}
on := loaded
mu.Unlock()
- if on {
+ switch {
+ case on:
agent401(w)
- return
+ case BaselineOps(x.app) == OpsApp401:
+ app401(w)
+ default:
+ w.WriteHeader(http.StatusNotFound)
}
- w.WriteHeader(http.StatusNotFound)
}
}
@@ -165,7 +168,7 @@ func (w *writeFixture) configured(t *testing.T) Snapshot {
}
base := w.baseline(t)
ctx := context.Background()
- if _, err := RestartAndWait(ctx, w.c, w.h, w.app, base.Identity, func(d Delivery) error { return Delivered(base.Delivery, d) }, true); err != nil {
+ if _, err := RestartAndWait(ctx, w.c, w.h, w.app, base.Identity, func(d Delivery) error { return Delivered(w.app, base.Delivery, d) }, true); err != nil {
t.Fatalf("RestartAndWait: %v", err)
}
after, err := CaptureAfter(ctx, w.c, w.h, w.s, w.app)
@@ -292,7 +295,7 @@ func TestConfigureRefusesInheritingNeighbour(t *testing.T) {
func TestConfigureRefusesBadTeam(t *testing.T) {
w := newWriteFixture(t, "docs")
for _, sqid := range []string{"", " tQx7kPa", "t-1", "tQx7kPa\n"} {
- if _, err := WriteAgentKeys(context.Background(), w.c, w.h, w.s, w.app, sqid, true); err == nil {
+ if _, err := WriteAgentKeys(context.Background(), w.c, w.h, w.s, w.app, sqid, sha256Hex(w.site.header), true); err == nil {
t.Fatalf("sqid %q accepted", sqid)
}
}
@@ -341,7 +344,7 @@ func TestWriteHappyPathReceiptChecked(t *testing.T) {
t.Fatalf("a landed write made %d more requests", got-n)
}
// A call naming another team never rides on the landed record.
- if _, err := WriteAgentKeys(context.Background(), w.c, w.h, w.s, w.app, "tOther9", true); err == nil {
+ if _, err := WriteAgentKeys(context.Background(), w.c, w.h, w.s, w.app, "tOther9", sha256Hex(w.site.header), true); err == nil {
t.Fatal("a landed write accepted another team")
}
}
@@ -423,6 +426,50 @@ func TestWriteResumeAfterCrashFindsLanded(t *testing.T) {
}
}
+// The reviewed release is checked before anything is written or
+// journalled, with --apply and without.
+func TestWriteRefusesUnreviewedReleaseBeforeWriting(t *testing.T) {
+ for name, artifact := range map[string]string{
+ "artifact-unreviewed": "",
+ "artifact-mismatch": sha256Hex("v1.3.9"),
+ } {
+ for _, apply := range []bool{false, true} {
+ w := newWriteFixture(t, "docs")
+ _, err := WriteAgentKeys(context.Background(), w.c, w.h, w.s, w.app, fixtureSQID, artifact, apply)
+ if err == nil || err.Error() != "adopt: configure refused: "+name {
+ t.Fatalf("%s apply %v: err = %v", name, apply, err)
+ }
+ w.nothingWritten(t)
+ }
+ }
+ // The release moved under a sent write: the resume refuses to send
+ // again.
+ w := newWriteFixture(t, "docs")
+ ctx := context.Background()
+ base, err := Observe(ctx, w.c, w.h, w.app)
+ setupOK(t, err)
+ setupOK(t, w.s.SaveBaseline(ctx, "docs", base))
+ setupOK(t, w.s.SaveWrite(ctx, WriteRecord{App: "docs", State: "sent", Sent: w.sent()}))
+ w.site.version, w.site.header = "v1.5.0", "v1.5.0"
+ if _, err := WriteAgentKeys(ctx, w.c, w.h, w.s, w.app, fixtureSQID, sha256Hex(valueVersion), true); err == nil || !strings.Contains(err.Error(), "artifact-mismatch") {
+ t.Fatalf("resume on another release: err = %v", err)
+ }
+ if n := w.puts(); n != 0 {
+ t.Fatalf("%d PUTs", n)
+ }
+}
+
+// An app whose door answers something Delivered could never move on is
+// refused before its baseline is journalled.
+func TestWriteRefusesUnsupportedOperationsBaseline(t *testing.T) {
+ w := newWriteFixture(t, "docs")
+ w.site.ops = func(rw http.ResponseWriter) { rw.WriteHeader(500) }
+ if _, err := w.configure(true); err == nil || !strings.Contains(err.Error(), "operations-other") {
+ t.Fatalf("err = %v", err)
+ }
+ w.nothingWritten(t)
+}
+
func TestWriteRetriesAfterUnrelatedKeyAdded(t *testing.T) {
w := newWriteFixture(t, "docs")
_, beforeVersion, _ := w.f.Layer("docs", "")
@@ -1027,7 +1074,7 @@ func TestAfterSnapshotRefusesSecretResealedBeforeCapture(t *testing.T) {
}
base := w.baseline(t)
ctx := context.Background()
- if _, err := RestartAndWait(ctx, w.c, w.h, w.app, base.Identity, func(d Delivery) error { return Delivered(base.Delivery, d) }, true); err != nil {
+ if _, err := RestartAndWait(ctx, w.c, w.h, w.app, base.Identity, func(d Delivery) error { return Delivered(w.app, base.Delivery, d) }, true); err != nil {
t.Fatalf("RestartAndWait: %v", err)
}
edit(w)
@@ -1067,7 +1114,7 @@ func TestAfterSnapshotAcceptsUnrelatedNewKey(t *testing.T) {
}
base := w.baseline(t)
ctx := context.Background()
- if _, err := RestartAndWait(ctx, w.c, w.h, w.app, base.Identity, func(d Delivery) error { return Delivered(base.Delivery, d) }, true); err != nil {
+ if _, err := RestartAndWait(ctx, w.c, w.h, w.app, base.Identity, func(d Delivery) error { return Delivered(w.app, base.Delivery, d) }, true); err != nil {
t.Fatal(err)
}
w.f.PlatformWrite("docs", "", "DOCS_MAIL_EVENTS_URL", "https://mail.example/hook")
diff --git a/cmd/alta-adopt/main.go b/cmd/alta-adopt/main.go
index f86308f..69277d7 100644
--- a/cmd/alta-adopt/main.go
+++ b/cmd/alta-adopt/main.go
@@ -461,10 +461,13 @@ func (r *runner) preflight(ctx context.Context) error {
} else if ok {
mine = w.Sent
}
- _, codes, err := adopt.Preflight(ctx, c, r.public, a, mine)
+ snap, codes, err := adopt.Preflight(ctx, c, r.public, a, mine)
if err != nil {
return err
}
+ if code := adopt.ReviewedRelease(snap.Delivery, r.cfg.artifacts[a.Slug]); code != "" {
+ codes = append(codes, code)
+ }
refused = refused || len(codes) > 0
r.say(adopt.SayActivateApp(a.Slug, codes))
}
@@ -648,7 +651,7 @@ func (r *runner) configure(ctx context.Context) error {
if err != nil {
return err
}
- summary, err := adopt.WriteAgentKeys(ctx, c, r.public, r.js, a, sqid, r.o.apply)
+ summary, err := adopt.WriteAgentKeys(ctx, c, r.public, r.js, a, sqid, r.cfg.artifacts[a.Slug], r.o.apply)
if err != nil {
return err
}
@@ -677,7 +680,7 @@ func (r *runner) configure(ctx context.Context) error {
if !ok {
return errors.New("adopt: " + adopt.RefuseNoJournalBase)
}
- until := func(d adopt.Delivery) error { return adopt.Delivered(base.Delivery, d) }
+ until := func(d adopt.Delivery) error { return adopt.Delivered(a, base.Delivery, d) }
if _, err := adopt.RestartAndWait(ctx, c, r.public, a, base.Identity, until, true); err != nil {
return err
}
diff --git a/cmd/alta-adopt/main_test.go b/cmd/alta-adopt/main_test.go
index 73ce23c..0401a23 100644
--- a/cmd/alta-adopt/main_test.go
+++ b/cmd/alta-adopt/main_test.go
@@ -196,6 +196,13 @@ func (r *rig) site(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
case "/api/v1/operations":
if !r.serving(slug) {
+ // Slides and Calls answer their own middleware's 401 before
+ // adoption; the others have no such route.
+ if a, _ := provision.AppBySlug(slug); adopt.BaselineOps(a) == adopt.OpsApp401 {
+ w.WriteHeader(http.StatusUnauthorized)
+ _, _ = io.WriteString(w, `{"error":"unauthorized"}`)
+ return
+ }
http.NotFound(w, req)
return
}
@@ -815,17 +822,26 @@ func TestConfigureResumesDeliveryCheck(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) {
+// A served release that is not the reviewed one is refused before
+// anything is written (Astra review, 2026-11-17): by preflight, by
+// configure's dry run and by configure itself, which journals and sends
+// nothing. Activation stays refused.
+func TestConfigureRefusesUnreviewedReleaseBeforeWriting(t *testing.T) {
t.Parallel()
r := newRig(t)
r.throughPlanA()
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 out := r.refused("preflight-refused", "", true, "preflight"); !strings.Contains(out, adopt.SayActivateApp(adopt.CanaryApp, []string{"artifact-mismatch"})) {
+ t.Fatalf("preflight did not name the release\n%s", out)
+ }
+ before := r.writes()
+ r.refused("artifact-mismatch", "", true, "configure", "--app", adopt.CanaryApp)
+ r.refused("artifact-mismatch", "", true, "configure", "--app", adopt.CanaryApp, "--apply")
+ if after := r.writes(); after != before {
+ t.Fatalf("a refused configure wrote: %+v %+v", before, after)
+ }
if r.checked(adopt.CanaryApp) {
t.Fatal("a delivery check was recorded for an unreviewed release")
}