77import socket
88import subprocess
99import sys
10+ import tempfile
1011import time
1112
1213SCRIPTS = Path (__file__ ).resolve ().parent
@@ -40,6 +41,11 @@ def __init__(self, binary, root):
4041 self .binary = str (Path (binary ).resolve ())
4142 self .root = Path (root ).resolve ()
4243 self .root .mkdir (parents = True )
44+ # Unix sockets have a 108-byte path limit. Keep ephemeral sockets out of
45+ # arbitrarily deep artifact paths, while retaining all logs in root.
46+ self .runtime = tempfile .TemporaryDirectory (prefix = "jca-" , dir = "/tmp" )
47+ for side in ("local" , "cloud" ):
48+ (Path (self .runtime .name ) / side ).mkdir ()
4349 self .children = []
4450 self .files = []
4551 self .env = {"PATH" : "/usr/bin:/bin" , "LANG" : "C.UTF-8" , "TERM" : "xterm-256color" ,
@@ -49,10 +55,10 @@ def __init__(self, binary, root):
4955 self .repo = self .root / "local-repo"
5056 self .cloud_repo = self .root / "cloud-repo"
5157 self .control = self .root / "control"
52- self .sock = str (self .root / "tmux.sock" )
58+ self .sock = str (Path ( self .runtime . name ) / "tmux.sock" )
5359 self .sid = None
54- for name in ("local-repo" , "cloud-repo" , "local-home" , "cloud-home" , "local-run" ,
55- "cloud-run" , " control" , "ssh" , "bin" ):
60+ for name in ("local-repo" , "cloud-repo" , "local-home" , "cloud-home" ,
61+ "control" , "ssh" , "bin" ):
5662 (self .root / name ).mkdir ()
5763
5864 def checkpoint (self , message ):
@@ -159,7 +165,7 @@ def start(self):
159165 (self .root / "ssh/known_hosts" ).write_text (f"[127.0.0.1]:{ ssh_port } { host_key } \n " )
160166 cloud_env = dict (self .env , ** model_env , HOME = str (self .root / "cloud-home" ),
161167 JCODE_HOME = str (self .root / "cloud-home" ),
162- JCODE_RUNTIME_DIR = str (self .root / "cloud-run " ),
168+ JCODE_RUNTIME_DIR = str (Path ( self .runtime . name ) / "cloud" ),
163169 JCODE_CLOUD_HOST_LABEL = "cloud-acceptance" )
164170 # Same absolute workspace path on separate disks. This is a real SSH
165171 # command, not the JCODE_CLOUD_TRANSPORT override used by CLI tests.
@@ -214,7 +220,7 @@ def start(self):
214220 self .local_env = dict (self .env , ** model_env , HOME = str (self .root / "local-home" ),
215221 PATH = f"{ self .root } /bin:/usr/bin:/bin" ,
216222 JCODE_HOME = str (self .root / "local-home" ),
217- JCODE_RUNTIME_DIR = str (self .root / "local-run " ),
223+ JCODE_RUNTIME_DIR = str (Path ( self .runtime . name ) / "local" ),
218224 JCODE_CLOUD_HOST = "cloud-acceptance" , JCODE_CLOUD_HOST_LABEL = "laptop-acceptance" ,
219225 JCODE_CLOUD_REMOTE_BINARY = str (remote_binary ),
220226 JCODE_DEBUG_CMD_PATH = str (self .control / "debug.cmd" ),
@@ -230,7 +236,12 @@ def probe():
230236 command += '; result=$?; printf "\\ nJCODE_ACCEPTANCE_EXIT=%s\\ n" "$result"; sleep 600'
231237 self .tmux ("-f" , "/dev/null" , "new-session" , "-d" , "-s" , "acceptance" , "-x" , "160" , "-y" , "48" ,
232238 shlex .join (["/bin/bash" , "-c" , command ]))
233- wait_for (lambda : "Welcome to jcode" in self .frame () or "Ready to use" in self .frame (), "TUI startup" )
239+ def ready ():
240+ frame = self .frame ()
241+ if "JCODE_ACCEPTANCE_EXIT=" in frame :
242+ raise AssertionError ("TUI exited during startup; see frame.txt" )
243+ return "Welcome to jcode" in frame or "Ready to use" in frame
244+ wait_for (ready , "TUI startup" )
234245 if "Welcome to jcode" in self .frame ():
235246 self .tmux ("send-keys" , "-t" , "acceptance" , "Right" , "Enter" )
236247 self .wait_text ("Ready to use" )
@@ -323,7 +334,7 @@ def close(self):
323334 for side in ("local" , "cloud" ):
324335 env = dict (self .env , HOME = str (self .root / f"{ side } -home" ),
325336 JCODE_HOME = str (self .root / f"{ side } -home" ),
326- JCODE_RUNTIME_DIR = str (self .root / f" { side } -run" ))
337+ JCODE_RUNTIME_DIR = str (Path ( self .runtime . name ) / side ))
327338 try :
328339 subprocess .run ([self .binary , "--no-update" , "server" , "stop" ], env = env ,
329340 stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL , timeout = 10 )
@@ -367,6 +378,7 @@ def owned():
367378 raise AssertionError (f"Fixture processes survived cleanup: { remaining } " )
368379 for handle in self .files :
369380 handle .close ()
381+ self .runtime .cleanup ()
370382
371383
372384def idle_round_trip (t ):
0 commit comments