console: billing pages copy gate checks every BDP constant
Fix round 1 of Task 2 (Astra review of fdaae167). All 150 BDP rows are in billingPagesCopyBuilt, and TestApprovedBillingPagesCopy reads opbilling_copy.go with go/parser: each row is its own constant, named by its "// BDP-n:" comment, equal to the approved text byte for byte; no constant is unnamed, doubled or outside the built list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+103
−21
approved_billing_dashboard_copy_test.go+103 −21
CI failed — run details
diff --git a/approved_billing_dashboard_copy_test.go b/approved_billing_dashboard_copy_test.go| index dab470181..cd35a4fb8 100644 |
| --- a/approved_billing_dashboard_copy_test.go |
| +++ b/approved_billing_dashboard_copy_test.go |
| @@ -2,8 +2,13 @@ |
| package main |
| import ( |
| + "go/ast" |
| + "go/parser" |
| + "go/token" |
| "os" |
| + "path/filepath" |
| "regexp" |
| + "sort" |
| "strconv" |
| "strings" |
| "testing" |
| @@ -101,8 +106,10 @@ func TestApprovedBillingDashboardCopy(t *testing.T) { |
| // |
| // - TestBillingPagesCopyInventory: the record names exactly |
| // billingPagesCopyIDs, and no row holds an em dash; |
| -// - TestApprovedBillingPagesCopy: an id in billingPagesCopyBuilt is an |
| -// approved row, and its text is in internal/console/opbilling_copy.go. |
| +// - TestApprovedBillingPagesCopy: every BDP row is in billingPagesCopyBuilt, |
| +// is approved, and is one constant of internal/console/opbilling_copy.go |
| +// (named by its "// BDP-n:" comment) whose value is the row's text byte |
| +// for byte. |
| // The record's BDC rows are the same text as Plan 1's record, which |
| // TestApprovedBillingDashboardCopy checks in the code and docs. |
| const billingPagesCopyRecordPath = "docs/superpowers/plans/2026-11-09-billing-dashboard-2-copy.md" |
| @@ -121,20 +128,72 @@ var billingPagesCopyIDs = func() []string { |
| return append(ids, "BDC-20", "BDC-36") |
| }() |
| -// billingPagesCopyBuilt is every BDP row the pages render. Every row has |
| -// its constant in opbilling_copy.go from Task 2; the task that renders a |
| -// row adds its id here in the same commit. |
| -var billingPagesCopyBuilt = []string{ |
| - // Task 2: the rail label (also the overview's <h1>), the three pages' |
| - // titles and subheads, and the test-mode line. |
| - "BDP-1", "BDP-2", "BDP-3", "BDP-100", "BDP-116", "BDP-136", "BDP-137", |
| -} |
| +// billingPagesCopyBuilt is every BDP row the code carries: all of them, |
| +// since Task 2 wrote each row's constant in opbilling_copy.go. Later tasks |
| +// only use the constants. |
| +var billingPagesCopyBuilt = func() []string { |
| + ids := make([]string, 0, 150) |
| + for i := 1; i <= 150; i++ { |
| + ids = append(ids, "BDP-"+strconv.Itoa(i)) |
| + } |
| + return ids |
| +}() |
| -// billingPagesShortGoText is the built rows checked as a whole string |
| -// literal of opbilling_copy.go (checkShortGoText), so a word is never |
| -// matched as a fragment of a longer one. |
| -var billingPagesShortGoText = map[string]bool{ |
| - "BDP-1": true, "BDP-100": true, "BDP-136": true, |
| +// billingPagesCopyFile is where every BDP row lives, under |
| +// billingPagesCopyRoot. |
| +const billingPagesCopyFile = "opbilling_copy.go" |
| + |
| +// billingPagesConstPattern is a row constant's id comment: "// BDP-n: ...". |
| +var billingPagesConstPattern = regexp.MustCompile(`^// (BDP-[0-9]+): `) |
| + |
| +// billingPagesConsts reads opbilling_copy.go: each constant's BDP id (from |
| +// the comment above it) and its string value. It refuses a constant with no |
| +// id, an id on two constants, and a value that is not one string literal. |
| +func billingPagesConsts(src []byte) (map[string]string, []string) { |
| + f, err := parser.ParseFile(token.NewFileSet(), billingPagesCopyFile, src, parser.ParseComments) |
| + if err != nil { |
| + return nil, []string{err.Error()} |
| + } |
| + out := map[string]string{} |
| + var problems []string |
| + for _, d := range f.Decls { |
| + g, ok := d.(*ast.GenDecl) |
| + if !ok || g.Tok != token.CONST { |
| + continue |
| + } |
| + for _, sp := range g.Specs { |
| + vs := sp.(*ast.ValueSpec) |
| + name := vs.Names[0].Name |
| + var id string |
| + if vs.Doc != nil { |
| + for _, c := range vs.Doc.List { |
| + if m := billingPagesConstPattern.FindStringSubmatch(c.Text); m != nil { |
| + id = m[1] |
| + } |
| + } |
| + } |
| + if id == "" || len(vs.Names) != 1 || len(vs.Values) != 1 { |
| + problems = append(problems, name+": not one constant under one \"// BDP-n: \" comment") |
| + continue |
| + } |
| + lit, ok := vs.Values[0].(*ast.BasicLit) |
| + if !ok || lit.Kind != token.STRING { |
| + problems = append(problems, name+" ("+id+"): its value is not one string literal") |
| + continue |
| + } |
| + v, err := strconv.Unquote(lit.Value) |
| + if err != nil { |
| + problems = append(problems, name+" ("+id+"): "+err.Error()) |
| + continue |
| + } |
| + if _, dup := out[id]; dup { |
| + problems = append(problems, id+" is the comment of two constants") |
| + continue |
| + } |
| + out[id] = v |
| + } |
| + } |
| + return out, problems |
| } |
| func mustParseBillingPagesCopyRecord(t *testing.T) []copyRow { |
| @@ -159,19 +218,42 @@ func TestBillingPagesCopyInventory(t *testing.T) { |
| func TestApprovedBillingPagesCopy(t *testing.T) { |
| rows := mustParseBillingPagesCopyRecord(t) |
| built, problems := entryBuiltRows(rows, billingPagesCopyBuilt, "billingPagesCopyBuilt") |
| - var whole []copyRow |
| + src, err := os.ReadFile(filepath.Join(billingPagesCopyRoot, billingPagesCopyFile)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + consts, cp := billingPagesConsts(src) |
| + problems = append(problems, cp...) |
| + // Every built row is its own constant, equal to the record byte for |
| + // byte, and the file holds no constant the record does not have. |
| + seen := map[string]bool{} |
| for _, r := range built { |
| if !strings.HasPrefix(r.ID, "BDP-") { |
| problems = append(problems, "billingPagesCopyBuilt names "+r.ID+": the BDC rows are built through Plan 1's record") |
| continue |
| } |
| - if billingPagesShortGoText[r.ID] { |
| - problems = append(problems, checkShortGoText(r, billingPagesCopyRoot)...) |
| - continue |
| + if r.Path() != billingPagesCopyFile { |
| + problems = append(problems, r.ID+": the record's file is "+r.Path()+", not "+billingPagesCopyFile) |
| } |
| - whole = append(whole, r) |
| + seen[r.ID] = true |
| + got, ok := consts[r.ID] |
| + switch { |
| + case !ok: |
| + problems = append(problems, r.ID+": "+billingPagesCopyFile+" has no constant for it") |
| + case got != r.Text: |
| + problems = append(problems, r.ID+": the constant is "+strconv.Quote(got)+", the approved text "+strconv.Quote(r.Text)) |
| + } |
| + } |
| + var extra []string |
| + for id := range consts { |
| + if !seen[id] { |
| + extra = append(extra, id) |
| + } |
| + } |
| + sort.Strings(extra) |
| + for _, id := range extra { |
| + problems = append(problems, billingPagesCopyFile+" has a constant for "+id+", which billingPagesCopyBuilt does not name") |
| } |
| - problems = append(problems, checkMovesApplied(whole, billingPagesCopyRoot)...) |
| // The follow-ups: the approved text replaced Plan 1's row. |
| plan1 := map[string]copyRow{} |
| for _, r := range mustParseBillingDashboardCopyRecord(t) { |