grouproll: the ten required mutations as executor seams
TestRequiredMutations ports test_ten_required_mutations: decrement=false, permit before Standby, blind desired reset, exit on timeout, an ignored lock, CONTINUE and ABANDON on Pending:Wait, an unflagged divergence, a terminated member recorded as pass and PreInService as InService. Each fails its named scenario; each scenario passes unmutated. Seams take the engine. A finish-return refusal now stops through the return loop, as the script's finish_return runs inside the loop's try.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+131
−20
internal/grouproll/mutation_test.go+111 −0internal/grouproll/roll.go+20 −20
Intent
diff --git a/internal/grouproll/mutation_test.go b/internal/grouproll/mutation_test.go| new file mode 100644 |
| index 000000000..07e087e8e |
| --- /dev/null |
| +++ b/internal/grouproll/mutation_test.go |
| @@ -0,0 +1,111 @@ |
| +//go:build linux || darwin |
| + |
| +package grouproll |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "os" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// TestRequiredMutations ports the script's test_ten_required_mutations |
| +// (scripts/region_group_roll_test.py:2622): each source mutation becomes an |
| +// executor hook (the engine's unexported seams), an injected decider, the |
| +// adapter's phase mapping or the lock seam, and each must fail the |
| +// scenario the script names. |
| +func TestRequiredMutations(t *testing.T) { |
| + // call journals and sends an extra provider operation, as the |
| + // mutants' inserted self.call lines do. |
| + call := func(ctx context.Context, e *Engine, op string, args map[string]any, send func() (any, error)) { |
| + e.call(ctx, op, args, time.Time{}, func(context.Context, func(string)) (any, error) { return send() }) |
| + } |
| + complete := func(h *harness, result string) func(ctx context.Context, e *Engine) { |
| + return func(ctx context.Context, e *Engine) { |
| + args := map[string]any{"iid": fakeIID, "hook": h.c.Hook, "result": result} |
| + call(ctx, e, "complete", args, func() (any, error) { return h.f.complete(fakeIID, result) }) |
| + } |
| + } |
| + cases := []struct { |
| + name string |
| + mutate func(h *harness) |
| + scenario func(h *harness) error |
| + }{ |
| + {"decrement=false", func(h *harness) { h.seams.noDecrement = true }, scenarioStandbyRollOrder}, |
| + {"permit-before-Standby", func(h *harness) { |
| + h.seams.beforeEnter = func(ctx context.Context, e *Engine) { |
| + e.box(ctx, fakeIID, "permit", BoxArgs{Permit: map[string]any{}}) |
| + } |
| + }, scenarioStandbyRollOrder}, |
| + {"blind desired reset", func(h *harness) { |
| + h.seams.afterExit = func(ctx context.Context, e *Engine) { |
| + n := e.hInt("n") |
| + call(ctx, e, "desired", map[string]any{"value": n}, func() (any, error) { |
| + w, err := h.f.RaiseDesired(ctx, n) |
| + return writeMap(w), err |
| + }) |
| + } |
| + }, scenarioStandbyRollOrder}, |
| + {"exit-on-timeout", func(h *harness) { |
| + h.seams.beforeAlert = func(ctx context.Context, e *Engine) { |
| + call(ctx, e, "exit", map[string]any{"iid": fakeIID}, func() (any, error) { |
| + w, err := h.f.Unpark(ctx, fakeIID) |
| + return writeMap(w), err |
| + }) |
| + } |
| + }, scenarioStandbySharedOutage}, |
| + {"ignored transaction lock", func(h *harness) { |
| + old := flockGroup |
| + flockGroup = func(*os.File) error { return nil } |
| + h.t.Cleanup(func() { flockGroup = old }) |
| + }, scenarioLockRefusesSecondWriter}, |
| + {"tool sends CONTINUE on Pending:Wait", func(h *harness) { h.seams.onDiverged = complete(h, "CONTINUE") }, |
| + func(h *harness) error { return scenarioHookDivergence(h, true) }}, |
| + {"tool sends ABANDON", func(h *harness) { h.seams.onDiverged = complete(h, "ABANDON") }, |
| + func(h *harness) error { return scenarioHookDivergence(h, true) }}, |
| + {"divergence not flagged", func(h *harness) { h.seams.skipDivergence = true }, |
| + func(h *harness) error { return scenarioHookDivergence(h, true) }}, |
| + {"terminated member recorded as pass", func(h *harness) { |
| + h.classify = func(f Facts) Decision { |
| + if d := Classify(f); d.Action == "failed" && d.Reason == "lost_member" { |
| + return Decision{Action: "finish-return"} |
| + } |
| + return Classify(f) |
| + } |
| + }, scenarioDefaultAbandon}, |
| + {"PreInService as InService", func(h *harness) { |
| + h.f.phase = func(raw string) Phase { |
| + if raw == "PreInService" { |
| + return Serving |
| + } |
| + return fakePhase(raw) |
| + } |
| + }, scenarioPreInService}, |
| + } |
| + for _, c := range cases { |
| + t.Run(c.name, func(t *testing.T) { |
| + // The unmutated scenario passes. |
| + clean := newHarness(t, 2) |
| + clean.f.collect = true |
| + if err := c.scenario(clean); err != nil { |
| + t.Fatalf("scenario fails without the mutation: %v", err) |
| + } |
| + h := newHarness(t, 2) |
| + h.f.collect = true |
| + c.mutate(h) |
| + err := func() (err error) { |
| + defer func() { |
| + if r := recover(); r != nil { |
| + err = fmt.Errorf("panicked: %v", r) |
| + } |
| + }() |
| + return c.scenario(h) |
| + }() |
| + if err == nil { |
| + t.Fatalf("%s survived", c.name) |
| + } |
| + t.Logf("mutation caught: %s: %v", c.name, err) |
| + }) |
| + } |
| +} |
diff --git a/internal/grouproll/roll.go b/internal/grouproll/roll.go| index e358e7aea..db56917a8 100644 |
| --- a/internal/grouproll/roll.go |
| +++ b/internal/grouproll/roll.go |
| @@ -51,12 +51,12 @@ func isStop(err error, kind string) bool { |
| // the zero value is production). Each names the script line its mutant |
| // changes. |
| type seams struct { |
| - noDecrement bool // enter with decrement=False |
| - beforeEnter func(ctx context.Context) // a box call before EnterStandby |
| - afterExit func(ctx context.Context) // a provider call after ExitStandby |
| - beforeAlert func(ctx context.Context) // a provider call before a resumable stop |
| - onDiverged func(ctx context.Context) // a provider call on a return hook |
| - skipDivergence bool // the divergence flag is not written |
| + noDecrement bool // enter with decrement=False |
| + beforeEnter func(ctx context.Context, e *Engine) // a box call before EnterStandby |
| + afterExit func(ctx context.Context, e *Engine) // a provider call after ExitStandby |
| + beforeAlert func(ctx context.Context, e *Engine) // a provider call before a resumable stop |
| + onDiverged func(ctx context.Context, e *Engine) // a provider call on a return hook |
| + skipDivergence bool // the divergence flag is not written |
| } |
| // observed are the loop observations classify reads beside the journal |
| @@ -579,7 +579,7 @@ func (e *Engine) stopDecision(ctx context.Context, d Decision, opErr error) erro |
| return opErr |
| } |
| if e.seams.beforeAlert != nil { |
| - e.seams.beforeAlert(ctx) |
| + e.seams.beforeAlert(ctx, e) |
| } |
| return e.alert(d.Reason, false) |
| } |
| @@ -766,7 +766,7 @@ func (e *Engine) resume(ctx context.Context) error { |
| } |
| } |
| if e.seams.beforeEnter != nil { |
| - e.seams.beforeEnter(ctx) |
| + e.seams.beforeEnter(ctx, e) |
| } |
| w, err := e.parkMember(ctx, iid) |
| if err != nil { |
| @@ -1173,7 +1173,7 @@ func (e *Engine) returnMember(ctx context.Context) error { |
| return e.stopDecision(ctx, d, opErr) |
| case "diverged": |
| if e.seams.onDiverged != nil { |
| - e.seams.onDiverged(ctx) |
| + e.seams.onDiverged(ctx, e) |
| } |
| intent, hasIntent := e.last("exit-intent", nil) |
| if !e.seams.skipDivergence { |
| @@ -1242,7 +1242,7 @@ func (e *Engine) returnMember(ctx context.Context) error { |
| return err |
| } |
| if e.seams.afterExit != nil { |
| - e.seams.afterExit(ctx) |
| + e.seams.afterExit(ctx, e) |
| } |
| group, o = nil, observed{} |
| case "hold": |
| @@ -1274,7 +1274,12 @@ func (e *Engine) returnMember(ctx context.Context) error { |
| } |
| group, o = nil, observed{} |
| case "finish-return": |
| - return errFinished{e.finishReturn(ctx, ready)} |
| + // Its refusals stop the loop as any operation's do (the |
| + // script's finish_return runs inside the loop's try). |
| + if err := e.finishReturn(ctx, ready); err != nil { |
| + return err |
| + } |
| + return errFinished{} |
| default: |
| return fmt.Errorf("grouproll: classify chose %q, which return does not execute", d.Action) |
| } |
| @@ -1284,7 +1289,7 @@ func (e *Engine) returnMember(ctx context.Context) error { |
| switch { |
| case err == nil: |
| case errors.As(err, &done): |
| - return done.err |
| + return nil |
| case isStop(err, "drain-moving"): |
| return err |
| case refusalOrUncertain(err): |
| @@ -1300,15 +1305,10 @@ func (e *Engine) returnMember(ctx context.Context) error { |
| } |
| } |
| -// errFinished carries finish-return's outcome out of the loop untouched. |
| -type errFinished struct{ err error } |
| +// errFinished ends the return loop after a finished return. |
| +type errFinished struct{} |
| -func (e errFinished) Error() string { |
| - if e.err == nil { |
| - return "finished" |
| - } |
| - return e.err.Error() |
| -} |
| +func (errFinished) Error() string { return "finished" } |
| // returnReadiness is the return's observe-ready: the member's readiness |
| // with the maintenance checks, the process the exit intent named once the |