ifc_lite_processing/
pipeline_diagnostics_report.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! Extensible wire report preserving the original constructible Rust struct.
6use super::PipelineDiagnostics;
7use crate::types::response::ProcessingStats;
8
9/// Pipeline diagnostics report used by `getPipelineDiagnostics`.
10/// `PipelineDiagnostics` remains constructible for existing Rust callers.
11/// Construct reports via `Default` or `from_processing_stats`.
12#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
13#[serde(rename_all = "camelCase")]
14#[non_exhaustive]
15pub struct PipelineDiagnosticsReport {
16    #[serde(flatten)]
17    pub pipeline: PipelineDiagnostics,
18    /// Attempted elements whose own decode or geometry read refused input.
19    #[serde(default)]
20    pub refused_input_elements: u64,
21    /// Distinct records refused in prepass or batch resolution on this worker.
22    #[serde(default)]
23    pub refused_prepass_records: u64,
24    /// F2 (#8341): distinct type records whose planned type geometry was
25    /// omitted because the full decoder rejects them (plain decode failures,
26    /// never in the two refusal counters). Browser: the prepass on this
27    /// worker. Native: `ProcessingStats` cannot carry it, so
28    /// `from_processing_stats` leaves 0; set it from
29    /// `ProcessingSink::on_omitted_type_records`.
30    #[serde(default)]
31    pub omitted_type_records: u64,
32}
33
34impl PipelineDiagnosticsReport {
35    pub fn from_processing_stats(stats: &ProcessingStats, element_count: u64) -> Self {
36        Self {
37            pipeline: PipelineDiagnostics::from_processing_stats(stats, element_count),
38            refused_input_elements: stats.refused_input_elements,
39            refused_prepass_records: stats.refused_prepass_records,
40            omitted_type_records: 0,
41        }
42    }
43}
44
45impl std::ops::Deref for PipelineDiagnosticsReport {
46    type Target = PipelineDiagnostics;
47    fn deref(&self) -> &Self::Target {
48        &self.pipeline
49    }
50}
51
52impl std::ops::DerefMut for PipelineDiagnosticsReport {
53    fn deref_mut(&mut self) -> &mut Self::Target {
54        &mut self.pipeline
55    }
56}
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn c4_10a_report_projects_native_refusals_in_the_current_schema_7782() {
64        let stats = ProcessingStats {
65            refused_input_elements: 2,
66            refused_prepass_records: 1,
67            ..Default::default()
68        };
69        let report = PipelineDiagnosticsReport::from_processing_stats(&stats, 3);
70        let json = serde_json::to_value(&report).unwrap();
71        assert_eq!(json["schemaVersion"], 2);
72        assert_eq!(json["refusedInputElements"], 2);
73        assert_eq!(json["refusedPrepassRecords"], 1);
74        assert_eq!(json["omittedTypeRecords"], 0, "F2 #8341: additive v1 key");
75        assert_eq!(json["elementCount"], 3);
76        assert_eq!(PipelineDiagnostics::default().schema_version, 2);
77    }
78}