Skip to content

fix(test): the suite calls production SahajCloud with fake API keys - #29

Merged
sydevs-bot merged 4 commits into
mainfrom
claude/fix-28-no-network-in-tests
Sep 18, 2026
Merged

sydevs-bot merged 4 commits into
mainfrom
claude/fix-28-no-network-in-tests

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Every lane now refuses outbound HTTP by default, so no test run reaches production SahajCloud.
  • An unstubbed request is recorded and fails the run, instead of degrading quietly to a cache miss.
  • The two lanes that were actually leaking — the render deep link, and the sitemap cache flush — now get their answers locally.
  • The render lanes prove the guard is armed before they trust its log, and no longer render a page before the fixtures are seeded.

Changes

  • tests/no-network.php — new. Takes an unroutable SAHAJ_ATLAS_API_ORIGIN, sets DISABLE_WP_CRON, and refuses any pre_http_request no lane answered, recording the URL. It also creates that log as it loads, so absent and empty are different worlds.
  • tests/{blueprint,render-blueprint,render-classic}.json — a writeFile step loads it as an mu-plugin, before activatePlugin. mu-plugins run before regular plugins, which is what lets the origin win the defined() guard in sahaj-atlas.php:42.
  • tests/run.php, tests/render.mjs — read the record, and fail on a non-empty one. The render lanes also assert the log exists at all.
  • tests/render.mjs — DEEP now asks about /nl/amsterdam, a route the blueprints seed an answer for. /gb/london had none, so its SEO fetch went live.
  • tests/sitemap.php — seeds the empty set a failed fetch leaves behind, instead of flushing the cache before a group that runs parse_request.
  • tests/{render-blueprint,render-classic}.json — the Atlas page is created last, after the transients. See "The readiness race" below.

Test results

  • Lean gate: ✓ pnpm test:all — lint clean, 236 assertions / 0 failures, both render lanes 0 failures.
  • Contract step: ✓ tests/atlas-url-contract.json matches SahajCloud main byte for byte.
  • Outbound blocked: ✓ all three lanes pass with HTTPS_PROXY/HTTP_PROXY/ALL_PROXY pointed at a dead port.
  • Every new assertion was watched fail on the real defect before the fix went back in.

Manual verification

  1. The third acceptance criterion is post-merge only. After the first CI run on main, check that neither 847a359574ff nor 625faa3fbbc3 has a lastSeen after the merge commit, with the curl in the ticket.

Notes for reviewer

  • Pre-mortem for the new guard. It assumes pre_http_request is the one chokepoint WP_Http::request() passes through, and that mu-plugins load before regular plugins. Checked against sahaj-atlas.php:41-42, whose defined() guard is what the mu-plugin has to beat, and confirmed empirically: the URL a reintroduced leak records is https://api.sahaj-atlas.invalid/…, not the production origin, so the define() did land first.
  • The filter runs at PHP_INT_MAX and passes through when an earlier filter already answered. At priority 10 it would be overwritten by tests/seo.php's own stub and record a leak that lane had in fact covered.
  • .distignore gains .test-network.txt. tests/ was already excluded, so nothing here reaches a host site.
  • AGENTS.md said "Three more traps" over a five-item list; that is now "More traps".
  • ⚠ Harness anomaly, untouched by this PR. tests/render.mjs ends each lane with server.kill('SIGTERM'), which kills the npx wrapper and not the playground child. A killed run leaves servers holding ports 8801/8802, and the next run then tests the old build while looking green. Worth its own ticket.
Detail

Why not WP_HTTP_BLOCK_EXTERNAL. It is the core API for this and would block just as well, but it returns a WP_Error the plugin handles gracefully — the run would go quiet rather than red, and acceptance criterion 2 asks for the opposite. The filter blocks and records, in one place.

Why .invalid. RFC 2606 reserves it, so it resolves nowhere. The filter is what stops the request; the origin is there for a path that ever slips past it.

Why DISABLE_WP_CRON. Cron spawns a loopback request to wp-cron.php, and the job answering it asks api.wordpress.org for updates — a second way out of the instance that a single page load is enough to trigger.

The two leaks, as reintroduced. Reverting the render change records https://api.sahaj-atlas.invalid/api/atlas/seo?route=/gb/london&locale=en-US, matching the route=/gb/london&locale=en-US Sentry saw. Reverting the sitemap change records /api/atlas/sitemap. Both fingerprints in the ticket account for themselves.

Rejected: seeding a /gb/london answer. It would have meant a second region fixture carrying the same shape, against the one-copy rule in tests/fixtures/seo-answer.php. Pointing DEEP at the seeded route costs one line and adds no fixture.

Why the render lanes assert the log exists. readFile(...).catch(() => '') made an absent log and an empty one the same world, so a blueprint that stopped writing the mu-plugin would put the lane back on the real endpoint and still pass. tests/run.php already refused to trust an empty log until has_filter proved the refusal installed; the render lanes had the log but not the proof. Dropping the writeFile step from tests/render-blueprint.json now fails block: the refusal is armed at all while block: no request left the instance still passes — the pair that made the old assertion hollow.

The readiness race. waitForAtlasPage polls the Atlas page until it answers 200, and a poll is a real page render. Both blueprints created the page first and seeded the SEO transients last, so a poll landing in that window rendered the root view with nothing cached and sent GET /api/atlas/seo?route=/ to the endpoint for real. Nothing downstream noticed: seeding finished long before the assertions ran, so every root-view assertion passed on the seeded answer and only the network log remembered. It failed roughly one run in several. Creating the page last closes the window — the probe cannot return 200 until the transients are in place.

Closes #28

🤖 Generated with Claude Code

https://claude.ai/code/session_01WuVr6DVBHXDLMDU7wfFHoR

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

…tries

Every lane reached production SahajCloud on every run, from CI runners and
from developer machines. `SAHAJ_ATLAS_API_ORIGIN` defaulted to the real host
and no lane overrode it, so two fake keys were rejected there several times a
day and filed a Sentry event each time. Two of the three "broken client
integrations" in sydevs/SahajCloud#789 were these tests.

Each blueprint now writes an mu-plugin that loads `tests/no-network.php`
before the plugin file. It takes an unroutable API origin and refuses any
`pre_http_request` no lane answered, recording the URL. `tests/run.php` and
`tests/render.mjs` read that record, so an unstubbed fetch fails the run
instead of escaping quietly — the half that keeps the next lane from
regressing.

Two lanes were leaking. The render lanes fetched a deep link whose route the
blueprint seeds no answer for, so the SEO fetch went live; they now ask about
the seeded route. `tests/sitemap.php` flushed the sitemap cache before a group
that runs `parse_request`, and the sitemap consults the endpoint to answer
that hook; it now seeds the empty set a failed fetch leaves behind.

Both leaks were reintroduced and watched fail, at
`route=/gb/london&locale=en-US` and `/api/atlas/sitemap` — the two
fingerprints the ticket names.

Closes #28

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0125etxw2h5Va3FyX86g5jK6
@sydevs-bot

sydevs-bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 16:31Z address-review · attempt 1 · session · done
  • 16:31Z address-review · attempt 1 · session
  • 01:30Z address-review · attempt 1 · session · done
  • 01:30Z address-review · attempt 1 · session
  • 01:20Z adversarial-review · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 17, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The diff is the size of the ticket: two leaks fixed at source, one default-deny guard, no refactor smuggled in. The ticket proposed the constant in tests/bootstrap.php; the mu-plugin is the right deviation, because that file runs after wp-load.php and the defined() guard at sahaj-atlas.php:42 has already fired.

tests/run.php:360 will not trust an empty log until it has proved the filter armed. The render lanes read the same log with no such proof, and that lane is where the /gb/london leak lived.

Findings

  • should-fix — tests/render.mjs:305: an empty log and a guard that never loaded read identically.
  • consider — tests/render.mjs:297: near-verbatim from tests/run.php:350.

What was checked

includes/sitemap.php:124-129 uses is_array(), so the empty-set transient skips the fetch, and tests/sitemap.php:87 still covers the flush. tests/fixtures/seo-answer.php seeds /nl/amsterdam, so the new DEEP route is answered locally. The in-content hosts embed /gb/london/1204, gated by trap 17.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread tests/render.mjs Resolved
Comment thread tests/render.mjs Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 17, 2026
The render lanes read the network log with `readFile(...).catch(() => '')`,
so an absent log and an empty one were the same world. A blueprint that
stopped writing the mu-plugin would put the lane back on the real endpoint
and still go green — reading a file nobody writes reports a leak as a pass.
That is the lane the `/gb/london` leak actually lived in.

`tests/run.php:360` already refuses to trust an empty log until `has_filter`
proves the refusal installed. The render lanes inherited the log but not the
proof, and the mu-plugin one-liner is copied into three blueprints, so drift
is one edit away.

`tests/no-network.php` now creates the log as it loads, which makes absence
mean "this file never ran". `FILE_APPEND` is what keeps that safe: a render
lane loads the guard on every request, and truncating would drop what the
earlier ones recorded.

Watched fail: dropping the `writeFile` step from `tests/render-blueprint.json`
fails `block: the refusal is armed at all` while `block: no request left the
instance` still passes — the exact pair that made the old assertion hollow.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WuVr6DVBHXDLMDU7wfFHoR
This block restated `tests/run.php:350-355` almost word for word. Two copies
of one rationale diverge the first time the thing they describe changes, and
`tests/no-network.php` already carries the story in full — both lanes point
at that file anyway.

The ⚠ marker and the #28 breadcrumb stay. What goes is the retelling.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WuVr6DVBHXDLMDU7wfFHoR
`waitForAtlasPage` polls the Atlas page until it answers 200, and a poll is a
real page render. Both blueprints created the page first and seeded the SEO
transients last, so a poll landing in that window rendered the root view with
nothing cached and sent its `GET /api/atlas/seo?route=/` to the endpoint for
real.

Nothing downstream noticed. Seeding finished long before the assertions ran,
so every root-view assertion passed on the seeded answer and only the network
log remembered — an intermittent `route=/` escape that failed one run in
several, and that the old `catch(() => '')` reader would have reported as a
pass whenever the log went missing too.

Creating the page last closes the window: the probe cannot return 200 until
the transients are in place, so no render happens against an unseeded site.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WuVr6DVBHXDLMDU7wfFHoR
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Both critic threads adopted. The gate caught a third thing.

  • should-fix — 99ec316. The guard creates its log at load, so the render lanes tell an empty log from an absent one, and assert it.
  • consider — 1849017. The duplicated ⚠ block now points at tests/no-network.php.
  • Not from a thread — 5b81fbe. The new assertion went red on a rerun. waitForAtlasPage polls the Atlas page, a poll is a real render, and both blueprints seeded the SEO transients after creating the page. A poll in that window sent route=/ to the endpoint for real. The blueprints now create the page last.

Gate: lint clean, 236 assertions / 0 failures, both render lanes 0 failures. Contract byte-identical.

⚠ Anomaly, not from this diff: server.kill('SIGTERM') kills the npx wrapper, not the playground child. Servers from a prior run keep ports 8801/8802, so the next run tests the old build.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 17, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 17, 2026 02:19
@sydevs-bot
sydevs-bot requested a review from Ardnived September 17, 2026 02:19

@Ardnived Ardnived left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a testing framework or package we could use to handle these changes instead of re-implementing them ourselves?

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 17, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

No. I checked the one switch that could have replaced this.

Playground's own features: { networking: false } is not honoured by @wp-playground/cli v3. A probe blueprint with it set still reached TLS on a live host. There is no --networking flag either.

Packaged options:

  • WP_HTTP_BLOCK_EXTERNAL — core's API, rejected in the body. It blocks, but returns a WP_Error the plugin handles, so the run goes quiet, not red. It never records which URL leaked.
  • php-vcr — hooks curl via runkit7 or uopz. The PHP-WASM build ships neither.
  • brain/monkey, wp_mock — stub functions in an unbooted process. This suite boots real WordPress.
  • nock, msw — the call leaves from inside the WASM instance. Node never sees it.

What is left is 12 lines on pre_http_request, core's own hook for this.

The one real alternative is swapping the harness for PHPUnit and wordpress-develop. That needs Docker or system PHP, which this harness exists to avoid (AGENTS.md). Want that costed as its own ticket?

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 17, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit 864c48e Sep 18, 2026
35 of 38 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-28-no-network-in-tests branch September 18, 2026 00:20
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 18, 2026
@sydevs-bot sydevs-bot mentioned this pull request Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(test): the suite calls production SahajCloud with fake API keys

3 participants