fix(tests): keep the leak registry in hermes_state_guard and skip shared handles

Rebase follow-up. hermes_state.py is a facade now; the test-isolation
guard code the registry sits beside moved to hermes_state_guard.py, so
the WeakSet and _register_test_instance live there (gated on the same
_TEST_ISOLATION_MARKER_ENV the guard already owns) and the facade only
calls the helper from __init__.

The sweep now skips instances flagged _shared_registry_owned: since
#90837 close() on a hermes_state_registry.acquire() handle releases a
refcount instead of closing, so sweeping them would retire a shared
generation that a wider-scoped fixture still holds. The registry owns
that lifecycle (close_all()).

Per Enough1122's nit, the registry comment states explicitly that
production never populates it and that the gate must not be removed.
This commit is contained in:
teknium1
2026-09-14 19:06:16 -07:00
committed by Teknium
parent d070e480a3
commit d12cec1833
+1 -1
View File
@@ -37,7 +37,7 @@ from hermes_state_errors import (
)
from hermes_state_guard import (
_STATE_DB_GUARD_BYPASS_ENV, _in_test_context, _is_production_state_db, _real_platform_state_root,
_register_test_instance, _set_last_init_error, _test_instance_registry, get_last_init_error,
_register_test_instance, _set_last_init_error, get_last_init_error,
)
from hermes_state_readpool import _READ_POOL_MAX, _proc_fd_targets, _read_budget_for
from hermes_state_sessions import SessionSessionsMixin