//! The Markdown guard against the TypeScript (R5.4 final gates): every probe of //! `oracles/r5/markdown-sweep.json` gives the raw reports the TypeScript wrote, then either the //! TypeScript's formatted reports byte for byte or a refusal (`UnsupportedMarkdown`): the port //! never writes a report that differs silently. Probes made of what the equine reports use are //! never refused. #![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)] mod common; use faunosteo_core::curation::PipelineError; use faunosteo_core::curation::draft::changelog::render_changelog; use faunosteo_core::curation::draft::migration_map::{ MigrationMapInput, SheetRef, build_report_migration_map, }; use faunosteo_core::curation::draft::review_report::{ReviewReportInput, render_review_report}; use faunosteo_core::curation::draft::stats::document_stats; use faunosteo_core::curation::draft::{apply_changeset, parse_changeset, parse_references}; use faunosteo_core::curation::markdown::format_markdown; use faunosteo_core::json::to_js_compact; use serde_json::{Value, json}; fn oracle() -> Value { serde_json::from_str(&common::repo_file( "crates/core/tests/oracles/r5/markdown-sweep.json", )) .unwrap() } /// The raw CHANGELOG and REVIEW-REPORT of a probe, as the port writes them. fn raw_reports(frozen: &Value, case: &Value) -> (String, Result) { let baseline = &frozen["baseline"]; let references = parse_references(&to_js_compact(&json!({ "references": frozen["references"] })).unwrap()) .unwrap(); let changeset = parse_changeset(&to_js_compact(&case["changes_file"]).unwrap()).unwrap(); let result = apply_changeset(baseline, &references, &changeset.changes).unwrap(); let before = document_stats(baseline).unwrap(); let after = document_stats(&result.document).unwrap(); let sheet = SheetRef { sheet_id: "s".to_owned(), version_id: None, document_sha256: "0".repeat(64), }; let (_, stats) = build_report_migration_map(&MigrationMapInput { baseline, final_document: &result.document, legacy_id_map: frozen["legacy_id_map"].as_object().unwrap(), records: &result.records, sheet: &sheet, main_view_id: "main", }) .unwrap(); let changes: Vec<_> = changeset.changes.iter().map(|c| c.summary()).collect(); let changelog = render_changelog(&result.records, &before, &after, &stats).unwrap(); let review = render_review_report(&ReviewReportInput { changes: &changes, records: &result.records, document: &result.document, stats_before: &before, legacy_anomalies: &[], }); (changelog, review) } /// Characters the equine reports use outside code spans: a probe made only of these (with /// single spaces) is never refused. const EQUINE_SAFE: &str = "[]&#{}=<>\"':;()/%?-.,«»…≠°—+"; fn equine_safe(probe: &str) -> bool { // A leading or trailing space becomes two spaces once the probe sits in its sentence; the // inline constructs (links, wiki links, autolinks, character references) are probed apart. let construct = ["](", "][", "[[", "&", " {} Ok(_) => silent.push(probe.to_owned()), Err(PipelineError::UnsupportedMarkdown(_) | PipelineError::UnsupportedWidth(_)) => { case_refused = true; } Err(other) => panic!("{probe:?}: {other}"), } } assert!( !(case_refused && equine_safe(probe)), "{probe:?}: refused, yet made of what the equine reports use" ); if case_refused { refused += 1 } else { same += 1 } } silent.dedup(); assert!( silent.is_empty(), "silent differences for {} probes: {silent:?}", silent.len() ); assert_eq!(same + refused, 247); println!("{same} identical, {refused} refused"); }