From 022ffd09ecf9deb68e236f5c8773bc7c8126cc26 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 16 Nov 2026 02:39:59 +0800 Subject: [PATCH] provider: Qianfan's cURL cookie patterns compile when first used (TestNoEagerPackageRegexps) 8f3f7a46a added two package-level regexp.MustCompile in qianfan_plan.go, so the root package's TestNoEagerPackageRegexps went red on ubuntu CI (run 43743744465): "a package-level regexp is compiled at launch; use lazyre.New". Its run record named internal/provider, internal/gui and internal/cli, not the root package, where the guard lives. Both are lazyre.New now, as every other package-level pattern is. Run on mote at this tree (origin/main 52e83f7b5 + this): - go test -count=1 -run TestNoEagerPackageRegexps .: ok (red at 8f3f7a46a on CI, the two lines above) - go test -count=1 -run Qianfan ./internal/provider ./internal/gui: ok - gofmt -l: clean Not run: the whole suite; the change is the regexps' type only. --- internal/provider/qianfan_plan.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/provider/qianfan_plan.go b/internal/provider/qianfan_plan.go index ec98748ef..053578e41 100644 --- a/internal/provider/qianfan_plan.go +++ b/internal/provider/qianfan_plan.go @@ -43,7 +43,6 @@ import ( "net/http" "os" "path/filepath" - "regexp" "slices" "strings" "sync" @@ -51,6 +50,7 @@ import ( "github.com/yetone/magpie/internal/filememo" "github.com/yetone/magpie/internal/lastgood" + "github.com/yetone/magpie/internal/lazyre" ) // qianfanConsole is Baidu Cloud's console, a var for tests. @@ -191,8 +191,8 @@ func renameQianfan(from, to string) error { var ( // a copied cURL command's cookies: -b '…' or -H 'Cookie: …' - qianfanCurlB = regexp.MustCompile(`(?:^|\s)(?:-b|--cookie)\s+(?:'([^']*)'|"([^"]*)"|\$'([^']*)')`) - qianfanCurlHeader = regexp.MustCompile(`(?i)(?:-H|--header)\s+(?:'cookie:\s*([^']*)'|"cookie:\s*([^"]*)"|\$'cookie:\s*([^']*)')`) + qianfanCurlB = lazyre.New(`(?:^|\s)(?:-b|--cookie)\s+(?:'([^']*)'|"([^"]*)"|\$'([^']*)')`) + qianfanCurlHeader = lazyre.New(`(?i)(?:-H|--header)\s+(?:'cookie:\s*([^']*)'|"cookie:\s*([^"]*)"|\$'cookie:\s*([^']*)')`) ) // qianfanCookie is the Cookie header in what the user pasted: what the @@ -208,7 +208,7 @@ func qianfanCookie(text string) (string, error) { text = in.Cookie } else if strings.HasPrefix(text, "curl ") { var found string - for _, re := range []*regexp.Regexp{qianfanCurlHeader, qianfanCurlB} { + for _, re := range []*lazyre.RE{qianfanCurlHeader, qianfanCurlB} { if m := re.FindStringSubmatch(text); m != nil { found = m[1] + m[2] + m[3] break