Skip to content

fix: skip config loading for __complete command#111

Merged
lexfrei merged 1 commit intocozystack:mainfrom
kitsunoff:fix/complete-command-config-loading
Feb 15, 2026
Merged

fix: skip config loading for __complete command#111
lexfrei merged 1 commit intocozystack:mainfrom
kitsunoff:fix/complete-command-config-loading

Conversation

@kitsunoff
Copy link
Contributor

@kitsunoff kitsunoff commented Feb 15, 2026

Summary

Fix shell autocompletion (Tab key) failing with "error loading configuration" when used outside a talm project directory.

This is a follow-up to PR #109 which fixed completion bash/zsh subcommands but missed the __complete command.

Problem

$ talm __complete ini ""
error loading configuration: error reading configuration file: open Chart.yaml: no such file or directory

Root cause: __complete is cobra's internal hidden command for shell autocompletion, triggered when the user presses Tab. It's a separate top-level command, not a child of completion, so the fix in PR #109 didn't cover it.

Changes

  • Add __complete to skipConfigCommands list
  • Extract command list to a package-level variable for better testability and documentation
  • Add unit tests in main_test.go

Test Plan

Unit tests

go test -v -run 'TestSkipConfigCommands' .

Tests cover:

  • completion command
  • completion bash subcommand
  • completion zsh subcommand
  • __complete (cobra internal) ← new
  • init command
  • apply command (should NOT skip)
  • template command (should NOT skip)

Manual testing

# Outside any talm project directory:
$ talm __complete ini ""    # Should output completion suggestions, not error
$ talm <Tab>                 # Should show command completions

How to verify the bug exists (before this fix)

Remove __complete from skipConfigCommands in main.go:

var skipConfigCommands = []string{"init", "completion"}  // missing __complete

Run tests:

go test -v -run 'TestSkipConfigCommands' .

Test __complete_(cobra_internal_for_shell_autocompletion) will fail:

main_test.go:107: skipConfigCommands check = false, want true (skipConfigCommands = [init completion])

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Adjusted startup logic to skip loading full configuration for specific command flows (e.g., init and shell completion) to avoid unnecessary initialization.
  • Tests

    • Added unit tests validating command hierarchy detection and the behavior that determines when configuration should be skipped or loaded.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kitsunoff, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical user experience issue where shell autocompletion for the talm CLI tool would fail in contexts where a project configuration file was not present. By ensuring that internal autocompletion commands bypass configuration loading, the change significantly improves the robustness and usability of the command-line interface, preventing unexpected errors during interactive shell use.

Highlights

  • Autocompletion Fix: Resolved an issue where shell autocompletion (Tab key) would fail with a 'error loading configuration' message when used outside of a talm project directory.
  • Configuration Skipping Logic: The __complete command, which is Cobra's internal mechanism for shell autocompletion, has been added to the list of commands that should skip loading the Chart.yaml configuration.
  • Code Refactoring: The list of commands that skip configuration loading (skipConfigCommands) was extracted into a package-level variable for improved testability and clarity.
  • Unit Tests: New unit tests were introduced in main_test.go to cover the isCommandOrParent logic and specifically verify that __complete and other relevant commands correctly skip configuration loading.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • main.go
    • Declared a new package-level variable skipConfigCommands to centralize the list of commands that should bypass configuration loading.
    • Added __complete to the skipConfigCommands list, along with init and completion.
    • Updated the init function to use the skipConfigCommands variable when determining whether to load the configuration, replacing hardcoded command names.
  • main_test.go
    • Added a new test file to include unit tests for command configuration skipping.
    • Implemented buildCommandHierarchy helper function to programmatically create Cobra command structures for testing purposes.
    • Introduced TestIsCommandOrParent to validate the logic for identifying commands or their parents within a given list.
    • Added TestSkipConfigCommands to specifically verify that __complete, init, and completion commands correctly trigger the configuration skipping mechanism, while other commands like apply and template do not.
Activity
  • This pull request is a follow-up to PR fix: skip config loading for completion subcommands #109, aiming to address a missed scenario for the __complete command.
  • The changes include adding __complete to the skipConfigCommands list and introducing new unit tests.
  • The PR description includes detailed manual testing steps and instructions on how to verify the bug before the fix.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Feb 15, 2026

📝 Walkthrough

Walkthrough

Replaces inline command-name checks with a new skipConfigCommands slice ("init", "completion", "__complete") to skip loading Chart.yaml for those commands; adds tests (main_test.go) to validate command-hierarchy matching and skip behavior.

Changes

Cohort / File(s) Summary
Config Command Skip List
main.go
Adds var skipConfigCommands = []string{"init", "completion", "__complete"} and replaces explicit isCommandOrParent checks with variadic expansion using that slice to determine when to skip loading Chart.yaml.
Command Hierarchy Tests
main_test.go
New tests: buildCommandHierarchy() helper; TestIsCommandOrParent and TestSkipConfigCommands validate command matching and config-skip behavior (covers __complete, shells, init, and an apply path).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 I hop through code with lists in paw,

Commands named clear — no more hidden flaw,
Tests nibble paths to prove what’s true,
Config stays closed when skip flags cue,
A tiny hop, a tidy view. 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 clearly and specifically describes the main fix: adding the __complete command to the skip list to prevent config loading during shell autocompletion.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
main.go (1)

132-149: Pre-existing: os.Args[1] can panic with index-out-of-range.

Not introduced in this PR, but worth noting: if talm is invoked with no arguments, os.Args[1] on Line 133 will panic. A bounds check would make this safer.

Suggested guard
 func initConfig() {
+	if len(os.Args) < 2 {
+		return
+	}
 	cmdName := os.Args[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.

❤️ Share

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

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a bug where shell autocompletion would fail outside of a talm project directory. The fix is correctly implemented by adding the __complete command to the list of commands that skip configuration loading. Extracting this list into a package-level variable skipConfigCommands is a good refactoring that improves code clarity and maintainability. The addition of main_test.go with comprehensive unit tests, including for the new __complete case, is excellent and ensures the fix is well-covered. I have one suggestion to improve the readability of a test helper function.

The __complete command is cobra's internal hidden command used for
shell autocompletion (triggered when user presses Tab). It was not
included in the skip list after PR cozystack#109, causing autocompletion to
fail outside project directories.

Bug reproduction:
  $ talm __complete ini ""
  error loading configuration: error reading configuration file: open Chart.yaml: no such file or directory

Changes:
- Add "__complete" to skipConfigCommands list
- Extract command list to a variable for testability and documentation
- Add unit tests for isCommandOrParent and skipConfigCommands

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
@kitsunoff kitsunoff force-pushed the fix/complete-command-config-loading branch from f553e76 to c68c17f Compare February 15, 2026 12:57
@kitsunoff
Copy link
Contributor Author

fixed

@lexfrei lexfrei merged commit e4f5cf8 into cozystack:main Feb 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants