Text chat 49: fluxer-capture audio target listing, property rules, one PipeWire initialiser (#339) #345

Manually merged
charles merged 1 commit from textchat-49-capture-audio-targets into textchat 2026-11-12 20:38:21 +00:00
Owner

What this builds (Text chat 49, audio spec §3.3, #225.1/.6/.7)

  • audio::AudioTarget { props: BTreeMap<String, String> } and AUDIO_TARGET_FIELDS (the 14 keys of LinuxAudioCapture.ts:43-58, same order).
  • StreamAudioCapturer::list_targets() with a default body returning CaptureError::Unsupported("no audio source listing") (so Unsupported and WASAPI need nothing).
  • AppMatch::Props(BTreeMap) and AudioRule.exclude: Vec<BTreeMap> (default empty). RoutingRule::from_audio_rule: Props become include_when minus fluxer.display.* keys (a display-only pattern is ignored, so "specific" with nothing routable still falls back to the system rule); exclude entries become never_when with the same stripping. fluxer.target.objects keeps working through matches_pattern. WASAPI ignores both.
  • routing::Graph::targets(&identity, own_sink): routable nodes (is_routable_media_class, moved to routing and made pub) of enriched_nodes, minus identity.matches, the node named own_sink and any fluxer-native-stream-audio-* node, projected to the 14 fields, sorted by object.serial (numerically, serial-less last) then node.name.
  • PipeWireAudioCapturer::list_targets: snapshot thread + Graph::targets, at most READY_TIMEOUT (now pub); the running session's sink name is kept in Session so it is excluded by name too.
  • #225.6: snapshot_graph arms a loop timer for READY_TIMEOUT that quits the main loop, so the fluxer-pipewire-list thread always ends; a snapshot that did not complete is None. list_applications keeps its signature over the same snapshot.
  • #225.7: #[cfg(target_os = "linux")] pub fn initialize_pipewire() -> bool in desktop/rtc.rs (webrtc's InitializePipeWire then pw_init), re-exported as fluxer_capture::initialize_pipewire, the only declaration of _ZN6webrtc18InitializePipeWireEv; pipewire_audio::init_pipewire calls it.
  • Fake: FakeCaptureControl::set_audio_targets, list_targets returns them; default Firefox (pid 4242), mpv (pid 4343) and an Audio/Sink "Speakers".
  • README updated.

Tests

  • Unit (routing.rs): props_match_is_an_include_pattern_without_display_keys, display_only_props_match_is_ignored, exclude_patterns_become_never_when, target_objects_pattern_routes_streams_to_that_sink, targets_are_routable_nodes_minus_self_and_own_sink, targets_are_projected_to_the_fourteen_fields.
  • tests/fake.rs: default_list_targets_is_unsupported, fake_lists_its_targets_and_records_props_rules, audio_rule_default_has_no_exclude.
  • Real (FLUXER_CAPTURE_TESTS=1, tests/pipewire_real.rs): list_targets_sees_a_playing_tone_and_not_itself, list_targets_thread_ends_within_timeout. Ran on this machine (CachyOS, Wayland desktop, PipeWire with pw-play) with FLUXER_CAPTURE_TESTS=1 cargo test -p fluxer-capture --test pipewire_real -- --test-threads 1: all 6 pass, including the existing ones. Not part of CI.
  • FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green locally.

Deviations

  • apps/fluxer/src/capture_rt.rs: one line, exclude: Vec::new() in the capture::AudioRule literal so the app compiles with the new field. The real conversion of Props/exclude is Text chat 52's.
  • pipewire_audio::READY_TIMEOUT is now pub (the real timeout test uses it); routing::is_routable_media_class and routing::OWN_SINK_PREFIX are now pub.
  • list_targets on PipeWire answers Backend (not an empty list) when the snapshot fails or is late, so the app can answer AudioTargets(None).

Closes #339

🤖 Generated with Claude Code

## What this builds (Text chat 49, audio spec §3.3, #225.1/.6/.7) - `audio::AudioTarget { props: BTreeMap<String, String> }` and `AUDIO_TARGET_FIELDS` (the 14 keys of `LinuxAudioCapture.ts:43-58`, same order). - `StreamAudioCapturer::list_targets()` with a default body returning `CaptureError::Unsupported("no audio source listing")` (so `Unsupported` and WASAPI need nothing). - `AppMatch::Props(BTreeMap)` and `AudioRule.exclude: Vec<BTreeMap>` (default empty). `RoutingRule::from_audio_rule`: `Props` become `include_when` minus `fluxer.display.*` keys (a display-only pattern is ignored, so "specific" with nothing routable still falls back to the system rule); `exclude` entries become `never_when` with the same stripping. `fluxer.target.objects` keeps working through `matches_pattern`. WASAPI ignores both. - `routing::Graph::targets(&identity, own_sink)`: routable nodes (`is_routable_media_class`, moved to `routing` and made pub) of `enriched_nodes`, minus `identity.matches`, the node named `own_sink` and any `fluxer-native-stream-audio-*` node, projected to the 14 fields, sorted by `object.serial` (numerically, serial-less last) then `node.name`. - `PipeWireAudioCapturer::list_targets`: snapshot thread + `Graph::targets`, at most `READY_TIMEOUT` (now `pub`); the running session's sink name is kept in `Session` so it is excluded by name too. - #225.6: `snapshot_graph` arms a loop timer for `READY_TIMEOUT` that quits the main loop, so the `fluxer-pipewire-list` thread always ends; a snapshot that did not complete is `None`. `list_applications` keeps its signature over the same snapshot. - #225.7: `#[cfg(target_os = "linux")] pub fn initialize_pipewire() -> bool` in `desktop/rtc.rs` (webrtc's `InitializePipeWire` then `pw_init`), re-exported as `fluxer_capture::initialize_pipewire`, the only declaration of `_ZN6webrtc18InitializePipeWireEv`; `pipewire_audio::init_pipewire` calls it. - Fake: `FakeCaptureControl::set_audio_targets`, `list_targets` returns them; default Firefox (pid 4242), mpv (pid 4343) and an `Audio/Sink` "Speakers". - README updated. ## Tests - Unit (`routing.rs`): `props_match_is_an_include_pattern_without_display_keys`, `display_only_props_match_is_ignored`, `exclude_patterns_become_never_when`, `target_objects_pattern_routes_streams_to_that_sink`, `targets_are_routable_nodes_minus_self_and_own_sink`, `targets_are_projected_to_the_fourteen_fields`. - `tests/fake.rs`: `default_list_targets_is_unsupported`, `fake_lists_its_targets_and_records_props_rules`, `audio_rule_default_has_no_exclude`. - Real (`FLUXER_CAPTURE_TESTS=1`, `tests/pipewire_real.rs`): `list_targets_sees_a_playing_tone_and_not_itself`, `list_targets_thread_ends_within_timeout`. **Ran on this machine** (CachyOS, Wayland desktop, PipeWire with `pw-play`) with `FLUXER_CAPTURE_TESTS=1 cargo test -p fluxer-capture --test pipewire_real -- --test-threads 1`: all 6 pass, including the existing ones. Not part of CI. - `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green locally. ## Deviations - `apps/fluxer/src/capture_rt.rs`: one line, `exclude: Vec::new()` in the `capture::AudioRule` literal so the app compiles with the new field. The real conversion of `Props`/`exclude` is Text chat 52's. - `pipewire_audio::READY_TIMEOUT` is now `pub` (the real timeout test uses it); `routing::is_routable_media_class` and `routing::OWN_SINK_PREFIX` are now `pub`. - `list_targets` on PipeWire answers `Backend` (not an empty list) when the snapshot fails or is late, so the app can answer `AudioTargets(None)`. Closes #339 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Refs #339

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Independent review: Text chat 49 (capture audio targets)

Scope: git diff 9fcc13d..origin/textchat-49-capture-audio-targets (one commit, df0ec50).

Plan tests (step 1): all 11 named tests exist and assert what the plan asks. Unit tests in routing.rs: props include without display keys, display-only props ignored (rule equals the System rule), exclude goes to never_when and wins over an include, fluxer.target.objects matched against target.object / node.target by serial and by name, targets minus self and own sink, projection to the 14 fields. Tests in tests/fake.rs: default list_targets is Unsupported, the fake inventory and rule recording, AudioRule::default().exclude is empty. Real tests in tests/pipewire_real.rs, gated on FLUXER_CAPTURE_TESTS. The fake's default inventory is Firefox pid 4242, mpv pid 4343 and an Audio/Sink "Speakers", as specified.

Interfaces: match the plan exactly. AudioTarget { props }, AUDIO_TARGET_FIELDS: [&str; 14] (checked key by key and in order against fluxer_desktop/src/main/LinuxAudioCapture.ts:43-58), the list_targets default body with the message "no audio source listing", AppMatch::Props, AudioRule.exclude (empty by default), Graph::targets(&SelfIdentity, Option<&str>), FakeCaptureControl::set_audio_targets, and initialize_pipewire() (Linux only) re-exported at the crate root. That function is the only declaration of _ZN6webrtc18InitializePipeWireEv in the workspace, and pipewire_audio::init_pipewire delegates to it. The WASAPI match is extended only for the new variant. The one-line exclude: Vec::new() in apps/fluxer/src/capture_rt.rs is needed to compile and is acceptable until Task 52 converts the rule.

Invariants: this change touches no fluxer-core, fluxer-ui or fluxer-emoji code, adds no dependency and no fixture, and contains no secrets or paths. The listing fails with Backend errors instead of panicking. #225.6: snapshot_graph arms a READY_TIMEOUT loop timer that quits the main loop. The done flag correctly tells a timer quit apart from a completed round trip (a late answer returns None, which becomes Backend), so the fluxer-pipewire-list thread always ends.

Sort key (implementer asked): the key is (numeric serial, with a missing or non-numeric serial as u64::MAX; then the raw serial string; then node.name). This sorts numerically as the plan intends and puts serial-less nodes last, ordered by name. The test covers this.

Review Focus: none of items 1-7 belongs to this task.

Findings

  • minor: crates/fluxer-capture/README.md now has two desktop rows in the module table (lines 14 and 17). The new row should be merged into the existing one.
  • minor: list_targets_thread_ends_within_timeout only exercises the path where the daemon answers. The timer-quit path (#225.6) is not tested directly. A test with an unresponsive remote would be hard to build, so this is a note, not a request.
  • minor: on Windows, an Applications rule that contains only Props returns Unsupported ("picks an application by its process id") instead of being ignored as audio spec §3.3 says. This is the same as today's handling of Name/Binary, and the core should not send Props on Windows (Task 50/52 should keep it that way).

Local CI: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci in a fresh review worktree finished with "all steps passed" (exit 0). I did not rerun the PipeWire real tests.

Verdict: approve. There are no blocking findings.

## Independent review: Text chat 49 (capture audio targets) Scope: `git diff 9fcc13d..origin/textchat-49-capture-audio-targets` (one commit, df0ec50). **Plan tests (step 1):** all 11 named tests exist and assert what the plan asks. Unit tests in `routing.rs`: props include without display keys, display-only props ignored (rule equals the System rule), exclude goes to `never_when` and wins over an include, `fluxer.target.objects` matched against `target.object` / `node.target` by serial and by name, targets minus self and own sink, projection to the 14 fields. Tests in `tests/fake.rs`: default `list_targets` is Unsupported, the fake inventory and rule recording, `AudioRule::default().exclude` is empty. Real tests in `tests/pipewire_real.rs`, gated on `FLUXER_CAPTURE_TESTS`. The fake's default inventory is Firefox pid 4242, mpv pid 4343 and an `Audio/Sink` "Speakers", as specified. **Interfaces:** match the plan exactly. `AudioTarget { props }`, `AUDIO_TARGET_FIELDS: [&str; 14]` (checked key by key and in order against `fluxer_desktop/src/main/LinuxAudioCapture.ts:43-58`), the `list_targets` default body with the message `"no audio source listing"`, `AppMatch::Props`, `AudioRule.exclude` (empty by default), `Graph::targets(&SelfIdentity, Option<&str>)`, `FakeCaptureControl::set_audio_targets`, and `initialize_pipewire()` (Linux only) re-exported at the crate root. That function is the only declaration of `_ZN6webrtc18InitializePipeWireEv` in the workspace, and `pipewire_audio::init_pipewire` delegates to it. The WASAPI match is extended only for the new variant. The one-line `exclude: Vec::new()` in `apps/fluxer/src/capture_rt.rs` is needed to compile and is acceptable until Task 52 converts the rule. **Invariants:** this change touches no fluxer-core, fluxer-ui or fluxer-emoji code, adds no dependency and no fixture, and contains no secrets or paths. The listing fails with `Backend` errors instead of panicking. #225.6: `snapshot_graph` arms a `READY_TIMEOUT` loop timer that quits the main loop. The `done` flag correctly tells a timer quit apart from a completed round trip (a late answer returns `None`, which becomes `Backend`), so the `fluxer-pipewire-list` thread always ends. **Sort key (implementer asked):** the key is (numeric serial, with a missing or non-numeric serial as `u64::MAX`; then the raw serial string; then `node.name`). This sorts numerically as the plan intends and puts serial-less nodes last, ordered by name. The test covers this. **Review Focus:** none of items 1-7 belongs to this task. ### Findings - minor: `crates/fluxer-capture/README.md` now has two `desktop` rows in the module table (lines 14 and 17). The new row should be merged into the existing one. - minor: `list_targets_thread_ends_within_timeout` only exercises the path where the daemon answers. The timer-quit path (#225.6) is not tested directly. A test with an unresponsive remote would be hard to build, so this is a note, not a request. - minor: on Windows, an `Applications` rule that contains only `Props` returns `Unsupported` ("picks an application by its process id") instead of being ignored as audio spec §3.3 says. This is the same as today's handling of `Name`/`Binary`, and the core should not send `Props` on Windows (Task 50/52 should keep it that way). **Local CI:** `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` in a fresh review worktree finished with "all steps passed" (exit 0). I did not rerun the PipeWire real tests. **Verdict: approve. There are no blocking findings.**
charles manually merged commit 55e5d937ec into textchat 2026-11-12 20:38:21 +00:00
Sign in to join this conversation.
No description provided.