@@ -975,6 +975,44 @@ describe('[#29007] a stored object carrying the retired titleFormat', () => {
975975 } ) ;
976976} ) ;
977977
978+ // [#29557, #29696] The legacy-D2 flow fixtures the publish doors (#29557) and the
979+ // reads (#29696) are both pinned on.
980+
981+ /** start → get_record → end, the match map spelled under `filterKey`. */
982+ const fetchFlow = ( name : string , filterKey : 'filters' | 'filter' ) => ( {
983+ name,
984+ label : name ,
985+ type : 'autolaunched' ,
986+ nodes : [
987+ { id : 'start' , type : 'start' , label : 'Start' } ,
988+ { id : 'fetch' , type : 'get_record' , label : 'Fetch' , config : { objectName : 'deal' , [ filterKey ] : { name : 'Acme' } , outputVariable : 'deal' } } ,
989+ { id : 'end' , type : 'end' , label : 'End' } ,
990+ ] ,
991+ edges : [
992+ { id : 'e1' , source : 'start' , target : 'fetch' } ,
993+ { id : 'e2' , source : 'fetch' , target : 'end' } ,
994+ ] ,
995+ } ) ;
996+
997+ /** The stored active row a legacy draft is a re-save of. */
998+ async function seedActive ( engine : any , body : { name : string } ) {
999+ await engine . insert ( 'sys_metadata' , {
1000+ type : 'flow' ,
1001+ name : body . name ,
1002+ organization_id : null ,
1003+ package_id : PKG ,
1004+ state : 'active' ,
1005+ metadata : JSON . stringify ( body ) ,
1006+ checksum : hashSpec ( body , 'flow' ) ,
1007+ version : 1 ,
1008+ } ) ;
1009+ }
1010+
1011+ const storedConfig = ( rows : Map < string , Row > , name : string , state : 'active' | 'draft' ) => {
1012+ const row = [ ...rows . values ( ) ] . find ( ( r ) => r . type === 'flow' && r . name === name && r . state === state ) ;
1013+ return row ? JSON . parse ( row . metadata ) . nodes [ 1 ] . config : undefined ;
1014+ } ;
1015+
9781016/**
9791017 * [#29557] A flow draft stored in a legacy ADR-0087 D2 spelling the engine
9801018 * registers (`get_record` `config.filters`, `flow-node-crud-filter-alias`). The
@@ -998,41 +1036,6 @@ describe('[#29557] a stored flow draft in a legacy D2 spelling the engine regist
9981036 warn . mockRestore ( ) ;
9991037 } ) ;
10001038
1001- /** start → get_record → end, the match map spelled under `filterKey`. */
1002- const fetchFlow = ( name : string , filterKey : 'filters' | 'filter' ) => ( {
1003- name,
1004- label : name ,
1005- type : 'autolaunched' ,
1006- nodes : [
1007- { id : 'start' , type : 'start' , label : 'Start' } ,
1008- { id : 'fetch' , type : 'get_record' , label : 'Fetch' , config : { objectName : 'deal' , [ filterKey ] : { name : 'Acme' } , outputVariable : 'deal' } } ,
1009- { id : 'end' , type : 'end' , label : 'End' } ,
1010- ] ,
1011- edges : [
1012- { id : 'e1' , source : 'start' , target : 'fetch' } ,
1013- { id : 'e2' , source : 'fetch' , target : 'end' } ,
1014- ] ,
1015- } ) ;
1016-
1017- /** The stored active row a legacy draft is a re-save of. */
1018- async function seedActive ( engine : any , body : { name : string } ) {
1019- await engine . insert ( 'sys_metadata' , {
1020- type : 'flow' ,
1021- name : body . name ,
1022- organization_id : null ,
1023- package_id : PKG ,
1024- state : 'active' ,
1025- metadata : JSON . stringify ( body ) ,
1026- checksum : hashSpec ( body , 'flow' ) ,
1027- version : 1 ,
1028- } ) ;
1029- }
1030-
1031- const storedConfig = ( rows : Map < string , Row > , name : string , state : 'active' | 'draft' ) => {
1032- const row = [ ...rows . values ( ) ] . find ( ( r ) => r . type === 'flow' && r . name === name && r . state === state ) ;
1033- return row ? JSON . parse ( row . metadata ) . nodes [ 1 ] . config : undefined ;
1034- } ;
1035-
10361039 async function stageLegacy ( name : string , body = fetchFlow ( name , 'filters' ) ) {
10371040 const { engine, rows } = makeStubEngine ( ) ;
10381041 const protocol = new ObjectStackProtocolImplementation ( engine ) ;
@@ -1116,3 +1119,90 @@ describe('[#29557] a stored flow draft in a legacy D2 spelling the engine regist
11161119 expect ( issueTriples ( batch . failed [ 0 ] . issues ) ) . toEqual ( issueTriples ( canonical . err . issues ) ) ;
11171120 } ) ;
11181121} ) ;
1122+
1123+ /**
1124+ * [#29696] A flow READ judges a stored legacy D2 row in the spelling the doors
1125+ * judge it in. A row at rest in a legacy ADR-0087 D2 spelling (`get_record`
1126+ * `config.filters`) is accepted by the save door, both publish doors (#29557)
1127+ * and the engine's canonicalizer; the read's `_diagnostics` schema half judges
1128+ * it through the same seam (`storedFlowVerdictBody`), and serves it as stored.
1129+ * Measured on `origin/main` `0eb97fa4` before the fix: every read below
1130+ * answered `valid: false` with `unrecognized_keys` on `config.filters`.
1131+ */
1132+ describe ( '[#29696] a flow read judges a stored legacy D2 row in its D2-converted spelling' , ( ) => {
1133+ let warn : ReturnType < typeof vi . spyOn > ;
1134+ beforeEach ( ( ) => {
1135+ warn = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
1136+ delete process . env . OS_ALLOW_UNLINTED_METADATA_WRITES ;
1137+ } ) ;
1138+ afterEach ( ( ) => {
1139+ warn . mockRestore ( ) ;
1140+ } ) ;
1141+
1142+ /** The legacy fixture with a config key no conversion rewrites and the parse refuses. */
1143+ const withUndeclaredKey = ( name : string , filterKey : 'filters' | 'filter' ) => {
1144+ const flow = fetchFlow ( name , filterKey ) ;
1145+ flow . nodes [ 1 ] = { ...flow . nodes [ 1 ] ! , config : { ...flow . nodes [ 1 ] ! . config , not_a_config_key : true } } as typeof flow . nodes [ number ] ;
1146+ return flow ;
1147+ } ;
1148+
1149+ async function seeded ( body : { name : string } ) {
1150+ const { engine, rows } = makeStubEngine ( ) ;
1151+ const protocol = new ObjectStackProtocolImplementation ( engine ) ;
1152+ await seedActive ( engine , body ) ;
1153+ return { engine, rows, protocol } ;
1154+ }
1155+
1156+ /** The active item read's `_diagnostics` and the config it serves. */
1157+ async function activeRead ( protocol : ObjectStackProtocolImplementation , name : string ) {
1158+ const read : any = await protocol . getMetaItem ( { type : 'flow' , name, packageId : PKG } as any ) ;
1159+ return { diagnostics : read . item . _diagnostics , config : read . item . nodes [ 1 ] . config } ;
1160+ }
1161+
1162+ it ( 'the active item read reads valid: true and serves the stored bytes' , async ( ) => {
1163+ const { protocol } = await seeded ( fetchFlow ( 'legacy_fetch' , 'filters' ) ) ;
1164+
1165+ const { diagnostics, config } = await activeRead ( protocol , 'legacy_fetch' ) ;
1166+
1167+ expect ( diagnostics ) . toEqual ( { valid : true } ) ;
1168+ expect ( config ) . toEqual ( { objectName : 'deal' , filters : { name : 'Acme' } , outputVariable : 'deal' } ) ;
1169+ } ) ;
1170+
1171+ it ( 'the list read reads valid: true and serves the stored bytes' , async ( ) => {
1172+ const { protocol } = await seeded ( fetchFlow ( 'legacy_fetch' , 'filters' ) ) ;
1173+
1174+ const list : any = await protocol . getMetaItems ( { type : 'flow' , packageId : PKG } ) ;
1175+ const item = ( list . items as any [ ] ) . find ( ( i ) => i . name === 'legacy_fetch' ) ;
1176+
1177+ expect ( item ?. _diagnostics ) . toEqual ( { valid : true } ) ;
1178+ expect ( item . nodes [ 1 ] . config ) . toEqual ( { objectName : 'deal' , filters : { name : 'Acme' } , outputVariable : 'deal' } ) ;
1179+ } ) ;
1180+
1181+ it ( 'the layered read reads valid: true' , async ( ) => {
1182+ const { protocol } = await seeded ( fetchFlow ( 'legacy_fetch' , 'filters' ) ) ;
1183+
1184+ const layered : any = await protocol . getMetaItemLayered ( { type : 'flow' , name : 'legacy_fetch' , packageId : PKG } as any ) ;
1185+
1186+ expect ( layered . _diagnostics ) . toEqual ( { valid : true } ) ;
1187+ } ) ;
1188+
1189+ it ( 'the draft read of a re-save of it reads valid: true' , async ( ) => {
1190+ const body = fetchFlow ( 'legacy_fetch' , 'filters' ) ;
1191+ const { rows, protocol } = await seeded ( body ) ;
1192+ expect ( await stageDraft ( protocol , 'flow' , body ) ) . toMatchObject ( { success : true , state : 'draft' } ) ;
1193+ expect ( storedConfig ( rows , 'legacy_fetch' , 'draft' ) ) . toEqual ( { objectName : 'deal' , filters : { name : 'Acme' } , outputVariable : 'deal' } ) ;
1194+
1195+ expect ( await draftDiagnostics ( protocol , 'flow' , 'legacy_fetch' ) ) . toEqual ( { valid : true } ) ;
1196+ } ) ;
1197+
1198+ it ( 'a row still refused once converted reads valid: false, with the errors its canonical spelling reads' , async ( ) => {
1199+ const canonical = await activeRead ( ( await seeded ( withUndeclaredKey ( 'refused_fetch' , 'filter' ) ) ) . protocol , 'refused_fetch' ) ;
1200+ const legacy = await activeRead ( ( await seeded ( withUndeclaredKey ( 'refused_fetch' , 'filters' ) ) ) . protocol , 'refused_fetch' ) ;
1201+
1202+ expect ( canonical . diagnostics . valid ) . toBe ( false ) ;
1203+ expect ( JSON . stringify ( canonical . diagnostics . errors ) ) . toContain ( 'not_a_config_key' ) ;
1204+ expect ( legacy . diagnostics ) . toEqual ( canonical . diagnostics ) ;
1205+ // Served as stored: the legacy spelling is what the read hands back.
1206+ expect ( legacy . config . filters ) . toEqual ( { name : 'Acme' } ) ;
1207+ } ) ;
1208+ } ) ;
0 commit comments