@@ -83,6 +83,27 @@ describe("legacy channel pairing state migration", () => {
8383 ) ;
8484 } ) ;
8585
86+ it ( "imports a built-in channel's explicit default account without channel config" , async ( ) => {
87+ const { env, sourceDir } = await createFixture ( ) ;
88+ const filePath = path . join ( sourceDir , "whatsapp-default-allowFrom.json" ) ;
89+ writeJson ( filePath , {
90+ version : 1 ,
91+ allowFrom : [ "+12025550101" , "+12025550102" , "+12025550103" ] ,
92+ } ) ;
93+
94+ const detected = detectLegacyChannelPairingState ( { sourceDir } ) ;
95+ const result = migrateLegacyChannelPairingState ( { detected, env } ) ;
96+
97+ expect ( result . warnings ) . toEqual ( [ ] ) ;
98+ expect ( result . changes ) . toEqual ( [
99+ "Migrated 3 whatsapp/default allowFrom entries → shared SQLite state" ,
100+ ] ) ;
101+ expect ( fs . existsSync ( filePath ) ) . toBe ( false ) ;
102+ expect ( readChannelPairingStateSnapshot ( "whatsapp" , env ) . allowFrom ) . toEqual ( {
103+ default : [ "+12025550101" , "+12025550102" , "+12025550103" ] ,
104+ } ) ;
105+ } ) ;
106+
86107 it ( "merges with authoritative SQLite rows and keeps unreadable sources" , async ( ) => {
87108 const { env, sourceDir } = await createFixture ( ) ;
88109 const createdAt = new Date ( ) . toISOString ( ) ;
@@ -159,6 +180,27 @@ describe("legacy channel pairing state migration", () => {
159180 expect ( readChannelPairingStateSnapshot ( "telegram" , env ) . allowFrom ) . toEqual ( { } ) ;
160181 } ) ;
161182
183+ it ( "does not infer default accounts for external channels" , async ( ) => {
184+ const { env, sourceDir } = await createFixture ( ) ;
185+ const filePath = path . join ( sourceDir , "custom-channel-default-allowFrom.json" ) ;
186+ writeJson ( filePath , { version : 1 , allowFrom : [ "external-user" ] } ) ;
187+
188+ const detected = detectLegacyChannelPairingState ( {
189+ sourceDir,
190+ configuredChannelIds : [ "custom-channel" ] ,
191+ } ) ;
192+ const result = migrateLegacyChannelPairingState ( { detected, env } ) ;
193+
194+ expect ( result . changes ) . toEqual ( [ ] ) ;
195+ expect ( result . warnings ) . toEqual ( [
196+ expect . stringContaining (
197+ "Legacy channel allowFrom channel/account is unresolved; left in place" ,
198+ ) ,
199+ ] ) ;
200+ expect ( fs . existsSync ( filePath ) ) . toBe ( true ) ;
201+ expect ( readChannelPairingStateSnapshot ( "custom-channel" , env ) . allowFrom ) . toEqual ( { } ) ;
202+ } ) ;
203+
162204 it ( "leaves overlapping channel and account filename interpretations in place" , async ( ) => {
163205 const { env, sourceDir } = await createFixture ( ) ;
164206 const filePath = path . join ( sourceDir , "telegram-business-allowFrom.json" ) ;
0 commit comments