From cbdf1eb6db5e20c960bea43a89bc97b2f5d05874 Mon Sep 17 00:00:00 2001 From: goodboy Date: Mon, 27 Apr 2026 20:06:44 -0400 Subject: [PATCH] Guard `subint_forkserver` stub against re-alias MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `test_subint_forkserver_key_errors_cleanly` — a tn-tier regression guard that pins down the variant-2 reservation contract: the `'subint_forkserver'` key in `_spawn._methods` MUST raise `NotImplementedError` today, not silently dispatch to `main_thread_forkserver_proc`. The transient alias-state existed briefly during the rename (commit `57dae0e4`'s "Split forkserver backend into variant 1/2 mods" landed the alias; `5e83881f` flipped it to the stub). Without a guard, a future refactor could easily re-collapse the two keys back to a single coro and silently break the variant-1 / variant-2 contract. Also asserts the stub's error msg surfaces the two pointers an operator hitting it actually needs: - `'main_thread_forkserver'` — the working backend they prolly meant, - `'msgspec#1026'` — the upstream blocker that has to land before variant-2 can ship. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- tests/spawn/test_main_thread_forkserver.py | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/spawn/test_main_thread_forkserver.py b/tests/spawn/test_main_thread_forkserver.py index 2ccc3c6c..8371d67a 100644 --- a/tests/spawn/test_main_thread_forkserver.py +++ b/tests/spawn/test_main_thread_forkserver.py @@ -603,3 +603,50 @@ def test_orphaned_subactor_sigint_cleanup_DRAFT( proc.wait(timeout=2.0) except subprocess.TimeoutExpired: pass + + +# ---------------------------------------------------------------- +# regression guard: variant-2 (`subint_forkserver`) placeholder +# MUST raise `NotImplementedError` today — guards against future +# commits accidentally re-aliasing the key to the variant-1 +# coroutine (which was a transient state during the rename). +# ---------------------------------------------------------------- +def test_subint_forkserver_key_errors_cleanly() -> None: + ''' + `--spawn-backend=subint_forkserver` is reserved for the + eventual variant-2 (subint-isolated child runtime) + backend, gated on jcrist/msgspec#1026 unblocking PEP 684 + isolated-mode subints upstream. + + Until that lands, the dispatch entry MUST raise + `NotImplementedError` immediately rather than silently + aliasing to `main_thread_forkserver_proc`. Verify the + error message also surfaces both the working-backend + pointer and the upstream-blocker ref so an operator + arriving at the error has somewhere to go. + + ''' + import asyncio + from tractor.spawn._spawn import _methods + + proc = _methods['subint_forkserver'] + with pytest.raises(NotImplementedError) as ei: + # signature args match `main_thread_forkserver_proc`'s + # — the stub raises before touching them so dummy + # values are fine. + asyncio.run( + proc( + 'x', None, None, {}, [], + ('127.0.0.1', 0), {}, + ) + ) + + msg: str = str(ei.value) + assert 'main_thread_forkserver' in msg, ( + f'stub error msg should redirect to the working ' + f'variant-1 backend; got: {msg!r}' + ) + assert 'msgspec#1026' in msg or '1026' in msg, ( + f'stub error msg should reference the upstream ' + f'blocker (jcrist/msgspec#1026); got: {msg!r}' + )