//go:build linux && rootrunner package host import ( "bytes" "context" "os" "testing" "github.com/carlosframework/platform/internal/instancectl" "github.com/carlosframework/platform/internal/rootstate" ) func plan14ProductionStartupDefersReplacement(t *testing.T, original *ClaimLaunchRoot, material *claimUnitMaterializer, binding claimUnitBinding, ctl func(context.Context, ...string) (string, error)) { t.Helper() launch := *original before, id, err := material.read(binding.Shape.Unit) if err != nil { t.Fatal(err) } invocation, err := ctl(t.Context(), "show", binding.Shape.Unit, "-p", "InvocationID", "--value") if err != nil || invocation == "" { t.Fatal("missing live predecessor", err) } oldOpen, oldMaterials, oldShapes := openClaimUnitBindings, openClaimUnitMaterializations, productionClaimUnitShapes defer func() { openClaimUnitBindings, openClaimUnitMaterializations, productionClaimUnitShapes = oldOpen, oldMaterials, oldShapes }() openClaimUnitBindings = func() (rootstate.Store, error) { return launch.unitBindings.state, nil } openClaimUnitMaterializations = func() (rootstate.Store, error) { return material.state, nil } productionClaimUnitShapes = func() (map[string]claimUnitShape, error) { return map[string]claimUnitShape{binding.Shape.Host: binding.Shape}, nil } base := launch.Units.(instancectl.ClaimUnits) base.BoundHost, base.BoundUnit = "", "" for _, retained := range []bool{true, false} { if !retained { if err := launch.unitBindings.state.Remove(binding.Shape.Host + ".json"); err != nil { t.Fatal(err) } } launch.Units = base wrapped := ClaimRootWithLaunch{Launch: &launch} wrapped.Root.Stop.Coordinator.Kernel = claimUnitStopKernel{Units: base} assembly := &ClaimAssembly{} if err := bindProductionClaimUnits(t.Context(), &wrapped, assembly); err != nil { t.Fatal("named unit blocked control startup", err) } after, afterID, err := material.read(binding.Shape.Unit) if err != nil || !bytes.Equal(before, after) || !id.Same(afterID) { t.Fatal("startup replaced named unit before reserved startup works", err) } afterInvocation, err := ctl(t.Context(), "show", binding.Shape.Unit, "-p", "InvocationID", "--value") if err != nil || afterInvocation != invocation { t.Fatal("startup stopped live predecessor", err) } if _, err := material.load(binding.Shape.Host); !os.IsNotExist(err) { t.Fatal("startup retained named replacement intent", err) } if !retained { if _, err := launch.unitBindings.read(binding.Shape.Host); !os.IsNotExist(err) { t.Fatal("startup established named authority before startup works", err) } } } }