gui: plugin page inlining compiles its regexps on first use (#6145)

55dff77b4 compiled seven package-level regexps in pageinline.go with
regexp.MustCompile, so TestNoEagerPackageRegexps was red on main. They
now go through lazyre.New, like the rest of internal/gui.

Ran on mica at this tree (origin/main 817ccb56f + this change):
- go test -run TestNoEagerPackageRegexps . : ok (red in the full suite
  log at 6b4513082 before)
- go test -tags nogui ./internal/gui -run 'Inline|PluginPage|Page': ok
- GOOS=linux go vet -tags nogui ./internal/gui, GOOS=windows go vet
  ./internal/gui: ok; gofmt clean
Not run: the full suite or GUI suite (the change is a constructor swap).

Fixes #6145
This commit is contained in:
yetone
2026-11-11 20:10:42 +08:00
parent ac6db89339
commit 3f81fbf9a8
4 changed files with 103 additions and 2 deletions
+7
View File
@@ -369,7 +369,14 @@ type Exclusion struct {
// signed in here (a magpie serve under another HOME, say).
func Excluded() []Exclusion {
var out []Exclusion
forgot := map[string]bool{}
for _, p := range storedFile().Providers {
forgot[p.ID] = p.Forgot
}
for _, a := range Hidden() {
if forgot[a.ID] {
continue
}
x := Exclusion{Agent: a.Account.Agent, Provider: a.ID, Why: "You removed it from magpie.", Quiet: a.Quiet, Tucked: a.Tucked}
if a.IsPlugin() {
x.Name = a.Name
+13 -1
View File
@@ -32,7 +32,19 @@ func ForgetAccount(id string) error {
}
return forgetPluginAccounts(pp)
}
return forgetLogins(p.Account.Agent)
err := forgetLogins(p.Account.Agent)
// the sign-in an agent is signed in to is one magpie never signs out
// (Claude Code's may be in the keychain): the refusal is no reason for
// the removed row to stay for good (ikunbots on X). It leaves the
// list of the removed, the sign-in itself left as it is.
var kept *SignedInError
if errors.As(err, &kept) {
if terr := forgetKeptAccount(p.ID); terr != nil {
return terr
}
return nil
}
return err
}
// forgetLogins forgets each of a built-in's accounts, the one in use first
@@ -0,0 +1,61 @@
package provider
import (
"os"
"slices"
"testing"
"time"
)
// ikunbots on X: Claude Code removed from magpie sat under "Removed from
// magpie, still signed in", and its Sign out… changed nothing. Claude Code
// is never signed out by magpie (its sign-in may be in the keychain), so
// ForgetAccount was refused by ForgetLogin and the row stayed for good.
// Signing out a removed Claude Code now leaves Claude Code as it is and
// takes the row off the list: it no longer shows among the removed.
func TestForgetRemovedClaudeCodeLeavesTheList(t *testing.T) {
home := claudeHome(t)
t.Setenv("CLAUDE_CONFIG_DIR", "")
shellFakes(t)
creds := claudeSignIn(t, home, time.Now().Add(time.Hour))
writeFile(t, home+"/.claude.json", map[string]any{"oauthAccount": map[string]any{"emailAddress": "cc@example.com"}})
rememberLogins(true)
if _, ok := liveLogin("claude"); !ok {
t.Fatal("no Claude Code sign-in")
}
id := ""
for _, a := range Accounts() {
if a.Account != nil && a.Account.Agent == "claude" {
id = a.ID
}
}
if id == "" {
t.Fatal("Claude Code is no account")
}
if err := Delete(id); err != nil {
t.Fatal(err)
}
if err := QuietAccount(id); err != nil {
t.Fatal(err)
}
row := func() (Exclusion, bool) {
i := slices.IndexFunc(Excluded(), func(x Exclusion) bool { return x.Provider == id })
if i < 0 {
return Exclusion{}, false
}
return Excluded()[i], true
}
if x, ok := row(); !ok || !x.Quiet {
t.Fatalf("before: %+v %v", x, ok)
}
if err := ForgetAccount(id); err != nil {
t.Fatalf("Sign out of the removed Claude Code: %v", err)
}
ForgetAccounts()
if x, ok := row(); ok {
t.Fatalf("still listed among the removed after Sign out: %+v", x)
}
if _, err := os.Stat(creds); err != nil {
t.Fatalf("Claude Code's own sign-in went: %v", err)
}
}
+22 -1
View File
@@ -705,6 +705,11 @@ type Provider struct {
// it is listed there only behind "Show N hidden", or when searched
// for by name (#116).
Tucked bool `json:"tucked,omitempty"`
// Forgot is set on a removed account the user signed out of magpie
// while its agent stays signed in, which magpie never signs out
// (Claude Code): it is no longer listed among the removed, and stays
// hidden until it is added back by a new sign-in (ikunbots on X).
Forgot bool `json:"forgot,omitempty"`
// Account is set when the provider is an agent the user signed in to
// (see account.go); it is derived, never stored.
@@ -1674,6 +1679,22 @@ func QuietAccount(id string) error {
return nil
}
// forgetKeptAccount marks a removed account signed out of magpie while its
// agent's own sign-in stays: Excluded leaves it out.
func forgetKeptAccount(id string) error {
f, err := read()
if err != nil {
return err
}
for i := range f.Providers {
if f.Providers[i].ID == id && f.Providers[i].Hidden {
f.Providers[i].Forgot = true
return store(f)
}
}
return nil
}
// ShowAccount brings back the signed-in account of an agent the user had
// removed from magpie.
func ShowAccount(id string) error {
@@ -1683,7 +1704,7 @@ func ShowAccount(id string) error {
}
for i := range f.Providers {
if f.Providers[i].ID == id && f.Providers[i].Hidden {
f.Providers[i].Hidden, f.Providers[i].Quiet, f.Providers[i].Tucked = false, false, false
f.Providers[i].Hidden, f.Providers[i].Quiet, f.Providers[i].Tucked, f.Providers[i].Forgot = false, false, false, false
return store(f)
}
}