feat(cli): silence proxy warning in non-interactive invocations#1241
feat(cli): silence proxy warning in non-interactive invocations#1241zhengzhijiej-tech wants to merge 1 commit into
Conversation
WarnIfProxied prints a one-time proxy notice to stderr. Agent / CI / piped callers parse stdout as JSON and frequently merge streams with 2>&1, where a stray stderr warning corrupts the parsed payload. Gate the warning on interactivity (stdin is a TTY): human interactive sessions still get the security notice, machine-consumed output stays clean. Passing interactive=false does not consume the once guard, so a later interactive call can still warn.
📝 WalkthroughWalkthroughThis pull request adds an ChangesProxy Warning Interactivity Control
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1241 +/- ##
=======================================
Coverage 69.22% 69.22%
=======================================
Files 639 639
Lines 59798 59800 +2
=======================================
+ Hits 41395 41397 +2
Misses 15058 15058
Partials 3345 3345 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/transport/warn_test.go (1)
80-95: ⚡ Quick winConsider covering the once-guard-preservation contract.
This test verifies suppression when
interactive=false, but the documented behavior that a non-interactive call does not consumeproxyWarningOnce(so a subsequent interactive call still warns) is untested. A small follow-up assertion would lock in that contract.💚 Suggested additional assertion
// A non-interactive call must not consume the once guard: // a later interactive call should still warn. var buf2 bytes.Buffer WarnIfProxied(&buf2, true) if buf2.Len() == 0 { t.Error("expected warning on interactive call after a suppressed non-interactive call") }Note: to make this assertion reliable, this test should also call
unsetProxyPluginEnv(t)/resetProxyPluginState()like the sibling tests, since the interactive path reachesproxyPluginStatus().🤖 Prompt for 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. In `@internal/transport/warn_test.go` around lines 80 - 95, Add an assertion to TestWarnIfProxied_SilentWhenNonInteractive that verifies the once-guard is not consumed by the non-interactive path: after the existing non-interactive call to WarnIfProxied(&buf, false) set up the same test env cleanup (call unsetProxyPluginEnv(t) and resetProxyPluginState()) and then call WarnIfProxied with interactive=true into a new buffer (e.g., buf2) and assert buf2.Len() > 0 so an interactive call still emits the warning; reference the proxyWarningOnce guard and proxyPluginStatus indirectly by exercising WarnIfProxied to ensure the contract is preserved.
🤖 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.
Nitpick comments:
In `@internal/transport/warn_test.go`:
- Around line 80-95: Add an assertion to
TestWarnIfProxied_SilentWhenNonInteractive that verifies the once-guard is not
consumed by the non-interactive path: after the existing non-interactive call to
WarnIfProxied(&buf, false) set up the same test env cleanup (call
unsetProxyPluginEnv(t) and resetProxyPluginState()) and then call WarnIfProxied
with interactive=true into a new buffer (e.g., buf2) and assert buf2.Len() > 0
so an interactive call still emits the warning; reference the proxyWarningOnce
guard and proxyPluginStatus indirectly by exercising WarnIfProxied to ensure the
contract is preserved.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 36e35052-5268-4c09-b09e-e537e960ff32
📒 Files selected for processing (3)
internal/cmdutil/factory_default.gointernal/transport/warn.gointernal/transport/warn_test.go
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@f4a9094c5cfd46b94aedd2e6dc9dc55339727205🧩 Skill updatenpx skills add zhengzhijiej-tech/cli#feat/cli-proxy-warn-noninteractive -y -g |
Problem
transport.WarnIfProxiedprints a one-time proxy notice to stderr whenever anHTTP(S)_PROXYenv var is detected (and not disabled viaLARK_CLI_NO_PROXY). For human interactive use this is a useful security hint.But agent / CI / piped callers parse the CLI's stdout as JSON and frequently merge streams with
2>&1. In that case the stray stderr warning corrupts the parsed payload, breaking machine consumers.Change
Gate the warning on interactivity — i.e. whether stdin is a TTY:
WarnIfProxied(w io.Writer)→WarnIfProxied(w io.Writer, interactive bool); returns early wheninteractive == false.internal/cmdutil/factory_default.gopassf.IOStreams.IsTerminal.Human interactive sessions still get the security notice; machine-consumed output stays clean. Passing
interactive=falsedoes not consume theonceguard, so a later interactive call can still warn.Scope
Split out of the lark-sheets refactor PR as an independent, generic CLI/agent-UX change. Only touches the proxy-warning path:
internal/transport/warn.gointernal/transport/warn_test.go(adds a non-interactive-silence case)internal/cmdutil/factory_default.go(2 call sites)Verification
go build ./...andgo test ./internal/transport/... ./internal/cmdutil/...pass.Summary by CodeRabbit