57 lines
2.6 KiB
Python
57 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Run real builder path/helper-import setup only, never build/data imports.
|
|
|
|
Child processes isolate sys.modules. Identity is checked by filename, so master
|
|
helper bytes may change concurrently without weakening the regression.
|
|
"""
|
|
import ast
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
BUILDERS = (
|
|
'content-crmodels-20261127/build.py',
|
|
'content-detail-models-20261125/build9.py',
|
|
'content-gomodels-20261125/build_m2.py',
|
|
'content-sdrace-20261125/build_body.py',
|
|
)
|
|
|
|
def inspect_prefix(script):
|
|
source=script.read_text()
|
|
tree=ast.parse(source)
|
|
selected=[]; found=False
|
|
for node in tree.body:
|
|
text=ast.get_source_segment(source,node) or ''
|
|
if isinstance(node,ast.ImportFrom) and node.module=='m2_sequence_hash':
|
|
selected.append(node);found=True;break
|
|
if isinstance(node,ast.Assign) and any(isinstance(t,ast.Name) and t.id=='native_sequence_hash' for t in node.targets):
|
|
selected.append(node);found=True;break
|
|
# Execute only real path setup and the explicitly named helper-loader
|
|
# nodes. All converter/store imports and build statements are excluded.
|
|
if isinstance(node,ast.Expr) and (text.startswith('sys.path.insert(') or text.startswith('_sequence_hash_spec.loader.exec_module(')):
|
|
selected.append(node)
|
|
elif isinstance(node,ast.Assign) and ('Path(__file__).resolve().parent' in text or text.startswith('_sequence_hash_spec =') or text.startswith('_sequence_hash_module =')):
|
|
selected.append(node)
|
|
assert found, 'No helper import boundary: '+str(script)
|
|
env={'__file__':str(script),'Path':Path,'sys':sys}
|
|
import importlib.util
|
|
env['importlib']=importlib
|
|
exec(compile(ast.Module(body=selected,type_ignores=[]),str(script),'exec'),env)
|
|
function=env['native_sequence_hash']
|
|
return Path(function.__code__.co_filename).resolve()
|
|
|
|
class Imports(unittest.TestCase):
|
|
def test_all_production_builders_use_own_checkout(self):
|
|
for rel in BUILDERS:
|
|
with self.subTest(builder=rel):
|
|
script=ROOT/'ops'/rel
|
|
result=subprocess.run([sys.executable,__file__,'--inspect',str(script)],text=True,capture_output=True)
|
|
self.assertEqual(result.returncode,0,result.stderr)
|
|
self.assertEqual(Path(result.stdout.strip()),ROOT/'ops/m2_sequence_hash.py')
|
|
|
|
if __name__=='__main__':
|
|
if len(sys.argv)==3 and sys.argv[1]=='--inspect':print(inspect_prefix(Path(sys.argv[2])))
|
|
else:unittest.main()
|