Skip to content

test: keep daemon status tests off a real biffd (PL-1871) - #709

Merged
jmf-pobox merged 4 commits into
mainfrom
fix/pl-1871-status-port-isolation
Dec 1, 2026
Merged

jmf-pobox merged 4 commits into
mainfrom
fix/pl-1871-status-port-isolation

Conversation

@jmf-pobox

Copy link
Copy Markdown
Contributor

Problem

On a machine running a real biffd on 127.0.0.1:8424, TestDaemonStatus::test_not_installed got exit 0 instead of 1, and test_installed_but_not_answering_exits_1 (record = port 1) still reported healthy.

Cause

Not a product bug. ServiceCommands.status probes the recorded port in the run directory first (so --port users get the right answer), then falls back to the unit's port (BIFFD_SPEC.health_port, 8424) because a recorded port can be stale after a crash. With no record, RunDir.read_port() returns DEFAULT_PORT (8424). The test home fixture only faked PortProbe, not these two paths, so both reached the real daemon.

Fix

The home fixture now points run_dir.DEFAULT_PORT and the unit's health_port at a port nothing listens on. New tests: a guard that the unrecorded default is not 8424, and one that a stale record falls back to the unit's port (against a live listener there), so the fallback stays covered. test_installed_and_running_reports_version_and_port is unchanged and still uses a real loopback listener. No source or CHANGELOG change; status behaviour is unchanged.

Evidence

Before (real biffd on 8424), pytest tests/test_daemon/test_service_cli.py -k TestDaemonStatus:

  • test_not_installed: assert (0, True) == (1, True)
  • test_installed_but_not_answering_exits_1: assert (0, False) == (1, True)
  • new guard: assert 8424 != 8424

After, real biffd still listening on 8424 (confirmed with lsof): tests/test_daemon/test_service_cli.py all pass (56); tests/test_daemon + tests/test_supervision pass. ruff, ruff format, mypy clean on the file.

@qodo-code-review

qodo-code-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

test: keep daemon status tests off a real biffd's port

🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Points the test home fixture's default port and unit health port at an unused loopback port.
• Adds a guard that the unrecorded default port is not 8424, and a stale-record fallback test.
• Test-only change; status behaviour and product source are unchanged.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 0 capabilities

  • No production behavior changes identified.
Behavioral complexity 🟢 Low 🧩 Assessed behavior

  • No production behavior changes identified.
Potential damage 🟢 Low 🩹 Assessed behavior

  • No production behavior changes identified.
Assessed commit 00eb2f5
Diagram

graph TD
  T["home fixture"] --> U["unused port"]
  U --> D["run_dir.DEFAULT_PORT"]
  U --> B["BIFFD_SPEC health_port"]
  D --> S["ServiceCommands.status"]
  B --> S
  S --> P["Probe port"]
Loading
High-Level Assessment

Patching the port constants per test is the narrowest fix: it keeps the production fallback logic intact and the existing real-loopback test still exercises the live path. Mocking ServiceCommands.status or the probe wholesale would hide the fallback behaviour the new stale-record test is meant to cover. Choosing a fresh ephemeral port per test avoids a fixed port that a developer's biffd could occupy.

Files changed (1) +41 / -2

Tests (1) +41 / -2
test_service_cli.pyIsolate daemon status tests from real biffd port 8424 +41/-2

Isolate daemon status tests from real biffd port 8424

• The 'home' fixture now patches run_dir.DEFAULT_PORT and the lifecycle BIFFD_SPEC health_port to an unused loopback port. Adds a '_unused_port' helper, a 'unit_port' listener fixture, and two tests: a guard that the unrecorded default is not 8424, and a stale-record fallback to the unit's port. Also updates one expected warning string to use run_dir.DEFAULT_PORT.

tests/test_daemon/test_service_cli.py

@qodo-code-review

qodo-code-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


View medium (1)
Remediation recommended
1. Guard test passes without checking the probed port ✓ Resolved Medium Strong Bug

Resolving commit: 0c7a1aa

Description
test_the_default_suite_cannot_reach_a_real_biffd only asserts that RunDir.default().read_port()
differs from the import-time DEFAULT_PORT (8424), so it checks one fixture patch and nothing about
the health probe. It would still pass if the biff.daemon.lifecycle.BIFFD_SPEC patch in home were
removed, and it does not cover the unit-port fallback that the PR description names as the other
leak path. The test name promises that no path in the default suite reaches a real biffd, which this
assertion does not establish.

Grey Divider

Context sources
✅ Compliance rules (platform): 42 rules
✅ Cross-repo context — repo relationships
✅ REVIEW.md
Review mode: Auto: 🚀 Fast: Test-only, localized fixture isolation with no production behavior changes.

Grey Divider

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo Fixer

✅ Committed (1) · ☑ Fixed (1)

Grey Divider

Commits pushed directly to this PR — no separate fix PR opened.

Process — 1 fixed
  • ☑ Fixed: Guard test passes without checking the probed port

@jmf-pobox
jmf-pobox merged commit 2402444 into main Dec 1, 2026
11 checks passed
@jmf-pobox
jmf-pobox deleted the fix/pl-1871-status-port-isolation branch December 1, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant