package host import ( "testing" "time" "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/release" ) // ClaimOriginProof is the moves provider's proof (movesOriginProof's batch // contract), adopted with the Plan 15 switch. var _ movesOriginProof = ClaimOriginProof{} func TestPlan15MovesProof(t *testing.T) { t.Setenv("CARLOS_HOST_CLAIM", "1") t.Setenv("CARLOS_HOST_CLAIM_ORIGINS", "1") s := release.NewDirStore(t.TempDir()) host := "test.example" o, err := hostclaim.Read(t.Context(), s, host) if err != nil { t.Fatal(err) } n := hostclaim.NewHolder{Family: "instance", Key: "apps/bab/app/instances/test.example.json", Account: "bab", App: "app", Host: host, Region: "ie", CreatedAt: time.Date(2026, 10, 12, 0, 0, 0, 0, time.UTC)} o, err = hostclaim.Update(t.Context(), s, o, hostclaim.BeginCreate(n, []byte(`{"host":"test.example","account":"bab","app":"app","created_at":"2026-10-12T00:00:00Z"}`), "create", "console", time.Now())) if err != nil { t.Fatal(err) } o, err = hostclaim.Update(t.Context(), s, o, hostclaim.CompleteCreate("create", "box")) if err != nil { t.Fatal(err) } o, err = hostclaim.Update(t.Context(), s, o, hostclaim.AdmitWriter(hostclaim.Admission{Box: "box", Mode: "cold", Region: "ie", NewGeneration: "admitted"})) if err != nil { t.Fatal(err) } for _, tc := range []struct { home, region, generation string want bool }{ {"", "ie", "admitted", true}, {"ie", "@home", "admitted", true}, {"", "@home", "admitted", false}, {"ie", "uk", "admitted", false}, {"", "ie", "prepared", false}, } { p := ClaimOriginProof{Claims: s, HomeRegion: tc.home, Region: tc.region} got, err := p.Proven(t.Context(), o, hostclaim.Admission{NewGeneration: tc.generation}, []string{tc.generation}) if got[tc.generation] != tc.want || err != nil { t.Fatalf("%+v: %v %v", tc, got, err) } } }