@@ -106,6 +106,41 @@ describe("signalSetupAdapter", () => {
106106 expect ( detectSignalTransportMock ) . not . toHaveBeenCalled ( ) ;
107107 } ) ;
108108
109+ it . each ( [
110+ {
111+ accountId : "default" ,
112+ signalNumber : " +1 (555) 555-0123 " ,
113+ expectedAccount : "+15555550123" ,
114+ } ,
115+ {
116+ accountId : "work" ,
117+ signalNumber : "signal: +1 (555) 555-0124" ,
118+ expectedAccount : "+15555550124" ,
119+ } ,
120+ { accountId : "default" , signalNumber : "15555550125" , expectedAccount : "+15555550125" } ,
121+ { accountId : "work" , signalNumber : "+12345" , expectedAccount : "+12345" } ,
122+ {
123+ accountId : "default" ,
124+ signalNumber : "+123456789012345" ,
125+ expectedAccount : "+123456789012345" ,
126+ } ,
127+ ] ) (
128+ "stores the canonical Signal number for the $accountId account" ,
129+ ( { accountId, signalNumber, expectedAccount } ) => {
130+ const next = signalSetupAdapter . applyAccountConfig ?.( {
131+ cfg : { } ,
132+ accountId,
133+ input : { signalNumber } ,
134+ } ) ;
135+ const account =
136+ accountId === "default"
137+ ? next ?. channels ?. signal ?. account
138+ : next ?. channels ?. signal ?. accounts ?. [ accountId ] ?. account ;
139+
140+ expect ( account ) . toBe ( expectedAccount ) ;
141+ } ,
142+ ) ;
143+
109144 it ( "restores a generically promoted default account before writing a named account" , ( ) => {
110145 const next = signalSetupAdapter . applyAccountConfig ?.( {
111146 cfg : {
@@ -427,6 +462,19 @@ describe("signalSetupAdapter", () => {
427462 expect ( next ?. channels ?. signal ?. accounts ?. Default ) . not . toHaveProperty ( "transport" ) ;
428463 } ) ;
429464
465+ it . each ( [ "abc" , "++12345" , "+1+2345" , "+1234" , "+1234567890123456" , " " , "" ] ) (
466+ "rejects invalid Signal account number %s" ,
467+ ( signalNumber ) => {
468+ expect (
469+ signalSetupAdapter . validateInput ?.( {
470+ cfg : { } ,
471+ accountId : "work" ,
472+ input : { signalNumber } ,
473+ } ) ,
474+ ) . toBe ( "Invalid E.164 phone number (must start with + and country code, e.g. +15555550123)" ) ;
475+ } ,
476+ ) ;
477+
430478 it . each ( [ "0" , "abc" , "65536" ] ) ( "rejects invalid managed HTTP port %s" , ( httpPort ) => {
431479 expect (
432480 signalSetupAdapter . validateInput ?.( {
@@ -473,6 +521,30 @@ describe("signalSetupAdapter", () => {
473521 ) . toBe ( "Signal container transport requires --signal-number or an existing account." ) ;
474522 } ) ;
475523
524+ it ( "rejects an invalid replacement without overwriting an existing container account" , ( ) => {
525+ const cfg : OpenClawConfig = {
526+ channels : {
527+ signal : {
528+ account : "+15555550123" ,
529+ transport : { kind : "container" , url : "http://signal-container:8080" } ,
530+ } ,
531+ } ,
532+ } ;
533+ const input = {
534+ signalNumber : "abc" ,
535+ signalTransport : "container" as const ,
536+ httpUrl : "http://signal-container:8080" ,
537+ } ;
538+
539+ expect ( signalSetupAdapter . validateInput ?.( { cfg, accountId : "default" , input } ) ) . toBe (
540+ "Invalid E.164 phone number (must start with + and country code, e.g. +15555550123)" ,
541+ ) ;
542+ expect (
543+ signalSetupAdapter . applyAccountConfig ?.( { cfg, accountId : "default" , input } ) ?. channels
544+ ?. signal ?. account ,
545+ ) . toBe ( "+15555550123" ) ;
546+ } ) ;
547+
476548 it ( "allows a container transport to reuse the configured Signal account" , ( ) => {
477549 expect (
478550 signalSetupAdapter . validateInput ?.( {
0 commit comments