wifi-densepose/v2/crates/wifi-densepose-bfld/tests
ruv 926c66f677 feat(adr-118/p4.1): BfldEvent privacy-gated output + JSON (102/102 GREEN)
Iter 13. Lands ADR-121 §2.1 (output event) + ADR-122 §2.1 (field-gating
policy). BfldEvent collapses the GateAction-driven sensing pipeline
into the canonical wire-format publishable on MQTT.

Added:
- serde (workspace, derive feature, optional) + serde_json (workspace, optional) deps
- New crate feature `serde-json` (default-on; requires `std`)
- src/event.rs (gated on `feature = "std"`):
  * BfldEvent struct with all sensing + identity-derived fields
  * with_privacy_gating(...) constructor that applies field-gating policy:
      class < Restricted (3): identity_risk_score + rf_signature_hash kept
      class >= Restricted (3): both nulled to None
  * apply_privacy_gating() — idempotent in-place masking
  * to_json() -> Result<String, serde_json::Error> (gated on serde-json)
  * Custom ser_privacy_class serializer emits lowercase names
    ("anonymous", "restricted", etc.) per the BFLD JSON spec
  * skip_serializing_if = "Option::is_none" on identity-derived fields so
    privacy-gated events are observationally indistinguishable from
    events that never had the field set
- pub use BfldEvent from lib.rs

tests/event_privacy_gating.rs (9 named tests, all green):
  anonymous_event_retains_identity_risk_and_hash
  restricted_event_strips_identity_fields (class 3 → None)
  apply_privacy_gating_is_idempotent
  event_type_is_always_bfld_update (parameterized over 3 classes)
  json::json_round_trip_emits_type_field_first_or_last_but_present
  json::anonymous_json_includes_identity_fields
  json::restricted_json_omits_identity_fields_entirely
    (asserts the JSON string does NOT contain identity_risk_score or
     rf_signature_hash, verifying skip_serializing_if works as intended)
  json::privacy_class_serializes_to_lowercase_name
  json::zone_id_none_is_omitted_from_json

ACs progressed:
- ADR-121 AC6 (identity_risk score absent at class 3) — structurally
  enforced by with_privacy_gating + skip_serializing_if combination.
- ADR-122 AC1 — JSON shape matches the HA-DISCO publishable event
  contract; identity fields can be reliably stripped by privacy_class.
- ADR-118 AC5 — privacy_mode = engaged maps to PrivacyClass::Restricted
  with no identity fields in the published event.

Test config:
- cargo test --no-default-features → 64 passed (unchanged; event cfg-out)
- cargo test                       → 102 passed (93 + 9)

Out of scope (next iter target):
- Emitter struct that wires GateAction + privacy class + sensing inputs
  into BfldEvent construction (ADR-118 §2.1 pipeline diagram).
- MQTT topic publisher (ADR-122 §2.2) — depends on a runtime (tokio).

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-24 15:27:49 -04:00
..
coherence_gate.rs feat(adr-118/p3.3): CoherenceGate hysteresis + 5s debounce — 85/85 GREEN 2026-05-24 15:07:40 -04:00
embedding_ring.rs feat(adr-118/p2.2): EmbeddingRing 64-entry FIFO buffer — 53/53 GREEN 2026-05-24 14:37:03 -04:00
event_privacy_gating.rs feat(adr-118/p4.1): BfldEvent privacy-gated output + JSON (102/102 GREEN) 2026-05-24 15:27:49 -04:00
frame_header_size.rs feat(adr-118/p1): scaffold wifi-densepose-bfld crate + frame header (3/3 tests GREEN) 2026-05-24 13:34:05 -04:00
frame_payload_integration.rs feat(adr-118/p1.6): BfldFrame <-> BfldPayload wire integration (39/39 GREEN) 2026-05-24 14:16:54 -04:00
frame_roundtrip.rs feat(adr-118/p1.4): BfldFrame (header + payload + CRC32) — 24/24 GREEN 2026-05-24 13:58:26 -04:00
header_roundtrip.rs feat(adr-118/p1.2): header encode/decode + 6 round-trip tests (9/9 GREEN) 2026-05-24 13:38:11 -04:00
identity_embedding.rs feat(adr-118/p2.1): IdentityEmbedding newtype + zeroizing Drop — 44/44 GREEN 2026-05-24 14:27:28 -04:00
identity_risk_score.rs feat(adr-118/p3.2): identity_risk score + GateAction enum — 72/72 GREEN 2026-05-24 14:57:08 -04:00
payload_sections.rs feat(adr-118/p1.5): payload section parser (BfldPayload) — 32/32 GREEN 2026-05-24 14:07:14 -04:00
privacy_gate_demote.rs feat(adr-118/p3.1): PrivacyGate::demote monotonic class transformer (60/60 GREEN) 2026-05-24 14:48:01 -04:00
sink_enforcement.rs feat(adr-118/p1.3): Sink marker traits + PrivacyClass::try_from (17/17 GREEN) 2026-05-24 13:43:05 -04:00
soul_match_oracle.rs feat(adr-118/p3.4): SoulMatchOracle + Recalibrate exemption (93/93 GREEN) 2026-05-24 15:17:24 -04:00