From 91b9065a5fdf5b7aa0adeeeb17266c121bf5691c Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 14 Oct 2026 18:21:47 +0800 Subject: [PATCH] gui: the window's core scripts have a size budget, so a page can't grow back into it (P2) TestCoreScriptBudget adds up the scripts index.html loads that aren't a plugin's (assets/plugins//) or the words (i18n.js): app.js may weigh 1,215,000 bytes (1,198,239 now Sessions, Library, Routing and Usage are plugins) and the core 1,377,000 (1,358,034), about 1.4% room. A change that needs more raises them and says why in its commit. boot.js, made by the server, isn't on disk and isn't counted. Run: go test -run TestCoreScriptBudget ./internal/gui ok. Broken by hand: with the app.js budget at 1,190,000 it fails naming app.js's bytes, and with plugins/usage/page.js counted as core it fails on the total (about 1.5 MB). --- internal/gui/core_budget_test.go | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 internal/gui/core_budget_test.go diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go new file mode 100644 index 000000000..8956bf63a --- /dev/null +++ b/internal/gui/core_budget_test.go @@ -0,0 +1,52 @@ +package gui + +import ( + "os" + "path/filepath" + "regexp" + "strings" + "testing" +) + +// What the window's core may weigh, in bytes of script: everything +// index.html loads that isn't a plugin's (assets/plugins//) and isn't +// the words (i18n.js). A page belongs in a plugin. Each page moved out +// lowers these to what is left, with about 1.5% room for the core's own work, +// so a page can't quietly grow back into the core; a change that needs more +// raises them and says why in its commit. +const ( + appScriptBudget = 1_215_000 // app.js: 1,198,239 after Usage left (P2) + coreScriptBudget = 1_377_000 // every core script: 1,358,034 after Usage left +) + +func TestCoreScriptBudget(t *testing.T) { + page, err := os.ReadFile("assets/index.html") + if err != nil { + t.Fatal(err) + } + total, n := 0, 0 + for _, m := range regexp.MustCompile(`