Skip to content

Fix .env fallback semantics for binary services#64

Merged
munezaclovis merged 6 commits intomainfrom
fix/binary-service-fallbacks
Apr 20, 2026
Merged

Fix .env fallback semantics for binary services#64
munezaclovis merged 6 commits intomainfrom
fix/binary-service-fallbacks

Conversation

@munezaclovis
Copy link
Copy Markdown
Contributor

Summary

  • stop.go: pv service:stop (no args) no longer applies .env fallbacks to binary services it didn't actually stop. Previously rewrote e.g. MAIL_MAILER=smtp → log while mail was still supervised and listening.
  • remove.go + destroy.go: binary service:remove and service:destroy now apply .env fallbacks and call reg.UnbindService to clear ProjectServices.Mail/S3 flags on linked projects, matching Docker service:remove behavior.
  • destroy.go Docker path: fixes a pre-existing bug where Docker service:destroy unbinds projects but doesn't apply fallbacks first (unlike service:remove which does both).

Bugs fixed

Operation Was Now
pv service:stop (no args) Fallback applied to binary services that were never stopped Binary services skipped in fallback loop
pv service:remove mail No fallback, no unbind Fallback applied + project unbound
pv service:destroy mail No fallback, no unbind Fallback applied + project unbound
pv service:destroy mysql (Docker) Unbind but no fallback Fallback applied before unbind

Test plan

  • go build ./... / go vet ./... / go test ./... — 30 packages pass
  • 3 new tests: TestApplyFallbacksToLinkedProjects_Mail, TestStopAllFallbackLoop_SkipsBinaryServices, TestUnbindService_ClearsMailBinding
  • CI: existing E2E phases pass (no E2E changes in this PR)
  • Manual: pv service:stop with a linked project using mail — verify .env keeps MAIL_MAILER=smtp
  • Manual: pv service:destroy mail with a linked project — verify .env gets MAIL_MAILER=log

Two bugs: (1) pv service:stop (no args) applies .env fallbacks to
binary services it didn't actually stop; (2) pv service:remove/destroy
for binary services don't apply fallbacks even though the service is
permanently gone. Three surgical edits to fix both.
Three issues from the review agent:
1. Binary remove/destroy paths were missing reg.UnbindService — added.
2. Docker destroy doesn't apply fallbacks (spec incorrectly claimed it
   did) — added Edit 4 to fix the pre-existing Docker bug.
3. Tests didn't pin the actual command-path changes — added targeted
   tests for the stop-all skip loop and the mail fallback wiring.
Two tasks executing the revised design spec:
1. Three new tests (mail fallback, stop-all skip, unbind) + fix stop.go
   to skip binary services in the no-args fallback loop.
2. Add fallback + unbind to binary remove/destroy paths; fix Docker
   destroy to apply fallbacks before unbinding (pre-existing bug).

Two commits to land on the branch.
The no-args stop command skips binary services in the container-stop
loop (they're managed by the daemon) but then applied .env fallbacks
to ALL registered services, including binaries that were never stopped.
This rewrote e.g. MAIL_MAILER=smtp → log in linked projects' .env
while mail was still supervised and listening.

Fix: skip inst.Kind == "binary" entries in the fallback loop.

Also adds three new tests:
- mail fallback integration (pins FallbackMapping("mail") wiring)
- stop-all loop simulating the correct skip behavior
- unbind clears ProjectServices.Mail
Binary service:remove and service:destroy now apply .env fallbacks
(e.g. MAIL_MAILER=smtp → log) and call reg.UnbindService to clear
ProjectServices.Mail/S3 flags on linked projects, matching the
existing behavior of their Docker counterparts.

Also fixes a pre-existing Docker bug: service:destroy did not call
applyFallbacksToLinkedProjects before unbinding, unlike service:remove
which does both. Docker destroy now applies fallbacks too.
PR review flagged that TestStopAllFallbackLoop_SkipsBinaryServices
re-implemented the loop logic from stop.go inside the test, so
removing the production guard would not break any test.

Fix: extract the fallback loop into applyStopAllFallbacks(reg) in
hooks.go, call it from stop.go, and test the extracted function
directly. Now deleting the binary-skip guard causes the test to fail.
@munezaclovis munezaclovis force-pushed the fix/binary-service-fallbacks branch from c4249a7 to 3c14ce6 Compare April 17, 2026 06:03
@munezaclovis munezaclovis merged commit 9356dc3 into main Apr 20, 2026
1 check failed
@munezaclovis munezaclovis deleted the fix/binary-service-fallbacks branch April 20, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant