Repository navigation
fix(seo): a variant site locale still gets English metadata - #82
Conversation
`sahaj_atlas_seo_locale()` anchored its pattern at `xx` or `xx-YY`, so a WordPress locale spelled any other way matched nothing, the SEO request carried no `locale`, and SahajCloud answered in English. #73 fixed the regional case by retrying a refused tag as its bare language, but a locale that never matched never entered that chain. Real locales this refused: `de_DE_formal`, `nl_NL_formal`, `pt_PT_ao90`, `de_CH_informal`, and every three-letter language such as `ckb`, `bal` and `rup_MK`. A site set to "German (Formal)" handed crawlers the English title and description. Read the first two subtags and ignore whatever follows them, and let the language subtag be two or three letters. The retry chain already drops a refused tag to its bare language and then to no locale, so nothing else changes and the plugin still keeps no copy of SahajCloud's locale list. The new `tests/seo.php` group walks all three hops with every locale refused, and pins that a value with no language subtag still sends none — the guard the widened pattern needs. Closes #80 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXvebmSqNbgVwW3jam
The locale group added a `determine_locale` returner and a `pre_http_request` refusal stub beside the ones the regional group already had, so the file carried four one-line locale functions and two copies of the endpoint's 400 shape. Each also needed its own hand-paired add_filter/remove_filter, and an unmatched one leaks a locale into every group below. The locale is now a global one filter reads, and the refusal pattern is a third argument to `sahaj_seo_stub()`, which `sahaj_seo_http_stub()` already owned the response shape for. Both refusal stubs go. `sahaj_seo_asked_locale()` replaces the hand-rolled URL probe in six assertions, so `sahaj_is` can print the locale a failing hop actually asked for instead of `false`. Both halves were watched failing: the old pattern still fails four of the new assertions, and a refusal pattern that matches nothing still fails the regional group's two. The production comment moves the locale inventory into the docblock and keeps only the constraint, the #80 breadcrumb and why the refusal branch stays. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXvebmSqNbgVwW3jam
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the size of its ticket: one widened pattern, plus the test refactor four locales force. Asserting the locale per hop, not just the hop count, is what fails against the defect. Criterion 5 checks out — B on #81's thread settles it, so readme.txt is correctly untouched here.
Not the question you asked. You offer a site-wide transient against the 2–3 blocking hops. Do not build it. The hops exist only because this plugin must not hold SahajCloud's locale list — and the endpoint that owns that list already has baseLanguage() beside it (src/lib/locales/index.ts:54). An endpoint resolving de-DE to de itself would delete the retry chain, this widening and the 15s diagnostics block, for every consumer at once. Is the fallback in the wrong repo?
Findings
consider— start fromget_bloginfo( 'language' ), notdetermine_locale():includes/seo.php:622.consider— the ⚠ narrates the pattern and the one it replaced, and omits the backtracking:includes/seo.php:624.consider— ask SahajCloud to resolve a near-miss locale, above. No line in this diff.
What was checked
Read on the branch: includes/seo.php, tests/seo.php, includes/embed.php:380-396. Re-traced the new pattern by hand over de_DE_formal, be_tarask, art_xemoji, es_419, ckb, default and EN_us — no case it gets wrong. Producer side read: de is listed and de-DE is not, with no three-letter code (src/lib/locales/index.ts:13), and an unlisted locale is refused by the querySchema refine (src/endpoints/atlas/seo/index.ts:90), so the fixture's premises hold. Ladder: no new file, hook, option or dependency. One global and one filter replace sahaj_seo_dutch(); sahaj_seo_asked_locale() replaces six inline URL probes; $refuse replaces sahaj_seo_refuse_region(). Four call sites each.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The first two sentences restated the pattern and the pattern it replaced, neither of which a fresh reader of this file can see. What was missing is why the trailing `(?:-|$)` is there at all: without it a two-letter variant subtag backtracks into the region group and `be_tarask` asks for `be-TA`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYThPkR3z8N5N9mYEL
|
Both adversarial-review threads answered. Pushed d5045b4.
Lean gate 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
de_DE_formalorckbsite now gets its own language's SEO metadata, not English.tests/seo.phpcollapse to one of each.Change outline
Flow — what an Atlas page asks the SEO endpoint for
Only the locale parser changed. The retry chain below it is untouched — it finally has a tag to drop.
sahaj_atlas_seo_fetch( route ) includes/seo.php sahaj_atlas_seo_locale() determine_locale(), underscores → hyphens - `xx` or `xx-YY` exactly, else '' # de-DE-formal, ckb → '' → asks in English + first two subtags, language 2–3 letters # de-DE-formal → de-DE, ckb → ckb + no leading language subtag → '' # default, x — refused without a round trip foreach unique( tag, bare language, '' ) # unchanged 400 → next hop # de-DE → de → (none)deis listed upstream andde-DEis not, so a "German (Formal)" site lands on German at the second hop.Behaviour — one locale stub and one refusal stub in
tests/seo.phpThis ticket's group would have added a fifth locale returner and a second copy of the endpoint's 400 shape, so both collapse instead.
Each group now arms one filter instead of pairing two by hand, and a failing hop prints the locale it asked for rather than
false.Test results
pnpm test:all— PHP syntax lint (15 files), measure lane, WordPress 6.7 / PHP 7.4 behaviour suite, render checks per theme kind. 0 failures.tests/seo.phplocale groups, 8 new assertions; 440 in the behaviour lane.tests/atlas-url-contract.jsonmatches SahajCloud's copy.Both halves were watched failing. Restoring
^([a-z]{2})(?:-([A-Za-z]{2}))?$fails four of the new assertions (expected: 'de-DE' / actual: ''). A refusal pattern matching nothing fails the regional group's two, so the collapsed stub is load-bearing there too.Manual verification
<title>and<meta name="description">in the source — both should be German. Before this, both were English.Notes for reviewer
Bon #81's thread. There is no next version to carry an entry, soreadme.txtis untouched and no version heading is opened. chore(release): 0.3.4 #81 updates its unpublished= 0.3.4 =entry once this lands.SAHAJ_ATLAS_SEO_TTL,includes/seo.php:30). The settings panel's description check runs the same call synchronously (includes/diagnostics.php:388), so it can block up to 15s instead of 5s on such a site. Pre-existing since fix: localized SEO for national sites, clean query routes, release-only updates #73; this change widens who pays it. Two fixes, neither built here: a site-wide transient holding the tag the server last accepted, or — the adversarial review's case, which reads stronger — moving the fallback upstream, since SahajCloud already hasbaseLanguage()beside the locale list (src/lib/locales/index.ts:54), and an endpoint resolvingde-DEtodeitself would delete the retry chain, this widening and the diagnostics block for every consumer at once. Which repo pays is your call.determine_locale(). The question this body asked is answered on its thread.get_bloginfo( 'language' )is not the page's declared tag: core builds the attribute from it, then hands the whole string to thelanguage_attributesfilter (general-template.php:4403), which is the hook a multilingual plugin uses — so starting there closes no gap. It would also trade a mechanical transform for__( 'html_lang_attribute' ), a translator-supplied string, which trap 10 bars from running beforeinit. Where a language pack leaves that string untranslated, core's own fallback isstr_replace( '_', '-', determine_locale() )— byte-identical to this function's input, so the 92-locale check still holds.explode/array_slice. It reads the same for every real locale, butes-419andxwould then go upstream and cost a 400 each, and criterion 3 asks for no locale when there is no language subtag. The ⚠ now records why the branch stays, so it is not widened a third time.'' → ''by callingsahaj_atlas_seo_locale()directly instead of end-to-end. The criterion is about what the request carries, which only the request chain shows.Detail
Fixture pre-mortem. The new cases assume SahajCloud refuses an unlisted
localewith a 400, and listsdebut notde-DEand no three-letter code at all. Verified against the real config:src/lib/locales/index.tsin SahajCloud (en,es,de,it,fr,ru,ro,cs,uk,el,hy,pl,pt-BR,fa,bg,tr,en-AU,hu,nl— none three-letter), thelocalerefine atsrc/endpoints/atlas/seo/index.ts:90, andsrc/lib/endpoints/parseQuery.ts:30, where a failed schema parse returns 400. No lane reaches the real endpoint; the behaviour lane's no-network assertion still passes.What the pattern resolves. Checked against the WordPress locales that matter:
de_DE_formal→de-DE,nl_NL_formal→nl-NL,pt_PT_ao90→pt-PT,de_CH_informal→de-CH,ckb→ckb,rup_MK→rup-MK,be_tarask→be,art_xemoji→art,es_419→es. Unchanged foren_US,pt_BR,nl_NL,zh_TW. Refused, as before:'',x,default,EN_us.The trailing
(?:-|$)is load-bearing, not decoration. Without it a two-letter variant subtag would backtrack into the region group andbe_taraskwould ask forbe-TA. The ⚠ on the pattern now carries that, in place of two sentences restating the pattern and the one it replaced.Review passes.
/simplify(four angles) and/code-review high— nopr-review-toolkitin a routine./security-reviewran on each push because the diff matchessecurityReview.triggerPattern; no findings. The return value is rebuilt from the two capture groups, so the producible alphabet is still[a-z]{2,3}optionally plus-[A-Z]{2}, it israwurlencode_deep-ed into a constant origin, and nothing echoes it. Docs checked acrossAGENTS.md,docs/andreadme.txt: nothing stale.Closes #80
Generated by Claude Code