Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ mod tests {
keywords: None,
record_id: Some(record),
activity_id: None,
event_version: None,
named_data: named_data
.iter()
.map(|(name, value)| IntuneNamedValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ mod tests {
keywords: None,
record_id: Some(1),
activity_id: None,
event_version: None,
named_data: named_data
.iter()
.map(|(name, value)| IntuneNamedValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ mod tests {
keywords: None,
record_id: None,
activity_id: None,
event_version: None,
named_data: vec![
crate::intune::evidence::IntuneNamedValue {
name: "SettingUri".to_owned(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ mod tests {
keywords: None,
record_id: None,
activity_id: None,
event_version: None,
named_data: data
.iter()
.map(|(name, value)| IntuneNamedValue {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,118 @@
//! Windows Autopilot identity, profile, and OOBE evidence outside ESP.
//!
//! Owner: issue #362 of epic #356. Implementation pending.
//! Owner: issue #362 of epic #356.
//!
//! ESP remains a sibling reducer in `crate::esp` and may be correlated through explicit enrollment/session keys; it is not renamed into Autopilot.
//! # Where the boundary with ESP sits
//!
//! This is a reserved slot created by the parser-family skeleton so that issue
//! #362 can be implemented without editing any file shared with a sibling issue.
//! Add source classification, reduction, and findings submodules here, and
//! consume the shared contracts in [`crate::intune::evidence`].
//! Autopilot and the Enrollment Status Page are **sibling contracts**, not one
//! contract under two names. This module owns device registration and identity,
//! profile discovery, retrieval and application, OOBE mode and deployment
//! profile facts, diagnostics-page/export evidence, and the handoff into
//! enrollment and ESP. `crate::esp` continues to own app and policy progress and
//! blocking status *after* that handoff, and nothing here re-derives it.
//!
//! The only thing crossing the boundary is an explicit key. An
//! [`AutopilotEspSessionFact`] supplied by the ESP side binds to this analysis
//! when it shares an enrollment, correlation, activity, or device identifier;
//! overlapping timestamps alone can only ever produce
//! [`AutopilotEspLinkState::TimeOnlyCandidate`] at low confidence, and are
//! refused outright when the collection's timezone is missing or unrecognizable.
//!
//! # What stays native
//!
//! EVTX decoding, registry reads, diagnostics-export generation, and live OOBE
//! interaction are all outside this crate; see the wasm32 invariant in the crate
//! root. What crosses the boundary is a set of versioned, self-declaring
//! documents plus the shared
//! [`NormalizedWindowsEvent`](crate::intune::normalized::NormalizedWindowsEvent)
//! type. Nothing here performs I/O.
//!
//! # Shape
//!
//! Deliberately the same shape as `crate::esp`, so the two read side by side:
//!
//! 1. [`sources`] declares the input contract and detects document schemas;
//! 2. [`normalize`] classifies records against Microsoft's documented event
//! table, refusing to interpret anything outside it;
//! 3. [`reduce_autopilot_bundle`] folds observations into an immutable
//! [`AutopilotSnapshot`];
//! 4. [`derive_findings`] turns that snapshot into
//! [`IntuneFinding`](crate::intune::evidence::IntuneFinding)s, each citing
//! evidence or a coverage gap and each naming the next smallest artifact;
//! 5. [`redacted_export_projection`] makes a snapshot safe to share.
//!
//! ```
//! use cmtraceopen_parser::intune::enrollment::windows::autopilot::{
//! reduce_autopilot_bundle, AutopilotBundleInput, AutopilotCaptureMetadata,
//! AutopilotCaptureState, AutopilotOutcome, AutopilotSourceInput,
//! };
//!
//! let events = r#"{
//! "autopilotDocument": "autopilot.events",
//! "documentVersion": 1,
//! "events": [{
//! "context": {
//! "evidenceRef": { "evidenceId": "ap:0", "sourceArtifactId": "autopilot-channel" },
//! "provenance": {
//! "sourceKind": "eventLog", "sourceArtifactId": "autopilot-channel",
//! "filePath": null, "lineNumber": null, "recordNumber": 1,
//! "registry": null, "event": null
//! },
//! "sourceTimestamp": null,
//! "observedAtUtc": "2026-07-31T09:00:00Z",
//! "sensitivity": "public", "parseState": "parsed", "accessState": "available"
//! },
//! "channel": "Microsoft-Windows-ModernDeployment-Diagnostics-Provider/Autopilot",
//! "provider": "Microsoft-Windows-ModernDeployment-Diagnostics-Provider",
//! "eventId": 815,
//! "level": "error",
//! "task": null, "keywords": null, "recordId": 1, "activityId": null,
//! "namedData": [],
//! "message": "ZtdDeviceHasNoAssignedProfile - No profile assigned to the device."
//! }]
//! }"#;
Comment on lines +50 to +73

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Show the NormalizedWindowsEvent declaration with its serde attributes.
fd -a normalized.rs crates/cmtraceopen-parser/src | while IFS= read -r f; do
  echo "== $f =="
  rg -n -B 12 'pub struct NormalizedWindowsEvent' "$f"
  rg -n -A 20 'pub struct NormalizedWindowsEvent' "$f"
done

Repository: adamgell/cmtraceopen

Length of output: 1816


🏁 Script executed:

#!/bin/bash
set -eu

echo "== doctest references =="
rg -n -C 12 'autopilotDocument|NormalizedWindowsEvent|from_str|event_version|eventVersion' \
  crates/cmtraceopen-parser/src/intune/enrollment/windows/autopilot/mod.rs \
  crates/cmtraceopen-parser/src/intune/normalized.rs

echo "== normalized context definitions =="
rg -n -A 35 -B 8 'pub struct IntuneObservationContext|source_timestamp|observed_at_utc' \
  crates/cmtraceopen-parser/src/intune

echo "== parser dependency versions =="
rg -n -A 6 -B 2 'serde|serde_json' crates/cmtraceopen-parser/Cargo.toml Cargo.lock

Repository: adamgell/cmtraceopen

Length of output: 50379


🏁 Script executed:

#!/bin/bash
set -eu

sed -n '44,115p' crates/cmtraceopen-parser/src/intune/enrollment/windows/autopilot/mod.rs
printf '\n== serde declarations ==\n'
sed -n '44,66p' crates/cmtraceopen-parser/src/intune/normalized.rs

python3 - <<'PY'
from pathlib import Path
import re

doctest = Path("crates/cmtraceopen-parser/src/intune/enrollment/windows/autopilot/mod.rs").read_text()
struct = Path("crates/cmtraceopen-parser/src/intune/normalized.rs").read_text()

block = re.search(r'let events = r#"(.*?)"#;', doctest, re.S)
if not block:
    raise SystemExit("autopilot doctest JSON block not found")

json_body = block.group(1)
field = re.search(r'\bpub event_version:\s*Option<u32>', struct)
default = re.search(r'#\[serde\([^]]*\bdefault\b[^]]*\)\]', struct)
wire_field = '"eventVersion"'

print(f"event_version declaration present: {bool(field)}")
print(f"struct-level serde(default) present: {bool(default)}")
print(f'doctest contains {wire_field}: {wire_field in json_body}')
print("structural result: missing eventVersion with no serde default"
      if field and not default and wire_field not in json_body
      else "structural result: no omission detected")
PY

Repository: adamgell/cmtraceopen

Length of output: 4095


🏁 Script executed:

#!/bin/bash
set -eu

echo "== autopilot source models and deserialization =="
rg -n -C 8 'struct .*Document|events:|NormalizedWindowsEvent|serde_json::from_str|from_value' \
  crates/cmtraceopen-parser/src/intune/enrollment/windows/autopilot/{models.rs,sources.rs,normalize.rs,reducer.rs}

echo "== reducer entry and source absorption =="
rg -n -A 45 -B 12 'pub fn reduce_autopilot_bundle|content|detect_document|parse' \
  crates/cmtraceopen-parser/src/intune/enrollment/windows/autopilot/{reducer.rs,sources.rs}

Repository: adamgell/cmtraceopen

Length of output: 50377


Add #[serde(default)] to NormalizedWindowsEvent.event_version. AutopilotEventsDocument deserializes events directly into this type, so version 1 documents that omit eventVersion, including this doctest, currently fail.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/cmtraceopen-parser/src/intune/enrollment/windows/autopilot/mod.rs`
around lines 50 - 73, Add #[serde(default)] to the event_version field on
NormalizedWindowsEvent so AutopilotEventsDocument can deserialize version 1
events that omit eventVersion, including the shown doctest, while preserving
explicitly provided values.

//!
//! let snapshot = reduce_autopilot_bundle(&AutopilotBundleInput {
//! generated_at_utc: "2026-07-31T09:05:00Z".to_string(),
//! capture: AutopilotCaptureMetadata {
//! timezone: Some("UTC".to_string()),
//! ..AutopilotCaptureMetadata::default()
//! },
//! sources: vec![AutopilotSourceInput {
//! artifact_id: "autopilot-channel".to_string(),
//! family: "autopilotEvents".to_string(),
//! capture_state: AutopilotCaptureState::Captured,
//! original_basename: Some("autopilot-events.json".to_string()),
//! sanitized_source_path: None,
//! content: Some(events.to_string()),
//! ..AutopilotSourceInput::default()
//! }],
//! events: Vec::new(),
//! });
//!
//! assert_eq!(snapshot.outcome, AutopilotOutcome::NoProfileCandidate);
//! assert!(snapshot.findings_are_evidence_backed());
//! ```

pub mod models;
pub mod normalize;
pub mod redaction;
pub mod reducer;
pub mod rules;
pub mod sources;

pub use models::*;
pub use normalize::{
classify_event, error_code_from_token, extract_error_code, extract_oobe_setting,
extract_policy_pair, extract_profile_state, is_autopilot_channel,
};
pub use redaction::{redact_text, redacted_export_projection};
pub use reducer::reduce_autopilot_bundle;
pub use rules::derive_findings;
pub use sources::{
capture_is_validated, classify_timezone, detect_document, is_validated_schema_version,
is_validated_windows_build, AutopilotBundleInput, AutopilotCaptureState,
AutopilotDocumentDetection, AutopilotDocumentKind, AutopilotEspSessionDocument,
AutopilotEventsDocument, AutopilotReportDocument, AutopilotReportSection, AutopilotSourceInput,
AUTOPILOT_DOCUMENT_VERSION, AUTOPILOT_EVENT_CHANNEL, AUTOPILOT_EVENT_PROVIDER,
};
Loading