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(afterHid(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 // (1901/AC3). A failure that hides its cause (none, or a passing line) is said loudly first in the words and in the status // line, naming the build module and the version it says it is, and the level still fails; a failure that keeps the // contract is worded as before (1901/AC8). func TestAnOlderBuildModulesFailureIsAcceptedWithItsWholeOutput(t *testing.T) { // 1901/AC3, AC8 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 afterHid(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, "the build module hid the failure") || strings.Contains(got, "\n") { t.Errorf("1901/AC3, AC8: status = %q", got) } by := "mesh-build-node with mesh-sdk v0.1.14-0.20261026184535-e40dd0f56a78" for _, c := range []struct { name, module, by, cause, output, loud string }{ {"no cause", "mesh-build-node", by, "", "test/b.test.ts: something", "the build module hid the failure (mesh-build-node at mesh-sdk v0.1.14-0.20261026184535-e40dd0f56a78): it sent no cause"}, {"a passing line as its cause", "mesh-build-node", by, "\u2714 the same merge has the same id (8.006913ms)", "", "the build module hid the failure (mesh-build-node at mesh-sdk v0.1.14-0.20261026184535-e40dd0f56a78): its cause is a passing line"}, {"from before the contract", "mesh-build-node", "", "", "\u2714 the same merge has the same id (8.006913ms)", "the build module hid the failure (mesh-build-node at a version before the failure contract): it sent no cause"}, {"a real cause", "mesh-build-node", by, "one plus one is not three", "not ok 3 - fails", ""}, } { t.Run(c.name, func(t *testing.T) { v := levelFailure(&target{module: c.module}, "unit", Tested{By: c.by, Failed: []Failure{{Package: "modules/gitea", Test: "fails", Cause: c.cause, Output: c.output}}}) if v.State != delivery.VerdictFail { t.Errorf("1901/AC8: the verdict is %q, want it failed", v.State) } line := firstFailed(*v) switch { case c.loud == "" && strings.Contains(v.Failed.Words, "hid the failure"): t.Errorf("1901/AC8: a failure that keeps the contract is said hidden: %q", v.Failed.Words) case c.loud != "" && (!strings.HasPrefix(v.Failed.Words, c.loud) || !strings.Contains(line, c.loud) || !strings.Contains(v.Failures[0].Words, "hid the failure")): t.Errorf("1901/AC8: words %q, status %q, want both to start with %q", v.Failed.Words, line, c.loud) } }) } }