import contextlib, glob, json, os, pathlib, shlex, subprocess, sys, unittest
os.umask(0o077)
root = pathlib.Path('/evidence')
sys.path.append('/tool-overlay')
sys.path.append('/evidence')
os.environ['REDIS_STREAMS_ENABLED'] = 'false'
os.environ['TMPDIR'] = '/evidence'
assert not glob.glob('/dev/nvidia*')
with (root/'tests.log').open('w') as log, contextlib.redirect_stdout(log), contextlib.redirect_stderr(log):
    # SDK native boundary is BLOCKED by absent ABI-compatible headers; do not replay it.
    suite = unittest.TestSuite()
    for pattern in ['test_det_result_path.py','test_native_metadata.py','test_identity_contracts.py',
                    'test_metadata_publisher.py','test_stream_manager_lifecycle.py','test_async_restart.py',
                    'test_stream_apply.py','test_cleanup_boundary.py','test_composition_architecture.py']:
        suite.addTests(unittest.defaultTestLoader.discover('tests', pattern=pattern))
    result = unittest.TextTestRunner(stream=log, verbosity=2).run(suite)
    assert not glob.glob('/dev/nvidia*')
summary = dict(tests=result.testsRun, failures=len(result.failures), errors=len(result.errors),
               sdk_identity='BLOCKED_HEADER_ABI', gpu_nodes=0)
(root/'verify.json').write_text(json.dumps(summary,indent=2))
print(json.dumps(summary))
sys.exit(not result.wasSuccessful())
