With Hide accounts (账号打码) on, the name a user gave an account (#1515) was blurred like the account, so faketrader's several Antigravity accounts couldn't be told apart; and an Antigravity account whose value is "Google" blurred "Google" of its plan "Google AI Pro" on Usage and on the Providers row. The name the user gave an account is shown text, not an identity. The account is. - provider: a card's Alias says whether it is the user's own name (SubscriptionQuota.Named, set by withAccountNames from AccountNameOf), since Alias is also a plugin's name for an account (PluginUserOf, a masked phone, #4416) or a seat's key plan, and the Usage page and tray panel may have no /api/providers to tell them apart. labelProvider is AccountLabelOf's "plugin:" lookup, shared. - app.js names(): the user's own names (accountNames) and named aliases are no longer accounts to hide; accountUsers, an unnamed alias and a seat still are (noteAccounts keeps an alias without named). - app.js mask(): labels are scoped by element, never by value (LESSONS: scope an exemption by where the value sits). In .own-name, .plan, .acct-plan (the Providers row's plan pill, new class), .model-value and .subscription-head > b only an address is hidden; a plan's and a model's tooltip too (TIPS). The own name's tooltip ("name · account") is masked in full. - .own-name is set only where the text is the user's own: the editor's rename span when it has one (else it shows the raw account and stays hidden), Usage's quota-alias and the panel's pq-user when q.named. From skygunner's patch (95c0511 on19253f67), changed: - Its .acct-who .rename exemption showed a raw non-email account (the rename span shows the account when it has no name of the user's). Now only an own-name span is exempt. - Its [title]:not(LABELS) skipped those elements' tooltips altogether, so the address in "alias · user" (quota-alias, rename) went unmasked. Tooltips are masked; only a plan's or model's hides just an address. - Dropping every alias from names() would have shown a plugin's name for an account (#4416 came after the patch's base). Named tells the user's own apart. - The n.data.length < 2 skip the patch removed is kept. - Its test is rewritten on the new fixtures: an unnamed plugin alias, an address in a plan, the editor with and without an own name, the panel, a model value, tooltips. account-alias.test.cjs and account-eye.test.cjs said Hide accounts hides the user's own name; they now say it stays in sight, the accounts still hidden. account-alias brings the window's page to the front before clicking #usageMask, and the panel's before waiting on it: behind the panel's page it gets no frames and the click waited for one, red 5 times in 2 runs atfb3942ee6(#2984's account-alias half), 0 in 100 after. Not changed: the tray panel card's tooltip is one string of account and plan, so a plan word that equals an account's value is still hidden there (#4677). OpenCode Zen's "Signed in as <account>" in the issue's screenshot is the raw account, hidden as before. Core scripts: app.js's own comments in the masking module are cut, so the core is 742 bytes under its budget at the pushed head (no raise). What was run: - At this on4c815ac2a, on mote (then rebased onto39bade71d, whose 8 commits change only i18n.js and plugins/gateway/settings.js; the budget measured again, 742 under): gofmt -l; go vet of provider, gui, usageapi; go test -tags nogui ./internal/provider ./internal/usageapi ok; TestCoreScriptBudget ok; the 19 masking GUI files (account-*, mask-*, masking-records, privacy-*, provider-mask, provider-unmasked, routing-masking, window-mask, click-scroll, i18n-keys), both engines: 539/540. The red was account-alias's panel wait behind the window's page, fixed by the panel bringToFront above. account-alias + account-mask-alias-plan after it: 4 runs, 159/160 (one red in "renamed in place", whose body this change doesn't touch, #4749). account-alias 6 more runs: 120/120 here, 117/120 on origin/main90c02326b(#2984). - account-mask-alias-plan: 20/20 on the fix (Chromium, WebKit; en, zh, zh-TW, ja, de; 1100 and 420), 20/20 red atfb3942ee6(the alias is masked); red with the plan selectors taken out of LABELS by hand. account_plugin_user_test red with Named always false by hand. - At 4eeba1ca6 (this on90c02326b): go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build for darwin, linux (nogui) and windows: ok. go test -tags nogui ./... on the Linux box: every package ok except internal/agent (8 install tests red the same on origin/main there, #4033, #3548) and internal/gui (TestSettingsSaveKeepsWhatItDoesNotSend, red on main, #4514; TestColdTurnsTaken on mote once, #4510). The whole GUI suite on the Linux box, 6 wide: 16857 pass, 491 fail in 100 files, none of them the masking files but account-every-reset; being run against origin/main to sort. Co-authored-by: skygunner <84759+skygunner@users.noreply.github.com> Co-authored-by: vincent <vincent@users.noreply.github.com> Co-authored-by: Fake Trader <9635792+faketrader@users.noreply.github.com>
121 lines
4.0 KiB
Go
121 lines
4.0 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/plugin"
|
|
"github.com/yetone/magpie/internal/testenv"
|
|
)
|
|
|
|
// #4416: a plugin keeps the vendor's id as accountId, the key the user's
|
|
// own name, proxy and gateway key are kept by (codearts: an IAM id), and
|
|
// tells the account's name in usage().user (a masked phone). The account
|
|
// is shown by the user's own name, else the plugin's, else its id: what
|
|
// was read last, kept across a restart and a failed read, never nothing.
|
|
func TestPluginAccountShownByItsUsageUser(t *testing.T) {
|
|
bun := testenv.Bun(t)
|
|
claudeHome(t)
|
|
t.Setenv("MAGPIE_BUN", bun)
|
|
// a month's window of no model's own, so the reading is kept on disk
|
|
// as quotas.json keeps any (a pool of some models' isn't)
|
|
ws := filepath.Join(t.TempDir(), "windows.json")
|
|
if err := os.WriteFile(ws, []byte(`{"iam::01a18be16b297c5197d8569e4be6a479:user:hw059194106570983": [{"name": "Month", "used": 10, "span": 2592000}]}`), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Setenv("FAKE_WINDOWS", ws)
|
|
t.Cleanup(plugin.Settle)
|
|
forget := func() {
|
|
loginUsageCache.Lock()
|
|
loginUsageCache.m, loginUsageCache.pending = nil, nil
|
|
loginUsageCache.Unlock()
|
|
lastQuotas.Lock()
|
|
lastQuotas.m, lastQuotas.loaded = nil, false
|
|
lastQuotas.Unlock()
|
|
}
|
|
forget()
|
|
t.Cleanup(forget)
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
abs, _ := filepath.Abs("../plugin/testdata/fake/index.js")
|
|
if _, err := plugin.Add(ctx, abs); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
const iam, phone = "iam::01a18be16b297c5197d8569e4be6a479:user:hw059194106570983", "180****2361"
|
|
k, err := plugin.Import(ctx, "fakeco", map[string]any{"type": "oauth", "refresh": "r", "access": "a", "expires": 9e15, "accountId": iam})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
saveLogins(t, savedLogin{Agent: "plugin:fakeco", User: iam, Home: k, On: true})
|
|
if _, err := plugin.Providers(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
id := PluginID("fakeco")
|
|
shown := func(want, why string) {
|
|
t.Helper()
|
|
p, err := Find(id)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := p.AccountShown(iam); got != want {
|
|
t.Fatalf("%s: the provider shows %q, not %q", why, got, want)
|
|
}
|
|
for _, of := range []string{id, "plugin:fakeco"} {
|
|
if got := AccountShownOf(of, iam); got != want {
|
|
t.Fatalf("%s: %s shows %q, not %q", why, of, got, want)
|
|
}
|
|
}
|
|
var keys []string
|
|
for _, v := range AccountNames() {
|
|
if strings.HasPrefix(v, id+"/") {
|
|
keys = append(keys, v)
|
|
}
|
|
}
|
|
if len(keys) != 1 || keys[0] != id+"/"+want {
|
|
t.Fatalf("%s: a gateway key's accounts read %q", why, keys)
|
|
}
|
|
card := withAccountNames([]SubscriptionQuota{{Provider: id, User: iam}})[0]
|
|
if want == iam {
|
|
want = ""
|
|
}
|
|
if card.Alias != want {
|
|
t.Fatalf("%s: the card's alias is %q, not %q", why, card.Alias, want)
|
|
}
|
|
// the plugin's name for the account is the account's, hidden
|
|
// with it; only a name of the user's own is Named (#3656)
|
|
if card.Named != (want == "Work") {
|
|
t.Fatalf("%s: %q read as the user's own: %v", why, card.Alias, card.Named)
|
|
}
|
|
}
|
|
shown(iam, "nothing read yet")
|
|
if got := LoginUsage(ctx, "plugin:fakeco")[iam]; got.Error != "" || got.User != phone {
|
|
t.Fatalf("the reading: %+v", got)
|
|
}
|
|
shown(phone, "read")
|
|
// a restart: what quotas.json kept
|
|
forget()
|
|
shown(phone, "after a restart")
|
|
// a read that failed holds the account's own id, not the phone
|
|
loginUsageCache.Lock()
|
|
loginUsageCache.m = map[string]loginUsageEntry{"plugin:fakeco/" + iam: {at: time.Now(), q: SubscriptionQuota{Provider: id, User: iam, Error: "fetch failed"}}}
|
|
loginUsageCache.Unlock()
|
|
shown(phone, "a failed read")
|
|
// the user's own name is never overridden
|
|
if err := SetAccountName(id, iam, "Work"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
shown("Work", "named")
|
|
if err := SetAccountName(id, iam, ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// nothing known: the id, never blank
|
|
lastQuotas.Lock()
|
|
lastQuotas.m, lastQuotas.loaded = nil, true
|
|
lastQuotas.Unlock()
|
|
shown(iam, "nothing known")
|
|
}
|