Repository navigation
test: refuse fake tunnels' peer and health connects at once - #39236
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS This is a test-only change: it fails the fake tunnels' connects at once without touching the product code or any assertion, and it takes nothing away. Notes
[DESIGN-REVIEWED] aac861c Description read[DESCRIPTION-READ] 41e94fbfb69c6bcaad231ac854955eee31173a06cf5f341917438eb55a354e70 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
65aa36f to
86c58b4
Compare
|
Backend Tests (3.12, 8) red on 86c58b4 is main's, not this diff: |
test_remote_crew_chaining_chained_refresh_and_repair.py assigned _FakeMintSession.reply, a class attribute, and left it at a token of "T". A later test in the same process that reads the default reply, TestChainedToken::test_the_mint_asks_the_parent_by_the_parents_own_id_not_ours, then failed. Serial runs of both files on main fail that way every time. Setting the reply through monkeypatch restores it at teardown.
Fake tunnels bind nothing, so the peer-session prime after each connect (_exchange_link) dials a closed loopback port. Linux refuses that in under a millisecond; Windows retries the SYN and refuses after about 2 s, once per prime, across 152 tests in 17 files. closed_peer_helpers.refused_peer_connects replaces aiohttp only inside ssh_tunnel_manager_peer with a view whose ClientSession raises the same ClientConnectorError a refused connect raises, so the product's except branches still run. A test that swapped ClientSession itself keeps its stand-in, and the two tests that dial a real aiohttp server opt back out with real_peer_connects. test_app_off_contract.py refuses the health probe's connect to its unserved port 9301 at the opener, so probe and loopback_urlopen still run.
86c58b4 to
aac861c
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved. This review checked the following on aac861c:
- The
aiohttppatch goes through the ssh_tunnel_manager facade mirror. One write rebinds the child, peer and transport owners, and teardown restores all three. - The refusing session covers every
ClientSessioncall in that family (get,post, awaitedrequest,close,async with). It raises a realClientConnectorErrorwith ECONNREFUSED, so the product's except branches and the redial check run as before. - The four tests that need a real server or a real closed port opt out with
real_peer_connects. - The
build_loopback_openerpatch in test_app_off_contract takes effect at call time. - The
_FakeMintSession.replyfix restores the class default at teardown, and no other test leaks that attribute. - No assertion is loosened, and the PR adds no sleep, clock, port literal or environment write.
Done well: the PR measures its claims. It shows the same src line and branch coverage on both sides, a count of refused connects, and planted-bug runs that fail the same tests on main and on the branch.
Optional:
- Opt-in is per file, so a new test file that uses
_FakeTunnelwithout thepytestmarkline goes back to the slow connect without failing. A reply to the Design note could explain why a fixture in a helper module would still need an import in each file.
Problem / Motivation
Goal: The instance-tunnel and app-off tests stop waiting on Windows' closed-port SYN retry, with every check unchanged.
The tests' fake tunnels bind nothing. After each successful
SshTunnelManager.connect(), the manager primes the peer session (_exchange_link, an aiohttp GET to127.0.0.1:<local_port>), and that GET meets a closed port. Linux refuses it in under a millisecond. Windows retries the SYN and refuses after about 2 s, once per prime. On main that is 187 refused connects across 152 tests in 17 files.test_app_off_contract.pydoes the same through the app health probe: 16 tests dial port 9301, which nothing serves.Why it matters
The Windows shards that carry these files are among the slowest, and every PR waits on them. The closed-port waits come to about 320 s of worker time for the peer prime and about 32 s for the health probe (closed-port scan of main run 44329986204).
Not a goal
src/or totest/conftest.py.test_instances_orphan_reclaim.py's_forwarder_listener_goneandtest_remote_crew_chaining_credential_destination.py::test_an_unreachable_port_is_no_answer(which goes throughssh_tunnel_manager_transport, not the peer module).aiohttpmodule is not touched: real aiohttp servers run intest_instances_proxy.pyandtest_remote_crew_chaining_credential_destination.py.What changed (motivation → approach → change)
Closed port on Windows → about 2 s per connect → fail that connect at once, in the same way, so the product code takes the same path.
test/closed_peer_helpers.py.refused_peer_connectsreplacesaiohttpfor thessh_tunnel_managerfamily only, through the facade, whose mirror rebinds it in every owner that holds it (_child,_peer,_transport); patching one owner directly is whattest_facade_mirror_guards.pyforbids, because the facade's undo would restore the other owners to that owner's value. The replacement is a view that resolves every name to the real module exceptClientSession. Whileaiohttp.ClientSessionis the real class, the view returns a session whoseget/post/requestraiseaiohttp.ClientConnectorErrorbuilt the way aiohttp's connector builds it: a realConnectionKeyfor the URL's host and port, andConnectionRefusedError(ECONNREFUSED, "Connect call failed (host, port)"). Itsstr()andrepr()match a real refused connect byte for byte (checked against one locally), and the fixture asserts thatstr()renders before it patches anything. So_exchange_link's andtoken_validates' ownexceptbranches still run and logPeer link exchange failed (ClientConnectorError)as before. A test that already replacedaiohttp.ClientSessionwith its own fake keeps that fake, because the view passes any non-real class through.pytestmark = pytest.mark.usefixtures("refused_peer_connects"). Four tests opt back out with@pytest.mark.usefixtures("real_peer_connects"): the twotest_instances_proxy.pytests that call_exchange_linkagainst a real aiohttp server,test_the_crews_id_comes_back_through_two_hops(a real server through_transport), andtest_an_unreachable_port_is_no_answer, whose subject is a real refused connect.test_app_off_contract.py: an autouse fixture (patching through_floor_monkeypatch, so a test'smonkeypatch.undo()cannot lift it) wrapsloopback_http.build_loopback_openerso the opener'sopenraisesURLError(ConnectionRefusedError(ECONNREFUSED))for port 9301 only._health_probeandloopback_urlopenstill run and classify the same error. Tests that patch_health_probenever reach it.test_remote_crew_chaining_chained_refresh_and_repair.pyassigned_FakeMintSession.reply, a class attribute, and left it at a token of"T".test_remote_crew_chaining.py::TestChainedToken::test_the_mint_asks_the_parent_by_the_parents_own_id_not_oursthen failed in any process that ran it later. A serial run of the 18 files on main fails that test every time. The reply is now set throughmonkeypatch, which puts it back at teardown.Rejected: patching the global
aiohttp.ClientSession(it would break the real servers above), and having the fake tunnels bind a real listener (their ports are fixed and would collide across workers).Backwards compatibility
Compatible: test files only.
Removes nothing: every test and assertion stays; only the fake tunnels' closed-port connects fail sooner.
Tests
All 18 files, Linux, same host, main
0d68cae9e6against this branch:-n0with coveragesrc/kiro_crewlines / branches covered,-n0 --cov-branchEvery
srcfile has identical executed lines and branches. One line moves between runs on main itself, and it is not caused by this change:subprocess_pool/executor.py:372, thereturn Falsewhen the pool's background reaper thread finds a slot's lock already held. Whether that happens depends on thread timing. Main hit it in one of its three runs (one-n 4, two-n0) and missed it in the other two; the table shows main's second-n0run.Plants (each reverted afterwards), all 18 files at
-n 4:_exchange_linkreturning a value instead of raising_PeerUnavailablefrom itsexcept: the same 5test_instances_proxy.pytests fail on main and on this branch.token_validatesreturningTruefrom itsexcept:test_instances.py::TestSshTunnelManager::test_token_validates_denies_on_errorfails on both.Main also fails the leaked-reply test above in both plant runs. That test passes on the branch.
Three runs at
-n 4 --dist loadgroupand one in reversed order at-n0: 644 passed each time.test_flake_pattern_ratchet.py, comment-history, brand, subprocess-encoding, black, flake8, isort and file-line-cap gates pass.Proof: not provable -- test-only change
Manual verification
N/A — unit coverage sufficient: test-only change; the counts, coverage and plants above were run locally.
Real-machine verification
N/A -- test-only change; Windows timing is measured by CI's Windows shards.
Related Issues
Part of #30257
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.