From 00869f38e748ac382cf819aecfb266e1c8e618fb Mon Sep 17 00:00:00 2001 From: Prince Karikari Date: Wed, 28 Oct 2026 21:46:11 -0500 Subject: [PATCH 1/3] Issue #252 solved: build and test the Rust crates in CI Nothing in CI touched the Rust side. meson-build.yml builds the C++ plugin on Windows with its test step commented out, and super-linter lints YAML and clang-format. So relay, src/server and baton had no automated coverage at all, which is how main came to be failing two relay tests without anyone noticing (#251). Add a workflow that builds and tests all three crates on pull requests and on pushes to main, as a matrix so each crate reports separately, with fail-fast off so one failure does not hide the others. The relay needs wayland, x11, drm and fontconfig headers because of its iced dependency tree, installed only for that crate. No toolchain is named: rust-toolchain.toml at the repository root decides, once #243 lands. Cargo registry and target output are cached per crate, keyed on each Cargo.lock. --- .github/workflows/rust.yml | 83 ++++++++++++++++++++++++++++++++++++++ AGENTS.md | 2 +- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..9bbff48 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,83 @@ +--- +name: Rust + +# Builds and tests the Rust crates. The Meson workflow covers the C++ +# plugin only, so without this nothing checks the relay, the mock server +# or baton. + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: + +permissions: + contents: read + +jobs: + build-and-test: + name: ${{ matrix.crate }} + runs-on: ubuntu-latest + + strategy: + # Report every crate, rather than hiding the rest behind the + # first failure. + fail-fast: false + matrix: + crate: + - relay + - src/server + - xplane_plugin/subprojects/baton + + steps: + - uses: actions/checkout@v4 + + # The relay is an iced GUI, so its dependency tree pulls in + # wayland, x11 and drm crates that need these headers present to + # build. The other two crates are plain std and need none of it. + - name: Install GUI build dependencies + if: matrix.crate == 'relay' + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends -y \ + libwayland-dev \ + libxkbcommon-dev \ + libx11-dev \ + libxcursor-dev \ + libxi-dev \ + libxrandr-dev \ + libgl1-mesa-dev \ + libudev-dev \ + libfontconfig1-dev \ + pkg-config + + # rust-toolchain.toml at the repository root decides the version, + # so no toolchain is named here. + - name: Show toolchain + run: | + rustc --version + cargo --version + + - name: Cache cargo registry and build output + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + ${{ matrix.crate }}/target + key: >- + ${{ runner.os }}-cargo-${{ matrix.crate }}-${{ + hashFiles(format('{0}/Cargo.lock', matrix.crate)) }} + restore-keys: | + ${{ runner.os }}-cargo-${{ matrix.crate }}- + + - name: Build + working-directory: ${{ matrix.crate }} + run: cargo build --verbose + + - name: Test + working-directory: ${{ matrix.crate }} + run: cargo test --verbose diff --git a/AGENTS.md b/AGENTS.md index 45e5751..aec49c5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -20,7 +20,7 @@ Run from the repo root, in order, per component: - Baton: `cd xplane_plugin/subprojects/baton && cargo test` - Inference: `cd inference && uv sync`, then `uv run python -m pilot_inference..`. `uv run pytest` runs the tests in `inference/tests/`; the event classification scripts are mostly untested. -CI is in `.github/workflows/` (`meson-build.yml`, `super-linter.yml`, `release.yml`: a `v*` tag publishes the plugin and `relay.exe` to a GitHub Release, a manual run is a dry run). Run `meson setup` with the cross-file for your OS if not on native Windows (see README). +CI is in `.github/workflows/`: `meson-build.yml` builds the C++ plugin on Windows, `rust.yml` builds and tests the three Rust crates on Ubuntu, `super-linter.yml` lints, and `release.yml` publishes the plugin and `relay.exe` to a GitHub Release on a `v*` tag (a manual run is a dry run). Run `meson setup` with the cross-file for your OS if not on native Windows (see README). ## Gotchas From 36df1191f2a9d2f0c0aeb87e0de27ab6ea016192 Mon Sep 17 00:00:00 2001 From: Prince Karikari Date: Sun, 8 Nov 2026 21:29:46 -0600 Subject: [PATCH 2/3] Build and test with --locked SonarCloud's quality gate flagged githubactions:S8549, a MAJOR vulnerability on the build step: dependencies resolved without locking (CWE-494, CWE-829). One MAJOR on new code drops the security rating to C, and the gate requires A. relay/Cargo.toml pins iced and anyhow at "*", so an unlocked CI build can resolve a different dependency set than anyone tested locally. --locked builds the committed Cargo.lock instead, and fails loudly if a Cargo.toml change ever lands without its matching lockfile update. All three crates have Cargo.lock committed and pass with it: relay 23 tests, src/server 5, baton 0. --- .github/workflows/rust.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9bbff48..6203003 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -74,10 +74,16 @@ jobs: restore-keys: | ${{ runner.os }}-cargo-${{ matrix.crate }}- + # --locked builds the versions in Cargo.lock instead of re-resolving. + # relay/Cargo.toml pins iced and anyhow at "*", so without it CI can + # quietly test a different dependency set than anyone ran locally, and + # a build that passes today can break tomorrow with no commit to blame. + # It also fails loudly if a Cargo.toml change was committed without the + # matching lockfile update. - name: Build working-directory: ${{ matrix.crate }} - run: cargo build --verbose + run: cargo build --locked --verbose - name: Test working-directory: ${{ matrix.crate }} - run: cargo test --verbose + run: cargo test --locked --verbose From 4b871ce7e72ef3614f09b627075060d9ea48e046 Mon Sep 17 00:00:00 2001 From: Prince Karikari Date: Sun, 8 Nov 2026 21:44:16 -0600 Subject: [PATCH 3/3] Feed the stalled-mirror test until the drop, not a fixed burst The test went red on CI again after #251. The buffer bound in state.rs was right; reducing SAMPLES from 3000 to 500 alongside it was not. mirror_send try_sends into a 256-deep queue and drops when full, so a fixed burst does not determine how much reaches the writer thread - the race between the two threads does. A burst that loses it leaves the writer with well under a bufferful, no write blocks, MIRROR_WRITE_TIMEOUT never fires and the mirror is never dropped. Feeding in batches until the mirror is actually dropped removes the guess. The stalled reader never drains, so whatever the writer does get through accumulates across batches and the timeout is reached regardless of how any single batch races. Verified against the mechanism that failed: 40/40 runs pinned to one core, and 25/25 on one core against six competing CPU hogs. --- relay/src/update.rs | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/relay/src/update.rs b/relay/src/update.rs index 02fe298..555a512 100644 --- a/relay/src/update.rs +++ b/relay/src/update.rs @@ -827,11 +827,19 @@ mod tests { // feed to iMotions. #[test] fn a_python_process_that_stops_reading_is_dropped_not_waited_on() { - // The Python side never reads, so its pinned receive buffer fills and - // stays full: writes block, the 100ms timeout fires and the mirror is - // dropped. With the host's default buffers the whole run fits in the - // kernel, nothing blocks, and the timeout never fires at all. - const SAMPLES: usize = 500; + // The Python side never reads, so the buffers fill and stay full: + // writes block, the 100ms timeout fires and the mirror is dropped. + // With the host's default buffers the whole run fits in the kernel, + // nothing blocks, and the timeout never fires at all. + // + // Fed in batches until that happens rather than as one fixed burst. + // mirror_send drops into a 256-deep queue when it is full, so a burst + // does not decide how much reaches the writer thread -- the race + // between the two threads does, and a burst that loses it leaves the + // writer with far less than a bufferful and nothing ever blocks. The + // stalled reader never drains, so what the writer does get through + // accumulates across batches and the timeout is reached for certain. + const BATCH: usize = 200; let (imotions, imotions_addr) = listener_on_free_port(); let (python, python_addr) = stalling_listener_on_free_port(); @@ -862,15 +870,18 @@ mod tests { ); let started = std::time::Instant::now(); - for i in 0..SAMPLES { - send_sample(&mut state, &format!("{}", 1000 + i % 100)); - } + let mut samples = 0usize; + let was_dropped = wait_until(|| { + for i in 0..BATCH { + send_sample(&mut state, &format!("{}", 1000 + (samples + i) % 100)); + } + samples += BATCH; + let _ = update(&mut state, Message::Update); + !state.mirror_connected + }); assert!( - wait_until(|| { - let _ = update(&mut state, Message::Update); - !state.mirror_connected - }), - "a stalled reader was never dropped" + was_dropped, + "a stalled reader was never dropped after {samples} samples" ); let elapsed = started.elapsed();