Commit Graph
2 Commits
Author SHA1 Message Date
yetone a36319d607 tests: TestProviderListReadsSettingsOnce counts settings.json's parses, not a 2s bar a loaded runner exceeds (#2185)
The guarantee is that a provider's model list parses settings.json once,
not once to three times per model. The test timed one providerInfo call
against 2s, and on a Mac at load 270-360 it took 6.4s with the settings
read once. It now counts settings.Parses() around the call: 6 parses for
300 models, failing at 50, while reading per model gives 300 to 900. The
settings file no longer needs 20000 entries to make a read slow; 200 are
kept so the user's own answers still sit among others'.

Broken by hand, both fail with a real FAIL:
- ImageOverrideIn given a fresh settings.Load() per model: "300 models
  parsed settings.json 306 times".
- providerInfo put back to before 9db5753ba (ApplyImage, ImageOverride,
  ReplyLimit per model): "parsed settings.json 906 times".
Restored: passes, -count=3 under load ~290 (1.98s, 0.31s, 0.27s).

Run: gofmt -l, go vet ./internal/gui for darwin, GOOS=linux -tags nogui
and GOOS=windows; go test -tags nogui -timeout 40m ./... under a sandbox HOME at load
~240-300: internal/gui ok (835s) and every other package ok but three.
internal/agent and internal/gateway hit the 40m package timeout with a
test that had run 1m39s and 52s, not a hang; rerun with -timeout 90m
both pass (1273s, 1286s). internal/provider's
TestCopilotSecretToolUsername failed on its 5s secret-tool bound, which
is #1627 (open). Not run: Windows box (test-only change, no OS path).
2026-10-14 23:06:35 +08:00
yetone 9db5753ba3 providers: a provider's model list reads the settings once, not three times per model (lml on Discord, Windows: 每次至少都得等五六秒…供应商或者额度列表还在加载) — each model's row asked for its image answer twice (ApplyImage, ImageOverride) and its reply limit once (ReplyLimit), and each ask parsed settings.json again, even inside a GET's hold, since filememo keeps its bytes, not the parse. providerInfo now reads the settings once and uses provider.ImageOverrideIn and Provider.ReplyLimitIn. This removes redundant work found while measuring lml's report; it does not explain the whole 5-6s, which needs their setup (see below).
Measured with a copy of the owner's config (23 providers, ~1500 models) under a sandbox HOME and the real server (magpie web, dead proxy): GET /api/providers on the Windows box 497-558ms → 148-214ms, on the Mac 442-525ms → 174-191ms; the JSON answer is byte-for-byte the same apart from the gateway port. Everything else the window waits on at open answered locally in under 0.6s on Windows, so the rest of a 5-6s wait is network (the usage cards wait for every vendor on a cold start, and on Usage's own open), not this.

TestProviderListReadsSettingsOnce (300 models, a big settings file, held as a GET is) takes 5.3s without the change and 41ms with it, and checks an image answer and a reply limit the user set are still said. go vet, GOOS=windows go build, GOOS=linux go build -tags nogui and go test -tags nogui ./... under a temp HOME pass.
2026-10-07 01:58:10 +08:00