Files
Joseph Doherty fb40e4c20b
rust / build / test / clippy / fmt (push) Has been cancelled
[F34 partial] mxaccess-asb: fix collect_asbidata_payloads + add Active flag
Investigation via examples/asb-relay.rs middleman captured the full
S→C bytes of a working PublishResponse from the .NET probe against
MxDataProvider. Decoder fix verified by regression test against the
captured fixture; one further wire-format gap surfaced and is filed.

Closed in this commit:

1. collect_asbidata_payloads filtered out empty <ASBIData/> elements
   so positional payload[N] indexing collapsed when Status was
   empty-but-present. The wire form for PublishResponse is:
     <Status><ASBIData/></Status>          ← empty placeholder
     <Values><ASBIData>{bytes}</ASBIData></Values>
   Our decoder lost the positional info and read Values as Status,
   then panicked on the malformed parse. Fix: always push every
   <ASBIData> element (empty or not) so payloads[0]=Status and
   payloads[1]=Values stay aligned. New regression test
   tests/publish_capture.rs runs the full decode chain over the
   captured wire bytes (305-byte frame at
   tests/fixtures/publish-response-with-value.bin) and asserts
   values.len() == 1.

2. MinimalMonitoredItem.active: Option<bool> + new with_active()
   constructor. The .NET reference's MxAsbDataClient.AddMonitoredItems
   defaults to active: true (cs:441). Without <Active>true</Active>
   on the wire, MxDataProvider treats the subscription as inactive
   and Publish polls return empty Values. Both binary build and
   canonical XML emitters now conditionally emit <Active> when
   active.is_some(). Shared push_monitored_item_body helper
   eliminates the duplicate MonitoredItem encoder between
   AddMonitoredItems and DeleteMonitoredItems builders.

3. SampleInterval unit: clarified as **milliseconds** in
   MinimalMonitoredItem.sample_interval doc + the example
   (sample_interval_ticks → sample_interval_ms = 1000). Matches the
   .NET reference's `ulong sampleInterval = 1000` default.

Open: F34's deeper finding — `MonitoredItem`'s wire schema is
DataContract field-suffix names (`activeField`, `bufferedField`,
`itemField`, `sampleIntervalField`, etc., per the per-session NBFX
dictionary the .NET probe declares), NOT XmlSerializer property
names (`Active`, `Buffered`, `Item`, `SampleInterval`). Our binary
NBFX builder still uses the property names, so MxDataProvider
silently fails to register monitored items — successField=true with
a 0-length Status array. The fix needs a complete rebuild of
build_add_monitored_items_request_body and
build_delete_monitored_items_request_body to use the field-suffix
names plus emit the *Specified siblings (activeFieldSpecified,
idFieldSpecified, etc.) as their own elements. The HMAC canonical
XML side is unaffected (XmlSerializer naming is correct there;
verified byte-equal to .NET via the F28 fixtures). Detailed in
design/followups.md F34's "Open" section.

Live verification of the F34-partial bonus context:
  - Read still returns 99 end-to-end via canonical XML signing.
  - AddMonitoredItems still returns Status[0] = 0 items
    (server doesn't recognize our DataContract-misnamed payload).
  - Publish still returns 0 values (the F34-open consequence).
  - All other 13 canonical-XML signed ops succeed at the request
    level (no SOAP faults, no HMAC rejections).

Workspace: mxaccess-asb 95 → 96 (+1 capture-driven decoder test);
default-feature clippy clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 02:49:11 -04:00

66 lines
2.5 KiB
Rust

//! F34 — wire-byte trace of a captured `PublishResponse`.
//!
//! `tests/fixtures/publish-response-with-value.bin` is the verbatim
//! S→C bytes the .NET probe (`MxAsbClient.Probe --subscribe`) saw on
//! its first `Publish` poll against the local AVEVA install on
//! 2026-05-06, captured via `examples/asb-relay.rs` middleman with
//! `--via=net.tcp://127.0.0.1:8088/...`. The .NET probe extracted
//! `preview:99` from this exchange — the value bytes
//! `[63 00 00 00]` (= 99 in LE i32) are visible at file offset 0x110.
//!
//! Test goal: dump `decode_envelope` + `decode_publish_response`
//! output so we can see exactly where our value-extraction diverges
//! from .NET's (F34 hypotheses).
//!
//! Frame layout: 3-byte NMF SizedEnvelope header (`06 ae 02`,
//! varint length = 302) + 302-byte SOAP envelope.
#![allow(
clippy::unwrap_used,
clippy::expect_used,
clippy::indexing_slicing,
clippy::panic
)]
use mxaccess_asb::{decode_envelope, decode_publish_response};
use mxaccess_asb_nettcp::nbfx::DynamicDictionary;
#[test]
fn publish_response_capture_decoder_trace() {
let raw = std::fs::read(
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/publish-response-with-value.bin"),
)
.expect("read fixture");
assert_eq!(raw.len(), 305, "frame length sanity check");
// Strip 3-byte NMF SizedEnvelope header.
let envelope = &raw[3..];
assert_eq!(envelope.len(), 302);
let mut dict = DynamicDictionary::new();
let decoded = decode_envelope(envelope, &mut dict).expect("decode_envelope succeeds");
eprintln!("=== body tokens ({} total) ===", decoded.body_tokens.len());
for (i, tok) in decoded.body_tokens.iter().enumerate() {
eprintln!(" body[{i}]={tok:?}");
}
let response = decode_publish_response(&decoded.body_tokens)
.expect("decode_publish_response succeeds");
eprintln!("=== decoded PublishResponse ===");
eprintln!(" status_count: {}", response.status.len());
eprintln!(" values_count: {}", response.values.len());
eprintln!(" result_code: {:?}", response.result_code);
eprintln!(" success: {:?}", response.success);
// The .NET probe extracted 1 value with preview:99 from the same
// wire bytes. If our decoder reports 0 values, the test fails and
// the eprintln body-token dump above shows where the gap is.
assert_eq!(
response.values.len(),
1,
".NET sees 1 value (preview:99) from the same bytes; our decoder reads {}",
response.values.len(),
);
}