test: make completion test robust to shfmt formatting
Metadata
Current evaluation
Merged PR #505 fixes test_completion_output by formatting the expected fixture with shfmt and normalizing generated output, preventing byte-for-byte comparison failures after repo tooling reformatting.
Resolution: closed resolved
Reason: The PR was merged, resolving the test failure caused by shfmt reformatting the completion fixture. All CI checks passed and tests validated successfully.
Evaluated by: mr-cal-bot
No scores available.
Issue body
🤖 This message was generated by kimi-k3.
## Problem
`tests/integration/test_completion.py::test_completion_output` compares a generated bash completion script byte-for-byte against the checked-in fixture `tests/integration/test_completion/expected_script.sh`.
The shared Starcraft build tooling (canonical/starbase `common.mk`) formats every git-tracked file that `file --mime-type` reports as a shell script using `shfmt -w`, explicitly excluding `*.sh.j2` templates so the Jinja2 source (`craft_cli/completion/bash_completion.sh.j2`) is not corrupted. However, the *expected output* fixture is still a plain shell script, so shfmt rewrites it (e.g. `_complete_testcraft(){` → `_complete_testcraft() {`, `all_cmds=( ls cp )` → `all_cmds=(ls cp)`), while the generated output continues to follow the template's original formatting. The byte-for-byte comparison then fails.
## Fix
- Format the fixture with `shfmt` so it matches what repo tooling produces.
- Make the test normalize the generated script through `shfmt -i 2` before comparing, so the comparison is formatting-insensitive on both sides. The test skips if `shfmt` is not installed.
This keeps the test passing regardless of whether the fixture has been reformatted by repo tooling.
## Validation
- `uv run pytest tests/integration/test_completion.py` — 2 passed
- `uv run pytest tests/integration -q` — 188 passed
- `uv run pytest tests/unit -q` — 684 passed, 1 skipped
## Provenance
Discovered while validating the Starbase sync merge for this repository: the updated `common.mk` from canonical/starbase adds `format-shfmt`/`lint-shfmt` targets covering all tracked shell scripts. This is a preparation PR for that starbase update.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | closed resolved | Merged PR #505 fixes test_completion_output by formatting the expected fixture with shfmt and normalizing generated output, preventing byte-for-byte comparison failures after repo tooling reformatting. |
Update history
| Date | Change |
|---|---|
| merged | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| updated | |
| created |
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #531 Add shell formatting tool | starbase | closed | Added shfmt formatting and linting plus a pre-commit hook in merged PR #565 (commit e978069). | |
| #565 feat(build): add shfmt tool for shell formatting | starbase | merged | Merged #565 in commit e978069, adding shfmt formatting, a make format-shell target, and a pre-commit hook; this implemented #531. |