Repository navigation
fix(sitemap): the plugin publishes a sitemap URL it cannot serve - #53
Conversation
`sahaj_atlas_sitemap_url()` composed `home_url( '/sahaj-atlas-sitemap.xml' )` on every permalink shape. An `index.php` structure is what WordPress offers when mod_rewrite is unavailable, so that address reaches the filesystem and 404s, while `/index.php/sahaj-atlas-sitemap.xml` reaches `parse_request` like every other URL on such a site. The composer now prefixes `index.php/` under `WP_Rewrite::using_index_permalinks()`, and `robots.txt`, both SEO-plugin index entries, and the diagnostics row follow it at once. `sahaj_atlas_maybe_serve_sitemap()` needs no matching branch. WordPress strips its index file before setting `$wp->request`, so the guard compares `sahaj-atlas-sitemap.xml` on both shapes. Measured on a booted WordPress 6.7 / PHP 7.4: a real request for `/index.php/sahaj-atlas-sitemap.xml` was answered with the XML, 200, `application/xml`, and `robots.txt` announced that same address. The `ok` panel row read its displayed path from `SAHAJ_ATLAS_SITEMAP_PATH` while its link read the composer, so on this shape it would have shown a volunteer an address that 404s under a link to the one that works. It now derives the path from the URL, as check 2 already does. `using_index_permalinks()` reads `$wp_rewrite->permalink_structure`, cached at setup rather than the option every other permalink check here reads. The two agree on a real request. A fixture that writes the option has to reach `WP_Rewrite::init()` as well, which is what `sahaj_set_permalink_structure()` exists for — without it every new assertion passes against the shape the instance booted with. Refs #50 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nyuoa2BuQw3QQskhQeKbC
…serve `WP_Rewrite` builds no rules at all for an empty `permalink_structure`, and `WP::parse_request()` sets `$wp->request` only when the rule set is non-empty, so `sahaj_atlas_maybe_serve_sitemap()` is unreachable on a plain-permalink site. `sahaj_atlas_register_sitemap()` gates only on page health and the API key, so both SEO-plugin index filters were registered anyway and `sahaj_atlas_sitemap_index_entry()` appended a `<loc>` for an address that 404s. Measured on all three shapes. That entry is not hypothetical here. Yoast maps `sitemap_index.xml` through a rewrite rule, so its pretty URL 404s like ours, but `sitemap` is a registered query var (`inc/sitemaps/class-sitemaps-router.php:39,52`, wordpress.org trunk, read 2026-10-01), so `/?sitemap=1` still serves the index — with our 404 in it. A crawler that finds the index that way does fetch the dead URL. The guard sits in `sahaj_atlas_sitemap_index_entry()`, the one function both adapters call, rather than on the two `add_filter()` calls the ticket named. Same effect, and it puts the refusal where the unservable URL would be composed, so the rule is testable by calling the adapter directly — which is what the ticket's own verification checklist asks for. `robots_txt` keeps its filter. Core serves no virtual `robots.txt` on this shape either, so that filter never runs, and diagnostics check 6 is what tells the volunteer — it reports `fail` here and deliberately offers no `Sitemap:` line to paste. Whether a plain-permalink site should instead get a servable sitemap at `/?sahaj_atlas_sitemap=1` is still open on #50 and is not decided here. Refs #50 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nyuoa2BuQw3QQskhQeKbC
…p 24 Both halves of this branch are invisible from inside the plugin: the address is composed, published, and returns 200 in a lane that routes every request through PHP. The trap names each shape, the one composer every published address reads, and why `robots.txt` needs no guard on either. Also re-points trap 13 and trap 15 at `includes/sitemap.php` and trap 14 at `includes/diagnostics.php`, which this branch moved by 22 and 5 lines. Refs #50 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nyuoa2BuQw3QQskhQeKbC
- `sahaj_atlas_sitemap_url()` reads `$wp_rewrite->root` instead of re-deriving it. Core assigns `root = $this->index . '/'` under `using_index_permalinks()` in `WP_Rewrite::init()` and prepends that property itself in `link-template.php`, so the ternary was a second expression of core's own index-prefix rule. Verified in the lane's WordPress 6.7.9, including that `root` stays `''` for `/blog/%postname%/` — `front` is the one that absorbs a path prefix, and would have published the wrong address. - The plain-permalink guard asks `$wp_rewrite->using_permalinks()` rather than reading `permalink_structure` directly. The composer two functions above it now reads `$wp_rewrite`, and two sources for one question can disagree inside a request. - `sahaj_atlas_check_sitemap_discovery()` called the composer three times. One `$url` local, declared where the first branch needs it. - The guard's comment said `sahaj_atlas_maybe_serve_sitemap()` is never reached on a plain-permalink site. It is reached — `sahaj_atlas_parse_request()` calls it before its own permalink return. What never happens is the match, because core leaves `$wp->request` empty with no rules. - `sahaj_set_permalink_structure()` moves to `tests/run.php`, beside the other shared fixtures, and delegates to `WP_Rewrite::set_permalink_structure()` — the option write plus `init()`, which is what `options-permalink.php` calls. `tests/sitemap.php`'s own four bare `update_option()` writes now route through it: this file exercises the composer, and the composer now reads `$wp_rewrite`. - Trap 24 loses the argument it repeated from both docblocks, and the test comments that restated them lose their mechanics. The serve assertion's comment now records what the lane cannot prove instead: it routes every request through PHP, so the bare path answers there too. The nine bare `update_option( 'permalink_structure', … )` writes in `tests/run.php`, `tests/contract.php` and `tests/seo.php` are left alone. Converting them changes state those suites are asserting against, and none of them reads the sitemap composer. Refs #50 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012nyuoa2BuQw3QQskhQeKbC
|
🤖 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 fix is smaller than the ticket asked for. One composer owns the address, the serve guard needed no branch, and the ticket's two add_filter() guards became one guard at the seam both adapters share.
The shape awareness stops one row short. Check 6 is the only model of when robots.txt carries the line. An index.php site, this PR's premise, is a case it does not name.
Nothing owns servability: the guard asks $wp_rewrite, check 6 asks the option, and this diff added a fixture because they can disagree.
Findings
- should-fix — diagnostics.php:533 —
okclaims a line this site cannot publish. - consider — sitemap.php:311 — two spellings of one predicate
- consider — sitemap.php:308 —
/?robots=1runs the filter unguarded.
What was checked
#50, the PR body, the diff at c175a29. Read whole: includes/sitemap.php, sahaj_atlas_check_sitemap_discovery(), tests/sitemap.php. Every rewritten AGENTS.md pointer resolves. WP_Rewrite::init() and WP::$public_query_vars checked against the new ⚠ blocks.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
An `index.php` permalink structure is what WordPress offers when mod_rewrite is unavailable, and on that server `/robots.txt` reaches the filesystem rather than WordPress. Core writes the rewrite rule for it either way, so the shape cannot be told apart from one that works — the row claimed `ok` on a site whose `Sitemap:` line is never served. It now warns and names both the file a crawler reads and the line to paste, the same remedy the subfolder branch offers. Check 6 is the only model of when that line exists, so the case it did not name was invisible. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01STv5BmDf3saWEGu8THHybC
The composer owned the address; nothing owned whether it can be served. The index-entry guard asked the cached rewrite state and check 6 asked the option, and those two disagree until `WP_Rewrite::init()` runs — the desync the permalink fixture exists to avoid. A request is routed by the cached state, so a row following the option can call a working site broken. `sahaj_atlas_sitemap_is_servable()` now answers for both, beside the composer it belongs to. Path routing keeps its own reading of the option: that is a different question, and #50 says not to move it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01STv5BmDf3saWEGu8THHybC
The premise that this filter cannot run on a plain-permalink site was wrong. `robots` is one of `WP::$public_query_vars`, and that loop sits outside `parse_request()`'s rewrite block, so `/?robots=1` fires `do_robots()` with no rewrite rules at all — measured in the lane's WordPress 6.7.9. The file then announced the address the index entries had just withheld. Low stakes, since no crawler guesses `?robots=1`. Both halves of one refusal now read the same predicate, which is the point. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01STv5BmDf3saWEGu8THHybC
Check 6 now warns on an `index.php` site, `robots.txt` carries the same servability guard as the index entries, and one predicate answers that question for all four readers. Line references re-derived. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01STv5BmDf3saWEGu8THHybC
|
Three threads from the adversarial review, all adopted. Head
Nothing rebutted, nothing to ask. Trap 24 and the moved line references follow. The PR body carries the measurements. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#54 and this branch each appended a trap numbered 24 to AGENTS.md. The i18n trap keeps 24, the number already on main, and the sitemap trap becomes 25. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01S3FoZd9LTWqERDq4qh5ZUf
|
Merged
🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Only AGENTS.md conflicted, and only on a line-number breadcrumb. Both sides shifted includes/diagnostics.php, so trap 14's anchors were stale on both and neither side's numbers were right for the merged file. Recomputed from the merged file instead of taking a side, and trap 24's breadcrumb — this branch's own, untouched by main and so unconflicted — moved by the same amount. #52 added checks 7 and 8 while this branch changed check 6, which git merged cleanly; verified both survive. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01W59UqW1sLWMePpX8ZYaxy2
|
Merged Took neither side. Both sides shifted that file, so both numbers were already wrong for the merged tree — #52 added checks 7 and 8 while this branch rewrote check 6. Git merged that cleanly and both behaviours survive: all eight checks run, and the servability guard is intact. Gate green — lint 12 files, measure, 333 assertions, render both theme kinds. The count rose from 275 because #52 brought its own assertions. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
index.phppermalink structure the sitemap is now published at the address that site actually serves, so both SEO-plugin indexes and the panel row stop naming a 404.robots.txt. Nothing it names there can be served.index.phpsite:/robots.txtreaches the filesystem on the server that shape implies, so the row names the file a crawler reads and the line to paste into it.Changes
includes/sitemap.php— the composer reads$wp_rewrite->root;sahaj_atlas_sitemap_is_servable()answers servability for the index entries,robots.txtand the panel.includes/diagnostics.php— check 6 gains theindex.phpbranch, derives the displayed path from the composer's URL, and reads the one servability predicate instead of the option.tests/run.php—sahaj_set_permalink_structure()joins the shared fixtures, delegating toWP_Rewrite::set_permalink_structure().AGENTS.md— trap 24, and the line references the diff moved.Test results
pnpm test:all— lint (12 files), measure, PHP suite (275 assertions), render (both theme kinds)tests/sitemap.php, each made to fail once firstManual verification
The automated lanes cannot reach the defect this fixes, because wp-playground routes every request through PHP and so has no missing mod_rewrite to reproduce. On a server without mod_rewrite:
Custom Structure→/index.php/%postname%/. Open Settings → Sahaj Atlas and confirm the Sitemap row warns, names/robots.txtat the top of the domain, and offers aSitemap:line carrying theindex.phpsegment./sahaj-atlas-sitemap.xmland confirm it 404s — that 404 is what the plugin used to publish.robots.txtat the domain root, fetch it, and confirm a crawler now reaches the sitemap. The row then reports the real-file case instead.Plain, fetch/?sitemap=1and confirm the index has no Sahaj Atlas entry, and/?robots=1and confirm noSitemap:line./index.php/%postname%/, confirm the Clean URLs row staysokand a deep link such as/index.php/find-a-class/gb/londonstill serves the atlas.Notes for reviewer
add_filter()calls. It is instead one guard insahaj_atlas_sitemap_index_entry(), the seam both adapters funnel through, plus the same guard insahaj_atlas_robots_txt(). Same effect, and it sits where the unservable URL would be composed, so a direct call to the adapter is testable — which is what the ticket's verification checklist asks for.robots.txtneeded the guard after all. The ticket said to leave that filter alone, because core serves no virtualrobots.txton a plain-permalink site. True of/robots.txt, false of/?robots=1:robotsis a public query var and that loop runs outsideparse_request()'s rewrite block, sodo_robots()fires with no rewrite rules at all. Measured, below. Low stakes — no crawler guesses?robots=1— but the two halves of one refusal now read one predicate./?sahaj_atlas_sitemap=1) would make the file servable on plain permalinks instead of withholding the entry, and core's ownWP_Sitemaps_Index::get_index_url()does exactly that. That is evidence for whoever answers the question, not a decision this PR took;robots.txtstill cannot carry the line there, and check 6's wording would have to change.$wp_rewriteis a new dependency in this plugin, the first, and it is now deliberate rather than incidental:sahaj_atlas_sitemap_is_servable()reads the cached rewrite state because that is what a request is routed by, and an assertion writes the option bare to pin the difference. Path routing's three reads of the option are untouched — fix(sitemap): the plugin publishes a sitemap URL it cannot serve #50 says moving them would switch a working feature off.update_option( 'permalink_structure', … )writes intests/run.php,tests/contract.phpandtests/seo.phpnow have a fixture they should use and do not. Left alone deliberately — converting them changes state those suites assert against. Worth its own ticket.Detail
Measured, in the lane's own WordPress 6.7.9 / PHP 7.4
using_index_permalinksusing_mod_rewrite_permalinksrootfront''''''/index.php/%postname%/'index.php/''/index.php/'/%postname%/'''/'/blog/%postname%/'''/blog/'rootis the right field andfrontis the trap:frontabsorbs a/blog/prefix the sitemap must not carry.A real request for
/index.php/sahaj-atlas-sitemap.xmlagainst a booted instance on that structure returned 200application/xmlwith the<urlset>.sahaj_atlas_maybe_serve_sitemap()needed no change because core strips its index file before setting$wp->request.Measured for the review round.
WP_Rewrite::rewrite_rules()returns 0 rules for an empty structure and 94 for the other two, and writesrobots\.txt$ => index.php?robots=1on both non-empty shapes — so core does author the rule on anindex.phpsite, and only the server's missing rewrite layer keeps/robots.txtfrom reaching it. That is why check 6 warns rather than failing: a site can choose this structure with mod_rewrite present, and the two are indistinguishable from inside the plugin. Separately,robotsis inWP::$public_query_vars, andparse_request()'s! empty( $rewrite )block closes atclass-wp.php:298while that loop starts at:319— outside it.What the automated lanes do not prove. On that same instance the bare
/sahaj-atlas-sitemap.xmlalso returned 200, because wp-playground has no rewrite layer to be missing. The claim that the bare path 404s rests on how such a site is configured —index.phppermalinks are what WordPress offers when mod_rewrite is unavailable — not on a measurement, which is why step 2 of the manual checks exists. The same limit applies to/robots.txtin step 3.Each new assertion failed once, per AGENTS.md. Of the first round's twelve, six failed against
main, and six were regression guards made to fail against the wrong fix instead: forcingusing_mod_rewrite_permalinks()into the Clean URLs row and intosahaj_atlas_parse_request()'s gate, making the composer prefix unconditionally, demanding the prefix in the serve guard, and stripping the index segment fromsahaj_atlas_mount_key(). One of the twelve is gone, because theokrow it asserted on no longer exists on that shape. This round's five failed against the branch as reviewed: three with theindex.phpbranch disabled, therobots.txtone with its guard disabled, and the desync one with check 6 readingget_option( 'permalink_structure' )again.Fixture pre-mortem.
sahaj_set_permalink_structure()assumes a real permalink change writes the option and re-initialisesWP_Rewrite. Verified againstwp-includes/class-wp-rewrite.phpin the lane:set_permalink_structure()is that pair plus thepermalink_structure_changedaction, and it is whatwp-admin/options-permalink.phpcalls. Core guards it on a changed value, so a repeated call is a no-op.Rejected: guarding registration instead of the entry. Cheaper by three
add_filter()calls, but it puts the refusal far from the composer and leaves the entry function happy to publish a 404 to a direct caller.Rejected: converting all nine bare permalink writes in the other test files. A latent desync, but not this ticket's, and
tests/seo.phpandtests/contract.phpassert against the state those writes leave.Review passes run.
/simplifyover the branch (four lenses) plus the built-in/security-review, since the diff matchessecurityReview.triggerPattern. Security found nothing; the efficiency lens found nothing. The reuse and simplification lenses both found the$wp_rewrite->rootduplication, which is the firstrefactor:commit. The altitude lens proposed the query-arg mount, declined above as an open question.pr-review-toolkitis not installed here, so the pass was/code-review highplus/simplify.Tool limitation hit.
comment-lint.mjsreports0 changed file(s)on this diff: its extension filter covers only JS/TS, so it sees nothing in a PHP-only change, although its own docstring calls it the one comment check that covers this repo.Closes #50
🤖 Generated with Claude Code
https://claude.ai/code/session_01STv5BmDf3saWEGu8THHybC