Skip to content

fix(seo): read ?atlas= into the route variable, so a query-routed page declares our canonical instead of contradicting it - #21

Merged
Ardnived merged 6 commits into
mainfrom
claude/fix-20-query-route-seo
Sep 12, 2026
Merged

Ardnived merged 6 commits into
mainfrom
claude/fix-20-query-route-seo

Conversation

@sydevs-bot

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

Copy link
Copy Markdown
Contributor

Summary

  • A query-routed atlas deep link now gets the SEO takeover: the canonical SahajCloud published, the route's own title, description, hreflang, JSON-LD and crawlable body content.
  • Core's rel_canonical and the host's SEO plugin are suppressed on those pages, so each one stops contradicting the canonical the sitemap points at.
  • Path routing, the atlas root, and every page that is not the Atlas page behave exactly as before.

Changes

  • includes/routing.php — sahaj_atlas_current_route() falls back to ?atlas=, gated on the Atlas page; the canonical-redirect filter keys on the path route alone.
  • sahaj-atlas.php — SAHAJ_ATLAS_ROUTE_PARAM, pinned to the shared contract's queryParam.
  • includes/seo.php — the transient key moves into sahaj_atlas_seo_slot(), so a fixture seeds the cache through the plugin's own builder rather than a copy.
  • includes/routing.php, AGENTS.md, tests/seo.php — the rationale for keying the canonical-redirect filter on the path route, restated after review (08183d8). See Notes for reviewer.

Contract impact

tests/atlas-url-contract.json is untouched and verified byte-identical to SahajCloud's copy. What changes is that this plugin now answers the contract's seven routing: "query" cases as well as its path cases — tests/contract.php replays both halves. Named but not filed by sydevs/SahajCloud#644; the two changes stay independent.

Test results

  • Lean gate: ✓ pnpm test:all — 12 files lint clean, 167 assertions / 0 failures, render 0 failures across both theme kinds. Re-run on 08183d8, same result.
  • Contract step: ✓ tests/atlas-url-contract.json diffs clean against SahajCloud main
  • Security review: ✓ /security-review over the diff (^includes/|^sahaj-atlas\.php matches securityReview.triggerPattern) — no findings

Manual verification

  1. On a site whose client record uses routing: query, open an atlas deep link and view source: one <link rel="canonical">, matching the loc in /sahaj-atlas-sitemap.xml.
  2. With Yoast or Rank Math active on that site, confirm neither emits a second canonical on that page.
  3. Confirm an ordinary page still redirects normally when its permalink changes — the canonical redirect is untouched off atlas routes.

Notes for reviewer

The judgement call worth checking is the split between sahaj_atlas_current_route() and sahaj_atlas_path_route(). The ticket said to leave sahaj_atlas_suppress_canonical_redirect() "correct for both", and to check rather than assume. Checking said the two want different answers — but not for the reason first recorded here, which the adversarial review then caught and 08183d8 corrects.

The false reason: that widening the filter would switch redirect_canonical() off for any page load carrying ?atlas=. It would not. sahaj_atlas_query_route() refuses off the Atlas page, so an ordinary page load never reaches a non-empty route, and tests/seo.php asserts exactly that.

The real reason: the contract publishes /?p=42&atlas=… and /index.php?page_id=7&atlas=… mounts, and core 301s each to the page's pretty permalink with ?atlas= intact — atlas is no registered query var for core to consume. That redirect is what carries a query-routed visitor to the canonical URL. Suppressing it would strand them on the mount. So the filter keys on the path route, which is byte-identical to today's behaviour, and the tests pin both directions.

Detail

Why the Atlas page gate is load-bearing. ?atlas= is a parameter anyone can append to any URL on the site, and sahaj_atlas_current_route() feeds sahaj_atlas_seo_boot(). Without the gate an arbitrary page could be talked into claiming an atlas route's canonical as its own. sahaj_atlas_seo_boot() checks the same thing, but the guarantee belongs where the parameter is read.

Why $_GET and not a registered query var. Recorded as a third ⚠ on the function. A registered var is filled from $_POST before $_GET, so the route would become accepted from a request body; it would still need the Atlas page check, since get_query_var() answers on every page; it would claim the bare name atlas across the host's whole site; and sahaj_atlas_parse_request() replaces $wp->query_vars wholesale, so it would be discarded on the path-routed requests. It also keeps redirect_canonical() from consuming atlas on the mount shapes above.

The sanitiser is the existing one. sahaj_atlas_clean_route(), the same function the block and shortcode attribute already use. A value it refuses leaves the route empty, so the page falls back to the host's own metadata rather than emitting a wrong canonical. An unresolvable route is refused one step later: the endpoint 404s it and sahaj_atlas_seo_fetch() caches the miss.

sahaj_atlas_parse_request() is untouched, as the ticket asked. A query-routed page needs no rewrite — WordPress already served it — and its three refusals are what sahaj_atlas_path_routing_viable() declares to SahajCloud#644's probe.

Fixture pre-mortem. tests/fixtures/seo-answer.php is one AtlasSeoResponse, shared by the PHP suite and both render blueprints. Its shape was verified against src/endpoints/responseTypes.ts:149-188 in sydevs/SahajCloud (AtlasSeoBase, AtlasSeoRegionContent, AtlasSeoEventCard), not invented from this plugin's reader — a fixture derived from the reader would only assert that the reader reads itself.

⚠ A trap this cost one round. $_GET is already slashed when a plugin reads it; wp_magic_quotes() runs on every request, so the plugin unslashes. A fixture that assigns a raw value therefore tests a request WordPress never delivers — /\evil.com sailed through as /evil.com until every query-routing case went through sahaj_set_query_route(), which slashes first. Recorded in AGENTS.md and at tests/run.php:242.

⚠ A wrong reason costs more than no reason. The rationale corrected in 08183d8 read plausible and survived a whole implementation round. The next reader checks it, finds it false, and then has to re-derive the decision or undo it. All three copies now carry the real reason and mark the wider claim wrong, so it does not come back.

Each new assertion was watched failing. With the early return reintroduced: 21 red in the PHP suite, 6 per theme in the render lane. Restored, all green. Re-run after the cleanup pass rewrote the assertions' shape.

The /simplify pass is the last code commit. Four cleanup agents (reuse, simplification, efficiency, altitude) reviewed the branch; that commit's body lists what was applied and what was skipped, with reasons.

add_query_arg() does not URL-encode its values, so a route splices raw into the outbound endpoint request. The security review traced it and declined to report it: the caller already controls route legitimately, the only other parameter is locale (affecting that request's own answer), the answer caches under its own transient slot, and the host, path and Authorization header are unreachable. Not exploitable today, and it predates this branch — a path route can carry & too. Worth rawurlencode() if /api/atlas/seo ever grows a parameter that matters. Left alone rather than widening this PR; say the word and I will file it.

One pipeline step did not run. /pr-review-toolkit:review-pr is not available in this session, so the six-lens review was not performed. /simplify and /security-review were.

Closes #20

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

🤖 Generated with Claude Code

https://claude.ai/code/session_013q7a2QtKsRJLAwYyfZwYUM

`sahaj_atlas_current_route()` read one thing: the query var only
`sahaj_atlas_parse_request()` sets, and only under path routing. So on a
query-routed host every atlas deep link returned `''`, `sahaj_atlas_seo_boot()`
returned early, and two things followed: no per-route metadata and no crawlable
body content, and no suppression either — core's `rel_canonical` and the host's
SEO plugin kept emitting the bare permalink. Each `loc` SahajCloud publishes
named a page that named a different canonical.

Query routing is permanent for the hosts on it, not transitional: a site with
plain permalinks, an atlas at its front page, or a server SahajCloud cannot
probe stays there for good.

`sahaj_atlas_current_route()` now falls back to `?atlas=`, through the same
`sahaj_atlas_clean_route()` sanitiser the block attribute uses, gated on the
Atlas page — the parameter is one anyone can append to any URL, and an ungated
read would let an arbitrary page claim an atlas route's canonical.

`sahaj_atlas_suppress_canonical_redirect()` keys on the path route alone now.
A query-routed URL is the page's own permalink plus a parameter, so
`redirect_canonical()` has nothing to strip, and widening the filter would
disable a core behaviour on every ordinary page load carrying `?atlas=`.

`sahaj_atlas_parse_request()` is untouched: a query-routed page needs no
rewrite, and its three refusals are what `sahaj_atlas_path_routing_viable()`
declares.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013q7a2QtKsRJLAwYyfZwYUM
`tests/seo.php` seeds the endpoint's answer and asserts the takeover itself:
the canonical emitted once and equal to the published one, core's
`rel_canonical` and shortlink silenced, the title, hreflang, JSON-LD and
crawlable body, the root exclusion, a hostile or array parameter refused, and
an ordinary page carrying `?atlas=` left alone.

`tests/contract.php` now replays the contract's seven `routing: "query"` cases
as the parameter they arrive in, alongside the path cases it already replayed
as requests, and pins `SAHAJ_ATLAS_QUERY_VAR` to the contract's `queryParam`.

The render lane fetches `/find-a-class/?atlas=/nl/amsterdam` on both theme
kinds and asserts the rendered `<head>`, not a status code.

⚠ `$_GET` is already slashed when a plugin reads it — `wp_magic_quotes()` runs
on every request. A fixture assigning a raw value tests a request WordPress
never delivers, and `/\evil.com` passed as `/evil.com` until every case went
through `sahaj_set_query_route()`.

Each new assertion was watched failing against the reintroduced early return:
21 in the PHP suite, 6 per theme in the render lane.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013q7a2QtKsRJLAwYyfZwYUM
…refs

Trap 9 now states which route the canonical-redirect filter keys on. Trap 17
states that the route variable answers both shapes, and why reading `?atlas=`
stays gated on the Atlas page. The testing section gains the `$_GET` slashing
trap. Five `⚠` line references moved with this diff.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013q7a2QtKsRJLAwYyfZwYUM
The hook comment said `sahaj_atlas_seo_boot()` reads a route the embed
resolver already validated. The resolver hard-codes `'atlas' => ''` for the
Atlas page, so it validates nothing here — `sahaj_atlas_query_route()` does.
Found by the branch security review, which confirmed the code is right and
only the comment misattributed the check.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013q7a2QtKsRJLAwYyfZwYUM
Four cleanup agents reviewed the branch for reuse, simplification, efficiency
and altitude. Applied:

- `sahaj_atlas_seo_slot()` loses its `$locale` parameter. The one production
  caller passed exactly what the null branch computed, and a caller free to
  name a different locale writes a transient nothing ever reads — a fixture
  failure that surfaces as a live request timing out.
- `SAHAJ_ATLAS_QUERY_VAR` becomes `SAHAJ_ATLAS_ROUTE_PARAM`. It sat beside
  `SAHAJ_ATLAS_ROUTE_VAR` reading as though it were a registered query var,
  which is the one thing it is pointedly not.
- `sahaj_atlas_query_route()` unslashes after its type and emptiness guards
  instead of before, so an array or empty parameter is rejected without
  walking it. Behaviour is unchanged; `wp_unslash()` never yielded a string
  from a non-string.
- A third `⚠` records why the read is `$_GET` and not a registered query var:
  a registered var is filled from `$_POST` first, still needs the Atlas page
  check, claims the bare name `atlas` site-wide, and would be discarded by
  this file's own `parse_request` handler.
- `includes/routing.php`'s header said "Path routing"; the file now owns both
  shapes.
- One SEO answer fixture, `tests/fixtures/seo-answer.php`, replaces three
  copies — the PHP suite's and one inside each render blueprint's JSON-escaped
  `runPHP` string. The copies had already diverged on `breadcrumbs`.
- `sahaj_query_page()`, `sahaj_clear_query_route()` and
  `sahaj_seo_untouched()` replace hand-rolled repeats in the new test code.
- `sahaj_seo_reset()` drops two `remove_filter` lines no assertion reads.

Skipped, with reasons: passing the API key into `sahaj_atlas_seo_slot()` to
save one cached `get_option` (the signature is worth more than the lookup);
dropping the `'' === $raw` guard as redundant with the sanitiser (it is the
early-out that keeps an empty parameter from reaching `is_atlas_page()`);
routing the pre-existing `WP_Query` at tests/run.php:197 through the new
helper (it is outside this branch's diff, and the helper is defined below it).

The 21-red / 6-red-per-theme defect check was re-run after the test rewrite.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013q7a2QtKsRJLAwYyfZwYUM
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 12, 2026
@sydevs-bot

sydevs-bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 18:53Z address-review · attempt 1 · session · done
  • 18:53Z address-review · attempt 1 · session
  • 18:44Z adversarial-review · attempt 1 · session · done
  • 18:44Z adversarial-review · attempt 1 · session

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

Right-sized for #20: ~20 lines of logic, the rest tests, a fixture and AGENTS.md. Path routing is untouched, the ?atlas= read is gated on the Atlas page, and a path route still beats a crafted parameter. sahaj_atlas_seo_slot() is the one thing #20 did not ask for, and it earns its place by deleting a copied md5 recipe from three test sites.

Producer side verified: SahajCloud's canonicalUrlBase() ends a query base at …?atlas= and appends the path raw, so the fixture and SAHAJ_ATLAS_ROUTE_PARAM match what it publishes.

On add_query_arg() not encoding the route: file it separately.

Findings

  • should-fix — the rationale at routing.php:121-124, copied into AGENTS.md trap 9 and tests/seo.php:88-92.

What was checked

  • #20 against the diff; routing.php, seo.php, page.php:36, embed.php:179 read.
  • Contract JSON byte-identical to SahajCloud's; canonicalUrl.ts:118-134 read.
  • Render lane asserts the <head>, not a status.
  • Only sahaj_atlas_seo_boot() calls sahaj_atlas_current_route().

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


Generated by Claude Code

Comment thread includes/routing.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 Sep 12, 2026
The rationale on `sahaj_atlas_suppress_canonical_redirect()` claimed that
widening the filter to every atlas route would switch `redirect_canonical()`
off for any page load carrying `?atlas=`. It would not.
`sahaj_atlas_query_route()` already refuses off the Atlas page, so
`sahaj_atlas_current_route()` is never non-empty there — tests/seo.php pins
exactly that.

The decision stands on a different fact. The shared contract publishes
`/?p=42&atlas=…` and `/index.php?page_id=7&atlas=…` mounts, and core 301s
each to the page's pretty permalink with `?atlas=` intact, since `atlas` is
no registered query var for core to consume. That redirect is what carries a
query-routed visitor to the canonical URL. Suppressing it would strand them
on the mount.

A wrong reason in a comment is worse than no reason: the next reader checks
it, finds it false, and has to re-derive the decision or undo it. Restated in
all three places that carried it — routing.php, AGENTS.md trap 9, and the
assertion comment in tests/seo.php — with the wider claim marked as wrong so
it does not come back.

Line references in AGENTS.md traps 12 and 17 move with the inserted lines.
Trap 12 now points at the `⚠` comment the file's own convention promises,
rather than a docblock five lines above it.

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

Copy link
Copy Markdown
Contributor Author

One thread, adopted. No behaviour changed — comments, AGENTS.md and the PR body only.

  • Adopted — the recorded reason is not the reason. ?atlas= is refused off the Atlas page, so the site-wide claim was false. The real reason is the contract's /?p=42&atlas=… mounts: core 301s each to the permalink with ?atlas= intact, and that redirect is what lands a query-routed visitor on the canonical URL. Restated in includes/routing.php, AGENTS.md trap 9 and tests/seo.php, each marking the wider claim wrong. 08183d8.

Nothing rebutted, nothing asked.

Lean gate re-run on 08183d8: 12 files lint clean, 167 assertions / 0 failures, render 0 failures on both theme kinds. Contract file still byte-identical to SahajCloud main.

🤖 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 12, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 12, 2026 19:03
@sydevs-bot
sydevs-bot requested a review from Ardnived September 12, 2026 19:03
@Ardnived
Ardnived merged commit 6b5e194 into main Sep 12, 2026
22 checks passed
@Ardnived
Ardnived deleted the claude/fix-20-query-route-seo branch September 12, 2026 19:06
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 12, 2026
sydevs-bot pushed a commit that referenced this pull request Sep 12, 2026
`main` moved under this branch with #21, which rewrote the same two files:
`sahaj_atlas_current_route()` now answers for `?atlas=` as well as the path
route, and `tests/seo.php` arrived there first, covering the query-routed
shape. Both halves are kept; four resolutions were needed.

- `sahaj_atlas_seo_cache_key()` is dropped for `sahaj_atlas_seo_slot()`.
  They are the same helper, written twice. #21's own /simplify pass removed
  the locale parameter on purpose — a caller free to name a locale writes a
  transient nothing reads — so the version without it wins, and the slot
  assertions drive the locale through `determine_locale` instead.
- `tests/seo.php` is one file again: #21's routing groups, then this
  branch's root, opt-out and trap-16 groups. The group asserting the root
  is *excluded* is now the group asserting it is described, which is the
  behaviour change this ticket is.
- A refused `?atlas=` now falls back to the root view rather than to
  nothing, since the page is the root view either way. The assertion that
  matters is the one that survives: the crafted value reaches neither the
  endpoint nor the canonical.
- `tests/fixtures/seo-answer.php` carries the root answer beside the region
  one, so both render blueprints seed from the one copy. It is seeded under
  `/search` as well as `/`, because the endpoint answers them alike but the
  cache is keyed on the route as asked.

`pnpm test:all` passes: 220 assertions, and 112 render assertions across
both theme kinds.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CyxoefN47eov1tQxCQ4Y7Z
Ardnived pushed a commit that referenced this pull request Sep 18, 2026
* chore(release): v0.2.0

Three merged changes ship in the plugin zip since v0.1.0, and a volunteer sees
none of them until a tag builds one: #21, #23 and #24. Everything else merged
since c1fec89 is CI, docs or tests, all of which `.distignore` keeps out of the
zip, and #10 and #13 touched shipping files in comments only.

Minor, not patch, and pre-1.0 either way: #23 adds a capability and a second
site setting, so the version has to move more than a fix would.

Four declarations, not two. `release.yml` compares the tag against the plugin
header alone, so it would have passed with `SAHAJ_ATLAS_VERSION` left at 0.1.0
— and that constant is the cache-buster on `atlas-page.css`, `atlas-page.js`
and the editor assets. Every updated site would have kept serving the 0.1.0
copies. `blocks/embed/block.json` declares the same version to the editor.
`package.json` declares none: it is dev tooling, and `.distignore` excludes it.

The changelog is written for the one non-technical volunteer who runs each
site, so it names what they will see rather than what changed in the code.

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

* fix(readme): the 0.1.0 entry claimed a 0.2.0 row

#23 edited the shipped `= 0.1.0 =` changelog entry, adding "and which
side describes the Atlas page" to the status-panel bullet. That row did
not exist at v0.1.0 — `git show v0.1.0:readme.txt` has the panel covering
four things, not five.

Plugin Update Checker merges readme.txt's sections into the WordPress
update modal, so a volunteer on 0.1.0 deciding whether to update reads
the fifth row credited to the version they already run. The 0.2.0 entry
announcing that same row then reads as a repeat, and the release that
actually ships it loses the credit.

A shipped release's entry describes what that release shipped.

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

---------

Co-authored-by: Claude <[email protected]>
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(seo): read ?atlas= into the route variable, so a query-routed page declares our canonical instead of contradicting it

3 participants