203 lines
13 KiB
Plaintext
203 lines
13 KiB
Plaintext
#import "../modules/diagnostics-normalize.typ": normalize, value-text, datetime-day, date-index, datetime-second, catalog-correlation, group-events, display-time
|
|
|
|
#let rules = yaml("../config/diagnostics-rules.yaml")
|
|
#let fixture = json("fixtures/windiagnostics-v1.json")
|
|
#let data = normalize(fixture, rules: rules, source-name: "tools/fixtures/windiagnostics-v1.json")
|
|
|
|
#assert.eq(data.computer, "TEST-PC")
|
|
#assert.eq(data.mode, "Full")
|
|
#assert.eq(data.generated, "2026-09-14")
|
|
#assert.eq(data.administrator, "Yes")
|
|
#assert.eq(data.system.ram_total_gb, 31.82)
|
|
#assert.eq(data.system.ram_free_gb, 12.5)
|
|
#assert.eq(data.disk_free.len(), 2)
|
|
#assert.eq(data.disk_free.at(0).drive, "C:")
|
|
#assert.eq(data.disk_free.at(0).free_percent, 40.0)
|
|
#assert.eq(data.disk_free.at(1).free_percent, 60.0)
|
|
|
|
#let programs = data.inventory.find(item => item.label == "Desktop programs")
|
|
#assert(programs != none)
|
|
#assert.eq(programs.count, 42)
|
|
|
|
#let service-event = data.event_groups.find(item => item.provider == "Service Control Manager" and item.id == "7000")
|
|
#assert(service-event != none, message: "Service Control Manager / 7000 missing from structured events")
|
|
#assert.eq(service-event.severity, "warning")
|
|
#assert(service-event.remediation != "" or service-event.resolution_steps.len() > 0)
|
|
#assert(data.findings.any(item => item.title == "Service Control Manager · Event 7000"))
|
|
#assert(not data.findings.any(item => item.title == "System-file integrity violations"))
|
|
#assert(not data.findings.any(item => item.title == "Windows Firewall protection is incomplete"))
|
|
|
|
#assert.eq(datetime-day("2026-09-14T15:00:00+02:00"), date-index(2026, 9, 14))
|
|
#assert.eq(datetime-day("/Date(1789390800000)/"), date-index(2026, 9, 14))
|
|
|
|
// Unknown events must remain visible rather than being silently discarded.
|
|
#let unknown-report = (
|
|
schema_version: 1,
|
|
report_type: "windows_system_maintenance",
|
|
mode: "Full",
|
|
generated_at: "2026-09-14T16:00:00+02:00",
|
|
host: (computer_name: "UNKNOWN-EVENT-PC", administrator: true),
|
|
sections: (
|
|
recent_system_errors: (
|
|
status: "ok",
|
|
count: 1,
|
|
data: ((TimeCreated: "2026-09-14T12:00:00+02:00", Id: 999, ProviderName: "UnknownProvider", Message: "Unrecognized event"),),
|
|
error: none,
|
|
),
|
|
recent_application_errors: (status: "ok", count: 0, data: (), error: none),
|
|
),
|
|
)
|
|
#let unknown = normalize(unknown-report, rules: rules)
|
|
#assert.eq(unknown.issue_counts.unanalysed, 1)
|
|
|
|
Diagnostics JSON regression checks passed.
|
|
|
|
#let native = normalize(json("../diagnostics/windows_system_report_DESKTOP-SAU019H_20260914_163753.json"), rules: rules)
|
|
#assert.eq(native.system.cores, 8)
|
|
#assert.eq(native.disk_free.at(0).free_percent, 51.4)
|
|
#assert.eq(native.event_groups.map(item => item.count).sum(), 33)
|
|
#assert(not native.findings.any(item => item.title == "Windows Firewall protection is incomplete"))
|
|
#let legacy = normalize(json("../diagnostics/hardware-17-tA6kwqAg-windows-system-report-desktop-2osf051-20260904-134702.json"), rules: rules)
|
|
#assert.eq(legacy.system.cores, 8)
|
|
#assert.eq(legacy.security.antivirus, "Yes")
|
|
#assert.eq(legacy.inventory.at(0).count, "Unavailable")
|
|
#assert(legacy.findings.any(item => item.title == "Legacy conversion has incomplete evidence"))
|
|
#assert(legacy.findings.any(item => item.title == "Windows component store is repairable"))
|
|
#assert(not legacy.findings.any(item => item.title == "Devices report problems"))
|
|
#assert(not legacy.findings.any(item => item.title == "Windows Firewall protection is incomplete"))
|
|
#assert(legacy.event_groups.any(item => item.provider == "Application Error" and item.message.contains("0xc0000409")))
|
|
#assert.eq(datetime-second("1970-01-01T01:00:00+01:00"), datetime-second("/Date(0)/"))
|
|
#let cluster = (
|
|
(provider: "ESENT", id: "474", time: "1970-01-01T01:00:00+01:00", message: "catroot2 -1018"),
|
|
(provider: "Application Error", id: "1000", time: "/Date(1000)/", message: "CryptSvc ESENT.dll"),
|
|
(provider: "Microsoft-Windows-WindowsUpdateClient", id: "20", time: "1970-01-01T00:02:00Z", message: "Update failed"),
|
|
)
|
|
#assert(catalog-correlation(cluster) != none)
|
|
#assert.eq(catalog-correlation(cluster.slice(0, 2)), none)
|
|
#let distant = cluster
|
|
#{ distant.at(2).time = "1970-01-01T00:02:01Z" }
|
|
#assert.eq(datetime-second(distant.at(2).time), 121)
|
|
#assert.eq(catalog-correlation(distant), none)
|
|
#let repeated = group-events((
|
|
(provider: "Service Control Manager", id: "7000", time: "2026-01-01T00:00:00Z", message: "Failure"),
|
|
(provider: "Service Control Manager", id: "7000", time: "2026-09-14T00:00:00Z", message: "Failure"),
|
|
), rules, reference-day: date-index(2026, 9, 14))
|
|
#assert.eq(repeated.at(0).age_days, 0)
|
|
#assert.eq(repeated.at(0).weight_factor, 1.0)
|
|
#let compact = normalize((schema_version: 1, mode: "Compact", generated_at: "2026-09-14T00:00:00Z", host: (administrator: true), summary: (memory: (total_gb: 16, free_gb: 8), devices: (problem_count: 1))))
|
|
#assert.eq(compact.system.ram_total_gb, 16)
|
|
#assert(compact.findings.any(item => item.title == "Devices report problems"))
|
|
|
|
#assert.eq(native.issue_counts.unanalysed, 0)
|
|
#let bugcheck = native.event_groups.find(item => item.provider == "Microsoft-Windows-WER-SystemErrorReporting" and item.id == "1001")
|
|
#assert.eq(bugcheck.severity, "critical")
|
|
#assert(bugcheck.message.contains("DPC_WATCHDOG_VIOLATION"))
|
|
#assert.eq(bugcheck.display_time, "2026-09-14 12:49:36 UTC")
|
|
#let dump = native.event_groups.find(item => item.provider == "volmgr" and item.id == "162")
|
|
#assert.eq(dump.severity, "info")
|
|
#assert(not native.findings.any(item => item.title == "volmgr · Event 162"))
|
|
#assert.eq(display-time("/Date(0)/"), "1970-01-01 00:00:00 UTC")
|
|
#assert.eq(display-time("/Date(-1000)/"), "1969-12-31 23:59:59 UTC")
|
|
#assert.eq(display-time("2026-09-14T15:29:36+02:00"), "2026-09-14 13:29:36 UTC")
|
|
#assert.eq(display-time("Unknown"), "Unknown")
|
|
|
|
// Synthetic schema 2 contracts, not Windows collector execution evidence.
|
|
#let v2 = normalize(json("fixtures/windiagnostics-v2-full.json"), rules: rules)
|
|
#assert.eq(v2.schema_version, 2)
|
|
#assert.eq(v2.event_counts, (critical: 0, error: 1, warning: 2, information: 1, unknown: 0))
|
|
#assert.eq(v2.raw_events.len(), 4)
|
|
#assert.eq(v2.event_groups.find(e => e.level == 3).count, 2)
|
|
#assert.eq(v2.event_groups.find(e => e.level == 4).severity, "info")
|
|
#assert(v2.coverage.any(c => c.section == "recent_system_events" and c.use.contains("truncation: no")))
|
|
#assert(v2.coverage.any(c => c.section == "storage.storage_health" and c.severity == "warning"))
|
|
#assert(v2.excerpts.any(e => e.title == "DRIVER STORE" and e.text.contains("Échec")))
|
|
#assert(v2.excerpts.any(e => e.title == "MINIDUMPS"))
|
|
#assert(v2.collection_incomplete)
|
|
#assert(v2.analysis_confidence <= 50)
|
|
#assert.eq(v2.parameters.event_log_days, 30)
|
|
#let v2compact = normalize(json("fixtures/windiagnostics-v2-compact.json"), rules: rules)
|
|
#assert.eq(v2compact.inventory.at(0).count, "Unavailable")
|
|
#assert(not v2compact.findings.any(f => f.title == "Devices report problems"))
|
|
#assert(v2compact.coverage.any(c => c.section == "problem_devices" and c.severity == "warning"))
|
|
#let v2partial = normalize(json("fixtures/windiagnostics-v2-partial.json"), rules: rules)
|
|
#assert(v2partial.coverage.any(c => c.section == "services" and c.severity == "warning"))
|
|
#assert(v2partial.excerpts.any(e => e.title == "DRIVER STORE" and e.text.contains("exit_code")))
|
|
#for mode in ("Compact", "Mid", "Full") {
|
|
let old = fixture
|
|
old.mode = mode
|
|
assert.eq(normalize(old, rules: rules).schema_version, 1)
|
|
}
|
|
|
|
// Older native captures do not acquire placeholder inventories for newer fields.
|
|
#assert(not native.inventory.any(item => item.label == "filter drivers"))
|
|
#assert(native.coverage.any(item => item.section == "filter_drivers" and item.records == "Unavailable"))
|
|
#assert(not native.findings.any(item => item.title.contains("filter_drivers")))
|
|
#assert(not native.collection_incomplete)
|
|
#let second-native = normalize(json("../diagnostics/windows_system_report_DESKTOP-SAU019H_20260915_113124.json"), rules: rules)
|
|
#assert.eq(second-native.schema_version, 1)
|
|
#assert.eq(second-native.raw_events.len(), 102)
|
|
#assert(not second-native.inventory.any(item => item.label == "filter drivers"))
|
|
|
|
// One normalization path: collection shape, not schema label, controls Compact.
|
|
#let compact-with-old-label = json("fixtures/windiagnostics-v2-compact.json")
|
|
#{ compact-with-old-label.schema_version = 1 }
|
|
#assert.eq(normalize(compact-with-old-label, rules: rules).inventory, v2compact.inventory)
|
|
#let summary-only-new-label = (schema_version: 2, mode: "Compact", summary: (devices: (problem_count: 1)))
|
|
#assert(normalize(summary-only-new-label).findings.any(item => item.title == "Devices report problems"))
|
|
|
|
// Real schema 2 inventories contain booleans, including inside nested values.
|
|
#assert.eq(value-text(true), "Yes")
|
|
#assert.eq(value-text(false), "No")
|
|
#assert.eq(value-text((IsSigned: true, flags: (false, none))), "IsSigned: Yes; flags: No\nUnknown")
|
|
#let captured-v2 = normalize(json("../diagnostics/windows_system_report_DESKTOP-SAU019H_20260915_121057.json"), rules: rules)
|
|
#assert.eq(captured-v2.schema_version, 2)
|
|
#assert.eq(captured-v2.raw_events.len(), 249)
|
|
#assert(captured-v2.excerpts.any(item => item.title == "SIGNED DRIVERS" and item.text.contains("IsSigned: Yes")))
|
|
#assert(captured-v2.excerpts.any(item => item.title == "STORAGE DISKS" and item.text.contains("IsBoot:")))
|
|
|
|
// Reviewed schema 2 events and source-aware supplemental reliability history.
|
|
#assert.eq(captured-v2.issue_counts.unanalysed, 0)
|
|
#assert(captured-v2.findings.any(item => item.title.contains("AX200") and item.title.contains("Code 22")))
|
|
#assert(captured-v2.findings.any(item => item.title == "volmgr · Event 161"))
|
|
#assert.eq(captured-v2.event_groups.find(item => item.provider == "Microsoft-Windows-DistributedCOM" and item.id == "10016").severity, "info")
|
|
#assert.eq(captured-v2.event_groups.find(item => item.provider == "Microsoft-Windows-CodeIntegrity" and item.id == "3099").severity, "info")
|
|
#assert(captured-v2.findings.any(item => item.at("watch_id", default: "") == "intel-wifi-observed"))
|
|
#assert(not captured-v2.findings.any(item => item.at("watch_id", default: "") == "obs-overlay"))
|
|
#import "../modules/diagnostics-normalize.typ": watchlist-findings, reliability-events
|
|
#let watch-report = json("fixtures/windiagnostics-watchlist.json")
|
|
#let watch = normalize(watch-report, rules: rules)
|
|
#let watch-ids = watch.findings.filter(f => "watch_id" in f).map(f => f.watch_id)
|
|
#assert.eq(watch-ids, ("winring0", "dell-dbutil", "gigabyte-oc-guru", "obs-overlay", "obs-audio-hooks", "smb1"))
|
|
#assert(watch.findings.filter(f => "watch_id" in f).all(f => f.weight_factor == 0 and f.reference_url.starts-with("https://")))
|
|
#let clean-watch = watch-report
|
|
#{
|
|
clean-watch.sections.system_drivers.data = ((Name: "NotWinRing0", PathName: "C:\\Drivers\\NotWinRing0x64.sys", State: "Stopped"),)
|
|
clean-watch.sections.installed_programs.data = ((DisplayName: "OBS Studio", DisplayVersion: "32"), (DisplayName: "GIGABYTE OC GURU II", DisplayVersion: "2.09"))
|
|
clean-watch.sections.services.status = "unavailable"
|
|
clean-watch.sections.enabled_windows_features.data = ((FeatureName: "SMB1Protocol", State: 4), (FeatureName: "SmbDirect", State: 2))
|
|
}
|
|
#assert.eq(watchlist-findings(clean-watch, ()), ())
|
|
#let no-obs = watch-report
|
|
#{ no-obs.sections.installed_programs.data = ((DisplayName: "RivaTuner Statistics Server", DisplayVersion: "7.3.7"),) }
|
|
#assert(not watchlist-findings(no-obs, ()).any(f => f.watch_id in ("obs-overlay", "obs-audio-hooks")))
|
|
#let missing-version = watch-report
|
|
#{ missing-version.sections.installed_programs.data = ((DisplayName: "GIGABYTE OC GURU II", DisplayVersion: none),) }
|
|
#assert(not watchlist-findings(missing-version, ()).any(f => f.watch_id == "gigabyte-oc-guru"))
|
|
#let reliability-report = (sections: (reliability_records: (status: "ok", data: ((SourceName: "Application Hang", EventIdentifier: 1002, TimeGenerated: "/Date(1000)/", Message: "Hang"), (SourceName: "Microsoft-Windows-WindowsUpdateClient", EventIdentifier: 19, TimeGenerated: "/Date(2000)/", Message: "Success")))))
|
|
#assert.eq(reliability-events(reliability-report, (), rules).len(), 1)
|
|
#assert.eq(reliability-events(reliability-report, ((provider: "Application Hang", id: "1002", time: "1970-01-01T00:00:01Z", message: "Hang"),), rules).len(), 0)
|
|
|
|
#let unhealthy-report = watch-report
|
|
#{
|
|
unhealthy-report.sections.signed_drivers.data = ((DeviceName: "Synthetic unsigned device", IsSigned: false),)
|
|
unhealthy-report.sections.storage_disks.data = ((FriendlyName: "Synthetic warning disk", HealthStatus: "Warning"),)
|
|
}
|
|
#let unhealthy = normalize(unhealthy-report, rules: rules)
|
|
#assert(unhealthy.findings.any(f => f.title == "Drivers explicitly report unsigned status"))
|
|
#assert(unhealthy.findings.any(f => f.title.starts-with("Storage health requires review")))
|
|
#assert(not captured-v2.findings.any(f => f.title == "Drivers explicitly report unsigned status"))
|
|
#assert(not captured-v2.findings.any(f => f.title.starts-with("Storage health requires review")))
|
|
|
|
#assert.eq(reliability-events(reliability-report, ((provider: "Application Hang", id: "1002", time: "1970-01-01T00:00:01Z", message: "A different application hung"),), rules).len(), 1)
|
|
#assert(captured-v2.excerpts.any(item => item.title == "SIGNED DRIVERS" and item.text.contains("AX200")))
|