test(opencode): add adapter contract, TUI readiness, and lifecycle integration tests

This commit is contained in:
2026-08-29 14:59:04 +09:00
parent 94af7f6b8a
commit de2c0e6824
5 changed files with 495 additions and 15 deletions
+52 -9
View File
@@ -533,13 +533,6 @@ elif cmd1 == "agent":
sys.stderr.write(json.dumps(err_payload) + "\\n")
sys.exit(1)
# TUI Welcome Tokens definition to prevent TUI readiness check timeout
buffer_content = {
"claude": "Anthropic Claude Ready",
"agy": "Antigravity Ready",
"hermes": "Hermes Ready"
}.get(agent_type, "Ready")
# Look up cwd from target pane in state if not explicitly passed
if not cwd and pane:
for p in state.get("panes", []):
@@ -550,6 +543,16 @@ elif cmd1 == "agent":
if not ws and pane and ":" in pane:
ws = pane.split(":")[0]
# TUI Welcome Tokens definition to prevent TUI readiness check timeout
resolved_cwd = cwd or "TMP_PATH_PLACEHOLDER"
buffer_content = {
"claude": f"Anthropic Claude Ready in {resolved_cwd}",
"agy": f"Antigravity Ready in {resolved_cwd}",
"hermes": f"Hermes Ready in {resolved_cwd}",
"grok": f"Grok Ready in {resolved_cwd}",
"opencode": f"OpenCode Ready in {resolved_cwd}"
}.get(agent_type, f"Ready in {resolved_cwd}")
agents = state.get("agents", {})
agents[name] = {
"agent": agent_type,
@@ -576,7 +579,9 @@ elif cmd1 == "agent":
own_key_map = {
"claude": "claude_session_id_own",
"agy": "agy_conversation_id_own",
"hermes": "hermes_conversation_id_own"
"hermes": "hermes_conversation_id_own",
"grok": "grok_session_id_own",
"opencode": "opencode_session_id_own"
}
own_key = own_key_map.get(agent_type)
if own_key:
@@ -627,6 +632,16 @@ elif cmd1 == "agent":
conn.execute("INSERT OR REPLACE INTO sessions (id, cwd) VALUES (?, ?)", (session_uuid, ws_abs))
conn.commit()
conn.close()
elif agent_type == "opencode":
opencode_dir = os.path.join(home_dir, ".local", "share", "opencode")
os.makedirs(opencode_dir, exist_ok=True)
odb = os.path.join(opencode_dir, "opencode.db")
conn = sqlite3.connect(odb)
conn.execute("CREATE TABLE IF NOT EXISTS session (id TEXT PRIMARY KEY, directory TEXT, time_created INTEGER, cwd TEXT, created_at REAL)")
now_ms = int(time.time() * 1000)
conn.execute("INSERT OR REPLACE INTO session (id, directory, time_created, cwd, created_at) VALUES (?, ?, ?, ?, ?)", (session_uuid, ws_abs, now_ms, ws_abs, time.time()))
conn.commit()
conn.close()
state["agents"] = agents
save_state()
@@ -946,7 +961,35 @@ sys.exit(0)
""")
hermes_bin.chmod(0o755)
# 4. uuidgen mock to guarantee isolated creation UUIDs
# 4. grok mock
grok_bin = bin_dir / "grok"
grok_bin.write_text("""#!/usr/bin/env python3
import sys
sys.exit(0)
""")
grok_bin.chmod(0o755)
# 5. opencode mock
opencode_bin = bin_dir / "opencode"
opencode_bin.write_text("""#!/usr/bin/env python3
import sys, os
args = sys.argv[1:]
if len(args) >= 2 and args[0] == "db" and args[1] == "path":
home = os.environ.get("HOME", "")
db_path = f"{home}/.local/share/opencode/opencode.db"
os.makedirs(os.path.dirname(db_path), exist_ok=True)
if not os.path.exists(db_path):
import sqlite3
conn = sqlite3.connect(db_path)
conn.execute("CREATE TABLE IF NOT EXISTS session (id TEXT PRIMARY KEY, directory TEXT, time_created INTEGER)")
conn.close()
print(db_path)
sys.exit(0)
sys.exit(0)
""")
opencode_bin.chmod(0o755)
# 6. uuidgen mock to guarantee isolated creation UUIDs
uuidgen_bin = bin_dir / "uuidgen"
uuidgen_bin.write_text("""#!/usr/bin/env python3
import uuid