Files
magpie/internal/gui/core_budget_test.go
T
yetone 0cad76cd99 gui: the provider editor folds rarely used fields under Advanced
The owner: "Provider表单太复杂了…有一些可以折叠在高级里面". Headers,
proxy, concurrency and RPM limits, prices, context and output windows,
native compaction and fallback now sit in an "Advanced" fold beside the
key and models. It opens on its own when any of them is set, keeps the
state it was left in across the editor's redraws (keyed by the provider
being edited), and a Save refused on a field inside it opens it and
focuses that field. A signed-in account's editor folds the same.
Strings in zh, zh-TW, ja and de.

Motion ("整个弹窗高度的改变也应该是丝滑的动画"): the fold grows and
shrinks on one spring-like curve, its rows fading in, its arrow turning,
and the dialog's height follows on the same curve both ways; clicked
again mid-way it turns back from where it is. Reduce motion: at once.

Every dialog holds its place: the element last pressed or focused stays
where it was while the dialog grows or shrinks (a relative top plus a
max-height cap), so the button under the pointer doesn't run away. Where
there is no room above, only a pressed button below the fields shortens
them through the cap; nothing a click does scrolls the fields
(models-fold, names-fold). An element mid-scale (a Copy button's pop) is
measured by its parent (key-copy). The names list holds its height while
drawNames rebuilds it, so WebKit doesn't clamp the editor's scroll mid
rebuild (provider-detect, "Ask on one API moved" 64→190).

Tests: provider-advanced-fold (new, 5 languages × 2 engines, 420px);
about 21 editor tests open Advanced before reaching a folded field;
balance-method and plugin-move find the fold by its class; detect-draft
allows 0.5px. appScriptBudget 1,250,000 and coreScriptBudget 1,426,000
(1,232,466 and 1,405,937 with this).

Run: go test ./internal/gui/ ok. Every GUI file (771) in a full run,
4 at a time; its reds, rerun alone at this head, both engines:
key-copy 8/0, models-fold 4/0, names-fold 8/0, balance-method 42/0,
provider-detect 4/0, plus provider-remove 16/0, plugin-move 8/0,
provider-detect-draft 20/0, provider-advanced-fold 50/0,
provider-add-models 4/0. Red on origin/main as well, filed: #2435
(agent-connect-no-models, fixed in cf21b71ff), #2439 (fonts), #2443
(key-balance-card), #2228 (quota-count-wrap, quota-name-translated),
#1905 (routing-wb-restricted), #2448 (s3-sync); mobile-web and
library-workbuddy-trust red only under load, noted on #1544;
readable-focus and text-size fixed on main in 1a16fc0b5 and d3ca90afc.
2026-10-16 04:08:02 +08:00

53 lines
1.9 KiB
Go

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_426_000 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold
)
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)
}
}