Skip to content

The agent that grows with you

test: cover encoded socket limits with direct control paths

Teknium34407c9ec6ca
diff --git a/gateway/shutdown_watchdog.py b/gateway/shutdown_watchdog.py
index 21b883e1f21..0d6e2b32e00 100644
--- a/gateway/shutdown_watchdog.py
+++ b/gateway/shutdown_watchdog.py
@@ -337,9 +337,9 @@ async def loop_heartbeat_forever(
# loopback transport when AF_UNIX is unavailable or the encoded address will not fit;
# consumers already discover this port in the heartbeat, independent of their TMPDIR.
from gateway.control_socket import _fits_sun_path
- unix_path = get_loop_tick_socket_path(home) if os.name == "posix" else None
tick_server = tick_socket_path = tick_tcp_port = None
try:
+ unix_path = get_loop_tick_socket_path(home) if os.name == "posix" else None
if unix_path is not None and _fits_sun_path(unix_path):
tick_socket_path = unix_path
tick_socket_path.parent.mkdir(parents=True, exist_ok=True)
diff --git a/tests/gateway/test_runtime_token_identity.py b/tests/gateway/test_runtime_token_identity.py
index 7be634d94f9..b3df6cb1f36 100644
--- a/tests/gateway/test_runtime_token_identity.py
+++ b/tests/gateway/test_runtime_token_identity.py
@@ -87,7 +87,13 @@ def test_ordinary_daemon_keeps_control_auth_and_loop_witness(tmp_path, layout):
# A normal-path control, not a substitute for the deliberately long cases.
with tempfile.TemporaryDirectory(prefix='hgw-') as short:
- home = Path(short) if layout == 'normal' else tmp_path / ('界' * 60 if layout == 'unicode' else 'x' * 120)
+ if layout == 'normal':
+ home = Path(short)
+ elif layout == 'unicode':
+ # The character count fits even though the encoded tick address does not.
+ home = Path(short) / ('界' * 20)
+ else:
+ home = tmp_path / ('x' * 120)
home.mkdir(mode=0o700, exist_ok=True)
user = tmp_path / 'user'
user.mkdir()
@@ -124,6 +130,7 @@ def test_ordinary_daemon_keeps_control_auth_and_loop_witness(tmp_path, layout):
assert descriptor.get('state') == 'ready', (descriptor, log.read())
assert descriptor['pid'] == process.pid
control_path = resolve_client_socket_path(home)
+ assert control_path is not None
assert control_path.stat().st_mode & 0o077 == 0
if control_path.parent != home:
assert control_path.parent.stat().st_mode & 0o077 == 0
@@ -132,7 +139,9 @@ def test_ordinary_daemon_keeps_control_auth_and_loop_witness(tmp_path, layout):
while not heartbeat.exists() and time.monotonic() < deadline:
time.sleep(.05)
payload = json.loads(heartbeat.read_text())
+ tick_path = get_loop_tick_socket_path(home, process.pid)
receipt = {'layout': layout, 'home_bytes': len(os.fsencode(home)),
+ 'tick_chars': len(str(tick_path)), 'tick_bytes': len(os.fsencode(tick_path)),
'control': str(control_path), 'created_session': sid,
'loop_tick_socket': payload['loop_tick_socket'],
'loop_tick_tcp_port': payload['loop_tick_tcp_port']}
@@ -155,7 +164,7 @@ def test_ordinary_daemon_keeps_control_auth_and_loop_witness(tmp_path, layout):
peer.settimeout(2)
assert peer.connect_ex(address) != 0
else:
- assert not Path(address).exists()
+ assert not get_loop_tick_socket_path(home, process.pid).exists()
finally:
if process.poll() is None:
process.terminate()