Fix ANSI logging in auth and add completion support#1637
Conversation
- Remove lipgloss styling from log.Info call in manager.go to prevent ANSI escape sequences in logs - Add identity flag completion for auth commands - Add AddIdentityCompletion helper function in cmd_utils.go - Enable completion for --identity flag in auth and auth exec commands The logger should handle all colorization internally. Passing pre-styled text with ANSI codes breaks structured logging. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add unit tests for identityFlagCompletion function - Add unit tests for AddIdentityCompletion function - Add integration tests for auth command completion - Test edge cases: no auth config, partial matches, empty identities - Test format flag completion for auth env command - Test inheritance of persistent identity flag in subcommands - Coverage for completion functions: 80-90% 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds shell completion for the Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant Sh as Shell
participant C as Cobra Command (auth/*)
participant AC as AddIdentityCompletion
participant IC as identityFlagCompletion
participant CFG as Config Loader
U->>Sh: Press Tab for --identity
Sh->>C: Request completions
C->>AC: Completion registered on init?
Note right of AC #D3E4CD: Registration attaches IC when identity flag exists
C->>IC: Invoke completion handler (toComplete)
IC->>CFG: Load atmos config, collect identities
CFG-->>IC: Sorted identity names
IC-->>C: Return candidates + NoFile directive
C-->>Sh: Provide completion list
Sh-->>U: Show suggestions
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used📓 Path-based instructions (4)cmd/**/*.go📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
Files:
**/*.go📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
Files:
**/!(*_test).go📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
Files:
cmd/*.go📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (1)📚 Learning: 2025-02-18T13:18:53.146ZApplied to files:
🧬 Code graph analysis (1)cmd/auth_whoami.go (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🔇 Additional comments (1)
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: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (6)
cmd/auth.go(1 hunks)cmd/auth_exec.go(1 hunks)cmd/auth_integration_test.go(1 hunks)cmd/cmd_utils.go(1 hunks)cmd/cmd_utils_test.go(2 hunks)pkg/auth/manager.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
cmd/**/*.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands
Implement each CLI command in a separate file under cmd/
Use Viper for managing configuration, environment variables, and flags in the CLI
Keep separation of concerns between CLI interface (cmd) and business logic
Use kebab-case for command-line flags
Provide comprehensive help text for all commands and flags
Include examples in Cobra command help
Use Viper for configuration management; support files, env vars, and flags with precedence flags > env > config > defaults
Follow single responsibility; separate command interface from business logic
Provide meaningful user feedback and include progress indicators for long-running operations
Provide clear error messages to users and troubleshooting hints where appropriate
cmd/**/*.go: Define one Cobra command per file under cmd/ and follow example pattern with embedded markdown examples.
New commands should rely on automatic telemetry capture; add explicit CaptureCmd/CaptureCmdString only for non-standard paths.
Files:
cmd/auth.gocmd/auth_integration_test.gocmd/cmd_utils.gocmd/cmd_utils_test.gocmd/auth_exec.go
**/*.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments
**/*.go: All comments must end with periods across all Go code (godot linter enforced).
Organize imports into three groups (stdlib, 3rd-party, Atmos) separated by blank lines and sorted alphabetically within groups; preserve existing aliases.
Add defer perf.Track(<atmosConfig|nil>, ".")() at the start of all public and critical private functions, followed by a blank line.
All errors must be wrapped using static errors from errors/errors.go; prefer errors.Join for multiple errors, fmt.Errorf with %w for context, and check with errors.Is; never use dynamic errors directly.
Use utils.PrintfMarkdown() to render embedded markdown examples for CLI help output.
Co-locate unit tests with implementation files; integration tests reside under tests/.
Distinguish UI output from logging: UI prompts/status/errors to stderr; data/results to stdout; logging for system/debug info only with structured fields.
Most text UI must go to stderr; only data/results to stdout. Prefer utils.PrintfMessageToTUI for UI messages.
Bind all environment variables with viper.BindEnv(); every env var must have an ATMOS_ alternative binding.
Favor cross-platform code: prefer SDKs over external binaries, use filepath/os/runtime, and handle OS-specific differences or use build tags.
For non-standard execution paths, capture telemetry using telemetry.CaptureCmd or telemetry.CaptureCmdString without collecting user data.
Search for existing methods and utilities (internal/exec, pkg/) before implementing new functionality; prefer reuse/refactoring over duplication.
Files:
cmd/auth.gocmd/auth_integration_test.gocmd/cmd_utils.gopkg/auth/manager.gocmd/cmd_utils_test.gocmd/auth_exec.go
**/!(*_test).go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
Document all exported functions, types, and methods with Go doc comments
Files:
cmd/auth.gocmd/cmd_utils.gopkg/auth/manager.gocmd/auth_exec.go
cmd/*.go
📄 CodeRabbit inference engine (CLAUDE.md)
Place each CLI command in its own file (one command per file) under cmd/.
Files:
cmd/auth.gocmd/auth_integration_test.gocmd/cmd_utils.gocmd/cmd_utils_test.gocmd/auth_exec.go
**/*_test.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios
**/*_test.go: Write unit tests as table-driven tests focused on behavior; prefer high coverage for pkg/ and internal/exec/; comments must end with periods.
Use t.Skipf with a reason instead of t.Skip; never skip without a reason.
Test files must mirror implementation file names (e.g., aws_ssm_store_test.go pairs with aws_ssm_store.go).
Files:
cmd/auth_integration_test.gocmd/cmd_utils_test.go
cmd/**/*_test.go
📄 CodeRabbit inference engine (CLAUDE.md)
Place command tests under cmd/ as *_test.go files.
Files:
cmd/auth_integration_test.gocmd/cmd_utils_test.go
pkg/**/*.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
Place business logic in pkg rather than in cmd
Files:
pkg/auth/manager.go
🧠 Learnings (2)
📚 Learning: 2025-02-09T14:38:53.443Z
Learnt from: samtholiya
PR: cloudposse/atmos#992
File: cmd/cmd_utils.go:0-0
Timestamp: 2025-02-09T14:38:53.443Z
Learning: Error handling for RegisterFlagCompletionFunc in AddStackCompletion is not required as the errors are non-critical for tab completion functionality.
Applied to files:
cmd/cmd_utils.gocmd/cmd_utils_test.go
📚 Learning: 2025-02-18T13:18:53.146Z
Learnt from: samtholiya
PR: cloudposse/atmos#1068
File: cmd/vendor_pull.go:31-31
Timestamp: 2025-02-18T13:18:53.146Z
Learning: Error checking is not required for cobra.Command.RegisterFlagCompletionFunc calls as these are static configurations done at init time.
Applied to files:
cmd/cmd_utils_test.go
🧬 Code graph analysis (6)
cmd/auth.go (1)
cmd/cmd_utils.go (1)
AddIdentityCompletion(754-760)
cmd/auth_integration_test.go (1)
cmd/auth_env.go (1)
SupportedFormats(20-20)
cmd/cmd_utils.go (3)
pkg/config/config.go (1)
InitCliConfig(25-62)pkg/schema/schema.go (1)
ConfigAndStacksInfo(460-539)pkg/logger/log.go (1)
Trace(14-16)
pkg/auth/manager.go (1)
pkg/logger/log.go (1)
Info(34-36)
cmd/cmd_utils_test.go (1)
cmd/cmd_utils.go (2)
AddIdentityCompletion(754-760)AddStackCompletion(731-736)
cmd/auth_exec.go (1)
cmd/cmd_utils.go (1)
AddIdentityCompletion(754-760)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Build (windows-latest, windows)
- GitHub Check: Analyze (go)
- GitHub Check: Lint (golangci)
- GitHub Check: Summary
🔇 Additional comments (5)
pkg/auth/manager.go (1)
591-591: LGTM!Removing lipgloss styling from the log call is correct. The logger handles colorization internally now.
cmd/auth_integration_test.go (1)
156-255: LGTM!The integration tests are comprehensive and well-structured. They properly handle directory changes with cleanup, test both identity and format flag completions, verify directive values, and check flag inheritance across subcommands.
cmd/cmd_utils_test.go (1)
264-516: LGTM!The unit tests are thorough and well-structured. They cover edge cases including missing auth config, partial input matching, and completion function registration. The tests properly handle directory changes and follow table-driven patterns where appropriate.
cmd/auth.go (1)
43-44: LGTM!The identity completion wiring is correctly placed in the init function and follows the established pattern for flag completion registration.
cmd/auth_exec.go (1)
140-140: LGTM!The identity completion wiring is correctly placed and follows the same pattern as the auth command.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1637 +/- ##
==========================================
+ Coverage 64.90% 64.95% +0.05%
==========================================
Files 337 337
Lines 37448 37472 +24
==========================================
+ Hits 24305 24341 +36
+ Misses 11199 11184 -15
- Partials 1944 1947 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
- Add doc comments for identityFlagCompletion and AddIdentityCompletion - Sort identity completions alphabetically for predictable order - Add sort import to cmd_utils.go and cmd_utils_test.go - Add TestIdentityFlagCompletionSorting to verify sorted output - Add TestIdentityFlagCompletionErrorPath to test error handling - Add TestAddIdentityCompletionErrorHandling to test error path - Coverage improvements target 90%+ Addresses CodeRabbit review comments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add shell completion for --output flag on auth whoami command - Completion suggests "json" as the only valid output format - Add TestAuthWhoamiOutputCompletion integration test - Ensures all auth command flags have appropriate completion Now all auth commands with applicable flags have completion: - auth --identity (persistent, inherited by all subcommands) - auth exec --identity (local flag) - auth env --format (json, bash, dotenv) - auth whoami --output (json) - auth login (inherits --identity from parent) - auth validate --verbose (boolean, no completion needed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
cmd/cmd_utils_test.go (1)
265-594: Excellent test coverage!The tests comprehensively validate the new completion functionality across multiple scenarios—valid configs, missing configs, edge cases, sorting behavior, and error paths. The table-driven structure and proper cleanup with defer make these tests maintainable and reliable.
One minor suggestion: Consider using
cobra.ShellCompDirectiveNoFileCompconstant instead of the magic number4in assertions for better readability, though the comments explaining the value work fine.- assert.Equal(t, 4, int(directive)) // cobra.ShellCompDirectiveNoFileComp + assert.Equal(t, int(cobra.ShellCompDirectiveNoFileComp), int(directive))
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
cmd/cmd_utils.go(2 hunks)cmd/cmd_utils_test.go(2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
cmd/**/*.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands
Implement each CLI command in a separate file under cmd/
Use Viper for managing configuration, environment variables, and flags in the CLI
Keep separation of concerns between CLI interface (cmd) and business logic
Use kebab-case for command-line flags
Provide comprehensive help text for all commands and flags
Include examples in Cobra command help
Use Viper for configuration management; support files, env vars, and flags with precedence flags > env > config > defaults
Follow single responsibility; separate command interface from business logic
Provide meaningful user feedback and include progress indicators for long-running operations
Provide clear error messages to users and troubleshooting hints where appropriate
cmd/**/*.go: Define one Cobra command per file under cmd/ and follow example pattern with embedded markdown examples.
New commands should rely on automatic telemetry capture; add explicit CaptureCmd/CaptureCmdString only for non-standard paths.
Files:
cmd/cmd_utils.gocmd/cmd_utils_test.go
**/*.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments
**/*.go: All comments must end with periods across all Go code (godot linter enforced).
Organize imports into three groups (stdlib, 3rd-party, Atmos) separated by blank lines and sorted alphabetically within groups; preserve existing aliases.
Add defer perf.Track(<atmosConfig|nil>, ".")() at the start of all public and critical private functions, followed by a blank line.
All errors must be wrapped using static errors from errors/errors.go; prefer errors.Join for multiple errors, fmt.Errorf with %w for context, and check with errors.Is; never use dynamic errors directly.
Use utils.PrintfMarkdown() to render embedded markdown examples for CLI help output.
Co-locate unit tests with implementation files; integration tests reside under tests/.
Distinguish UI output from logging: UI prompts/status/errors to stderr; data/results to stdout; logging for system/debug info only with structured fields.
Most text UI must go to stderr; only data/results to stdout. Prefer utils.PrintfMessageToTUI for UI messages.
Bind all environment variables with viper.BindEnv(); every env var must have an ATMOS_ alternative binding.
Favor cross-platform code: prefer SDKs over external binaries, use filepath/os/runtime, and handle OS-specific differences or use build tags.
For non-standard execution paths, capture telemetry using telemetry.CaptureCmd or telemetry.CaptureCmdString without collecting user data.
Search for existing methods and utilities (internal/exec, pkg/) before implementing new functionality; prefer reuse/refactoring over duplication.
Files:
cmd/cmd_utils.gocmd/cmd_utils_test.go
**/!(*_test).go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
Document all exported functions, types, and methods with Go doc comments
Files:
cmd/cmd_utils.go
cmd/*.go
📄 CodeRabbit inference engine (CLAUDE.md)
Place each CLI command in its own file (one command per file) under cmd/.
Files:
cmd/cmd_utils.gocmd/cmd_utils_test.go
**/*_test.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios
**/*_test.go: Write unit tests as table-driven tests focused on behavior; prefer high coverage for pkg/ and internal/exec/; comments must end with periods.
Use t.Skipf with a reason instead of t.Skip; never skip without a reason.
Test files must mirror implementation file names (e.g., aws_ssm_store_test.go pairs with aws_ssm_store.go).
Files:
cmd/cmd_utils_test.go
cmd/**/*_test.go
📄 CodeRabbit inference engine (CLAUDE.md)
Place command tests under cmd/ as *_test.go files.
Files:
cmd/cmd_utils_test.go
🧠 Learnings (2)
📚 Learning: 2025-02-09T14:38:53.443Z
Learnt from: samtholiya
PR: cloudposse/atmos#992
File: cmd/cmd_utils.go:0-0
Timestamp: 2025-02-09T14:38:53.443Z
Learning: Error handling for RegisterFlagCompletionFunc in AddStackCompletion is not required as the errors are non-critical for tab completion functionality.
Applied to files:
cmd/cmd_utils_test.go
📚 Learning: 2025-02-18T13:18:53.146Z
Learnt from: samtholiya
PR: cloudposse/atmos#1068
File: cmd/vendor_pull.go:31-31
Timestamp: 2025-02-18T13:18:53.146Z
Learning: Error checking is not required for cobra.Command.RegisterFlagCompletionFunc calls as these are static configurations done at init time.
Applied to files:
cmd/cmd_utils_test.go
🧬 Code graph analysis (2)
cmd/cmd_utils.go (3)
pkg/config/config.go (1)
InitCliConfig(25-62)pkg/schema/schema.go (1)
ConfigAndStacksInfo(460-539)pkg/logger/log.go (1)
Trace(14-16)
cmd/cmd_utils_test.go (1)
cmd/cmd_utils.go (3)
Contains(793-800)AddIdentityCompletion(760-766)AddStackCompletion(732-737)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build (windows-latest, windows)
- GitHub Check: Build (macos-latest, macos)
- GitHub Check: Lint (golangci)
- GitHub Check: Analyze (go)
- GitHub Check: Summary
🔇 Additional comments (2)
cmd/cmd_utils.go (2)
739-757: Nice work addressing the previous feedback!Both the doc comment and sorting have been implemented as suggested. The function now provides deterministic, sorted completion results, making the shell experience more predictable.
759-766: Previous feedback addressed—looks good!The doc comment has been added, and the implementation correctly handles the registration with appropriate trace logging for debugging purposes.
|
These changes were released in v1.195.0-test.0. |
what
why
\x1b[1m) to the logger, which breaks structured logging--identityand--formatflags to improve CLI usabilitychanges
Fix ANSI Logging Issue
log.Info()call inpkg/auth/manager.go:594lipglossimportAdd Completion Support
identityFlagCompletion()function that reads identities fromatmos.yamlAddIdentityCompletion()helper function to register completion for identity flagsauthcommand (persistent--identity/-iflag)auth execcommandauth envwas already implementedTest Coverage
cmd/cmd_utils_test.go:TestIdentityFlagCompletion- core completion logic with valid/invalid configsTestIdentityFlagCompletionWithNoAuthConfig- edge case handlingTestIdentityFlagCompletionPartialMatch- partial input handlingTestAddIdentityCompletion- helper function registrationTestStackFlagCompletion- existing completion testingTestAddStackCompletion- existing helper testingcmd/auth_integration_test.go:TestAuthCommandCompletion- 5 sub-tests for auth command completionTestAuthEnvFormatCompletion- 2 sub-tests for format flag completionidentityFlagCompletion87.5%,AddIdentityCompletion83%, overall 85-90%testing
references
Summary by CodeRabbit
New Features
Tests
Style