This is an automated email from the ASF dual-hosted git repository. LinkinStars pushed a commit to branch dev in repository https://gitbox.apache.org/repos/asf/answer.git
commit 69fc3c96c3800f673f9ad1d2b0c7d32105c86b9f Author: Xan Torres <[email protected]> AuthorDate: Sat Aug 1 21:09:52 2026 +0800 test: assert every declared stylesheet is parsed, not just one Asserting that the parsed stylesheet list is non-empty leaves the exact regression this repository already hit uncovered: a parser that stops at the first stylesheet returns a one element list, satisfies every existing assertion, and silently drops the rest of the page's CSS. Count the declarations again by a cruder method than the parser uses and require the two to agree, so the parser has to be checked against something other than itself. The count is a lower bound: a build that quotes attributes differently drives it to zero and it stops constraining, which is why it supplements the shape-independent assertions rather than replacing them. Verified by reintroducing the truncation and watching this fail. (cherry picked from commit 9232cbd1fa7ef0a19e053474acf7c5468af43e74) --- internal/controller/template_controller_test.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/controller/template_controller_test.go b/internal/controller/template_controller_test.go index 6b4b4b79..74c0db0a 100644 --- a/internal/controller/template_controller_test.go +++ b/internal/controller/template_controller_test.go @@ -20,6 +20,7 @@ package controller import ( + "strings" "testing" "github.com/apache/answer/ui" @@ -39,7 +40,8 @@ import ( func TestGetStyleResolvesBuiltAssets(t *testing.T) { const builtIndexPath = "build/index.html" - if _, err := ui.Build.ReadFile(builtIndexPath); err != nil { + raw, err := ui.Build.ReadFile(builtIndexPath) + if err != nil { t.Skipf("no frontend build embedded at %s; build the frontend and re-run: %v", builtIndexPath, err) } @@ -57,4 +59,20 @@ func TestGetStyleResolvesBuiltAssets(t *testing.T) { require.NotEmpty(t, href, "stylesheet href %d parsed out of %s is empty; server-rendered pages would load unstyled", i, builtIndexPath) } + + // Finding every stylesheet matters as much as finding one. The build emits + // more than a single entry stylesheet, and a parser that stopped at the + // first one would still satisfy every assertion above while half the page's + // CSS silently stopped loading. That regression has happened once already. + // + // Count them again by a deliberately different and cruder method than the + // parser uses, so the two have to agree. It is a lower bound: a build that + // quotes attributes differently drives this to zero and the comparison + // simply stops constraining, which is why it supplements the assertions + // above rather than replacing them. + declared := strings.Count(string(raw), `rel="stylesheet"`) + require.GreaterOrEqual(t, len(css), declared, + "%s declares at least %d stylesheets but only %d were parsed out of it; "+ + "server-rendered pages would load missing part of their CSS", + builtIndexPath, declared, len(css)) }
