Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-trackerrow-drift-guard.md
Original file line number Diff line number Diff line change
@@ -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).
3 changes: 2 additions & 1 deletion src/docs/dashboard-source-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
13 changes: 13 additions & 0 deletions src/pkg/dashboard/tracker_row_shared_asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 34 additions & 0 deletions src/pkg/webassets/trackerrow/trackerrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
38 changes: 38 additions & 0 deletions src/pkg/webassets/trackerrow/trackerrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package trackerrow

import (
"io/fs"
"regexp"
"sort"
"strings"
"testing"
)
Expand Down Expand Up @@ -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)
}
}
Loading