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

Function TestMainLoopStopStringAndReason

internal/llmloop/loop_test.go:801–832  ·  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

799// stop diagnostics surviving a --format json run. Neither may collide across
800// stops, or a reader cannot tell which exit fired from the artifact alone.
801func TestMainLoopStopStringAndReason(t *testing.T) {
802 names := make(map[string]MainLoopStop)
803 reasons := make(map[string]MainLoopStop)
804 for _, tc := range []struct {
805 stop MainLoopStop
806 wantName string
807 }{
808 {StopNone, "none"},
809 {StopMaxRounds, "max_rounds"},
810 {StopEmptyRounds, "empty_rounds"},
811 {StopCompression, "compression"},
812 } {
813 t.Run(tc.wantName, func(t *testing.T) {
814 name := tc.stop.String()
815 if name != tc.wantName {
816 t.Errorf("String() = %q, want %q", name, tc.wantName)
817 }
818 reason := tc.stop.Reason()
819 if reason == "" {
820 t.Fatal("Reason() is empty; every stop needs a diagnostic sentence")
821 }
822 if prev, dup := names[name]; dup {
823 t.Errorf("String() %q is shared by %v and %v", name, prev, tc.stop)
824 }
825 if prev, dup := reasons[reason]; dup {
826 t.Errorf("Reason() %q is shared by %v and %v; stops must stay distinguishable", reason, prev, tc.stop)
827 }
828 names[name] = tc.stop
829 reasons[reason] = tc.stop
830 })
831 }
832}
833
834// A value outside the enum must name itself in both registers rather than borrow
835// 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