88
99import pytest
1010
11+ import ci .run_wiki_acceptance as wiki_acceptance
1112from supernote_module_generator import __version__
1213from ci .materialize_readme_examples import materialize , read_examples
1314from ci .run_wiki_acceptance import (
2425from supernote_module_generator .arguments import parse_arguments
2526from supernote_module_generator .feature_generator import FeatureConfig , stage_feature
2627from supernote_module_generator .feature_model import StarterFamily
28+ from supernote_module_generator .errors import ConfigurationError
2729from supernote_module_generator .helptext import COMMAND_HELP
2830
2931
@@ -379,12 +381,8 @@ def test_every_readme_and_wiki_command_output_record_is_source_classified(
379381 if record .classification in {"explanatory_output" , "placeholder" }
380382 )
381383 for record in records :
382- if (
383- record .argv
384- and record .argv [0 ] == "sn-module-gen"
385- and record .classification != "placeholder"
386- ):
387- parse_arguments (list (record .argv [1 :]))
384+ if record .argv and record .argv [0 ] == "sn-module-gen" :
385+ parse_arguments (wiki_acceptance ._grammar_arguments (record ))
388386
389387 by_source_and_text = {(record .source , record .text ): record for record in records }
390388 expected = {
@@ -428,6 +426,7 @@ def test_every_readme_and_wiki_command_output_record_is_source_classified(
428426
429427def test_pinned_wiki_audit_inventories_commands_and_explanatory_output (
430428 tmp_path : Path ,
429+ monkeypatch : pytest .MonkeyPatch ,
431430) -> None :
432431 bundle = ROOT / "ci/fixtures/supernote-module-generator-wiki.bundle"
433432 wiki = tmp_path / "wiki"
@@ -452,7 +451,15 @@ def test_pinned_wiki_audit_inventories_commands_and_explanatory_output(
452451 encoding = "utf-8" ,
453452 )
454453 generator .chmod (0o755 )
455- audit_commands (wiki , ROOT / "README.md" , str (generator ), output )
454+ parsed_arguments : list [tuple [str , ...]] = []
455+ original_parse_arguments = wiki_acceptance .parse_arguments
456+
457+ def tracked_parse_arguments (arguments : list [str ]):
458+ parsed_arguments .append (tuple (arguments ))
459+ return original_parse_arguments (arguments )
460+
461+ monkeypatch .setattr (wiki_acceptance , "parse_arguments" , tracked_parse_arguments )
462+ audited_records = audit_commands (wiki , ROOT / "README.md" , str (generator ), output )
456463 manifest = json .loads (output .read_text (encoding = "utf-8" ))
457464 assert manifest ["schema_version" ] == "1.1"
458465 assert manifest ["record_count" ] == len (manifest ["records" ])
@@ -464,6 +471,27 @@ def test_pinned_wiki_audit_inventories_commands_and_explanatory_output(
464471 record ["classification" ] == "explanatory_output"
465472 for record in manifest ["records" ]
466473 )
474+ placeholders = [
475+ record
476+ for record in audited_records
477+ if record .classification == "placeholder"
478+ and record .argv [:1 ] == ("sn-module-gen" ,)
479+ ]
480+ assert {(record .source , record .text ) for record in placeholders } == {
481+ (
482+ "Error-Handling.md" ,
483+ "sn-module-gen validate <module-name> --build --verbose" ,
484+ ),
485+ ("Using-the-CLI.md" , "sn-module-gen add [PACKAGE] [options]" ),
486+ ("Using-the-CLI.md" , "sn-module-gen update [FEATURE] [options]" ),
487+ ("Using-the-CLI.md" , "sn-module-gen validate [FEATURE] [options]" ),
488+ ("Using-the-CLI.md" , "sn-module-gen validate --all [options]" ),
489+ ("Using-the-CLI.md" , "sn-module-gen remove [FEATURE] [options]" ),
490+ ("Using-the-CLI.md" , "sn-module-gen remove --all [options]" ),
491+ }
492+ assert {
493+ tuple (wiki_acceptance ._grammar_arguments (record )) for record in placeholders
494+ } <= set (parsed_arguments )
467495
468496
469497def test_pinned_wiki_doctor_adb_claim_matches_source_and_installed_help (
@@ -574,6 +602,31 @@ def test_wiki_acceptance_commands_are_bounded_and_source_backed(tmp_path: Path)
574602 with pytest .raises (ValueError , match = "unclassified bash fenced command" ):
575603 scan_documented_commands ([page ])
576604
605+ wiki = tmp_path / "invalid-wiki"
606+ wiki .mkdir ()
607+ readme = tmp_path / "empty-readme.md"
608+ readme .write_text ("# Readme\n " , encoding = "utf-8" )
609+ invalid = wiki / "Invalid.md"
610+ invalid .write_text (
611+ "# Invalid placeholder command\n \n "
612+ "```bash\n "
613+ "sn-module-gen validate <module-name> --definitely-invalid\n "
614+ "```\n " ,
615+ encoding = "utf-8" ,
616+ )
617+ with pytest .raises (ConfigurationError , match = 'unknown option "--definitely-invalid"' ):
618+ audit_commands (wiki , readme , "unused-generator" , tmp_path / "invalid.json" )
619+
620+ invalid .write_text (
621+ "# Unsupported placeholder\n \n "
622+ "```bash\n "
623+ "sn-module-gen validate <unknown-module>\n "
624+ "```\n " ,
625+ encoding = "utf-8" ,
626+ )
627+ with pytest .raises (ValueError , match = "unsupported documented placeholder" ):
628+ audit_commands (wiki , readme , "unused-generator" , tmp_path / "invalid.json" )
629+
577630
578631def test_template_launch_contract_and_fake_device_harness (tmp_path : Path ) -> None :
579632 template = tmp_path / "template"
0 commit comments