1313// decoration (`_diagnostics` computed on the raw body, then the type's
1414// credential redaction), so this one equality says "the served item minus
1515// `_diagnostics` and redaction", for a redacting type as for a plain one.
16+ // A PENDING DRAFT's served item also carries what its publish will refuse
17+ // (#26707): `_diagnostics` is the decoration's verdict extended by the
18+ // protocol's own `draftPublishVerdict` on the draft body
19+ // (`withPublishVerdict`), the execution face carrying neither.
1620// - THE ENVELOPE: every other key (`lock`, `editable`, `version`, `packageId`,
1721// …) is equal, save `registration`, which the served face alone carries,
1822// as the list read's served face alone carries `registrations`.
3034import { describe , it , expect } from 'vitest' ;
3135import { assertEngineFindOnePredicate } from '@objectstack/metadata-core' ;
3236import { ObjectStackProtocolImplementation } from './protocol.js' ;
33- import { decorateMetadataItem } from './metadata-diagnostics.js' ;
37+ import { decorateMetadataItem , withPublishVerdict } from './metadata-diagnostics.js' ;
3438import { metaOverlayCacheEntryCount } from './meta-overlay-cache.js' ;
3539
3640type Row = Record < string , unknown > ;
@@ -139,6 +143,14 @@ function harness(rows: Row[], opts: { disabledObjects?: string[]; automation?: b
139143 return { protocol, engine, reads, write } ;
140144}
141145
146+ /**
147+ * [#26707] The publish verdict a pending draft's served read carries: the
148+ * protocol's own judge, on the stored draft body.
149+ */
150+ async function draftVerdictOf ( h : ReturnType < typeof harness > , type : string , body : Row ) : Promise < unknown [ ] > {
151+ return h . protocol . draftPublishVerdict ( { type, name : body . name , body, packageId : null } ) ;
152+ }
153+
142154/** Read one request on both faces. */
143155async function bothFaces ( h : ReturnType < typeof harness > , request : Row ) {
144156 const served = await h . protocol . getMetaItem ( structuredClone ( request ) ) ;
@@ -150,11 +162,16 @@ async function bothFaces(h: ReturnType<typeof harness>, request: Row) {
150162 * THE parity: the served item is the execution item decorated, every other
151163 * envelope key is equal, and the served item really is decorated.
152164 */
153- function expectParity ( type : string , served : any , execution : any ) {
165+ function expectParity ( type : string , served : any , execution : any , publishVerdict ?: unknown [ ] ) {
154166 expect ( served . item , 'the served face found an item' ) . toBeTruthy ( ) ;
155167 expect ( served . item . _diagnostics , 'the served item is decorated (anti-vacuity)' ) . toBeDefined ( ) ;
156168 expect ( Object . prototype . hasOwnProperty . call ( execution . item , '_diagnostics' ) ) . toBe ( false ) ;
157- expect ( served . item ) . toEqual ( decorateMetadataItem ( type , execution . item ) ) ;
169+ const decorated = decorateMetadataItem ( type , execution . item ) ;
170+ expect ( served . item ) . toEqual (
171+ publishVerdict === undefined
172+ ? decorated
173+ : { ...decorated , _diagnostics : withPublishVerdict ( type , execution . item . name , decorated . _diagnostics , publishVerdict as never ) } ,
174+ ) ;
158175 const { item : _servedItem , registration : _servedOnly , ...servedEnvelope } = served ;
159176 const { item : _executionItem , ...executionEnvelope } = execution ;
160177 expect ( executionEnvelope ) . toEqual ( servedEnvelope ) ;
@@ -213,7 +230,10 @@ describe('[#24535] the by-name execution read is the served read minus the servi
213230 ] ;
214231 const h = harness ( rows ) ;
215232 const { served, execution } = await bothFaces ( h , { type : 'object' , name : 'stored_widget' , state : 'draft' } ) ;
216- expectParity ( 'object' , served , execution ) ;
233+ const verdict = await draftVerdictOf ( h , 'object' , JSON . parse ( rows [ 1 ] . metadata as string ) ) ;
234+ // The draft declares no sharingModel, which its publish refuses (#26707).
235+ expect ( verdict ) . toContainEqual ( expect . objectContaining ( { rule : 'security-owd-unset' } ) ) ;
236+ expectParity ( 'object' , served , execution , verdict ) ;
217237 expect ( execution . item . label ) . toBe ( 'Draft' ) ;
218238 } ) ;
219239
@@ -223,7 +243,7 @@ describe('[#24535] the by-name execution read is the served read minus the servi
223243 objectRow ( 'stored_widget' , 'draft' , { label : 'Draft' } ) ,
224244 ] ) ;
225245 const preview = await bothFaces ( withDraft , { type : 'object' , name : 'stored_widget' , previewDrafts : true } ) ;
226- expectParity ( 'object' , preview . served , preview . execution ) ;
246+ expectParity ( 'object' , preview . served , preview . execution , await draftVerdictOf ( withDraft , 'object' , { name : 'stored_widget' , fields : { } , label : 'Draft' } ) ) ;
227247 expect ( preview . execution . item ) . toMatchObject ( { label : 'Draft' , _draft : true } ) ;
228248
229249 const withoutDraft = harness ( [ objectRow ( 'stored_widget' , 'active' , { label : 'Active' } ) ] ) ;
0 commit comments