package host import ( "errors" "github.com/carlosframework/platform/internal/hostwrite" "github.com/carlosframework/platform/internal/release" "testing" ) func TestPlan14Fix2RecoveryContinuesPastBadAttempt(t *testing.T) { t.Parallel() e, _, u, c, pub := plan14AdoptionFixture(t) u.crashNew = true restart := rootRestartRouteWith(e.root.reg, u, u.opt, func(string) string { return "5s" }, nil, c) crashed := errors.New("crash") func() { defer func() { if recover() != crashed { t.Fatal("missing crash") } }() _ = release.Pass(t.Context(), e.root.reg, e.store, pub, u.opt, func(host string) error { _ = restart(host); panic(crashed) }, release.WithRestartFailurePropagation()) }() state, err := c.attempts() if err != nil { t.Fatal(err) } if err := state.Write("0.attempt", []byte("malformed")); err != nil { t.Fatal(err) } if err := recoverRootRestarts(t.Context(), u, u.opt, func(string) string { return "5s" }, c, hostwrite.Config{}); err == nil { t.Fatal("corrupt attempt not reported") } if u.props.MainPID <= 0 || u.exe != release.VersionPath(u.opt, "bab", "v1", "console") { t.Fatal("bad attempt skipped other host recovery") } if err := state.Remove("0.attempt"); err != nil { t.Fatal(err) } state.(*rollbackMemory).failWrite = true if err := recoverRootRestarts(t.Context(), u, u.opt, func(string) string { return "5s" }, c, hostwrite.Config{}); err != nil { t.Fatal("settled attempt rewritten", err) } }