MCPcopy Create free account
hub / github.com/alibaba/open-code-review / TestMainLoopStopStringAndReason

Function TestMainLoopStopStringAndReason

internal/llmloop/loop_test.go:817–848  ·  view source on GitHub ↗

MainLoopStop must be self-describing in both registers: String() for logs and telemetry, Reason() for the manifest reason and scan warning that are the only stop diagnostics surviving a --format json run. Neither may collide across stops, or a reader cannot tell which exit fired from the artifact al

(t *testing.T)

Source from the content-addressed store, hash-verified

815// stop diagnostics surviving a --format json run. Neither may collide across
816// stops, or a reader cannot tell which exit fired from the artifact alone.
817func TestMainLoopStopStringAndReason(t *testing.T) {
818 names := make(map[string]MainLoopStop)
819 reasons := make(map[string]MainLoopStop)
820 for _, tc := range []struct {
821 stop MainLoopStop
822 wantName string
823 }{
824 {StopNone, "none"},
825 {StopMaxRounds, "max_rounds"},
826 {StopEmptyRounds, "empty_rounds"},
827 {StopCompression, "compression"},
828 } {
829 t.Run(tc.wantName, func(t *testing.T) {
830 name := tc.stop.String()
831 if name != tc.wantName {
832 t.Errorf("String() = %q, want %q", name, tc.wantName)
833 }
834 reason := tc.stop.Reason()
835 if reason == "" {
836 t.Fatal("Reason() is empty; every stop needs a diagnostic sentence")
837 }
838 if prev, dup := names[name]; dup {
839 t.Errorf("String() %q is shared by %v and %v", name, prev, tc.stop)
840 }
841 if prev, dup := reasons[reason]; dup {
842 t.Errorf("Reason() %q is shared by %v and %v; stops must stay distinguishable", reason, prev, tc.stop)
843 }
844 names[name] = tc.stop
845 reasons[reason] = tc.stop
846 })
847 }
848}
849
850// A value outside the enum must name itself in both registers rather than borrow
851// the StopNone catch-all. This also guards the enum's growth: adding a constant

Callers

nothing calls this directly

Calls 3

ReasonMethod · 0.80
RunMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected