agent-desktop/.github/workflows/ci.yml
Lahfir ee2374e565 feat(ffi): build hygiene — pinned cbindgen, drift check, variant parity (Unit 12)
Closes R14, R19, R20, R23 from PR #22 review.

Build pipeline:
- crates/ffi/Cargo.toml: pin cbindgen = "= 0.27.0" exactly. No more
  silent formatting drift from patch-version bumps of cbindgen; any
  future bump is a deliberate PR that also commits the regenerated
  header.
- crates/ffi/build.rs: replace .expect()/.ok() swallowing with explicit
  panics on every failure path. Missing CARGO_MANIFEST_DIR or OUT_DIR
  now emits a cargo:warning rather than crashing rustc. cbindgen errors
  now panic loudly with the diagnostic; previously an .ok() on fs::copy
  silently emitted a stale header.

CI:
- .github/workflows/ci.yml: new "FFI cdylib build" step under the
  release-ffi profile and a "FFI header drift" step that runs
  `git diff --exit-code crates/ffi/include/agent_desktop.h` immediately
  after. Any uncommitted change to the generated header fails the build
  with a clear message telling the developer to run the local rebuild
  and commit.

Variant parity:
- crates/ffi/src/error.rs: compile-time assertion
  `const _: () = assert!(error_code_variant_count() ==
  ad_result_error_variant_count())` guards against core adding an
  ErrorCode variant without a matching AdResult entry (which would
  silently drop information at the FFI boundary). Uses stable const fn
  + explicit variant arrays, no nightly variant_count feature.

50 lib tests, 1 integration test — all passing. Clippy clean.
2026-04-16 03:58:30 -07:00

89 lines
2.6 KiB
YAML

name: CI
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
test:
name: Test
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
run: rustup show
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Cache build artifacts
uses: actions/cache@v4
with:
path: target/
key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/*.rs') }}
restore-keys: |
${{ runner.os }}-build-${{ hashFiles('**/Cargo.toml') }}-
${{ runner.os }}-build-
- name: Check dependency isolation
run: |
if cargo tree -p agent-desktop-core 2>/dev/null | grep -E 'agent-desktop-(macos|windows|linux)'; then
echo "FAIL: core crate depends on platform crates"
exit 1
fi
echo "OK: core crate has no platform dependencies"
- name: Clippy
run: cargo clippy --all-targets -- -D warnings
- name: Unit tests
run: cargo test --lib --workspace
- name: Build release binary
run: cargo build --release
- name: Check binary size
run: |
SIZE=$(stat -f%z target/release/agent-desktop)
LIMIT=$((15 * 1024 * 1024))
echo "Binary size: $(du -sh target/release/agent-desktop | cut -f1)"
if [ "$SIZE" -gt "$LIMIT" ]; then
echo "FAIL: binary exceeds 15MB limit (${SIZE} bytes)"
exit 1
fi
echo "OK: binary within 15MB limit"
- name: FFI cdylib build (release-ffi profile)
run: cargo build --profile release-ffi -p agent-desktop-ffi
- name: FFI header drift check
run: |
if ! git diff --exit-code crates/ffi/include/agent_desktop.h; then
echo "FAIL: crates/ffi/include/agent_desktop.h is out of date"
echo "Run 'cargo build -p agent-desktop-ffi' locally and commit the regenerated header."
exit 1
fi
echo "OK: FFI header is in sync with source"
fmt:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup component add rustfmt
- run: cargo fmt --all -- --check