From a68f114d9e29db03c2a015dab8dbd8e5a24c6a4c Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 05:30:02 +0800 Subject: [PATCH] lazyre: the plugin name and export file name regexps compile on first use (#6020) 6af54dc9a (internal/library/plugin.go, pluginName) and b9f8548d2 (internal/provider/login_export.go, exportUnsafe) each added a package-level regexp.MustCompile, so TestNoEagerPackageRegexps was red on main on ubuntu and macOS CI (run 42893454569 at 51da6f1f5). Both go through lazyre.New now, like the rest since e4197144a. The patterns and callers are unchanged. yinwu01 found it and had the same patch on a fork branch. Run on mote at this tree (on origin/main d2a80b317): - go vet -tags nogui of internal/library, internal/provider and the root package: ok; gofmt -l clean; - TestNoEagerPackageRegexps: ok (red on main in CI's run above); - internal/cli TestEveryRouteHasACommandOrIsNamed: ok at this head (red in the same CI run, already fixed by 91d4eaa70 and 966ddff20); - go test -tags nogui ./internal/library ./internal/provider: ok. Not run: the full suite, and Windows and Linux vet (a two-line change of how a variable is declared, with no OS-specific files). Co-authored-by: yinwu01 --- internal/library/plugin.go | 4 +++- internal/provider/login_export.go | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/library/plugin.go b/internal/library/plugin.go index bdd06f92a..f01ca1074 100644 --- a/internal/library/plugin.go +++ b/internal/library/plugin.go @@ -14,6 +14,8 @@ import ( "time" "gopkg.in/yaml.v3" + + "github.com/yetone/magpie/internal/lazyre" ) // A bundle is a Claude Code plugin kept in the library as one item @@ -157,7 +159,7 @@ func inside(dir, p string) (string, bool) { return p, true } -var pluginName = regexp.MustCompile(`[^A-Za-z0-9_-]+`) +var pluginName = lazyre.New(`[^A-Za-z0-9_-]+`) func pluginSlug(s string) string { s = strings.Trim(pluginName.ReplaceAllString(strings.TrimSpace(s), "-"), "-_") diff --git a/internal/provider/login_export.go b/internal/provider/login_export.go index 7edaef8df..211cf0aa1 100644 --- a/internal/provider/login_export.go +++ b/internal/provider/login_export.go @@ -20,10 +20,11 @@ import ( "fmt" "os" "path/filepath" - "regexp" "slices" "strings" "time" + + "github.com/yetone/magpie/internal/lazyre" ) // Export formats. @@ -155,7 +156,7 @@ func ExportLogins(agent, format string, users []string) (ExportResult, error) { return res, nil } -var exportUnsafe = regexp.MustCompile(`[^A-Za-z0-9@._+-]+`) +var exportUnsafe = lazyre.New(`[^A-Za-z0-9@._+-]+`) // exportName is CLIProxyAPI's name for an auth file: -.json, // a ChatGPT one's plan after the email.