feat: Inject AHOY_CMD and AHOY_COMMAND_NAME environment variables into subprocesses#170
feat: Inject AHOY_CMD and AHOY_COMMAND_NAME environment variables into subprocesses#170ocean wants to merge 7 commits into
Conversation
…o subprocesses Sets AHOY_CMD to the resolved path of the running ahoy binary and AHOY_COMMAND_NAME to the name of the invoked command, making both available to every subprocess ahoy runs. Adds a testdata fixture and BATS integration tests to verify the behaviour.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThe PR adds environment variable injection to ahoy command execution. Config and Command structs now declare explicit YAML tags for schema alignment. Command handlers switch from Run to RunE for error propagation. The ahoy binary path is captured at startup via os.Executable() and injected as AHOY_CMD alongside AHOY_COMMAND_NAME into every executed command's environment. Bash completion logic is simplified, and test configuration and Bats tests validate the new variables' presence and executability. ChangesEnvironment variable injection feature
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
🚥 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 |
|
@coderabbitai There should be a configuration change to include you doing code reviews on the v3-candidate branch, please check your configuration |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain
🛠 Debug Information Gathered
To fix this, add reviews:
auto_review:
base_branches:
- v3-candidateThis field accepts regex patterns too, so if you want to cover all non-default branches you could use Once that change is merged into the default branch, CodeRabbit will automatically review PRs that target |
|
@coderabbitai help |
ChatThere are 3 ways to chat with CodeRabbit:
CodeRabbit commands
Other keywords and placeholders
CodeRabbit configuration file (
|
|
Note Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
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 `@v2/ahoy.go`:
- Line 321: The current assignment to command.Env appends ahoyEnvVars before
envVars so user-provided environment entries can override injected values;
change the append order so envVars are appended first and ahoyEnvVars are
appended last (so injected AHOY_CMD / AHOY_COMMAND_NAME override any
duplicates), i.e., update the expression that builds command.Env which uses
command.Environ(), ahoyEnvVars and envVars to append envVars then ahoyEnvVars.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 850910d1-4739-42ea-8472-a116e8914154
📒 Files selected for processing (3)
v2/ahoy.gov2/testdata/ahoy-self-env.ahoy.ymlv2/tests/environment-variables.bats
|
❌ Failed to create PR with unit tests: AGENT_CHAT: Failed to open pull request |
- $AHOY_CMD contains a path to the actual ahoy executable so it can be used for substitution for running ahoy-driven subcommands with the exact same binary. - $AHOY_COMMAND_NAME contains the name of the ahoy command (within the .ahoy.yml file) that is being run, and therefore allows the subprocess to know it is being run by an ahoy parent process. Signed-off-by: Drew Robinson <drew.robinson@gmail.com>
…bles into subprocesses" This reverts commit 1f78216.
… files... ... don't override the injected runtime values. In Go's os/exec, the last occurrence of a duplicate environment variable key takes precedence, and we want that to be the ones set by ahoy itself. Signed-off-by: Drew Robinson <drew.robinson@gmail.com>
yaml.v2 uses case-insensitive field matching as a fallback when no tags are present, but yaml.v3 (the current maintained version) requires exact matches. Without tags, migrating to yaml.v3 would silently leave AhoyAPI empty on every config file, causing spurious "unsupported API version" errors for all users. Add explicit yaml:"..." tags to every field on both Config and Command to make the structs safe for a future yaml.v3 migration.
…os.Exit os.Exit inside rootCmd.Execute() bypasses the pipe-drain cleanup in main(), which can cause in-flight subprocess stderr output to be silently truncated. Switching the command closure from Run to RunE and returning the subprocess error lets main() close the write-end of the pipe and wait for the drain goroutine to flush before exiting.
The block logged the sourcefile path and called os.Exit(0) whenever sourcefile was set, which in normal usage is always. This meant shell completion was printing the config file path instead of command names and exiting without running the pipe-drain cleanup in main(). Removing it lets the correct completion logic below run and avoids the os.Exit inside Execute().
Sets AHOY_CMD to the resolved path of the running ahoy binary and AHOY_COMMAND_NAME to the name of the invoked command, making both available to every subprocess ahoy runs.
Adds a testdata fixture and BATS integration tests to verify the behaviour.
This is a fix for #165
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Tests