carlos / platform Public

console test: billing stale rows read the row's text, not its markup

TestBillingPageUsageStalePeriodUnknown failed whenever "999" appeared
anywhere in a pack row's markup; a form's CSRF token or an attribute
value now and then does, so it failed by chance on CI (main at
a23423b7). It now strips the tags and looks at the row's visible text.
Showing stale rows as figures still fails it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 41d81762acc2bfeb382422f6f46b7f56ca51518f parent a23423b
1 file changed, +8 −1
  • internal/console/billingusage_test.go +8 −1

CI passed — run details

diff --git a/internal/console/billingusage_test.go b/internal/console/billingusage_test.go
index b071d2ec4..7a3b17176 100644
--- a/internal/console/billingusage_test.go
+++ b/internal/console/billingusage_test.go
@@ -49,6 +49,9 @@ func changeRow(t *testing.T, body, name string) string {
return m[1]
}
+// markupTags matches every tag, attributes and all, to read a row's text.
+var markupTags = regexp.MustCompile(`<[^>]*>`)
+
// useSpan is the usage element a row or card carries, "" for none.
var useSpan = regexp.MustCompile(`<(?:span|dd) class="[^"]*\buse\b[^"]*">[^<]*</(?:span|dd)>`)
@@ -138,7 +141,11 @@ func TestBillingPageUsageStalePeriodUnknown(t *testing.T) {
if got := useOf(t, row); got != unknown {
t.Errorf("%s: usage %q, want %q", pack, got, unknown)
}
- if strings.Contains(row, "999") || strings.Contains(row, "70 GB") || strings.Contains(row, esc(fmt.Sprintf(billingCopy["usage.of_today"], "0", "1,000"))) {
+ // The row's visible text, not its markup: a form's CSRF token or an
+ // attribute value contains "999" now and then, which failed this
+ // test by chance on CI (main at a23423b7).
+ text := markupTags.ReplaceAllString(row, " ")
+ if strings.Contains(text, "999") || strings.Contains(text, "70 GB") || strings.Contains(text, esc(fmt.Sprintf(billingCopy["usage.of_today"], "0", "1,000"))) {
t.Errorf("%s: a stale row shows as a figure:\n%s", pack, row)
}
}