package check import ( "encoding/json" "strings" "testing" "git.novox.be/novox/mesh-sdk/go/delivery" ) // The failure the build module reported for group r4g on 2026-10-23: the test logged a line, then failed with a multi-line // t.Fatalf. Its output is what the build module now sends (its last lines, with the error line as Cause). func fatalAfterLog() Failure { return Failure{ Package: "github.com/novox/mesh-controller/internal/broker", Test: "TestTheCataloguesDerivedSubjectsMeet", Cause: "3 subscription(s) derive to a subject no emitter owns:", Output: " agreement_catalogue_test.go:130: judged against /var/lib/mesh-build-go-work/id/beside/mesh-catalog as cloned\n" + " agreement_catalogue_test.go:186: 3 subscription(s) derive to a subject no emitter owns:\n" + " a.b.c\n d.e.f\n g.h.i\n--- FAIL: TestTheCataloguesDerivedSubjectsMeet (0.00s)", } } func TestAFailedTestsVerdictKeepsItsWholeFailureMessage(t *testing.T) { // 1901/AC1 v := levelFailure(&target{}, "unit", Tested{Failed: []Failure{fatalAfterLog()}}) for _, want := range []string{"3 subscription(s) derive to a subject no emitter owns:", "a.b.c", "d.e.f", "g.h.i"} { if !strings.Contains(v.Failed.Words, want) { t.Errorf("words lack %q: %q", want, v.Failed.Words) } } if len(v.Failed.Words) > MaxWords+200 { t.Errorf("words are %d bytes, bound %d", len(v.Failed.Words), MaxWords) } } func TestTheStatusLineNamesTheFailureNotTheFirstLoggedLine(t *testing.T) { // 1901/AC2 v := levelFailure(&target{}, "unit", Tested{Failed: []Failure{fatalAfterLog()}}) got := firstFailed(*v) if !strings.Contains(got, "3 subscription(s) derive to a subject no emitter owns:") || strings.Contains(got, "judged against") || strings.Contains(got, "\n") { t.Errorf("firstFailed = %q", got) } // With no cause told apart (an older build module), the words still start at the first line, as before. f := fatalAfterLog() f.Cause = "" v = levelFailure(&target{}, "unit", Tested{Failed: []Failure{f}}) if !strings.HasPrefix(v.Failed.Words, "agreement_catalogue_test.go:130") { t.Errorf("words = %q", v.Failed.Words) } } func TestWordsLongerThanTheBoundKeepTheirLastLines(t *testing.T) { // 1901/AC1 f := Failure{Output: strings.Repeat("log line of some length\n", 500) + "the cause is here"} v := levelFailure(&target{}, "unit", Tested{Failed: []Failure{f}}) if !strings.HasSuffix(v.Failed.Words, "the cause is here") || len(v.Failed.Words) > MaxWords+200 { t.Errorf("%d bytes, ends %q", len(v.Failed.Words), v.Failed.Words[len(v.Failed.Words)-30:]) } _ = delivery.VerdictFail } // An older build module sends no "cause": its answer is still accepted and the verdict's words are its output, as before. func TestAnOlderBuildModulesFailureIsAcceptedWithItsWholeOutput(t *testing.T) { // 1901/AC3 old := `{"package":"p","test":"TestX","output":"x_test.go:1: logged\nx_test.go:2: the old kept lines"}` var f Failure if err := json.Unmarshal([]byte(old), &f); err != nil || f.Cause != "" { t.Fatalf("1901/AC3: err = %v, cause = %q", err, f.Cause) } v := levelFailure(&target{}, "unit", Tested{Failed: []Failure{f}}) if v.Failed.Words != "x_test.go:1: logged\nx_test.go:2: the old kept lines" { t.Errorf("1901/AC3: words = %q", v.Failed.Words) } if got := firstFailed(*v); !strings.Contains(got, "logged") || strings.Contains(got, "\n") { t.Errorf("1901/AC3: status = %q", got) } }