@@ -372,13 +372,20 @@ describe('[#12975] the share family: convergence, and the two exits still carryi
372372 expect ( dataAnswer . body . code ) . toBe ( 'FORBIDDEN' ) ;
373373 } ) ;
374374
375- it ( '⚠️ MEASURED, NOT REPAIRED HERE — two exits still ship the prefix' , async ( ) => {
376- // Recorded rather than fixed: the ruling moved ONE arm, and both exits
377- // below are reached through `resolveErrorResponse`'s own declared-4xx
378- // passthrough, which it did not name. Filed for the maintainer as
379- // #13095; this case is the evidence, and it REDS the day either exit is
380- // converged, which is the point — the follow-up moves it deliberately
381- // instead of discovering the divergence a third time.
375+ it ( 'CONVERGENCE [#13095] — the two exits that used to ship the prefix no longer do' , async ( ) => {
376+ // ⚠️ MOVED DELIBERATELY. Until #13095 this case was titled
377+ // "MEASURED, NOT REPAIRED HERE" and pinned the OLD truth — both exits
378+ // below are reached through `resolveErrorResponse`'s declared-4xx
379+ // passthrough (checked BEFORE it delegates to `mapDataError`), which
380+ // the #12975 ruling did not name, so both still shipped
381+ // `FORBIDDEN: ${ZH}` while the by-id door had converged. That case
382+ // existed to red the day either exit converged, so the follow-up
383+ // would move it deliberately instead of discovering the divergence a
384+ // third time. This is that day: the 2026-08-31 maintainer ruling on
385+ // #13095 (option 1) put the same declared-code-anchored
386+ // `withoutDeclaredCodePrefix` in the passthrough arm, and the
387+ // record-share classified arm converges with it for free because it
388+ // re-dresses that same classification.
382389 //
383390 // (a) the record-share family's CLASSIFIED arm — a producer that
384391 // declared `{ code, status }` AND used the prefix idiom;
@@ -388,13 +395,99 @@ describe('[#12975] the share family: convergence, and the two exits still carryi
388395 boot ( { } , throwingShareService ( sharingWriteRefusal ( ) ) ) ,
389396 'GET' , SHARES , { params : { object : 'showcase_inquiry' , id : 'rec1' } } ,
390397 ) ;
391- expect ( classified . body . error . message ) . toBe ( `FORBIDDEN: ${ ZH } ` ) ;
398+ expect ( classified . body . error . message ) . toBe ( ZH ) ;
399+ expect ( classified . body . error . code ) . toBe ( 'FORBIDDEN' ) ;
392400
393401 const bulk = await call (
394402 boot ( { batchData : vi . fn ( ) . mockRejectedValue ( sharingWriteRefusal ( ) ) } ) ,
395403 'POST' , `${ COLLECTION } /batch` ,
396404 { params : { object : 'showcase_inquiry' } , body : { operation : 'update' , records : [ { id : 'r1' } ] } } ,
397405 ) ;
398- expect ( bulk . body . error ) . toBe ( `FORBIDDEN: ${ ZH } ` ) ;
406+ expect ( bulk . body . error ) . toBe ( ZH ) ;
407+ expect ( bulk . body . code ) . toBe ( 'FORBIDDEN' ) ;
408+ } ) ;
409+ } ) ;
410+
411+ // ---------------------------------------------------------------------------
412+ // §6 The passthrough arm's own controls — the strip stays ANCHORED (#13095)
413+ // ---------------------------------------------------------------------------
414+
415+ describe ( '[#13095] the bulk door strips by declared code, never by pattern' , ( ) => {
416+ const batchWith = ( error : unknown ) => call (
417+ boot ( { batchData : vi . fn ( ) . mockRejectedValue ( error ) } ) ,
418+ 'POST' , `${ COLLECTION } /batch` ,
419+ { params : { object : 'showcase_inquiry' } , body : { operation : 'update' , records : [ { id : 'r1' } ] } } ,
420+ ) ;
421+
422+ it ( '⭐ a declared 4xx with NO `code` KEEPS its prefix — the token is nowhere else' , async ( ) => {
423+ // §2's control, restated on the arm #13095 moved: `thrownCodeFields`
424+ // answers `{}` for a producer that named no code, so stripping here
425+ // would delete the only machine token in the response rather than
426+ // move it to its axis.
427+ const answer = await batchWith ( thrown ( `FORBIDDEN: ${ ZH } ` , { status : 403 } ) ) ;
428+ expect ( answer . status ) . toBe ( 403 ) ;
429+ expect ( answer . body . error ) . toBe ( `FORBIDDEN: ${ ZH } ` ) ;
430+ expect ( 'code' in answer . body ) . toBe ( false ) ;
431+ } ) ;
432+
433+ it ( '⭐ a prefix that does not name the declared code is left alone — driver prose stays' , async ( ) => {
434+ const answer = await batchWith (
435+ thrown ( 'SQLITE_ERROR: no such table: showcase_inquiry' , { code : 'FORBIDDEN' , status : 400 } ) ,
436+ ) ;
437+ expect ( answer . body . error ) . toBe ( 'SQLITE_ERROR: no such table: showcase_inquiry' ) ;
438+ } ) ;
439+
440+ it ( 'a message that is nothing but the prefix degrades to the generic sentence' , async ( ) => {
441+ const answer = await batchWith ( thrown ( 'FORBIDDEN:' , { code : 'FORBIDDEN' , status : 403 } ) ) ;
442+ expect ( answer . body . error ) . toBe ( 'Request failed' ) ;
443+ expect ( answer . body . code ) . toBe ( 'FORBIDDEN' ) ;
444+ } ) ;
445+ } ) ;
446+
447+ // ---------------------------------------------------------------------------
448+ // §7 The approvals door — the third strip point, converged onto the anchor
449+ // ---------------------------------------------------------------------------
450+
451+ describe ( '[#13095] the approvals door strips the code it answers, never a blanket pattern' , ( ) => {
452+ const APPROVE = '/api/v1/approvals/requests/:id/approve' ;
453+
454+ const approveWith = ( error : unknown ) => {
455+ const protocol : any = {
456+ getDiscovery : vi . fn ( ) . mockResolvedValue ( {
457+ version : 'v0' , routes : { data : '' , metadata : '' , ui : '' , auth : '/auth' } ,
458+ } ) ,
459+ getMetaTypes : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
460+ getMetaItems : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
461+ findData : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
462+ } ;
463+ const rest = new RestServer (
464+ mockServer ( ) as any , protocol , { api : { requireAuth : false } } as any ,
465+ undefined , undefined , undefined , undefined , undefined , undefined ,
466+ undefined , undefined ,
467+ ( async ( ) => ( { decide : vi . fn ( ) . mockRejectedValue ( error ) } ) ) as any ,
468+ ) ;
469+ ( rest as any ) . resolveExecCtx = async ( ) => ( { userId : 'u1' } ) ;
470+ rest . registerRoutes ( ) ;
471+ return call ( rest , 'POST' , APPROVE , { params : { id : 'req_1' } } ) ;
472+ } ;
473+
474+ it ( 'the well-formed idiom is unchanged: the answered code is stripped from the sentence' , async ( ) => {
475+ const answer = await approveWith ( thrown ( `FORBIDDEN: ${ ZH } ` ) ) ;
476+ expect ( answer . status ) . toBe ( 403 ) ;
477+ expect ( answer . body . code ) . toBe ( 'FORBIDDEN' ) ;
478+ expect ( answer . body . error ) . toBe ( ZH ) ;
479+ } ) ;
480+
481+ it ( '⭐ a LONGER token sharing the matched spelling is NOT eaten — the blanket regex would have' , async ( ) => {
482+ // The distinguisher between the old `/^[A-Z_]+:\s*/` strip and the
483+ // anchored one: `/^FORBIDDEN/` matches this message, so the row
484+ // answers `code: 'FORBIDDEN'` — but the sentence opens with a
485+ // DIFFERENT token, which the wire carries nowhere else. The blanket
486+ // regex deleted it; the anchored strip removes only a duplicate of
487+ // the code being answered (#12975's rule, spread by #13095).
488+ const answer = await approveWith ( thrown ( 'FORBIDDEN_BY_POLICY: contact your administrator' ) ) ;
489+ expect ( answer . status ) . toBe ( 403 ) ;
490+ expect ( answer . body . code ) . toBe ( 'FORBIDDEN' ) ;
491+ expect ( answer . body . error ) . toBe ( 'FORBIDDEN_BY_POLICY: contact your administrator' ) ;
399492 } ) ;
400493} ) ;
0 commit comments