feat: simplify proxy plugin warning and gate on tty#1448
Conversation
Collapse the multi-line proxy plugin warning to a single concise line and suppress it entirely on non-interactive stderr (pipes, CI, agent runs).
📝 WalkthroughWalkthroughAdds an exported IOStreams.StderrIsTerminal field computed from ErrOut, gates proxy warning emissions during cached HTTP and Lark client initialization on that field, simplifies the proxy-plugin warning to a single generic line, and updates/adds tests including a test seam to spy on proxy-warning invocations. ChangesProxy Warning Terminal Detection and Simplification
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/cmdutil/factory_default.go`:
- Around line 105-107: Add unit tests for both cachedHttpClientFunc and
cachedLarkClientFunc that verify transport.WarnIfProxied is invoked only when
f.IOStreams.StderrIsTerminal() returns true: for each function, create two test
cases (StderrIsTerminal=true and false), inject a fake IOStreams with ErrOut
capturing writer and a stubbed StderrIsTerminal, replace or spy on
transport.WarnIfProxied to record invocations, call the client-init function,
and assert WarnIfProxied was called in the true case and not called in the false
case; ensure tests cover both client init paths.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 336f61fe-3e21-4973-9e28-ad1539ade8b0
📒 Files selected for processing (4)
internal/cmdutil/factory_default.gointernal/cmdutil/iostreams.gointernal/transport/warn.gointernal/transport/warn_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1448 +/- ##
==========================================
+ Coverage 72.88% 73.35% +0.46%
==========================================
Files 738 750 +12
Lines 69553 69250 -303
==========================================
+ Hits 50695 50799 +104
+ Misses 15043 14711 -332
+ Partials 3815 3740 -75 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@b74f5e247fd691a4383047860e320b02674c2403🧩 Skill updatenpx skills add larksuite/cli#feat/proxy-hint-opt -y -g |
Mirror the existing IsTerminal field instead of a live method, computed once in NewIOStreams. This drops the stderrIsTerminal package-level test seam (the gate now reads the field directly); tests inject the field like bind_test.go does for IsTerminal. The warnIfProxied seam stays, since the real function is guarded by an internal sync.Once and cannot be counted across subtests.
Summary
The proxy plugin warning printed two-to-three verbose lines (proxy address, disable instructions, and a custom-CA notice) on every command that built a network client, including non-interactive runs piped to files or consumed by agents. This collapses it to a single concise line and suppresses it entirely when stderr is not a terminal.
Changes
internal/transport/warn.goto one line:[lark-cli] [WARN] proxy plugin enabled: all requests are forced through proxy.(drops the address, theLARKSUITE_CLI_PROXY_ENABLEdisable hint, and the custom-CA line); remove the now-unusedenvvarsimportStderrIsTerminalfield toIOStreamsininternal/cmdutil/iostreams.go(computed once inNewIOStreams, mirroring the existingIsTerminalfield)WarnIfProxiedcall sites ininternal/cmdutil/factory_default.goonf.IOStreams.StderrIsTerminalso the notice is silent on pipes / CI / agent runs; introduce awarnIfProxiedtest seam (the real function is guarded by async.Once)internal/cmdutil/factory_proxy_warn_test.go: verify both client-init paths warn only when stderr is a terminalinternal/transport/warn_test.go: assert the single-line message and credential non-leak; drop the obsolete custom-CA assertion testSecurity note
The custom-CA / TLS-MITM line (
...TLS to upstreams can be intercepted/inspected by this proxy) is intentionally removed, not overlooked. Proxy-plugin mode and a custom CA are both operator self-inflicted local configuration (not attacker-controllable), so this was a defense-in-depth awareness line rather than a vulnerability guard. Dropping it is a deliberate noise-vs-signal tradeoff; the remaining one-liner still states that all requests are forced through the proxy.Test Plan
go build ./...passedgo vet ./internal/transport/ ./internal/cmdutil/passedgo test ./internal/transport/ ./internal/cmdutil/passed (incl. newProxyWarnGatetests: 4/4)LARKSUITE_CLI_PROXY_ENABLE=true LARKSUITE_CLI_PROXY_ADDRESS=http://127.0.0.1:8888 lark-cli auth login --domain docs 2>err.txt— 0 warning lines... script -q /dev/null lark-cli auth login --domain docs— exactly oneproxy plugin enabledlineRelated Issues
N/A
Summary by CodeRabbit
Improvements
Tests