@@ -440,6 +440,35 @@ describe("matrix doctor contract state migrations", () => {
440440 await expect ( migration . detectLegacyState ( createMigrationParams ( stateDir ) ) ) . resolves . toBeNull ( ) ;
441441 } ) ;
442442
443+ it ( "archives malformed inbound dedupe JSON without importing it" , async ( ) => {
444+ const stateDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-matrix-doctor-" ) ) ;
445+ tempDirs . push ( stateDir ) ;
446+ const jsonRoot = path . join (
447+ stateDir ,
448+ "matrix" ,
449+ "accounts" ,
450+ "home" ,
451+ "matrix.example.org__bot" ,
452+ "token-a" ,
453+ ) ;
454+ fs . mkdirSync ( jsonRoot , { recursive : true } ) ;
455+ const jsonPath = path . join ( jsonRoot , "inbound-dedupe.json" ) ;
456+ fs . writeFileSync ( jsonPath , "not-json" ) ;
457+
458+ const migration = migrationById ( "matrix-inbound-dedupe-to-claimable-dedupe" ) ;
459+ await expect ( migration . migrateLegacyState ( createMigrationParams ( stateDir ) ) ) . resolves . toEqual ( {
460+ changes : [
461+ "Migrated Matrix inbound dedupe markers to the claimable dedupe store (0 of 0 entries)" ,
462+ `Archived Matrix inbound dedupe legacy source -> ${ jsonPath } .migrated` ,
463+ ] ,
464+ warnings : [
465+ `Matrix inbound dedupe JSON for ${ jsonRoot } is malformed; archived without import` ,
466+ ] ,
467+ } ) ;
468+ expect ( fs . existsSync ( jsonPath ) ) . toBe ( false ) ;
469+ expect ( fs . existsSync ( `${ jsonPath } .migrated` ) ) . toBe ( true ) ;
470+ } ) ;
471+
443472 it ( "keeps newer runtime dedupe rows when legacy imports hit capacity" , async ( ) => {
444473 const stateDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-matrix-doctor-" ) ) ;
445474 tempDirs . push ( stateDir ) ;
0 commit comments