"""Seed the REAL isolated OpenCode 2.4.2 server; only Console upstream is synthetic.

Run console-fixture.py on port 17434. Start OpenCode inside a container with
host networking, cwd /srv/remote-default, and the downloaded 2.4.2 binary.
Supply its password in OPENCODE_PROOF_PASSWORD. No real account is required.
"""
import base64, json, os, urllib.request
password = os.environ['OPENCODE_PROOF_PASSWORD']
body = {'integrationID':'opencode','label':'Synthetic remote workspace','value':{
    'type':'key','key':'synthetic-no-real-credential','metadata':{
        'server':'http://127.0.0.1:17434/console',
        'orgID':'wrk_proof','orgName':'Remote proof workspace'}}}
request = urllib.request.Request('http://127.0.0.1:17433/api/credential',
    data=json.dumps(body).encode(), headers={'Content-Type':'application/json',
    'Authorization':'Basic '+base64.b64encode(('opencode:'+password).encode()).decode()})
with urllib.request.urlopen(request) as response:
    assert response.status == 200
print('Synthetic Console workspace credential seeded')
