diff --git a/changelog.d/fixed-trackerrow-drift-guard.md b/changelog.d/fixed-trackerrow-drift-guard.md new file mode 100644 index 0000000000..3254210088 --- /dev/null +++ b/changelog.d/fixed-trackerrow-drift-guard.md @@ -0,0 +1 @@ +- The shared tracker row asset now exports `trackerrow.RequiredGlobals`, the `STAGE_TRACKER_*` constants it reads from its host page pinned to the spoke's values, and tests fail if that list drifts from the asset or if the spoke declares a different value, so the hub cannot silently light different columns than the spoke. `dashboard-source-layout.md` also lists `tracker-human-attention` in manifest order (#16067, #16068). diff --git a/src/docs/dashboard-source-layout.md b/src/docs/dashboard-source-layout.md index 66c04266ed..0546e8186a 100644 --- a/src/docs/dashboard-source-layout.md +++ b/src/docs/dashboard-source-layout.md @@ -77,7 +77,8 @@ JS (`js/`): `boot`, `core`, `feedback`, `sections`, `layout`, `agent-detail`, `sidebar`, `history-sparklines`, `cost-trend`, `stats`, `agent-now`, `tracker-words-core`, `tracker-words-stage`, `tracker-words-gate`, `tracker-words`, `tracker-row-anchor`, `tracker-row`, `tracker-row-strip`, -`tracker-row-acted`, `tracker-row-layout`, `tracker-row-title`, +`tracker-row-acted`, `tracker-human-attention`, `tracker-row-layout`, +`tracker-row-title`, `tracker-row-render`, `tracker-motion`, `tracker-filter`, `tracker-filter-state`, `nav-count-delta`, `tracker-preparation`, `tracker-native-queue`, `tracker-filter-render`, diff --git a/src/pkg/dashboard/tracker_row_shared_asset_test.go b/src/pkg/dashboard/tracker_row_shared_asset_test.go index 423549fae5..d92166908c 100644 --- a/src/pkg/dashboard/tracker_row_shared_asset_test.go +++ b/src/pkg/dashboard/tracker_row_shared_asset_test.go @@ -46,6 +46,19 @@ func TestTrackerRowSharedAssetCompat(t *testing.T) { } } +// TestTrackerRowRequiredGlobalsDefinedBySpoke pins that the spoke page defines +// every STAGE_TRACKER_* constant the shared row asset reads with exactly the +// value trackerrow.RequiredGlobals carries (hivecommons/hive#16068), so the +// list the hub asserts against is the one the spoke serves. +func TestTrackerRowRequiredGlobalsDefinedBySpoke(t *testing.T) { + html := indexHTML(t) + for _, g := range trackerrow.RequiredGlobals { + if got := strings.TrimSpace(jsConstLine(t, html, g.Name)); got != g.Decl() { + t.Errorf("spoke declares %q, trackerrow.RequiredGlobals pins %q; edit both together", got, g.Decl()) + } + } +} + // TestTrackerRowSharedAssetRendersSpokeFixtures renders the same fixtures // through the functions the spoke page defines and through the shared asset // files, and pins both to the spoke's existing columns and title markup. diff --git a/src/pkg/webassets/trackerrow/trackerrow.go b/src/pkg/webassets/trackerrow/trackerrow.go index a80d5863d8..9a0a5af04d 100644 --- a/src/pkg/webassets/trackerrow/trackerrow.go +++ b/src/pkg/webassets/trackerrow/trackerrow.go @@ -30,3 +30,37 @@ var Files = []string{ // stageTrackerSplitTitleTag / stageTrackerTitleHtml: the escaped, text-only title. "tracker-row-title.js", } + +// Global is one STAGE_TRACKER_* constant the assets read as a free global, +// with the spoke's JavaScript literal for it. +type Global struct { + Name string + // JS is the spoke's literal for the constant, verbatim as it appears in + // pkg/dashboard/static-src/js (agent-now.js, tracker-words-core.js). + JS string +} + +// Decl returns the `const NAME = JS;` declaration a host page must carry. +func (g Global) Decl() string { + return "const " + g.Name + " = " + g.JS + ";" +} + +// RequiredGlobals lists the STAGE_TRACKER_* constants the assets read as free +// globals, each pinned to the spoke's value (hivecommons/hive#16068). A host +// must define every one with exactly that value: TestRequiredGlobals keeps +// the names equal to what the assets reference, and +// TestTrackerRowRequiredGlobalsDefinedBySpoke in pkg/dashboard fails when the +// spoke's declaration differs from Decl(), so the hub can assert its own +// definitions against this list when it embeds the assets. +var RequiredGlobals = []Global{ + {Name: "STAGE_TRACKER_ISSUE_DECISION_COLUMN", JS: "10"}, + {Name: "STAGE_TRACKER_ISSUE_NEEDS_DECISION", JS: "45"}, + {Name: "STAGE_TRACKER_MERGE_COLUMN", JS: "80"}, + {Name: "STAGE_TRACKER_NEEDS_DECISION", JS: "85"}, + {Name: "STAGE_TRACKER_PATH", JS: "[0, 10, 20, 30, 50, 80]"}, + {Name: "STAGE_TRACKER_POSSIBLY_EXISTS", JS: "17"}, + {Name: "STAGE_TRACKER_PRE_MERGE_SOAK", JS: "95"}, + {Name: "STAGE_TRACKER_PR_COLUMN", JS: "30"}, + {Name: "STAGE_TRACKER_TERMINAL", JS: "110"}, + {Name: "STAGE_TRACKER_TRIAGE_NEEDED", JS: "15"}, +} diff --git a/src/pkg/webassets/trackerrow/trackerrow_test.go b/src/pkg/webassets/trackerrow/trackerrow_test.go index 02291bd8a3..18acfb4566 100644 --- a/src/pkg/webassets/trackerrow/trackerrow_test.go +++ b/src/pkg/webassets/trackerrow/trackerrow_test.go @@ -2,6 +2,8 @@ package trackerrow import ( "io/fs" + "regexp" + "sort" "strings" "testing" ) @@ -62,3 +64,39 @@ func TestAssetsDefineRowFunctions(t *testing.T) { } } } + +// TestRequiredGlobals pins RequiredGlobals to the STAGE_TRACKER_* names the +// embedded assets reference, so a new input cannot be added without listing +// it, and that every entry carries a value and a well-formed declaration. +func TestRequiredGlobals(t *testing.T) { + re := regexp.MustCompile(`\bSTAGE_TRACKER_[A-Z0-9_]+\b`) + seen := map[string]bool{} + for _, name := range Files { + b, err := fs.ReadFile(FS, name) + if err != nil { + t.Fatal(err) + } + for _, m := range re.FindAllString(string(b), -1) { + seen[m] = true + } + } + var got []string + for m := range seen { + got = append(got, m) + } + sort.Strings(got) + var want []string + for _, g := range RequiredGlobals { + want = append(want, g.Name) + if g.JS == "" { + t.Errorf("%s has no JS value; RequiredGlobals must pin the spoke's literal", g.Name) + } + if d := g.Decl(); d != "const "+g.Name+" = "+g.JS+";" || !re.MatchString(d) { + t.Errorf("%s Decl() = %q", g.Name, d) + } + } + sort.Strings(want) + if strings.Join(got, ",") != strings.Join(want, ",") { + t.Errorf("assets reference %v, RequiredGlobals is %v", got, want) + } +}