Repository navigation
test: block the network in the Bob plugin test suite - #1126
Merged
Merged
Conversation
A test once downloaded a real proxy release from GitHub into a temp HOME, because a fake was skipped. Nothing stopped the next one. - block_network() patches urllib's OpenerDirector.open (the plugin's urlopen and LOOPBACK opener), socket.create_connection and socket.socket.connect/connect_ex. - Only 127.0.0.1, ::1 and localhost pass. Anything else raises NetworkBlocked, which names the scheme, host and port, never the user info, path or query. - NetworkBlocked is a BaseException, so the plugin's `except Exception` cannot hide it. - setUpModule in both test files turns it on; a module cleanup undoes it. - NetworkGuardTest covers a blocked download, a blocked raw socket, a blocked create_connection before DNS, no credential in the message, and loopback still working. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
vz-ibm
commented
Nov 12, 2026
vz-ibm
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | fresh | 2 of 2 | 1 of 2 | d80e3521caa2 |
approve |
Verdict: approve
Findings
None.
Non-blocking
- The guard covers only the test process, not child processes. The module docstring says "A call to any host but 127.0.0.1, ::1 or localhost raises NetworkBlocked". Some tests run
bob_plugin.py, hook commands andcontext-guru-resetthroughsubprocess.run(test_bob_plugin.py:613,:1054,:1060,:1162). Those children have no guard. Today they run onlycheck,signal,ensure,statusand reset. None of these callslatest_release_tagorfetch, so nothing leaks now. A future subprocess test ofsetuporupdatewould not be stopped. Proposal: add one sentence to the docstring, for example "Child processes are not guarded: do not start setup or update in a subprocess." Another option is asitecustomizeonPYTHONPATHfor child Pythons, but that is more than this PR needs. - One address of a host can stop the address loop in
create_connection.socket.create_connectioncatches onlyOSErrorfor each resolved address.NetworkBlockedis aBaseException, so the loop stops at the first blocked address and does not try the next one. If a hosts file mapslocalhostto an address that is not inLOOPBACK_HOSTS, for examplefe80::1%lo0(older macOS/etc/hosts), thentest_loopback_calls_still_reach_a_fake_serverfails on that machine. A current macOS/etc/hostsmapslocalhostonly to127.0.0.1and::1, so this is a low risk. The failure is fail-closed and clear. socket_checkblocks other loopback addresses such as127.0.0.2or::ffff:127.0.0.1. That is fail-closed and correct for a test guard. I note it only so that nobody is surprised later.
What I checked
- I read the full diff
cd82e95a..d80e3521(one commit) and the commit message. - Coverage of the plugin's network paths.
fetchandlatest_release_tag(bob_plugin.py:441-453) useurllib.request.urlopen. It goes through the globalOpenerDirector.open, which the guard patches.LOOPBACK(bob_plugin.py:295) is also anOpenerDirector, so it is guarded too. Redirects callself.parent.openagain, so each redirect hop is checked.FakeReleaseredirects to127.0.0.1, which passes. - Backstops.
http.client.HTTPConnectionreadssocket.create_connectionwhen it creates each connection, so the patch applies.socket.socket.connectandconnect_exare patched on the Python class, and the check runs only forAF_INETandAF_INET6.first_free_portuses onlybind, which the guard does not touch. - No credential in the error.
guarded_openbuilds the message from the scheme,hostnameandportonly.test_the_guard_error_names_no_credentialproves it with user info and a query that holdSECRET. except Exceptioncannot hide the error.NetworkBlockedis aBaseException. The plugin has oneexcept BaseException(bob_plugin.py:962). It records the error, restores the files and lets the error go on, so it does not hide it either.- Setup and undo. Each test module has its own
setUpModule.test_bob_control.pyimports only named symbols, so it does not take over thesetUpModuleoftest_bob_plugin.py. unittest runs the module cleanup before it starts the next module, so the two guards never stack.undorestores all four originals. - Tests.
NetworkGuardTestchecks a blocked download, a blocked raw socket to TEST-NET-1, a blockedcreate_connectionbefore any DNS lookup (getaddrinfois mocked to fail), and127.0.0.1andlocalhoststill working.FakeProxybinds127.0.0.1. Whenlocalhostgoes to::1first, that connect is refused and the loop goes on to127.0.0.1. The test expects 3/healthzcalls, which is correct. - Rules. Only tests changed. There is no change to a component or a feature, so no data-dependence row is needed, and fail-open behavior does not change.
- I did not run the tests, because live tests are not approved for this review.
vz-ibm
commented
Nov 12, 2026
vz-ibm
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | fresh | 1 of 2 | 1 of 2 | d80e3521caa2 |
approve |
Verdict: approve
Findings
None.
Non-blocking
- The guard covers this process only.
CanaryTestandHookCommandShellTeststartbob_plugin.pyand the hook commands as child processes (test_bob_plugin.py:1054,:1060,:613).block_network()does not reach them. Today these subcommands (check,signal,ensure,status) call only 127.0.0.1, so nothing leaks. But the module docstring says "A call to any host but 127.0.0.1 ... raises NetworkBlocked". That is true only in-process. Suggest one sentence: "Child processes are not guarded." - A DNS lookup can still leave the machine on the backstop path.
http.client.HTTPConnection._create_connectionis bound to the realsocket.create_connectionat import time. So a directhttp.clientcall skipsguarded_create, resolves the name, and only thenguarded_connectblocks it. The plugin uses only urllib, whichguarded_openstops before the lookup. The docstring calls this path a backstop, which is correct. No change needed. It is just a known limit. NetworkGuardTest.test_loopback_calls_still_reach_a_fake_serverdepends on the developer's proxy settings.PLUGIN.fetchis plainurlopen, so it readsHTTP_PROXY. On a Mac withHTTP_PROXYset and noNO_PROXY(the casetest_bob_plugin.py:828describes), the twofetchcalls at:2045-2046go to the proxy host. The guard then raisesNetworkBlocked. TheFakeReleasetests already have the same dependence, so this PR does not add a new kind of failure. Amock.patch.dict(os.environ, ...)that removes the proxy variables in this test would make it hold on such machines.real_createcan leave a socket open whenguarded_connectraises inside it.create_connectioncloses the socket only onOSError. At most this gives aResourceWarningin a test that is already failing.
What I checked
- I read the full diff of both files and the commit message. DCO sign-off and
Assisted-Byare there. There is noCo-Authored-By. - Patch points.
urllib.request.urlopenuses a globalOpenerDirector, andLOOPBACK(bob_plugin.py:295) is anOpenerDirectorinstance. PatchingOpenerDirector.openon the class therefore covers both. Redirects callself.parent.open, soguarded_openalso blocks a redirect away from loopback.ssl.SSLSocket.connectends insocket.socket.connect, so the backstop covers TLS sockets too. - The plugin cannot hide the error. All plugin network calls are in
except Exceptionblocks, or in urllib'sexcept OSError(which wraps errors asURLError). The oneexcept BaseException(bob_plugin.py:962) is inchange_and_restart. It wrapsload_service/wait_healthy, and these call onlyhealthy()on 127.0.0.1. unittest's bareexceptreports aBaseExceptionfrom a test as an error, so a blocked call fails the test in a way you can see. The plugin starts no threads, so no error gets lost in a thread. - Setup and teardown. Each module has its own
setUpModule, which callsaddModuleCleanup(undo). unittest runsdoModuleCleanupswhen it moves to the next module, so the patches never stack.test_bob_controlimports only helpers andTempHome(which has no test methods), so it picks up no test classes from the other module. - The undo puts back every patched attribute. The restored
socket.socket.connectis an explicit class attribute that holds the same C method, so behavior is the same. - Credential masking. The message holds the scheme,
hostnameandportonly.test_the_guard_error_names_no_credentialchecks that the user info and the query are not in it. - The new tests can fail. The raw-socket test uses TEST-NET-1. The
create_connectiontest mocksgetaddrinfoto raiseAssertionError, so a missing guard gives the wrong exception type and the test fails. The loopback test checks thatproxy.pathsis exactly 3×/healthz. - No existing test reaches a non-loopback host in-process. I grepped both files for URLs. The
bob.ibm.com/evil.comstrings only go tovalid_upstreamand argument parsing, never to the network. Release tests useFakeReleaseon 127.0.0.1 throughRELEASE_BASE. reset.shandbob_route.pymake no network calls.- Data dependence. This is a test-only change with no new or changed feature, so no row file is needed.
- I did not run the suite. Live tests are not approved for this review.
Raised by both round-1 reviewers of #1126. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
Collaborator
Author
|
Round 1: both reviewers approve. Changes in bc36262:
Checks: the guard tests pass (5). No other change. |
main added FAKE_STRATEGIES to the same import line in test_bob_control.py; the line now has both. The whole Bob suite passes with the network guard on (230 tests). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
amiddavid
reviewed
Nov 17, 2026
amiddavid
left a comment
Collaborator
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @amiddavid) | Claude Code 2.1.326 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 2 of 2 | 0e2e52487d76 |
approve |
Verdict: approve
Findings
None.
Non-blocking
- None new. The round-1 non-blocking points stay as the author answered them (see below).
What I checked
- Last review: round 1,
d80e3521caa2, 2026-11-12T09:12:36Z - New commits read: 2
bc362621test: say that the network guard does not cover child processes0e2e5248chore: merge main into test/bob-suite-no-network (brings main up toa4d43d94)
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Reviewer 1, round 1 review (09:13:48Z): read. Approve, 4 non-blocking points.
- Author comment (09:15:36Z): read. I checked each answer below.
Earlier findings
Neither reviewer had a finding in round 1. Status of the non-blocking points:
- Child processes are not guarded (both reviewers): fixed.
bc362621adds the docstring line "Child processes are not guarded: do not start setup or update in a subprocess." (test_bob_plugin.py:11). - The loopback test depends on
HTTP_PROXY(reviewer 1): rejected by the author. I accept the reason.urllib.request.urlopenbuilds one global opener on its first call, with the proxy handler it sees then. A later env change in one test does not change it. A real fix needs the privateurllib.request._opener. TheFakeReleasetests have the same limit. http.clientpre-DNS gap, thecreate_connectionaddress loop, other loopback addresses (both reviewers): rejected by the author. I accept the reason. The plugin uses only urllib. Each case fails closed with a clearNetworkBlocked.- Socket leak in
real_createon a blocked connect (reviewer 1): no reply. It is non-blocking and only affects a test that already fails. No action needed.
The merge of main
The PR diff against base a4d43d94 is the same guard as in round 1, plus the one docstring line. I read main's changes to the Bob plugin since d80e3521 (#1111 and #975: find_binary now probes strategies, too_old_for_preset, SetupSkipsOldProxyTest, FAKE_STRATEGIES):
- The merge keeps the guard intact.
test_bob_control.pyimportsFAKE_STRATEGIESandblock_networkand has its ownsetUpModule.test_bob_plugin.pykeepsimport time,json,urllib.parseandurllib.request. Both files parse. - No new main test reaches a real host in-process. Each setup test in
SetupSkipsOldProxyTesteither patchesRELEASE_BASEto aFakeReleaseon 127.0.0.1, or patchesinstall_release_binaryto raise.UpdateTest.setUppatchesinstall_release_binary.test_a_release_before_v0_7_1...andtest_release_v0_7_1_is_installedcallinstall_release_binaryonly afterserve()patchesRELEASE_BASE. - The new
strategiesprobe runs a fake binary throughsubprocess. It makes no network call. The fake prints JSON or "listening", and one fake runssleep 30. - The guard adds safety to main's change.
find_binaryis stricter now. A future fake withoutstrategieswould make setup download a release, and the guard now stops that call withNetworkBlocked.
Rules
- Test-only change. No component or feature changes, so no data-dependence row is needed. No change to fail-open behavior, and no behavior change for users.
bc362621has a DCO sign-off andAssisted-By, with noCo-Authored-By.- I did not run the tests. Live tests are not approved for this review.
amiddavid
reviewed
Nov 17, 2026
amiddavid
left a comment
Collaborator
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @amiddavid) | Claude Code 2.1.326 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 2 of 2 | 0e2e52487d76 |
approve |
Verdict: approve
Findings
None.
Non-blocking
- No CI job runs the Bob Python suite. I found no
unittestortest_bobstep in.github/workflows/or theMakefile. The green checks on0e2e5248therefore do not prove that the merged suite passes under the guard. The author's round-1 reply says "the guard tests pass (5)". That coversNetworkGuardTestonly, and it was before the merge of main. Proposal: run the full suite one time on the merge head before merge (python3 -m unittest discover -s bob-plugin/context-guru/scripts -p 'test_*.py'). My code reading (below) finds no test that the guard would now stop.
What I checked
- Last review: round 1,
d80e3521, 2026-11-12T09:13:48Z (posted by @vz-ibm's session, verdict approve). - New commits read: 2.
bc362621test: say that the network guard does not cover child processes.0e2e5248chore: merge main into test/bob-suite-no-network (brings 13 main commits).
- Read in full: 2 reviews, 1 comment, 0 inline comments.
- New items since my last review:
- Author comment of 09:15:36Z (round-1 replies). I checked each point:
- Child processes: fixed.
bc362621adds the docstring sentence attest_bob_plugin.py:11. HTTP_PROXYin the loopback test (my point): rejected with a reason. The reason is right.urlopencaches one global opener (urllib.request._opener) with the proxy handler it built on first use, so a lateros.environpatch has no effect. I accept it.http.client, thecreate_connectionaddress loop and other loopback addresses: no change. I accept it. All three fail closed, and the plugin uses urllib only.
- Child processes: fixed.
- Reviewer 2 round 1: approve, no findings. Its non-blocking points match mine or are covered by the reply above.
- Author comment of 09:15:36Z (round-1 replies). I checked each point:
- Merge result.
git diff a4d43d94..HEADshows only this PR's change: the guard,NetworkGuardTest, the docstring, and thesetUpModuleintest_bob_control.py. The import line merges cleanly with main's newFAKE_STRATEGIESimport. - Main's Bob changes under the guard. I read
git diff cd82e95a..a4d43d94 -- bob-plugin/(#1111):find_binarynow also callsload_strategy_table, which runs the binary as a subprocess. No network.SetupSkipsOldProxyTest.setup_downloadingusesFakeReleasethroughRELEASE_BASEon 127.0.0.1. The guard lets it pass.setup_without_download, the offline test,UpdateTest.setUpandtest_setup_says_why_it_downloadsmockinstall_release_binary. So a binary thatfind_binarynow skips does not fall through to a real download.- Most other
setuptests mockfind_binary(for exampletest_bob_plugin.py:662).
- Rules: test-only change. No component or feature changes, so no data-dependence row. No behavior change for users.
- I did not run the tests. Live tests are not approved for this review.
amiddavid
added a commit
that referenced
this pull request
Nov 19, 2026
Plugin versions for v0.7.4: - Claude Code plugin 0.7.3 -> 0.7.4 (#1096, #1135, #1174, #1177, #1199, #1216). - Codex plugin 0.2.12 -> 0.2.13 (#1115, #1135). - Pi package 0.1.1 -> 0.1.2 (#1113). - Bob plugin 0.1.1 -> 0.1.2 (#1093, #1111, #1118, #1124, #1126, #1127). The owner's Bob hold (#1221) covers release tests only. - OpenCode: PINNED_VERSION v0.7.3 -> v0.7.4 in opencode-plugin/index.js, its README, docs/how-to/install-opencode-plugin.md and 3 tests. Behavior change: the version numbers; the OpenCode plugin's first start downloads proxy v0.7.4. Release bumps are approved by the owner ("I approve version bumps"). Data dependence: none. Reviews: 2 offload review rounds (GLM): both approve at ab79001. After it: 1422093, a merge of main with no hand resolution (remerge-diff 0; approval-still-valid: SAME CHANGE). Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Bob plugin's Python test suite now blocks every real network call. One test reached GitHub on 2026-11-12 (during #1111): a fake was skipped, and that setup call downloaded a real proxy release into a temp HOME. That test is fixed in #1111. This PR makes the next such test fail loudly, not download.
What changed
block_network()inbob-plugin/context-guru/scripts/test_bob_plugin.py, next toTempHome. AsetUpModulein each test file turns it on, and a module cleanup undoes it. It covers every test in both files, also the 4 classes that do not useTempHome.urllib.request.OpenerDirector.open: the plugin's downloads and itsLOOPBACKopener both go through it. It checks the URL before anyHTTP_PROXYor DNS step.socket.create_connection: checked by host, before the DNS lookup.socket.socket.connectandconnect_ex: checked by address (IPv4 and IPv6; Unix sockets pass).127.0.0.1,::1andlocalhostpass, so the fake release server, the fake proxies and the plugin's loopback calls still work.BaseException(NetworkBlocked), so the plugin's ownexcept Exceptioncannot hide it. Its message names only the scheme, host and port: never the user info, the path or the query, so a credential cannot leak.How it was tested
NetworkGuardTest). 4 were red first against an empty guard, on real network errors (a DNS failure, a socket timeout, urllib's parse error, a DNS lookup that must not happen). The 5th checks that loopback still works.Open point
CanaryTestandHookCommandShellTeststartbob_plugin.pyas a child process, which the guard does not cover. Covering them needs a change to how those tests start the child. A later PR.