Repository navigation
fix(list): sort recommended by the base language, not the resolved locale - #225
Conversation
…cale i18next resolves to a regional tag wherever one carries the bundle, and two of SahajCloud's nineteen LOCALES are regional: `pt-BR` and `en-AU`. On either of them `recommended` compared that tag against an event's `languages[0]`, which is always an ISO 639-1 two-letter code — the `languages` select is built from `getLanguageOptions()` and offers nothing else. No event matched, so the x2 wrong-language penalty landed on all of them. Being uniform it then cancelled out of the ordering, and `recommended` silently went language-blind: a local class was no longer promoted over an equidistant foreign-language one. `useLocale()` already publishes both shapes, and `languageCode` is the base subtag `docs/rules/i18n-and-state.md` names for exactly this comparison — `EventChips`, `Map` and `use-turnstile` all take it. `DynamicEventsList` was the one call site reaching for `locale` instead. `sortEvents` and `calculateOrder` keep the `language` parameter they already had, so the pure module gains no knowledge of BCP-47 tag shapes. Both in-scope values are strings, so `sortEvents` cannot tell them apart and no pure spec can see which one a call passes. `DynamicEventsList.test.ts` therefore pins the argument against the source, as `responsive.test.ts` and `href.test.ts` pin their own call sites. It goes red both when the call passes `locale` again and when the call stops matching at all. Closes #223 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying sahajatlas-design with
|
| Latest commit: |
f1e356f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a24baa9f.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://claude-fix-223-regional-loca.sahajatlas-design.pages.dev |
Deploying sahajatlas with
|
| Latest commit: |
f1e356f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c6676af3.sahajatlas.pages.dev |
| Branch Preview URL: | https://claude-fix-223-regional-loca.sahajatlas.pages.dev |
|
🤖 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
One line of behaviour, and it is the right line. languageCode is the repo's base-subtag accessor, sortEvents is untouched, and the ticket's open question is moot: use-locale.ts:72 returns resolvedLanguage || 'en', so the split it asked for is the same value. The diff is no bigger than the problem. The one real question is the source-scraping spec.
Findings — three consider, each on its thread: the spec pins a token, the comment restates the diff, the CHANGELOG entry sits above Added.
Worth a ticket, not this PR. lib/distance.ts:12 is the same defect one step on: preferredLocale returns only offered locales, and neither en-US nor en-GB is offered, so MILE_LOCALES never matches — #52's miles branch is unreachable.
Checked. #223, the diff, and in full: the call site, sort.ts + spec, use-locale.ts, i18n-options.ts, distance.ts. On SahajCloud main: 19 LOCALES, pt-BR and en-AU the only regional ones; Events.ts:215 builds languages from ISO 639-1 codes. sortEvents has one caller.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`docs/rules/code-comments.md` keeps the why, not the narration. The three added lines restated the diff and the spec beside it. The one constraint a fresh reader cannot derive is that an event's language is an ISO 639-1 base code, so the tag has to be narrowed before it reaches `sortEvents`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The call-site spec read `.at(-1)` over a `[^)]*` match, so it asserted a token at a position rather than a fact. `sortEvents(events, order, locale, languageCode)` passed it, and an argument carrying a `)` broke the match. It now normalises whitespace and a trailing comma away and pins the call text with `toContain`, the idiom `href.test.ts` already uses: the wrapped form passes, the four-argument form fails. A source pin still cannot say what the two values MEAN, so `sort.test.ts` gains the case that can. Under `pt-BR` a `pt` event counts as foreign, the penalty lands on every event and cancels, and distance alone decides — what #223 shipped. The same set under `pt` ranks the local class first, so the pair shows the tag shape moving the ordering rather than the fixtures. Proven red before restoring: the call-site spec with `locale` passed again, with the call renamed, and with a fourth argument; the `sort.test.ts` case with the tag narrowed inside `calculateOrder` and with the penalty removed. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Every other group run in the file reaches Fixed after Added, and the header claims Keep a Changelog order. The new group sat above Added instead. A pure relocation — the entry's text is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
The session for this item did not finish after 3 attempts. I have stopped retrying. A comment, a verb, or a push from you starts me again. 🤖 sydevs dispatcher |
|
Three review threads, all answered. Head is 0d519c5, pushed. Adopted. The call-site comment is cut to your one line (9a722d1). The CHANGELOG group moved below Adopted in part, thread left open. The call-site spec: your Lean gate green — 125 files, 1619 tests. Each new assertion was proven red at the site that causes it before restoring. Body refreshed with the live branch preview. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
GitHub reported the PR conflicting. The one conflict was the CHANGELOG's link-reference list: #223 here and #234 on main both appended a definition after #220. Both entries exist in the file, so both definitions stay, in number order. No entry text on either side was touched. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Merged 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
pt-BRoren-AU,recommendedpromotes a class in the viewer's own language again.DynamicEventsListpassesuseLocale().languageCode— the base subtag — instead of the resolved locale.sortEventsandcalculateOrderare untouched. The defect was which of two in-scope values the call site picked.Changes
src/components/organisms/EventsList/DynamicEventsList.tsx— passeslanguageCode; the memo dep follows it.src/components/organisms/EventsList/DynamicEventsList.test.ts— new. Pins that argument against the source.src/lib/shape/sort.test.ts— one case: a regional tag matches no event, so distance decides alone.CHANGELOG.md— aFixedentry. See the judgement call below.Preview
No Ladle link: the ordering is driven by the resolved locale and the fetched set, neither of which a story exercises.
Test results
pnpm lint,pnpm typecheck,pnpm test:run— 125 files, 1619 tests.localepassed again, with the call renamed, and with a fourth argument appended; thesort.test.tscase with the tag narrowed insidecalculateOrder, and with the language penalty removed. The call-site pin was also proven to survive the call wrapped across lines with a trailing comma.Manual verification
pnpm dev, then?locale=pt-BR&sort=recommendedover a search returning Portuguese and non-Portuguese classes. The Portuguese ones now outrank equidistant foreign-language ones.?locale=en-AUover a mixed English/non-English search.?locale=ensearch is unchanged.Whether this is live right now depends on whether SahajCloud's
sy-atlas-config.availableLocalescurrently carriespt-BRoren-AU(#198).Notes for reviewer
The ticket named a different line, and refactor(list): move sortEvents into src/lib/shape/sort.ts #224 is why. It put the fix at
DynamicEventsList.tsx:83, narrowing i18next's singleton. refactor(list): move sortEvents into src/lib/shape/sort.ts #224 landed between filing and implementation and moved that read intouseLocale(), so the fix is the argument at the call site instead. The ticket anticipated this and said to passi18n.resolvedLanguage?.split('-')[0]rather thanlanguageCode, to avoid also closing the unresolved-language window. That window is already closed onmain:use-locale.ts:72readsi18n.resolvedLanguage || 'en', solanguageCodeand a hand-rolled split are now the same value. This PR still changes one behaviour.Judgement call 1 — the CHANGELOG entry. The ticket said none was needed, on the grounds that no attribute, origin or URL shape changes.
CHANGELOG.md's own header says it records "visible behaviour", and a visitor on two of the offered locales sees a different order, so I added one. Drop the entry if you read that charter more narrowly.Judgement call 2 — the call-site spec survives, repaired, and its thread is still open. Review asked for it to be dropped in favour of a
sort.test.tscase. That case is now in, and it is the better assertion: it pins a value rather than a token. It cannot replace the call-site pin, though, because only that pin reds when the call passeslocaleagain, and that regression is fix(list): recommended ignores language on a regional locale #223 itself. So both ship. The pin no longer asserts a token at a position: whitespace and a trailing comma are normalised away and the call text is matched withtoContain, ashref.test.tsdoes, sosortEvents(events, order, locale, languageCode)now fails where it used to pass. It does pin one spelling — an inlineuseLocale().languageCodewould red it, loudly and legibly. Delete the file if you would rather this fix ship with only the value contract, as the four siblinglanguageCodecall sites do.Worth a second look, not filed:
src/lib/distance.ts:12matches the whole resolved locale against{'en-us','en-gb'}— the mirror of this defect, sincepreferredLocalenarrows a requesteden-GBtoenwhere onlyenis offered.distance.test.ts:18-22pinsusesMiles('en') === falsedeliberately, so that is a product decision to re-open rather than a bug, and I left it alone. Review reached the same file independently and read it as feat(event): redesign event display & registration surfaces #52's miles branch being unreachable.Detail
Why the call site rather than
sortEvents. The first version of this branch narrowed insidesortEvents, because that is the only shape the node lane can pin directly. Three review lenses anddocs/rules/i18n-and-state.mdall pointed the other way:useLocale().languageCodeas the base-subtag accessor, under Language — "an event's spoken language in a filter" is the same comparisoncalculateOrdermakes.EventChips.tsx:43,Map.tsx:216anduse-turnstile.ts:155already takelanguageCode.DynamicEventsListwas the only one reaching forlocale.sort.ts:71states the module "stays free of React and i18n". Parsing a BCP-47 tag is i18n knowledge, and the first version had to reword that very comment to fit.sortEventsto "pass me either kind, I'll cope" hides which kind a caller holds — the shape the bug arrived in.The two specs together buy back the coverage that move costs:
sort.test.tssays what the parameter means, the call-site pin says which value reaches it.Fixture pre-mortem. The claim the fix rests on is that an event's
languages[0]is always an ISO 639-1 two-letter code, and that exactly two offered locales are regional. Verified against SahajCloudmain:src/collections/Events/Events.ts:215builds thelanguagesselect fromgetLanguageOptions(), which isISO6391.getAllCodes()(src/lib/locales/languageOptions.ts:18);src/lib/locales/index.ts:13-32lists nineteenLOCALES, of whichpt-BRanden-AUare the only regional tags.Not narrowing the event's side would be dead code for the same reason.
Security review: skipped — no changed path matches
securityReview.triggerPattern, and no added line undersrc/matches its content pattern.Docs sync: checked, nothing stale.
docs/rules/i18n-and-state.mdalready namesuseLocale().languageCodeas the base-subtag accessor for an event's spoken language, which is what this fix now honours.Dismissed review findings: hoisting a
constabove aswitchand trimming two test cases both applied to the first version of the branch and no longer exist in the diff. The comment and CHANGELOG findings from the latest review were adopted; the request to delete the call-site spec was not, for the reason in judgement call 2, and that thread is left open.Closes #223
🤖 Written by the sydevs autonomous loop — see what this is