@@ -55,8 +55,8 @@ def write(path, content):
5555 target = root / path
5656 target .parent .mkdir (parents = True , exist_ok = True )
5757 target .write_text (content )
58- def classify (base , * extra ):
59- result = subprocess .run ([sys .executable , script , "classify" , "--base" , base , "--head" , "HEAD" ,
58+ def classify (base , * extra , head = "HEAD" ):
59+ result = subprocess .run ([sys .executable , script , "classify" , "--base" , base , "--head" , head ,
6060 "--plan" , str (root / "plan.json" ), * extra ], cwd = root , env = env , capture_output = True , text = True )
6161 self .assertEqual (result .returncode , 0 , result .stderr )
6262 return json .loads ((root / "plan.json" ).read_text ()), result .stdout
@@ -67,7 +67,8 @@ def classify(base, *extra):
6767 path = "loopx/web/chat/index.html"
6868 write (path , "old" )
6969 for policy in POLICY_PATHS :
70- write (policy , "reviewed policy" )
70+ write (policy , "jobs:\n test-shard:\n strategy:\n matrix:\n shard: [1, 2, 3, 4, 5, 6]\n "
71+ if policy .endswith (".yml" ) else "reviewed policy" )
7172 git ("add" , "." )
7273 git ("commit" , "-qm" , "base" )
7374 base = git ("rev-parse" , "HEAD" )
@@ -78,14 +79,15 @@ def classify(base, *extra):
7879 self .assertFalse (packet ["python_tests" ])
7980 self .assertFalse (packet ["backend_tests" ])
8081 self .assertFalse (packet ["stage2c_tests" ])
82+ self .assertEqual (packet ["python_shards" ], 0 )
8183 self .assertTrue (packet ["presentation_tests" ])
8284 self .assertEqual (packet ["head_sha" ], git ("rev-parse" , "HEAD" ))
8385 for flag in ("--force-full" , "--non-pr" ):
8486 forced , _ = classify (base , flag )
8587 self .assertTrue (forced ["python_tests" ])
8688 self .assertTrue (forced ["backend_tests" ])
8789 self .assertTrue (forced ["stage2c_tests" ])
88- self .assertEqual (forced ["python_shards" ], 4 )
90+ self .assertEqual (forced ["python_shards" ], 6 )
8991 # A policy change cannot authorize its own exemption.
9092 write (POLICY_PATHS [0 ], "changed policy" )
9193 git ("commit" , "-qam" , "policy" )
@@ -116,6 +118,39 @@ def classify(base, *extra):
116118 failed = subprocess .run ([sys .executable , script , "classify" , "--base" , "missing" , "--head" , "HEAD" ],
117119 cwd = root , env = env , capture_output = True )
118120 self .assertNotEqual (failed .returncode , 0 )
121+ # The workflow executing this checkout owns topology, even when
122+ # the candidate head differs or an uncommitted file is misleading.
123+ published = git ("rev-parse" , "HEAD" )
124+ workflow = POLICY_PATHS [- 1 ]
125+ prefix = "jobs:\n test-shard:\n strategy:\n matrix:\n "
126+ write (workflow , prefix + " shard: [1, 2, 3, 4, 5, 6, 7, 8]\n " )
127+ self .assertEqual (classify (published , "--non-pr" )[0 ]["python_shards" ], 6 )
128+ git ("commit" , "-qam" , "executing workflow has eight shards" )
129+ packet , _ = classify (published , "--non-pr" , head = published )
130+ self .assertEqual (packet ["python_shards" ], 8 )
131+ self .assertEqual (packet ["head_sha" ], published )
132+ self .assertEqual (packet ["checkout_sha" ], git ("rev-parse" , "HEAD" ))
133+ for axis in ("shard: []" , "shard: [1, 1]" , "shard: [1, 3]" , "shard: [1, '02']" ,
134+ "shard: '${{ inputs.shards }}'" , "shard: [1, 2]\n python: ['3.11']" , None ):
135+ with self .subTest (axis = axis ):
136+ write (workflow , prefix + " " + axis + "\n " if axis else "jobs: {}\n " )
137+ git ("commit" , "-qam" , "unsupported execution topology" )
138+ output = root / "rejected.json"
139+ result = subprocess .run ([sys .executable , script , "classify" , "--base" , "HEAD" ,
140+ "--head" , "HEAD" , "--non-pr" , "--plan" , str (output )],
141+ cwd = root , env = env , capture_output = True , text = True )
142+ self .assertNotEqual (result .returncode , 0 )
143+ self .assertIn ("test-shard.strategy.matrix" , result .stderr )
144+ self .assertFalse (output .exists (), "invalid topology must not publish a fallback plan" )
145+ # The docs exemption still reports no Python coverage or shards.
146+ docs_base = git ("rev-parse" , "HEAD" )
147+ write ("README.md" , "fixture documentation" )
148+ git ("add" , "--" , "README.md" )
149+ git ("commit" , "-qm" , "docs-only change" )
150+ packet , _ = classify (docs_base )
151+ self .assertEqual (packet ["change_kind" ], "docs" )
152+ self .assertFalse (packet ["python_tests" ])
153+ self .assertEqual (packet ["python_shards" ], 0 )
119154
120155
121156if __name__ == "__main__" :
0 commit comments