@@ -172,6 +172,56 @@ describe('#25062 PROBE: the preview and the walled write, side by side (origin/m
172172 } ) ;
173173} ) ;
174174
175+ describe ( '#25062 PROBE: the HTTP validate door — `POST /api/v1/data/:object/import`, dry run vs commit' , ( ) => {
176+ // The real RestServer route and import runner, over the real protocol
177+ // (`validateData` / `createData`) over the walled engine. Only the request's
178+ // execution context is supplied, as the dry-run parity suite supplies it.
179+ const importDoor = async ( b : Booted , context : object ) => {
180+ const { RestServer } = await import ( '@objectstack/rest' ) ;
181+ // Probe-only relative reach: this package does not declare metadata-protocol.
182+ const { ObjectStackProtocolImplementation } = await import ( '../../../metadata-protocol/src/index.js' ) ;
183+ const noop = ( ) => { } ;
184+ const server = { get : noop , post : noop , put : noop , delete : noop , patch : noop , use : noop , listen : async ( ) => { } , close : async ( ) => { } } ;
185+ const protocol = new ObjectStackProtocolImplementation ( b . engine as never ) ;
186+ const rest = new RestServer ( server as never , protocol as never , { api : { requireAuth : false } } as never ) ;
187+ ( rest as unknown as { resolveExecCtx : ( ) => Promise < object > } ) . resolveExecCtx = async ( ) => ( { ...context } ) ;
188+ rest . registerRoutes ( ) ;
189+ const route = rest . getRoutes ( ) . find ( ( r : any ) => r . method === 'POST' && r . path === '/api/v1/data/:object/import' ) as any ;
190+ return async ( rows : unknown [ ] , dryRun : boolean ) => {
191+ const res : any = {
192+ write : ( ) => true , end : ( ) => { } , header : ( ) => res ,
193+ status : ( code : number ) => { res . _status = code ; return res ; } ,
194+ json : ( body : unknown ) => { res . _json = body ; return res ; } ,
195+ } ;
196+ await route . handler ( { params : { object : INJECTED } , body : { format : 'json' , rows, dryRun } , headers : { } } , res ) ;
197+ return { status : res . _status ?? 200 , body : res . _json } ;
198+ } ;
199+ } ;
200+
201+ it ( 'M5 cell (a), `group`: the dry run reports organization_id dropped, the commit stores it as sent' , async ( ) => {
202+ const b = await boot ( 'group' ) ;
203+ const door = await importDoor ( b , GROUP_CTX ) ;
204+ const dry = await door ( [ { id : 'r2' , name : 'n' , organization_id : SISTER_ORG } ] , true ) ;
205+ const commit = await door ( [ { id : 'r2' , name : 'n' , organization_id : SISTER_ORG } ] , false ) ;
206+ console . log ( 'M5a' , JSON . stringify ( { dry : dry . body ?. results , commit : commit . body ?. results , stored : await b . table ( ) } ) ) ;
207+ expect ( dry . body . results [ 0 ] ) . toMatchObject ( { ok : true , droppedFields : [ { object : INJECTED , fields : [ 'organization_id' ] , reason : 'readonly' } ] } ) ;
208+ expect ( commit . body . results [ 0 ] ) . toMatchObject ( { ok : true } ) ;
209+ expect ( commit . body . results [ 0 ] ) . not . toHaveProperty ( 'droppedFields' ) ;
210+ expect ( await b . table ( ) ) . toContainEqual ( { id : 'r2' , organization_id : SISTER_ORG } ) ;
211+ } ) ;
212+
213+ it ( 'M5 cell (b), `isolated`: the dry run answers ok, the commit refuses the row 403' , async ( ) => {
214+ const b = await boot ( 'isolated' ) ;
215+ const door = await importDoor ( b , MEMBER_CTX ) ;
216+ const dry = await door ( [ { id : 'r2' , name : 'n' , organization_id : FOREIGN_ORG } ] , true ) ;
217+ const commit = await door ( [ { id : 'r2' , name : 'n' , organization_id : FOREIGN_ORG } ] , false ) ;
218+ console . log ( 'M5b' , JSON . stringify ( { dry : dry . body ?. results , commit : commit . body ?. results , stored : await b . table ( ) } ) ) ;
219+ expect ( dry . body . results [ 0 ] ) . toMatchObject ( { ok : true } ) ;
220+ expect ( commit . body . results [ 0 ] ) . toMatchObject ( { ok : false } ) ;
221+ expect ( await b . table ( ) ) . toEqual ( [ { id : 'r1' , organization_id : OWN_ORG } ] ) ;
222+ } ) ;
223+ } ) ;
224+
175225describe ( '#25062 PROBE: the one existing preview seam, `registerWriteGateProbe` (security: `canWriteObject`)' , ( ) => {
176226 it ( 'M3: answers one boolean for the whole set, the same `true` for an admitted, a refused and an unwalled organization' , async ( ) => {
177227 const answers : Record < string , unknown > = { } ;
0 commit comments