Accept a describe body with its commit-id X-Carlos-Version
Four of the six production apps serve the same build named two ways: /api/version answers the git-describe name (v0.1.0-53-gef9c313) and X-Carlos-Version the commit id (ef9c313). The preflight and the activation gate refused them with version-header-mismatch. adopt.SameRelease implements the controller ruling of 2026-11-17: the body and header agree when equal, or when the body is v<maj>.<min>.<patch>-<n>-g<hex>, the header is lowercase hex, and one hex is a prefix of the other with at least 7 digits in common. Both guards (Preflight, Observer) use it. The artifact rule is unchanged: SHA-256 of the header. app_version is still the body. Tests: all six production pairs pass SameRelease, the preflight and the full observer path; lookalikes (other hex, six digits, uppercase, non-hex, dirty or other describe, non-describe body) are refused at both guards. homecompat now activates each app at Home's real operator code with its production body as app_version and checks the recorded value.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+215
−12
adopt/observer.go+4 −3adopt/release.go+33 −0adopt/release_test.go+150 −0adopt/snapshot.go+1 −1homecompat/adopt_flow_test.go+27 −8
CI passed — run details
CI log
=== vet === go vet ./... === fmt === === test === CGO_ENABLED=0 go test ./... ok amadan.net/oficina/alta/adopt 16.575s ok amadan.net/oficina/alta/carlosop 0.039s ? amadan.net/oficina/alta/carlosop/fakecarlos [no test files] ok amadan.net/oficina/alta/cmd/alta 0.168s ok amadan.net/oficina/alta/cmd/alta-adopt 26.817s 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.046s ok amadan.net/oficina/alta/internal/web 0.115s ok amadan.net/oficina/alta/provision 11.435s === compat === cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./... ok amadan.net/oficina/home/altacompat 0.548s
diff --git a/adopt/observer.go b/adopt/observer.go| index 68db52f..3cdb092 100644 |
| --- a/adopt/observer.go |
| +++ b/adopt/observer.go |
| @@ -89,8 +89,9 @@ func (o *Observer) now() time.Time { |
| // write layer's, and its delivered version and header are the fresh |
| // ones (delivery-check-superseded). There is no wall-clock limit; |
| // - delivery: the fresh probe passes Delivered against the baseline |
| -// (not-delivered), the version body equals X-Carlos-Version |
| -// (version-header-mismatch) and Home admits it |
| +// (not-delivered), the version body and X-Carlos-Version name the |
| +// same release, SameRelease (version-header-mismatch), and Home |
| +// admits the body |
| // (version-unacceptable); |
| // - artifact: the SHA-256 of the served release name (X-Carlos-Version) |
| // is the reviewed one (artifact-mismatch). |
| @@ -150,7 +151,7 @@ func (o *Observer) Observe(ctx context.Context, app, teamSQID string) (provision |
| if Delivered(a, ev.base.Delivery, d) != nil { |
| add("not-delivered") |
| } |
| - if d.Version != d.Header { |
| + if !SameRelease(d.Version, d.Header) { |
| add("version-header-mismatch") |
| } |
| if !appVersion.MatchString(d.Version) { |
diff --git a/adopt/release.go b/adopt/release.go| new file mode 100644 |
| index 0000000..5e4bcb9 |
| --- /dev/null |
| +++ b/adopt/release.go |
| @@ -0,0 +1,33 @@ |
| +package adopt |
| + |
| +import ( |
| + "regexp" |
| + "strings" |
| +) |
| + |
| +// describeName is a `git describe --tags` name of an untagged commit, |
| +// v<maj>.<min>.<patch>-<n>-g<hex>, capturing the commit's hex. Git writes |
| +// it lowercase; so must the app. |
| +var describeName = regexp.MustCompile(`^v(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)-(?:0|[1-9][0-9]*)-g([0-9a-f]{7,64})$`) |
| + |
| +// commitID is a commit id, full or abbreviated to at least 7 lowercase hex. |
| +var commitID = regexp.MustCompile(`^[0-9a-f]{7,64}$`) |
| + |
| +// SameRelease says the /api/version body and X-Carlos-Version name the |
| +// same release (controller ruling, 2026-11-17). They do when they are |
| +// equal, or when the body is a describe name, the header a commit id, and |
| +// one hex is a prefix of the other: both are at least 7 digits, so at |
| +// least 7 are in common. Production serves both forms (Sheets: body |
| +// v0.1.0-53-gef9c313, header ef9c313). Anything else is |
| +// version-header-mismatch. Only the header is the served release name the |
| +// artifact hashes; the body is what Home is sent as app_version. |
| +func SameRelease(body, header string) bool { |
| + if body == header { |
| + return true |
| + } |
| + m := describeName.FindStringSubmatch(body) |
| + if m == nil || !commitID.MatchString(header) { |
| + return false |
| + } |
| + return strings.HasPrefix(m[1], header) || strings.HasPrefix(header, m[1]) |
| +} |
diff --git a/adopt/release_test.go b/adopt/release_test.go| new file mode 100644 |
| index 0000000..328d2ec |
| --- /dev/null |
| +++ b/adopt/release_test.go |
| @@ -0,0 +1,150 @@ |
| +package adopt |
| + |
| +import ( |
| + "crypto/sha256" |
| + "encoding/base64" |
| + "testing" |
| +) |
| + |
| +// productionVersions is what each app served in production on |
| +// 2026-11-17: the /api/version body and X-Carlos-Version, the same build |
| +// named two ways by four of the six. |
| +var productionVersions = map[string]struct{ body, header string }{ |
| + "docs": {"v0.1.0-80-g9de84e4", "v0.1.0-80-g9de84e4"}, |
| + "sheets": {"v0.1.0-53-gef9c313", "ef9c313"}, |
| + "slides": {"v0.1.0-42-gcb30df5", "cb30df5"}, |
| + "calendar": {"v0.1.0-53-g800406a", "800406a"}, |
| + "calls": {"ef2335e9df94bf9be1561fcbb1335c87e7c6e4ca", "ef2335e9df94bf9be1561fcbb1335c87e7c6e4ca"}, |
| + "memoria": {"v0.1.0-47-g174fb45", "174fb45"}, |
| +} |
| + |
| +func TestSameReleaseAcceptsProductionPairs(t *testing.T) { |
| + for app, v := range productionVersions { |
| + if !SameRelease(v.body, v.header) { |
| + t.Errorf("%s: body %q and header %q refused", app, v.body, v.header) |
| + } |
| + } |
| +} |
| + |
| +func TestSameRelease(t *testing.T) { |
| + full := "ef2335e9df94bf9be1561fcbb1335c87e7c6e4ca" |
| + cases := []struct { |
| + name, body, header string |
| + want bool |
| + }{ |
| + {"equal names", "v1.4.0", "v1.4.0", true}, |
| + {"equal commit ids", full, full, true}, |
| + {"describe, short header", "v0.1.0-53-gef9c313", "ef9c313", true}, |
| + {"describe, full header", "v0.1.0-53-gef2335e", full, true}, |
| + {"describe, longer abbreviation than header", "v0.1.0-53-gef2335e9df94", "ef2335e9", true}, |
| + {"describe, many-digit parts", "v12.40.3-1207-g800406a", "800406a", true}, |
| + |
| + {"different hex", "v0.1.0-53-gef9c313", "ef9c314", false}, |
| + {"different first digit", "v0.1.0-53-gef9c313", "af9c313", false}, |
| + {"header of six hex digits", "v0.1.0-53-gef9c313", "ef9c31", false}, |
| + {"describe of six hex digits", "v0.1.0-53-gef9c31", "ef9c313", false}, |
| + {"six in common, both longer", "v0.1.0-53-gef9c31a", "ef9c31b", false}, |
| + {"non-describe body, short header", "v1.4.0", "ef9c313", false}, |
| + {"bare-commit body, its own prefix as header", full, "ef2335e", false}, |
| + {"build-name body, short header", "rel-ef9c313", "ef9c313", false}, |
| + {"header not hex", "v0.1.0-53-gef9c313", "ef9c31z", false}, |
| + {"header a dirty describe", "v0.1.0-53-gef9c313", "v0.1.0-53-gef9c313-dirty", false}, |
| + {"header a tag", "v0.1.0-53-gef9c313", "v0.1.0", false}, |
| + {"body describes another commit", "v0.1.0-53-gcb30df5", "ef9c313", false}, |
| + {"uppercase header", "v0.1.0-53-gef9c313", "EF9C313", false}, |
| + {"uppercase describe hex", "v0.1.0-53-gEF9C313", "ef9c313", false}, |
| + {"dirty describe", "v0.1.0-53-gef9c313-dirty", "ef9c313", false}, |
| + {"describe without v", "0.1.0-53-gef9c313", "ef9c313", false}, |
| + {"describe without count", "v0.1.0-gef9c313", "ef9c313", false}, |
| + {"describe of a two-part tag", "v0.1-53-gef9c313", "ef9c313", false}, |
| + {"describe with a pre-release tag", "v0.1.0-rc1-53-gef9c313", "ef9c313", false}, |
| + {"describe with a newline", "v0.1.0-53-gef9c313\n", "ef9c313", false}, |
| + {"header with a newline", "v0.1.0-53-gef9c313", "ef9c313\n", false}, |
| + {"header with a space", "v0.1.0-53-gef9c313", " ef9c313", false}, |
| + {"empty header", "v0.1.0-53-gef9c313", "", false}, |
| + {"empty body", "", "ef9c313", false}, |
| + {"names swapped", "ef9c313", "v0.1.0-53-gef9c313", false}, |
| + {"different names", "v1.4.0", "v1.4.1", false}, |
| + } |
| + for _, c := range cases { |
| + t.Run(c.name, func(t *testing.T) { |
| + if got := SameRelease(c.body, c.header); got != c.want { |
| + t.Fatalf("SameRelease(%q, %q) = %v, want %v", c.body, c.header, got, c.want) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// Each app serving its production names passes the CARLOS preflight, |
| +// configure, the delivery check and the activation gate, which sends the |
| +// body as app_version and hashes the header for artifact_digest. |
| +func TestObserverAcceptsProductionVersionNames(t *testing.T) { |
| + for app, v := range productionVersions { |
| + t.Run(app, func(t *testing.T) { |
| + x := newObserverFixture(t, app, func(w *writeFixture) { w.site.version, w.site.header = v.body, v.header }) |
| + if app != CanaryApp { |
| + canaryActive(t, x.s) |
| + } |
| + obs, err := x.observe() |
| + if err != nil { |
| + t.Fatalf("Observe: %v", err) |
| + } |
| + if obs.AppVersion != v.body { |
| + t.Fatalf("app_version = %q, want the body %q", obs.AppVersion, v.body) |
| + } |
| + sum := sha256.Sum256([]byte(v.header)) |
| + if obs.ArtifactDigest != base64.RawURLEncoding.EncodeToString(sum[:]) { |
| + t.Fatal("artifact_digest is not the SHA-256 of X-Carlos-Version") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestPreflightAcceptsProductionVersionNames(t *testing.T) { |
| + for app, v := range productionVersions { |
| + t.Run(app, func(t *testing.T) { |
| + x := newCarlosFixture(t, app) |
| + x.site.version, x.site.header = v.body, v.header |
| + _, codes := x.preflight(t, nil) |
| + wantCodes(t, codes) |
| + }) |
| + } |
| +} |
| + |
| +// A lookalike pair is refused at both guards: by the preflight before |
| +// anything is written, and by the activation gate when the app moved to |
| +// it afterwards (the journal rewritten to agree, so only the pair is |
| +// wrong). |
| +func TestLookalikeVersionNamesRefused(t *testing.T) { |
| + lookalikes := map[string]string{ |
| + "another commit": "ef9c314", |
| + "six hex digits": "ef9c31", |
| + "uppercase": "EF9C313", |
| + "not hex": "ef9c31g", |
| + "dirty describe": "v0.1.0-53-gef9c313-dirty", |
| + "other describe": "v0.1.0-54-gef9c313", |
| + "another app's": "cb30df5", |
| + "full id, other": "ef9c314" + "000000000000000000000000000000000", |
| + "seven, one off": "ef9c312", |
| + } |
| + const body = "v0.1.0-53-gef9c313" |
| + for name, header := range lookalikes { |
| + t.Run("preflight "+name, func(t *testing.T) { |
| + x := newCarlosFixture(t, "sheets") |
| + x.site.version, x.site.header = body, header |
| + _, codes := x.preflight(t, nil) |
| + wantCodes(t, codes, "version-header-mismatch") |
| + }) |
| + t.Run("gate "+name, func(t *testing.T) { |
| + x := newObserverFixture(t, "sheets") |
| + x.site.version, x.site.header = body, header |
| + x.o.Artifacts = map[string]string{"sheets": sha256Hex(header)} |
| + x.rejournal(t, func(e *evidence) { |
| + e.base.Delivery.Version, e.after.Delivery.Version, e.check.Delivery.Version = body, body, body |
| + e.base.Delivery.Header, e.after.Delivery.Header, e.check.Delivery.Header = header, header, header |
| + }) |
| + canaryActive(t, x.s) |
| + wantCodes(t, x.refused(t, "version-header-mismatch"), "version-header-mismatch") |
| + }) |
| + } |
| +} |
diff --git a/adopt/snapshot.go b/adopt/snapshot.go| index 43a8cc1..541662b 100644 |
| --- a/adopt/snapshot.go |
| +++ b/adopt/snapshot.go |
| @@ -265,7 +265,7 @@ func Preflight(ctx context.Context, c *carlosop.Client, h *http.Client, app prov |
| } |
| } |
| d := snap.Delivery |
| - if d.Redirected || d.Version == "" || d.Version != d.Header { |
| + if d.Redirected || d.Version == "" || !SameRelease(d.Version, d.Header) { |
| add("version-header-mismatch") |
| } |
| if d.Health != http.StatusOK { |
diff --git a/homecompat/adopt_flow_test.go b/homecompat/adopt_flow_test.go| index 25da8dd..2b069a8 100644 |
| --- a/homecompat/adopt_flow_test.go |
| +++ b/homecompat/adopt_flow_test.go |
| @@ -24,13 +24,23 @@ import ( |
| "amadan.net/oficina/home/internal/operator" |
| ) |
| -// served is the release name each canonical app serves. |
| -const served = "v1.4.0" |
| +// served is what each canonical app served in production on 2026-11-17: |
| +// the /api/version body and X-Carlos-Version, the same build named two |
| +// ways by four of the six. |
| +var served = map[string]struct{ body, header string }{ |
| + "docs": {"v0.1.0-80-g9de84e4", "v0.1.0-80-g9de84e4"}, |
| + "sheets": {"v0.1.0-53-gef9c313", "ef9c313"}, |
| + "slides": {"v0.1.0-42-gcb30df5", "cb30df5"}, |
| + "calendar": {"v0.1.0-53-g800406a", "800406a"}, |
| + "calls": {"ef2335e9df94bf9be1561fcbb1335c87e7c6e4ca", "ef2335e9df94bf9be1561fcbb1335c87e7c6e4ca"}, |
| + "memoria": {"v0.1.0-47-g174fb45", "174fb45"}, |
| +} |
| // observer stands in for the CARLOS half's activation gate: what it |
| -// answers is shaped as adopt.Observer answers it (the served version, |
| -// Alta's artifact digest of it, the binding over the team), so Home's real |
| -// activation checks meet the evidence they will meet in production. |
| +// answers is shaped as adopt.Observer answers it (the body as app_version |
| +// once adopt.SameRelease admits the pair, Alta's artifact digest of the |
| +// header, the binding over the team), so Home's real activation checks |
| +// meet the evidence they will meet in production. |
| type observer struct { |
| mu sync.Mutex |
| calls []string |
| @@ -40,12 +50,16 @@ func (o *observer) Observe(_ context.Context, app, team string) (provision.Obser |
| o.mu.Lock() |
| o.calls = append(o.calls, app) |
| o.mu.Unlock() |
| - sum := sha256.Sum256([]byte(served)) |
| + v, ok := served[app] |
| + if !ok || !adopt.SameRelease(v.body, v.header) { |
| + return provision.Observation{}, &adopt.Refusal{Codes: []string{"version-header-mismatch"}} |
| + } |
| + sum := sha256.Sum256([]byte(v.header)) |
| return provision.Observation{ |
| - AppVersion: served, |
| + AppVersion: v.body, |
| ArtifactDigest: base64.RawURLEncoding.EncodeToString(sum[:]), |
| EnvironmentBinding: adopt.EnvironmentBinding(adopt.BindingInput{ |
| - TeamSQID: team, Issuer: adopt.Issuer, ArtifactSHA256: hex.EncodeToString(sum[:]), Version: served, |
| + TeamSQID: team, Issuer: adopt.Issuer, ArtifactSHA256: hex.EncodeToString(sum[:]), Version: v.body, |
| }), |
| }, nil |
| } |
| @@ -199,6 +213,11 @@ func TestAdoptionFlowAgainstRealHome(t *testing.T) { |
| if err != nil || !ok || data["manifest_digest"] != before { |
| t.Fatalf("%s: register's manifest digest is not the unchanged one", a) |
| } |
| + // Home activated each app on its production /api/version body. |
| + data, ok, err = r.store.Done(ctx, provision.AdoptionLabel, a, provision.StepActivate) |
| + if err != nil || !ok || data["app_version"] != served[a].body { |
| + t.Fatalf("%s: activated with app_version %v, want %q", a, data["app_version"], served[a].body) |
| + } |
| } |
| // Alta's streams are Home's. |
| for _, role := range []string{"directory", "credential"} { |