tests: add smoke coverage for shell completion script
PR Type
- [ ] Bug fix
- [x] New feature
- [ ] Core Runtime change (higher bar -- see CONTRIBUTING.md)
- [ ] Docs / tooling
- [ ] Refactoring
Summary
Add a bash smoke test for metaflow-complete.sh to ensure shell completion is loadable and returns expected top-level commands. This catches completion script regressions early in CI and provides a direct local test command for contributors.
Issue
Fixes #3107
Fixes #
Reproduction
Runtime: local (Linux bash)
Commands to run:
# run only the new smoke test
python -m pytest test/unit/test_shell_completion.py -v
# optional: run via tox unit env
tox -e unit -- test/unit/test_shell_completion.py
Where evidence shows up:
Before (error / log snippet)
No dedicated automated smoke coverage existed for `metaflow-complete.sh`.
Completion regressions could pass CI undetected until user-facing breakage.
After (evidence that fix works)
test/unit/test_shell_completion.py::test_metaflow_completion_script_smoke PASSED
Sample completion candidates returned:
code
configure
develop
help
status
tutorials
Root Cause
The completion script is user-facing shell glue that was not covered by a focused automated smoke test. Without CI/runtime validation of script sourcing and returned candidates, regressions in completion behavior can slip through normal test paths.
Why This Fix Is Correct
The test validates the critical behavior contract directly:
- script can be sourced in bash
- completion is registered for metaflow
- completion output contains expected top-level commands
This is minimal and scoped: it adds only a targeted smoke test plus a contributor doc command, without changing CLI/runtime behavior.
Failure Modes Considered
- Bash loads script but no completion registration (
complete -p metaflowcheck fails) - Completion function runs but expected command candidates are missing (assertion includes actionable missing set and full output)
Tests
- [x] Unit tests added/updated
- [ ] Reproduction script provided (required for Core Runtime)
- [ ] CI passes
- [ ] If tests are impractical: explain why below and provide manual evidence above
Non-Goals
- No changes to completion algorithm or CLI command behavior.
- No cross-shell expansion beyond the current bash smoke scope.
- No refactor of packaging or test runner infrastructure.
AI Tool Usage
- [ ] No AI tools were used in this contribution
- [x] AI tools were used (describe below)
Used an AI coding assistant (Claude) to draft the test structure and PR text. All generated content was reviewed, adjusted, and validated manually (including command-level behavior checks and syntax checks) before submission.
Greptile Summary
This PR adds a single new unit test (test/unit/test_shell_completion.py) that smoke-tests metaflow-complete.sh by sourcing the script, invoking the bash completion function with a temp wrapper named metaflow, and asserting that expected top-level CLI commands appear in COMPREPLY.
- Adds
test_metaflow_completion_script_smokeas the first automated check for the shell completion script, catching regressions early in CI. - Uses
tempfile.TemporaryDirectoryand a correctly-namedmetaflowwrapper to satisfy click's_METAFLOW_COMPLETEvariable derivation, addressing concerns raised in prior review threads.
Confidence Score: 5/5
Safe to merge — adds only a new test file with no changes to runtime or CLI behaviour.
The change is isolated to a single new test file. The core issues flagged in previous review threads (fixed-path race condition, unbound wrapper_path in finally, click's prog_name derivation) have all been addressed in the current revision. Remaining observations are hardening suggestions that do not affect correctness.
No files require special attention.
Important Files Changed
| Filename | Overview |
|---|---|
| test/unit/test_shell_completion.py | New smoke test that sources metaflow-complete.sh, invokes the completion function with a named temp wrapper, and asserts expected top-level commands are returned; no platform skip guard and no subprocess timeout. |
Reviews (7): Last reviewed commit: "Merge branch 'master' into tests/smoke-t..." | Re-trigger Greptile
@savingoyal