Repository navigation
fix(map): let a geocoder mount ask Mapbox for a storable answer - #407
Conversation
SahajCloud stores the Mapbox feature ids a client sends with a proposal, and its client contract now requires those ids to come from a `permanent=true` Geocoding v6 lookup (sydevs/SahajCloud#893). Mapbox's terms allow keeping an id only from such a lookup, and bills it separately — so permanence belongs to the caller, not to the control: one component serves both plain map browsing and the submit flow, and only the second may store what it gets back. `permanent` is therefore a `MapSearchProps` prop, absent by default, spread into the `<Geocoder options>` block the same way `country` is — left out rather than passed as `undefined`, since the geocoder serializes whatever it is handed. `options` is `Partial<GeocodingOptions>`, which declares `permanent`, so no cast is involved and a renamed option fails to compile. `reverseGeocode` stays temporary: its answer fills the search field and `?cc`, never a row SahajCloud keeps. Refs #404 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWJYfynaSBQf48tfqn
…catch Three review passes found the same thing: "permanent means storable, and bills separately" was stated four times over three files. The prop docblock keeps it; the rest shrink to the clause a reader cannot re-derive. A conditionally spread option also turns out not to be checked for its name. TypeScript applies the excess-property check to a literal's own keys, never to one spread into it, so a misspelled `permanent` compiles clean — and `satisfies Partial<GeocodingOptions>` on the literal does not close it either, measured both ways. A plainly written key does fail (TS2561). So the spec, not the type, is what holds this option, and the comment says so where someone would otherwise trust the compiler. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWJYfynaSBQf48tfqn
Two docblocks inside `MapSearch` and `reverseGeocode` are only read by someone who opens those two files. `docs/rules/mapbox.md` loads for anyone editing the Mapbox directory, which is where a second geocoder mount gets added. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWJYfynaSBQf48tfqn
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The functional change is two lines, and that is the right size. Decision 1A made permanence a prop, and #404's Notes route the mounts to #318, so a prop with no mount here is not an unused knob.
One gap outranks the code. Closes #404 closes a ticket meeting 3 of its 5 criteria, and criterion 1 is the storage-terms breach the ticket exists to fix. Nothing open records the remainder — neither #147 nor #318 mentions permanent. Merge this and #318's PlaceField ships without the prop, with nothing left saying it should not.
The other 90 added lines are prose about one option, in five places.
Findings
- should-fix —
Closes #404should readPart of #404. It sits in the body, so no thread. - should-fix —
MapSearch.tsx:182claims more coverage than the spec holds. - consider —
docs/rules/mapbox.md:372-382restates the call-site comment.
What was checked
Read whole on the branch: MapSearch.tsx, SearchField (views/shared.tsx:258), geocode.ts, the new spec, the mapbox.md section and its paths:.
Verified against installed @mapbox/[email protected], not the body: permanent?: boolean at GeocodingCore.d.ts:86, options?: Partial<GeocodingOptions> at Geocoder.d.ts:43, and the query serializer pushes every non-null value. So permanent: false would reach the request, and the conditional spread is right.
Ladder on the one new file: 20 sibling specs render with renderToStaticMarkup, and nothing on main mocks search-js-react, so no harness was duplicated. The SearchField case is non-vacuous — Pick<MapSearchProps, 'label'> binds callers, never the body.
docs/embedding.md needs nothing — no origin or CSP changes.
Searched open items naming permanent: #404, #407, #258 alone. No preview link was posted, and this repo seeds none.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`country` is spread the same way `permanent` is, so the excess-property check misses its name too — but only `permanent` had a case, while the call-site comment and `docs/rules/mapbox.md` both claimed the spec held whatever is spread there. The new case pins both directions through the route, since `country` comes from the pathname. Watched red twice: with the spread removed, and with the key written `countryy`, which `pnpm typecheck` accepts. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYQRgweYgmyXPxYWBF
The two ⚠ paragraphs restated `MapSearch.tsx`'s own comment, and this file's `paths:` loads it beside that file — so both reached one reader at one moment. What a future mount needs is the policy: spread an optional option, and give it a case. The `permanentt` demonstration and the TS2561 citation justified the call-site comment, which stands without them. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYQRgweYgmyXPxYWBF
|
Addressed the adversarial review. Base was already current, so nothing was merged. Adopted.
Lean gate: ✓ lint, typecheck, 169 files / 2070 tests. PR body refreshed: 4 spec cases, and why the ticket stays open. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
main now threads `permanent` through `MapSearch` (#407), and SahajCloud's client contract requires the Mapbox ids a proposal sends to come from a permanent lookup (sydevs/SahajCloud#893). `PlaceField` is the flow's only geocoder, behind both the address and the online city, so the option goes on its one mount, as #404 decision 1A set out. The header field stays temporary; `MapSearch.permanent.test.tsx` holds that half. Watched the new case fail with the prop removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
MapSearchtakes apermanentprop, so a geocoder mount whose answer is submitted to SahajCloud can ask Mapbox for a result its terms allow storing (fix(mapbox): move every stored geocode to Geocoding v6 permanent SahajCloud#893).reverseGeocodestay temporary, and nothing visible changes today.docs/rules/mapbox.mdgains the rule, so a future second geocoder mount reads it without openingMapSearch.country, spread the same way, gains the spec case it never had.Change outline
The prop is the whole change. Permanence belongs to the caller because one component serves both plain map browsing and the submit flow, and only the second may keep what it gets back.
Preview
Preview pending — the CI smoke job publishes the
pr-<n>Workers alias, and the Cloudflare branch alias appears on this PR once it deploys.This change is not visible on a preview, and that is not a gap. The one mount a preview can reach is the header search field, whose request is byte-identical to
main— worth confirming it still carries nopermanent, but it is the unchanged direction. The mount that does ask for permanence lives on #318's branch (see Notes), so nothing on this branch issues a permanent lookup for a preview to show. No wait for the deploy was taken for that reason.Test results
expected undefined to be truepermanent: permanent ?? true→ both absence cases redSearchFieldgivenpermanent→ the header case redcountryspread removed, and the key writtencountryy→ the country case red both ways, whilepnpm typecheckstays greenpnpm size: left to CI (no bundle-shape change — one branch and a ≤1-key object copy)Manual verification
api.mapbox.com/search/geocode/v6/forwardrequest carries nopermanentparameter.reverserequest carries nopermanenteither.Notes for reviewer
permanentonPlaceField(ProposalForm/WhereStep.tsx), which exists only on feat(widget): submit or correct a class, and opt into a mailing list #318's branch — a session may not push to a PR it does not hold, and a PR is never based on another PR's branch. fix(map): ask Mapbox for a permanent answer where the id is stored #404 § Notes routes exactly this case: "whichever of the two lands first adds the prop and the other consumes it", and "if this is decided first, feat(widget): submit or correct a class, and opt into a mailing list #147 can carry it". So acceptance criterion 1 and the first half of criterion 4 are feat(widget): submit or correct a class, and opt into a mailing list #318's to meet, and until they are, no lookup in this repo asks for permanence. Criteria 2, 3 and 5 are met here; criterion 1 holds vacuously onmain, which the ticket states ("the widget sends no ids yet"). The open ticket is the record of that remainder — which is why this isPart of #404and notCloses....(permanent ? { permanentt } : {})compiles clean.satisfies Partial<GeocodingOptions>on the literal does not close it — measured both ways; a plainly written key does fail (TS2561). So the new spec, not the type, is what holds these options.countrybeside it has the same property and now has its own case, measured the same way; feat(widget): submit or correct a class, and opt into a mailing list #318'stypes/proximitywill need theirs. Named rather than closed: an inventory spec over<MapSearchmounts would cost more than it catches at two mounts. The comment anddocs/rules/mapbox.mdsay so where someone would otherwise trust the compiler.docs/embedding.mdandCHANGELOG.mdare untouched on purpose: no new origin, no CSP change, no host-observable behaviour.CHANGELOG.md's own header excludes internal work.Detail
Review passes.
/simplify(4 angles) and/code-review high;pr-review-toolkitis not installed here./security-reviewskipped — the diff matches neithersecurityReview.triggerPatternnorcontentPattern.comment-lint.mjs: no banned comment added.Applied. Three of four
/simplifyangles independently found the same thing: "permanent means storable, and bills separately" was stated four times across three files. The prop docblock keeps it; the spec preamble, the spec's inline note and thereverseGeocodeparagraph shrank to the clause a reader cannot re-derive (0cb8993). Thedocs/rules/mapbox.mdsection was the altitude angle's own finding before it found it already written (4025c80). The adversarial review then took the same line one step further: the section's two ⚠ paragraphs restated the call-site comment, and one keeps the policy (54a4246).Dismissed, with reasons.
/code-review: addsatisfies Partial<GeocodingOptions>to the options literal to restore the excess-property check. Verified not to work — withsatisfies, the misspelled key inside the conditional spread still compiles; without it, likewise. The finding's diagnosis is right and its fix is not, so the hole is documented instead (see Notes)./simplify×3: drop theSearchFieldcase; the type already forbidsSearchFieldpassingpermanent. It does not —Pick<MapSearchProps, 'label'>constrains what callers handSearchField, not whatSearchFieldhandsMapSearch. Reintroducing that defect turned the case red, and it is acceptance criterion 4's second half. Its measured cost is +1.1s on this spec andsrc/config/i18n.ts's per-edit selection 13 → 14 specs (5.88s → 6.65s against a 12s budget). The pinned widest selection (src/test-support/repo-source.ts) stays 21/21 — the spec names neither walker./simplify: replaceoptionsOf's hoisted array withvi.fn()+toHaveBeenCalledOnce(). A wash on lines, andmock.calls[0][0]needs its own annotation. Declined.geocoderOptions({ locale, scope, permanent, … })builder besidesearchBias. It would move the mount → options coupling out of the component, so the spec could no longer assert what the mount sends, which is what criterion 4 asks for. Declined; the angle offered it as decline-able.Verified against the installed source, not inferred.
@mapbox/[email protected]'s geocode query builder listspermanent: e.permanentamong the forward and reverse parameters, and its serializer skips onlynull/undefined— sopermanent: falsewould reach the request as a parameter, which is why both it andcountryare spread conditionally.permanent?: booleanis atGeocodingCore.d.ts:86andoptions?: Partial<GeocodingOptions>atGeocoder.d.ts:43, so no cast is involved.Fixture pre-mortem. The spec's one assumption is that
<Geocoder>'soptionsprop is the only placepermanentis observable from a mount. Checked againstnode_modules/@mapbox/search-js-react/dist/components/Geocoder.d.ts(options?: Partial<GeocodingOptions>) and the core query builder above. The mock stubsGeocoderalone; every othervi.mockin the file exists to keep the node lane offmapbox-gl,react-map-gland i18next's boot, and each has precedent in a sibling spec.Non-vacuity.
optionsOfthrows unless exactly one geocoder mounted, so neithernot.toHavePropertyassertion can pass for want of a render — the trapdocs/testing.mdrecords for absence assertions. The country case reachessearchCountryScopethrough the harness's ownMemoryRouter, by the route it is given, so both of its directions come from the component rather than the fixture.Part of #404
Generated by Claude Code