carlos / platform Public

nearest-region follow-ups: the floor names its commit (#442); a sidecar at the home's code is a home create (#441)

#442: release consoles are built with -buildvcs=false, so the hostname
history's floor named no commit and roll-console.sh would refuse every
later flagship console roll. Builds now stamp the full commit with
-ldflags (version.Commit, read through version.Revision, falling back to
vcs.revision); make build and make build-console pass it, and
build-console refuses when git can't give one. console hosts-used
activate refuses a build that doesn't name a full commit before writing
anything (C13), and WriteHostsFloor refuses an empty commit. The README
release recipe builds the console with make build-console.

#441: the sidecar create door now normalises the home region's name to
the record's "" before validation, as the instance door has since #346.
A sidecar created with -region <home code> is stored at the home (the
region the home's boxes serve) and passes S4, which examines the home as
"". The instance door already normalised; the witness covers both doors.

Witnesses: the built console binary (release-shaped build, with and
without the stamped commit); activation refusals with nothing written;
sidecar and instance creates at the home code through the HTTP doors
after a real activation, lifetimes off and on. Census: no units changed;
envelopes ., internal/provision, internal/version re-pinned; the
record-write census re-digests WriteHostsFloor. Copy: C13, MK1 and the
README lines by delegated Luna pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 6bb0c1f25dca88a9744f36a57368ddf9c0908a20 parent bf55f29
19 files changed, +351 −47
  • Makefile +6 −1
  • README.md +3 −2
  • accounts_hostsused.go +1 −14
  • cmd/console/hostsused.go +1 −0
  • cmd/console/main_test.go +5 −1
  • cmd/console/servelock_test.go +66 −4
  • docs/superpowers/notes/census-proposal-nearest-region-followups.md +11 −0
  • docs/superpowers/notes/copy/nearest-region-never-reuse-b.md +18 −0
  • internal/console/apisidecars.go +8 −2
  • internal/console/hostsused_activate.go +25 −18
  • internal/console/hostsused_activate_test.go +45 −3
  • internal/console/hostsused_homecode_test.go +91 −0
  • internal/provision/hostsused.go +6 −1
  • internal/provision/hostsused_test.go +14 −0
  • internal/provision/nearest_region_a_census_test.go +2 −1
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-nearest-region-followups.tsv +5 −0
  • internal/version/version.go +26 −0
  • internal/version/version_test.go +17 −0

CI cancelled — superseded by a newer push — run details

diff --git a/Makefile b/Makefile
index 4ce396a77..279192e98 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,9 @@
SHA := $(shell git rev-parse --short HEAD 2>/dev/null || echo dev)
-LDFLAGS := -s -w -X github.com/carlosframework/platform/internal/version.Build=$(SHA)
+# COMMIT is the full commit, stamped beside the version: a console names it
+# in the hostname history's floor, and release builds from a linked
+# worktree (-buildvcs=false) have no other record of it (#442).
+COMMIT := $(shell git rev-parse HEAD 2>/dev/null)
+LDFLAGS := -s -w -X github.com/carlosframework/platform/internal/version.Build=$(SHA) -X github.com/carlosframework/platform/internal/version.Commit=$(COMMIT)
GOOS ?=
GOARCH ?=
@@ -22,6 +26,7 @@ build:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -o carlos .
build-console:
+ @test -n "$(COMMIT)" || { echo "build-console: git can't say which commit this is, so the console couldn't name it. Build from a git checkout." >&2; exit 1; }
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -trimpath -ldflags "$(LDFLAGS)" -o console ./cmd/console
fmt:
diff --git a/README.md b/README.md
index 5c3899b89..d5e31e74b 100644
--- a/README.md
+++ b/README.md
@@ -247,7 +247,7 @@ step, and an unhurried one now that nothing resolves through them.
A release is a `vX.Y.Z` tag on this repo plus signed binaries on [carlosframework/releases](https://github.com/carlosframework/releases). Everything downstream reads that one set of files: `carlos update`, the Homebrew tap, apt, and every deployment's `carlos system update`. Cut it from a green `main` and verify it from the public side, never from your build directory.
1. **Tag.** `git tag -a vX.Y.Z <sha> -m "carlos vX.Y.Z"` on the `main` commit you are releasing, then `git push origin vX.Y.Z` to the forge.
-2. **Build.** Six targets, darwin, linux and windows on amd64 and arm64, each with `make build GOOS=<os> GOARCH=<arch> SHA=vX.Y.Z` from a clean checkout of the tag. Build with `TMPDIR` and `GOCACHE` on a real disk: `/tmp` is a shared tmpfs, and a full one fails the link with "no space left on device". Zip each Windows binary as a lone `carlos.exe`.
+2. **Build.** Six targets, darwin, linux and windows on amd64 and arm64, each with `make build GOOS=<os> GOARCH=<arch> SHA=vX.Y.Z` from a clean checkout of the tag. Build with `TMPDIR` and `GOCACHE` on a real disk: `/tmp` is a shared tmpfs, and a full one fails the link with "no space left on device". Zip each Windows binary as a lone `carlos.exe`. Build the console the same way, with `make build-console GOOS=linux GOARCH=arm64 SHA=vX.Y.Z`. Both targets stamp the tag's full commit into the binary. The console writes that commit into the hostname history's floor, and the console roll script refuses a floor with no commit. `console hosts-used activate` refuses a console without a full commit.
3. **Debs.** One per architecture, built with `dpkg-deb --root-owner-group`, holding `usr/bin/carlos`. Copy the last release's `control` and change the version and the description's last sentence. Wrap the description without breaking on hyphens, or apt shows "step- by-step".
4. **Sums and signature.** Write `SHA256SUMS.txt` over the eight files. Sign it with the ed25519 seed in SSM `/carlos/cli-update-key`, passed on stdin and never in argv, and write the signature base64-encoded to `SHA256SUMS.txt.sig`. Before signing, check that the key's public half equals `cliUpdatePubKey` in `update.go`. A mismatch publishes a release nobody can update to.
5. **Release notes.** Draft them, and put them through copy review before anything is published. Lead with what changed for people using the CLI. Add a short section for operators, taken from the release notes below this recipe, about anything to check before rolling.
@@ -387,7 +387,8 @@ add the box, then complete the history again.
**The history's floor.** Completing writes the floor to
`control/hosts-used/@floor`. The floor is the release that completed the
-history, and `status` shows it. From then on, never run a console or
+history and the commit it was built from, and `status` shows both.
+Completing refuses a console that doesn't name its commit. From then on, never run a console or
`carlos accounts migrate` older than the floor: an older build creates
records without recording them. The roll script refuses a console below
the floor, and `carlos accounts migrate` refuses to run below it.
diff --git a/accounts_hostsused.go b/accounts_hostsused.go
index 5992f2612..7bcf2f295 100644
--- a/accounts_hostsused.go
+++ b/accounts_hostsused.go
@@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"os"
- "runtime/debug"
"strings"
"github.com/carlosframework/platform/internal/provision"
@@ -53,21 +52,9 @@ func buildMeetsFloor(floor provision.HostsFloor, build, commit string) bool {
return releaseBuild(build) && releaseBuild(floor.Version) && !newerVersion(floor.Version, build)
}
-// thisBuildCommit is the commit this binary was built from, when it says.
-func thisBuildCommit() string {
- if bi, ok := debug.ReadBuildInfo(); ok {
- for _, kv := range bi.Settings {
- if kv.Key == "vcs.revision" {
- return kv.Value
- }
- }
- }
- return ""
-}
-
// checkMigrationFloorNow is checkMigrationFloor for this build.
func checkMigrationFloorNow(ctx context.Context, store release.Store) error {
- return checkMigrationFloor(ctx, store, version.Build, thisBuildCommit())
+ return checkMigrationFloor(ctx, store, version.Build, version.Revision())
}
// migrationRecordHost is a record key's hostname and whether the record is a
diff --git a/cmd/console/hostsused.go b/cmd/console/hostsused.go
index 54e11929b..ea2d790c0 100644
--- a/cmd/console/hostsused.go
+++ b/cmd/console/hostsused.go
@@ -46,6 +46,7 @@ func hostsActivationFromEnv() console.HostsActivation {
Registry: envOr("CARLOS_REGISTRY", "/data/registry.db"),
HostClaim: hostClaimEnabled(os.Getenv),
MovesEnabled: moves.Enabled(os.Getenv),
+ Floor: console.HostsFloorNow(),
}
}
diff --git a/cmd/console/main_test.go b/cmd/console/main_test.go
index 2e93612e3..c498a46da 100644
--- a/cmd/console/main_test.go
+++ b/cmd/console/main_test.go
@@ -36,7 +36,11 @@ func buildConsole(t *testing.T) string {
return
}
consoleBin = filepath.Join(buildDir, "console")
- build := exec.Command(goBin, "build", "-o", consoleBin, ".")
+ // The commit is stamped as the release recipe stamps it: activation
+ // refuses a console that names none (#442).
+ build := exec.Command(goBin, "build", "-ldflags",
+ "-X github.com/carlosframework/platform/internal/version.Commit=0123456789abcdef0123456789abcdef01234567",
+ "-o", consoleBin, ".")
build.Env = os.Environ()
if out, err := build.CombinedOutput(); err != nil {
buildErr = err
diff --git a/cmd/console/servelock_test.go b/cmd/console/servelock_test.go
index ae34cc645..86227a917 100644
--- a/cmd/console/servelock_test.go
+++ b/cmd/console/servelock_test.go
@@ -3,12 +3,16 @@
package main
import (
+ "context"
"errors"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/release"
)
// The serve lock is exclusive across processes: a second taker is refused
@@ -37,12 +41,14 @@ func TestServeLockIsExclusive(t *testing.T) {
again.Close()
}
-// buildConsole builds this binary once per test.
-func buildConsole(t *testing.T) (bin, dir string) {
+// buildConsole builds this binary once per test, with any extra go build
+// flags.
+func buildConsole(t *testing.T, flags ...string) (bin, dir string) {
t.Helper()
dir = t.TempDir()
bin = filepath.Join(dir, "console")
- if out, err := exec.Command("go", "build", "-o", bin, ".").CombinedOutput(); err != nil {
+ args := append(append([]string{"build"}, flags...), "-o", bin, ".")
+ if out, err := exec.Command("go", args...).CombinedOutput(); err != nil {
t.Fatalf("build: %v\n%s", err, out)
}
return bin, dir
@@ -66,7 +72,7 @@ func runConsole(t *testing.T, bin, dir, db string, args ...string) string {
// order: the roster is written, activation completes the history, and
// invalidate invalidates it.
func TestHostsUsedVerbsNeedTheConsoleStopped(t *testing.T) {
- bin, dir := buildConsole(t)
+ bin, dir := buildConsole(t, releaseBuild(testCommit)...)
db := filepath.Join(dir, "console.db")
roster := filepath.Join(dir, "roster.json")
listings := filepath.Join(dir, "scan.jsonl")
@@ -103,9 +109,65 @@ func TestHostsUsedVerbsNeedTheConsoleStopped(t *testing.T) {
if out := runConsole(t, bin, dir, db, v...); !strings.Contains(out, want[i]) {
t.Fatalf("%v with the console stopped printed:\n%s", v, out)
}
+ if v[1] == "activate" {
+ // The floor names the release and the commit the recipe stamped
+ // (#442), though the build carries no vcs.revision.
+ f, _, err := provision.ReadHostsFloor(context.Background(), release.NewDirStore(filepath.Join(dir, "bucket")))
+ if err != nil || f == nil || *f != (provision.HostsFloor{Version: "v9.9.9", Commit: testCommit}) {
+ t.Fatalf("floor = %+v %v, want v9.9.9 at %s", f, err, testCommit)
+ }
+ }
+ }
+}
+
+// testCommit is the commit the release-shaped builds stamp.
+const testCommit = "0123456789abcdef0123456789abcdef01234567"
+
+// releaseBuild is the release recipe's console build (README, "Releasing
+// the platform"): from a linked worktree, so with -buildvcs=false and no
+// vcs.revision, and with the tag and the commit stamped by -ldflags. An
+// empty commit is a build made before the recipe stamped one.
+func releaseBuild(commit string) []string {
+ ld := "-X github.com/carlosframework/platform/internal/version.Build=v9.9.9"
+ if commit != "" {
+ ld += " -X github.com/carlosframework/platform/internal/version.Commit=" + commit
+ }
+ return []string{"-buildvcs=false", "-ldflags", ld}
+}
+
+// TestHostsUsedActivateRefusesABuildWithNoCommit (#442): through the built
+// binary, a release console that does not name its commit refuses to
+// complete the history, and writes no floor and no mode, rather than
+// writing a floor roll-console.sh would refuse on every later roll.
+func TestHostsUsedActivateRefusesABuildWithNoCommit(t *testing.T) {
+ bin, dir := buildConsole(t, releaseBuild("")...)
+ db := filepath.Join(dir, "console.db")
+ roster := filepath.Join(dir, "roster.json")
+ listings := filepath.Join(dir, "scan.jsonl")
+ if err := os.MkdirAll(filepath.Join(dir, "bucket"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(listings, nil, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if out := runConsole(t, bin, dir, db, "hosts-used", "roster", "-o", roster); !strings.Contains(out, "roster written to ") {
+ t.Fatalf("roster printed:\n%s", out)
+ }
+ if out := runConsole(t, bin, dir, db, "hosts-used", "activate", "-roster", roster, "-listings", listings); !strings.Contains(out, msgFloorNoCommit) {
+ t.Fatalf("activate with no commit printed:\n%s", out)
+ }
+ store := release.NewDirStore(filepath.Join(dir, "bucket"))
+ if f, _, err := provision.ReadHostsFloor(context.Background(), store); err != nil || f != nil {
+ t.Fatalf("floor = %+v %v, want none", f, err)
+ }
+ if st, _, err := provision.ReadHostsState(context.Background(), store); err != nil || st.Mode == provision.HostsModeActive {
+ t.Fatalf("mode = %+v %v, want not active", st, err)
}
}
+// msgFloorNoCommit is C13 as the binary prints it.
+const msgFloorNoCommit = "This console doesn't name a full commit, so the history's floor can't name one. Build it with make build-console, then run this again."
+
// TestServeRefusesWithoutTheLock: through the built binary, console serve
// takes the lock before anything else, making the database's directory on
// a fresh install; refuses while another process holds it; and refuses on
diff --git a/docs/superpowers/notes/census-proposal-nearest-region-followups.md b/docs/superpowers/notes/census-proposal-nearest-region-followups.md
new file mode 100644
index 000000000..aa74cd587
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-nearest-region-followups.md
@@ -0,0 +1,11 @@
+# Census approval: nearest-region-followups
+
+Ruling `census-ruling-nearest-region-followups`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+Envelopes re-pinned: `.`, `internal/provision`, `internal/version`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Escalate if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. An escalation goes to the census owner as a decision.
+
+Seal: `f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7` → `f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-nearest-region-followups.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/notes/copy/nearest-region-never-reuse-b.md b/docs/superpowers/notes/copy/nearest-region-never-reuse-b.md
index 2d86d01ab..6806e8fe9 100644
--- a/docs/superpowers/notes/copy/nearest-region-never-reuse-b.md
+++ b/docs/superpowers/notes/copy/nearest-region-never-reuse-b.md
@@ -223,3 +223,21 @@ stop the console, run `console hosts-used invalidate`, start the console,
add the box, then complete the history again.
Reused existing strings: placement with the mode unreadable answers "could not update this app's instances — try again"; add-box with the mode unreadable answers "could not add the box — try again"; a create whose targets grew answers S4, and one whose targets cannot be read, or before the start-up check passes (now at seed and import too), answers S5. S4's <target> for an unnamed home region is "the home region".
+
+## Follow-ups #441 and #442: approved copy
+
+approved by delegated Luna pass on Paul's standing rule, 2026-10-27 (gpt-5.6-luna; C13 and README step 2 rewritten by Luna, MK1 and the floor paragraph approved as drafted). Apply verbatim. #441 adds no copy: the region allow-list refusals keep their bytes and name the home by its name.
+
+C13 (`console hosts-used activate`, a build that does not name a full commit, before anything is written):
+This console doesn't name a full commit, so the history's floor can't name one. Build it with make build-console, then run this again.
+
+MK1 (`make build-console` when git can't give the commit):
+build-console: git can't say which commit this is, so the console couldn't name it. Build from a git checkout.
+
+README, "Releasing the platform" step 2, after "Zip each Windows binary as a lone `carlos.exe`.":
+Build the console the same way, with `make build-console GOOS=linux GOARCH=arm64 SHA=vX.Y.Z`. Both targets stamp the tag's full commit into the binary. The console writes that commit into the hostname history's floor, and the console roll script refuses a floor with no commit. `console hosts-used activate` refuses a console without a full commit.
+
+README, "The history's floor", replacing its second sentence:
+The floor is the release that completed the
+history and the commit it was built from, and `status` shows both.
+Completing refuses a console that doesn't name its commit.
diff --git a/internal/console/apisidecars.go b/internal/console/apisidecars.go
index fb4a891de..ea26cc629 100644
--- a/internal/console/apisidecars.go
+++ b/internal/console/apisidecars.go
@@ -271,13 +271,19 @@ func (s *Server) handleAPISidecarCreate(w http.ResponseWriter, r *http.Request)
jsonError(w, http.StatusBadGateway, "could not check this app's placement")
return
}
- region := strings.TrimSpace(req.Region)
+ // The home region's NAME normalizes to the record's "" before any
+ // validation, as at the instance door (issue #346): the home's boxes
+ // serve region "", so a record naming the home's code would be served
+ // by none, and the hostname history examines the home as "" (#441).
+ // The allow-list then reads the normalized code, as the instance door's
+ // does.
+ region := s.homeRegionIn(strings.TrimSpace(req.Region))
if placed != "" {
region = placed
} else if !provision.ValidRegion(region) || !instanceRegionAllowed(m.Regions, region) {
msg := "invalid region"
if len(m.Regions) > 0 {
- msg = "region " + region + " is not one this app's sidecars run in — allowed: " + strings.Join(m.Regions, ", ")
+ msg = "region " + s.homeRegionOut(region) + " is not one this app's sidecars run in — allowed: " + strings.Join(m.Regions, ", ")
}
jsonError(w, http.StatusBadRequest, msg)
return
diff --git a/internal/console/hostsused_activate.go b/internal/console/hostsused_activate.go
index 814dcfecd..fb544b236 100644
--- a/internal/console/hostsused_activate.go
+++ b/internal/console/hostsused_activate.go
@@ -7,7 +7,7 @@ import (
"fmt"
"os"
"reflect"
- "runtime/debug"
+ "regexp"
"slices"
"sort"
"strings"
@@ -32,10 +32,11 @@ import (
// The approved strings (docs/superpowers/notes/copy/nearest-region-never-reuse-b.md).
const (
- msgHostsAlreadyComplete = "The hostname history is already complete." // C1
- msgHostsNotActive = "The hostname history is not active, so there is nothing to invalidate." // C12
- msgHostsClaimsOn = "This console runs host claims or live moves, so the hostname history can't be completed." // C11
- msgHostsPageOperator = "the hostname history is invalidated by an operator" // D4
+ msgHostsAlreadyComplete = "The hostname history is already complete." // C1
+ msgHostsNotActive = "The hostname history is not active, so there is nothing to invalidate." // C12
+ msgHostsClaimsOn = "This console runs host claims or live moves, so the hostname history can't be completed." // C11
+ msgHostsPageOperator = "the hostname history is invalidated by an operator" // D4
+ msgHostsFloorNoCommit = "This console doesn't name a full commit, so the history's floor can't name one. Build it with make build-console, then run this again." // C13
)
func msgHostsNoListing(targets []string) string { // C7
@@ -93,6 +94,10 @@ type HostsActivation struct {
Registry string
HostClaim bool
MovesEnabled bool
+ // Floor is the build that completes the history, written as its floor:
+ // HostsFloorNow() for the console binary. Activate refuses one that does not
+ // name a full commit.
+ Floor provision.HostsFloor
}
// Roster reads the roster now: the edges files (all of them, read and
@@ -283,20 +288,19 @@ func recordFacts(ctx context.Context, rel release.Store) (hosts []string, unfini
return hosts, unfinished, "", nil
}
-// floorNow is this build: its version and, when the build carries it, its
-// commit.
-func floorNow() provision.HostsFloor {
- f := provision.HostsFloor{Version: version.Build}
- if bi, ok := debug.ReadBuildInfo(); ok {
- for _, kv := range bi.Settings {
- if kv.Key == "vcs.revision" {
- f.Commit = kv.Value
- }
- }
- }
- return f
+// HostsFloorNow is this build: its version and its commit, as stamped by the
+// release recipe or recorded by Go (version.Revision). It can be empty;
+// Activate refuses then.
+func HostsFloorNow() provision.HostsFloor {
+ return provision.HostsFloor{Version: version.Build, Commit: version.Revision()}
}
+// fullCommit is a whole git object name in lower-case hex: 40 characters,
+// or 64 in a SHA-256 repository. roll-console.sh resolves the floor's
+// commit in the platform checkout, so anything else (empty, abbreviated, a
+// tag or ref name) is refused before the history is touched (#442).
+var fullCommit = regexp.MustCompile(`^(?:[0-9a-f]{40}|[0-9a-f]{64})$`)
+
// Activate makes the history active. scanned is the roster the adapter
// scanned, listings its output, closeFleets the fleets not scanned. It
// refuses (each error is the operator's sentence) with claims or Phase 1
@@ -307,6 +311,9 @@ func floorNow() provision.HostsFloor {
// the records, the lifetime tables and the listings, writes the floor and
// the active mode, and answers how many hostnames the history holds.
func (a HostsActivation) Activate(ctx context.Context, scanned HostsRoster, listings []provision.TargetListing, closeFleets []string) (int, error) {
+ if !fullCommit.MatchString(a.Floor.Commit) {
+ return 0, errors.New(msgHostsFloorNoCommit)
+ }
if a.HostClaim || a.MovesEnabled {
return 0, errors.New(msgHostsClaimsOn)
}
@@ -434,7 +441,7 @@ func (a HostsActivation) Activate(ctx context.Context, scanned HostsRoster, list
if err != nil {
return 0, fmt.Errorf("read the floor: %w", err)
}
- if _, err := provision.WriteHostsFloor(ctx, a.Releases, floorNow(), floorETag); err != nil {
+ if _, err := provision.WriteHostsFloor(ctx, a.Releases, a.Floor, floorETag); err != nil {
return 0, fmt.Errorf("write the floor: %w", err)
}
var examined []string
diff --git a/internal/console/hostsused_activate_test.go b/internal/console/hostsused_activate_test.go
index 9ef88afc5..659342efa 100644
--- a/internal/console/hostsused_activate_test.go
+++ b/internal/console/hostsused_activate_test.go
@@ -18,6 +18,7 @@ import (
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/seeds"
+ "github.com/carlosframework/platform/internal/version"
)
// putHostsEdges publishes one box's edges file.
@@ -38,8 +39,11 @@ func invFx(t *testing.T) lifetimesFx {
return l
}
+// testFloor is the build the activation tests complete the history as.
+var testFloor = provision.HostsFloor{Version: "v0.0.0-test", Commit: "0123456789abcdef0123456789abcdef01234567"}
+
func activation(l lifetimesFx) HostsActivation {
- return HostsActivation{DB: l.fx.st, Releases: l.fx.rel, Registry: l.fx.srv.cfg.Registry}
+ return HostsActivation{DB: l.fx.st, Releases: l.fx.rel, Registry: l.fx.srv.cfg.Registry, Floor: testFloor}
}
func rosterOf(t *testing.T, l lifetimesFx) HostsRoster {
@@ -104,8 +108,8 @@ func TestActivateHistoricalOnlyNameAllowed(t *testing.T) {
if err != nil || st.Mode != provision.HostsModeActive || !contains(st.Examined, "region:ie") {
t.Fatalf("state = %+v %v, want active with region:ie examined", st, err)
}
- if f, _, err := provision.ReadHostsFloor(context.Background(), l.fx.rel); err != nil || f == nil || f.Version == "" {
- t.Fatalf("floor = %+v %v, want written", f, err)
+ if f, _, err := provision.ReadHostsFloor(context.Background(), l.fx.rel); err != nil || f == nil || *f != testFloor {
+ t.Fatalf("floor = %+v %v, want %+v", f, err, testFloor)
}
if _, err := activate(t, l, clean(nil, nil)); err == nil || err.Error() != msgHostsAlreadyComplete {
t.Fatalf("activate again = %v, want C1", err)
@@ -355,6 +359,44 @@ func TestInvalidateOffline(t *testing.T) {
}
}
+// TestActivateRefusesABuildThatNamesNoCommit (#442): the floor must name
+// the commit this console was built from, because roll-console.sh checks
+// commits only and refuses a floor that names just a release. A build that
+// does not name a full commit is refused before anything is written: no
+// mark, no floor, and the mode stays as it was.
+func TestActivateRefusesABuildThatNamesNoCommit(t *testing.T) {
+ for _, commit := range []string{"", "0123abc", "HEAD", "0123456789ABCDEF0123456789ABCDEF01234567", "v0.28.28"} {
+ t.Run("commit "+commit, func(t *testing.T) {
+ l := invFx(t)
+ a := activation(l)
+ a.Floor = provision.HostsFloor{Version: "v0.28.28", Commit: commit}
+ _, err := a.Activate(context.Background(), rosterOf(t, l), clean([]string{"kept.shop.example.com.db"}, nil), nil)
+ refusedWith(t, err, msgHostsFloorNoCommit)
+ if marked(t, l.fx.rel, "kept.shop.example.com") {
+ t.Fatal("the refused activation marked a hostname")
+ }
+ if f, _, err := provision.ReadHostsFloor(context.Background(), l.fx.rel); err != nil || f != nil {
+ t.Fatalf("floor = %+v %v, want none", f, err)
+ }
+ if st, _, err := provision.ReadHostsState(context.Background(), l.fx.rel); err != nil || st.Mode == provision.HostsModeActive {
+ t.Fatalf("state = %+v %v, want not active", st, err)
+ }
+ })
+ }
+}
+
+// TestFloorNowNamesTheStampedCommit (#442): the floor this build writes
+// carries the commit the release recipe stamps with -ldflags, which is all
+// a -buildvcs=false build has.
+func TestFloorNowNamesTheStampedCommit(t *testing.T) {
+ old := version.Commit
+ t.Cleanup(func() { version.Commit = old })
+ version.Commit = "89abcdef0123456789abcdef0123456789abcdef"
+ if f := HostsFloorNow(); f.Version != version.Build || f.Commit != version.Commit {
+ t.Fatalf("HostsFloorNow = %+v, want version %q commit %q", f, version.Build, version.Commit)
+ }
+}
+
func createAs(t *testing.T, l lifetimesFx, body string) (int, string) {
t.Helper()
code, _, out := rawReq(t, http.MethodPost, instancesURL(l.fx, "bab", ltApp), l.member, body)
diff --git a/internal/console/hostsused_homecode_test.go b/internal/console/hostsused_homecode_test.go
new file mode 100644
index 000000000..b83bed915
--- /dev/null
+++ b/internal/console/hostsused_homecode_test.go
@@ -0,0 +1,91 @@
+package console
+
+import (
+ "context"
+ "net/http"
+ "slices"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/provision"
+)
+
+// TestHomeCodeCreatesOnceActive (#441): on a deployment that names its home
+// (CONSOLE_HOME_REGION=ie), the home's boxes publish placement "" and
+// activation examines region "" and region uk. A create that names the
+// home by its code is a create at the home: through the real doors, lifetimes
+// off and on, a sidecar and an instance with -region ie are admitted and
+// stored with region "", which is the region the home's boxes serve. Neither
+// app has an allow-list, as on dev. With one, the sidecar door reads it as the
+// instance door does: the normalized code is checked, so a list that leaves
+// out "" refuses the home, named by its name.
+func TestHomeCodeCreatesOnceActive(t *testing.T) {
+ lifetimesFor(t, func(t *testing.T, on func(*testing.T, markCase)) {
+ fx := leftoverFixture(t, "code-home-code")
+ im := titoManifest()
+ im.Pool, im.Regions = "", nil
+ enableInstances(t, fx.consoleFixture, "titogo", im)
+ sm := titoSidecarManifest()
+ sm.Pool, sm.Regions = "", nil
+ enableSidecars(t, fx.consoleFixture, "titogo", sm)
+ fx.srv.cfg.HomeRegion = "ie"
+ fx.srv.cfg.Region = "" // the console's box is a home box
+ putHostsEdges(t, fx.rel, "b1", "", "data-test")
+ putHostsEdges(t, fx.rel, "b2", "uk", "data-uk")
+ ctx := context.Background()
+ a := HostsActivation{DB: fx.st, Releases: fx.rel, Registry: fx.srv.cfg.Registry, Floor: testFloor}
+ roster, err := a.Roster(ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+ listings := []provision.TargetListing{
+ {Target: "b1", Kind: "box", OK: true},
+ {Target: "b2", Kind: "box", OK: true},
+ {Target: "data-test", Kind: "bucket", Prefix: "instances", OK: true},
+ {Target: "data-uk", Kind: "bucket", Prefix: "instances", OK: true},
+ }
+ if _, err := a.Activate(ctx, roster, listings, nil); err != nil {
+ t.Fatalf("activate: %v", err)
+ }
+ fx.srv.hosts.reset()
+ fx.srv.LoadHostsMode(ctx)
+ st, _, err := provision.ReadHostsState(ctx, fx.rel)
+ if err != nil || st.Mode != provision.HostsModeActive || !slices.Equal(st.Examined, []string{"region:", "region:uk"}) {
+ t.Fatalf("state = %+v %v, want active with the home and uk examined", st, err)
+ }
+ on(t, markCase{fx: fx.consoleFixture})
+
+ for _, c := range []struct{ door, body string }{
+ {"sidecar", `{"name":"bot","region":"ie"}`},
+ {"sidecar", `{"name":"bot2"}`},
+ {"instance", `{"host":"acme.go.tito.io","region":"ie"}`},
+ {"instance", `{"host":"plain.go.tito.io"}`},
+ } {
+ u := instancesURL(fx.consoleFixture, "bab", "titogo")
+ if c.door == "sidecar" {
+ u = sidecarsURL(fx.consoleFixture, "bab", "titogo")
+ }
+ if code, _, out := rawReq(t, http.MethodPost, u, fx.token, c.body); code != http.StatusCreated {
+ t.Fatalf("%s create %s = %d %s, want 201", c.door, c.body, code, out)
+ }
+ }
+ for _, name := range []string{"bot", "bot2"} {
+ sc, err := provision.GetSidecarRecord(ctx, fx.rel, "bab", "titogo", name)
+ if err != nil || sc.Region != "" {
+ t.Fatalf("sidecar %s = %+v %v, want region \"\"", name, sc, err)
+ }
+ }
+ for _, host := range []string{"acme.go.tito.io", "plain.go.tito.io"} {
+ rec, err := provision.GetRecord(ctx, fx.rel, "bab", "titogo", host)
+ if err != nil || rec.Region != "" {
+ t.Fatalf("instance %s = %+v %v, want region \"\"", host, rec, err)
+ }
+ }
+
+ sm.Regions = []string{"uk"}
+ enableSidecars(t, fx.consoleFixture, "titogo", sm)
+ code, _, out := rawReq(t, http.MethodPost, sidecarsURL(fx.consoleFixture, "bab", "titogo"), fx.token, `{"name":"bot3","region":"ie"}`)
+ if want := "region ie is not one this app's sidecars run in — allowed: uk"; code != http.StatusBadRequest || ltErr(out) != want {
+ t.Fatalf("sidecar create at the home off the allow-list = %d %s, want 400 %q", code, out, want)
+ }
+ })
+}
diff --git a/internal/provision/hostsused.go b/internal/provision/hostsused.go
index 7f22fc4e1..ad59fce97 100644
--- a/internal/provision/hostsused.go
+++ b/internal/provision/hostsused.go
@@ -214,8 +214,13 @@ func ReadHostsFloor(ctx context.Context, s release.Store) (*HostsFloor, string,
return &f, etag, nil
}
-// WriteHostsFloor writes @floor on ifMatch, as WriteHostsMode.
+// WriteHostsFloor writes @floor on ifMatch, as WriteHostsMode. A floor that
+// names no commit is refused and nothing is written: roll-console.sh checks
+// commits only, so it would refuse every later console roll (#442).
func WriteHostsFloor(ctx context.Context, s release.Store, f HostsFloor, ifMatch string) (string, error) {
+ if f.Commit == "" {
+ return "", fmt.Errorf("provision: hosts used: %s: the floor names no commit", HostsFloorKey)
+ }
body, err := json.Marshal(f)
if err != nil {
return "", err
diff --git a/internal/provision/hostsused_test.go b/internal/provision/hostsused_test.go
index 0499d3ff1..9e600d18b 100644
--- a/internal/provision/hostsused_test.go
+++ b/internal/provision/hostsused_test.go
@@ -165,6 +165,20 @@ func TestHostsFloorRoundTrips(t *testing.T) {
}
}
+// TestWriteHostsFloorRefusesNoCommit (#442): a floor that names only a
+// version is refused by roll-console.sh (a tag can be moved), so it is never
+// written: the old floor stays as it was.
+func TestWriteHostsFloorRefusesNoCommit(t *testing.T) {
+ s := release.NewDirStore(t.TempDir())
+ ctx := context.Background()
+ if _, err := WriteHostsFloor(ctx, s, HostsFloor{Version: "v0.28.28"}, ""); err == nil {
+ t.Fatal("a floor with no commit was written")
+ }
+ if f, _, err := ReadHostsFloor(ctx, s); err != nil || f != nil {
+ t.Fatalf("after the refusal the floor is (%+v, %v), want none", f, err)
+ }
+}
+
// TestWriteRecordRefusesKindChange: a record's kind is fixed at create, so
// an exempt record (static, service) can never become a data kind in place
// and skip the mark its create would have written.
diff --git a/internal/provision/nearest_region_a_census_test.go b/internal/provision/nearest_region_a_census_test.go
index 6748b15f9..ac3fd01ef 100644
--- a/internal/provision/nearest_region_a_census_test.go
+++ b/internal/provision/nearest_region_a_census_test.go
@@ -54,7 +54,8 @@ func nearestRegionAWriteCensusInventory() []censusEntry {
{"internal/console/authcli.go", "Server.registerCLIRoutes", "key-site", "lit:instances,lit:sidecars", "25cb2b7d4f7d264d8a45e5b9306f8f7f95fe886237fd88b9e4a492d7e66e90e3"},
{"internal/console/lifetimes_create.go", "Server.createRecordWithLifetimeLocked", "key-site", "key:RecordKey", "c3b601f16c8ceeb03f7a9512d9c079ad2eadb5414036beeeb032fd622b587a92"},
{"internal/provision/hostsused.go", "MarkHostUsed", "nonrecord", "sel:Put", "439f9ca1443f2c815f2ddb18b4732285d236d745fb660de66dc3a175b4532fd3"},
- {"internal/provision/hostsused.go", "WriteHostsFloor", "nonrecord", "sel:Put", "c10e2e2fd57470c81785df3dddd9bb33013b416ce5381e74a9657811ec6b5c79"},
+ // Re-digested for nearest-region-followups (#442, census-ruling-nearest-region-followups): a floor with an empty commit is refused before the Put, which is unchanged. No record key.
+ {"internal/provision/hostsused.go", "WriteHostsFloor", "nonrecord", "sel:Put", "bafbd7294aec67c69a614209b37d010eb1f4940aee5d68d4c56b14211394fee6"},
{"internal/provision/hostsused.go", "WriteHostsMode", "nonrecord", "sel:Put", "21147fa65d21d7a074589ca4ea6cf2ec9852a7ab42ca3acaac429562d8f22146"},
{"internal/provision/record_sequence.go", "WriteRecord", "record-primitive", "key:IsRecordKey,key:WriteRecord,key:preparedRecordKey,sel:Put", "d58d11066b4e4445e4295170de0f4aec1d9c8c046f1a9fc4cd79fc6e6353d527"},
}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index cbde46058..9a65d869d 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -15,3 +15,4 @@ plan14-root-reads-alias-wake-338.tsv deeddee1bf22a18562acda97cc34c6d73ee0dff1825
plan14-root-reads-analytics-onramp.tsv f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7
plan14-root-reads-nearest-region-scan.tsv f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7
plan14-root-reads-plans-6b-checkout-flow.tsv f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7
+plan14-root-reads-nearest-region-followups.tsv f5afdacd495705841fcc8441eaefe0efb9db7056de281bb06d1714960a5575b7
diff --git a/internal/provision/testdata/plan14-root-reads-nearest-region-followups.tsv b/internal/provision/testdata/plan14-root-reads-nearest-region-followups.tsv
new file mode 100644
index 000000000..46d9a90a4
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-nearest-region-followups.tsv
@@ -0,0 +1,5 @@
+# Census overlay nearest-region-followups, written by census-propose (#369). census-ruling-nearest-region-followups, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-nearest-region-followups.md.
+# 0 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@coverage . e53421c8fa52765ef0db36d385755dbd58ebf59b5e719d7acf6608279eb98b1a
+@coverage internal/provision 0d5bf577b785f7ecb036fdb2db90e6aac26da08b61892c222a3b0aea203842d9
+@coverage internal/version c28de6a760457238ddd84846b141b2ccdc2511cb76f5b68197370dfb6b829af1
diff --git a/internal/version/version.go b/internal/version/version.go
index 63b7cccfe..235c7d21c 100644
--- a/internal/version/version.go
+++ b/internal/version/version.go
@@ -1,6 +1,32 @@
// Package version carries the build identity stamped at link time.
package version
+import "runtime/debug"
+
// Build is the git short sha of the release, or "dev" for local builds.
// Set via -ldflags "-X github.com/carlosframework/platform/internal/version.Build=<sha>".
var Build = "dev"
+
+// Commit is the full git commit the build was made from, when the build
+// stamps it: -ldflags "-X github.com/carlosframework/platform/internal/version.Commit=<sha>".
+// make build and make build-console stamp it. Release builds from a linked
+// worktree run with -buildvcs=false, so Go records no vcs.revision of its
+// own, and without this the hostname history's floor named no commit
+// (#442).
+var Commit = ""
+
+// Revision is the commit this binary was built from: Commit when the build
+// stamped one, else Go's vcs.revision build setting, else "".
+func Revision() string {
+ if Commit != "" {
+ return Commit
+ }
+ if bi, ok := debug.ReadBuildInfo(); ok {
+ for _, kv := range bi.Settings {
+ if kv.Key == "vcs.revision" {
+ return kv.Value
+ }
+ }
+ }
+ return ""
+}
diff --git a/internal/version/version_test.go b/internal/version/version_test.go
index d83f0ebd4..ae27e9ecf 100644
--- a/internal/version/version_test.go
+++ b/internal/version/version_test.go
@@ -7,3 +7,20 @@ func TestBuildDefaultsToDev(t *testing.T) {
t.Fatalf("Build = %q, want dev", Build)
}
}
+
+// TestRevisionPrefersTheStampedCommit (#442): a release build made with
+// -buildvcs=false carries no vcs.revision, so the commit stamped with
+// -ldflags is what Revision answers. Unstamped, it falls back to Go's own
+// build setting, which a test binary does not carry.
+func TestRevisionPrefersTheStampedCommit(t *testing.T) {
+ old := Commit
+ t.Cleanup(func() { Commit = old })
+ Commit = ""
+ if got := Revision(); got != "" {
+ t.Fatalf("Revision of an unstamped test binary = %q, want empty", got)
+ }
+ Commit = "0123456789abcdef0123456789abcdef01234567"
+ if got := Revision(); got != Commit {
+ t.Fatalf("Revision = %q, want the stamped %q", got, Commit)
+ }
+}