Repository navigation
feat(preview): let the atlas resolve a proposal's relationships without reading user-submissions - #816
Conversation
The atlas widget holds create-only on `user-submissions` (#723), so it can never read a merged event's relationships back for itself. `previewEvent` is the only transport, and it was handing over two things the widget could not use. **Photographs.** `images` came through as row ids, so SahajAtlasWeb#212 had to re-resolve them by hand from the posted message. They are resolved here instead, after the merge. Not by raising `loadTargetEvent`'s depth: `computeProposedChanges` shares that load through the request memo, and a populated relationship renders there by name rather than by row id, which would change the reviewer's diff. The diff is untouched, and a spec pins `region` as a bare id so it stays that way. An id that no longer resolves is dropped — the widget parses each entry against a schema, so one bare number would cost the preview every photograph rather than the missing one. **Region.** `newEventDefaults` sets none, while Accept writes `region ?? regionHint.anchorRegion`. So a new-event proposal previewed without the region screening had resolved, and then Accept wrote one — the preview disagreeing with the write, which is the failure `mergeProposal` exists to prevent. The new-event branch now carries it, by the same fallback order. A new-event proposal can never show photographs at all: `images` is in `PRIVILEGED_FIELDS`, so only a target event supplies them. The docblock now states all three facts, since they are what a consumer may rely on. All three assertions were verified red with the defects reintroduced. Closes #814 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013gcsNaBDXJ2RhJeFhhDvaS
Four review lenses over the branch diff. Both findings were the same shape — a rule written twice, kept in step by a comment. `resolveImages` was a line-for-line copy of the atlas SEO endpoint's `readImages`, down to the `byId` map that restores the editor's order. Both now call `readEventImages` (`src/lib/utilities/eventImages.ts`), which also carries `IMAGE_SELECT`. That select is the part worth sharing: `url` is virtual and reads `filename`, so a select naming `url` alone yields `null` and the photo silently disappears. The preview had no select at all and hydrated every column for two fields. `access` is spelled out at each call site, because the callers need opposite things — the endpoint reads as its client on the caller's request, the projection reads committed state on its own connection. The region fallback was a verbatim second copy of `applyReview`'s, promising by comment to stay in step with it. `submissionRegionId` is now the one statement, in `mergeProposal.ts` beside `newEventDefaults` — deliberately outside the merge itself, since in the merge it would add a Region line to every new-event diff and `proposedChanges` is meant to read exactly as it did. Also from the pass: the preview's image load joins the per-request memo, which every other load in that file already uses and `applyReview` needs — it reads the row and then updates it on one request, running the hook twice. `previewEvent.images` is asserted absent rather than `?? []`, which passed for three different values. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013gcsNaBDXJ2RhJeFhhDvaS
`src/AGENTS.md` enumerates every helper in `src/lib/utilities/`, and the list decides where the next reader looks for one. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013gcsNaBDXJ2RhJeFhhDvaS
|
🚅 Deployed to the SahajCloud-pr-816 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the size of its ticket and no larger. Option 1 is the right call. readEventImages earns its new file: two callers, and the ordering rule now has one home instead of two. The consumer already accepts the shape — SahajAtlasWeb#212 parses images as z.union([z.number(), EventImageSchema]) and passes a non-number entry through, so populated docs land there today and previewImageIds returns nothing.
Findings
should-fix—eventImages.ts:39types a four-field projection as the fullImage.consider— the region rule now has two of three consumers;proposedChangesstays silent.
What was checked
Read whole: computeReviewFields.ts, mergeProposal.ts, review.ts, eventImages.ts, requestMemo.ts, the SEO call site, submission.ts plus types/event.ts on SahajAtlasWeb#212. applyReview still spreads region: regionId after the patch, so the new-event preview mirrors the write order. The select and the order restore moved verbatim.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`readEventImages` selects four fields and promised a whole `Image`, so `image.createdAt` typechecked and was `undefined` at runtime. `EventImage` names what `IMAGE_SELECT` actually returns, the way `eventCard` types its own projection as a `Pick<Event, …>`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XVt38gWWy5xKZYsp1k5Sac
The banner says one merge serves three consumers. The region is the one field two of them name and the diff does not, and the exception was stated only at `submissionRegionId`, where a reader arrives after the claim. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XVt38gWWy5xKZYsp1k5Sac
|
Addressed the adversarial review. Pushed
Lean gate green, plus 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
previewEvent.imagesnow carries image documents (url,alt) in the editor's order, so the atlas widget no longer re-resolves them by hand.user-submissionsschema #723.Changes
src/lib/utilities/eventImages.ts— new.readEventImagesplusIMAGE_SELECT, lifted out of the atlas SEO endpoint, which now calls it too.EventImagetypes the four-field projection, so no caller can read a field the select never asked for.src/collections/UserSubmissions/lifecycle/mergeProposal.ts—submissionRegionId, the one statement ofregion ?? regionHint.anchorRegion.applyReviewnow calls it.src/collections/UserSubmissions/hooks/computeReviewFields.ts— the preview resolves images after the merge, and states its contract in the docblock.Preview
Contract impact
previewEventis the atlas widget's only view of a merged proposal — it holds create-only onuser-submissions(#723). SahajAtlasWeb#212 can now deletegetImages/imagesQueryand theresolveImageshalf ofsrc/lib/live-preview/submission.ts.resolveRegionstays: it reads the region tree the widget already holds, and costs no network read. No SahajCloud type or endpoint shape changed, so notypes:cmsresync is needed.Test results
tsc --noEmit(src + tests), 2133 unit testsuser-submissions-review-lifecycle21 passed,user-submissions-access8 passed,atlas-seo53 passed (it shares the lifted reader)Manual verification
Notes for reviewer
proposedChangesis deliberately untouched.submissionRegionIdsits outsidenewEventDefaultsfor that reason — inside the merge it would add a Region line to every new-event diff. So two of the three consumers of the merge now name the region and the diff still does not, and the merge banner records that exception. The adversarial-review pass argued for the deeper version (region innewEventDefaults,applyReviewdropping its post-patch override); it needs aresolveRegionload to avoid printingRegion: 12, and it trips the ticket's "reads the same for a reviewer" criterion. Worth a follow-up ticket if you want it.readEventImagestakesaccessexplicitly at both call sites: the endpoint reads as its client on the caller's request, the field hook reads committed state on its own connection (a projection that joins the caller's transaction aborts the write it decorates — Event submissions: judge a proposal, don't edit a copy #641).Detail
Why images resolve after the merge.
loadTargetEventis shared withcomputeProposedChangesthrough the request memo, so raising itsdepthwould make the diff render relationships by name instead of by row id. The preview resolves its own ids instead, and a spec pinspreviewEvent.regionas a bare number so that stays true.A missing id drops out. The widget parses each entry against
EventImageSchema, and the array has.default([])— one bare number would fail the whole array, costing the preview every photograph rather than the missing one.Open question answered. A populated image satisfies
EventImageSchemawith no further shaping:urlis virtual and derived fromfilename, soIMAGE_SELECTco-selectsfilename. Without that co-select the preview would shipurl: nulland the photos would vanish silently. The spec asserts a non-nullurlon every entry.The ordering assertion is correct but was not watched fail. Removing the order restore in
readEventImagesleft the spec green — Postgres answeredid in (…)in the listed order for that fixture. The ordering contract is pinned bidirectionally intests/int/atlas-seo.int.spec.tsinstead, and the new spec lists the highest id first so a regression would still show. The comment says exactly this rather than claiming a guard it does not have.Fixture pre-mortem. The spec assumes
imageson Events is an orderedhasManyupload to theimagescollection, and that an image created bytestData.createImagehas afilename. Verified againstsrc/collections/Events/Events.ts:314-321,src/collections/Images/Images.ts:66(thevirtualUrlField), andtests/utils/testData.ts:210-229.Security review: skipped. No changed path matches
securityReview.triggerPattern. The one access-carrying line — the SEO endpoint'soverrideAccess: falseplusreq— is preserved verbatim, andatlas-seo.int.spec.tscovers it.Not fixed here.
docs/rules/endpoints.md:156states the co-select rule thatIMAGE_SELECTexists for; nothing there went stale.Closes #814
🤖 Generated with Claude Code
https://claude.ai/code/session_013gcsNaBDXJ2RhJeFhhDvaS