Skip to content

refactor(platform): own pseudo-terminals behind the host boundary - #2113

Merged
zackees merged 1 commit into
mainfrom
agent/pty-capability
Nov 20, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/pty-capability

Conversation

@zackees

@zackees zackees commented Nov 20, 2026

Copy link
Copy Markdown
Member

Continues #1315 (phase 9/9): the next capability group off the
transitional ledger is the daemon's WebSocket serial handler tests —
15 of the 40 remaining occurrences were libc::openpty/ttyname_r/poll/read
plus five #[cfg(target_os = "linux")] gates inside
crates/fbuild-daemon/src/handlers/websockets_tests.rs.

What changed

platform::pty now owns the mechanic, with the native call in the concrete
per-OS tree:

neutral API Linux Windows / macOS
PtyPair::open() openpty + ttyname_r Err(Unsupported)
slave_name() /dev/pts/N unreachable (pair is unconstructible)
wait_for_master_input(timeout) poll(POLLIN) unreachable
read_master_exact(&mut [u8]) read loop, EINTR retry unreachable
is_supported() true false

Holding the pair keeps the terminal live; dropping it closes both directions,
which is exactly what serial_ws_preemption_reconnects_to_renumbered_port needs
in order to make the original port disappear.

The four handler tests ask is_supported() instead of selecting a host, so the
daemon carries no cfg(target_os …) and no libc here. The daemon's libc
dev-dependency is removed with its last user.

Counts (a migration, not a re-baseline)

  • ci/platform_boundary_ledger.tsv: 40 → 24 rows (15 websockets + the
    daemon Cargo.toml libc dependency row).
  • dylints/enforce_platform_boundary/src/baseline.txt: 39 → 24.
  • ci/platform_boundary_research.tsv regenerated (--write); --check passes.
  • ci/test_enforce_platform_boundary.py explicit row count 40 → 24.

Verification

  • soldr cargo test -p fbuild-daemon --lib serial_ws — 4 passed / 0 failed.
  • Red proof (wiring, not just the helper): making the Linux capability name
    /dev/null instead of the real slave fails
    serial_ws_replies_follow_request_order (panic at the attach assertion);
    restored, the four are green again. So the tests really drive the new path.
  • soldr cargo test -p fbuild-core --lib — 452 passed / 0 failed / 2 ignored.
  • soldr cargo test -p fbuild-daemon --lib — 332 passed / 0 failed / 3 ignored.
  • soldr cargo clippy -p fbuild-core -p fbuild-daemon --all-targets --no-deps -- -D warnings — exit 0.
  • soldr cargo fmt --all -- --check — exit 0.
  • uv run --no-project python ci/enforce_platform_boundary.py --print-totals — rows=24; dylint_rows=24, exit 0.
  • uv run --no-project python ci/platform_boundary_research.py --check — exit 0.
  • uv run --no-project --with pyyaml python -m unittest ci.test_enforce_platform_boundary ci.test_platform_boundary_research — 30 tests, OK.
  • Gate red proof: re-adding #[cfg(unix)] to the test module makes the enforcer
    report new occurrence … #[cfg(unix)] and exit 1.

Not in this PR

The remaining 24 rows (fbuild-paths/executable_hash.rs 7, esp_qemu.rs 6,
esp_qemu_runtime.rs 3, emulator/tests_process 2, platformio_package_resolution 2,
and the current_exe/qemu singletons) are the next units, one per run. No
zeroing of the baseline (that needs phase-8's toolchain/emulator group) and no
three-host audit table (closing pass) here.

#1315 stays open.

The daemon's WebSocket serial handler tests drove the production code with
`libc::openpty`/`ttyname_r`/`poll`/`read` directly, and each of the four
Linux-only tests carried its own `#[cfg(target_os = "linux")]`. That is
fifteen baselined host occurrences in test code, and no other crate could
reuse the terminal.

`platform::pty` now owns the mechanic: `PtyPair::open` allocates the pair
inside the concrete per-OS tree, `slave_name` reports the device path fbuild
is given as an attached port, `wait_for_master_input` polls the master side,
and `read_master_exact` drains it. Holding the pair keeps the terminal live
and dropping it closes both directions, which is how the deploy-preemption
tests make a port disappear.

Linux implements it against `openpty`; Windows and macOS report
`is_supported() == false` and `open()` returns `Unsupported` (a ConPTY pipe is
not a serial device path, and macOS allocates PTYs through a path this repo
has not verified), so the tests ask the facade instead of selecting a host.
The daemon's `libc` dev-dependency is gone with its last user.

Ledger 40 -> 24 occurrences, Dylint baseline 39 -> 24; the research TSV is
regenerated and `--check` passes.

#1315
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@zackees
zackees added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit fc2231a Nov 20, 2026
32 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 21, 2026
@zackees
zackees deleted the agent/pty-capability branch November 24, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant