Files
magpie/internal/gui/core_budget_test.go
T
yetone 81313b9121 gui: the core script budget makes room for 10-16's core work (#2612)
TestCoreScriptBudget was red on macOS and ubuntu CI on main from
1978eabe5 (runs 38935231106 and 38939182388). The core's scripts were
1,426,102 bytes, 102 over 1,426,000. The total, counted at each commit:
9fcf6a6e7 1,424,832, then 1978eabe5's Settings › Long conversations
switch for Codex background compaction added 1,270. That switch is core
Settings, not a page that belongs in a plugin, and the GitHub list
loading (1d6f461a9) and the move to plugins (7d7dba31a, 9fcf6a6e7) that
used the rest of the room are core too. So the budget goes to
1,426,102 plus 1.5%, as the test's comment asks.

1978eabe5's body records its suite at a751f5282. That was before
1d6f461a9 and the 22:58 batch, so the budget passed there and failed
only at the pushed head.

app.js is 1,247,683 of its 1,250,000. It is not raised here. The next
core change to app.js that needs room says why in its own commit.

Run at 9228bd443 (origin/main) plus this change:
- go test -tags nogui -count=1 -run TestCoreScriptBudget ./internal/gui:
  ok. At the old 1_426_000: red with CI's message.
- go test -tags nogui -count=1 -timeout 30m ./internal/gui: ok (136s,
  load ~240).
- gofmt -l and go vet -tags nogui ./internal/gui: clean.
- Not run: the full suite. The change is one constant in a _test.go
  file that only TestCoreScriptBudget reads.
2026-10-17 01:50:12 +08:00

53 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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/<id>/) 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_250_000 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16)
coreScriptBudget = 1_447_000 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612)
)
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(`<script src="([^"?]+)`).FindAllStringSubmatch(string(page), -1) {
name := m[1]
if strings.HasPrefix(name, "plugins/") || name == "i18n.js" {
continue
}
b, err := os.ReadFile(filepath.Join("assets", name))
if os.IsNotExist(err) {
continue // made by the server as it serves the page (boot.js)
}
if err != nil {
t.Fatal(err)
}
if name == "app.js" && len(b) > appScriptBudget {
t.Errorf("app.js is %d bytes, over its budget of %d: put the page's code in its plugin, or raise the budget and say why", len(b), appScriptBudget)
}
total += len(b)
n++
}
if n < 5 {
t.Fatalf("found only %d core scripts in index.html", n)
}
if total > coreScriptBudget {
t.Errorf("the core's scripts are %d bytes, over their budget of %d: put the page's code in its plugin, or raise the budget and say why", total, coreScriptBudget)
}
}