@@ -555,12 +555,49 @@ def test_gemma3_recipe_examples_match_source_signatures():
555555 assert not unsupported_by_recipe , f"Gemma 3 docs use unsupported recipe keywords: { unsupported_by_recipe } "
556556
557557
558+ def _normalize_model_guide_format (text : str ) -> str :
559+ """Normalize only the catalog's intentional Sphinx/Fern rendering differences."""
560+ for boundary in ("BEGIN" , "END" ):
561+ text = text .replace (
562+ f"{{/* { boundary } GENERATED VERIFIED CONFIGURATIONS */}}" ,
563+ f"<!-- { boundary } GENERATED VERIFIED CONFIGURATIONS -->" ,
564+ )
565+ text = re .sub (r"<p>(.*?)</p>" , lambda match : "<p>" + " " .join (match [1 ].split ()) + "</p>" , text , flags = re .DOTALL )
566+ return re .sub (
567+ r'(<code class="language-bash">)(.*?)(</code>)' ,
568+ lambda match : match [1 ] + match [2 ].replace ("{" , "{" ).replace ("}" , "}" ) + match [3 ],
569+ text ,
570+ flags = re .DOTALL ,
571+ )
572+
573+
574+ def test_model_guide_format_normalization_preserves_content () -> None :
575+ """Format parity must still detect changed prose, commands, and code spacing."""
576+ sphinx = (
577+ "<!-- BEGIN GENERATED VERIFIED CONFIGURATIONS -->\n "
578+ "<p>Expected result\n </p>\n "
579+ '<code class="language-bash">echo ${MODEL}\n --flag</code>\n '
580+ "<!-- END GENERATED VERIFIED CONFIGURATIONS -->\n "
581+ )
582+ fern = (
583+ "{/* BEGIN GENERATED VERIFIED CONFIGURATIONS */}\n "
584+ "<p>Expected result</p>\n "
585+ '<code class="language-bash">echo ${MODEL}\n --flag</code>\n '
586+ "{/* END GENERATED VERIFIED CONFIGURATIONS */}\n "
587+ )
588+ expected = _normalize_model_guide_format (sphinx )
589+ assert expected == _normalize_model_guide_format (fern )
590+ for old , new in (("Expected result" , "Different result" ), ("MODEL" , "OTHER" ), (" --flag" , " --flag" )):
591+ assert expected != _normalize_model_guide_format (fern .replace (old , new ))
592+ assert _normalize_model_guide_format ("Prose {value}" ) == "Prose {value}"
593+
594+
558595def test_qwen3_model_guides_match_fern_and_reference_exported_recipes ():
559596 """Split Qwen3 guides must match Fern and reference exported recipes."""
560597 defined_recipes = _defined_recipe_names ()
561598 for sphinx_path , fern_path in QWEN3_DOC_PAIRS :
562599 sphinx_text = _read (sphinx_path )
563- assert sphinx_text == _read (fern_path )
600+ assert _normalize_model_guide_format ( sphinx_text ) == _normalize_model_guide_format ( _read (fern_path ) )
564601
565602 documented_recipes = set (re .findall (r"(qwen[0-9A-Za-z_]+_config)" , sphinx_text ))
566603 assert documented_recipes , f"{ sphinx_path .relative_to (REPO_ROOT )} documents no Qwen recipes"
0 commit comments