@@ -401,6 +401,61 @@ describe("oc-chatgpt import adapter", () => {
401401 ) ;
402402 } ) ;
403403
404+ it ( "keeps reversed-order shared-account imports distinct when only one destination email exists" , ( ) => {
405+ const destination : AccountStorageV3 = {
406+ version : 3 ,
407+ activeIndex : 0 ,
408+ accounts : [
409+ {
410+ accountId : "shared-account" ,
411+ email : "alice@example.com" ,
412+ refreshToken : "dest-alice" ,
413+ addedAt : 10 ,
414+ lastUsed : 10 ,
415+ } ,
416+ ] ,
417+ } ;
418+
419+ const source : AccountStorageV3 = {
420+ version : 3 ,
421+ activeIndex : 1 ,
422+ accounts : [
423+ {
424+ accountId : "shared-account" ,
425+ email : "bob@example.com" ,
426+ refreshToken : "source-bob" ,
427+ addedAt : 2 ,
428+ lastUsed : 2 ,
429+ } ,
430+ {
431+ accountId : "shared-account" ,
432+ email : "alice@example.com" ,
433+ refreshToken : "source-alice-older" ,
434+ addedAt : 1 ,
435+ lastUsed : 1 ,
436+ } ,
437+ ] ,
438+ } ;
439+
440+ const preview = previewOcChatgptImportMerge ( { source, destination } ) ;
441+
442+ expect ( preview . toUpdate ) . toHaveLength ( 0 ) ;
443+ expect ( preview . toAdd ) . toEqual ( [
444+ {
445+ accountId : "shared-account" ,
446+ email : "bob@example.com" ,
447+ refreshTokenLast4 : "-bob" ,
448+ } ,
449+ ] ) ;
450+ expect ( preview . merged . accounts ) . toHaveLength ( 2 ) ;
451+ expect ( preview . merged . accounts . map ( ( account ) => account . email ) ) . toEqual (
452+ expect . arrayContaining ( [ "alice@example.com" , "bob@example.com" ] ) ,
453+ ) ;
454+ expect ( preview . merged . accounts . map ( ( account ) => account . refreshToken ) ) . toEqual (
455+ expect . arrayContaining ( [ "dest-alice" , "source-bob" ] ) ,
456+ ) ;
457+ } ) ;
458+
404459 it ( "keeps newer destination metadata when a refresh-token fallback match is older than destination" , ( ) => {
405460 const destination : AccountStorageV3 = {
406461 version : 3 ,
0 commit comments