fix: use lookbehind anchor so binary-decoded and remote-read content still scans
The separator-class anchor broke two fail-closed tests (binary bytes decode to U+FFFD adjacent to the CLI name; remote head-c reads). A negative lookbehind excluding path/word chars keeps the #77173 fix while preserving every fail-closed content-scan path.
This commit is contained in:
@@ -64,13 +64,13 @@ _GATEWAY_LIFECYCLE_PATTERN = re.compile(
|
||||
# `start` is intentionally excluded: starting a gateway from inside a
|
||||
# gateway is benign (a no-op or "already running" error), and a
|
||||
# legitimate cron job might start a sibling profile's gateway.
|
||||
# The leading separator class (#77173): `hermes` must sit at command
|
||||
# position — start of text, after whitespace/`;`/`&`/`|`, or inside a
|
||||
# substitution/subshell opener — not be a path component. Without it, a
|
||||
# file path with embedded spaces like `/docs/hermes gateway
|
||||
# restart-notes.md` matched via the `/hermes` tail and hard-blocked an
|
||||
# innocent `cat`.
|
||||
r"(?:(?:^|[\s;&|(`])hermes\s+gateway\s+(?:restart|stop)\b)"
|
||||
# The lookbehind (#77173): `hermes` must not be a path component or a
|
||||
# word tail. Excluding `/`, word chars, `.` and `-` keeps file paths
|
||||
# with embedded spaces (`/docs/hermes gateway restart-notes.md`) from
|
||||
# matching via the `/hermes` tail, while every real command position
|
||||
# (start of text, whitespace, `;`/`&`/`|`, `$(`, backtick, even a
|
||||
# U+FFFD from binary-content decoding) still matches.
|
||||
r"(?:(?<![/\w.\-])hermes\s+gateway\s+(?:restart|stop)\b)"
|
||||
# Branch B: launchctl ops on a hermes-gateway label. macOS launchd
|
||||
# labels look like `ai.hermes.gateway` / `hermes-gateway`. Requiring the
|
||||
# gateway identifier prevents blocking unrelated hermes services (e.g.
|
||||
|
||||
@@ -1404,7 +1404,7 @@ class TestTerminalToolGatewayLifecycleGuardRemote:
|
||||
def execute(self, command, **kwargs):
|
||||
calls.append(command)
|
||||
if "head -c" in command and "/remote/workspace/remote.sh" in command:
|
||||
return {"output": "#!/bin/bash\\nhermes gateway restart\\n", "returncode": 0}
|
||||
return {"output": "#!/bin/bash\nhermes gateway restart\n", "returncode": 0}
|
||||
return {"output": "", "returncode": 0}
|
||||
|
||||
fake_env = _RemoteEnv()
|
||||
|
||||
Reference in New Issue
Block a user