package thintest import ( "strings" "testing" "amadan.net/oficina/equipo/internal/wire" ) // TestShellUnavailableRoundIsFree (stopped-jobs audit, fix 4): a fix // round the engineer ran without a working shell (the runner reports it // done with shell_unavailable) does not count against the task's two // automatic rounds; at most two such rounds are free. The next round is // still told it is round 1 of 2. func TestShellUnavailableRoundIsFree(t *testing.T) { for _, free := range []int{0, 1, 3} { r := newToolRigAt(t, wire.ProtocolCurrent) base := strings.Repeat("1", 40) sha := func(n int) string { return strings.Repeat(string(rune('2'+n)), 40) } id, _ := r.pushed("f", "Add project rename control", base, sha(0)) task := r.task(id) r.expect(wire.FrameWatchMerge) rounds := 0 for n := 0; ; n++ { c := r.dispatched(wire.SpecialistChecks, base, sha(n), n) r.step("f-c"+itoa(n), hostedReport(c, task.Branch, wire.HostedFailure, "compile")) if r.task(id).NeedsYou == wire.NeedsFixRounds { break } fix := r.dispatched(wire.SpecialistEngineering, sha(n), "", n+1) reason := "" if n < free { reason = "shell_unavailable" } counted := n + 1 - min(n, free, wire.MaxFixRounds) if want := "Fix round " + itoa(counted) + " of 2."; !strings.Contains(fix.Feedback, want) { t.Fatalf("free %d, round %d: feedback lacks %q: %q", free, n+1, want, fix.Feedback) } r.step("f-e"+itoa(n), wire.StepReport{TaskID: id, StepID: fix.StepID, Attempt: 1, State: wire.StepDone, Reason: reason, BaseSHA: sha(n), CandidateSHA: sha(n + 1), Pushed: true, Termination: true}) r.expect(wire.FrameWatchMerge) rounds++ } if want := wire.MaxFixRounds + min(free, wire.MaxFixRounds); rounds != want { t.Fatalf("free %d: %d automatic rounds, want %d", free, rounds, want) } } } // shell_unavailable is a done step's reason only: a step that stopped // with it is recorded as stopped for an unknown reason. func TestShellUnavailableOnlyOnDone(t *testing.T) { r := newToolRigAt(t, wire.ProtocolCurrent) id, d := r.started("x", "Stopped oddly") r.stop("x", d, wire.ReasonShellUnavailable) if s := r.task(id).Steps[0]; s.State != wire.StepFailed || s.Reason != wire.ReasonUnknown { t.Fatalf("step %+v", s) } }