Exercise OpenCode terminal tickets in proxy and browser regressions

This commit is contained in:
Nick Sweeting 2026-09-03 18:26:28 -07:00
parent 860892960a
commit 397505cbec
No known key found for this signature in database
2 changed files with 25 additions and 0 deletions

View File

@ -339,6 +339,24 @@ def test_opencode_proxy_waits_for_owned_process_readiness(admin_client, live_ope
assert runtime._PROCESS_READY is process
def test_opencode_proxy_preserves_protocol_headers(admin_client, live_opencode):
headers = {"HTTP_HOST": ADMIN_TEST_HOST, "HTTP_SEC_FETCH_SITE": "same-origin"}
created = admin_client.post(
"/admin/agent/opencode/pty",
data={"command": "/bin/sh", "args": []},
content_type="application/json",
**headers,
)
assert created.status_code == 200
path = f"/admin/agent/opencode/pty/{created.json()['id']}"
try:
response = admin_client.post(path + "/connect-token", HTTP_X_OPENCODE_TICKET="1", **headers)
assert response.status_code == 200, response.content
assert response.json()["ticket"]
finally:
assert admin_client.delete(path, **headers).status_code == 200
def test_opencode_proxy_sse_response_is_unbuffered(admin_client, live_opencode):
response = admin_client.get(
"/admin/agent/opencode/global/event",

View File

@ -72,8 +72,15 @@ const config = JSON.parse(require('node:fs').readFileSync(0, 'utf8'));
if (!created.ok) throw new Error('PTY create: ' + created.status);
const pty = await created.json();
try {
const authorized = await fetch(base + '/pty/' + pty.id + '/connect-token', {
method: 'POST', headers: {'x-opencode-ticket': '1'},
});
if (authorized.status !== 200) throw new Error('PTY ticket: ' + authorized.status);
const {ticket} = await authorized.json();
if (!ticket) throw new Error('PTY ticket missing');
return await new Promise((resolve, reject) => {
const url = new URL(base + '/pty/' + pty.id + '/connect');
url.searchParams.set('ticket', ticket);
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
const socket = new WebSocket(url);
const timer = setTimeout(() => { socket.close(); reject(new Error('PTY output timed out')); }, 10000);