carlos / platform Public

provision: the file seed kind and its transitions

Adds seeds.KindFile, FileSeedProtocol (3, ProtocolVersion 3) and the
SeedPublishFile, SeedAbortFileUploadBecause and SeedFail transitions.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 74f15303c9b6a8245d80a65bb1a0e2ffca3d9773 parent 0c4af6d
6 files changed, +169 −5
  • internal/provision/seed.go +36 −3
  • internal/provision/seed_test.go +98 −1
  • internal/seeds/floor.go +8 −1
  • internal/seeds/floor_test.go +9 −0
  • internal/seeds/seeds.go +1 −0
  • internal/seeds/seeds_test.go +17 −0

CI failed — run details

diff --git a/internal/provision/seed.go b/internal/provision/seed.go
index 419b67aae..d48289422 100644
--- a/internal/provision/seed.go
+++ b/internal/provision/seed.go
@@ -61,15 +61,15 @@ func (s *SeedSource) Abandoned() bool {
// door's import rule can remove;
// - aborted, rolled-back: its rollback or its finish is still owed.
//
-// Finished, and the only two: a --from seed at placed and an import at
-// committed. Any other kind and state is unfinished, including a state or a
+// Finished, and the only two shapes: a --from or file seed at placed and an
+// import at committed. Any other kind and state is unfinished, including a state or a
// kind this build does not know and a pairing no door writes (a committed
// --from seed).
func (s *SeedSource) Unfinished() bool {
if s == nil {
return false
}
- finished := (s.Kind == seeds.KindReplica && s.State == seeds.StatePlaced) ||
+ finished := ((s.Kind == seeds.KindReplica || s.Kind == seeds.KindFile) && s.State == seeds.StatePlaced) ||
((s.Import() || s.DemoClaim()) && s.State == seeds.StateCommitted)
return !finished
}
@@ -168,6 +168,39 @@ func SeedPublishReplica(id, txid, sha string, bytes int64) func(*Record) error {
})
}
+// SeedPublishFile is the upload's last step for a file seed: reserving to
+// ready. The sha256 and length were set at begin and checked by the upload.
+func SeedPublishFile(id string) func(*Record) error {
+ return seedStep(id, seeds.KindFile, []string{seeds.StateReserving}, seeds.StateReady, nil)
+}
+
+// SeedAbortFileUploadBecause is SeedAbortUploadBecause for a file seed: only
+// while it is still reserving.
+func SeedAbortFileUploadBecause(id, reason string) func(*Record) error {
+ abort := SeedAbortBecause(id, reason)
+ return func(rec *Record) error {
+ if err := seedIn(rec, id, seeds.KindFile, seeds.StateReserving); err != nil {
+ return err
+ }
+ return abort(rec)
+ }
+}
+
+// SeedFail is a box's terminal placement failure (design §3.6): a file seed
+// from ready to aborted, with Reason. Never an import (SeedRefuse is
+// unchanged). It also accepts an aborted file seed and sets only Reason
+// (Decision D6), so a rollback that finds a copy can say so.
+func SeedFail(id, reason string) func(*Record) error {
+ return func(rec *Record) error {
+ if err := seedIn(rec, id, seeds.KindFile, seeds.StateReady, seeds.StateAborted); err != nil {
+ return err
+ }
+ rec.Seed.State = seeds.StateAborted
+ rec.Seed.Reason = reason
+ return nil
+ }
+}
+
// SeedUploaded is the upload's last step (spec §5.2 step 5).
func SeedUploaded(id string) func(*Record) error {
return seedStep(id, seeds.KindImport, []string{seeds.StateAwaitingUpload}, seeds.StateUploaded, nil)
diff --git a/internal/provision/seed_test.go b/internal/provision/seed_test.go
index be759a41a..9da835c01 100644
--- a/internal/provision/seed_test.go
+++ b/internal/provision/seed_test.go
@@ -308,13 +308,22 @@ func TestSeedTransitionTable(t *testing.T) {
"swapped": {SeedSwapped, map[cell]string{{seeds.KindImport, seeds.StateReady}: seeds.StateSwapped}},
"place": {SeedPlace, map[cell]string{
{seeds.KindReplica, seeds.StateReady}: seeds.StatePlaced,
+ {seeds.KindFile, seeds.StateReady}: seeds.StatePlaced,
{seeds.KindImport, seeds.StateSwapped}: seeds.StatePlaced}},
+ "publish file": {SeedPublishFile, map[cell]string{{seeds.KindFile, seeds.StateReserving}: seeds.StateReady}},
+ "fail": {func(id string) func(*Record) error { return SeedFail(id, "x") }, map[cell]string{
+ {seeds.KindFile, seeds.StateReady}: seeds.StateAborted,
+ {seeds.KindFile, seeds.StateAborted}: seeds.StateAborted}},
+ "abort file upload": {func(id string) func(*Record) error { return SeedAbortFileUploadBecause(id, "no") },
+ map[cell]string{{seeds.KindFile, seeds.StateReserving}: seeds.StateAborted}},
"commit": {SeedCommit, map[cell]string{{seeds.KindImport, seeds.StatePlaced}: seeds.StateCommitted}},
"refuse": {func(id string) func(*Record) error { return SeedRefuse(id, "no") },
map[cell]string{{seeds.KindImport, seeds.StateReady}: seeds.StateRefused}},
"abort": {SeedAbort, map[cell]string{
{seeds.KindReplica, seeds.StateReserving}: seeds.StateAborted,
{seeds.KindReplica, seeds.StateReady}: seeds.StateAborted,
+ {seeds.KindFile, seeds.StateReserving}: seeds.StateAborted,
+ {seeds.KindFile, seeds.StateReady}: seeds.StateAborted,
{seeds.KindImport, seeds.StateAwaitingUpload}: seeds.StateAborted,
{seeds.KindImport, seeds.StateUploaded}: seeds.StateAborted,
{seeds.KindImport, seeds.StateReady}: seeds.StateAborted,
@@ -325,6 +334,7 @@ func TestSeedTransitionTable(t *testing.T) {
map[cell]string{{seeds.KindImport, seeds.StateAwaitingUpload}: seeds.StateAborted}},
"rolled back": {SeedRolledBack, map[cell]string{
{seeds.KindReplica, seeds.StateAborted}: seeds.StateRolledBack,
+ {seeds.KindFile, seeds.StateAborted}: seeds.StateRolledBack,
{seeds.KindImport, seeds.StateAborted}: seeds.StateRolledBack}},
"rolled back before swap": {SeedRolledBackBeforeSwap, map[cell]string{
{seeds.KindImport, seeds.StateAwaitingUpload}: seeds.StateRolledBack,
@@ -336,7 +346,7 @@ func TestSeedTransitionTable(t *testing.T) {
t.Fatal(err)
}
for name, tr := range table {
- for _, kind := range []string{seeds.KindReplica, seeds.KindImport} {
+ for _, kind := range []string{seeds.KindReplica, seeds.KindImport, seeds.KindFile} {
for _, from := range all {
seed := testSeed(t, kind, from)
// Under another id, no cell moves.
@@ -712,3 +722,90 @@ func TestSetRecordRegionRefusesAnHARecord(t *testing.T) {
t.Fatalf("a write that keeps the region: %v", err)
}
}
+
+// TestSeedLifecycleFileKind pins the file kind's rows against the other two
+// kinds (the full grid is TestSeedTransitionTable).
+func TestSeedLifecycleFileKind(t *testing.T) {
+ apply := func(kind, state string, mut func(string) func(*Record) error) error {
+ seed := testSeed(t, kind, state)
+ return mut(seed.ID)(&Record{Seed: seed})
+ }
+ if err := apply(seeds.KindFile, seeds.StateReserving, SeedPublishFile); err != nil {
+ t.Fatalf("publish file: %v", err)
+ }
+ for _, kind := range []string{seeds.KindReplica, seeds.KindImport} {
+ if err := apply(kind, seeds.StateReserving, SeedPublishFile); !errors.Is(err, ErrSeedConflict) {
+ t.Errorf("SeedPublishFile on %s: %v", kind, err)
+ }
+ }
+ replica := func(id string) func(*Record) error { return SeedPublishReplica(id, "1", strings.Repeat("e", 64), 1) }
+ if err := apply(seeds.KindFile, seeds.StateReserving, replica); !errors.Is(err, ErrSeedConflict) {
+ t.Errorf("SeedPublishReplica on file: %v", err)
+ }
+ if err := apply(seeds.KindFile, seeds.StateReady, SeedPlace); err != nil {
+ t.Errorf("place: %v", err)
+ }
+ for _, from := range []string{seeds.StateReserving, seeds.StateReady} {
+ if err := apply(seeds.KindFile, from, SeedAbort); err != nil {
+ t.Errorf("abort from %s: %v", from, err)
+ }
+ }
+ if err := apply(seeds.KindFile, seeds.StateAborted, SeedRolledBack); err != nil {
+ t.Errorf("rolled back: %v", err)
+ }
+}
+
+func TestUnfinishedFilePlacedIsFinished(t *testing.T) {
+ for state, want := range map[string]bool{seeds.StatePlaced: false, seeds.StateReady: true,
+ seeds.StateAborted: true, seeds.StateCommitted: true} {
+ if got := (&SeedSource{Kind: seeds.KindFile, State: state}).Unfinished(); got != want {
+ t.Errorf("file %s: unfinished %v, want %v", state, got, want)
+ }
+ }
+}
+
+func TestSeedFailFileOnly(t *testing.T) {
+ seed := testSeed(t, seeds.KindFile, seeds.StateReady)
+ rec := Record{Seed: seed}
+ if err := SeedFail(seed.ID, "placing-failed")(&rec); err != nil || rec.Seed.State != seeds.StateAborted || rec.Seed.Reason != "placing-failed" {
+ t.Fatalf("ready: %v %+v", err, rec.Seed)
+ }
+ if err := SeedFail(seed.ID, "copy-in-storage")(&rec); err != nil || rec.Seed.State != seeds.StateAborted || rec.Seed.Reason != "copy-in-storage" {
+ t.Fatalf("aborted: %v %+v", err, rec.Seed)
+ }
+ for _, c := range []struct{ kind, state string }{
+ {seeds.KindImport, seeds.StateReady}, {seeds.KindImport, seeds.StateAborted},
+ {seeds.KindFile, seeds.StateReserving}, {seeds.KindFile, seeds.StatePlaced},
+ } {
+ other := testSeed(t, c.kind, c.state)
+ if err := SeedFail(other.ID, "x")(&Record{Seed: other}); !errors.Is(err, ErrSeedConflict) {
+ t.Errorf("%s %s: %v", c.kind, c.state, err)
+ }
+ }
+ if err := SeedFail("sd_other", "x")(&Record{Seed: testSeed(t, seeds.KindFile, seeds.StateReady)}); !errors.Is(err, ErrSeedConflict) {
+ t.Errorf("another id: %v", err)
+ }
+}
+
+func TestSeedAbortFileUploadOnlyWhileReserving(t *testing.T) {
+ seed := testSeed(t, seeds.KindFile, seeds.StateReserving)
+ rec := Record{Seed: seed}
+ if err := SeedAbortFileUploadBecause(seed.ID, "too big")(&rec); err != nil || rec.Seed.State != seeds.StateAborted || rec.Seed.Reason != "too big" {
+ t.Fatalf("reserving: %v %+v", err, rec.Seed)
+ }
+ for _, state := range []string{seeds.StateReady, seeds.StatePlaced, seeds.StateAborted, seeds.StateRolledBack} {
+ s := testSeed(t, seeds.KindFile, state)
+ if err := SeedAbortFileUploadBecause(s.ID, "x")(&Record{Seed: s}); !errors.Is(err, ErrSeedConflict) || s.State != state {
+ t.Errorf("%s: %v", state, err)
+ }
+ }
+}
+
+func TestMoveBlockFileUnplaced(t *testing.T) {
+ for state, want := range map[string]string{seeds.StateReserving: SeedMoveUnplaced, seeds.StateReady: SeedMoveUnplaced,
+ seeds.StateAborted: SeedMoveUnplaced, seeds.StatePlaced: ""} {
+ if got := (&SeedSource{Kind: seeds.KindFile, State: state}).MoveBlock(); got != want {
+ t.Errorf("file %s: %q, want %q", state, got, want)
+ }
+ }
+}
diff --git a/internal/seeds/floor.go b/internal/seeds/floor.go
index bc0d7f322..b5df3ab77 100644
--- a/internal/seeds/floor.go
+++ b/internal/seeds/floor.go
@@ -25,7 +25,14 @@ import (
// to 1. Raising it opens nothing alone: a door opens only once an
// operator publishes the seeds floor (spec §10 step 2).
// 2 adds fresh demo-claim seeds. The ordinary doors still accept protocol 1.
-const ProtocolVersion = 2
+//
+// 3 adds file seeds: a box that places, and rolls back, a region file seed.
+const ProtocolVersion = 3
+
+// FileSeedProtocol is the protocol a region file seed needs of every box in
+// its region (fleet seeded create plan D1). A fleet file seed needs a higher
+// one, added with the fleet release.
+const FileSeedProtocol = 3
// RequiredProtocol is what the console requires every box in the region to
// report before it writes any seed state (spec §3.3).
diff --git a/internal/seeds/floor_test.go b/internal/seeds/floor_test.go
index 28231e217..fb1d46186 100644
--- a/internal/seeds/floor_test.go
+++ b/internal/seeds/floor_test.go
@@ -118,3 +118,12 @@ func TestProtocolMeetsWhatTheConsoleRequires(t *testing.T) {
t.Fatalf("ProtocolVersion = %d, RequiredProtocol = %d", ProtocolVersion, RequiredProtocol)
}
}
+
+func TestFileSeedProtocol(t *testing.T) {
+ if FileSeedProtocol != 3 || ProtocolVersion != 3 {
+ t.Fatalf("FileSeedProtocol = %d, ProtocolVersion = %d; want 3 and 3", FileSeedProtocol, ProtocolVersion)
+ }
+ if ProtocolVersion < FileSeedProtocol {
+ t.Fatal("a build that places file seeds must report at least FileSeedProtocol")
+ }
+}
diff --git a/internal/seeds/seeds.go b/internal/seeds/seeds.go
index 1a14b82ba..834b4dbaa 100644
--- a/internal/seeds/seeds.go
+++ b/internal/seeds/seeds.go
@@ -27,6 +27,7 @@ const (
DemoClaimProtocol = 2
KindReplica = "replica" // --from: a sibling's replica
KindImport = "import" // an uploaded snapshot
+ KindFile = "file" // an uploaded file, --from's states (fleet seeded create design §3.2)
)
// The states of spec §3.2.
diff --git a/internal/seeds/seeds_test.go b/internal/seeds/seeds_test.go
index 108f3693a..42bf43dab 100644
--- a/internal/seeds/seeds_test.go
+++ b/internal/seeds/seeds_test.go
@@ -180,3 +180,20 @@ func TestClosedGateIsTheRegistrysClosedGate(t *testing.T) {
t.Fatalf("seeds.ClosedGate = %q, registry.ImportGateClosed = %q", ClosedGate, registry.ImportGateClosed)
}
}
+
+func TestKindFileIsNotAKnownImport(t *testing.T) {
+ if KindFile != "file" {
+ t.Fatalf("KindFile = %q", KindFile)
+ }
+ for _, k := range []string{KindReplica, KindImport, KindDemoClaim} {
+ if k == KindFile {
+ t.Errorf("KindFile collides with %q", k)
+ }
+ }
+ id, _ := NewID()
+ r := RowSeed{ID: id, Kind: KindFile, SHA256: strings.Repeat("a", 64), Bytes: 1, State: StateReady}
+ got, err := ParseRowSeed(r.Encode())
+ if err != nil || got == nil || *got != r {
+ t.Fatalf("round trip = %+v, %v", got, err)
+ }
+}