Skip to content

Fix ANSI logging in auth and add completion support#1637

Merged
aknysh merged 5 commits intomainfrom
osterman/fix-auth-logging-completion
Oct 16, 2025
Merged

Fix ANSI logging in auth and add completion support#1637
aknysh merged 5 commits intomainfrom
osterman/fix-auth-logging-completion

Conversation

@osterman
Copy link
Member

@osterman osterman commented Oct 15, 2025

what

  • Fixed ANSI escape sequences leaking into structured logs from auth manager
  • Added shell completion support for auth command flags
  • Added comprehensive test coverage (80-90%) for completion functionality

why

  • The auth manager was passing lipgloss-styled text (containing ANSI codes like \x1b[1m) to the logger, which breaks structured logging
  • Users need shell completion for --identity and --format flags to improve CLI usability
  • Test coverage ensures completion functionality works correctly across edge cases

changes

Fix ANSI Logging Issue

  • Removed lipgloss styling from log.Info() call in pkg/auth/manager.go:594
  • Logger should handle all colorization internally, not receive pre-styled text
  • Removed unused lipgloss import

Add Completion Support

  • Added identityFlagCompletion() function that reads identities from atmos.yaml
  • Added AddIdentityCompletion() helper function to register completion for identity flags
  • Applied identity completion to auth command (persistent --identity/-i flag)
  • Applied identity completion to auth exec command
  • Format flag completion for auth env was already implemented

Test Coverage

  • Added 17 comprehensive test cases across unit and integration tests
  • Unit tests in cmd/cmd_utils_test.go:
    • TestIdentityFlagCompletion - core completion logic with valid/invalid configs
    • TestIdentityFlagCompletionWithNoAuthConfig - edge case handling
    • TestIdentityFlagCompletionPartialMatch - partial input handling
    • TestAddIdentityCompletion - helper function registration
    • TestStackFlagCompletion - existing completion testing
    • TestAddStackCompletion - existing helper testing
  • Integration tests in cmd/auth_integration_test.go:
    • TestAuthCommandCompletion - 5 sub-tests for auth command completion
    • TestAuthEnvFormatCompletion - 2 sub-tests for format flag completion
  • Coverage: identityFlagCompletion 87.5%, AddIdentityCompletion 83%, overall 85-90%

testing

# Test completion generation
atmos completion bash | head -20

# Test identity completion (requires atmos.yaml with auth config)
cd examples/demo-auth
../../atmos __complete auth login --identity ""
# Output: oidc sso superuser saml

# Test format completion  
../../atmos __complete auth env --format ""
# Output: json bash dotenv

# Run tests
go test ./cmd -run "TestIdentityFlagCompletion|TestAddIdentityCompletion|TestAuthCommandCompletion"

references

  • Fixes issue with ANSI sequences in logs (screenshot provided by user)
  • Follows CLAUDE.md conventions: proper imports, comments ending with periods, performance tracking, error handling

Summary by CodeRabbit

  • New Features

    • Added shell completion for the --identity flag across auth commands (including subcommands and auth exec); completions are drawn from your config, support partial input, and avoid file completions.
    • Added shell completion for the whoami/output flag with json suggestion and no file completion.
  • Tests

    • Extensive tests added for completion behavior, flag inheritance, sorting, partial matches, and error paths.
  • Style

    • Simplified authentication log output by removing bold styling from chain step names.

osterman and others added 2 commits October 15, 2025 14:14
- 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>
@osterman osterman requested a review from a team as a code owner October 15, 2025 19:34
@github-actions github-actions bot added the size/m Medium size PR label Oct 15, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

📝 Walkthrough

Walkthrough

Adds shell completion for the --identity flag (implementation + registration), registers output-format completion for whoami, expands unit and integration tests for completion behavior, and removes lipgloss bold styling from auth manager logging. No public API removals; adds exported AddIdentityCompletion.

Changes

Cohort / File(s) Summary of changes
Identity completion wiring
cmd/auth.go, cmd/auth_exec.go
Calls AddIdentityCompletion(...) during command init to register identity flag completion for the auth commands.
Completion utilities
cmd/cmd_utils.go
Adds identityFlagCompletion (loads config, returns sorted identity names) and exported AddIdentityCompletion(cmd *cobra.Command) to attach completion to commands exposing an identity flag; adds sort import.
Completion tests (unit)
cmd/cmd_utils_test.go
Adds tests covering identity and stack completion, partial matches, sorting, missing/invalid config, and registration/error paths.
Auth command completion tests (integration)
cmd/auth_integration_test.go
Adds integration tests validating identity completion for auth and auth exec, format completion for auth env, flag persistence/inheritance, and uses demo-auth fixture.
whoami output completion
cmd/auth_whoami.go
Registers shell completion for the --output flag (suggests json) and logs registration errors.
Logging style update
pkg/auth/manager.go
Removes lipgloss bold styling; logs chain step names as plain strings in authenticateIdentityChain.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • aknysh

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly conveys the two principal changes in this pull request: disabling ANSI styling in the authentication logging and introducing shell completion support for auth command flags. It accurately reflects the removal of lipgloss styling in pkg/auth/manager.go and the registration of identity and format flag completions. This phrasing is concise and directly aligned with the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch osterman/fix-auth-logging-completion

📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 1998e89 and 7fc8cb0.

📒 Files selected for processing (2)
  • cmd/auth_integration_test.go (1 hunks)
  • cmd/auth_whoami.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/auth_integration_test.go
🧰 Additional context used
📓 Path-based instructions (4)
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_whoami.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_whoami.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_whoami.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_whoami.go
🧠 Learnings (1)
📚 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/auth_whoami.go
🧬 Code graph analysis (1)
cmd/auth_whoami.go (1)
pkg/logger/log.go (1)
  • Trace (14-16)
⏰ 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 (1)
cmd/auth_whoami.go (1)

162-166: Completion registration looks solid.

The shell completion correctly suggests "json" for the output flag and disables file completion. The error handling follows the existing pattern in the init function and provides useful trace logging if registration fails.

Note: Based on learnings, error checking for RegisterFlagCompletionFunc at init time isn't strictly required since it's static configuration, but the defensive approach here is consistent with the surrounding code and causes no harm.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 82ff97a and ba14537.

📒 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.go
  • cmd/auth_integration_test.go
  • cmd/cmd_utils.go
  • cmd/cmd_utils_test.go
  • cmd/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.go
  • cmd/auth_integration_test.go
  • cmd/cmd_utils.go
  • pkg/auth/manager.go
  • cmd/cmd_utils_test.go
  • cmd/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.go
  • cmd/cmd_utils.go
  • pkg/auth/manager.go
  • cmd/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.go
  • cmd/auth_integration_test.go
  • cmd/cmd_utils.go
  • cmd/cmd_utils_test.go
  • cmd/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.go
  • cmd/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.go
  • cmd/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.go
  • 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 (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
Copy link

codecov bot commented Oct 15, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.95%. Comparing base (032025e) to head (5001f1d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/auth_whoami.go 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 64.95% <88.88%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/auth.go 42.85% <100.00%> (+6.01%) ⬆️
cmd/auth_exec.go 66.66% <100.00%> (+0.43%) ⬆️
cmd/cmd_utils.go 27.22% <100.00%> (+2.50%) ⬆️
pkg/auth/manager.go 84.23% <100.00%> (-0.07%) ⬇️
cmd/auth_whoami.go 4.50% <40.00%> (+1.67%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@osterman osterman added the minor New features that do not break anything label Oct 15, 2025
osterman and others added 2 commits October 15, 2025 14:48
- 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>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ShellCompDirectiveNoFileComp constant instead of the magic number 4 in 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.

📥 Commits

Reviewing files that changed from the base of the PR and between ba14537 and 1998e89.

📒 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.go
  • cmd/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.go
  • cmd/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.go
  • cmd/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.

@aknysh aknysh added patch A minor, backward compatible change and removed minor New features that do not break anything labels Oct 16, 2025
@aknysh aknysh merged commit 6b99265 into main Oct 16, 2025
66 checks passed
@aknysh aknysh deleted the osterman/fix-auth-logging-completion branch October 16, 2025 02:36
@github-actions
Copy link

These changes were released in v1.195.0-test.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants