Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ga_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def launch_frontend(cmd_parts, args=None):
# 插入额外参数
if args:
full_cmd.extend(args)
if full_cmd and full_cmd[0] == "python":
full_cmd[0] = sys.executable

print(f"🚀 {' '.join(full_cmd)}")
sys.stdout.flush()
Expand Down
32 changes: 32 additions & 0 deletions tests/test_ga_cli_interpreter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys
import unittest
from unittest import mock

from ga_cli import cli


class GaCliInterpreterTests(unittest.TestCase):
def test_python_launcher_uses_current_interpreter(self):
proc = mock.Mock()
with mock.patch.object(cli.subprocess, "Popen", return_value=proc) as popen, \
mock.patch.object(cli.os, "chdir"):
cli.launch_frontend(["python", "{PROJECT_DIR}/agentmain.py"], ["--help"])

popen.assert_called_once()
command = popen.call_args.args[0]
self.assertEqual(command[0], sys.executable)
self.assertTrue(command[1].endswith("agentmain.py"))
self.assertEqual(command[2:], ["--help"])
proc.wait.assert_called_once_with()

def test_non_python_launcher_is_not_rewritten(self):
proc = mock.Mock()
with mock.patch.object(cli.subprocess, "Popen", return_value=proc) as popen, \
mock.patch.object(cli.os, "chdir"):
cli.launch_frontend(["custom-runtime", "script"], None)

self.assertEqual(popen.call_args.args[0][0], "custom-runtime")


if __name__ == "__main__":
unittest.main()