Skip to content

refactor: printer factory, MQTT/FTPS hardening, coverage to 86 - #119

Merged
DLANSAMA merged 2 commits into
mainfrom
refactor/printer-factory-hardening
Aug 14, 2026
Merged

refactor: printer factory, MQTT/FTPS hardening, coverage to 86#119
DLANSAMA merged 2 commits into
mainfrom
refactor/printer-factory-hardening

Conversation

@DLANSAMA

Copy link
Copy Markdown
Owner

Reviewed batch of changes (originally drafted with Grok). Full gate run passed locally: ruff check, ruff format --check, mypy (clean), bandit (exit 0), check_layers, all smokes, and 1499 passed at 91.0% coverage (floor now 86).

Architecture

  • RuntimeContext.printer() now goes through an injectable factory registered downward from bambu_cli.printer (set_printer_factory); context.py no longer imports printer.py. This closes the last check_layers ALLOWED edge — the allowlist is now empty. Every entrypoint routes through cli.py, which imports printer at module top, so the factory is always installed before any .printer() call. Guarded with a RuntimeError + tests.

Correctness / resources

  • mqtt_session: lock _pending_payload/_command_issued across the paho network thread; cached-complete-snapshot fast path when a pushall stays silent.
  • mqtt_tls: drop the global socket.setdefaulttimeout() mutation; bound the connect via client._connect_timeout (paho 2.x uses it in create_connection); configurable + validated MQTTS port.
  • mqtt_cmd / mqtt_print / mqtt_monitor: teardown in finally — fixes a socket leak on the connect-exception path.
  • ftps: close the socket if connect/login/prot_p fails.
  • snapshot / slice: drop unreachable safe_log_error(...)+abort(...) tails after emit_json_error (now typed NoReturn, already logs+raises). Continues refactor: commands raise; cli.main is the sole error emitter #117/fix: size_verified, leftover contracts, and extras on raised errors #118.

Tests / CI / docs

  • +40 targeted tests covering the above error paths; CI coverage floor 83 → 86 (measured 91.0% Linux, ~5pt headroom). test_docs_consistency gains a stronger drift guard (docs coverage % must be ≥ floor).
  • api.md gains a support matrix; SECURITY.md residuals marked accepted for 1.0; scoreboard refreshed.

Follow-up (not in this PR)

  • AGENTS.md coverage line still cites a historical "Linux 3.9" CI run — left for the upcoming full documentation pass.

Continues the boundary/error-model arc (#117/#118).

Architecture:
- RuntimeContext.printer() now uses an injectable factory registered
  downward from bambu_cli.printer (set_printer_factory); context.py no
  longer imports printer. Removes the last check_layers ALLOWED edge
  (context -> printer); ALLOWED is now empty.

Correctness / resources:
- mqtt_session: lock _pending_payload/_command_issued across the paho
  network thread; cached-complete-snapshot fast path on silent pushall.
- mqtt_tls: drop global socket.setdefaulttimeout mutation; bound connect
  via client._connect_timeout; configurable, validated MQTTS port.
- mqtt_cmd/mqtt_print/mqtt_monitor: teardown in finally (fixes leak on
  the connect-exception path).
- ftps: close the socket if connect/login/prot_p fails.
- snapshot/slice: drop unreachable safe_log_error+abort tails after
  emit_json_error (now typed NoReturn); it already logs and raises.

Tests / CI:
- +40 targeted tests for the above error paths; raise CI cov floor
  83 -> 86 (measured 91.0% Linux). Stronger docs-coverage drift guard.
- Docs: api.md support matrix; SECURITY.md residuals marked accepted
  for 1.0; scoreboard refreshed.
_file_permission_check returns None on win32 by design (POSIX mode bits
don't apply — see the Windows secret ACLs residual in SECURITY.md), so
the 0o644/0o600 assertions only hold off-Windows. Assert the None path
on win32 instead.
@DLANSAMA
DLANSAMA merged commit f1350b6 into main Aug 14, 2026
6 checks passed
@DLANSAMA
DLANSAMA deleted the refactor/printer-factory-hardening branch August 14, 2026 11:11
DLANSAMA added a commit that referenced this pull request Aug 14, 2026
Truth-sync only (grades and narrative untouched). Reconciles stale
snapshots against the measured post-#119 state:
- coverage: 89.1/89.2% -> 90.99% Linux / 90.68% Windows
- tests: 1419/1459 -> 1499 non-live (1 live deselected)
- statements: 8120 -> 8368
- Python: drop the stale "Linux 3.9" / py39 refs -> 3.10/3.12/3.14
- floor-history / ratchet-headroom margins recomputed for the 86 floor

quality-roadmap.md was internally contradictory (current scoreboard vs
stale header + floor-history + ratchet paragraphs); those now agree.
Historical dated records (the 5b08720 re-verification blockquote) are
preserved as-is and a current 2026-08-13 entry appended. docs-consistency
test passes.

Co-authored-by: DLANSAMA <258674612+DLANSAMA@users.noreply.github.com>
DLANSAMA added a commit that referenced this pull request Aug 14, 2026
Re-verified the 2026-07-31 post-audit residual table against current main
rather than trusting the audit snapshot. Four residuals it lists as open are
closed, and one the follow-up notes recorded as closed is not:

- S5 closed: utils.py:63-67 is now a shim delegating to jsonio; both spellings
  redact the audit's own repro identically. No weaker second implementation.
- A4 closed: mqtt_port is wired end to end (context -> printer -> mqtt_tls
  _mqtt_port -> client.connect). Doctor no longer reports a port it ignores.
- T1 closed: textual is pinned >=8.0,<9.0 (#115), not <2.0.
- A3/Q1/S1/B1/R1/R3 closed by #119, the camera opt-in work, and the TUI merge.
- Q4 NOT closed: #116 removed 81 setdefault stubs across 33 files but
  tests/bambu_test_base.py:26-29 still assigns MagicMock to sys.modules for
  paho at import time and never restores it, which is also order-dependent.
- P1, Q5, Q6, A1, A2, S3, R2, T2/WS4, W3.4 re-confirmed open with current
  file:line evidence; A1's target moved to bambu_cli.cliparse.

Plan headers carried numbers from before #119/#120 and read as live state.
Both gameplans now lead with measured current values (1499 non-live, 90.99%
Linux / 90.68% Windows over 8368 statements, floor 86, Python 3.10/3.12/3.14)
and keep the old figures marked as historical, including the a-plus W1 sizing
that was derived from the 89.4% baseline.

mutation-baseline.md claimed its per-module table reconciles to the 50.7%
headline. It does not: the seven rows are the whole only_mutate scope yet sum
to 2010 mutants against a headline 2091, leaving 81 unattributed (37 survived,
41 killed, 3 timeout). Also corrected the "residual survivors should be
cosmetic" prediction, which the same file already disproves at 21.8% with 269
survivors, and the stale "re-run mutmut on slicer/output.py" note, which was
already done on 2026-08-04.

tui-plan.md kept imperative branch instructions after its own "implemented"
banner; folded into the historical framing.

Also drops AI-vendor attribution from these two plan docs: the audience and
source lines, the "pasteable brief for a new <vendor> session" heading, and
the trailer rule, which now reads "AI/session attribution trailers" instead of
naming a product. References to the local-only agent notes filename are left
intact where removing the name would void the rule.

Docs only, no code changes. Gates: 1499 passed / 1 deselected, 91.0% total;
test_docs_consistency + test_docs_links 25 passed.
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