11from __future__ import annotations
2+ import copy , tempfile
23import sys , unittest
34from pathlib import Path
45ROOT = Path (__file__ ).resolve ().parents [1 ]; sys .path .insert (0 ,str (ROOT / 'scripts' ))
5- from scripts .docs_districts .docs_thematic_common import load_classifier
6+ from scripts .docs_districts .docs_thematic_common import build_plan , load_classifier
7+ from scripts .docs_districts .validate_docs_migration_map import validate_migration_map
68class DocsMigrationMapTests (unittest .TestCase ):
79 def setUp (self ): self .c = load_classifier (ROOT )
810 def test_all_exact_migrations_target_known_districts (self ):
@@ -15,6 +17,24 @@ def test_external_pattern_routes_are_explicit(self):
1517 self .assertIn ('external_owner_route' , item )
1618 self .assertEqual (item ['external_owner_route' ], item ['target_dir' ])
1719 self .assertTrue ((ROOT / item ['external_owner_route' ]).is_dir (), item ['external_owner_route' ])
20+ def test_external_pattern_routes_are_bound_to_traces_district (self ):
21+ classifier = copy .deepcopy (self .c )
22+ rule = next (item for item in classifier ['pattern_migrations' ] if item ['source_glob' ]== 'docs/EXPERIENCE_*.md' )
23+ rule ['district' ]= 'decisions'
24+ errors = validate_migration_map (classifier , ROOT )
25+ self .assertIn ('must use district traces, got decisions' , '\n ' .join (errors ))
26+ def test_experience_wildcard_routes_to_external_owner_route (self ):
27+ name = 'EXPERIENCE_' + 'ROUTE.md'
28+ source = 'docs/' + name
29+ with tempfile .TemporaryDirectory () as tmp :
30+ root = Path (tmp )
31+ (root / 'docs' ).mkdir ()
32+ (root / 'docs' / name ).write_text ('# Experience route\n ' , encoding = 'utf-8' )
33+ (root / 'mechanics' / 'experience' / 'legacy' / 'raw' ).mkdir (parents = True )
34+ moves = build_plan (root ,self .c )
35+ move = next (item for item in moves if item ['source' ]== source )
36+ self .assertEqual (move ['target' ],'mechanics/experience/legacy/raw/' + name )
37+ self .assertEqual (move ['district' ],'traces' )
1838 def test_no_current_root_allowlist_item_is_exact_moved (self ):
1939 allow = set (self .c ['current_root_allowlist' ]); moved = {Path (i ['source' ]).name for i in self .c ['exact_migrations' ]}; self .assertFalse (allow & moved )
2040if __name__ == '__main__' : unittest .main ()
0 commit comments