@@ -379,6 +379,34 @@ def test_nested_list_fence_uses_container_relative_indentation() -> None:
379379 assert "rm -rf /" in projected
380380
381381
382+ @pytest .mark .parametrize ("newline" , ["\n " , "\r \n " ])
383+ @pytest .mark .parametrize (
384+ "opening,indent" ,
385+ [("- ~~~sh" , " " ), ("- Modes:\n - Commands:\n ~~~sh" , " " ), ("-\t ~~~sh" , "\t " )],
386+ )
387+ @pytest .mark .parametrize ("threat_location" , [None , "inside" , "after" ])
388+ def test_list_fence_dedent_preserves_prose_and_commands (
389+ newline : str , opening : str , indent : str , threat_location : str | None
390+ ) -> None :
391+ content = opening + "\n " + indent + "printf ok\n "
392+ if threat_location == "inside" :
393+ content += indent + "rm -rf /\n "
394+ content += "\n The interface doesn't match the spec.\n "
395+ if threat_location == "after" :
396+ content += "```sh\n rm -rf /\n ```\n "
397+ content += "Ordinary documentation.\n " * 500
398+ content = content .replace ("\n " , newline )
399+
400+ result = static_runner .run_static_patterns_with_ledger (
401+ {"components" : ["guide.md" ], "file_cache" : {"guide.md" : content }}, [tm_module ]
402+ )
403+
404+ assert result ["inspection_ledger" ][0 ]["outcome" ] is LedgerOutcome .COMPLETED
405+ assert any (finding .rule_id == "TM1" for finding in result ["findings" ]) is (
406+ threat_location is not None
407+ )
408+
409+
382410@pytest .mark .parametrize ("language" , ["tcl" , "verilog" ])
383411def test_nested_list_fence_keeps_typed_fence_quote_ownership (language : str ) -> None :
384412 # A nested list fence takes the same typed-fence path as a top-level fence:
@@ -415,7 +443,11 @@ def test_list_fence_container_relative_indentation_boundary(
415443
416444@pytest .mark .parametrize ("opening,indent" , [(" ```sh" , " " ), ("- - ```sh" , " " )])
417445def test_deeply_indented_marker_does_not_close_fence (opening : str , indent : str ) -> None :
418- content = opening + "\n " + indent + "```\n " + _LITERAL_BACKTICK_COMMAND + "\n ```\n "
446+ # Keep the command inside the list; dedenting would itself end its fence.
447+ command_indent = " " if opening .startswith ("-" ) else ""
448+ content = (
449+ opening + "\n " + indent + "```\n " + command_indent + _LITERAL_BACKTICK_COMMAND + "\n ```\n "
450+ )
419451 projected = tm_module ._markdown_shell_text (content , lambda : None )
420452 assert _LITERAL_BACKTICK_COMMAND in projected
421453
0 commit comments