hosts-used floor names a release; raise-floor for commit floors
Flagship's hostname history floor names a bare commit (50c0cb14), written by a console rolled from a checkout. carlos accounts migrate compares release versions, and a binary cannot tell whether it contains a commit, so every release build was refused as "older than the floor". - console hosts-used activate refuses a console that is not a release build (C14), so a new floor always names a release and its commit. - console hosts-used raise-floor -release vX.Y.Z -checkout <dir> gives an existing commit floor the release that contains it. It accepts only when the running console is a release at or above it, the checkout's tag is this console's commit or an ancestor of it, and the tag contains the floor's commit (merge-base --is-ancestor, object names only). It writes with If-Match on the floor it read. No serve lock or database. - carlos accounts migrate still refuses a bare-commit floor, but says to give the floor a release (B11) instead of "update carlos". - README floor section, design note, approved copy (Luna), census card (envelope . only, no unit changed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 files changed,
+900
−14
README.md+14 −2accounts_hostsused.go+17 −4accounts_record_sequence_test.go+26 −0cmd/console/hostsused.go+18 −1cmd/console/hostsused_floor_test.go+91 −0cmd/console/main.go+1 −1cmd/console/main_test.go+4 −3docs/superpowers/notes/census-proposal-hosts-floor-release.md+11 −0docs/superpowers/notes/copy/hosts-floor-names-a-release.md+62 −0docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md+105 −0internal/console/hostsused_activate.go+9 −2internal/console/hostsused_activate_test.go+1 −1internal/console/hostsused_floor.go+244 −0internal/console/hostsused_floor_test.go+293 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-hosts-floor-release.tsv+3 −0
CI cancelled — superseded by a newer push — run details
diff --git a/README.md b/README.md| index 25a9e7ca9..f02a29b69 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`. Build the console the same way, with `make build-console GOOS=linux GOARCH=<arch> SHA=vX.Y.Z` for amd64 and arm64, and name the two `carlos-console-linux-<arch>`. 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. |
| +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=<arch> SHA=vX.Y.Z` for amd64 and arm64, and name the two `carlos-console-linux-<arch>`. 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 that isn't a release build or doesn't name 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. Write `CONSOLE_SHA256SUMS.txt` over the two console binaries and sign it the same way, to `CONSOLE_SHA256SUMS.txt.sig`. Keep the console out of `SHA256SUMS.txt`: `carlos update` reads that file. The public self-host guide downloads the console and checks this signature, so a release without it leaves the guide on an older console. |
| 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. |
| @@ -390,11 +390,23 @@ 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 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 |
| +Completing refuses a console that isn't a release build or 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. |
| +A floor written by a console that wasn't a release names only a commit. |
| +`carlos accounts migrate` can't tell whether a release contains a commit, |
| +so it refuses every release. Give the floor the oldest release that |
| +contains the commit. In a platform checkout with its tags fetched, |
| +`git tag --contains <commit>` lists tags that contain it; choose the oldest |
| +release by version. Then, with the deployment |
| +bucket's credentials and a release console at that release or later, run |
| +`console hosts-used raise-floor -release vX.Y.Z -checkout <checkout>`. It |
| +checks that the release contains the floor's commit and writes the release |
| +and its commit as the floor. |
| + |
| **Restores.** Restoring the console's database alone is safe. A restore of |
| the control bucket must keep every object under `control/hosts-used/`. If |
| any objects may have been dropped, stop the console, run `console |
diff --git a/accounts_hostsused.go b/accounts_hostsused.go| index 7bcf2f295..f7ae2ed0c 100644 |
| --- a/accounts_hostsused.go |
| +++ b/accounts_hostsused.go |
| @@ -30,19 +30,32 @@ func msgMigrateHoldsData(name string) string { |
| return name + ": not migrated. carlos accounts migrate doesn't move an instance that holds data." |
| } |
| +// msgMigrateFloorNoRelease is B11: a floor that names a commit and no |
| +// release, which no build but that commit's own can show it is above. |
| +func msgMigrateFloorNoRelease(floor string) string { |
| + return "the hostname history's floor, " + floor + ", names a commit and not a release, so this carlos can't tell whether it is at or above it. " + |
| + "give the floor a release with console hosts-used raise-floor, then run this again." |
| +} |
| + |
| // checkMigrationFloor reads the history's floor and refuses a build below |
| // it (B10). A build is at or above it when both are release tags and this |
| // one is not older, or when it is the floor's own commit; anything else (a |
| -// dev build, a bare commit) cannot show it is, and refuses. |
| +// dev build, a bare commit) cannot show it is, and refuses. A binary has no |
| +// git history, so against a floor that names only a commit every other |
| +// build refuses, and is told to give the floor a release (B11; design |
| +// 2026-11-05-hosts-floor-names-a-release) rather than to update. |
| func checkMigrationFloor(ctx context.Context, store release.Store, build, commit string) error { |
| floor, _, err := provision.ReadHostsFloor(ctx, store) |
| if err != nil { |
| return fmt.Errorf("accounts migrate: read the hostname history's floor: %w", err) |
| } |
| - if floor != nil && !buildMeetsFloor(*floor, build, commit) { |
| - return errors.New("this carlos is older than the hostname history's floor, " + floor.Version + ". update carlos, then run it again.") |
| + if floor == nil || buildMeetsFloor(*floor, build, commit) { |
| + return nil |
| } |
| - return nil |
| + if !releaseBuild(floor.Version) { |
| + return errors.New(msgMigrateFloorNoRelease(floor.Version)) |
| + } |
| + return errors.New("this carlos is older than the hostname history's floor, " + floor.Version + ". update carlos, then run it again.") |
| } |
| func buildMeetsFloor(floor provision.HostsFloor, build, commit string) bool { |
diff --git a/accounts_record_sequence_test.go b/accounts_record_sequence_test.go| index f3b6634a8..1aceff6ec 100644 |
| --- a/accounts_record_sequence_test.go |
| +++ b/accounts_record_sequence_test.go |
| @@ -379,3 +379,29 @@ func TestCLIRefusesBelowFloor(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// TestCLIBareCommitFloorSaysRaiseIt (hosts-floor-names-a-release design): |
| +// a floor that names a commit and no release still refuses every build but |
| +// its own commit, since a binary cannot tell whether it contains a commit, |
| +// and the refusal says how to give the floor a release instead of telling |
| +// a release that may well be newer to update. |
| +func TestCLIBareCommitFloorSaysRaiseIt(t *testing.T) { |
| + store := release.NewDirStore(t.TempDir()) |
| + ctx := context.Background() |
| + commit := "50c0cb14b429993b89bcb71dbf51a645580cc4aa" |
| + if _, err := provision.WriteHostsFloor(ctx, store, provision.HostsFloor{Version: "50c0cb14", Commit: commit}, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + want := "the hostname history's floor, 50c0cb14, names a commit and not a release, so this carlos can't tell whether it is at or above it. " + |
| + "give the floor a release with console hosts-used raise-floor, then run this again." |
| + for _, build := range []struct{ version, commit string }{ |
| + {"v0.34.3", "e047662751aaaedbad638d1ab9279d32f5860914"}, {"v0.1.0", ""}, {"dev", ""}, {"0123abc", "0123abcdef"}, |
| + } { |
| + if err := checkMigrationFloor(ctx, store, build.version, build.commit); err == nil || err.Error() != want { |
| + t.Errorf("%+v against a bare-commit floor = %v, want %q", build, err, want) |
| + } |
| + } |
| + if err := checkMigrationFloor(ctx, store, "50c0cb14", commit); err != nil { |
| + t.Errorf("the floor's own commit = %v, want allowed", err) |
| + } |
| +} |
diff --git a/cmd/console/hostsused.go b/cmd/console/hostsused.go| index ea2d790c0..e3665f367 100644 |
| --- a/cmd/console/hostsused.go |
| +++ b/cmd/console/hostsused.go |
| @@ -17,7 +17,7 @@ import ( |
| "github.com/carlosframework/platform/internal/provision" |
| ) |
| -// console hosts-used roster | activate | invalidate (nearest-region |
| +// console hosts-used roster | activate | invalidate | raise-floor (nearest-region |
| // never-reuse; Paul's cut on #404): the hostname history is made active, and |
| // invalidated by an operator, offline, on the console's box with the |
| // console stopped. roster, activate and invalidate take the console's serve |
| @@ -139,6 +139,23 @@ func runHostsUsed(args []string) { |
| log.Fatal(err) |
| } |
| fmt.Printf(msgActivated+"\n", n) |
| + case "raise-floor": |
| + // The floor names a release (hostsused_floor.go). No serve lock and |
| + // no database: only activate writes the floor besides this, under |
| + // the lock, and this write is conditional on the floor it read. So |
| + // it runs anywhere with the bucket and a platform checkout. |
| + fs := flag.NewFlagSet("hosts-used raise-floor", flag.ExitOnError) |
| + rel := fs.String("release", "", "the release the floor names from now on") |
| + checkout := fs.String("checkout", "", "a platform checkout that has the release's tag") |
| + fs.Parse(args[1:]) |
| + if *rel == "" || *checkout == "" || fs.NArg() != 0 { |
| + usage() |
| + } |
| + from, to, err := console.RaiseHostsFloor(ctx, openStore(nil), console.HostsFloorNow(), *rel, console.GitCheckout{Dir: *checkout}) |
| + if err != nil { |
| + log.Fatal(err) |
| + } |
| + fmt.Println(console.MsgFloorRaised(from, to)) |
| case "invalidate": |
| if len(args) != 1 { |
| usage() |
diff --git a/cmd/console/hostsused_floor_test.go b/cmd/console/hostsused_floor_test.go| new file mode 100644 |
| index 000000000..b5edd6d83 |
| --- /dev/null |
| +++ b/cmd/console/hostsused_floor_test.go |
| @@ -0,0 +1,91 @@ |
| +package main |
| + |
| +import ( |
| + "context" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// TestHostsUsedRaiseFloorThroughTheBinary (hosts-floor-names-a-release |
| +// design): a release console, run with a platform checkout, gives a floor |
| +// that names only a commit the release that contains it, and refuses a |
| +// release that does not, writing nothing. It needs no console database and |
| +// no serve lock: it writes only the floor, conditionally. |
| +func TestHostsUsedRaiseFloorThroughTheBinary(t *testing.T) { |
| + if _, err := exec.LookPath("git"); err != nil { |
| + t.Skip("git is not installed") |
| + } |
| + repo := filepath.Join(t.TempDir(), "platform") |
| + git := func(args ...string) string { |
| + t.Helper() |
| + cmd := exec.Command("git", append([]string{"-C", repo, "-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false", "-c", "tag.gpgsign=false"}, args...)...) |
| + cmd.Env = append(cmd.Environ(), "GIT_CONFIG_NOSYSTEM=1", "GIT_CONFIG_GLOBAL=/dev/null") |
| + out, err := cmd.CombinedOutput() |
| + if err != nil { |
| + t.Fatalf("git %v: %v\n%s", args, err, out) |
| + } |
| + return strings.TrimSpace(string(out)) |
| + } |
| + if out, err := exec.Command("git", "init", "-q", "-b", "main", repo).CombinedOutput(); err != nil { |
| + t.Fatalf("git init: %v\n%s", err, out) |
| + } |
| + commit := func(msg string) string { |
| + git("commit", "-q", "--allow-empty", "-m", msg) |
| + return git("rev-parse", "HEAD") |
| + } |
| + commit("before") |
| + git("tag", "-a", "v9.9.7", "-m", "carlos v9.9.7") |
| + floor := commit("the floor") |
| + tagged := commit("released") |
| + git("tag", "-a", "v9.9.8", "-m", "carlos v9.9.8") |
| + built := commit("this console") |
| + git("tag", "-a", "v9.9.9", "-m", "carlos v9.9.9") |
| + |
| + ld := "-X github.com/carlosframework/platform/internal/version.Build=v9.9.9 -X github.com/carlosframework/platform/internal/version.Commit=" + built |
| + bin, dir := buildConsole(t, "-buildvcs=false", "-ldflags", ld) |
| + store := release.NewDirStore(filepath.Join(dir, "bucket")) |
| + if err := os.MkdirAll(filepath.Join(dir, "bucket"), 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + bare := provision.HostsFloor{Version: floor[:8], Commit: floor} |
| + if _, err := provision.WriteHostsFloor(context.Background(), store, bare, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + db := filepath.Join(dir, "no-console.db") |
| + // runConsole's environment, with PATH so the binary finds git. |
| + run := func(args ...string) string { |
| + t.Helper() |
| + cmd := exec.Command(bin, args...) |
| + cmd.Dir = dir |
| + cmd.Env = []string{"CONSOLE_DB=" + db, "CARLOS_DEPLOYMENT_DIR=" + filepath.Join(dir, "bucket"), |
| + "CARLOS_REGISTRY=" + filepath.Join(dir, "registry.db"), "HOME=" + dir, "PATH=" + os.Getenv("PATH")} |
| + out, _ := cmd.CombinedOutput() |
| + return string(out) |
| + } |
| + |
| + out := run("hosts-used", "raise-floor", "-release", "v9.9.7", "-checkout", repo) |
| + if !strings.Contains(out, "v9.9.7 doesn't contain the floor's commit, "+floor+".") { |
| + t.Fatalf("raise-floor to a release without the floor printed:\n%s", out) |
| + } |
| + if f, _, err := provision.ReadHostsFloor(context.Background(), store); err != nil || f == nil || *f != bare { |
| + t.Fatalf("floor after the refusal = %+v %v, want %+v", f, err, bare) |
| + } |
| + |
| + out = run("hosts-used", "raise-floor", "-release", "v9.9.8", "-checkout", repo) |
| + want := "The hostname history's floor is now v9.9.8 (" + tagged + "). It was " + floor[:8] + " (" + floor + ")." |
| + if !strings.Contains(out, want) { |
| + t.Fatalf("raise-floor printed:\n%s\nwant %q", out, want) |
| + } |
| + if f, _, err := provision.ReadHostsFloor(context.Background(), store); err != nil || f == nil || *f != (provision.HostsFloor{Version: "v9.9.8", Commit: tagged}) { |
| + t.Fatalf("floor = %+v %v, want v9.9.8 at %s", f, err, tagged) |
| + } |
| + if _, err := os.Stat(db); !os.IsNotExist(err) { |
| + t.Fatalf("raise-floor opened a console database: %v", err) |
| + } |
| +} |
diff --git a/cmd/console/main.go b/cmd/console/main.go| index 8f3f0395a..013660429 100644 |
| --- a/cmd/console/main.go |
| +++ b/cmd/console/main.go |
| @@ -239,7 +239,7 @@ func usage() { |
| log.Fatal("usage: console serve | grant [-operator] <address> [<app>] | revoke [-operator] <address> [<app>] | owners | " + |
| "member -add|-remove <address> <account-sqid> [-role owner|member] | member -list <account-sqid> | " + |
| "migrate-app -app <app> -to <sqid> [-from <sqid>] | " + |
| - "hosts-used roster -o <file> | hosts-used activate -roster <file> -listings <file> [-close-fleet <fleet>]... | hosts-used invalidate") |
| + "hosts-used roster -o <file> | hosts-used activate -roster <file> -listings <file> [-close-fleet <fleet>]... | hosts-used invalidate | hosts-used raise-floor -release <vX.Y.Z> -checkout <dir>") |
| } |
| // migrateApp completes the second half of `carlos accounts migrate`: that |
diff --git a/cmd/console/main_test.go b/cmd/console/main_test.go| index 086b7f6f6..d75081aa2 100644 |
| --- a/cmd/console/main_test.go |
| +++ b/cmd/console/main_test.go |
| @@ -36,10 +36,11 @@ func buildConsole(t *testing.T) string { |
| return |
| } |
| consoleBin = filepath.Join(buildDir, "console") |
| - // The commit is stamped as the release recipe stamps it: activation |
| - // refuses a console that names none (#442). |
| + // The release and the commit are stamped as the release recipe |
| + // stamps them: activation refuses a console that names no commit |
| + // (#442) or no release (hosts-floor-names-a-release design). |
| build := exec.Command(goBin, "build", "-ldflags", |
| - "-X github.com/carlosframework/platform/internal/version.Commit=0123456789abcdef0123456789abcdef01234567", |
| + "-X github.com/carlosframework/platform/internal/version.Build=v9.9.9 -X github.com/carlosframework/platform/internal/version.Commit=0123456789abcdef0123456789abcdef01234567", |
| "-o", consoleBin, ".") |
| build.Env = os.Environ() |
| if out, err := build.CombinedOutput(); err != nil { |
diff --git a/docs/superpowers/notes/census-proposal-hosts-floor-release.md b/docs/superpowers/notes/census-proposal-hosts-floor-release.md| new file mode 100644 |
| index 000000000..50923ed15 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-hosts-floor-release.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: hosts-floor-release |
| + |
| +Ruling `census-ruling-hosts-floor-release`. 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: `.`. |
| + |
| +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. Reject 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. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Seal: `1daafee8030f9d370adf5541b5e87313523073c4afdc022d4238c3a7bc1a60ba` → `1daafee8030f9d370adf5541b5e87313523073c4afdc022d4238c3a7bc1a60ba`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-hosts-floor-release.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/notes/copy/hosts-floor-names-a-release.md b/docs/superpowers/notes/copy/hosts-floor-names-a-release.md| new file mode 100644 |
| index 000000000..d8cd9eb12 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/copy/hosts-floor-names-a-release.md |
| @@ -0,0 +1,62 @@ |
| +# The floor names a release: approved copy |
| + |
| +approved by delegated Luna pass on Paul's standing rule, 2026-11-05 (gpt-6-luna, `codex exec -s read-only`): every string approved as drafted except the README's new paragraph, rewritten by Luna and applied verbatim. Placeholders are in angle brackets. Design: docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md. |
| + |
| +## Strings |
| + |
| +C14 (`console hosts-used activate`, a console that isn't a release build, before anything is written): |
| +This console isn't a release build, so the history's floor can't name a release. Build it from a release tag with make build-console, then run this again. |
| + |
| +`console hosts-used raise-floor`: |
| +R1 <name> isn't a release tag. Name one like v0.34.4. |
| +R2 This console isn't a release build, so it can't vouch for a release. Run this with a release console. |
| +R3 This console is <build>, older than <release>. Run this with <release> or later. |
| +R4 The hostname history has no floor yet. Completing the history writes one. |
| +R5 The floor already names a release, <version>. |
| +R6 The floor doesn't name a full commit, so the checkout can't show that <release> contains it. |
| +R7 The checkout has no tag <release>. Fetch the platform repo's tags, then run this again. |
| +R8 The checkout doesn't have commit <commit>. Fetch the platform repo, then run this again. |
| +R9 The checkout's tag <release> names <tag commit>, but this console was built from <commit>. |
| +R10 <release> (<tag commit>) isn't in the history of this console's commit, <commit>. |
| +R11 <release> doesn't contain the floor's commit, <commit>. Name a later release. |
| +R12 The floor changed while this ran. Run this again. |
| +R13 The hostname history's floor is now <release> (<commit>). It was <old version> (<old commit>). |
| + |
| +B11 (`carlos accounts migrate` against a floor that names only a commit): |
| +the hostname history's floor, <floor version>, names a commit and not a release, so this carlos can't tell whether it is at or above it. give the floor a release with console hosts-used raise-floor, then run this again. |
| + |
| +N9, appended to the console binary's usage line: |
| +hosts-used raise-floor -release <vX.Y.Z> -checkout <dir> |
| + |
| +README, "Releasing the platform" step 2, last sentence: |
| +`console hosts-used activate` refuses a console that isn't a release build or doesn't name a full commit. |
| + |
| +README, "The history's floor", replacing "Completing refuses a console that doesn't name its commit.": |
| +Completing refuses a console that isn't a release build or doesn't name its commit. |
| + |
| +README, "The history's floor", new paragraph (Luna's rewrite): |
| +A floor written by a console that wasn't a release names only a commit. `carlos accounts migrate` can't tell whether a release contains a commit, so it refuses every release. Give the floor the oldest release that contains the commit. In a platform checkout with its tags fetched, `git tag --contains <commit>` lists tags that contain it; choose the oldest release by version. Then, with the deployment bucket's credentials and a release console at that release or later, run `console hosts-used raise-floor -release vX.Y.Z -checkout <checkout>`. It checks that the release contains the floor's commit and writes the release and its commit as the floor. |
| + |
| +## Luna's reply, whole |
| + |
| +``` |
| +C14 APPROVE |
| +R1 APPROVE |
| +R2 APPROVE |
| +R3 APPROVE |
| +R4 APPROVE |
| +R5 APPROVE |
| +R6 APPROVE |
| +R7 APPROVE |
| +R8 APPROVE |
| +R9 APPROVE |
| +R10 APPROVE |
| +R11 APPROVE |
| +R12 APPROVE |
| +R13 APPROVE |
| +B11 APPROVE |
| +N9 APPROVE |
| +README step 2 APPROVE |
| +README floor sentence APPROVE |
| +README new paragraph REWRITE: A floor written by a console that wasn't a release names only a commit. `carlos accounts migrate` can't tell whether a release contains a commit, so it refuses every release. Give the floor the oldest release that contains the commit. In a platform checkout with its tags fetched, `git tag --contains <commit>` lists tags that contain it; choose the oldest release by version. Then, with the deployment bucket's credentials and a release console at that release or later, run `console hosts-used raise-floor -release vX.Y.Z -checkout <checkout>`. It checks that the release contains the floor's commit and writes the release and its commit as the floor. |
| +``` |
diff --git a/docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md b/docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md| new file mode 100644 |
| index 000000000..9225b1d47 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md |
| @@ -0,0 +1,105 @@ |
| +# The hostname history's floor names a release |
| + |
| +Status: approved by Paul 2026-11-05 ("Yes" to fixing the floor check, then a |
| +patch release and roll). Branch `hosts-floor-release`. Amends the floor in |
| +`2026-10-26-nearest-region-without-claims-design.md` §4. |
| + |
| +## 1. The bug |
| + |
| +`carlos accounts migrate --app rastrillo --to bfu --dry-run` on annie |
| +(v0.34.3) refuses: "this carlos is older than the hostname history's floor, |
| +50c0cb14." Flagship's floor, `control/hosts-used/@floor`, is |
| +`{"version":"50c0cb14","commit":"50c0cb14b429…"}`. The console that completed |
| +flagship's history was rolled by `roll-console.sh`, which stamps the short |
| +sha as the version, so the floor names a commit and no release. |
| +`buildMeetsFloor` accepts a build whose commit is the floor's, or a release at |
| +or above a release floor. A release build is neither, so every release is |
| +refused, though 50c0cb14 is in every release from v0.28.29 on. The v0.34.3 |
| +roll checked the console against the floor by hand, because `ship-app.sh` |
| +does not. |
| + |
| +A binary has no git history, so "is 50c0cb14 an ancestor of my commit" cannot |
| +be answered at runtime. Only a checkout can answer it. |
| + |
| +## 2. The floor checks today |
| + |
| +| Check | Compares | Bare-commit floor | Release floor (with commit) | |
| +|---|---|---|---| |
| +| `carlos accounts migrate` (`checkMigrationFloor`) | release versions, or the floor's exact commit | refuses every release | works | |
| +| `roll-console.sh` (carloku-infrastructure) | `merge-base --is-ancestor` in the checkout | works | works (refuses a release with no commit) | |
| +| `ship-app.sh` (release console roll) | nothing | by hand | by hand | |
| + |
| +A floor that names a release and the commit its tag names satisfies both |
| +checks that exist. Dev's floor is already one (`v0.33.0`, 8294a520), so only |
| +flagship's is affected. |
| + |
| +## 3. Options |
| + |
| +1. **Teach the CLI ancestry.** Impossible without a checkout or the forge; a |
| + network call in a safety check is a new failure mode, and a list of |
| + "known ancestors" compiled into the binary goes stale. |
| +2. **Relax the CLI for bare-commit floors** (accept any release newer than |
| + some date, or than the release of the CLI that wrote the floor). Weakens |
| + the safety check on a guess. |
| +3. **Make the floor name a release** (chosen): change the data, not the |
| + check. Two parts: |
| + - `console hosts-used activate` refuses a console that is not a release |
| + build, so a new floor always names a release and its commit. It cannot |
| + recur. |
| + - `console hosts-used raise-floor -release vX.Y.Z -checkout <dir>` gives |
| + an existing commit floor the release that contains it, on the proof of |
| + the operator's checkout. |
| + |
| +## 4. raise-floor |
| + |
| +It accepts only when all hold, and writes nothing otherwise: |
| + |
| +- `-release` is a release tag, and the console running it is a release build |
| + with a full commit, at that release or later (the build cannot vouch for a |
| + release above it); |
| +- the floor exists, names no release, and names a full commit; |
| +- the checkout's `refs/tags/<release>` names a commit (through an annotated |
| + tag), and that commit is this console's own when the release is this |
| + console's, or an ancestor of this console's stamped commit when it is |
| + older. The tag is the operator's evidence; the binary's stamped commit |
| + anchors it; |
| +- the tag's commit contains the floor's commit (`git merge-base |
| + --is-ancestor`). Commits are full object names, checked with `cat-file -t` |
| + to be commits, so a ref named like one cannot stand in for it. |
| + |
| +It writes `{"version": "<release>", "commit": "<tag's commit>"}` with |
| +If-Match on the etag it read: a floor changed meanwhile is not overwritten |
| +(the history's conditional-update discipline). It takes no serve lock and no |
| +console database: only `activate` (under the lock) writes the floor besides |
| +it. So it runs where the checkout is, with the deployment bucket's |
| +credentials. |
| + |
| +The oldest release that contains the floor commit (`git tag --contains`) |
| +keeps the floor exactly where it was. Flagship's goes to v0.28.29: all 31 |
| +releases from v0.28.29 on contain 50c0cb14 and none before it does, so the |
| +release comparison accepts exactly the releases the commit check would. A |
| +build genuinely older than the floor is still refused by every check. |
| + |
| +## 5. The CLI's message |
| + |
| +Against a floor that names no release, `carlos accounts migrate` still |
| +refuses every build but the floor's commit, but says what is wrong (B11): |
| +"the hostname history's floor, 50c0cb14, names a commit and not a release, |
| +so this carlos can't tell whether it is at or above it. give the floor a |
| +release with console hosts-used raise-floor, then run this again." B10 |
| +("older than the floor … update carlos") stays for a release floor. |
| + |
| +## 6. Out of scope |
| + |
| +`ship-app.sh` (carloku-infrastructure) still checks no floor; the release |
| +recipe's console roll is the README's, and with a release floor the check is |
| +one version comparison. Left as a follow-up for that repo, named in the |
| +branch description. |
| + |
| +## 7. Census and copy |
| + |
| +The root binary changes in `accounts_hostsused.go` only (B11, one branch in |
| +`checkMigrationFloor`): census card on the branch, Astra review. The console |
| +package and binary are out of census scope. New strings C14, R1-R13 and B11: |
| +`docs/superpowers/notes/copy/hosts-floor-names-a-release.md`, delegated Luna |
| +pass. |
diff --git a/internal/console/hostsused_activate.go b/internal/console/hostsused_activate.go| index fb544b236..df6f35e6f 100644 |
| --- a/internal/console/hostsused_activate.go |
| +++ b/internal/console/hostsused_activate.go |
| @@ -96,7 +96,7 @@ type HostsActivation struct { |
| 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. |
| + // name a full commit and a release. |
| Floor provision.HostsFloor |
| } |
| @@ -303,7 +303,8 @@ 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 |
| +// refuses (each error is the operator's sentence) with a build that names |
| +// no full commit or no release, with claims or Phase 1 |
| // on, a history already active, any pending lifetime row, any unfinished |
| // move or seed, a roster changed since scanned, a closed name that is not a |
| // roster fleet, a listing of a target off the roster, a target with no good |
| @@ -314,6 +315,12 @@ func (a HostsActivation) Activate(ctx context.Context, scanned HostsRoster, list |
| if !fullCommit.MatchString(a.Floor.Commit) { |
| return 0, errors.New(msgHostsFloorNoCommit) |
| } |
| + // The floor names a release too, so every floor check can compare |
| + // versions (hostsused_floor.go): a binary cannot tell whether it |
| + // contains a bare commit. |
| + if !IsReleaseTag(a.Floor.Version) { |
| + return 0, errors.New(msgHostsFloorNotARelease) |
| + } |
| if a.HostClaim || a.MovesEnabled { |
| return 0, errors.New(msgHostsClaimsOn) |
| } |
diff --git a/internal/console/hostsused_activate_test.go b/internal/console/hostsused_activate_test.go| index 659342efa..6f3a736ee 100644 |
| --- a/internal/console/hostsused_activate_test.go |
| +++ b/internal/console/hostsused_activate_test.go |
| @@ -40,7 +40,7 @@ func invFx(t *testing.T) lifetimesFx { |
| } |
| // testFloor is the build the activation tests complete the history as. |
| -var testFloor = provision.HostsFloor{Version: "v0.0.0-test", Commit: "0123456789abcdef0123456789abcdef01234567"} |
| +var testFloor = provision.HostsFloor{Version: "v0.0.0", Commit: "0123456789abcdef0123456789abcdef01234567"} |
| func activation(l lifetimesFx) HostsActivation { |
| return HostsActivation{DB: l.fx.st, Releases: l.fx.rel, Registry: l.fx.srv.cfg.Registry, Floor: testFloor} |
diff --git a/internal/console/hostsused_floor.go b/internal/console/hostsused_floor.go| new file mode 100644 |
| index 000000000..b9e05098d |
| --- /dev/null |
| +++ b/internal/console/hostsused_floor.go |
| @@ -0,0 +1,244 @@ |
| +package console |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "errors" |
| + "fmt" |
| + "os/exec" |
| + "regexp" |
| + "strings" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// The floor names a release (design |
| +// docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md). |
| +// Every floor check but the console roll script compares release versions: |
| +// a binary has no git history, so it cannot tell whether it contains a |
| +// commit. A floor that names only a commit (flagship's, written by a console |
| +// rolled from a checkout) therefore refused every release. Activation now |
| +// writes a release floor only, and `console hosts-used raise-floor` gives an |
| +// existing commit floor the release that contains it, on the proof of an |
| +// operator's platform checkout. |
| + |
| +// The approved strings (docs/superpowers/notes/copy/hosts-floor-names-a-release.md). |
| +const ( |
| + msgHostsFloorNotARelease = "This console isn't a release build, so the history's floor can't name a release. Build it from a release tag with make build-console, then run this again." // C14 |
| + msgFloorBuildNotARelease = "This console isn't a release build, so it can't vouch for a release. Run this with a release console." // R2 |
| + msgFloorNone = "The hostname history has no floor yet. Completing the history writes one." // R4 |
| + msgFloorChanged = "The floor changed while this ran. Run this again." // R12 |
| +) |
| + |
| +func msgFloorNotARelease(name string) string { // R1 |
| + return name + " isn't a release tag. Name one like v0.34.4." |
| +} |
| + |
| +func msgFloorBuildOlder(build, rel string) string { // R3 |
| + return "This console is " + build + ", older than " + rel + ". Run this with " + rel + " or later." |
| +} |
| + |
| +func msgFloorAlreadyARelease(v string) string { // R5 |
| + return "The floor already names a release, " + v + "." |
| +} |
| + |
| +func msgFloorNoFullCommit(rel string) string { // R6 |
| + return "The floor doesn't name a full commit, so the checkout can't show that " + rel + " contains it." |
| +} |
| + |
| +func msgFloorNoTag(rel string) string { // R7 |
| + return "The checkout has no tag " + rel + ". Fetch the platform repo's tags, then run this again." |
| +} |
| + |
| +func msgFloorCheckoutMissing(commit string) string { // R8 |
| + return "The checkout doesn't have commit " + commit + ". Fetch the platform repo, then run this again." |
| +} |
| + |
| +func msgFloorTagNotThisBuild(rel, tagged, built string) string { // R9 |
| + return "The checkout's tag " + rel + " names " + tagged + ", but this console was built from " + built + "." |
| +} |
| + |
| +func msgFloorTagNotInBuild(rel, tagged, built string) string { // R10 |
| + return rel + " (" + tagged + ") isn't in the history of this console's commit, " + built + "." |
| +} |
| + |
| +func msgFloorNotContained(rel, floor string) string { // R11 |
| + return rel + " doesn't contain the floor's commit, " + floor + ". Name a later release." |
| +} |
| + |
| +// MsgFloorRaised is R13, what raise-floor prints when it has written. |
| +func MsgFloorRaised(from, to provision.HostsFloor) string { |
| + return "The hostname history's floor is now " + to.Version + " (" + to.Commit + "). It was " + from.Version + " (" + from.Commit + ")." |
| +} |
| + |
| +// releaseTagShape is a release's version stamp ("v0.34.4"), as update.go's. |
| +var releaseTagShape = regexp.MustCompile(`^v[0-9]+\.[0-9]+\.[0-9]+$`) |
| + |
| +// releaseTag parses a release tag; ok is false for anything else. |
| +func releaseTag(s string) (release.SemVer, bool) { |
| + if !releaseTagShape.MatchString(s) { |
| + return release.SemVer{}, false |
| + } |
| + return release.ParseSemVer(s[1:]) |
| +} |
| + |
| +// IsReleaseTag reports whether s is a release's version stamp. |
| +func IsReleaseTag(s string) bool { |
| + _, ok := releaseTag(s) |
| + return ok |
| +} |
| + |
| +// FloorCheckout answers what raise-floor asks of an operator's platform |
| +// checkout. Commits are full object names. |
| +type FloorCheckout interface { |
| + // TagCommit is the commit refs/tags/<tag> names, or ErrCheckoutNoTag. |
| + TagCommit(ctx context.Context, tag string) (string, error) |
| + // Contains reports whether ancestor is descendant or one of its |
| + // ancestors. A commit the checkout does not have is a |
| + // CheckoutMissingError. |
| + Contains(ctx context.Context, descendant, ancestor string) (bool, error) |
| +} |
| + |
| +// ErrCheckoutNoTag is a tag the checkout does not have. |
| +var ErrCheckoutNoTag = errors.New("console: the checkout has no such tag") |
| + |
| +// CheckoutMissingError is a commit the checkout does not have. |
| +type CheckoutMissingError struct{ Commit string } |
| + |
| +func (e CheckoutMissingError) Error() string { |
| + return "console: the checkout has no commit " + e.Commit |
| +} |
| + |
| +// RaiseHostsFloor gives a floor that names only a commit the release rel, |
| +// and the commit rel's tag names, when the checkout shows that commit |
| +// contains the floor's and build (this console) is rel or later: rel's own |
| +// commit when it is rel, or a descendant of it. The checkout's tag is the |
| +// operator's evidence; the build's stamped commit anchors it. The write is |
| +// conditional on the floor read, so a floor changed meanwhile is not |
| +// overwritten. Every refusal writes nothing. |
| +func RaiseHostsFloor(ctx context.Context, store release.Store, build provision.HostsFloor, rel string, co FloorCheckout) (from, to provision.HostsFloor, err error) { |
| + want, ok := releaseTag(rel) |
| + if !ok { |
| + return from, to, errors.New(msgFloorNotARelease(rel)) |
| + } |
| + have, ok := releaseTag(build.Version) |
| + if !ok || !fullCommit.MatchString(build.Commit) { |
| + return from, to, errors.New(msgFloorBuildNotARelease) |
| + } |
| + if have.Compare(want) < 0 { |
| + return from, to, errors.New(msgFloorBuildOlder(build.Version, rel)) |
| + } |
| + floor, etag, err := provision.ReadHostsFloor(ctx, store) |
| + if err != nil { |
| + return from, to, fmt.Errorf("read the floor: %w", err) |
| + } |
| + if floor == nil { |
| + return from, to, errors.New(msgFloorNone) |
| + } |
| + from = *floor |
| + if IsReleaseTag(floor.Version) { |
| + return from, to, errors.New(msgFloorAlreadyARelease(floor.Version)) |
| + } |
| + if !fullCommit.MatchString(floor.Commit) { |
| + return from, to, errors.New(msgFloorNoFullCommit(rel)) |
| + } |
| + tagged, err := co.TagCommit(ctx, rel) |
| + if errors.Is(err, ErrCheckoutNoTag) { |
| + return from, to, errors.New(msgFloorNoTag(rel)) |
| + } |
| + if err != nil { |
| + return from, to, err |
| + } |
| + if have.Compare(want) == 0 { |
| + if tagged != build.Commit { |
| + return from, to, errors.New(msgFloorTagNotThisBuild(rel, tagged, build.Commit)) |
| + } |
| + } else if ok, err := co.Contains(ctx, build.Commit, tagged); err != nil { |
| + return from, to, checkoutRefusal(err) |
| + } else if !ok { |
| + return from, to, errors.New(msgFloorTagNotInBuild(rel, tagged, build.Commit)) |
| + } |
| + if ok, err := co.Contains(ctx, tagged, floor.Commit); err != nil { |
| + return from, to, checkoutRefusal(err) |
| + } else if !ok { |
| + return from, to, errors.New(msgFloorNotContained(rel, floor.Commit)) |
| + } |
| + to = provision.HostsFloor{Version: rel, Commit: tagged} |
| + if _, err := provision.WriteHostsFloor(ctx, store, to, etag); errors.Is(err, release.ErrCASConflict) { |
| + return from, provision.HostsFloor{}, errors.New(msgFloorChanged) |
| + } else if err != nil { |
| + return from, provision.HostsFloor{}, fmt.Errorf("write the floor: %w", err) |
| + } |
| + return from, to, nil |
| +} |
| + |
| +func checkoutRefusal(err error) error { |
| + var missing CheckoutMissingError |
| + if errors.As(err, &missing) { |
| + return errors.New(msgFloorCheckoutMissing(missing.Commit)) |
| + } |
| + return err |
| +} |
| + |
| +// GitCheckout is a platform checkout on disk, read with git. |
| +type GitCheckout struct{ Dir string } |
| + |
| +func (g GitCheckout) git(ctx context.Context, args ...string) (string, int, error) { |
| + cmd := exec.CommandContext(ctx, "git", append([]string{"-C", g.Dir}, args...)...) |
| + var stderr bytes.Buffer |
| + cmd.Stderr = &stderr |
| + out, err := cmd.Output() |
| + var exit *exec.ExitError |
| + if errors.As(err, &exit) { |
| + return strings.TrimSpace(string(out)), exit.ExitCode(), fmt.Errorf("git %s: %s", strings.Join(args, " "), strings.TrimSpace(stderr.String())) |
| + } |
| + if err != nil { |
| + return "", -1, fmt.Errorf("git %s: %w", strings.Join(args, " "), err) |
| + } |
| + return strings.TrimSpace(string(out)), 0, nil |
| +} |
| + |
| +// TagCommit resolves refs/tags/<tag> to the commit it names, through an |
| +// annotated tag. Only a release tag is asked for. |
| +func (g GitCheckout) TagCommit(ctx context.Context, tag string) (string, error) { |
| + if !IsReleaseTag(tag) { |
| + return "", ErrCheckoutNoTag |
| + } |
| + if _, _, err := g.git(ctx, "rev-parse", "--git-dir"); err != nil { |
| + return "", err |
| + } |
| + out, code, err := g.git(ctx, "rev-parse", "--verify", "--quiet", "--end-of-options", "refs/tags/"+tag+"^{commit}") |
| + if code == 1 && out == "" { |
| + return "", ErrCheckoutNoTag |
| + } |
| + if err != nil { |
| + return "", err |
| + } |
| + if !fullCommit.MatchString(out) { |
| + return "", fmt.Errorf("git resolved %s to %q, not a commit", tag, out) |
| + } |
| + return out, nil |
| +} |
| + |
| +// Contains is git merge-base --is-ancestor over two full object names, |
| +// each first checked to be a commit object in the checkout. A full object |
| +// name is read as that object, never through a ref named like it. |
| +func (g GitCheckout) Contains(ctx context.Context, descendant, ancestor string) (bool, error) { |
| + for _, c := range []string{descendant, ancestor} { |
| + if !fullCommit.MatchString(c) { |
| + return false, CheckoutMissingError{Commit: c} |
| + } |
| + if t, _, err := g.git(ctx, "cat-file", "-t", c); err != nil || t != "commit" { |
| + return false, CheckoutMissingError{Commit: c} |
| + } |
| + } |
| + _, code, err := g.git(ctx, "merge-base", "--is-ancestor", ancestor, descendant) |
| + switch code { |
| + case 0: |
| + return true, nil |
| + case 1: |
| + return false, nil |
| + } |
| + return false, err |
| +} |
diff --git a/internal/console/hostsused_floor_test.go b/internal/console/hostsused_floor_test.go| new file mode 100644 |
| index 000000000..627ad8de9 |
| --- /dev/null |
| +++ b/internal/console/hostsused_floor_test.go |
| @@ -0,0 +1,293 @@ |
| +package console |
| + |
| +// The floor names a release (docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md): |
| +// RaiseHostsFloor turns a floor that names only a commit into one that names |
| +// a release containing it, on an operator checkout's proof, and Activate |
| +// writes a release floor only. |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "os/exec" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// Commits of a fake history: c0 <- floorC <- c2 <- c3 <- c4, linear. |
| +const ( |
| + c0 = "1000000000000000000000000000000000000000" |
| + floorC = "2000000000000000000000000000000000000000" |
| + c2 = "3000000000000000000000000000000000000000" |
| + c3 = "4000000000000000000000000000000000000000" |
| + c4 = "5000000000000000000000000000000000000000" |
| + stray = "6000000000000000000000000000000000000000" // not in the checkout |
| +) |
| + |
| +// fakeCheckout is a linear history and its tags. |
| +type fakeCheckout struct { |
| + order []string |
| + tags map[string]string |
| + during func() // runs inside the first Contains, to race the write |
| +} |
| + |
| +func newFakeCheckout() *fakeCheckout { |
| + return &fakeCheckout{ |
| + order: []string{c0, floorC, c2, c3, c4}, |
| + tags: map[string]string{"v0.28.28": c0, "v0.28.29": c2, "v0.34.3": c3, "v0.34.4": c4}, |
| + } |
| +} |
| + |
| +func (f *fakeCheckout) TagCommit(_ context.Context, tag string) (string, error) { |
| + c, ok := f.tags[tag] |
| + if !ok { |
| + return "", ErrCheckoutNoTag |
| + } |
| + return c, nil |
| +} |
| + |
| +func (f *fakeCheckout) Contains(_ context.Context, descendant, ancestor string) (bool, error) { |
| + if f.during != nil { |
| + run := f.during |
| + f.during = nil |
| + run() |
| + } |
| + at := map[string]int{} |
| + for i, c := range f.order { |
| + at[c] = i |
| + } |
| + d, ok := at[descendant] |
| + if !ok { |
| + return false, CheckoutMissingError{Commit: descendant} |
| + } |
| + a, ok := at[ancestor] |
| + if !ok { |
| + return false, CheckoutMissingError{Commit: ancestor} |
| + } |
| + return a <= d, nil |
| +} |
| + |
| +var bareFloor = provision.HostsFloor{Version: floorC[:8], Commit: floorC} |
| + |
| +func floorStore(t *testing.T, f *provision.HostsFloor) release.Store { |
| + t.Helper() |
| + st := release.NewDirStore(t.TempDir()) |
| + if f != nil { |
| + if _, err := provision.WriteHostsFloor(context.Background(), st, *f, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + return st |
| +} |
| + |
| +func readFloor(t *testing.T, st release.Store) *provision.HostsFloor { |
| + t.Helper() |
| + f, _, err := provision.ReadHostsFloor(context.Background(), st) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return f |
| +} |
| + |
| +// TestRaiseFloorNamesAReleaseThatContainsIt: a floor naming only a commit |
| +// becomes the named release and the commit its tag names, when that |
| +// release contains the floor's commit and this console is that release or |
| +// later. |
| +func TestRaiseFloorNamesAReleaseThatContainsIt(t *testing.T) { |
| + for _, c := range []struct { |
| + name string |
| + build provision.HostsFloor |
| + rel string |
| + want provision.HostsFloor |
| + }{ |
| + {"an older release than this console", provision.HostsFloor{Version: "v0.34.4", Commit: c4}, "v0.28.29", provision.HostsFloor{Version: "v0.28.29", Commit: c2}}, |
| + {"this console's own release", provision.HostsFloor{Version: "v0.34.4", Commit: c4}, "v0.34.4", provision.HostsFloor{Version: "v0.34.4", Commit: c4}}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + st := floorStore(t, &bareFloor) |
| + from, to, err := RaiseHostsFloor(context.Background(), st, c.build, c.rel, newFakeCheckout()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if from != bareFloor || to != c.want { |
| + t.Fatalf("raised %+v to %+v, want %+v to %+v", from, to, bareFloor, c.want) |
| + } |
| + if got := readFloor(t, st); got == nil || *got != c.want { |
| + t.Fatalf("floor = %+v, want %+v", got, c.want) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestRaiseFloorRefuses: every refusal writes nothing, and says why. |
| +func TestRaiseFloorRefuses(t *testing.T) { |
| + release4 := provision.HostsFloor{Version: "v0.34.4", Commit: c4} |
| + releaseFloor := provision.HostsFloor{Version: "v0.33.0", Commit: c0} |
| + for _, c := range []struct { |
| + name string |
| + floor *provision.HostsFloor |
| + build provision.HostsFloor |
| + rel string |
| + edit func(*fakeCheckout) |
| + want string |
| + }{ |
| + {"a name that is not a release", &bareFloor, release4, "v0.34", nil, msgFloorNotARelease("v0.34")}, |
| + {"a branch name", &bareFloor, release4, "main", nil, msgFloorNotARelease("main")}, |
| + {"a dev console", &bareFloor, provision.HostsFloor{Version: "dev", Commit: c4}, "v0.28.29", nil, msgFloorBuildNotARelease}, |
| + {"a console stamped with a commit", &bareFloor, provision.HostsFloor{Version: c4[:8], Commit: c4}, "v0.28.29", nil, msgFloorBuildNotARelease}, |
| + {"a console with no full commit", &bareFloor, provision.HostsFloor{Version: "v0.34.4", Commit: c4[:12]}, "v0.28.29", nil, msgFloorBuildNotARelease}, |
| + {"a console older than the release", &bareFloor, provision.HostsFloor{Version: "v0.34.3", Commit: c3}, "v0.34.4", nil, msgFloorBuildOlder("v0.34.3", "v0.34.4")}, |
| + {"no floor", nil, release4, "v0.28.29", nil, msgFloorNone}, |
| + {"a floor that names a release", &releaseFloor, release4, "v0.28.29", nil, msgFloorAlreadyARelease("v0.33.0")}, |
| + {"a floor with no full commit", &provision.HostsFloor{Version: "50c0cb14", Commit: "50c0cb14"}, release4, "v0.28.29", nil, msgFloorNoFullCommit("v0.28.29")}, |
| + {"no such tag", &bareFloor, release4, "v0.29.0", nil, msgFloorNoTag("v0.29.0")}, |
| + {"a release without the floor's commit", &bareFloor, release4, "v0.28.28", nil, msgFloorNotContained("v0.28.28", floorC)}, |
| + {"the tag is not this console's commit", &bareFloor, release4, "v0.34.4", func(f *fakeCheckout) { f.tags["v0.34.4"] = c3 }, msgFloorTagNotThisBuild("v0.34.4", c3, c4)}, |
| + {"the tag is after this console's commit", &bareFloor, release4, "v0.28.29", func(f *fakeCheckout) { f.order = []string{c0, floorC, c4, c2} }, msgFloorTagNotInBuild("v0.28.29", c2, c4)}, |
| + {"this console's commit is not in the checkout", &bareFloor, provision.HostsFloor{Version: "v0.34.4", Commit: stray}, "v0.28.29", nil, msgFloorCheckoutMissing(stray)}, |
| + {"the floor's commit is not in the checkout", &provision.HostsFloor{Version: stray[:8], Commit: stray}, release4, "v0.28.29", nil, msgFloorCheckoutMissing(stray)}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + st := floorStore(t, c.floor) |
| + co := newFakeCheckout() |
| + if c.edit != nil { |
| + c.edit(co) |
| + } |
| + _, _, err := RaiseHostsFloor(context.Background(), st, c.build, c.rel, co) |
| + if err == nil || err.Error() != c.want { |
| + t.Fatalf("err = %v, want %q", err, c.want) |
| + } |
| + got := readFloor(t, st) |
| + if (got == nil) != (c.floor == nil) || (got != nil && *got != *c.floor) { |
| + t.Fatalf("floor = %+v, want it unchanged at %+v", got, c.floor) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestRaiseFloorLosesARace: a floor that changes between the read and the |
| +// write is not overwritten (the history's conditional update). |
| +func TestRaiseFloorLosesARace(t *testing.T) { |
| + st := floorStore(t, &bareFloor) |
| + other := provision.HostsFloor{Version: "v0.30.0", Commit: c2} |
| + co := newFakeCheckout() |
| + co.during = func() { |
| + _, etag, err := provision.ReadHostsFloor(context.Background(), st) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := provision.WriteHostsFloor(context.Background(), st, other, etag); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + _, _, err := RaiseHostsFloor(context.Background(), st, provision.HostsFloor{Version: "v0.34.4", Commit: c4}, "v0.28.29", co) |
| + if err == nil || err.Error() != msgFloorChanged { |
| + t.Fatalf("err = %v, want %q", err, msgFloorChanged) |
| + } |
| + if got := readFloor(t, st); got == nil || *got != other { |
| + t.Fatalf("floor = %+v, want the other writer's %+v", got, other) |
| + } |
| +} |
| + |
| +// TestActivateRefusesABuildThatIsNotARelease: the floor activation writes |
| +// names a release, so every floor check can compare versions. A console |
| +// that is not a release build refuses before anything is written. |
| +func TestActivateRefusesABuildThatIsNotARelease(t *testing.T) { |
| + for _, v := range []string{"dev", "50c0cb14", "v0.0.0-test", "0.34.4", ""} { |
| + t.Run("version "+v, func(t *testing.T) { |
| + l := invFx(t) |
| + a := activation(l) |
| + a.Floor = provision.HostsFloor{Version: v, Commit: testFloor.Commit} |
| + _, err := a.Activate(context.Background(), rosterOf(t, l), clean([]string{"kept.shop.example.com.db"}, nil), nil) |
| + refusedWith(t, err, msgHostsFloorNotARelease) |
| + 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) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// gitRepo is a real checkout: a <- b <- c on main, d on a side branch off |
| +// a, tags on b and c, and a branch named like c's commit pointing at a. |
| +func gitRepo(t *testing.T) (dir string, a, b, c, d string) { |
| + t.Helper() |
| + if _, err := exec.LookPath("git"); err != nil { |
| + t.Skip("git is not installed") |
| + } |
| + dir = filepath.Join(t.TempDir(), "platform") |
| + git := func(args ...string) string { |
| + t.Helper() |
| + cmd := exec.Command("git", append([]string{"-C", dir, "-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false", "-c", "tag.gpgsign=false"}, args...)...) |
| + cmd.Env = append(cmd.Environ(), "GIT_CONFIG_NOSYSTEM=1", "GIT_CONFIG_GLOBAL=/dev/null") |
| + out, err := cmd.CombinedOutput() |
| + if err != nil { |
| + t.Fatalf("git %v: %v\n%s", args, err, out) |
| + } |
| + return strings.TrimSpace(string(out)) |
| + } |
| + if out, err := exec.Command("git", "init", "-q", "-b", "main", dir).CombinedOutput(); err != nil { |
| + t.Fatalf("git init: %v\n%s", err, out) |
| + } |
| + commit := func(msg string) string { |
| + git("commit", "-q", "--allow-empty", "-m", msg) |
| + return git("rev-parse", "HEAD") |
| + } |
| + a = commit("a") |
| + b = commit("b") |
| + git("tag", "-a", "v1.0.0", "-m", "carlos v1.0.0") |
| + c = commit("c") |
| + git("tag", "v1.1.0") |
| + git("checkout", "-q", "-b", "side", a) |
| + d = commit("d") |
| + git("checkout", "-q", "main") |
| + git("branch", c, a) |
| + return dir, a, b, c, d |
| +} |
| + |
| +// TestGitCheckout: tags resolve to the commit they name, annotated or not; |
| +// commits are found by object name only, never through a ref named like |
| +// one; ancestry is git's. |
| +func TestGitCheckout(t *testing.T) { |
| + dir, a, b, c, d := gitRepo(t) |
| + co := GitCheckout{Dir: dir} |
| + ctx := context.Background() |
| + for tag, want := range map[string]string{"v1.0.0": b, "v1.1.0": c} { |
| + if got, err := co.TagCommit(ctx, tag); err != nil || got != want { |
| + t.Errorf("TagCommit(%s) = %q %v, want %s", tag, got, err, want) |
| + } |
| + } |
| + if got, err := co.TagCommit(ctx, "v2.0.0"); !errors.Is(err, ErrCheckoutNoTag) { |
| + t.Errorf("TagCommit(v2.0.0) = %q %v, want ErrCheckoutNoTag", got, err) |
| + } |
| + for _, x := range []struct { |
| + desc, anc string |
| + want bool |
| + }{{c, a, true}, {c, b, true}, {b, b, true}, {a, c, false}, {d, b, false}, {d, a, true}} { |
| + if got, err := co.Contains(ctx, x.desc, x.anc); err != nil || got != x.want { |
| + t.Errorf("Contains(%s, %s) = %v %v, want %v", x.desc[:7], x.anc[:7], got, err, x.want) |
| + } |
| + } |
| + // The branch named like c points at a: c is still the commit c. |
| + if got, err := co.Contains(ctx, c, b); err != nil || !got { |
| + t.Errorf("Contains(c, b) through a branch named c = %v %v, want true", got, err) |
| + } |
| + var missing CheckoutMissingError |
| + if _, err := co.Contains(ctx, stray, a); !errors.As(err, &missing) || missing.Commit != stray { |
| + t.Errorf("Contains(stray, a) = %v, want CheckoutMissingError for %s", err, stray) |
| + } |
| + if _, err := co.Contains(ctx, c, stray); !errors.As(err, &missing) || missing.Commit != stray { |
| + t.Errorf("Contains(c, stray) = %v, want CheckoutMissingError for %s", err, stray) |
| + } |
| + if _, err := (GitCheckout{Dir: filepath.Join(dir, "nope")}).TagCommit(ctx, "v1.0.0"); err == nil || errors.Is(err, ErrCheckoutNoTag) { |
| + t.Errorf("TagCommit in no checkout = %v, want a failure that is not 'no tag'", err) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index cd8766e73..bc956918e 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -93,3 +93,4 @@ plan14-root-reads-static-markdown-twins.tsv ec831d3206622f34511bfbc2ec0cccb131fb |
| plan14-root-reads-agent-start-demo-1-followups.tsv ec831d3206622f34511bfbc2ec0cccb131fbd3861ec4c6a33a2dc6dff9a1791e |
| plan14-root-reads-region-ha-p3b1-f4.tsv 71bbbf68863266ffab90211a00aff2f1b694bf39bb4bd62ea565c168ba884564 |
| plan14-root-reads-agent-start-demo-2.tsv 1daafee8030f9d370adf5541b5e87313523073c4afdc022d4238c3a7bc1a60ba |
| +plan14-root-reads-hosts-floor-release.tsv 1daafee8030f9d370adf5541b5e87313523073c4afdc022d4238c3a7bc1a60ba |
diff --git a/internal/provision/testdata/plan14-root-reads-hosts-floor-release.tsv b/internal/provision/testdata/plan14-root-reads-hosts-floor-release.tsv| new file mode 100644 |
| index 000000000..fb2a41ef6 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-hosts-floor-release.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay hosts-floor-release, written by census-propose (#369). census-ruling-hosts-floor-release, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-hosts-floor-release.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage . 8d732496b55a5967e0f7328c1afe6a1466c1ff427d49ad73932b84cbc5db3695 |