From 108852b4e1f1e2b1ae11cbc0828f91c21f5ca699 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 7 Oct 2026 02:17:12 +0800 Subject: [PATCH] =?UTF-8?q?provider=20tests:=20the=20CLI=20sign-in=20tests?= =?UTF-8?q?=20run=20their=20fake=20login=20as=20/bin/sh=20-c,=20not=20a=20?= =?UTF-8?q?script=20written=20for=20the=20test,=20so=20macOS's=20first-run?= =?UTF-8?q?=20check=20of=20a=20new=20executable=20no=20longer=20eats=20lin?= =?UTF-8?q?kWait=20(TestCursorSignInJoinsAWrappedLink=20failed=20once=20in?= =?UTF-8?q?=20a=20full=20go=20test=20./...=20with=20"login=20gave=20no=20l?= =?UTF-8?q?ink=20to=20open")=20=E2=80=94=20macOS=20assesses=20a=20newly=20?= =?UTF-8?q?written=20executable=20before=20its=20first=20exec:=20~0.3s=20a?= =?UTF-8?q?lone=20(a=20fresh=20`#!/bin/sh`=20script=20runs=20in=200.25?= =?UTF-8?q?=E2=80=930.35s,=20the=20same=20file=20again=20in=200.00s),=20an?= =?UTF-8?q?d=20seconds=20while=20other=20new=20executables=20start,=20as?= =?UTF-8?q?=20a=20go=20test=20./...=20starts=20its=20test=20binaries.=20ru?= =?UTF-8?q?nCLISignIn's=20linkWait=20counts=20from=20Start,=20so=20the=20"?= =?UTF-8?q?never=20whole,=20and=20nothing=20more"=20case,=20which=20sets?= =?UTF-8?q?=20linkWait=20to=203s,=20got=20no=20line=20at=20all=20before=20?= =?UTF-8?q?the=20wait=20was=20over.=20Before:=20with=20a=20loop=20starting?= =?UTF-8?q?=208=20fresh=20scripts=20at=20a=20time=20beside=20it,=20the=20t?= =?UTF-8?q?est=20failed=202=20of=203=20at=20cursor=5Fsignin=5Ftest.go:70?= =?UTF-8?q?=20with=20"login=20gave=20no=20link=20to=20open",=2039s=20a=20r?= =?UTF-8?q?un.=20After,=20under=20the=20same=20load:=205=20of=205=20pass,?= =?UTF-8?q?=203.9s=20a=20run;=20-race=20-count=3D50=20-cpu=201,2,4=20of=20?= =?UTF-8?q?TestCursorSignIn|TestCLISignIn=20pass;=20-shuffle=3Don=20-count?= =?UTF-8?q?=3D5=20of=20the=20package=20beside=20go=20test=20./internal/gat?= =?UTF-8?q?eway=20and=20that=20loop=20never=20fails=20them.=20TestCLISignI?= =?UTF-8?q?nSaysWhyNoLink=20starts=20its=20fake=20the=20same=20way.=20No?= =?UTF-8?q?=20fake=20outlives=20its=20test:=20stop()=20kills=20the=20shell?= =?UTF-8?q?,=20which=20has=20exec'd=20its=20sleep.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/provider/cursor_signin_test.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/internal/provider/cursor_signin_test.go b/internal/provider/cursor_signin_test.go index aacdb96e..06ddb4b3 100644 --- a/internal/provider/cursor_signin_test.go +++ b/internal/provider/cursor_signin_test.go @@ -1,8 +1,6 @@ package provider import ( - "os" - "path/filepath" "runtime" "strings" "testing" @@ -13,16 +11,15 @@ import ( const cursorLink = "https://cursor.com/loginDeepControl?challenge=Zm9vYmFyYmF6cXV4Zm9vYmFyYmF6cXV4Zm9vYmFyYmF&uuid=0b9d5f3e-6f1c-4c2a-9a55-3d1f0e6b7a21&mode=login&redirectTarget=cli&supportsSelectedTeamLogin=true" // signInLink runs a fake login command printing script and says the link -// the sign-in hands to the window. +// the sign-in hands to the window. It is /bin/sh -c, not a script written +// for the test: macOS checks a new executable before its first run, which +// takes ~0.3s alone and seconds while a `go test ./...` starts its other +// new test binaries, all of it counted against linkWait. func signInLink(t *testing.T, whole func(string) bool, script string) string { t.Helper() - exe := filepath.Join(t.TempDir(), "login") - if err := os.WriteFile(exe, []byte("#!/bin/sh\n"+script+"\nexec sleep 5\n"), 0o755); err != nil { - t.Fatal(err) - } s := &signInFlow{done: make(chan struct{})} s.st = SignInState{State: "waiting"} - err := runCLISignIn(s, "login", nil, true, nil, func() (string, string, bool) { return "", "", false }, whole, exe) + err := runCLISignIn(s, "login", nil, true, nil, func() (string, string, bool) { return "", "", false }, whole, "/bin/sh", "-c", script+"\nexec sleep 5") s.mu.Lock() stop, u := s.stop, s.st.URL s.mu.Unlock() @@ -91,13 +88,9 @@ func TestCLISignInSaysWhyNoLink(t *testing.T) { t.Skip("fake CLI is a shell script") } said := "Error: error sending request for url (https://auth.x.ai/oauth2/device/code): client error (Connect): tunnel error: failed to create underlying connection: tcp connect error: Connection refused (os error 61)" - exe := filepath.Join(t.TempDir(), "login") - if err := os.WriteFile(exe, []byte("#!/bin/sh\necho '"+said+"' >&2\nexit 1\n"), 0o755); err != nil { - t.Fatal(err) - } s := &signInFlow{done: make(chan struct{})} s.st = SignInState{State: "waiting"} - err := runCLISignIn(s, "grok login", nil, true, nil, func() (string, string, bool) { return "", "", false }, nil, exe) + err := runCLISignIn(s, "grok login", nil, true, nil, func() (string, string, bool) { return "", "", false }, nil, "/bin/sh", "-c", "echo '"+said+"' >&2; exit 1") if err == nil || err.Error() != "grok login gave no link to open: "+said { s.mu.Lock() t.Fatalf("err %v, link %q", err, s.st.URL)