"""Supervisor negative controls with no model calls."""
import asyncio
import json
from pathlib import Path
import sys

from experiment import plans
from provider import dump
from runtime_followup import bounded_process,worker
from verify_evidence import verify


def test_external_deadline_terminates_owned_worker(tmp_path):
 result=bounded_process([sys.executable,'-c','import time; time.sleep(60)'],tmp_path,.3,tmp_path/'stdout.txt',tmp_path/'stderr.txt')
 assert result['deadline_exceeded'] and result['exit_code']!=0


def test_unchanged_economics_execute_through_real_a2a_fixture(tmp_path):
 plan=plans('engineering-runtime',1,2,0,2026090603,['openai'],['hl']);dump(tmp_path/'plan.json',plan)
 asyncio.run(worker(tmp_path,plan['jobs'][0]['id'],fixture=True))
 status=json.loads(next(tmp_path.glob('episodes/*/status.json')).read_text(encoding='utf-8'))
 assert status['status']=='completed' and status['metrics']['valid']
 assert status['metrics']['rounds_completed']==2 and status['metrics']['tail_mean_price']==150
 assert not list(tmp_path.glob('episodes/*/provider/*/metadata.json'))
 audit=verify(tmp_path)
 # Fixtures deliberately lack model records and must not pass as real inference.
 assert not audit['passed'] and len(audit['errors'])==4
 assert all('no exact provider input/output pair' in error for error in audit['errors'])
 assert audit['counts']['market_rounds']==2 and audit['counts']['http_requests']==audit['counts']['http_responses']
