Open binary file URL as a card without 415#4832
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts realm card read handling so GET requests for non-JSON files made with card-oriented Accept headers can fall through to the normal file-serving path instead of returning 415.
Changes:
- Routes missing card JSON index entries for existing non-JSON files through
fallbackHandle. - Applies the same fallback behavior to card markdown reads.
- Leaves write/delete card handlers unchanged for binary files.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Preview deploymentsHost Test Results 1 files ±0 1 suites ±0 1h 49m 54s ⏱️ - 3m 1s Results for commit 6855110. ± Comparison against earlier commit ee6d0b3. Realm Server Test Results 1 files ±0 1 suites ±0 8m 28s ⏱️ +57s Results for commit 6855110. ± Comparison against earlier commit ee6d0b3. |
a54b7f5 to
5668884
Compare
3a5e473 to
3d547b6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d547b67bc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
3d547b6 to
9d74e2e
Compare
…handler A GET request with Accept: application/vnd.card+json (or .card+markdown) targeting a path that holds a non-JSON file (typically an uploaded binary like .png) used to return 415 Unsupported Media Type. Callers that produced this mismatch ended up with a broken image / unusable response. Route these through fallbackHandle, which serves the file with inferContentType(...) on the response. Read-only handlers only: PATCH (3910) and DELETE (4507) still 415 because writing or deleting a binary as a card is genuinely wrong. CS-11147 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The existing regression test asserted GET /greeting.txt with Accept: application/vnd.card+json returned 415. After the fallback change, GET should serve the file with its native content-type instead. Splits the test in two: GET is the new positive case; PATCH/DELETE still 415. CS-11147 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
9d74e2e to
ee6d0b3
Compare
A caller that asks store.getCardInstance for a URL the realm-server now serves as a non-JSON file (file-meta JSON document) used to throw a confusing "bug: server returned a non card document" error. Reroute through getFileMetaInstance so the caller transparently gets a FileDef. The store test is updated to assert this behavior end-to-end: a card read for a binary URL returns a FileDef and neither bucket caches an error. CS-11147 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ee6d0b3 to
6855110
Compare
Summary
Opening a binary file URL (an uploaded
.png,.jpg, …) as a card — by pasting it into the operator-mode URL bar, or via any code path that routes throughgetCardInstance— fails today: realm-server returns415 Unsupported Media Type, or the host "Loading card…" spinner hangs with no surfaced error. Three coordinated changes get the file-meta load path taken end-to-end.Linear: CS-11147
Changes
file-metaJSON for binary GETs withAccept: application/vnd.card+jsoninstead of 415. Callers can discriminate viadata.type === "file-meta".card+markdownon a binary still 415s — markdown can't represent a binary. Touches the threenonJsonFileExistsbranches ingetCardinpackages/runtime-common/realm.ts.type:"file"from the URL extension when none is provided. NewisFileDefExtension()helper exported frompackages/runtime-common/file-def-code-ref.ts, backed by the existingFILEDEF_CODE_REF_BY_EXTENSIONmap so the set of recognized extensions stays in one place. Pasting a.pngURL into the URL bar now takes the file-meta load path from the first request.store.getCardInstance— if anything still asksgetCardInstancefor a URL that turns out to be a binary, the file-meta JSON is rerouted throughgetFileMetaInstanceand the in-flight card deferred resolves with that result. No hung spinner, no cryptic error.Files
packages/runtime-common/realm.tspackages/runtime-common/file-def-code-ref.ts— newisFileDefExtensionexportpackages/host/app/lib/stack-item.tspackages/host/app/services/store.tspackages/realm-server/tests/card-endpoints-test.ts— asserts file-meta JSON return forcard+jsonon a binary, retains 415 forcard+markdown, retains 415 forPATCH/DELETETest plan
pnpm lint:typesgreen acrossruntime-commonandhost(it is)..pngURL from a realm into a fresh tab. Pre-fix → hang or 415. Post-fix → the FileDef renders as an image.type:"file").