Commit 82bf49f
authored
fix(openemr-cmd): pre-create volume mount-point dirs + loosen remove probe (#838)
## Summary
Two complementary fixes for the bug surfaced in #836's multi-3 e2e job
("ccdaservice/packages/oe-cqm-service/node_modules is not writable by
you"). Defense in depth against the same root cause.
### (1) Pre-create volume mount-point dirs
New helper `wt_precreate_volume_mountpoints` parses each env's
`docker-compose.yml` for volume mounts targeting paths under
`/var/www/localhost/htdocs/openemr/` and pre-creates the host-side dirs
as the current user before docker first attaches the volumes.
**Without this:** docker creates missing mount-point dirs on the host as
`root:root 0755`. After `compose down --volumes`, those empty root-owned
dirs reappear on the host and trip the writability probe on the next
`worktree remove`.
**With this:** docker sees the dirs already exist (owned by host user)
and just attaches the volume — host ownership preserved across the
volume's lifetime.
Called from both `cmd_worktree_add` and `cmd_worktree_regen` so both
fresh and env-switched worktrees are covered. Idempotent (mkdir -p is
safe on existing dirs, including the ones already checked into the repo
like `public/assets`, `sites`).
### (2) Loosen the writability probe
`cmd_worktree_remove`'s probe now accepts the case where a non-writable
dir is **empty** AND its parent is writable — because `rm` only needs
write+execute on the PARENT to rmdir an empty child, not write on the
child itself.
Catches any drift where pre-create misses a mount point (e.g.,
openemr/openemr adds a new volume and the regex doesn't update).
Non-empty non-writable dirs still fail the probe since rm there would
genuinely fail mid-walk.
### Coverage matrix
| Ownership case | Handler |
|---|---|
| Container-written files in bind mount (apache uid) | `#833` auto-chown
via `docker exec` |
| Empty docker-daemon-created mount-point dirs (root) | Pre-create
(option 1) |
| Pre-create drift / future new volumes | Probe loosening (option 2) |
| Non-empty unwritable dirs | Probe still fails (correct — rm would too)
|
The remaining apache-uid mismatch (apache inside container chowns the
bind mount to uid=1000 on hosts where uid != 1000) is orthogonal and
tracked separately as the HOST_UID-passthrough work.
### CI workaround removed
The "Pre-remove host-side chown" step in `worktree-multi-concurrent-e2e`
(added in #836 commit `cf99562`) is no longer needed. This PR removes
that step from the workflow file as part of the fix — proving the change
works end-to-end in CI.
## Test plan
- [ ] New bats file `tests/bats/openemr-cmd/mountpoint_precreate.bats`
exercises 5 precreate cases (creates expected dirs, skips out-of-webroot
mounts, skips the bind mount itself, runs from regen path, idempotent) +
2 probe-loosening cases (empty-removable passes, non-empty fails)
- [ ] OC_SCRIPT_FUNCS_END bumped 1786 → 1861 to track the new function's
landing position
- [ ] CI's multi-3 e2e job passes without the sudo-chown workaround that
was just removed
- [ ] Other e2e jobs (lifecycle, prek, functional, nonworktree) still
pass — pre-create is additive, doesn't change existing behavior
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Enhanced worktree setup to pre-create named-volume webroot mount-point
directories from compose targets, and to repeat the same behavior during
`worktree regen`.
* **Bug Fixes**
* Updated worktree removal to allow removing empty, non-writable
directories when the parent is writable; non-empty non-writable
directories still block removal.
* **Tests**
* Added BATS coverage for pre-create behavior (idempotent regen,
symlink-safe traversal, webroot-only creation, and correct handling of
bind mounts) and the adjusted removal permission checks.
* **CI**
* Streamlined teardown by removing a prior host-side ownership
workaround and relying on existing auto-ownership behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent e4a1e46 commit 82bf49f
4 files changed
Lines changed: 346 additions & 34 deletions
File tree
- .github/workflows
- tests/bats/openemr-cmd
- utilities/openemr-cmd
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
670 | 670 | | |
671 | 671 | | |
672 | 672 | | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | 673 | | |
702 | 674 | | |
703 | 675 | | |
704 | 676 | | |
705 | 677 | | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
711 | 686 | | |
712 | 687 | | |
713 | 688 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
0 commit comments