refactor: remove redundant comments and docstrings (#6527)
* refactor: remove redundant comments and docstrings * fix(signal): annotate async context manager as a generator
This commit is contained in:
1 parent
cb3ba45317
commit
a4d2430140
922 files changed
+406
-7738
No files matched your search
@@ -1,5 +1,3 @@
|
||||
"""Identity-bound local HTTP readiness; ordinary legacy health remains compatible."""
|
||||
|
||||
import json
|
||||
import threading
|
||||
from dataclasses import asdict, replace
|
||||
@@ -49,7 +47,7 @@ def test_restart_requires_identity_while_legacy_health_still_works(tmp_path, hea
|
||||
with runtime.foreground_instance(GatewayStartOptions(port=port)):
|
||||
runtime.publish_health_host("127.0.0.1")
|
||||
assert _gateway_health_ready("127.0.0.1", port)
|
||||
assert not runtime.verify_ready(identity) # Older / unrelated HTTP 200.
|
||||
assert not runtime.verify_ready(identity)
|
||||
reply["body"] = json.dumps({
|
||||
"status": "ok", "ready": True,
|
||||
"runtime": {**asdict(identity), "future_optional_field": "ignored"},
|
||||
@@ -61,7 +59,7 @@ def test_restart_requires_identity_while_legacy_health_still_works(tmp_path, hea
|
||||
replace(identity, version="0.3.5"),
|
||||
):
|
||||
assert not runtime.verify_ready(wrong)
|
||||
assert not runtime.verify_ready(identity) # Port alone outlives its owner.
|
||||
assert not runtime.verify_ready(identity)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status,body", [
|
||||
|
||||
@@ -50,7 +50,6 @@ def _paths(tmp_path: Path) -> GatewayRuntimePaths:
|
||||
|
||||
|
||||
def test_runtime_state_publish_keeps_existing_snapshot_readable(tmp_path):
|
||||
"""Status polling must not prevent a gateway from publishing readiness."""
|
||||
from nanobot.utils.atomic_file import _open_snapshot
|
||||
|
||||
runtime = GatewayRuntime(paths=_paths(tmp_path / "网关 home"))
|
||||
@@ -67,7 +66,6 @@ def test_runtime_state_publish_keeps_existing_snapshot_readable(tmp_path):
|
||||
|
||||
|
||||
def test_runtime_state_reader_does_not_block_publish_while_decoding(tmp_path, monkeypatch):
|
||||
"""Pause a real status read while a readiness update replaces its record."""
|
||||
runtime = GatewayRuntime(paths=_paths(tmp_path))
|
||||
previous = {"pid": os.getpid(), "identity": "fixture"}
|
||||
current = {**previous, "health_host": "127.0.0.1"}
|
||||
@@ -554,7 +552,6 @@ def test_restart_stops_then_starts_the_background_gateway(tmp_path, monkeypatch)
|
||||
|
||||
|
||||
def test_client_lease_reader_keeps_snapshot_during_replacement(tmp_path, monkeypatch):
|
||||
"""A real lease read retains its contents while a writer publishes the next state."""
|
||||
from contextlib import contextmanager
|
||||
|
||||
from nanobot.utils import atomic_file
|
||||
@@ -803,7 +800,6 @@ def test_lease_queries_filter_a_reused_client_pid_without_writing(
|
||||
if auto_stop:
|
||||
client.mark_ephemeral()
|
||||
original = client.state_path.read_bytes()
|
||||
# An old timestamp detects same-content rewrites without timing sleeps.
|
||||
os.utime(client.state_path, (1, 1))
|
||||
modified_at = client.state_path.stat().st_mtime_ns
|
||||
|
||||
@@ -853,7 +849,7 @@ def test_darwin_lease_keeps_old_readers_compatible_and_detects_pid_reuse(
|
||||
state = json.loads(client.state_path.read_text(encoding="utf-8"))
|
||||
record = state["clients"]["client"]
|
||||
|
||||
assert record["identity"] is None # Pre-upgrade lease readers keep the live PID.
|
||||
assert record["identity"] is None
|
||||
assert record["stable_identity"] == identity
|
||||
|
||||
identity = "darwin:42:1786992348:654321"
|
||||
@@ -1420,7 +1416,6 @@ def test_terminate_windows_targets_only_the_recorded_process_tree(tmp_path, monk
|
||||
|
||||
def fake_wait_for_exit(_pid, _timeout_s):
|
||||
wait_timeouts.append(_timeout_s)
|
||||
# Simulate a process that exits only after its tree is forcibly terminated.
|
||||
return bool(taskkill_calls)
|
||||
|
||||
monkeypatch.setattr(runtime, "_wait_for_exit", fake_wait_for_exit)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
"""Exercise Windows gateway shutdown through real, isolated CLI processes."""
|
||||
|
||||
import asyncio
|
||||
import ctypes
|
||||
import http.client
|
||||
@@ -130,7 +128,7 @@ def _event_security(handle: int) -> str:
|
||||
) == 0
|
||||
assert security.OpenProcessToken(kernel.GetCurrentProcess(), 0x0008, ctypes.byref(token))
|
||||
size = wintypes.DWORD()
|
||||
security.GetTokenInformation(token, 1, None, 0, ctypes.byref(size)) # TokenUser
|
||||
security.GetTokenInformation(token, 1, None, 0, ctypes.byref(size))
|
||||
assert size.value > 0
|
||||
user = ctypes.create_string_buffer(size.value)
|
||||
assert security.GetTokenInformation(token, 1, user, len(user), ctypes.byref(size))
|
||||
@@ -163,7 +161,7 @@ def test_shutdown_signal_is_private_process_bound_and_latched(tmp_path: Path) ->
|
||||
assert signal is not None and signal._handle is not None
|
||||
owner, dacl = _event_security(signal._handle)[2:].split("D:", 1)
|
||||
assert dacl.startswith("P(A;;") and dacl.endswith(f";;;{owner})")
|
||||
assert dacl.count("(") == 1 # One owner-only allow ACE, no inherited grants.
|
||||
assert dacl.count("(") == 1
|
||||
assert request_windows_shutdown(pid + 1, identity, token) is False
|
||||
assert request_windows_shutdown(pid, identity + "1", token) is False
|
||||
other = WindowsShutdownEvent(pid, identity)
|
||||
@@ -173,7 +171,7 @@ def test_shutdown_signal_is_private_process_bound_and_latched(tmp_path: Path) ->
|
||||
kernel = ctypes.WinDLL("kernel32", use_last_error=True)
|
||||
kernel.WaitForSingleObject.argtypes = [wintypes.HANDLE, wintypes.DWORD]
|
||||
kernel.WaitForSingleObject.restype = wintypes.DWORD
|
||||
assert kernel.WaitForSingleObject(other._handle, 0) == 258 # Still unsignaled.
|
||||
assert kernel.WaitForSingleObject(other._handle, 0) == 258
|
||||
finally:
|
||||
other.close()
|
||||
assert request_windows_shutdown(pid, identity, token) is True
|
||||
@@ -189,7 +187,7 @@ def test_cancelling_shutdown_listener_drains_its_native_wait(tmp_path: Path) ->
|
||||
async def cancel_listener() -> None:
|
||||
shutdown = asyncio.Event()
|
||||
listener = asyncio.create_task(runtime.wait_for_shutdown_request(shutdown))
|
||||
await asyncio.sleep(0) # Admit the wait before exercising ordinary runtime cancellation.
|
||||
await asyncio.sleep(0)
|
||||
listener.cancel()
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await asyncio.wait_for(listener, timeout=2)
|
||||
@@ -265,9 +263,9 @@ def test_windows_stop_forces_only_its_stalled_tree(tmp_path: Path, published: bo
|
||||
assert process.wait(timeout=5) != 0
|
||||
assert not runtime.process_is_running(child_pid)
|
||||
assert not runtime.paths.state_path.exists()
|
||||
assert elapsed < 5 # Missing signals must not consume the 20-second grace.
|
||||
assert elapsed < 5
|
||||
if published:
|
||||
assert elapsed >= 1 # A delivered request retains the caller's grace period.
|
||||
assert elapsed >= 1
|
||||
finally:
|
||||
if process.poll() is None:
|
||||
runtime.stop(timeout_s=0)
|
||||
|
||||
Reference in new issue
Block a user