"""Run from a checkout after vp i; prepares only isolated scenario fixtures.
Run: T3CODE_DEV_SEED=0 vp run scenarios scenarios/scheduled-task-effort.e2e.ts --target web
Copy the accompanying scheduled-task-effort.e2e.ts into scripts/scenarios first.
No agent turn runs; the saved task is disabled. Model entries are synthetic.
"""
import json, pathlib, shutil, subprocess
p = subprocess.Popen(['codex', 'app-server'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True)
def request(message, request_id):
    p.stdin.write(json.dumps(message) + '\n'); p.stdin.flush()
    for line in p.stdout:
        response = json.loads(line)
        if response.get('id') == request_id:
            return response
request({'id': 1, 'method': 'initialize', 'params': {'clientInfo': {'name': 'proof', 'version': '1'}, 'capabilities': None}}, 1)
p.stdin.write(json.dumps({'method': 'initialized'}) + '\n'); p.stdin.flush()
response = request({'id': 2, 'method': 'model/list', 'params': {}}, 2)
p.terminate(); p.wait()
models = response['result']['data']
hidden = list(set(m['id'] for m in models) | set(m['model'] for m in models))
custom = [
    {'slug': 'scenario-reasoning', 'name': 'Reasoning model', 'capabilities': {'optionDescriptors': [
        {'id': 'reasoningEffort', 'label': 'Reasoning effort', 'type': 'select', 'options': [
            {'id': 'low', 'label': 'Low', 'isDefault': True}, {'id': 'high', 'label': 'High'}], 'currentValue': 'low'}]}},
    {'slug': 'scenario-plain', 'name': 'Plain model', 'capabilities': {'optionDescriptors': []}},
]
path = pathlib.Path('scripts/scenarios/start-app.ts')
source = path.read_text()
source = source.replace('defaultModelSelection: REPLAY,',
    'providerModelPreferences: ' + json.dumps({'codex': {'hiddenModels': hidden, 'modelOrder': []}}) + ',\n' +
    'defaultModelSelection: { instanceId: "codex", model: "scenario-reasoning" },')
source = source.replace('enabled: false,', 'enabled: driver === "codex",')
source = source.replace('{ config: { binaryPath: noModel } }', '{ config: ' + json.dumps({'binaryPath': shutil.which('codex'), 'customModels': custom}) + ' }')
path.write_text(source)
path = pathlib.Path('scripts/e2e.config.ts')
path.write_text(path.read_text().replace('  ],\n  // One server', '  ].filter((target) => target.name === "web"),\n  // One server'))
print('Prepared synthetic fixtures and hidden catalog entries; no agent turn was started.')
