carlos / platform Public

raise-floor: trust only the checkout's own commit history (Astra r2)

Astra r2 NOT READY: r1 resolved; P1-1 git grafts or replace objects could
fake the ancestry proof; P1-2 a 40-hex name in a SHA-256 checkout (or the
reverse) is resolved through refs.

GitCheckout, the one place raise-floor asks git: drops the caller's GIT_*
environment, sets GIT_NO_REPLACE_OBJECTS, core.useReplaceRefs=false and
core.commitGraph=false, refuses a checkout with a grafts file (R14, Luna
pass 3), and looks a commit up only as an object name of the checkout's
hash format that resolves to itself. Regressions watched to fail on
c5a9a576.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 923067dc89df26dd42b05429d86dc578ce61b652 parent 109c4f9
6 files changed, +339 −10
  • docs/superpowers/notes/copy/hosts-floor-names-a-release.md +8 −1
  • docs/superpowers/notes/reviews/ASTRA-FINDINGS-hosts-floor-release-r2.md +29 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-hosts-floor-release-R3.md +102 −0
  • docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md +7 −2
  • internal/console/hostsused_floor.go +80 −7
  • internal/console/hostsused_floor_test.go +113 −0
diff --git a/docs/superpowers/notes/copy/hosts-floor-names-a-release.md b/docs/superpowers/notes/copy/hosts-floor-names-a-release.md
index 58c4fe309..f2dfa51cc 100644
--- a/docs/superpowers/notes/copy/hosts-floor-names-a-release.md
+++ b/docs/superpowers/notes/copy/hosts-floor-names-a-release.md
@@ -1,6 +1,6 @@
# 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`). Pass 1: every string approved as drafted except the README's new paragraph, rewritten by Luna. Pass 2, after Astra r1 restricted raise-floor to the running console's release: C14 (now names SHA=<tag>, Astra r1 P2-3) approved; R3 and the README paragraph rewritten by Luna. R10 was removed. All applied verbatim. Placeholders are in angle brackets. Design: docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md.
+approved by delegated Luna pass on Paul's standing rule, 2026-11-05 (gpt-6-luna, `codex exec -s read-only`). Pass 1: every string approved as drafted except the README's new paragraph, rewritten by Luna. Pass 2, after Astra r1 restricted raise-floor to the running console's release: C14 (now names SHA=<tag>, Astra r1 P2-3) approved; R3 and the README paragraph rewritten by Luna. R10 was removed. Pass 3, after Astra r2: R14 (a grafted checkout) rewritten by Luna. All applied verbatim. Placeholders are in angle brackets. Design: docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md.
## Strings
@@ -20,6 +20,7 @@ R9 The checkout's tag <release> names <tag commit>, but this console was built
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>).
+R14 The checkout has a grafts file, which changes Git's commit history. Ancestry checks in this checkout cannot be trusted. Use a fresh clone of the platform repository.
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.
@@ -69,3 +70,9 @@ C14 APPROVE
R3 REWRITE: This console is <build>, not <release>. Run this with the <release> console. Its stamped commit identifies the commit for that release.
README 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 a release: with the deployment bucket's credentials and the vX.Y.Z release console, run `console hosts-used raise-floor -release vX.Y.Z -checkout <checkout>` in a platform checkout with its tags fetched. It accepts only the running console's release. The console's stamped commit identifies its source commit, and the checkout's tag must agree; a local tag alone isn't trusted because it can be moved. It checks that this commit contains the floor's commit, then writes the release and commit as the floor. Builds older than that release are refused from then on, so roll it out to every console and box first.
```
+
+Pass 3:
+
+```
+R14 REWRITE: The checkout has a grafts file, which changes Git's commit history. Ancestry checks in this checkout cannot be trusted. Use a fresh clone of the platform repository.
+```
diff --git a/docs/superpowers/notes/reviews/ASTRA-FINDINGS-hosts-floor-release-r2.md b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-hosts-floor-release-r2.md
new file mode 100644
index 000000000..cd4ce7ea5
--- /dev/null
+++ b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-hosts-floor-release-r2.md
@@ -0,0 +1,29 @@
+R1 P1-1 — **Resolved:** the requested release must equal the running console’s release, and its tag must match the stamped commit (`hostsused_floor.go:125–150`).
+R1 P1-2 — **Resolved:** the binary test now shares its helper’s `!windows` constraint; Windows `go list` excludes it.
+R1 P2-3 — **Resolved:** C14 specifies `make build-console SHA=<tag>`, matching the Makefile’s version stamping.
+
+1. **P1 — Raise-floor: Git grafts can falsify the ancestry proof.**
+
+ **Evidence:** [hostsused_floor.go:177](/home/paulca/amadan.net/carlos/platform-hosts-floor-release/internal/console/hostsused_floor.go:177) inherits Git’s environment and repository configuration. [Line 226](/home/paulca/amadan.net/carlos/platform-hosts-floor-release/internal/console/hostsused_floor.go:226) accepts Git’s ancestry result without excluding grafts or replacement objects.
+
+ **Failure scenario:** a release console’s genuine commit lacks the existing floor commit, but the operator’s checkout supplies rewritten ancestry. The tag still matches the stamped commit; `Contains` succeeds; the verb writes a release floor that admits a build lacking the old floor. Read-only reproduction confirmed the mechanism: ancestry of `50c0cb14` in `v0.28.28` returned exit 1 normally and exit 0 with an inherited `GIT_GRAFT_FILE`, without changing either object or tag.
+
+ **Fix:** refuse grafted history before checking ancestry and disable replacement objects for every Git invocation. Cover repository-local grafts and inherited overrides, with a regression proving refusal leaves the floor unchanged.
+
+ **Fault family:** authentic ancestry—the accepted release must contain the original floor commit.
+
+2. **P1 — Raise-floor: “full commit” validation permits ref substitution across hash formats.**
+
+ **Evidence:** [hostsused_activate.go:302](/home/paulca/amadan.net/carlos/platform-hosts-floor-release/internal/console/hostsused_activate.go:302) accepts either 40 or 64 hex characters without checking the checkout’s object format. [hostsused_floor.go:217](/home/paulca/amadan.net/carlos/platform-hosts-floor-release/internal/console/hostsused_floor.go:217) passes these strings directly to `cat-file` and `merge-base`. Git treats a hexadecimal string as an exact object ID only when its length matches the repository’s hash format; otherwise ref lookup remains possible. Verified in Git’s resolver: [https://raw.githubusercontent.com/git/git/v2.43.0/object-name.c](https://raw.githubusercontent.com/git/git/v2.43.0/object-name.c).
+
+ **Failure scenario:** a SHA-256 checkout contains a branch named after the old floor’s 40-character SHA-1 ID, pointing at an ancestor of the running console’s genuine 64-character commit. Both Git checks follow that branch and succeed, although the old floor object is absent. The tag/stamp equality check does not catch this substitution.
+
+ **Fix:** require both commits to match the checkout’s object format and resolve them through object-only lookup, requiring exact identity before ancestry checking. Add SHA-256 and mismatched-format ref regressions.
+
+ **Fault family:** object identity—a ref must never substitute for the stored floor commit.
+
+Targeted Go tests could not start: Go’s temporary work directory was denied by the read-only sandbox. Review proceeded by reading and read-only checks. The 31-release ancestry claim and changed Go files’ formatting were verified. HEAD `109c4f97` differs from reviewed implementation `c5a9a576` only by the round-2 brief.
+
+**Census envelope `.`: APPROVE.** I read [accounts_hostsused.go:33](/home/paulca/amadan.net/carlos/platform-hosts-floor-release/accounts_hostsused.go:33) through line 70 and [hostsused.go:205](/home/paulca/amadan.net/carlos/platform-hosts-floor-release/internal/provision/hostsused.go:205) through line 218. Acceptance and reads remain unchanged; only refusal wording changes. No new root access or weakened check appears. The independently recomputed envelope matches `8d732496…bc5db3695` in the overlay, and its files are unchanged since round 1.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-hosts-floor-release-R3.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-hosts-floor-release-R3.md
new file mode 100644
index 000000000..c408333ee
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-hosts-floor-release-R3.md
@@ -0,0 +1,102 @@
+# Review brief: branch hosts-floor-release (the floor names a release), round 3 of 3
+
+Repo carlos/platform, branch `hosts-floor-release`, commit <TIP>.
+Under review: the diff `origin/main..<TIP>` (main f86e9792), with the design note
+`docs/superpowers/specs/2026-11-05-hosts-floor-names-a-release-design.md` and the census card
+`docs/superpowers/notes/census-proposal-hosts-floor-release.md`.
+Authorities: `docs/superpowers/specs/2026-10-26-nearest-region-without-claims-design.md` §4 (the
+floor), README "The history's floor", AGENTS.md "The census" and "Stopping rules".
+
+You are an independent reviewer. Read the design note, then the code it names, and check every
+claim against that code. You are also the census reviewer for this branch (other model family
+than the Claude author).
+
+## Fixed: do not re-argue
+
+- Paul approved fixing the floor check on 2026-11-05 (the design note's status line). The choice
+ of changing the floor's data (a release floor) over teaching the CLI ancestry is the design;
+ report only mechanisms that fail its stated invariant.
+- Copy is approved by a delegated Luna pass (`docs/superpowers/notes/copy/hosts-floor-names-a-release.md`);
+ report a copy problem only if a sentence is false.
+- `ship-app.sh` (carloku-infrastructure) is out of scope (design §6).
+
+## What to check
+
+1. **Safety of raise-floor** (`internal/console/hostsused_floor.go`, `RaiseHostsFloor`,
+ `GitCheckout`). Invariant: after a raise, every build the release comparison accepts contains
+ the old floor commit, and a build genuinely older than the floor is still refused by every
+ floor check (`checkMigrationFloor`, roll-console.sh's commit ancestry). Can a raise write a
+ floor whose release does not contain the old floor commit? Can a ref, a moved/lightweight
+ tag, an abbreviated or ambiguous object name, a SHA-256 repo, or git's exit codes make it
+ accept wrongly? Is the check order such that every refusal writes nothing?
+2. **Conditional update.** The write is If-Match on the etag read; is there any path that writes
+ blind (empty etag on an existing floor; ErrCASConflict mapping; a floor deleted meanwhile)?
+3. **No serve lock.** The verb takes neither the console's serve lock nor its database. Is it
+ true that only `Activate` (under the lock) and this verb write `@floor`?
+4. **Activate.** The new release check (`hostsused_activate.go`) comes before any write; tests
+ (`TestActivateRefusesABuildThatIsNotARelease`) prove nothing is written. Does any existing
+ caller or test (cmd/console builds, scan test) still activate a non-release build?
+5. **CLI** (`accounts_hostsused.go`): B11 changes only the message for a floor whose version is
+ not a release; is any build now accepted that was refused before?
+6. **Census card.** Only envelope `.` re-pinned, no unit changed. Verdict for envelope `.`: does
+ the change let root open, run, query or follow anything new from a path or input a tenant,
+ app or box agent can create, write or name, or weaken any check root relies on?
+7. **README and design note** claims true against the code (including "all 31 releases from
+ v0.28.29 on contain 50c0cb14 and none before it does": `git tag --contains 50c0cb14`).
+
+## Round 3
+
+Earlier rounds: round 1, `docs/superpowers/notes/reviews/ASTRA-FINDINGS-hosts-floor-release-r1.md`
+(P1-1 moved older tag, P1-2 Windows test compile, P2-3 C14; fixed in c5a9a576); round 2,
+`docs/superpowers/notes/reviews/ASTRA-FINDINGS-hosts-floor-release-r2.md` (r1 all resolved; P1-1 git
+grafts / replace objects, P1-2 object names of the other hash format resolved through refs; census
+envelope `.` APPROVED). Round 2's fixes are in the tip's last code commit: `GitCheckout` (one place)
+drops the caller's GIT_* environment, turns replace refs and the commit-graph off, refuses a grafts
+file (R14), and looks a commit up only as an object name of the checkout's own hash format that must
+resolve to itself; regressions in `internal/console/hostsused_floor_test.go`
+(`TestGitCheckoutIgnoresRewrittenHistory`, `TestGitCheckoutObjectNamesMatchItsFormat`,
+`TestRaiseFloorRefusesAGraftedCheckout`), each watched to fail on c5a9a576. The root package is
+unchanged since round 1.
+
+This is the last round in budget (AGENTS.md stopping rules). Rounds 1 and 2 both found P1s against
+one invariant ("the floor raise-floor writes must be a release whose every build contains the old
+floor commit"; trust boundary: the operator's checkout as evidence). Judge round 2's fixes and
+anything still outstanding against that invariant. Weigh the threat model plainly: the operator who
+runs raise-floor already holds write access to the bucket and could write any floor directly; the
+checks exist to stop a mistaken raise, not to defend against that operator. Say whether any
+remaining finding is a mistake an operator could plausibly make, or only a deliberate subversion.
+
+First give one line per P1 and P2 from round 2: resolved, partly, or not. Carry every unresolved
+or partly resolved finding forward at its current severity, then add new findings. The verdict
+covers everything outstanding. A NOT READY also says whether the P1s share one cause, and whether
+refusing the case up front or cutting the feature would remove them.
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+ Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review. (The
+ census, and review of any newly changed security, root, termination
+ or production-storage behaviour, still check the fix; see AGENTS.md,
+ "Stopping rules".)
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for
+ another round.
+
+A P1 states its failure scenario and the evidence (file:line). Do not
+raise a P2 to P1 to keep the review open.
+
+## Output
+
+Findings ranked P1, P2, P3. Each gives the section or task, the problem,
+the evidence (file:line, verified), the failure scenario, a concrete
+fix and the invariant or trust boundary it breaks (that is its fault
+family). Then the census verdict for envelope `.` (APPROVE or REJECT, citing lines read). End
+with exactly one verdict:
+
+- **READY**: no P1 and no P2.
+- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another
+ round.
+- **NOT READY**: one or more P1s, listed.
+
+Do not edit files. Do not spawn Anthropic-model reviewers or subagents of
+your own. Do not run the full test suites (targeted `go test -run` is fine).
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
index 0ee4dbb94..9b1f1aa85 100644
--- 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
@@ -60,8 +60,13 @@ It accepts only when all hold, and writes nothing otherwise:
- the checkout's `refs/tags/<release>` names (through an annotated tag)
exactly this console's stamped commit;
- this console'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.
+ --is-ancestor`). The answer is the commits' own history (Astra r2): git
+ runs with the caller's `GIT_*` environment dropped (`GIT_GRAFT_FILE`,
+ `GIT_DIR`, object directories), replace refs off and no commit-graph, and
+ a checkout with a grafts file is refused (R14). A commit is looked up
+ only as an object name of the checkout's hash format (40 hex for SHA-1,
+ 64 for SHA-256) and must resolve to itself, so a ref named like one
+ cannot stand in for it.
It writes `{"version": "<release>", "commit": "<this console's commit>"}`
with If-Match on the etag it read: a floor changed meanwhile is not
diff --git a/internal/console/hostsused_floor.go b/internal/console/hostsused_floor.go
index cc48920ce..233a81271 100644
--- a/internal/console/hostsused_floor.go
+++ b/internal/console/hostsused_floor.go
@@ -5,7 +5,9 @@ import (
"context"
"errors"
"fmt"
+ "os"
"os/exec"
+ "path/filepath"
"regexp"
"strings"
@@ -59,6 +61,9 @@ func msgFloorTagNotThisBuild(rel, tagged, built string) string { // R9
return "The checkout's tag " + rel + " names " + tagged + ", but this console was built from " + built + "."
}
+// msgFloorGrafted is R14: a checkout whose history a grafts file rewrites.
+const msgFloorGrafted = "The checkout has a grafts file, which changes Git's commit history. Ancestry checks in this checkout cannot be trusted. Use a fresh clone of the platform repository."
+
func msgFloorNotContained(rel, floor string) string { // R11
return rel + " doesn't contain the floor's commit, " + floor + ". Name a later release."
}
@@ -99,6 +104,10 @@ type FloorCheckout interface {
// ErrCheckoutNoTag is a tag the checkout does not have.
var ErrCheckoutNoTag = errors.New("console: the checkout has no such tag")
+// ErrCheckoutGrafted is a checkout with a grafts file, which gives commits
+// parents they do not have.
+var ErrCheckoutGrafted = errors.New("console: the checkout has a grafts file")
+
// CheckoutMissingError is a commit the checkout does not have.
type CheckoutMissingError struct{ Commit string }
@@ -164,6 +173,9 @@ func RaiseHostsFloor(ctx context.Context, store release.Store, build provision.H
}
func checkoutRefusal(err error) error {
+ if errors.Is(err, ErrCheckoutGrafted) {
+ return errors.New(msgFloorGrafted)
+ }
var missing CheckoutMissingError
if errors.As(err, &missing) {
return errors.New(msgFloorCheckoutMissing(missing.Commit))
@@ -171,11 +183,31 @@ func checkoutRefusal(err error) error {
return err
}
-// GitCheckout is a platform checkout on disk, read with git.
+// GitCheckout is a platform checkout on disk, read with git. Its answers
+// are the commits' own history (Astra r2): every git it runs ignores the
+// caller's GIT_* environment (GIT_GRAFT_FILE, GIT_DIR, object directories,
+// replace-ref bases) and replace refs, reads no commit-graph, and a
+// checkout with a grafts file is refused. A commit is looked up only as an
+// object name of the checkout's own hash format, so a ref named like one
+// never stands in for it.
type GitCheckout struct{ Dir string }
+// gitEnv is the environment without GIT_* variables, with replace objects
+// off.
+func gitEnv() []string {
+ var env []string
+ for _, kv := range os.Environ() {
+ if !strings.HasPrefix(kv, "GIT_") {
+ env = append(env, kv)
+ }
+ }
+ return append(env, "GIT_NO_REPLACE_OBJECTS=1")
+}
+
func (g GitCheckout) git(ctx context.Context, args ...string) (string, int, error) {
- cmd := exec.CommandContext(ctx, "git", append([]string{"-C", g.Dir}, args...)...)
+ full := append([]string{"-C", g.Dir, "-c", "core.useReplaceRefs=false", "-c", "core.commitGraph=false"}, args...)
+ cmd := exec.CommandContext(ctx, "git", full...)
+ cmd.Env = gitEnv()
var stderr bytes.Buffer
cmd.Stderr = &stderr
out, err := cmd.Output()
@@ -211,15 +243,56 @@ func (g GitCheckout) TagCommit(ctx context.Context, tag string) (string, error)
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.
+// hashLength is the length of a full object name in the checkout's hash
+// format.
+func (g GitCheckout) hashLength(ctx context.Context) (int, error) {
+ format, _, err := g.git(ctx, "rev-parse", "--show-object-format")
+ switch {
+ case err != nil:
+ return 0, err
+ case format == "sha1":
+ return 40, nil
+ case format == "sha256":
+ return 64, nil
+ }
+ return 0, fmt.Errorf("git: unknown object format %q", format)
+}
+
+// grafted reports whether the checkout has a grafts file.
+func (g GitCheckout) grafted(ctx context.Context) (bool, error) {
+ path, _, err := g.git(ctx, "rev-parse", "--git-path", "info/grafts")
+ if err != nil {
+ return false, err
+ }
+ if !filepath.IsAbs(path) {
+ path = filepath.Join(g.Dir, path)
+ }
+ if _, err := os.Lstat(path); err == nil {
+ return true, nil
+ } else if !errors.Is(err, os.ErrNotExist) {
+ return false, err
+ }
+ return false, nil
+}
+
+// Contains is git merge-base --is-ancestor over two full object names of
+// the checkout's hash format, each resolved as that object and checked to
+// be a commit. A checkout with a grafts file is ErrCheckoutGrafted.
func (g GitCheckout) Contains(ctx context.Context, descendant, ancestor string) (bool, error) {
+ if grafted, err := g.grafted(ctx); err != nil {
+ return false, err
+ } else if grafted {
+ return false, ErrCheckoutGrafted
+ }
+ n, err := g.hashLength(ctx)
+ if err != nil {
+ return false, err
+ }
for _, c := range []string{descendant, ancestor} {
- if !fullCommit.MatchString(c) {
+ if len(c) != n || !fullCommit.MatchString(c) {
return false, CheckoutMissingError{Commit: c}
}
- if t, _, err := g.git(ctx, "cat-file", "-t", c); err != nil || t != "commit" {
+ if got, _, err := g.git(ctx, "rev-parse", "--verify", "--quiet", "--end-of-options", c+"^{commit}"); err != nil || got != c {
return false, CheckoutMissingError{Commit: c}
}
}
diff --git a/internal/console/hostsused_floor_test.go b/internal/console/hostsused_floor_test.go
index bbaf7d74a..9307dfb21 100644
--- a/internal/console/hostsused_floor_test.go
+++ b/internal/console/hostsused_floor_test.go
@@ -8,6 +8,7 @@ package console
import (
"context"
"errors"
+ "os"
"os/exec"
"path/filepath"
"strings"
@@ -284,3 +285,115 @@ func TestGitCheckout(t *testing.T) {
t.Errorf("TagCommit in no checkout = %v, want a failure that is not 'no tag'", err)
}
}
+
+// TestGitCheckoutIgnoresRewrittenHistory (Astra r2 P1-1): the checkout's
+// ancestry is the commits' own parents. A grafts file in the repository is
+// refused; an inherited GIT_GRAFT_FILE, replace refs and a commit-graph are
+// not consulted.
+func TestGitCheckoutIgnoresRewrittenHistory(t *testing.T) {
+ ctx := context.Background()
+ t.Run("inherited GIT_GRAFT_FILE", func(t *testing.T) {
+ dir, _, b, _, d := gitRepo(t)
+ grafts := filepath.Join(t.TempDir(), "grafts")
+ if err := os.WriteFile(grafts, []byte(d+" "+b+"\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ t.Setenv("GIT_GRAFT_FILE", grafts)
+ if got, err := (GitCheckout{Dir: dir}).Contains(ctx, d, b); err != nil || got {
+ t.Fatalf("Contains(d, b) with GIT_GRAFT_FILE = %v %v, want false", got, err)
+ }
+ })
+ t.Run("replace refs", func(t *testing.T) {
+ dir, _, b, _, d := gitRepo(t)
+ gitIn(t, dir, "replace", "--graft", d, b)
+ if got, err := (GitCheckout{Dir: dir}).Contains(ctx, d, b); err != nil || got {
+ t.Fatalf("Contains(d, b) with a replace ref = %v %v, want false", got, err)
+ }
+ })
+ t.Run("a grafts file in the repository", func(t *testing.T) {
+ dir, a, b, c, d := gitRepo(t)
+ path := gitIn(t, dir, "rev-parse", "--git-path", "info/grafts")
+ if !filepath.IsAbs(path) {
+ path = filepath.Join(dir, path)
+ }
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(path, []byte(d+" "+b+"\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ co := GitCheckout{Dir: dir}
+ if _, err := co.Contains(ctx, d, b); !errors.Is(err, ErrCheckoutGrafted) {
+ t.Fatalf("Contains(d, b) with a grafts file = %v, want ErrCheckoutGrafted", err)
+ }
+ if _, err := co.Contains(ctx, c, a); !errors.Is(err, ErrCheckoutGrafted) {
+ t.Fatalf("Contains(c, a) with a grafts file = %v, want ErrCheckoutGrafted", err)
+ }
+ })
+}
+
+// TestGitCheckoutObjectNamesMatchItsFormat (Astra r2 P1-2): a commit name
+// whose length is not the checkout's hash format is never looked up, so a
+// ref named like it cannot stand in for it.
+func TestGitCheckoutObjectNamesMatchItsFormat(t *testing.T) {
+ ctx := context.Background()
+ dir, a, _, c, _ := gitRepo(t)
+ sha256Name := strings.Repeat("ab", 32)
+ gitIn(t, dir, "branch", sha256Name, a)
+ var missing CheckoutMissingError
+ if _, err := (GitCheckout{Dir: dir}).Contains(ctx, c, sha256Name); !errors.As(err, &missing) {
+ t.Fatalf("Contains(c, a 64-hex branch) in a SHA-1 checkout = %v, want CheckoutMissingError", err)
+ }
+
+ dir256 := filepath.Join(t.TempDir(), "platform256")
+ if out, err := exec.Command("git", "init", "-q", "--object-format=sha256", "-b", "main", dir256).CombinedOutput(); err != nil {
+ t.Skipf("git can't make a SHA-256 repository: %v\n%s", err, out)
+ }
+ gitIn(t, dir256, "commit", "-q", "--allow-empty", "-m", "a")
+ first := gitIn(t, dir256, "rev-parse", "HEAD")
+ gitIn(t, dir256, "commit", "-q", "--allow-empty", "-m", "b")
+ head := gitIn(t, dir256, "rev-parse", "HEAD")
+ if len(head) != 64 {
+ t.Fatalf("SHA-256 HEAD = %q", head)
+ }
+ sha1Name := strings.Repeat("cd", 20)
+ gitIn(t, dir256, "branch", sha1Name, first)
+ co := GitCheckout{Dir: dir256}
+ if got, err := co.Contains(ctx, head, first); err != nil || !got {
+ t.Fatalf("Contains(head, first) in a SHA-256 checkout = %v %v, want true", got, err)
+ }
+ if _, err := co.Contains(ctx, head, sha1Name); !errors.As(err, &missing) || missing.Commit != sha1Name {
+ t.Fatalf("Contains(head, a 40-hex branch) in a SHA-256 checkout = %v, want CheckoutMissingError", err)
+ }
+}
+
+// TestRaiseFloorRefusesAGraftedCheckout: the grafts refusal reaches the
+// operator as R14 and writes nothing.
+func TestRaiseFloorRefusesAGraftedCheckout(t *testing.T) {
+ st := floorStore(t, &bareFloor)
+ _, _, err := RaiseHostsFloor(context.Background(), st, provision.HostsFloor{Version: "v0.34.4", Commit: c4}, "v0.34.4", graftedCheckout{newFakeCheckout()})
+ if err == nil || err.Error() != msgFloorGrafted {
+ t.Fatalf("err = %v, want %q", err, msgFloorGrafted)
+ }
+ if got := readFloor(t, st); got == nil || *got != bareFloor {
+ t.Fatalf("floor = %+v, want it unchanged", got)
+ }
+}
+
+type graftedCheckout struct{ *fakeCheckout }
+
+func (graftedCheckout) Contains(context.Context, string, string) (bool, error) {
+ return false, ErrCheckoutGrafted
+}
+
+// gitIn runs git in dir with a fixed identity and no user configuration.
+func gitIn(t *testing.T, dir string, 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))
+}