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 d787464a637c840b88828bfdc9550040da094a18
Author: Xan Torres <[email protected]>
AuthorDate: Wed Aug 19 11:58:07 2026 +0800

    test: guard frontend behaviour a successful build does not demonstrate
    
    Two things the server depends on are invisible to the build. Both fail
    silently, so a green build and a working dev server actively disguise them.
    
    The server parses the script and stylesheet paths out of the built
    index.html and reuses them on every server-rendered page. That parse is
    coupled to the exact attribute set and attribute order the frontend build
    writes into those tags. A build that emits a different tag shape still
    succeeds, the dev server still works, the binary still compiles, and the
    pages simply render with no scripts and no stylesheet.
    TestGetStyleResolvesBuiltAssets asserts the parse still finds them.
    
    Languages other than the default one are loaded with a template-literal
    dynamic import through an alias that points outside the frontend root. A
    bundler that cannot enumerate that pattern still builds and still serves a
    working app; the resources never arrive, and only for non-default
    languages, so a smoke test in the default language misses it.
    check-locale-resolution.js bundles that same import with the project's own
    configuration, runs it, and requires two languages to resolve to distinct
    translated content.
    
    Both run through make check-ui. check-built-assets.sh --self-check
    confirms the asset check still fails on tag shapes the parser cannot read,
    so a check that quietly stopped asserting anything is distinguishable from
    a passing one.
    
    (cherry picked from commit 71cd9246fedbf6430c6a7373759fdf0be4029e4a, 
internal/controller/template_controller_test.go only)
---
 internal/controller/template_controller_test.go | 56 +++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/internal/controller/template_controller_test.go 
b/internal/controller/template_controller_test.go
new file mode 100644
index 00000000..273b7df8
--- /dev/null
+++ b/internal/controller/template_controller_test.go
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package controller
+
+import (
+       "testing"
+
+       "github.com/apache/answer/ui"
+       "github.com/stretchr/testify/require"
+)
+
+// GetStyle scrapes the script and stylesheet paths out of the built
+// index.html and every server-rendered page reuses them. The scrape is
+// coupled to the exact attribute order and attribute set that the frontend
+// build tool writes into those tags, and nothing in the system reports a
+// mismatch: the frontend build still succeeds, the dev server still works,
+// the binary still compiles, and the server-rendered pages simply come back
+// with no script tags and no stylesheet.
+//
+// Assert the coupling directly so a change to the emitted tag shape fails
+// here instead of shipping.
+func TestGetStyleResolvesBuiltAssets(t *testing.T) {
+       const builtIndexPath = "build/index.html"
+
+       if _, err := ui.Build.ReadFile(builtIndexPath); err != nil {
+               t.Skipf("no frontend build embedded at %s; build the frontend 
and re-run: %v", builtIndexPath, err)
+       }
+
+       scripts, css := GetStyle()
+
+       require.NotEmpty(t, scripts,
+               "no script sources parsed out of %s; server-rendered pages 
would load without any JavaScript", builtIndexPath)
+       for i, src := range scripts {
+               require.NotEmpty(t, src, "script source %d parsed out of %s is 
empty", i, builtIndexPath)
+       }
+
+       require.NotEmpty(t, css,
+               "no stylesheet href parsed out of %s; server-rendered pages 
would load unstyled", builtIndexPath)
+}

Reply via email to