# I Blocked the Network in My Tests. Six of Them Tried to Reach My Seller Account.

> Source: <https://dev.to/dbsoul/i-blocked-the-network-in-my-tests-six-of-them-tried-to-reach-my-seller-account-3pgd>
> Published: 2026-12-02 14:10:04+00:00

**Recommendation:** Block outbound network for the whole test session and assert zero blocked attempts at session end, rather than trusting per-test stubs to prevent real calls.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

*A field note from the autonomous Claude Code agent I run every day on one Windows PC. The numbers come from its own ledgers, not from memory.*

**Free to read first:** a PDF sample of the book behind this setup — its first 3 chapters: [https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample](https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample)

One of my tests had been able to edit my published posts. So I stopped relying on each test to fake its own calls and put one block under the whole test run: no connections off my own machine. On November 26 I ran the suite with it for the first time, every test file but one. Among the failures, six tests failed on that block. All six had tried to reach one host: one of the marketplaces where I sell.

All six run my evening sales collector. It wraps each store's step in `try/except Exception`, so one broken store doesn't stop the rest. The tests lean on that. For a step they don't care about, they swap in a stub that raises on purpose, and the collector moves on.

I added those stubs on September 29 and October 15. For the marketplace step they replaced `revenue_delta`. At the time the collector called that function directly, and the function fetched my item list itself. Stubbing it covered the network too.

In early November the marketplace's response stopped including a field my code read. When I fixed that on November 6, I added a wrapper, `read_sales`, so that a failed read would end in a fixed warning line, and I pointed the collector at the wrapper. Trimmed down:

``` python
def read_sales(day):
    try:
        rows = items()                         # the network call
        total = total_revenue(rows)
    except Exception as e:
        report(e)
        return None
    if total is None:
        report("could not read the total")
        return None
    try:
        return revenue_delta(day, rows=rows)   # what the tests stubbed
    except Exception as e:
        report(e)
        return None
```

That commit didn't touch any of the three test files. From then on, the list request ran first, before the stubbed function was ever reached. In the code, `items` loads my saved login cookies, requests a seller page to get a token, then requests my item list. Both are GET requests.

I wanted to know what the tests would have said without the block. So I unpacked the November 26 code into an empty folder, put the three test files back the way they were, left the block on, and replaced `items` with a fake so that nothing could leave the machine. I ran the three files two ways:

| The fake list call | What the wrapper caught in the six tests | The three files together | 
|---|---|---|
| Returned data | my stub's error, 6 times | 190 passed | 
| Raised a connection error | the connection error, 6 times | 190 passed | 

Green both times. And in the first row the stub was reached in all six tests. A check that "my stub was called" would have passed in the first row, the one that stands for a real request that worked. It would have complained only if the code never got far enough to call the stub.

In a separate run without the fake, the real `items` ran with only the block in its way. The same copy gave six failed tests and six blocked name lookups, one per test. The November 26 fix stubs `read_sales`, the function the collector calls. With it, the three files gave 190 passed and no blocked attempts.

I didn't check whether any run before the block got an answer from the site.

`sys.addaudithook`) sees name lookups, connects and sends.` BaseException`. An `except Exception`, like the two above, can't turn it into a quiet "couldn't read."
The per-test check only looked while a test was running. In a scratch copy, a connection tried while a module was loading, with the error swallowed, gave "1 passed" and exit code 0. I added one more check at the end of the session. With it, the same kind of probe still prints "1 passed," but the exit code is 1.

Some things are still outside the block: programs that aren't Python, such as a browser or Node, and a child Python started with `-I` or `-S` or with an emptied environment. There's also an asyncio connection on Windows straight to a numeric IP address. I tried one, and it left no record.

`except`, a pass can't show that the stub did the skipping.
**Where this comes from.** Every post here comes from one setup I run daily: a CLAUDE.md and memory files the agent reads before it touches anything. I also built a separate auditor agent for it that returned PASS or FAIL. The first 3 chapters of the book that walks through it are free as a PDF: [https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample](https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code-free-sample)

The full edition is 11 chapters plus 4 ready-to-use templates (CLAUDE.md starter, memory files, auditor checklist, measurement guide) and a hands-on section for every chapter, $19 as a PDF: [https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code](https://dbsoul.gumroad.com/l/autonomous-ai-agents-claude-code)

Prefer Google Play? The same book is on Google Play Books: [https://play.google.com/store/books/details?id=hesIEgAAQBAJ](https://play.google.com/store/books/details?id=hesIEgAAQBAJ)

Questions about the setup are welcome in the comments — I'll answer with what actually happened, not theory.
