Match bDS2 canonical file serialization

This commit is contained in:
2026-07-22 20:19:21 +02:00
parent fdf47da40a
commit 7b8e539340
17 changed files with 706 additions and 338 deletions

View File

@@ -296,11 +296,11 @@ fn test_tag_sync_roundtrip() {
}
// ════════════════════════════════════════════════════════════════════
// Step 20: Golden-file Comparisons
// Step 20: Legacy Fixture Compatibility and Canonical Reserialization
// ════════════════════════════════════════════════════════════════════
#[test]
fn test_golden_post_esmeralda() {
fn test_legacy_post_fixture_reserializes_as_bds2_canonical_output() {
let path = fixture_dir().join("posts/2005/11/esmeralda.md");
let expected = fs::read_to_string(&path).unwrap();
let (fm, body) = read_post_file(&expected).unwrap();
@@ -323,12 +323,13 @@ fn test_golden_post_esmeralda() {
let yaml = fm.to_yaml();
let actual = bds_core::util::frontmatter::format_frontmatter(&yaml, &body);
// Compare byte-for-byte with fixture
assert_eq!(actual, expected, "golden output mismatch for esmeralda.md");
assert!(actual.find("language: es").unwrap() < actual.find("createdAt:").unwrap());
assert!(actual.find("publishedAt:").unwrap() < actual.find("tags:").unwrap());
assert!(actual.ends_with('\n'));
}
#[test]
fn test_golden_translation_esmeralda_en() {
fn test_legacy_translation_fixture_matches_bds2_canonical_output() {
let path = fixture_dir().join("posts/2005/11/esmeralda.en.md");
let expected = fs::read_to_string(&path).unwrap();
let (fm, body) = read_translation_file(&expected).unwrap();
@@ -348,7 +349,7 @@ fn test_golden_translation_esmeralda_en() {
}
#[test]
fn test_golden_sidecar() {
fn test_legacy_sidecar_fixture_reserializes_as_bds2_canonical_output() {
let path = fixture_dir().join("media/2005/11/eb0cf9d7-6fbd-4b74-9be3-759d6e16f240.jpg.meta");
let expected = fs::read_to_string(&path).unwrap();
let sc = read_sidecar(&expected).unwrap();
@@ -362,13 +363,10 @@ fn test_golden_sidecar() {
assert_eq!(sc.height, Some(1200));
assert_eq!(sc.title.as_deref(), Some("Esmeralda"));
// Write back via to_string() and compare
// Write back via to_string() in canonical bDS2 order.
let actual = sc.to_string();
assert_eq!(
actual.trim(),
expected.trim(),
"golden output mismatch for media sidecar"
);
assert!(actual.find("linkedPostIds:").unwrap() < actual.find("tags:").unwrap());
assert!(actual.ends_with("---"));
}
#[test]
@@ -426,7 +424,7 @@ fn test_golden_meta_files() {
}
#[test]
fn test_golden_template() {
fn test_legacy_template_fixture_reserializes_as_bds2_canonical_output() {
let path = fixture_dir().join("templates/testvorlage.liquid");
let expected = fs::read_to_string(&path).unwrap();
let (fm, body) = read_template_file(&expected).unwrap();
@@ -443,12 +441,11 @@ fn test_golden_template() {
assert!(fm.enabled);
assert_eq!(fm.version, 3);
// Write back and compare byte-for-byte
// Write back with bDS2 scalar and timestamp quoting.
let actual = write_template_file(&fm, &body);
assert_eq!(
actual, expected,
"golden output mismatch for testvorlage.liquid"
);
assert!(actual.contains("id: 38704737-b7e7-4dd4-b010-9208bcf80ef6\n"));
assert!(actual.contains("createdAt: '2026-02-27T20:33:00.000Z'"));
assert!(actual.ends_with('\n'));
}
// ════════════════════════════════════════════════════════════════════
@@ -841,7 +838,7 @@ fn template_diff_for_field(modify_fn: impl FnOnce(&str) -> String) -> Vec<String
#[test]
fn test_diff_detects_template_title() {
let fields = template_diff_for_field(|content| {
content.replace("title: \"Diff Template\"", "title: \"Changed Template\"")
content.replace("title: Diff Template", "title: Changed Template")
});
assert!(
fields.contains(&"title".to_string()),
@@ -851,8 +848,7 @@ fn test_diff_detects_template_title() {
#[test]
fn test_diff_detects_template_kind() {
let fields =
template_diff_for_field(|content| content.replace("kind: \"post\"", "kind: \"list\""));
let fields = template_diff_for_field(|content| content.replace("kind: post", "kind: list"));
assert!(
fields.contains(&"kind".to_string()),
"expected 'kind' in template diff fields, got: {fields:?}"
@@ -938,7 +934,7 @@ fn script_diff_for_field(modify_fn: impl FnOnce(&str) -> String) -> Vec<String>
#[test]
fn test_diff_detects_script_title() {
let fields = script_diff_for_field(|content| {
content.replace("title: \"Diff Script\"", "title: \"Changed Script\"")
content.replace("title: Diff Script", "title: Changed Script")
});
assert!(
fields.contains(&"title".to_string()),
@@ -948,9 +944,8 @@ fn test_diff_detects_script_title() {
#[test]
fn test_diff_detects_script_kind() {
let fields = script_diff_for_field(|content| {
content.replace("kind: \"utility\"", "kind: \"transform\"")
});
let fields =
script_diff_for_field(|content| content.replace("kind: utility", "kind: transform"));
assert!(
fields.contains(&"kind".to_string()),
"expected 'kind' in script diff fields, got: {fields:?}"
@@ -959,9 +954,8 @@ fn test_diff_detects_script_kind() {
#[test]
fn test_diff_detects_script_entrypoint() {
let fields = script_diff_for_field(|content| {
content.replace("entrypoint: \"main\"", "entrypoint: \"run\"")
});
let fields =
script_diff_for_field(|content| content.replace("entrypoint: main", "entrypoint: run"));
assert!(
fields.contains(&"entrypoint".to_string()),
"expected 'entrypoint' in script diff fields, got: {fields:?}"