Skip to content

The agent that grows with you

fix(gateway): decode the re-entered .cmd launcher directly; keep the base64 form untouched in the test

Tekniumf55f8d4e4ce4
diff --git a/gateway/status_inline_source.py b/gateway/status_inline_source.py
index 14d7eb4d37d..f661e6fe0cc 100644
--- a/gateway/status_inline_source.py
+++ b/gateway/status_inline_source.py
@@ -118,8 +118,13 @@ def _bootstrap_entry(source: str, argv: list[str]) -> list[str] | None:
# ``/n``), so it is matched in place by the launcher row's anchors, never decoded.
if assigned := _ASSIGNED_ARGV.search(source):
argv = [item.strip().strip("'\"") for item in assigned.group(1).split(",")][1:]
- if wrapped := _EXEC_BASE64.search(target):
- return _bootstrap_entry(f"import base64; exec(base64.b64decode('{wrapped['b64']}'))", argv)
+ if wrapped := _EXEC_BASE64.search(target): # the .cmd launcher: its script, base64-encoded
+ import base64
+ import binascii
+ try:
+ return _bootstrap_entry(base64.b64decode(wrapped["b64"], validate=True).decode("utf-8"), argv)
+ except (binascii.Error, UnicodeDecodeError):
+ return None
launcher = _EXEC_LAUNCHER.search(target)
if launcher is None:
return None
diff --git a/tests/gateway/test_gateway_inline_bootstrap_identity.py b/tests/gateway/test_gateway_inline_bootstrap_identity.py
index 4be6775fb2a..c51d5808048 100644
--- a/tests/gateway/test_gateway_inline_bootstrap_identity.py
+++ b/tests/gateway/test_gateway_inline_bootstrap_identity.py
@@ -23,24 +23,23 @@ from hermes_cli.update_cmd_windows import _hermes_holder_subcommand
ROOT = Path("/opt/Hermes Agent/hermes-agent")
PY = "/opt/venv/bin/python3"
_SCRIPT = _launchers._launcher_script("hermes", ROOT, None)
-_B64 = f"import base64; exec(base64.b64decode('{base64.b64encode(_SCRIPT.encode()).decode()}'))"
_JOINS = {"space-joined": " ".join, "windows": subprocess.list2cmdline}
def _forms(argv: list[str]) -> dict[str, list[str]]:
- return {
+ forms = {
"store-launcher": _launchers.runtime_command(ROOT, argv, python=Path(PY)),
"launcher-script": [PY, "-I", "-c", _SCRIPT, *argv],
- "cmd-launcher": [PY, "-I", "-c", _B64, *argv],
+ "cmd-launcher": [PY, "-I", "-c", f"import base64; exec(base64.b64decode('{base64.b64encode(_SCRIPT.encode()).decode()}'))", *argv],
"venv-reentry": venv_sync.relaunch_command(
Path(PY), ROOT, [str(ROOT / "hermes_cli" / "main.py"), *argv], ["/old/python", "-m", "hermes_cli.main", *argv],
"hermes_cli.main"),
- # A launch through the published launcher that synced dependencies first re-enters it via exec().
- "venv-reentry-launcher": venv_sync.relaunch_command(
- Path(PY), ROOT, ["-c", *argv], ["/old/python", "-I", "-c", _SCRIPT, *argv], None),
- "venv-reentry-cmd-launcher": venv_sync.relaunch_command(
- Path(PY), ROOT, ["-c", *argv], ["/old/python", "-I", "-c", _B64, *argv], None),
}
+ # A launch through a published launcher that synced dependencies first re-enters it via exec().
+ for name in ("launcher-script", "cmd-launcher"):
+ forms[f"venv-reentry-{name}"] = venv_sync.relaunch_command(
+ Path(PY), ROOT, ["-c", *argv], ["/old/python", *forms[name][1:]], None)
+ return forms
@pytest.mark.parametrize("join", _JOINS)