Skip to content

fix(sitemap): the plugin publishes a sitemap URL it cannot serve - #53

Merged
sydevs-bot merged 10 commits into
mainfrom
claude/fix-50-sitemap-permalinks
Oct 2, 2026
Merged

sydevs-bot merged 10 commits into
mainfrom
claude/fix-50-sitemap-permalinks

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • On an index.php permalink 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.
  • On plain permalinks the plugin no longer publishes a sitemap address at all — not to Yoast, not to Rank Math, and not in robots.txt. Nothing it names there can be served.
  • One composer owns the address and one predicate owns whether it can be served, so all four readers follow both. The serve guard needs no branch.
  • Check 6 warns on an index.php site: /robots.txt reaches 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.txt and the panel.
  • includes/diagnostics.php — check 6 gains the index.php branch, 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 to WP_Rewrite::set_permalink_structure().
  • AGENTS.md — trap 24, and the line references the diff moved.

Test results

  • Lean gate: ✓ pnpm test:all — lint (12 files), measure, PHP suite (275 assertions), render (both theme kinds)
  • Targeted specs: 16 new assertions in tests/sitemap.php, each made to fail once first
  • Build: N/A

Manual 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:

  1. Set Permalinks to Custom Structure → /index.php/%postname%/. Open Settings → Sahaj Atlas and confirm the Sitemap row warns, names /robots.txt at the top of the domain, and offers a Sitemap: line carrying the index.php segment.
  2. Fetch that sitemap address and confirm XML, then fetch /sahaj-atlas-sitemap.xml and confirm it 404s — that 404 is what the plugin used to publish.
  3. Paste the offered line into a real robots.txt at the domain root, fetch it, and confirm a crawler now reaches the sitemap. The row then reports the real-file case instead.
  4. With Yoast active and Permalinks set to Plain, fetch /?sitemap=1 and confirm the index has no Sahaj Atlas entry, and /?robots=1 and confirm no Sitemap: line.
  5. Still on /index.php/%postname%/, confirm the Clean URLs row stays ok and a deep link such as /index.php/find-a-class/gb/london still serves the atlas.

Notes for reviewer

  • Where the plain-permalink refusal lives. The ticket said to guard the two add_filter() calls. It is instead one guard in sahaj_atlas_sitemap_index_entry(), the seam both adapters funnel through, plus the same guard in sahaj_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.txt needed the guard after all. The ticket said to leave that filter alone, because core serves no virtual robots.txt on a plain-permalink site. True of /robots.txt, false of /?robots=1: robots is a public query var and that loop runs outside parse_request()'s rewrite block, so do_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.
  • The ticket's second open question is still open. A query-arg mount (/?sahaj_atlas_sitemap=1) would make the file servable on plain permalinks instead of withholding the entry, and core's own WP_Sitemaps_Index::get_index_url() does exactly that. That is evidence for whoever answers the question, not a decision this PR took; robots.txt still cannot carry the line there, and check 6's wording would have to change.
  • $wp_rewrite is 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.
  • The nine bare update_option( 'permalink_structure', … ) writes in tests/run.php, tests/contract.php and tests/seo.php now 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

structure using_index_permalinks using_mod_rewrite_permalinks root front
'' false false '' ''
/index.php/%postname%/ true false 'index.php/' '/index.php/'
/%postname%/ false true '' '/'
/blog/%postname%/ false true '' '/blog/'

root is the right field and front is the trap: front absorbs a /blog/ prefix the sitemap must not carry.

A real request for /index.php/sahaj-atlas-sitemap.xml against a booted instance on that structure returned 200 application/xml with 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 writes robots\.txt$ => index.php?robots=1 on both non-empty shapes — so core does author the rule on an index.php site, and only the server's missing rewrite layer keeps /robots.txt from 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, robots is in WP::$public_query_vars, and parse_request()'s ! empty( $rewrite ) block closes at class-wp.php:298 while that loop starts at :319 — outside it.

What the automated lanes do not prove. On that same instance the bare /sahaj-atlas-sitemap.xml also 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.php permalinks 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.txt in 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: forcing using_mod_rewrite_permalinks() into the Clean URLs row and into sahaj_atlas_parse_request()'s gate, making the composer prefix unconditionally, demanding the prefix in the serve guard, and stripping the index segment from sahaj_atlas_mount_key(). One of the twelve is gone, because the ok row it asserted on no longer exists on that shape. This round's five failed against the branch as reviewed: three with the index.php branch disabled, the robots.txt one with its guard disabled, and the desync one with check 6 reading get_option( 'permalink_structure' ) again.

Fixture pre-mortem. sahaj_set_permalink_structure() assumes a real permalink change writes the option and re-initialises WP_Rewrite. Verified against wp-includes/class-wp-rewrite.php in the lane: set_permalink_structure() is that pair plus the permalink_structure_changed action, and it is what wp-admin/options-permalink.php calls. 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.php and tests/contract.php assert against the state those writes leave.

Review passes run. /simplify over the branch (four lenses) plus the built-in /security-review, since the diff matches securityReview.triggerPattern. Security found nothing; the efficiency lens found nothing. The reuse and simplification lenses both found the $wp_rewrite->root duplication, which is the first refactor: commit. The altitude lens proposed the query-arg mount, declined above as an open question. pr-review-toolkit is not installed here, so the pass was /code-review high plus /simplify.

Tool limitation hit. comment-lint.mjs reports 0 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

claude added 4 commits October 1, 2026 21:39
`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
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 1, 2026
@sydevs-bot

sydevs-bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 00:35Z resolve-conflicts · attempt 1 · session · done
  • 00:35Z resolve-conflicts · attempt 1 · session
  • 00:27Z resolve-conflicts · attempt 1 · session · done
  • 00:27Z resolve-conflicts · attempt 1 · session
  • 22:03Z address-review · attempt 1 · session · done

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

@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 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 — ok claims a line this site cannot publish.
  • consider — sitemap.php:311 — two spellings of one predicate
  • consider — sitemap.php:308 — /?robots=1 runs 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

Comment thread includes/diagnostics.php Resolved
Comment thread includes/sitemap.php Resolved
Comment thread includes/sitemap.php 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 Oct 1, 2026
claude added 4 commits October 1, 2026 22:14
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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Three threads from the adversarial review, all adopted. Head 2d8a333, pnpm test:all green at 275 assertions.

  • diagnostics.php:533 — check 6 warns on an index.php site, naming the domain-root robots.txt and the line to paste. It claimed ok where that line is never served.
  • sitemap.php:311 — sahaj_atlas_sitemap_is_servable() answers servability for all four readers. Path routing keeps its own reading of the option.
  • sitemap.php:308 — /?robots=1 runs the robots_txt filter with no rewrite rules, confirmed in the lane, so it takes the same guard.

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

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 1, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review October 1, 2026 22:27
@sydevs-bot
sydevs-bot requested a review from Ardnived October 1, 2026 22:27
@sydevs-bot
sydevs-bot enabled auto-merge October 1, 2026 22:28
@sydevs-bot sydevs-bot moved this from Revising to Approved in SYDevelopers Technical Roadmap Oct 2, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 2, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 2, 2026
#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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main in. One conflict, in AGENTS.md: #54 and this branch each appended a trap numbered 24. Both are kept — the i18n trap keeps 24, the number already on main, and the sitemap trap becomes 25. Nothing cites a trap by number, so the renumber stays inside the file.

tests/run.php auto-merged, and both ⚠ line references in it still land.

pnpm test:all green: lint 12 files, measure, PHP suite 284 assertions, render both theme kinds.

🤖 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 Oct 2, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 2, 2026
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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main (#52). One conflict: trap 14 in AGENTS.md, a line-number breadcrumb into includes/diagnostics.php.

Took neither side. Both sides shifted that file, so both numbers were already wrong for the merged tree — 284,639 here, 296,928 on main, while the two ⚠ anchors land at 296,954. Recomputed from the merged file. Trap 24's breadcrumb into the same file never conflicted but moved the same way, so it goes to 545,564.

#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

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 2, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 2, 2026
Merged via the queue into main with commit 68838bf Oct 2, 2026
12 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-50-sitemap-permalinks branch October 2, 2026 00:46
@Ardnived Ardnived mentioned this pull request Oct 2, 2026
3 tasks done
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(sitemap): the plugin publishes a sitemap URL it cannot serve

3 participants