Skip to content

feat(routing): resolve Unicode place slugs from encoded and raw URLs - #483

Merged
Ardnived merged 10 commits into
mainfrom
feat/unicode-slugs
Nov 25, 2026
Merged

Ardnived merged 10 commits into
mainfrom
feat/unicode-slugs

Conversation

@Ardnived

@Ardnived Ardnived commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Change outline

Behaviour — reading a URL into a place

 src/lib/shape/path.ts
   safeDecode(pathname | segment)      → exported; decodes each segment, + NFC.
                                         One decoding to / \ ? # % or a control char stays encoded,
                                         so `/a%2Fb` is one segment to every caller.
   resolveStack                        → RESERVED_SLUGS / search / calendar AND the event-id test
                                         all read the decoded segment
   resolvePath                         → same terminal rule, on the decoded segment
   isCanonicalPath(a, b)               → compares both sides decoded
   placePathsOf                        → Map keyed by decoded NFC slug; the lookup does not decode again
 src/lib/shape/hierarchy.ts
   indexRegions                        → bySlug answers to both spellings of a slug
 src/lib/shape/routing.ts
   routeFromPathname(pathname, mount)  → decodes both through safeDecode, returns the raw Unicode route
   routeFromParam(?atlas=)             → + NFC
 src/hooks/use-recovery-offer.ts       → home-path check uses isCanonicalPath, not !==

One decoder, in path.ts. routing.ts held a second one until the review.

Writing a URL (hrefFor / pathHrefFor) already percent-encodes, which is what the contract expects.

Preview

No preview surface: the fixture regions are ASCII, so the new paths are only exercised by the unit tests.

Contract impact

  • src/lib/shape/atlas-url-contract.json is now version 2: a Unicode slugPattern, compiled with u, and two percent-encoded cases.
  • docs/embedding.md ("The URL") and CHANGELOG.md now say that a place slug may be non-ASCII and arrive percent-encoded.
  • SahajAtlasWordpress#98 carries the WordPress half. WeMeditateWeb needs no PR: canonicalAtlasRoute on its main already decodes per segment and normalises.

Test results

  • Lean gate (check.sh): ✓ — lint, typecheck, 2464 unit tests, on the review commits.
  • src/lib/shape/unicode-slugs.test.ts: 47 cases (Cyrillic, Latin with diacritics, Armenian), raw and encoded, plus NFD input and %2F/%5C staying encoded. Seven are the review's: the double decode, the encoded event id in both resolvers, the widened structural guard, a malformed escape, and the index answering to both spellings of a slug. Each was watched failing against its own defect.

Notes for reviewer

  • indexRegions now keys bySlug by both spellings, so a hand-typed NFD CMS slug resolves from a URL and from the ancestry climb alike. The cross-repo half is open: SahajCloud's parseAtlasRoute decodes without composing, so an NFD address resolves here and 404s there. Tracked as fix(slugs): parseAtlasRoute decodes a route without composing to NFC SahajCloud#1274, which is not a blocker for this PR.
  • Old ASCII place links (/bg/sofiya) stop resolving once SahajCloud renames its regions. The owner accepted this.
  • A segment that percent-encodes a separator stays an opaque slug rather than refusing the route, so /map/%2F%2Fevil.example resolves to /%2F%2Fevil.example where main returned undefined after chore(contracts): re-sync copied contracts from SahajCloud #484. safeDecode's guard is what keeps a separator out of the decoded route, and routing.test.ts:381 pins it. Settled on the review thread.

🤖 Generated with Claude Code

Slugs keep native letters now (SahajCloud#1269). Browsers hand the widget
percent-encoded pathnames while webPath is raw Unicode, so every slug
comparison decodes each segment and composes to NFC.

- safeDecode: NFC, exported; isCanonicalPath and placePathsOf decode both sides
- resolveStack: reserved words matched on the decoded segment
- routeFromPathname: decodes pathname and prefix per segment (structural
  escapes such as %2F stay encoded) and returns the raw route
- routeFromParam: NFC-normalises the route
- useRecoveryOffer: home-path check uses isCanonicalPath
- sync atlas-url-contract.json to version 2 (slugPattern needs the u flag)
- docs/embedding.md and CHANGELOG.md: slugs may be non-ASCII, arrive encoded

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sydevs-dispatcher

sydevs-dispatcher Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running
CI fix 3

recent dispatches
  • 20:40Z address-review · attempt 1 · session · done
  • 20:40Z address-review · attempt 1 · session
  • 20:29Z resolve-conflicts · attempt 1 · session · done
  • 20:29Z resolve-conflicts · attempt 1 · session
  • 20:22Z fix-ci · attempt 1 · session · done

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

@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 25, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

Not fixable from this repo: the contract copy is ahead of its source.

src/lib/shape/atlas-url-contract.json is version 2 here. SahajCloud main still serves version 1, so Contract check fails by design. Its source, sydevs/SahajCloud#1269, is still open.

Reverting the copy to version 1 would undo this PR and break atlas-url-contract.test.ts and unicode-slugs.test.ts. Both PR bodies set the merge order: #1269 first, then this one. So nothing was pushed.

The rest of the gate is green at 16d6271, run locally: lint, typecheck, and 2456 unit tests pass. CI never reached them — Contract check runs before pnpm lint and aborts the job.

This turns green once #1269 merges and CI runs again.

🤖 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 Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 25, 2026
@Ardnived
Ardnived enabled auto-merge November 25, 2026 18:51
CHANGELOG.md's Changed list conflicted: both sides added a new top entry.
Kept both, newest first — this branch's Unicode slug note, then #482's map
control column. docs/embedding.md took both sides without a conflict.

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

Copy link
Copy Markdown
Contributor

Merged main in. One conflict: CHANGELOG.md's Changed list, where both sides added a new top entry. Kept both, newest first — this branch's Unicode slug note, then #482's map control column. Neither entry describes the other's change, so there was nothing to reconcile.

docs/embedding.md took both sides with no conflict: #482's geolocation and map-control rows, and this branch's percent-encoded slug note.

Lean gate green on the merge commit: lint, typecheck, 2458 unit tests.

Contract check still fails for the reason in my earlier comment — the contract copy here is version 2 and SahajCloud main serves version 1. That clears when sydevs/SahajCloud#1269 merges, not here.

🤖 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 Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 25, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

Nothing to fix here. The blocker is still the one in my earlier comment: Contract check refuses a contract copy ahead of its source, and SahajCloud main still serves version 1. sydevs/SahajCloud#1269 is open.

New fact for whoever merges the pair: Contract check is the gate job's first step, so CI has never run the rest of it on this head. I ran it locally on 6bb9f2c — lint, typecheck, 2458 unit tests, pnpm build, and pnpm size (standalone 325.9 KiB of 336, loader 3.3 of 3.6, embed 326.9 of 336). All green.

So merge #1269, and this gate should pass on its next run. Pushed nothing.

🤖 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 Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 25, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
sahajatlas-design f4c80d7 Nov 25 2026, 08:39 PM

@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 25, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The diff is the size of the problem. One decoder, NFC at the read boundaries, and the contract bump that forced it — nothing smuggled, and the use-recovery-offer.ts line falls out of isCanonicalPath changing. It leaves behind a second pathname decoder, a second decode pass, and two /^\d+$/ tests reading the raw segment while all around them reads the decoded one.

The contract holds from all three sides. Byte-identical to SahajCloud#1269's copy and to SahajAtlasWordpress#98's, which compiles slugPattern with /u.

One body claim does not. Only #98 exists — WeMeditateWeb has no such PR, and needs none: canonicalAtlasRoute on its main already decodes per segment and normalises (lib/atlas/route.ts:107).

Findings

  • should-fix path.ts:334 — a reachable second decode: /bg/%25D1%2581… resolves to софия.
  • should-fix routing.ts:331 — Streamline: two pathname decoders; fold this one into safeDecode.
  • should-fix path.ts:316 — the event-id test reads the raw segment, diverging from both ports.
  • consider path.ts:24 — NFC stops here; hierarchy.ts and SahajCloud's parser do not normalise.
  • consider path.ts:302 — Streamline: one fact stated four times.

What was checked

Read whole: path.ts, routing.ts, hierarchy.ts, use-recovery-offer.ts, three specs. Consumers followed: WeMeditateWeb lib/atlas/route.ts, SahajCloud atlasRoute.ts and tests/contract.php in #98. Ladder walked for 2 new pieces; streamliner covered 2, kept 1; no new dependency. Reproduced the double decode from the branch's own safeDecode/placePathsOf. No previewUrl or fixture in .claude/workflow.json on main, and demo slugs are ASCII (src/mocks/sahajcloud-demo.ts:368), so "No preview surface" stands. A whole-file pass on path.ts found nothing else to fold.

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


Generated by Claude Code

Comment thread src/lib/shape/path.ts Resolved
Comment thread src/lib/shape/routing.ts Resolved
Comment thread src/lib/shape/path.ts Resolved
Comment thread src/lib/shape/path.ts Resolved
Comment thread src/lib/shape/path.ts Resolved
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 25, 2026
`placePathsOf` decoded both the Map key and the lookup, so a slug spelling
the literal percent-escapes of another resolved to that other place:
`/bg/%25D1%2581%25D0%25BE%25D1%2584%25D0%25B8%25D1%258F` decoded once to
`%D1%81%D0%BE%D1%84%D0%B8%D1%8F` and again to `софия`.

Every caller reaches it through `placedPathname`, which takes the slug off a
`StackEntry` — already decoded by `resolveStack`. So only the key side needs
the decode, for the raw CMS slug it is built from.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZ1ZYcZ63TU2JMw2Ug
The malformed-escape branch skips the structural test the success branch runs,
which is safe only because NFC cannot compose one of those characters. Nothing
said so, and widening the class would make the omission load-bearing.

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

Copy link
Copy Markdown
Contributor

Five threads adopted. Body refreshed.

6dfad5f and de7f20e are mine: an NFC-only key broke ancestorSlugs' re-lookup.

Seven new cases, each watched failing. Gate and security clean.

🤖 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 Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 25, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

Not this PR's failure, and the fix is already green in #484.

pnpm typecheck fails on one line:

src/types/translations.ts(68,28): error TS2344: Type '"compact"' is not assignable to type 'keyof SyAtlasTranslation'

sydevs/SahajCloud#1268 merged at 19:34Z and dropped the compact translations tab. Contract check runs pnpm types:cms before pnpm lint, so every branch now typechecks against CMS types with no compact group while WIDGET_TRANSLATION_TABS still lists one.

This head's committed tree is clean — pnpm typecheck passes on de7f20e until types:cms runs. origin/main at 7e8fe27 fails identically, so main and every open PR are blocked, not just this one.

#484 already removes compact from WIDGET_TRANSLATION_TABS, TRANSLATION_SELECT and sync-translations.mjs, carries the re-synced types, and is green and mergeable.

Merge #484, then merge main into this branch. Pushing the same removal here would duplicate #484 on a PR that already overlaps it in path.ts, routing.ts and atlas-url-contract.json. Pushed nothing.

🤖 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 Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 25, 2026
`main` solved the same decode through #484: a private segment decoder plus an
exported `decodePath` wrapper. This branch's `safeDecode` already decodes a whole
pathname segment by segment, so `decodePath` merged in as the same function twice
over, and the branch's review had removed a second decoder once already. The
survivor is `safeDecode`, carrying `decodePath`'s ordering warning, and
`routeFromPathname` decodes once at the top, where it also reaches the mount
prefix. `isCanonicalPath` keeps this branch's two-sided decode, which satisfies
main's new segment-wise assertion as well.

One assertion could not hold both ways. `safeDecode` refuses to decode a segment
whose decoded form would carry `/`, `\`, `?`, `#`, `%` or a control character, so
`//evil.example` can never be composed out of one slug and `safePath` is never
handed a structural character — where main expected `routeFromPathname` to refuse
the route outright. Both readings are safe and this one is the branch's, already
pinned from the other side by `unicode-slugs.test.ts` ("encoded structure is never
decoded"). The case stays, asserting what the merged decoder does; a review thread
carries the choice.

The contract fixture's docstring takes main's numeral-free refusal paragraph next
to this branch's percent-encoding paragraph, so a contract bump no longer edits
prose the assertions already pin.

Lean gate: lint, typecheck, 2469 unit tests, green.

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

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 question for the reviewer, one per thread.

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


Generated by Claude Code

Comment thread src/lib/shape/path.ts Resolved
@sydevs-bot

Copy link
Copy Markdown
Contributor

Merged origin/main (8c54e7e). Three files conflicted, all of it #484 having solved the same decode on main.

  • path.ts — main's decodePath arrived as safeDecode applied per segment, which is what safeDecode already is here, so one decoder survives and carries decodePath's ordering ⚠. isCanonicalPath keeps this branch's two-sided decode, and main's new segment-wise assertion passes on it.
  • routing.ts — decodes once at the top of routeFromPathname, where it also reaches the mount prefix, instead of a second time on rest.
  • atlas-url-contract.test.ts — the docstring takes main's numeral-free refusal paragraph beside this branch's percent-encoding one, so a contract bump no longer edits prose the assertions pin.

One assertion could not hold both ways. The thread on path.ts carries the choice.

Lean gate: lint, typecheck, 2469 unit tests, green.

🤖 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 Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 25, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

Your answer settles the last open thread. Option A was the built one, so nothing was pushed.

  • path.ts:40 — A stands. An encoded separator stays encoded, so routeFromPathname('/map/%2F%2Fevil.example', '/map') is /%2F%2Fevil.example, not a refusal. Resolved.

No code changed this run, so CI on f4c80d7 is the verdict. The branch is level with origin/main (8c54e7e), so there was no merge to make.

Body: one line under Notes for reviewer, recording that #484's refusal assertion was inverted by your answer. Nothing else in it was made false.

🤖 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 Nov 25, 2026

@sydevs-dispatcher sydevs-dispatcher Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for Ardnived, who wrote it: GitHub refuses an author's own approval. CI is green and the automated review has run. 🤖 Written by the sydevs autonomous loop — see what this is

@Ardnived
Ardnived added this pull request to the merge queue Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 25, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Pending to Awaiting in SYDevelopers Technical Roadmap Nov 25, 2026
Merged via the queue into main with commit 2b8e2a7 Nov 25, 2026
57 of 58 checks passed
@Ardnived
Ardnived deleted the feat/unicode-slugs branch November 25, 2026 20:50
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Awaiting to Done in SYDevelopers Technical Roadmap Nov 25, 2026
sydevs-bot pushed a commit that referenced this pull request Nov 25, 2026
Two conflicts, both in the host-facing docs, and both only because #483
re-padded every Markdown table in `docs/embedding.md` while this branch was
rewriting rows inside two of them.

`docs/embedding.md` — the Parameters and Troubleshooting tables take this
branch's rows. Normalising whitespace shows `main` changed nothing in either
table but the separator width, so there was no second behaviour to keep. #483's
own addition, the percent-encoded-slug bullet under indexing, merged on its own
and stands.

`CHANGELOG.md` — both entries stay, #483's first, where `main` has it.

Also here: #483's entry carried no `([#483])` reference or link definition,
which this file's preamble asks of every entry.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVmTA19YX1sUErABdU
Ardnived added a commit that referenced this pull request Nov 26, 2026
… a Unicode slug

#483's `indexRegions(...).bySlug` answers to a slug's raw and NFC spellings, and a slug decoded off the URL is NFC. The heading's own Map keyed the raw one, so a slug typed by hand in NFD named nothing. SahajCloud generates NFC slugs, so no live place was affected.

Watched failing first: the new encoded and raw München cases, against the hand-rolled Map.

Co-Authored-By: Claude Opus 5.5 <[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.

3 participants