"""Classify old failures in an isolated immutable HEAD snapshot."""
import contextlib
import io
import json
import os
from pathlib import Path
import sys

root=Path('/work/baseline-dev');sys.path[:0]=[str(root),str(root/'tests'),'/opt/contextra'];os.chdir(root)
import pytest
class Report:
    def __init__(self):self.failed=[];self.errors=[]
    def pytest_collectreport(self,report):
        if report.failed:self.errors.append(str(report.longrepr))
    def pytest_runtest_logreport(self,report):
        if report.failed:(self.failed if report.when=='call' else self.errors).append(report.nodeid)
r=Report();buffer=io.StringIO()
with contextlib.redirect_stdout(buffer),contextlib.redirect_stderr(buffer):
    code=pytest.main(['-q','-p','no:cacheprovider',*[str(root/'tests'/(n+'.py')) for n in
        ('test_fall_integration','test_output_settings','test_async_restart')]],plugins=[r])
Path('/work/baseline-pytest.log').write_text(buffer.getvalue())
value=dict(exit_code=int(code),failed=r.failed,errors=r.errors,head='4c1fc6dcbdb3e1229104b6761de156239b3282b8')
Path('/work/baseline-tests.json').write_text(json.dumps(value,indent=2));print(json.dumps(value))
assert not r.errors
assert len(r.failed)==11
