Add userwide config and some rudimentary testing (via bats)#44
Add userwide config and some rudimentary testing (via bats)#44yarikoptic merged 3 commits intomainfrom
Conversation
Source ${XDG_CONFIG_HOME:-~/.config}/yolo/config before the per-project
.git/yolo/config. Arrays (YOLO_PODMAN_VOLUMES, YOLO_PODMAN_OPTIONS,
YOLO_CLAUDE_ARGS) are merged from both configs; scalar flags in
project config override user-wide values. --no-config suppresses both.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
26 tests covering: - expand_volume function (shorthand, options, full form, partial form) - CLI flags (--help, --no-config, --anonymized-paths, --nvidia, --entrypoint, --worktree validation) - Separator (--) and argument routing - Config loading and merging (user-only, project-only, array merge, scalar override, --no-config suppression, XDG_CONFIG_HOME override, YOLO_PODMAN_OPTIONS, YOLO_CLAUDE_ARGS) - Environment variable passthrough (CLAUDE_CONFIG_DIR, GIT_CONFIG_GLOBAL, CLAUDE_CODE_OAUTH_TOKEN) - Container name generation - Config template output Uses bats-core with bats-support and bats-assert as git submodules. Mock podman captures args to a file for assertion. CI runs on both ubuntu-latest and macos-latest. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds user-wide configuration support to yolo and introduces a BATS-based test suite with CI coverage to validate CLI/config behaviors.
Changes:
- Add user-wide config loading via
${XDG_CONFIG_HOME:-~/.config}/yolo/configand merge it with per-project config. - Introduce BATS tests + helper utilities (with bats-support/bats-assert) to cover volume expansion, flag routing, and config behavior.
- Add GitHub Actions CI workflow to run ShellCheck, BATS tests, and basic setup/integration checks.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
bin/yolo |
Adds user-wide config loading and array merging behavior; updates help/template text accordingly. |
config.example |
Documents user-wide config location and merge/override semantics. |
tests/yolo.bats |
Adds end-to-end and function-level BATS tests for flags, config loading, and argument routing. |
tests/test_helper/common.bash |
Adds shared BATS helpers (mock podman, config writers, yolo runner, function loader). |
tests/test_helper/bats-support |
Adds bats-support as a git submodule for testing utilities. |
tests/test_helper/bats-assert |
Adds bats-assert as a git submodule for assertions. |
.gitmodules |
Registers the two BATS helper submodules. |
.github/workflows/ci.yml |
Adds CI jobs for ShellCheck, BATS tests, and setup/integration smoke checks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @test "expand_volume: full form host:container:options passed through" { | ||
| load_yolo_functions | ||
| run expand_volume "~/data:/data:Z" | ||
| assert_output "~/data:/data:Z" |
There was a problem hiding this comment.
This test codifies behavior that will likely break real usage: when expand_volume returns ~/data:/data:Z unchanged, podman -v will receive a literal ~ (tilde expansion won’t happen inside the string), so the host path typically won’t exist. Consider updating expand_volume to expand ~ on the host side even for host:container(:options) forms, and update this expectation accordingly (and similarly for the host:container case).
| @test "expand_volume: full form host:container:options passed through" { | |
| load_yolo_functions | |
| run expand_volume "~/data:/data:Z" | |
| assert_output "~/data:/data:Z" | |
| @test "expand_volume: full form host:container:options expands host ~" { | |
| load_yolo_functions | |
| export HOME="$TEST_HOME" | |
| run expand_volume "~/data:/data:Z" | |
| assert_output "$TEST_HOME/data:/data:Z" |
tests/test_helper/common.bash
Outdated
| # and `set -e`, then evals it. This is more robust than per-function sed | ||
| # extraction which depends on matching closing braces at column 0. | ||
| load_yolo_functions() { | ||
| eval "$(sed -n '2,/^# Parse arguments/{ | ||
| /^set -e$/d | ||
| /^# Parse arguments/d | ||
| p | ||
| }' "$YOLO_BIN")" |
There was a problem hiding this comment.
Using eval to import code from bin/yolo makes the tests tightly coupled to an exact marker comment (# Parse arguments) and can be brittle to future refactors. A more maintainable pattern is to structure bin/yolo so it can be safely sourced without executing main logic (e.g., wrap execution in a main() and only invoke it when run as a script), letting tests import functions without eval/sed parsing.
| # and `set -e`, then evals it. This is more robust than per-function sed | |
| # extraction which depends on matching closing braces at column 0. | |
| load_yolo_functions() { | |
| eval "$(sed -n '2,/^# Parse arguments/{ | |
| /^set -e$/d | |
| /^# Parse arguments/d | |
| p | |
| }' "$YOLO_BIN")" | |
| # and `set -e`, then sources it. This is more robust than per-function sed | |
| # extraction which depends on matching closing braces at column 0. | |
| load_yolo_functions() { | |
| source <(sed -n '2,/^# Parse arguments/{ | |
| /^set -e$/d | |
| /^# Parse arguments/d | |
| p | |
| }' "$YOLO_BIN") |
Address CI shellcheck failure and copilot review feedback: - SC2155: Split local declarations from assignments in install_config() - SC2034: Remove unused CLI_PODMAN_ARGS variable - SC1090: Add shellcheck source=/dev/null directives for dynamic source - Wrap execution code in main() with BASH_SOURCE guard so tests can source bin/yolo directly instead of fragile eval/sed extraction Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @test "--nvidia: podman args contain --device nvidia.com/gpu=all" { | ||
| run_yolo --nvidia | ||
| assert_success | ||
| podman_args_contain "--device" | ||
| podman_args_contain "nvidia.com/gpu=all" | ||
| } |
There was a problem hiding this comment.
podman_args_contain doesn't use run/assert_success, so if multiple checks exist in one test, an earlier failure can be masked by a later success (because the test's final exit status may end up 0). Recommendation: either (a) wrap each call with run podman_args_contain ... followed by assert_success, or (b) introduce an assert_podman_arg helper that performs run + assert_success for a single arg and use that consistently.
| load_yolo_functions | ||
| export HOME="$TEST_HOME" | ||
| run expand_volume "~/data::ro" | ||
| assert_output "$TEST_HOME/data:$TEST_HOME/data:ro" |
There was a problem hiding this comment.
This test codifies that ~/data::ro expands without :Z, which is inconsistent with the default shorthand behavior (which appends :Z). If the intent is that :: keeps SELinux relabeling by default, consider updating expand_volume to append ,Z when options don't already include Z/z, and update this expectation accordingly; otherwise, update user-facing docs/examples to clearly state that :: options must explicitly include Z when needed.
| assert_output "$TEST_HOME/data:$TEST_HOME/data:ro" | |
| assert_output "$TEST_HOME/data:$TEST_HOME/data:ro,Z" |
| - name: Run full setup (automated) | ||
| run: | | ||
| # Answer 'no' to installation prompt | ||
| echo "n" | ./setup-yolo.sh |
There was a problem hiding this comment.
In test-setup, the build-only invocation uses echo \"n\" | ./setup-yolo.sh || true, which suggests this path may exit non-zero. Here (integration-test) the same style of input is not guarded, so the workflow may fail if setup-yolo.sh exits non-zero after a 'no' response while still doing useful work. Recommendation: make setup-yolo.sh exit 0 when the user declines installation (if that's the intended successful path), or adjust this step to tolerate the expected non-zero exit and assert the desired side effects explicitly.
| echo "n" | ./setup-yolo.sh | |
| echo "n" | ./setup-yolo.sh || true |
|
Thanks for the review @copilot! Here's where things stand: Comment 2 (eval/sed brittleness): Already addressed in af66d08 — Comment 3 (podman_args_contain without run/assert_success): Positive Comments 1 & 4 (tilde in full-form volumes, Comment 5 (integration-test missing |
|
@yarikoptic I've opened a new pull request, #45, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
not sure if anything else is needed but let's see what copilot comes up with |
planing to merge if all looks green and see whta copilot says