Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(cli): name the TLS handshake timeout and stop masking it on login (MUL-7572, GH #8654) (#8744)
Bohan Jiang8355c7aeca76
diff --git a/apps/docs/content/docs/troubleshooting.ja.mdx b/apps/docs/content/docs/troubleshooting.ja.mdxindex 1c1b3336a6..f0bda2c4f8 100644--- a/apps/docs/content/docs/troubleshooting.ja.mdx+++ b/apps/docs/content/docs/troubleshooting.ja.mdx@@ -130,6 +130,25 @@ CLI の到達確認は `<server-url>/health` に GET を送り、200 を要求curl -fsS <server-url>/health```+## `multica login` が TLS ハンドシェイクのタイムアウトで失敗する++`multica login` でブラウザが開き、Web 側のサインインは完了するのに、CLI は「Sign-in did not complete」または「TLS handshake timed out」で失敗します。`multica --debug login` では `POST /api/tokens` に `net/http: TLS handshake timeout` と表示され、同じマシンの `curl.exe -I https://api.multica.ai` やブラウザは問題なく接続できます。++TCP 接続は確立されますが、TLS ハンドシェイクが完了しません。Multica CLI とデーモンを含む Go クライアントは、既定で TLS ClientHello にポスト量子鍵交換を含めるため、ClientHello が約 1.5 KB になり 2 つのパケットに分割されます。一部のセキュリティソフト、VPN、ルーター、ファイアウォールはこのようなハンドシェイクを破棄します。curl の ClientHello はずっと小さいため通過します。++ポスト量子鍵交換を無効にして再試行し、原因を確認します:++```powershell+$env:GODEBUG = 'tlsmlkem=0'+multica --debug login+```++```bash+GODEBUG=tlsmlkem=0 multica --debug login+```++これで成功する場合は、CLI とデーモンを実行するユーザーに対して `GODEBUG=tlsmlkem=0` を恒久的に設定し(Windows では `[Environment]::SetEnvironmentVariable('GODEBUG', 'tlsmlkem=0', 'User')` を実行して新しいターミナルを開く)、デーモンまたはデスクトップアプリを再起動してください。`MULTICA_HTTP_TIMEOUT` を大きくしても効果はありません。ハンドシェイクはこの設定の対象外です。根本的な解決はネットワーク側で行います。分割された TLS ハンドシェイクを破棄する機器やソフトウェアを更新または再設定してください。+## 認証コードや招待メールが届かないまず backend の起動ログを確認します。ログには、現在使っているのが `SMTP relay`、`Resend API`、`DEV mode` のどれかが表示されます:diff --git a/apps/docs/content/docs/troubleshooting.ko.mdx b/apps/docs/content/docs/troubleshooting.ko.mdxindex 49a9998d5e..a860919bd0 100644--- a/apps/docs/content/docs/troubleshooting.ko.mdx+++ b/apps/docs/content/docs/troubleshooting.ko.mdx@@ -130,6 +130,25 @@ CLI 도달 확인은 `<server-url>/health`에 GET을 보내 200을 기대합니curl -fsS <server-url>/health```+## `multica login`이 TLS 핸드셰이크 시간 초과로 실패함++`multica login`이 브라우저를 열고 웹 로그인은 완료되지만 CLI는 "Sign-in did not complete" 또는 "TLS handshake timed out"으로 실패합니다. `multica --debug login`은 `POST /api/tokens`에서 `net/http: TLS handshake timeout`을 표시하며, 같은 컴퓨터의 `curl.exe -I https://api.multica.ai`나 브라우저는 정상적으로 연결됩니다.++TCP 연결은 열리지만 TLS 핸드셰이크가 끝나지 않습니다. Multica CLI와 데몬을 포함한 Go 클라이언트는 기본적으로 TLS ClientHello에 양자내성 키 교환을 포함하므로 ClientHello가 약 1.5 KB가 되어 두 패킷으로 나뉩니다. 일부 보안 소프트웨어, VPN, 라우터, 방화벽은 이런 핸드셰이크를 버립니다. curl의 ClientHello는 훨씬 작아서 통과합니다.++양자내성 키 교환을 끄고 다시 시도해 원인을 확인합니다:++```powershell+$env:GODEBUG = 'tlsmlkem=0'+multica --debug login+```++```bash+GODEBUG=tlsmlkem=0 multica --debug login+```++이렇게 해서 성공하면 CLI와 데몬을 실행하는 사용자에게 `GODEBUG=tlsmlkem=0`을 영구적으로 설정하고(Windows에서는 `[Environment]::SetEnvironmentVariable('GODEBUG', 'tlsmlkem=0', 'User')`를 실행한 뒤 새 터미널을 여세요) 데몬 또는 데스크톱 앱을 다시 시작하세요. `MULTICA_HTTP_TIMEOUT`을 늘려도 도움이 되지 않습니다. 핸드셰이크는 이 설정의 영향을 받지 않습니다. 근본적인 해결은 네트워크 쪽에서 해야 합니다. 분할된 TLS 핸드셰이크를 버리는 장비나 소프트웨어를 업데이트하거나 재구성하세요.+## 인증 코드 및 초대 이메일이 도착하지 않음먼저 backend 시작 로그를 확인합니다. 로그에는 현재 `SMTP relay`, `Resend API`, `DEV mode` 중 무엇을 사용하는지 표시됩니다.diff --git a/apps/docs/content/docs/troubleshooting.mdx b/apps/docs/content/docs/troubleshooting.mdxindex 0062ba2f78..a03f3b4fe1 100644--- a/apps/docs/content/docs/troubleshooting.mdx+++ b/apps/docs/content/docs/troubleshooting.mdx@@ -130,6 +130,25 @@ Routing `/health` to the backend (port 8080) explicitly in your proxy works acrocurl -fsS <server-url>/health```+## `multica login` fails with a TLS handshake timeout++`multica login` opens the browser and the web sign-in completes, but the CLI still fails with "Sign-in did not complete" or "TLS handshake timed out". `multica --debug login` shows `net/http: TLS handshake timeout` on `POST /api/tokens`, while `curl.exe -I https://api.multica.ai` or a browser on the same machine connects fine.++The TCP connection opens, but the TLS handshake never completes. Go clients, including the Multica CLI and daemon, send a post-quantum key share in the TLS ClientHello by default, which makes it about 1.5 KB and splits it across two packets. Some security software, VPNs, routers, and firewalls drop such handshakes; curl sends a much smaller ClientHello and gets through.++Confirm the cause by retrying with the post-quantum key share disabled:++```powershell+$env:GODEBUG = 'tlsmlkem=0'+multica --debug login+```++```bash+GODEBUG=tlsmlkem=0 multica --debug login+```++If that succeeds, set `GODEBUG=tlsmlkem=0` permanently for the user that runs the CLI and the daemon — on Windows, run `[Environment]::SetEnvironmentVariable('GODEBUG', 'tlsmlkem=0', 'User')` and open a new terminal — then restart the daemon or the desktop app. Raising `MULTICA_HTTP_TIMEOUT` does not help: it does not govern the handshake. The permanent fix is on the network side: update or reconfigure the device or software that drops split TLS handshakes.+## Verification code and invitation emails not deliveredCheck the backend startup log first. It states whether the server is using `SMTP relay`, `Resend API`, or `DEV mode`:diff --git a/apps/docs/content/docs/troubleshooting.zh.mdx b/apps/docs/content/docs/troubleshooting.zh.mdxindex 60180b627d..a9206ca6aa 100644--- a/apps/docs/content/docs/troubleshooting.zh.mdx+++ b/apps/docs/content/docs/troubleshooting.zh.mdx@@ -130,6 +130,25 @@ CLI 的可达性探测会 GET `<server-url>/health` 并要求 200。backend 提curl -fsS <server-url>/health```+## `multica login` 报告 TLS 握手超时++`multica login` 能打开浏览器、网页登录也能完成,但 CLI 仍以 "Sign-in did not complete" 或 "TLS 握手超时" 失败。`multica --debug login` 在 `POST /api/tokens` 上显示 `net/http: TLS handshake timeout`,而同一台机器上的 `curl.exe -I https://api.multica.ai` 或浏览器都能正常连接。++TCP 连接已建立,但 TLS 握手始终没有完成。Go 客户端(包括 Multica CLI 和守护进程)默认在 TLS ClientHello 中携带后量子密钥交换,报文约 1.5 KB,会拆成两个包发送。部分安全软件、VPN、路由器和防火墙会丢弃这种握手;curl 的 ClientHello 小得多,所以能通过。++先关闭后量子密钥交换重试,确认是否为此原因:++```powershell+$env:GODEBUG = 'tlsmlkem=0'+multica --debug login+```++```bash+GODEBUG=tlsmlkem=0 multica --debug login+```++如果这样能成功,请为运行 CLI 和守护进程的用户永久设置 `GODEBUG=tlsmlkem=0`——Windows 上执行 `[Environment]::SetEnvironmentVariable('GODEBUG', 'tlsmlkem=0', 'User')` 后重新打开终端——然后重启守护进程或桌面应用。调高 `MULTICA_HTTP_TIMEOUT` 无效,它不控制握手。根本解决需要在网络侧处理:升级或重新配置丢弃分包 TLS 握手的设备或软件。+## 验证码与邀请邮件未送达先查看 backend 启动日志。日志会说明当前使用 `SMTP relay`、`Resend API` 还是 `DEV mode`:diff --git a/server/cmd/multica/cmd_auth.go b/server/cmd/multica/cmd_auth.goindex 195dd19092..795acb143c 100644--- a/server/cmd/multica/cmd_auth.go+++ b/server/cmd/multica/cmd_auth.go@@ -331,7 +331,7 @@ func runAuthLoginBrowser(cmd *cobra.Command) error {"expires_in_days": expiresInDays,}, &patResp)if err != nil {- return cli.WithUserMessage("Sign-in did not complete: the server could not issue an access token for the CLI. Run `multica login` again.", err)+ return cli.WithUserMessageUnlessNetwork("Sign-in did not complete: the server could not issue an access token for the CLI. Run `multica login` again.", err)}// Verify the PAT works.@@ -341,7 +341,7 @@ func runAuthLoginBrowser(cmd *cobra.Command) error {Email string `json:"email"`}if err := patClient.GetJSON(ctx, "/api/me", &me); err != nil {- return cli.WithUserMessage("Sign-in did not complete: the server did not accept the new credential. Run `multica login` again.", err)+ return cli.WithUserMessageUnlessNetwork("Sign-in did not complete: the server did not accept the new credential. Run `multica login` again.", err)}// Save to config. Reset workspace data on every login — the user or@@ -444,7 +444,7 @@ func runAuthLoginToken(cmd *cobra.Command, providedToken string) error {Email string `json:"email"`}if err := client.GetJSON(ctx, "/api/me", &me); err != nil {- return cli.WithUserMessage("Could not sign in with that token — make sure it is valid and not expired, then run `multica login --token <token>` again.", err)+ return cli.WithUserMessageUnlessNetwork("Could not sign in with that token — make sure it is valid and not expired, then run `multica login --token <token>` again.", err)}profile := resolveProfile(cmd)diff --git a/server/internal/cli/errors.go b/server/internal/cli/errors.goindex 3561b3db0b..a592f11bea 100644--- a/server/internal/cli/errors.go+++ b/server/internal/cli/errors.go@@ -36,6 +36,15 @@ const (// different: a timeout says "this took too long", a stall says "this went// quiet", and only the latter is unaffected by raising a time limit.KindNetworkStalled+ // KindNetworkTLSHandshakeTimeout is a TLS handshake that never completed+ // after the TCP connection opened. Distinct from KindNetworkTimeout+ // because the remedy is different: the request budget+ // (MULTICA_HTTP_TIMEOUT) does not govern the handshake, and the usual+ // cause is a network path that drops a ClientHello spanning two TCP+ // packets — which every Go client sends by default since Go 1.24 (the+ // post-quantum key share makes it ~1.5 KB) while curl on the same machine+ // gets through (GH #8654).+ KindNetworkTLSHandshakeTimeout// HTTP status layer.KindAuthRequired // 401@@ -67,7 +76,7 @@ const (// IsNetwork reports whether the kind is a transport-layer failure.func (k ErrorKind) IsNetwork() bool {switch k {- case KindNetworkTimeout, KindNetworkDNS, KindNetworkRefused, KindNetworkTLS, KindNetworkOffline, KindNetworkStalled:+ case KindNetworkTimeout, KindNetworkDNS, KindNetworkRefused, KindNetworkTLS, KindNetworkOffline, KindNetworkStalled, KindNetworkTLSHandshakeTimeout:return truedefault:return false@@ -91,6 +100,8 @@ func (k ErrorKind) String() string {return "network_offline"case KindNetworkStalled:return "network_stalled"+ case KindNetworkTLSHandshakeTimeout:+ return "network_tls_handshake_timeout"case KindAuthRequired:return "auth_required"case KindTaskTokenRejected:@@ -166,6 +177,28 @@ func WithUserMessage(msg string, err error) error {return &UserMessageError{Msg: msg, Err: err}}+// WithUserMessageUnlessNetwork is WithUserMessage for a command whose custom+// copy explains an HTTP-level refusal — a rejected token, a server that would+// not issue one — and would be wrong for a transport failure. When err is a+// *NetworkError it is returned unchanged, so FormatError renders the+// kind-based copy, which is the only place that names the actual remedy+// (DNS, proxy, TLS handshake).+//+// `multica login` needs this: with WithUserMessage, a TLS handshake that+// never completed was reported as "the server could not issue an access+// token" and "make sure the token is valid and not expired", and nothing in+// the default output pointed at the network (GH #8654).+func WithUserMessageUnlessNetwork(msg string, err error) error {+ if err == nil {+ return nil+ }+ var netErr *NetworkError+ if errors.As(err, &netErr) {+ return err+ }+ return &UserMessageError{Msg: msg, Err: err}+}+// Kind maps an HTTPError's status code onto an ErrorKind.func (e *HTTPError) Kind() ErrorKind {switch e.StatusCode {@@ -212,6 +245,16 @@ func classifyNetworkError(err error) ErrorKind {}var netErr net.Errorif errors.As(err, &netErr) && netErr.Timeout() {+ // net/http reports a TLS handshake that never completed with an+ // unexported type that also satisfies Timeout(), so only its message+ // tells it apart from a socket timeout. The remedy differs (see+ // KindNetworkTLSHandshakeTimeout), so it must not be folded into the+ // generic timeout. Error() is only consulted here, on a timeout: the+ // typed x509 checks below must keep running before any message is+ // rendered, because a hostname error renders its certificate.+ if isTLSHandshakeTimeout(err) {+ return KindNetworkTLSHandshakeTimeout+ }return KindNetworkTimeout}@@ -247,6 +290,8 @@ func classifyNetworkError(err error) ErrorKind {// String fallbacks for anything not surfaced as a typed error.msg := strings.ToLower(err.Error())switch {+ case strings.Contains(msg, "tls handshake timeout"):+ return KindNetworkTLSHandshakeTimeoutcase strings.Contains(msg, "context deadline exceeded"), strings.Contains(msg, "timeout"), strings.Contains(msg, "timed out"):return KindNetworkTimeoutcase strings.Contains(msg, "no such host"), strings.Contains(msg, "server misbehaving"), strings.Contains(msg, "name resolution"):@@ -259,6 +304,12 @@ func classifyNetworkError(err error) ErrorKind {return KindNetworkOffline}+// isTLSHandshakeTimeout reports whether err is net/http's TLS handshake+// timeout, which is only identifiable by its message.+func isTLSHandshakeTimeout(err error) bool {+ return strings.Contains(strings.ToLower(err.Error()), "tls handshake timeout")+}+// wrapTransport converts a raw transport error returned by http.Client.Do// into a *NetworkError. It returns nil when err is nil so call sites can// reassign unconditionally:@@ -345,6 +396,10 @@ var kindMessages = map[ErrorKind][2]string{"Request timed out: the server did not respond in time. Check your network connection or try again later. You can raise the limit with MULTICA_HTTP_TIMEOUT.","请求超时:服务器未在规定时间内响应。请检查网络连接或稍后重试。可通过 MULTICA_HTTP_TIMEOUT 调高超时时间。",},+ KindNetworkTLSHandshakeTimeout: {+ "TLS handshake timed out: the connection to the Multica server opened, but the secure handshake never completed. Something on this network path (security software, a VPN, a router, or a firewall) is probably dropping large TLS handshakes; curl or a browser on the same machine may still work. Retry with the environment variable GODEBUG=tlsmlkem=0 set, and keep it set for the CLI and the daemon if that fixes it. MULTICA_HTTP_TIMEOUT does not affect the handshake.",+ "TLS 握手超时:已连上 Multica 服务器,但安全握手一直没有完成。通常是网络路径上的安全软件、VPN、路由器或防火墙丢弃了较大的 TLS 握手包,同一台机器上的 curl 或浏览器可能仍然正常。请设置环境变量 GODEBUG=tlsmlkem=0 后重试;若因此恢复,请为 CLI 和守护进程长期保留该设置。MULTICA_HTTP_TIMEOUT 对握手无效。",+ },KindNetworkStalled: {"Transfer stalled: the connection stopped sending data before the response was complete. Check your network connection or try again. You can raise the no-progress budget with MULTICA_HTTP_STALL_TIMEOUT.","传输中断:响应尚未接收完毕,连接就停止发送数据。请检查网络连接或重试。可通过 MULTICA_HTTP_STALL_TIMEOUT 调高无进展等待时间。",diff --git a/server/internal/cli/errors_test.go b/server/internal/cli/errors_test.goindex 85a496877d..a1f9bf9997 100644--- a/server/internal/cli/errors_test.go+++ b/server/internal/cli/errors_test.go@@ -19,6 +19,15 @@ func (timeoutErr) Error() string { return "i/o timeout" }func (timeoutErr) Timeout() bool { return true }func (timeoutErr) Temporary() bool { return true }+// tlsHandshakeTimeoutErr mirrors net/http's unexported tlsHandshakeTimeoutError:+// it satisfies net.Error.Timeout(), so only its message tells it apart from a+// plain socket timeout.+type tlsHandshakeTimeoutErr struct{}++func (tlsHandshakeTimeoutErr) Error() string { return "net/http: TLS handshake timeout" }+func (tlsHandshakeTimeoutErr) Timeout() bool { return true }+func (tlsHandshakeTimeoutErr) Temporary() bool { return true }+func TestClassifyNetworkError(t *testing.T) {cases := []struct {name string@@ -28,11 +37,13 @@ func TestClassifyNetworkError(t *testing.T) {{"context deadline", context.DeadlineExceeded, KindNetworkTimeout},{"wrapped deadline", fmt.Errorf("resolve issue: %w", context.DeadlineExceeded), KindNetworkTimeout},{"net timeout", timeoutErr{}, KindNetworkTimeout},+ {"tls handshake timeout (net.Error)", tlsHandshakeTimeoutErr{}, KindNetworkTLSHandshakeTimeout},{"dns", &net.DNSError{Err: "no such host", Name: "api.multica.ai", IsNotFound: true}, KindNetworkDNS},{"connection refused", syscall.ECONNREFUSED, KindNetworkRefused},{"x509 unknown authority", x509.UnknownAuthorityError{}, KindNetworkTLS},{"x509 hostname", x509.HostnameError{Host: "api.multica.ai"}, KindNetworkTLS},{"timeout string fallback", errors.New("Get \"https://x\": net/http: request canceled (Client.Timeout exceeded)"), KindNetworkTimeout},+ {"tls handshake timeout string", errors.New("Post \"https://api.multica.ai/api/tokens\": net/http: TLS handshake timeout"), KindNetworkTLSHandshakeTimeout},{"dns string fallback", errors.New("dial tcp: lookup api.multica.ai: no such host"), KindNetworkDNS},{"refused string fallback", errors.New("dial tcp 127.0.0.1:443: connect: connection refused"), KindNetworkRefused},{"tls string fallback", errors.New("x509: certificate signed by unknown authority"), KindNetworkTLS},@@ -80,7 +91,7 @@ func TestHTTPErrorKind(t *testing.T) {func TestFormatErrorAllKinds(t *testing.T) {withLang(t, "") // default EnglishallKinds := []ErrorKind{- KindNetworkTimeout, KindNetworkDNS, KindNetworkRefused, KindNetworkTLS, KindNetworkOffline,+ KindNetworkTimeout, KindNetworkDNS, KindNetworkRefused, KindNetworkTLS, KindNetworkOffline, KindNetworkTLSHandshakeTimeout,KindAuthRequired, KindTaskTokenRejected, KindForbidden, KindNotFound, KindConflict,KindValidation, KindRateLimited, KindServerError, KindUnknown,}@@ -375,20 +386,21 @@ func withLang(t *testing.T, lang string) {func TestErrorKindString(t *testing.T) {cases := map[ErrorKind]string{- KindNetworkTimeout: "network_timeout",- KindNetworkDNS: "network_dns",- KindNetworkRefused: "network_refused",- KindNetworkTLS: "network_tls",- KindNetworkOffline: "network_offline",- KindAuthRequired: "auth_required",- KindTaskTokenRejected: "task_token_rejected",- KindForbidden: "forbidden",- KindNotFound: "not_found",- KindConflict: "conflict",- KindValidation: "validation",- KindRateLimited: "rate_limited",- KindServerError: "server_error",- KindUnknown: "unknown",+ KindNetworkTimeout: "network_timeout",+ KindNetworkDNS: "network_dns",+ KindNetworkRefused: "network_refused",+ KindNetworkTLS: "network_tls",+ KindNetworkOffline: "network_offline",+ KindNetworkTLSHandshakeTimeout: "network_tls_handshake_timeout",+ KindAuthRequired: "auth_required",+ KindTaskTokenRejected: "task_token_rejected",+ KindForbidden: "forbidden",+ KindNotFound: "not_found",+ KindConflict: "conflict",+ KindValidation: "validation",+ KindRateLimited: "rate_limited",+ KindServerError: "server_error",+ KindUnknown: "unknown",}seen := map[string]ErrorKind{}for k, want := range cases {@@ -610,3 +622,80 @@ func TestServerErrorCode(t *testing.T) {})}}++// TestFormatErrorTLSHandshakeTimeoutHint is GH #8654 in one assertion. A+// Windows user whose network dropped the two-packet ClientHello saw only+// "Request timed out ... raise the limit with MULTICA_HTTP_TIMEOUT", which+// cannot help: the handshake has its own fixed budget. The copy has to name+// the one knob that does (GODEBUG=tlsmlkem=0), in both languages.+func TestFormatErrorTLSHandshakeTimeoutHint(t *testing.T) {+ raw := errors.New("Post \"https://api.multica.ai/api/tokens\": net/http: TLS handshake timeout")+ err := wrapTransport(nil, raw)++ var netErr *NetworkError+ if !errors.As(err, &netErr) || netErr.Kind != KindNetworkTLSHandshakeTimeout {+ t.Fatalf("wrapTransport classified %v as %v, want network_tls_handshake_timeout", raw, err)+ }+ if code := ExitCodeFor(err); code != ExitNetwork {+ t.Errorf("ExitCodeFor = %d, want ExitNetwork(%d)", code, ExitNetwork)+ }++ withLang(t, "en_US.UTF-8")+ en := FormatError(err, false)+ for _, sub := range []string{"TLS handshake", "GODEBUG=tlsmlkem=0"} {+ if !strings.Contains(en, sub) {+ t.Errorf("EN %q missing %q", en, sub)+ }+ }+ if strings.Contains(en, "raise the limit") {+ t.Errorf("EN still suggests raising the request timeout: %q", en)+ }++ withLang(t, "zh_CN.UTF-8")+ zh := FormatError(err, false)+ for _, sub := range []string{"握手", "GODEBUG=tlsmlkem=0"} {+ if !strings.Contains(zh, sub) {+ t.Errorf("ZH %q missing %q", zh, sub)+ }+ }+}++// TestWithUserMessageUnlessNetwork pins what `multica login` relies on: its+// sign-in copy explains an HTTP refusal and must not paper over a transport+// failure, whose kind copy is the only text that names the remedy.+func TestWithUserMessageUnlessNetwork(t *testing.T) {+ withLang(t, "en_US.UTF-8")+ const hint = "Could not sign in with that token — make sure it is valid and not expired, then run `multica login --token <token>` again."++ t.Run("HTTP refusal keeps the command copy", func(t *testing.T) {+ underlying := &HTTPError{Method: "GET", Path: "/api/me", StatusCode: 401, Body: `{"error":"unauthorized"}`}+ err := WithUserMessageUnlessNetwork(hint, underlying)+ if got := FormatError(err, false); got != hint {+ t.Errorf("FormatError = %q, want the login hint", got)+ }+ if code := ExitCodeFor(err); code != ExitAuth {+ t.Errorf("ExitCodeFor = %d, want ExitAuth(%d)", code, ExitAuth)+ }+ })++ t.Run("transport failure keeps the network copy", func(t *testing.T) {+ underlying := wrapTransport(nil, errors.New("Get \"https://api.multica.ai/api/me\": net/http: TLS handshake timeout"))+ err := WithUserMessageUnlessNetwork(hint, underlying)+ if err != underlying {+ t.Fatalf("expected the *NetworkError to pass through unchanged, got %T", err)+ }+ got := FormatError(err, false)+ if strings.Contains(got, "valid and not expired") {+ t.Errorf("token copy masked a transport failure: %q", got)+ }+ if !strings.Contains(got, "GODEBUG=tlsmlkem=0") {+ t.Errorf("network remedy missing from %q", got)+ }+ })++ t.Run("nil error returns nil", func(t *testing.T) {+ if WithUserMessageUnlessNetwork("x", nil) != nil {+ t.Errorf("WithUserMessageUnlessNetwork(_, nil) should be nil")+ }+ })+}