diff --git a/internal/plugins/webui/kernel_buttons_render_test.go b/internal/plugins/webui/kernel_buttons_render_test.go index 9529bbb4..0daebabc 100644 --- a/internal/plugins/webui/kernel_buttons_render_test.go +++ b/internal/plugins/webui/kernel_buttons_render_test.go @@ -48,7 +48,11 @@ func TestKernelButtonsRenderedInPage(t *testing.T) { // 判定它处于顶层。jsdom 里的行为测试做不到这点(node 不强求), // 而浏览器里 onclick 走的是全局查找。 func TestKernelFunctionsAreGlobal(t *testing.T) { - src := string(mustReadEmbedded(t, "dashboard.js")) + js, err := FrontendAsset("dashboard.js") + if err != nil { + t.Fatalf("读 dashboard.js: %v", err) + } + src := string(js) for _, fn := range []string{"kernelRestart", "kernelShutdown", "doKernelControl", "waitForKernelBack"} { // 顶层定义:行首(可有 async 前缀),不带缩进 diff --git a/internal/plugins/webui/dashboard_js_scope_test.go b/internal/plugins/webui/test/dashboard_js_scope_test.go similarity index 91% rename from internal/plugins/webui/dashboard_js_scope_test.go rename to internal/plugins/webui/test/dashboard_js_scope_test.go index c2867f19..6f3b5ae4 100644 --- a/internal/plugins/webui/dashboard_js_scope_test.go +++ b/internal/plugins/webui/test/dashboard_js_scope_test.go @@ -1,4 +1,4 @@ -package webui +package test import ( "os" @@ -43,15 +43,7 @@ import ( // 判据做法:用 node 在沙箱里把 dashboard.js 跑一遍,抓未捕获异常。 // node 不在时 t.Skip(CI 里 GO 环境可能没有 node)。 -// dashboardJSSource 取出待测脚本文本(测试内复用以免重复读 embed)。 -func dashboardJSSource(t *testing.T) string { - t.Helper() - b, err := dashboardFS.ReadFile("dashboard.js") - if err != nil { - t.Fatalf("读 dashboard.js: %v", err) - } - return string(b) -} +// dashboardJSSource 见 helpers_test.go(迁移时去重)。 // TestDashboardJS_HasNoReferenceErrorInStrictMode 用 node 跑真脚本抓 ReferenceError。 // @@ -350,63 +342,4 @@ func TestDashboardJS_NoWriteOnlyGlobals(t *testing.T) { } } -func stripJSComments(s string) string { - var b strings.Builder - b.Grow(len(s)) - inLine, inBlock := false, false - var inStr byte - for i := 0; i < len(s); i++ { - c := s[i] - if inLine { - if c == '\n' { - inLine = false - b.WriteByte(c) - } - continue - } - if inBlock { - if c == '*' && i+1 < len(s) && s[i+1] == '/' { - inBlock = false - i++ - } - continue - } - if c == '\n' { - b.WriteByte(c) - continue - } - if inStr != 0 { - b.WriteByte(c) - if c == '\\' { - if i+1 < len(s) { - b.WriteByte(s[i+1]) - i++ - } - continue - } - if c == inStr { - inStr = 0 - } - continue - } - if c == '"' || c == '\'' || c == '`' { - // 反引号也是字符串定界符,但它可跨行 —— 本判据只统计标识符, - // 跨行模板串里出现标识符属正常,此处按普通字符串处理即可。 - inStr = c - b.WriteByte(c) - continue - } - if c == '/' && i+1 < len(s) && s[i+1] == '/' { - inLine = true - i++ - continue - } - if c == '/' && i+1 < len(s) && s[i+1] == '*' { - inBlock = true - i++ - continue - } - b.WriteByte(c) - } - return b.String() -} +// stripJSComments 见 helpers_test.go(迁移时去重)。 diff --git a/internal/plugins/webui/embed_read_test.go b/internal/plugins/webui/test/embed_read_test.go similarity index 52% rename from internal/plugins/webui/embed_read_test.go rename to internal/plugins/webui/test/embed_read_test.go index fb994ca4..e0e203c6 100644 --- a/internal/plugins/webui/embed_read_test.go +++ b/internal/plugins/webui/test/embed_read_test.go @@ -1,10 +1,13 @@ -package webui +package test -import "testing" +import ( + "github.com/JianFeeeee/HologramAgent/internal/plugins/webui" + "testing" +) func mustReadEmbedded(t *testing.T, name string) []byte { t.Helper() - b, err := dashboardFS.ReadFile(name) + b, err := webui.FrontendAsset(name) if err != nil { t.Fatalf("读 embed %s: %v", name, err) } diff --git a/internal/plugins/webui/test/helpers_test.go b/internal/plugins/webui/test/helpers_test.go index 4d9dca16..55e27761 100644 --- a/internal/plugins/webui/test/helpers_test.go +++ b/internal/plugins/webui/test/helpers_test.go @@ -6,10 +6,9 @@ package test // 而在"测试与源码分离"之后,它们不能再从包内符号借用。 import ( + "github.com/JianFeeeee/HologramAgent/internal/plugins/webui" "strings" "testing" - - "github.com/JianFeeeee/HologramAgent/internal/plugins/webui" ) // stripJSComments 剥掉 // 行注释与 /* */ 块注释(粗粒度,但足够用于词频统计)。 diff --git a/internal/plugins/webui/mascot_asset_test.go b/internal/plugins/webui/test/mascot_asset_test.go similarity index 97% rename from internal/plugins/webui/mascot_asset_test.go rename to internal/plugins/webui/test/mascot_asset_test.go index acfbec15..b152b470 100644 --- a/internal/plugins/webui/mascot_asset_test.go +++ b/internal/plugins/webui/test/mascot_asset_test.go @@ -1,9 +1,10 @@ -package webui +package test import ( "bytes" "encoding/binary" "errors" + "github.com/JianFeeeee/HologramAgent/internal/plugins/webui" "testing" ) @@ -21,7 +22,7 @@ import ( // 都在看。所以用容器格式本身来判定:判据看的是 VP8X 的 Alpha 标志位与 // ALPH chunk 是否**一致存在**,而不是「渲染出来像不像透明」。 func TestMascotAssetHasRealAlpha(t *testing.T) { - data, err := dashboardFS.ReadFile("mascot.webp") + data, err := webui.FrontendAsset("mascot.webp") if err != nil { t.Fatalf("读 mascot.webp: %v", err) }