1818 guided_todo_delta_schema_versions ,
1919 planning_horizon_schema_versions ,
2020 planning_inventory_detail_schema_versions ,
21- runtime_root_command_route_count ,
21+ command_route_counts ,
2222 todo_work_counts_schema_versions ,
2323)
2424
@@ -47,6 +47,7 @@ def _row(**overrides: object) -> dict[str, object]:
4747 "planning_inventory_detail_schema_versions" : [],
4848 "todo_work_counts_schema_versions" : [],
4949 "runtime_root_command_route_count" : 0 ,
50+ "registry_command_route_count" : 0 ,
5051 }
5152 row .update (overrides )
5253 return row
@@ -803,7 +804,8 @@ def test_planning_inventory_detail_migration_is_bounded_and_fail_closed() -> Non
803804 ]
804805
805806
806- def test_runtime_root_route_growth_has_per_route_budget () -> None :
807+ @pytest .mark .parametrize ("option" , ["runtime_root" , "registry" ])
808+ def test_command_route_growth_has_per_route_budget (option : str ) -> None :
807809 base = _row (
808810 chars = 1_000 ,
809811 utf8_bytes = 1_000 ,
@@ -819,7 +821,7 @@ def test_runtime_root_route_growth_has_per_route_budget() -> None:
819821 compact_payload_chars = 1_320 ,
820822 action_signature_sha256 = None ,
821823 action_signature_coverages = [],
822- runtime_root_command_route_count = 2 ,
824+ ** { f" { option } _command_route_count" : 2 } ,
823825 )
824826
825827 result = compare_cli_output_receipts (_receipt (base ), _receipt (candidate ))
@@ -833,11 +835,12 @@ def test_runtime_root_route_growth_has_per_route_budget() -> None:
833835 "compact_payload_chars" : 320 ,
834836 }
835837 assert result ["rows" ][0 ]["review_signals" ] == [
836- "runtime-root command route coverage added: 2 executable route(s)"
838+ f" { option . replace ( '_' , '-' ) } command route coverage added: 2 executable route(s)"
837839 ]
838840
839841
840- def test_runtime_root_route_growth_still_fails_above_per_route_budget () -> None :
842+ @pytest .mark .parametrize ("option" , ["runtime_root" , "registry" ])
843+ def test_command_route_growth_still_fails_above_per_route_budget (option : str ) -> None :
841844 base = _row (
842845 chars = 1_000 ,
843846 utf8_bytes = 1_000 ,
@@ -853,7 +856,7 @@ def test_runtime_root_route_growth_still_fails_above_per_route_budget() -> None:
853856 compact_payload_chars = 1_321 ,
854857 action_signature_sha256 = None ,
855858 action_signature_coverages = [],
856- runtime_root_command_route_count = 2 ,
859+ ** { f" { option } _command_route_count" : 2 } ,
857860 )
858861
859862 result = compare_cli_output_receipts (_receipt (base ), _receipt (candidate ))
@@ -862,19 +865,22 @@ def test_runtime_root_route_growth_still_fails_above_per_route_budget() -> None:
862865 assert "chars grew by 321; allowance is 320" in result ["rows" ][0 ]["failures" ]
863866
864867
865- def test_invalid_runtime_root_route_count_does_not_grant_budget () -> None :
868+ @pytest .mark .parametrize ("option" , ["runtime_root" , "registry" ])
869+ @pytest .mark .parametrize ("before, after" , [(0 , True ), (0 , "2" ), (None , 2 ), (- 1 , 2 ), (0 , - 1 ), (2 , 2 )])
870+ def test_invalid_or_unchanged_command_route_count_does_not_grant_budget (option : str , before : object , after : object ) -> None :
866871 base = _row (
867872 chars = 1_000 ,
868873 utf8_bytes = 1_000 ,
869874 lines = 10 ,
870875 compact_payload_chars = 1_000 ,
876+ ** {f"{ option } _command_route_count" : before },
871877 )
872878 candidate = _row (
873879 chars = 1_097 ,
874880 utf8_bytes = 1_097 ,
875881 lines = 10 ,
876882 compact_payload_chars = 1_097 ,
877- runtime_root_command_route_count = True ,
883+ ** { f" { option } _command_route_count" : after } ,
878884 )
879885
880886 result = compare_cli_output_receipts (_receipt (base ), _receipt (candidate ))
@@ -899,23 +905,24 @@ def test_runtime_root_route_count_only_matches_executable_command_prefixes() ->
899905 "loopx --runtime-root"
900906 )
901907
902- assert runtime_root_command_route_count (text ) == 4
908+ assert command_route_counts (text )[ "runtime_root" ] == 4
903909
904910
905- def test_runtime_root_route_allowance_is_fail_closed_for_invalid_counts () -> None :
911+ @pytest .mark .parametrize ("option" , ["runtime_root" , "registry" ])
912+ def test_command_route_allowance_is_fail_closed_for_invalid_counts (option : str ) -> None :
906913 base = _row (
907914 chars = 1_000 ,
908915 utf8_bytes = 1_000 ,
909916 lines = 10 ,
910917 compact_payload_chars = 1_000 ,
911- runtime_root_command_route_count = 0 ,
918+ ** { f" { option } _command_route_count" : 0 } ,
912919 )
913920 candidate = _row (
914921 chars = 1_000 ,
915922 utf8_bytes = 1_000 ,
916923 lines = 10 ,
917924 compact_payload_chars = 1_000 ,
918- runtime_root_command_route_count = "2" ,
925+ ** { f" { option } _command_route_count" : "2" } ,
919926 )
920927
921928 result = compare_cli_output_receipts (_receipt (base ), _receipt (candidate ))
@@ -1109,3 +1116,38 @@ def test_projection_envelope_migration_is_status_only_bounded_and_one_time(outpu
11091116 outside_base = {** base , "row_id" : f"surface/{ surface } /small/{ output_format } " }
11101117 outside = {** candidate , "row_id" : outside_base ["row_id" ]}
11111118 assert not compare_cli_output_receipts (_receipt (outside_base ), _receipt (outside ))["ok" ]
1119+
1120+
1121+ def test_both_command_routes_are_counted_in_either_order () -> None :
1122+ text = (
1123+ "loopx --registry '/tmp/registry path' --runtime-root /tmp/root refresh-state\n "
1124+ "loopx --runtime-root /tmp/root --registry /tmp/registry quota should-run\n "
1125+ "Use --registry PATH, or say loopx --registry /tmp/path.\n "
1126+ "loopx --registry"
1127+ )
1128+ assert command_route_counts (text ) == {"registry" : 2 , "runtime_root" : 2 }
1129+
1130+
1131+ @pytest .mark .parametrize ("command" , [
1132+ 'loopx --registry "" turn plan' ,
1133+ "loopx --registry --runtime-root /tmp/root turn plan" ,
1134+ 'loopx --registry "/tmp/unclosed turn plan' ,
1135+ "loopx --registry /tmp/registry" ,
1136+ "loopx --registry /tmp/registry --runtime-root" ,
1137+ "loopx --registry /tmp/registry --format invalid turn plan" ,
1138+ 'loopx --registry /tmp/registry ""' ,
1139+ 'loopx --registry /tmp/registry " "' ,
1140+ ])
1141+ @pytest .mark .parametrize ("render" , [str , lambda command : json .dumps ({"command" : command }), lambda command : f"- execute: `{ command } `" ])
1142+ def test_malformed_command_never_grants_route_growth (command , render ) -> None :
1143+ counts = command_route_counts (render (command ))
1144+ assert counts == {"registry" : 0 , "runtime_root" : 0 }
1145+ base = _row (chars = 1_000 , utf8_bytes = 1_000 , compact_payload_chars = 1_000 )
1146+ candidate = _row (chars = 1_160 , utf8_bytes = 1_160 , compact_payload_chars = 1_160 ,
1147+ ** {f"{ key } _command_route_count" : value for key , value in counts .items ()})
1148+ assert compare_cli_output_receipts (_receipt (base ), _receipt (candidate ))["ok" ] is False
1149+
1150+
1151+ def test_json_escaped_paths_and_duplicate_arguments_are_counted_once () -> None :
1152+ command = """loopx --format json --registry '/tmp/a \" quoted\" path' --registry /tmp/final --runtime-root '/tmp/root path' turn plan"""
1153+ assert command_route_counts (json .dumps ({"command" : command })) == {"registry" : 1 , "runtime_root" : 1 }
0 commit comments