Uh oh!
There was an error while loading. Please reload this page.
fix(metadata-protocol): draft preview no longer reports itself invalid over its own _draft badge - #8179
Conversation
…injected _draft badge Fixes#7656
…ft-preview-diagnostics
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
📓 Docs Drift CheckThis PR changes 1 package(s): 3 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also reference the affected code. These are read-only:
|
Uh oh!
There was an error while loading. Please reload this page.
Fixes#7656
The defect, reproduced
GET /api/v1/meta/{type}/{name}?preview=draftanswered_diagnostics.valid:falsefor a valid draft, complaining about a key the read itself had just added:
Confirmed on
origin/mainbefore any edit, on both injection sites, withtests that were red first (see "Reverse verification" below).
Root cause
The preview read stamps
_draft:trueonto the item so the console can badge it —protocol.ts:4462(list overlay) andprotocol.ts:4672(single-item read) — andthen hands the item to
decorateMetadataItem→computeMetadataDiagnostics,which re-parses it against the closed item schema.
That re-parse stripped only
_diagnostics, via a private one-key helper(
stripDiagnostics) that predated_draftjoining the sharedMETADATA_READ_DECORATIONSlist. So the reader validated its own badge andreported the document invalid for it. The verdict described the reader, not the
document — and it reached every draft of every type, on both exits.
The fix
computeMetadataDiagnosticsnow calls the sharedstripReadDecorationsinsteadof its private copy. One line of behaviour; the rest of the diff is the comment
explaining why the list is the right authority here.
This is the shape the codebase already owns. The module header of
spec/kernel/metadata-read-decorations.tsnames two classes of consumer thatmust strip: the write path's verbatim persist (#4326) and any re-parse of a
served document (cloud#971's cold-boot flow bind). Read-time diagnostics are a
re-parse of a served document in exactly that sense — the third consumer — so it
reads the list rather than keeping a private subset of it.
Same class as the closed#6810 (
indexed, rejected by name on a served object),different remedy, deliberately:
indexeddid not belong on the served bodyat all and was removed at its injection site, whereas
_draftis the previewbadge the UI reads and is already a declared read decoration. Removing the stamp
would break the badge; the list is where it is consumed.
⛔ The item schema is not loosened.
_draftstays rejected by name in astored body — pinned by a test — which is what keeps the #4326 write-path strip
load-bearing rather than cosmetic.
Scope note
The declared file surface was
protocol.ts— "the draft-preview read decorationand the
_diagnosticscomputation it feeds". The fix landed in the module thatis that computation (
metadata-diagnostics.ts, same package), not inprotocol.ts. Closing it there fixes both injection sites with one edit, coversany future decoration key for free, and touches none of
protocol.ts— which iscarrying two other claimed regions this round (#8136, #8003).
Tests
packages/metadata-protocol/src/protocol.read-decorations.test.ts, +6 cases inthe file that already owns this discipline:
getMetaItem({ previewDrafts: true })and through thegetMetaItemsdraftoverlay:
_diagnostics.validistrueand no error mentions_draft.typeis not a field type, seeded directly since the save path refuses it with 422)
still reads back
valid:false, with errors namingamountand not_draft. Without these, a fix that simply stopped computing diagnostics onthe draft path would pass.
METADATA_READ_DECORATIONSmust beinvisible to the verdict, so a fourth decoration fails on a unit here instead
of as
valid:falseon somebody's badge.objectschema still rejects_draftwithunrecognized_keys.Reverse verification
Reverting only
metadata-diagnostics.tstoorigin/mainturns 5 of the 6new cases red, each on the card's verbatim message. The sixth — the
anti-loosening pin — is green in both directions by design: it pins a
constraint the fix must not relax (the schema stays closed), not the fix itself,
so a direction change there would mean the schema had been loosened.
Evidence
Consumer direction: the five non-authoring packages above are downstream
consumers of
@objectstack/metadata-protocol(prefix filter...+ the packagename), picked as the ones whose suites exercise
/metareads, draft preview or_diagnostics. Type surface is unchanged, so this sweep is about behaviour pins,not types.
Gates named by
scripts/pm/dispatch-gates.mjsfor these files, all greenlocally:
check:error-code-casing,check:cross-package-test-inputs,check:durability-log-level,check:changeset-gate-self-tests,check:objectui-changeset,check-changeset-no-major, pluscheck:nul-bytesand
eslinton the changed files.Changeset:
.changeset/draft-preview-diagnostics-draft-badge.md(patch).Generated by Claude Code