agent-desktop/crates
Lahfir 482fd7aff5 fix(ffi): store enum fields as raw i32 in public ABI structs (todo 001)
Closes P1 todo 001. Every enum-typed field that a foreign caller writes
through the C ABI was previously stored as a Rust #[repr(i32)] enum —
out-of-range bit patterns crossed the boundary before the enum_raw_i32
validator could catch them, invoking undefined behavior at the field
read. The validator was directionally correct but fired too late.

Switched to raw i32 storage on every externally supplied public ABI
struct:

- AdAction.kind
- AdScrollParams.direction
- AdMouseEvent.kind, .button
- AdWindowOp.kind
- AdTreeOptions.surface
- AdScreenshotTarget.kind
- AdKeyCombo.modifiers (was *const AdModifier, now *const i32)

Every conversion site now reads the raw i32 directly and calls
<Enum>::from_c(raw) — an invalid discriminant returns None, and the
FFI entrypoint surfaces AD_RESULT_ERR_INVALID_ARGS without ever
constructing an invalid enum value in Rust. Dropped the now-unused
enum_raw_i32 helper and its test; replaced with a direct round-trip
test that confirms <Enum> as i32 -> from_c -> Some(<Enum>) still
holds for valid values.

Updated unit-test AdAction / AdMouseEvent / AdScrollParams builders to
use <Enum> as i32 casts. The c_abi_harness fuzz test simplifies — it
no longer needs ptr::copy_nonoverlapping because the field is just i32.

63 FFI tests pass, clippy --all-targets clean, header regenerated.
2026-04-16 05:11:48 -07:00
..
core merge: resolve conflicts with origin/main 2026-04-16 04:43:36 -07:00
ffi fix(ffi): store enum fields as raw i32 in public ABI structs (todo 001) 2026-04-16 05:11:48 -07:00
linux feat: Phase 1 foundation — workspace scaffold, core engine, macOS adapter, 31 commands 2026-02-19 10:44:38 -08:00
macos merge: resolve conflicts with origin/main 2026-04-16 04:43:36 -07:00
windows feat: Phase 1 foundation — workspace scaffold, core engine, macOS adapter, 31 commands 2026-02-19 10:44:38 -08:00