Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(cli): distinguish auth status verification failures (#10965)
Danila Katalshov64e4e10bbec6
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.mdindex 623dbfdff3..649547fc75 100644--- a/CLI_AND_DAEMON.md+++ b/CLI_AND_DAEMON.md@@ -97,7 +97,7 @@ Authenticate using a personal access token directly. Useful for headless environmultica auth status```-Shows your current server, user, and token validity.+Shows your current server and user when the token can be verified. If verification fails, check the reported error before signing in again.### Logoutdiff --git a/apps/docs/content/docs/troubleshooting.fr.mdx b/apps/docs/content/docs/troubleshooting.fr.mdxindex b046e0ca5e..0da16dfe7d 100644--- a/apps/docs/content/docs/troubleshooting.fr.mdx+++ b/apps/docs/content/docs/troubleshooting.fr.mdx@@ -45,6 +45,8 @@ multica daemon status --output jsonmultica daemon logs --lines 100```+Si la CLI ne peut pas vérifier le jeton, examinez l’erreur signalée avant de vous reconnecter.+Causes fréquentes :- Le CLI ne s'est pas connecté, ou le jeton stocké sur cette machine a expiré.diff --git a/apps/docs/content/docs/troubleshooting.ja.mdx b/apps/docs/content/docs/troubleshooting.ja.mdxindex 4123d17d9a..be9e95bc4b 100644--- a/apps/docs/content/docs/troubleshooting.ja.mdx+++ b/apps/docs/content/docs/troubleshooting.ja.mdx@@ -45,6 +45,8 @@ multica daemon status --output jsonmultica daemon logs --lines 100```+CLI がトークンを検証できない場合は、再ログインする前に表示されたエラーを確認してください。+よくある原因:- CLI がまだログインしていない、またはローカルに保存されたトークンが失効している。diff --git a/apps/docs/content/docs/troubleshooting.ko.mdx b/apps/docs/content/docs/troubleshooting.ko.mdxindex b203c7c37f..7048c8b3ea 100644--- a/apps/docs/content/docs/troubleshooting.ko.mdx+++ b/apps/docs/content/docs/troubleshooting.ko.mdx@@ -45,6 +45,8 @@ multica daemon status --output jsonmultica daemon logs --lines 100```+CLI가 토큰을 확인할 수 없으면 다시 로그인하기 전에 표시된 오류를 확인하세요.+일반적인 원인은 다음과 같습니다.- CLI에 아직 로그인하지 않았거나 로컬에 저장된 token이 만료됨diff --git a/apps/docs/content/docs/troubleshooting.mdx b/apps/docs/content/docs/troubleshooting.mdxindex 736ab77ed6..e2b1e83b6f 100644--- a/apps/docs/content/docs/troubleshooting.mdx+++ b/apps/docs/content/docs/troubleshooting.mdx@@ -45,6 +45,8 @@ multica daemon status --output jsonmultica daemon logs --lines 100```+If the CLI cannot verify the token, check the reported error before signing in again.+Common causes include:- The CLI has not signed in, or the token stored on this machine has expired.diff --git a/apps/docs/content/docs/troubleshooting.zh-Hant.mdx b/apps/docs/content/docs/troubleshooting.zh-Hant.mdxindex c6b6ca1375..641a735c2f 100644--- a/apps/docs/content/docs/troubleshooting.zh-Hant.mdx+++ b/apps/docs/content/docs/troubleshooting.zh-Hant.mdx@@ -45,6 +45,8 @@ multica daemon status --output jsonmultica daemon logs --lines 100```+如果 CLI 無法驗證權杖,請先檢查提示中的錯誤,再決定是否重新登入。+常見原因包括:- CLI 尚未登入,或本機儲存的令牌已經失效;diff --git a/apps/docs/content/docs/troubleshooting.zh.mdx b/apps/docs/content/docs/troubleshooting.zh.mdxindex fd60060ec0..cf6cd8fda7 100644--- a/apps/docs/content/docs/troubleshooting.zh.mdx+++ b/apps/docs/content/docs/troubleshooting.zh.mdx@@ -45,6 +45,8 @@ multica daemon status --output jsonmultica daemon logs --lines 100```+如果 CLI 无法验证令牌,请先检查提示中的错误,再决定是否重新登录。+常见原因包括:- CLI 尚未登录,或本机保存的令牌已经失效;diff --git a/server/cmd/multica/cmd_auth.go b/server/cmd/multica/cmd_auth.goindex cc4da7fff0..7694f5f4c4 100644--- a/server/cmd/multica/cmd_auth.go+++ b/server/cmd/multica/cmd_auth.go@@ -5,6 +5,7 @@ import ("context""crypto/rand""encoding/hex"+ "errors""fmt""net""net/http"@@ -512,7 +513,16 @@ func runAuthStatus(cmd *cobra.Command, _ []string) error {Email string `json:"email"`}if err := client.GetJSON(ctx, "/api/me", &me); err != nil {- fmt.Fprintf(os.Stderr, "Token is invalid or expired: %v\nRun 'multica login' to re-authenticate.\n", err)+ var httpErr *cli.HTTPError+ if errors.As(err, &httpErr) && httpErr.Kind() == cli.KindAuthRequired {+ if taskContext {+ fmt.Fprintln(os.Stderr, cli.FormatError(err, debugFlag))+ } else {+ fmt.Fprintln(os.Stderr, "Token is invalid or expired. Run 'multica login' to re-authenticate.")+ }+ } else {+ fmt.Fprintf(os.Stderr, "Could not verify the token: %s\n", cli.FormatError(err, debugFlag))+ }return nil}diff --git a/server/cmd/multica/cmd_auth_test.go b/server/cmd/multica/cmd_auth_test.goindex bd1be12f72..7aa40530d8 100644--- a/server/cmd/multica/cmd_auth_test.go+++ b/server/cmd/multica/cmd_auth_test.go@@ -609,3 +609,74 @@ func TestValidateLoginTokenPrefix(t *testing.T) {}}}++func TestRunAuthStatusDistinguishesVerificationFailure(t *testing.T) {+ t.Setenv("LC_ALL", "C")+ t.Setenv("MULTICA_DEBUG", "")++ debugOption := rootCmd.PersistentFlags().Lookup("debug")+ originalDebug, originalDebugChanged := debugFlag, debugOption.Changed+ t.Cleanup(func() {+ rootCmd.SetArgs(nil)+ debugFlag, debugOption.Changed = originalDebug, originalDebugChanged+ })++ for _, tc := range []struct {+ name string+ status int+ message string+ relogin bool+ task bool+ debug bool+ }{+ {"unauthorized", http.StatusUnauthorized, "Token is invalid or expired", true, false, false},+ {"task unauthorized", http.StatusUnauthorized, "This task token was rejected", false, true, false},+ {"unavailable", http.StatusServiceUnavailable, "Could not verify the token", false, false, false},+ {"unavailable with debug", http.StatusServiceUnavailable, "Could not verify the token", false, false, true},+ {"task unauthorized with debug", http.StatusUnauthorized, "This task token was rejected", false, true, true},+ } {+ t.Run(tc.name, func(t *testing.T) {+ token := "mul_test_auth_status"+ if tc.task {+ token = "mat_test_auth_status"+ t.Setenv("MULTICA_AGENT_ID", "agent-test")+ t.Setenv("MULTICA_TASK_ID", "task-test")+ t.Setenv("MULTICA_TASK_CONFIG_ROOT", filepath.Join(t.TempDir(), "task-multica"))+ }+ t.Setenv("MULTICA_TOKEN", token)+ const responseBody = "test verification failure"+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if r.URL.Path != "/api/me" {+ t.Errorf("unexpected request path %q", r.URL.Path)+ }+ w.WriteHeader(tc.status)+ fmt.Fprint(w, responseBody)+ }))+ defer srv.Close()+ t.Setenv("MULTICA_SERVER_URL", srv.URL)+ stderr := captureStderr(t)+ defer stderr.restore()+ args := []string{"auth", "status"}+ debugFlag = false+ if tc.debug {+ args = append(args, "--debug")+ }+ rootCmd.SetArgs(args)+ if err := rootCmd.Execute(); err != nil {+ t.Fatal(err)+ }+ out := stderr.read()+ if !strings.Contains(out, tc.message) || strings.Contains(out, "multica login") != tc.relogin || strings.Contains(out, token) {+ t.Fatalf("unexpected auth status output: %q", out)+ }+ if tc.debug {+ detail := fmt.Sprintf("[debug] http: GET /api/me status=%d body=%s", tc.status, responseBody)+ if !strings.Contains(out, detail) {+ t.Fatalf("expected %q in auth status output: %q", detail, out)+ }+ } else if strings.Contains(out, "[debug]") || strings.Contains(out, responseBody) {+ t.Fatalf("unexpected debug details in auth status output: %q", out)+ }+ })+ }+}