fix(e2e): finalize sqlite concurrency locking, mock_herdr atomic state, and e2e test suite (100% PASS)

This commit is contained in:
2026-08-07 22:39:23 +09:00
parent ab00be4ad2
commit 68f43349be
7 changed files with 266 additions and 71 deletions
+45 -10
View File
@@ -89,21 +89,35 @@ if not os.path.exists(state_file):
lock_f = open(state_file + ".lock", "w")
fcntl.flock(lock_f, fcntl.LOCK_EX)
with open(state_file, 'r') as f:
state = json.load(f)
state = {"workspaces": [], "agents": {}, "calls": []}
if os.path.exists(state_file):
for _retry in range(10):
try:
with open(state_file, 'r') as f:
content = f.read().strip()
if content:
state = json.loads(content)
break
except Exception:
import time
time.sleep(0.05)
# Record the command call
state["calls"].append(sys.argv[1:])
def save_state():
with open(state_file, 'w') as f:
tmp_state = state_file + f".tmp.{os.getpid()}"
with open(tmp_state, 'w') as f:
json.dump(state, f, indent=2)
f.flush()
os.fsync(f.fileno())
os.replace(tmp_state, state_file)
# Save calls immediately so they persist even if we exit early or error out
save_state()
args = sys.argv[1:]
if args and args[0] == "--session":
while args and args[0] in ("-L", "--server", "-s", "--session"):
if len(args) > 1:
args = args[2:]
else:
@@ -227,7 +241,7 @@ elif cmd1 == "agent":
"cwd": cwd or "TMP_PATH_PLACEHOLDER",
"workspace_id": ws or "w1",
"pid": 9999,
"pane_id": "w1:p1",
"pane_id": f"w1:p{len(agents)+1}",
"command": " ".join(agent_cmd),
"buffer": buffer_content
}
@@ -259,7 +273,7 @@ elif cmd1 == "agent":
os.makedirs(proj_dir, exist_ok=True)
jsonl_file = os.path.join(proj_dir, f"{session_uuid}.jsonl")
with open(jsonl_file, 'w') as jf:
jf.write(json.dumps({"sessionId": session_uuid}) + "\\\\n")
jf.write(json.dumps({"sessionId": session_uuid}) + "\\n")
elif agent_type == "agy":
db_dir = os.path.join(home_dir, ".gemini", "antigravity-cli", "conversations")
os.makedirs(db_dir, exist_ok=True)
@@ -307,6 +321,7 @@ elif cmd1 == "agent":
sys.exit(1)
name = args[2]
agents = state.get("agents", {})
sys.stderr.write(f"[mock_herdr] agent get '{name}' — known agents: {list(agents.keys())}\\n")
if name in agents:
agent_data = agents[name]
pane_info = {
@@ -365,9 +380,19 @@ elif cmd1 == "agent":
sys.exit(1)
elif cmd1 == "session":
if len(args) < 2:
sys.exit(0)
cmd2 = args[1]
if cmd2 == "list":
session_names = ["custom_server", "default", "multi-agent-mux"]
session_names.extend(list(state.get("agents", {}).keys()))
if os.environ.get("MAM_SESS"):
session_names.append(os.environ["MAM_SESS"])
res = {"sessions": [{"name": s, "running": True} for s in set(session_names)]}
print(json.dumps(res))
sys.exit(0)
if len(args) < 3:
sys.exit(1)
cmd2 = args[1]
name = args[2]
agents = state.get("agents", {})
if cmd2 == "stop":
@@ -456,13 +481,23 @@ elif cmd1 == "list-panes":
else:
sys.exit(1)
elif cmd1 == "has-session":
sess_target = ""
if "-t" in args:
sess_target = args[args.index("-t") + 1]
elif len(args) > 1:
sess_target = args[1]
agents = state.get("agents", {})
if sess_target in agents:
sys.exit(0)
else:
sys.exit(1)
elif cmd1 == "ls":
if "-F" in args:
for name, data in state.get("agents", {}).items():
print(f"{name}|999999")
print(name + "|999999")
sys.exit(0)
with open("/tmp/debug_mock_herdr.log", "a") as f_debug:
f_debug.write(f"ARGS: {sys.argv[1:]} | AGENTS: {list(state.get('agents', {}).keys())} | PATH: {os.path.exists(state_file)}\\n")
agents_list = []
for name, data in state.get("agents", {}).items():
agents_list.append({