test(openemr-cmd): deeper non-worktree bats — snapshot/capsule, webroot, LDAP, prek dispatch; 4 more set-u fixes#830
Conversation
…ot, LDAP, prek dispatch; 4 more set-u fixes 28 new tests across 3 files plus 4 small script fixes for the same set-u bug pattern uncovered in openemr#829 (ev): `local FOO="$1"` before the `$# != 1` check crashes under set -u instead of showing the usage hint. - snapshot_capsule_commands.bats: bs / rs / gc / pc. * Happy-path dispatch (bs/rs → /root/devtools backup|restore; gc/pc → docker cp in/out of /snapshots/). * No-arg usage hints with the right exit codes (20 / 21 / 19 / 18). * pc with a missing file exits 15 with the documented error. * Fixes: creat_a_backup_snapshot, restore_from_a_snapshot, copy_capsule_from_docker_to_host, copy_capsule_from_host_to_docker all reorder the $# check ahead of `local FOO="$1"`. Same pattern as ensure_current_ver_with_upgrade_ver in openemr#829. - webroot_swagger_ldap.bats: cwb/cwo (sed in container + docker restart), swtm (devtools passthrough with arg), el/dld (devtools enable-ldap/disable-ldap). - prek_dispatch.bats: outer dispatch shape (docker exec -w /var/www/localhost/htdocs/openemr -i <id> sh -c <inline> sh <args>), args pass-through for run/install-hooks/--version, the inline script contains the actionlint-docker → actionlint-system substitution + 'run|install-hooks' case + 'exec pre-commit' pass- through, and the no-container error path. OC_SCRIPT_FUNCS_END bumped to 1741 to match the post-fix function-defs end. VERSION 1.0.46 → 1.0.47. Total: 290 hermetic tests, 0 failures. shellcheck clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesUnbound-variable fix and BATS test coverage
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 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)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/bats/openemr-cmd/webroot_swagger_ldap.bats (1)
59-68: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winThe cwo DocumentRoot assertion does not actually distinguish the
openemrdirection.The logged
sedcommand for both directions contains the literal search patternDocumentRoot /var/www/localhost/htdocs.*@.... Your regexDocumentRoot /var/www/localhost/htdocs[^/]matches the.immediately afterhtdocsin that search pattern, so it also matches thecwb(blank) command, whose replacement string is.../htdocs/openemr. As written, this test would still pass even ifcworegressed to the blanksed, defeating its stated purpose ("set DocumentRoot WITHOUT /openemr suffix").Anchor the assertion to the replacement segment instead so it fails when the wrong direction runs.
♻️ Match the replacement target, not the search pattern
- grep -Eq 'DocumentRoot /var/www/localhost/htdocs[^/]' "${STUB_DIR}/docker.log" \ - || { cat "${STUB_DIR}/docker.log"; fail "expected sed to set DocumentRoot WITHOUT /openemr suffix"; } + grep -Fq "`@DocumentRoot` /var/www/localhost/htdocs@g" "${STUB_DIR}/docker.log" \ + || { cat "${STUB_DIR}/docker.log"; fail "expected sed replacement to set DocumentRoot WITHOUT /openemr suffix"; }🤖 Prompt for 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. In `@tests/bats/openemr-cmd/webroot_swagger_ldap.bats` around lines 59 - 68, The cwo test assertion is matching the sed search pattern instead of the replacement, so it cannot distinguish the openemr direction from the blank-webroot direction. Update the check in the cwo case to inspect the docker.log entry for the replacement target used by cwo, and anchor it to the DocumentRoot value after sed runs so it fails if the command still points at the /openemr path. Use the existing cwo test block and the docker.log grep assertion to make the match direction-specific.
🤖 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 `@tests/bats/openemr-cmd/snapshot_capsule_commands.bats`:
- Around line 119-122: The temporary capsule filename creation in the snapshot
capsule test is using a GNU-specific mktemp pattern that breaks on macOS; update
the mktemp usage in the pc snapshot test setup to a BSD/macOS-compatible form
while keeping the same tmp_cap variable and oc_run flow. Locate the change in
snapshot_capsule_commands.bats around the local tmp_cap assignment and replace
the -p-based invocation with a portable mktemp pattern under BATS_TMPDIR so the
test works in the macOS matrix.
---
Nitpick comments:
In `@tests/bats/openemr-cmd/webroot_swagger_ldap.bats`:
- Around line 59-68: The cwo test assertion is matching the sed search pattern
instead of the replacement, so it cannot distinguish the openemr direction from
the blank-webroot direction. Update the check in the cwo case to inspect the
docker.log entry for the replacement target used by cwo, and anchor it to the
DocumentRoot value after sed runs so it fails if the command still points at the
/openemr path. Use the existing cwo test block and the docker.log grep assertion
to make the match direction-specific.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c1c651d2-21e9-4ff4-81f8-4abc6678ac24
📒 Files selected for processing (5)
tests/bats/openemr-cmd/helpers.bashtests/bats/openemr-cmd/prek_dispatch.batstests/bats/openemr-cmd/snapshot_capsule_commands.batstests/bats/openemr-cmd/webroot_swagger_ldap.batsutilities/openemr-cmd/openemr-cmd
…ion-specific cwo assertion CodeRabbit review on openemr#830 caught two test-quality issues: 1. snapshot_capsule_commands.bats used `mktemp -p <dir>`, which is GNU- only. macOS bsd-mktemp accepts the template positionally, not via -p. macOS CI passed (BSD mktemp likely ignored the unrecognized -p and the test still got a file), but the form was non-portable. Switch to the full-path template form: `mktemp <dir>/<template>`, which works on both. 2. webroot_swagger_ldap.bats's cwo assertion matched the sed SEARCH pattern (which is identical for cwb and cwo: both contain `htdocs.*@` since `@` is non-`/`), defeating the test's purpose of distinguishing the openemr direction from the blank direction. Anchor to the sed REPLACEMENT segment instead — cwo replaces with `...htdocs@g`, cwb with `...htdocs/openemr@g`. Now a regression that swaps the directions would actually fail the test. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Continuation of #828 + #829's non-worktree coverage. 28 new tests across 3 files plus 4 small script fixes for the same set-u bug pattern uncovered in #829 (the
evfix).What's new (3 files, 28 tests)
snapshot_capsule_commands.batsbs/rs→ `/root/devtools backupwebroot_swagger_ldap.batscwb/cworun an in-container sed against apache'sopenemr.confthendocker restart <id>;swtm <name>passes through to/root/devtools set-swagger-to-multisite;el/dldare plain devtools passthroughs.prek_dispatch.batsdocker exec -w /var/www/localhost/htdocs/openemr -i <id> sh -c <inline> sh <args>). Args pass-through forrun/install-hooks/--version. Inline script contains the actionlint-docker → actionlint-system substitution + the `run4 more set-u fixes (same pattern as the ev fix in #829)
creat_a_backup_snapshot/restore_from_a_snapshot/copy_capsule_from_docker_to_host/copy_capsule_from_host_to_dockerall hadlocal FOO="$1"(or$2) BEFORE their$# != Ncheck. Underset -uthat crashes with "unbound variable" when called with no args instead of showing the documented help. All four reorder the check ahead of thelocalassignments. Pinned by dedicated regression tests.Test plan
shellcheck utilities/openemr-cmd/openemr-cmdclean🤖 Generated with Claude Code
Summary by CodeRabbit
set -u“unbound variable” crashes.prekdispatch, snapshot/capsule command CLI contracts, webroot switching, Swagger-to-multisite, and LDAP enable/disable.openemr-cmdversion to1.0.47.