release: the held stage binds an unrecorded digestless build to its record or refuses it (hunt H3-M1/H6-M2 third path)
HeldAuthorized answers want "" for a build only a digestless pointer names (no promotion record), and stageHeld handed that answer to ensureStagedDigest, which with an empty digest is the unbound ensureStagedChecked: a move's held stage took whatever manifest and artifact the bucket held under the version. Tasks 1 and 6 bound adoptHost and StageSignedHead to the signed promotion record; a fresh box materializing a held release still staged (and MaterializeHeld published) a swap made behind an untouched pointer once the record was gone or never written. stageHeld now routes an empty want through the same binding: recordBinding reads the record, and without one retainedOrRefused recovers only this box's own verified staged copy, so a fresh box refuses and downloads nothing. HeldAuthorized, the record-bound path, the digest-bearing path and the materializeHeldStage seam are unchanged. Two existing tests asserted the unbound stage (a pointer-named build with no record staged on a fresh box; pass 1 of the ratchet-memory test) and now assert the refusal, with nothing staged. The proof-gate fixture reached D3's bind on a stale copy only through that unbound stage; it now keeps the record and replaces the staged file after the bound stage, before bind (the window publishHeld documents).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
5 files changed,
+287
−35
internal/release/heldauth_test.go+38 −9internal/release/hunt_H3-M1_held_test.go+187 −0internal/release/materializeheld.go+29 −3internal/release/materializeheld_claim_test.go+2 −2internal/release/materializeheld_proof_test.go+31 −21
diff --git a/internal/release/heldauth_test.go b/internal/release/heldauth_test.go| index 7b8cf10a3..271d88b66 100644 |
| --- a/internal/release/heldauth_test.go |
| +++ b/internal/release/heldauth_test.go |
| @@ -79,7 +79,13 @@ func TestHeldStageAcceptsARecordedBuildOutOfHistory(t *testing.T) { |
| } |
| } |
| -func TestHeldStageAcceptsAPointerNamedBuildWithoutARecord(t *testing.T) { |
| +// A build only a digestless pointer names is authorized but bound to |
| +// nothing, so a fresh box refuses it rather than staging whatever the bucket |
| +// holds under the name (hunt H3-M1, H6-M2; `carlos releases authorize` |
| +// writes the record). The refusal is the binding's, not ErrHeldNotAuthorized: |
| +// the pointer does name the build. A box that staged the build while it was |
| +// recorded still recovers its own verified copy. |
| +func TestHeldStageRefusesAPointerNamedBuildWithoutARecordOnAFreshBox(t *testing.T) { |
| s := NewDirStore(t.TempDir()) |
| ctx := context.Background() |
| priv, pub := testKeys(t) |
| @@ -88,11 +94,29 @@ func TestHeldStageAcceptsAPointerNamedBuildWithoutARecord(t *testing.T) { |
| if err := Promote(ctx, s, priv, "bab", "km", "canary/x", "v1"); err != nil { |
| t.Fatal(err) |
| } |
| + raw, _, err := s.Get(ctx, ManifestKey("bab", "km", "v1")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| if err := s.Delete(ctx, PromotionRecordKey("bab", "km", "v1")); err != nil { // promoted before records |
| t.Fatal(err) |
| } |
| - if _, err := StageHeld(ctx, s, pub, nr(t), opt, heldAuthRoute("a.example.com"), "v1"); err != nil { |
| - t.Fatalf("a build the signed pointer names: %v", err) |
| + rec := &heldRecordingStore{Store: s} |
| + _, err = StageHeld(ctx, rec, pub, nr(t), opt, heldAuthRoute("a.example.com"), "v1") |
| + if err == nil || errors.Is(err, ErrHeldNotAuthorized) { |
| + t.Fatalf("StageHeld of a pointer-named build with no record on a fresh box = %v; want the record binding's refusal", err) |
| + } |
| + heldNothingDownloaded(t, rec, opt, "v1") |
| + |
| + // The same box, had it staged v1 while the record was there. |
| + if err := StageArtifact(opt, "bab", "v1", "km", []byte("v1")); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := StageManifest(opt, "bab", "v1", "km", raw); err != nil { |
| + t.Fatal(err) |
| + } |
| + if m, err := StageHeld(ctx, s, pub, nr(t), opt, heldAuthRoute("a.example.com"), "v1"); err != nil || m == nil || m.Version != "v1" { |
| + t.Fatalf("StageHeld over this box's verified copy = %+v, %v; want it recovered", m, err) |
| } |
| } |
| @@ -417,10 +441,12 @@ func TestHeldStageRefusesADigestlessEntryOnADigestedChannel(t *testing.T) { |
| } |
| // Astra final A2, ruling R15: a held stage remembers every verified pointer |
| -// with digests it reads, naming the build or not. Pass 1 stages v1 on channel |
| -// b's word while channel a's pointer signs digests for v2; pass 2, on the |
| -// same ratchet, is a saved digestless pointer of channel a replayed over |
| -// substituted v2 bytes, and is refused. |
| +// with digests it reads, naming the build or not. Pass 1 asks for v1 on |
| +// channel b's word while channel a's pointer signs digests for v2 (no build |
| +// has a record, so on this fresh box v1 is authorized, then refused for want |
| +// of a binding, hunt H3-M1); pass 2, on the same ratchet, is a saved |
| +// digestless pointer of channel a replayed over substituted v2 bytes, and is |
| +// refused as not authorized: channel a was remembered during pass 1. |
| func TestHeldStageRemembersEveryVerifiedPointer(t *testing.T) { |
| s := NewDirStore(t.TempDir()) |
| ctx := context.Background() |
| @@ -454,8 +480,11 @@ func TestHeldStageRemembersEveryVerifiedPointer(t *testing.T) { |
| put("a", sign(&ChannelPointer{Account: "bab", App: "km", Channel: "a", Version: "v2", Digest: ManifestDigest(v2raw)})) |
| put("b", sign(&ChannelPointer{Account: "bab", App: "km", Channel: "b", Version: "v1"})) |
| ratchet := NewDigestRatchet(t.TempDir(), nil, false) |
| - if _, err := StageHeld(ctx, s, pub, ratchet, opt, heldAuthRoute("a.example.com"), "v1"); err != nil { |
| - t.Fatalf("pass 1, v1 on channel b's word: %v", err) |
| + if _, err := StageHeld(ctx, s, pub, ratchet, opt, heldAuthRoute("a.example.com"), "v1"); err == nil || errors.Is(err, ErrHeldNotAuthorized) { |
| + t.Fatalf("pass 1, v1 on channel b's word alone, no record, fresh box = %v; want the record binding's refusal", err) |
| + } |
| + if _, err := os.Stat(VersionPath(opt, "bab", "v1", "km")); err == nil { |
| + t.Fatal("pass 1 staged v1 on a digestless pointer's word alone") |
| } |
| put("a", saved) |
| heldSubstitute(t, s, "v2") |
diff --git a/internal/release/hunt_H3-M1_held_test.go b/internal/release/hunt_H3-M1_held_test.go| new file mode 100644 |
| index 000000000..e17222fc5 |
| --- /dev/null |
| +++ b/internal/release/hunt_H3-M1_held_test.go |
| @@ -0,0 +1,187 @@ |
| +package release |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "errors" |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// huntHeldBox is the fresh box a move's held stage runs on: an empty opt |
| +// dir, empty ratchet dirs, the require flag off. It ships and promotes v1 of |
| +// bab/km with the account's digest marker off (the default), so the signed |
| +// pointer carries no digest and the promotion record Promote wrote is the |
| +// only binding of v1's name to its bytes. The route is a held row: the |
| +// account, the app and the move that holds it. |
| +func huntHeldBox(t *testing.T) (ctx context.Context, s *DirStore, pub []byte, rat *DigestRatchet, opt string, rt registry.Route) { |
| + t.Helper() |
| + ctx = context.Background() |
| + s = NewDirStore(t.TempDir()) |
| + priv, pub := testKeys(t) |
| + opt = t.TempDir() |
| + shipRelease(t, s, "bab", "km", "v1", adoptPlatform, []byte("the bytes the publisher shipped")) |
| + if err := Promote(ctx, s, priv, "bab", "km", "canary/x", "v1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + p, err := Channel(ctx, s, pub, "bab", "km", "canary/x") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if p.Digest != "" || p.CarriesDigests() { |
| + t.Fatalf("setup: marker off still produced a digest %q", p.Digest) |
| + } |
| + if rec, err := ReadPromotionRecord(ctx, s, pub, "bab", "km", "v1"); err != nil || rec.ManifestDigest != manifestDigestOf(t, s, "bab", "km", "v1") { |
| + t.Fatalf("setup: promotion record %+v, %v", rec, err) |
| + } |
| + rat = NewDigestRatchet(filepath.Join(t.TempDir(), "root-marks"), []string{filepath.Join(t.TempDir(), "edge-marks")}, false) |
| + rt = registry.Route{Host: "a.example.com", Kind: "instance", Account: "bab", App: "km", HoldOp: "op-1"} |
| + return ctx, s, pub, rat, opt, rt |
| +} |
| + |
| +// huntDropRecord removes v1's promotion record: a head promoted before |
| +// records existed, or one a bucket writer deleted. The signed pointer still |
| +// names v1, so HeldAuthorized admits the build on the pointer's word alone. |
| +func huntDropRecord(t *testing.T, ctx context.Context, s *DirStore) { |
| + t.Helper() |
| + if err := s.Delete(ctx, PromotionRecordKey("bab", "km", "v1")); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// huntHeldEntries are the held stage's entry points below the relay: the |
| +// agent's publication (MaterializeHeld) and the claim path's verified stage |
| +// (StageHeldVerified). Both run stageHeld. |
| +var huntHeldEntries = map[string]func(ctx context.Context, s Store, pub []byte, rat *DigestRatchet, opt string, rt registry.Route, gate *ProofGate) (*Manifest, error){ |
| + "MaterializeHeld": func(ctx context.Context, s Store, pub []byte, rat *DigestRatchet, opt string, rt registry.Route, gate *ProofGate) (*Manifest, error) { |
| + return MaterializeHeld(ctx, s, pub, rat, opt, rt, "v1", gate, openGuard) |
| + }, |
| + "StageHeldVerified": func(ctx context.Context, s Store, pub []byte, rat *DigestRatchet, opt string, rt registry.Route, gate *ProofGate) (*Manifest, error) { |
| + return StageHeldVerified(ctx, s, pub, rat, opt, rt, "v1", gate) |
| + }, |
| +} |
| + |
| +// H3-M1 third path: the held stage (HeldAuthorized -> stageHeld) binds a |
| +// digestless held pointer to its promotion record when the record is there, |
| +// but with the record ABSENT it admitted the build on the pointer's word and |
| +// handed want "" to the unbound stage, which took whatever manifest and |
| +// artifact the bucket held under the version. A bucket writer deletes the |
| +// record and swaps manifest+artifact; the signed pointer is untouched; a |
| +// fresh box has no retained copy. SECURE expectation: refused, nothing |
| +// downloaded, nothing staged, live/<host> untouched, through every entry. |
| +func TestHunt_H3_M1_HeldMaterializeRefusesNoRecordSwap(t *testing.T) { |
| + for name, entry := range huntHeldEntries { |
| + t.Run(name, func(t *testing.T) { |
| + ctx, s, pub, rat, opt, rt := huntHeldBox(t) |
| + huntDropRecord(t, ctx, s) |
| + evil := []byte("bytes nobody promoted") |
| + huntReplaceRelease(t, s, "bab", "km", "v1", evil) |
| + rec := &heldRecordingStore{Store: s} |
| + |
| + var out bytes.Buffer |
| + var m *Manifest |
| + var err error |
| + withCapturedStdout(t, &out, func() { |
| + m, err = entry(ctx, rec, pub, rat, opt, rt, offGate(t)) |
| + }) |
| + staged, rerr := os.ReadFile(VersionPath(opt, "bab", "v1", "km")) |
| + live, _ := LiveVersion(opt, rt.Host) |
| + if err == nil || rerr == nil || bytes.Equal(staged, evil) || live == "v1" { |
| + t.Fatalf("H3-M1 (%s): digestless held pointer with no promotion record admitted substituted bytes on a fresh box: err=%v manifest=%+v staged=%q live=%q\n%s", |
| + name, err, m, staged, live, out.String()) |
| + } |
| + if errors.Is(err, ErrHeldNotAuthorized) { |
| + t.Fatalf("%s: the pointer names v1, so the refusal is the binding's, not ErrHeldNotAuthorized: %v", name, err) |
| + } |
| + heldNothingDownloaded(t, rec, opt, "v1") |
| + gone(t, LiveLink(opt, rt.Host)) |
| + }) |
| + } |
| +} |
| + |
| +// A box that staged and verified v1 while it was recorded keeps recovering |
| +// it from its own copy (RetainedStaged, §4.1's retained identity) after the |
| +// record is gone and the bucket's bytes are swapped: the held release comes |
| +// back live on the shipped bytes, and the swap is never downloaded. |
| +func TestHunt_H3_M1_HeldMaterializeRecoversRetainedCopy(t *testing.T) { |
| + ctx, s, pub, rat, opt, rt := huntHeldBox(t) |
| + // This box's earlier, bound stage: the shipped bytes and the canonical |
| + // manifest beside them. |
| + raw, _, err := s.Get(ctx, ManifestKey("bab", "km", "v1")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := StageArtifact(opt, "bab", "v1", "km", []byte("the bytes the publisher shipped")); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := StageManifest(opt, "bab", "v1", "km", raw); err != nil { |
| + t.Fatal(err) |
| + } |
| + huntDropRecord(t, ctx, s) |
| + huntReplaceRelease(t, s, "bab", "km", "v1", []byte("bytes nobody promoted")) |
| + rec := &heldRecordingStore{Store: s} |
| + |
| + var out bytes.Buffer |
| + var m *Manifest |
| + withCapturedStdout(t, &out, func() { |
| + m, err = MaterializeHeld(ctx, rec, pub, rat, opt, rt, "v1", offGate(t), openGuard) |
| + }) |
| + if err != nil { |
| + t.Fatalf("a retained verified copy did not recover the held release: %v\n%s", err, out.String()) |
| + } |
| + if m == nil || m.Version != "v1" { |
| + t.Fatalf("manifest = %+v, want v1's", m) |
| + } |
| + if live, err := LiveVersion(opt, rt.Host); err != nil || live != "v1" { |
| + t.Fatalf("LiveVersion = %q, %v; want v1", live, err) |
| + } |
| + body, err := os.ReadFile(LiveLink(opt, rt.Host)) |
| + if err != nil || string(body) != "the bytes the publisher shipped" { |
| + t.Fatalf("live binary = %q, %v; want the shipped bytes", body, err) |
| + } |
| + heldDownloadedNothingOf(t, rec, "v1") |
| +} |
| + |
| +// Control: with the record in place, the same digestless held pointer stages |
| +// and publishes the shipped bytes on a fresh box, bound to the record. |
| +func TestHunt_H3_M1_HeldMaterializeStagesRecordedBuild(t *testing.T) { |
| + for name, entry := range huntHeldEntries { |
| + t.Run(name, func(t *testing.T) { |
| + ctx, s, pub, rat, opt, rt := huntHeldBox(t) |
| + var out bytes.Buffer |
| + var m *Manifest |
| + var err error |
| + withCapturedStdout(t, &out, func() { |
| + m, err = entry(ctx, s, pub, rat, opt, rt, offGate(t)) |
| + }) |
| + if err != nil { |
| + t.Fatalf("control (%s): the recorded build was refused: %v\n%s", name, err, out.String()) |
| + } |
| + if m == nil || m.Version != "v1" || m.Kind != "binary" { |
| + t.Fatalf("control (%s): manifest %+v", name, m) |
| + } |
| + staged, rerr := os.ReadFile(VersionPath(opt, "bab", "v1", "km")) |
| + if rerr != nil || string(staged) != "the bytes the publisher shipped" { |
| + t.Fatalf("control (%s): staged %q, %v", name, staged, rerr) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// heldDownloadedNothingOf is heldNothingDownloaded without its staged-file |
| +// check, for a box that holds the version already. |
| +func heldDownloadedNothingOf(t *testing.T, rec *heldRecordingStore, version string) { |
| + t.Helper() |
| + rel := ReleasesPrefix("bab", "km") + version + "/" |
| + rec.mu.Lock() |
| + defer rec.mu.Unlock() |
| + for _, c := range rec.calls { |
| + if strings.HasPrefix(c, "get "+rel) { |
| + t.Fatalf("the held stage downloaded %s", strings.TrimPrefix(c, "get ")) |
| + } |
| + } |
| +} |
diff --git a/internal/release/materializeheld.go b/internal/release/materializeheld.go| index 360569531..9ec6bc166 100644 |
| --- a/internal/release/materializeheld.go |
| +++ b/internal/release/materializeheld.go |
| @@ -56,6 +56,10 @@ var ErrHeldNotAuthorized = errors.New("release: the held release is not authoriz |
| // must bind: the record's, else a naming pointer entry's, preferring one that |
| // signs a digest ("" only when every admitted naming entry comes from a |
| // pointer whose channel carries no digests at all, today's pointer trust). |
| +// An empty want authorizes the build but binds nothing, and stageHeld no |
| +// longer stages on it alone (hunt H3-M1, H6-M2): it asks the promotion |
| +// record again through recordBinding, and without one only this box's own |
| +// verified staged copy is recovered. |
| // |
| // Every pointer that verifies goes through the box's ratchet, whether or not |
| // it names the version: §4.6 remembers a channel from the moment the box has |
| @@ -144,9 +148,9 @@ var ( |
| ) |
| // materializeHeldStage is MaterializeHeld's staging step, ensureStagedDigest |
| -// bound to the digest HeldAuthorized returned (want "" is ensureStaged |
| -// exactly), as a variable so a test can make it fail the way a read-only |
| -// mount does. |
| +// bound to the digest stageHeld settled on, which is never "" (stageHeld |
| +// refuses or recovers an unbound build before calling it), as a variable so |
| +// a test can make it fail the way a read-only mount does. |
| var materializeHeldStage = func(ctx context.Context, s Store, optDir, acct, app, ver, host, want string) (*Manifest, error) { |
| return ensureStagedDigest(ctx, s, optDir, acct, app, ver, host, want, stageCheck{}) |
| } |
| @@ -395,6 +399,22 @@ func StageHeldVerifiedWithPins(ctx context.Context, s Store, pub ed25519.PublicK |
| // to the digest it returned, whose manifest is checked before any artifact |
| // byte is written (ensureStagedDigest). Authorization lives here, below |
| // every entry point, so no held path stages a build it has not authorized. |
| +// |
| +// Authorized is not bound. HeldAuthorized answers "" for a build only a |
| +// digestless pointer names (no promotion record: promoted before records |
| +// existed, or the record deleted), and that answer used to reach the |
| +// unbound stage, which took whatever manifest and artifact the bucket held |
| +// under the version: a writer with s3:PutObject could swap both behind the |
| +// untouched signed pointer and a fresh box materialized the swap (hunt |
| +// H3-M1, H6-M2, the third path after adoptHost and StageSignedHead). So an |
| +// empty want goes where the adopt paths go (stageAuthorized, |
| +// stagePointerHead): the promotion record binds (recordBinding), and |
| +// without one only this box's own verified staged copy is recovered |
| +// (retainedOrRefused); a fresh box is refused and downloads nothing. A |
| +// recorded build, a digest-signing pointer, and a box that staged the build |
| +// while it was recorded are unchanged. The refusal is the record paths', |
| +// not ErrHeldNotAuthorized: a pointer does name the build, and `carlos |
| +// releases authorize` writes the record that lets the next pass stage it. |
| func stageHeld(ctx context.Context, s Store, pub ed25519.PublicKey, r *DigestRatchet, optDir string, rt registry.Route, version string, pins ...PinSource) (*Manifest, error) { |
| if err := heldShape(rt, version); err != nil { |
| return nil, err |
| @@ -403,6 +423,12 @@ func stageHeld(ctx context.Context, s Store, pub ed25519.PublicKey, r *DigestRat |
| if err != nil { |
| return nil, err |
| } |
| + if want == "" { |
| + var refused error |
| + if want, refused = recordBinding(ctx, s, pub, RouteAccount(rt), rt.App, version); refused != nil { |
| + return retainedOrRefused(optDir, RouteAccount(rt), rt.App, version, rt.Host, refused) |
| + } |
| + } |
| var m *Manifest |
| if len(pins) == 0 { |
| m, err = materializeHeldStage(ctx, s, optDir, RouteAccount(rt), rt.App, version, rt.Host, want) |
diff --git a/internal/release/materializeheld_claim_test.go b/internal/release/materializeheld_claim_test.go| index c2b9628a1..4e89faba7 100644 |
| --- a/internal/release/materializeheld_claim_test.go |
| +++ b/internal/release/materializeheld_claim_test.go |
| @@ -205,8 +205,8 @@ func TestStageHeldVerifiedStagesWithoutPublishing(t *testing.T) { |
| e.require(t, "console") |
| e.prove(t, e.pinnedSHA) |
| stale := []byte("not the shipped bytes") |
| - down := e.staleCopyDown(t, stale) |
| - if _, err := StageHeldVerified(e.ctx, down, heldPub, nr(t), e.opt, heldRoute(), "v1", e.gate); !errors.Is(err, ErrHeldNotProven) || e.live() != "v0" { |
| + swapped := e.staleBytesAtBind(t, stale) |
| + if _, err := StageHeldVerified(e.ctx, swapped, heldPub, nr(t), e.opt, heldRoute(), "v1", e.gate); !errors.Is(err, ErrHeldNotProven) || e.live() != "v0" { |
| t.Fatalf("other staged bytes: %v, live %q", err, e.live()) |
| } |
| r, _ := ReadRefusal(HeldRefusalBase(e.bake), heldTestHost) |
diff --git a/internal/release/materializeheld_proof_test.go b/internal/release/materializeheld_proof_test.go| index 1c7fdbd61..893181647 100644 |
| --- a/internal/release/materializeheld_proof_test.go |
| +++ b/internal/release/materializeheld_proof_test.go |
| @@ -78,20 +78,30 @@ func (e *heldProofEnv) prove(t *testing.T, sha string) { |
| } |
| } |
| -// staleCopyDown is stageStaleCopyKept for v1: a copy of other bytes staged |
| -// while v1's canonical manifest cannot be read, so only D3's bind can catch |
| -// it. A held stage reaches bind on such a copy only on pointer trust (want |
| -// "", a build promoted before records, settings spec §4.1): under v1's |
| -// promotion record the stage binds the record's digest and refuses the copy |
| -// before bind (TestHeldStageRecordRefusesAStaleCopyItCannotCheck). So v1's |
| -// record is removed first, and the digestless canary/x pointer is the |
| -// stage's evidence. |
| -func (e *heldProofEnv) staleCopyDown(t *testing.T, stale []byte) Store { |
| +// staleBytesAtBind puts other bytes under v1's staged path after the stage |
| +// and before D3's bind, once: the window publishHeld describes, in which |
| +// the guard's re-check reads the bucket and waits for the freeze while the |
| +// staged file can be replaced, so only bind can catch it. The stage itself |
| +// runs as it does in production, bound to v1's promotion record (an unbound |
| +// stage of a kept stale copy on pointer trust used to be the way here, and |
| +// is refused since hunt H3-M1: a build no record binds is not staged on a |
| +// fresh box). Returns the store the stage reads, unchanged. |
| +func (e *heldProofEnv) staleBytesAtBind(t *testing.T, stale []byte) Store { |
| t.Helper() |
| - if err := e.store.Delete(e.ctx, PromotionRecordKey("bab", "console", "v1")); err != nil { |
| - t.Fatal(err) |
| + orig := materializeHeldStage |
| + t.Cleanup(func() { materializeHeldStage = orig }) |
| + replaced := false |
| + materializeHeldStage = func(ctx context.Context, s Store, optDir, acct, app, ver, host, want string) (*Manifest, error) { |
| + m, err := orig(ctx, s, optDir, acct, app, ver, host, want) |
| + if err == nil && !replaced { |
| + replaced = true |
| + if err := StageArtifact(optDir, acct, ver, app, stale); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + return m, err |
| } |
| - return stageStaleCopyKept(t, e.ctx, e.store, e.opt, "bab", "console", "v1", stale) |
| + return e.store |
| } |
| func (e *heldProofEnv) live() string { v, _ := LiveVersion(e.opt, heldTestHost); return v } |
| @@ -224,17 +234,17 @@ func TestHeldStageProofBrokenPolicyIsRefused(t *testing.T) { |
| } |
| // bind: the manifest's sha256 is proven, but the staged file holds other |
| -// bytes (a kept stale copy: see stageStaleCopyKept). Refused before |
| +// bytes (replaced after the stage: see staleBytesAtBind). Refused before |
| // publishing, with adoption's not-proven record. |
| func TestHeldStageProofBindingRefusesOtherStagedBytes(t *testing.T) { |
| e := newHeldProofEnv(t) |
| e.require(t, "console") |
| e.prove(t, e.pinnedSHA) |
| stale := []byte("not the shipped bytes") |
| - down := e.staleCopyDown(t, stale) |
| + swapped := e.staleBytesAtBind(t, stale) |
| // bind runs inside the publication (fix round 1), so the guard is asked |
| // and the refusal comes from within it. |
| - err, _, out := e.materialize(t, down) |
| + err, _, out := e.materialize(t, swapped) |
| if !errors.Is(err, ErrHeldNotProven) || e.live() != "v0" { |
| t.Fatalf("MaterializeHeld: %v, live %q; want ErrHeldNotProven and v0", err, e.live()) |
| } |
| @@ -392,8 +402,8 @@ func TestHeldStageProofRefusalCarriesTheMove(t *testing.T) { |
| e := newHeldProofEnv(t) |
| e.require(t, "console") |
| e.prove(t, e.pinnedSHA) |
| - down := e.staleCopyDown(t, []byte("not the shipped bytes")) |
| - e.materialize(t, down) |
| + swapped := e.staleBytesAtBind(t, []byte("not the shipped bytes")) |
| + e.materialize(t, swapped) |
| r, _ := ReadRefusal(HeldRefusalBase(e.bake), heldTestHost) |
| if r == nil || r.MoveOp != heldTestOp || r.Kind != RefusalNotProven { |
| t.Fatalf("refusal = %+v, want a not-proven record naming op %s", r, heldTestOp) |
| @@ -417,8 +427,8 @@ func TestHeldStageProofLeavesAnAdoptionRefusal(t *testing.T) { |
| t.Fatal(err) |
| } |
| before, _ := os.ReadFile(filepath.Join(RefusalDir(e.bake), heldTestHost+".json")) |
| - down := e.staleCopyDown(t, []byte("not the shipped bytes")) |
| - err, _, _ := e.materialize(t, down) |
| + swapped := e.staleBytesAtBind(t, []byte("not the shipped bytes")) |
| + err, _, _ := e.materialize(t, swapped) |
| if !errors.Is(err, ErrHeldNotProven) { |
| t.Fatalf("MaterializeHeld: %v, want ErrHeldNotProven", err) |
| } |
| @@ -437,8 +447,8 @@ func TestHeldStageProofSuccessRetiresTheMovesRefusal(t *testing.T) { |
| e := newHeldProofEnv(t) |
| e.require(t, "console") |
| e.prove(t, e.pinnedSHA) |
| - down := e.staleCopyDown(t, []byte("not the shipped bytes")) |
| - e.materialize(t, down) |
| + swapped := e.staleBytesAtBind(t, []byte("not the shipped bytes")) |
| + e.materialize(t, swapped) |
| if r, _ := ReadRefusal(HeldRefusalBase(e.bake), heldTestHost); r == nil { |
| t.Fatal("no refusal to retire") |
| } |