test(opencode): the 2.x schema and CLI, a fake opencode, and an opt-in real-binary contract (Issue #60)
tests/_fake_opencode.py implements the two commands MAM calls (debug paths, session delete) as measured on 2.0.32; unit tests never run a real opencode (it would migrate the test database). test_real_opencode_2x_contract runs a real 2.x opencode, when installed, in a home and tmp dir of its own with --standalone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VCgu9Fa9iT7TbJUSzdq4Ff
This commit is contained in:
1 parent
a311c23303
commit
f0d1c000f9
5 files changed
+353
-147
No files matched your search
+5
-21
@@ -131,6 +131,7 @@ if _TESTS_DIR not in sys.path:
|
||||
sys.path.insert(0, _TESTS_DIR)
|
||||
import _mam_state_guard # noqa: E402
|
||||
import _agent_home_guard # noqa: E402
|
||||
import _fake_opencode # noqa: E402
|
||||
|
||||
_BINDING_VARS = ("WORKSPACE_ROOT", "AGENT_SESSIONS_YAML", "MAM_JOBS_DIR", "DELEGATE_JOB_LOGS_DIR")
|
||||
_RECORDED_BINDING = {}
|
||||
@@ -971,9 +972,9 @@ elif cmd1 == "agent":
|
||||
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)")
|
||||
conn.execute("CREATE TABLE IF NOT EXISTS session_v2 (id TEXT PRIMARY KEY, parent_id TEXT, directory TEXT, time_created INTEGER)")
|
||||
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.execute("INSERT OR REPLACE INTO session_v2 (id, directory, time_created) VALUES (?, ?, ?)", (session_uuid, ws_abs, now_ms))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
elif agent_type == "codex":
|
||||
@@ -1466,25 +1467,8 @@ 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)
|
||||
# 5. opencode mock (the 2.x commands MAM calls, Issue #60)
|
||||
_fake_opencode.write(bin_dir / "opencode")
|
||||
|
||||
# 6. codex mock
|
||||
codex_bin = bin_dir / "codex"
|
||||
|
||||
Reference in new issue
Block a user