Repository navigation
fix(test): the suite calls production SahajCloud with fake API keys - #29
Conversation
…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
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 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 fromtests/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
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
|
Both critic threads adopted. The gate caught a third thing.
Gate: lint clean, 236 assertions / 0 failures, both render lanes 0 failures. Contract byte-identical. ⚠ Anomaly, not from this diff: 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Ardnived
left a comment
There was a problem hiding this comment.
Is there a testing framework or package we could use to handle these changes instead of re-implementing them ourselves?
|
No. I checked the one switch that could have replaced this. Playground's own Packaged options:
What is left is 12 lines on 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 |
Summary
Changes
tests/no-network.php— new. Takes an unroutableSAHAJ_ATLAS_API_ORIGIN, setsDISABLE_WP_CRON, and refuses anypre_http_requestno 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— awriteFilestep loads it as an mu-plugin, beforeactivatePlugin. mu-plugins run before regular plugins, which is what lets the origin win thedefined()guard insahaj-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—DEEPnow asks about/nl/amsterdam, a route the blueprints seed an answer for./gb/londonhad 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 runsparse_request.tests/{render-blueprint,render-classic}.json— the Atlas page is created last, after the transients. See "The readiness race" below.Test results
pnpm test:all— lint clean, 236 assertions / 0 failures, both render lanes 0 failures.tests/atlas-url-contract.jsonmatches SahajCloudmainbyte for byte.HTTPS_PROXY/HTTP_PROXY/ALL_PROXYpointed at a dead port.Manual verification
main, check that neither847a359574ffnor625faa3fbbc3has alastSeenafter the merge commit, with thecurlin the ticket.Notes for reviewer
pre_http_requestis the one chokepointWP_Http::request()passes through, and that mu-plugins load before regular plugins. Checked againstsahaj-atlas.php:41-42, whosedefined()guard is what the mu-plugin has to beat, and confirmed empirically: the URL a reintroduced leak records ishttps://api.sahaj-atlas.invalid/…, not the production origin, so thedefine()did land first.PHP_INT_MAXand passes through when an earlier filter already answered. At priority 10 it would be overwritten bytests/seo.php's own stub and record a leak that lane had in fact covered..distignoregains.test-network.txt.tests/was already excluded, so nothing here reaches a host site.AGENTS.mdsaid "Three more traps" over a five-item list; that is now "More traps".tests/render.mjsends each lane withserver.kill('SIGTERM'), which kills thenpxwrapper 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 aWP_Errorthe 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 towp-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 theroute=/gb/london&locale=en-USSentry saw. Reverting the sitemap change records/api/atlas/sitemap. Both fingerprints in the ticket account for themselves.Rejected: seeding a
/gb/londonanswer. It would have meant a second region fixture carrying the same shape, against the one-copy rule intests/fixtures/seo-answer.php. PointingDEEPat 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.phpalready refused to trust an empty log untilhas_filterproved the refusal installed; the render lanes had the log but not the proof. Dropping thewriteFilestep fromtests/render-blueprint.jsonnow failsblock: the refusal is armed at allwhileblock: no request left the instancestill passes — the pair that made the old assertion hollow.The readiness race.
waitForAtlasPagepolls 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 sentGET /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