wip test stabalization is a mess still

This commit is contained in:
2026-03-03 23:53:53 -05:00
parent c0a8777204
commit 3203891b79
17 changed files with 263 additions and 422 deletions

View File

@@ -42,42 +42,45 @@ class GeminiCliAdapter:
env = os.environ.copy()
env["GEMINI_CLI_HOOK_CONTEXT"] = "manual_slop"
import shlex
# shlex.split handles quotes correctly even on Windows if we are careful.
# We want to split the entire binary_path into its components.
if os.name == 'nt':
# On Windows, shlex.split with default posix=True might swallow backslashes.
# Using posix=False is better for Windows paths.
cmd_list = shlex.split(self.binary_path, posix=False)
else:
cmd_list = shlex.split(self.binary_path)
if model:
cmd_list.extend(['-m', model])
cmd_list.extend(['--prompt', '""'])
if self.session_id:
cmd_list.extend(['--resume', self.session_id])
cmd_list.extend(['--output-format', 'stream-json'])
# Filter out empty strings and strip quotes (Popen doesn't want them in cmd_list elements)
cmd_list = [c.strip('"') for c in cmd_list if c]
process = subprocess.Popen(
command,
cmd_list,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
shell=True,
env=env,
bufsize=1 # Line buffered
encoding="utf-8",
shell=False,
env=env
)
# Use a thread or just communicate if we don't need real-time for stdin.
# But we must read stdout line by line to avoid blocking the main thread
# if this were called from the main thread (though it's usually in a background thread).
# The issue is that process.communicate blocks until the process exits.
# We want to process JSON lines as they arrive.
# Use communicate to avoid pipe deadlocks with large input/output.
# This blocks until the process exits, so we lose real-time streaming,
# but it's much more robust. We then simulate streaming by processing the output.
stdout_final, stderr_final = process.communicate(input=prompt_text)
import threading
def write_stdin():
try:
process.stdin.write(prompt_text)
process.stdin.close()
except: pass
stdin_thread = threading.Thread(target=write_stdin, daemon=True)
stdin_thread.start()
# Read stdout line by line
while True:
line = process.stdout.readline()
if not line and process.poll() is not None:
break
if not line:
continue
for line in stdout_final.splitlines():
line = line.strip()
if not line: continue
stdout_content.append(line)
try:
data = json.loads(line)
@@ -108,11 +111,6 @@ class GeminiCliAdapter:
except json.JSONDecodeError:
continue
# Read remaining stderr
stderr_final = process.stderr.read()
process.wait()
current_latency = time.time() - start_time
session_logger.open_session()
session_logger.log_cli_call(