package host import ( "github.com/carlosframework/platform/internal/moves" "testing" ) func TestPlan14FloorReconstruction(t *testing.T) { a := moves.Floor{Min: 1, MinRelease: "v1.0.0"} b := moves.Floor{Min: 2, MinRelease: "v2.0.0"} c := moves.Floor{Min: 3, MinRelease: "v3.0.0"} for _, tc := range []struct { name string history, remote *moves.Floor legacy []*moves.Floor want *moves.Floor bad bool }{ {"remote deleted", &b, nil, nil, &b, false}, {"remote regressed", &b, &a, nil, &b, true}, {"legacy stricter", &a, &a, []*moves.Floor{&b}, &b, true}, {"legacy cannot grant", nil, &b, []*moves.Floor{&b}, nil, true}, {"both legacy files missing", nil, &a, nil, nil, true}, {"remote and legacy missing", nil, nil, nil, nil, true}, {"corrupt legacy", &a, &c, []*moves.Floor{{Min: 2, MinRelease: "broken"}}, nil, true}, {"root history survives legacy deletion", &b, &c, nil, &c, false}, {"independent minima", &a, nil, []*moves.Floor{{Min: 3, MinRelease: "v1.0.0"}, &b}, &moves.Floor{Min: 3, MinRelease: "v2.0.0"}, true}, } { t.Run(tc.name, func(t *testing.T) { got, err := reconstructRootFloor(tc.history, tc.remote, tc.legacy) if (err != nil) != tc.bad { t.Fatalf("error = %v", err) } if (got == nil) != (tc.want == nil) || (got != nil && *got != *tc.want) { t.Fatalf("floor=%+v, want %+v", got, tc.want) } }) } }