@@ -79,6 +79,42 @@ describe("createMessageSendingHandler", () => {
7979 expect ( result ! . content ) . not . toContain ( "john@example.com" ) ;
8080 } ) ;
8181
82+ it ( "uses regex-only scanning to keep outbound delivery fast" , async ( ) => {
83+ const config = makeConfig ( ) ;
84+ const scanner = new Scanner ( config ) ;
85+ const fullScan = vi . spyOn ( scanner , "scan" ) . mockRejectedValue ( new Error ( "GLiNER path should not run" ) ) ;
86+ const handler = createMessageSendingHandler ( config , scanner ) ;
87+
88+ const result = await handler (
89+ { to : "user" , content : "Send to john@example.com" } ,
90+ makeCtx ( ) ,
91+ ) ;
92+
93+ expect ( result ) . toBeDefined ( ) ;
94+ expect ( result ! . content ) . toContain ( "[EMAIL_1]" ) ;
95+ expect ( fullScan ) . not . toHaveBeenCalled ( ) ;
96+ } ) ;
97+
98+ it ( "redacts secrets and tokens in outbound message" , async ( ) => {
99+ const config = makeConfig ( ) ;
100+ const scanner = new Scanner ( config ) ;
101+ const handler = createMessageSendingHandler ( config , scanner ) ;
102+
103+ const result = await handler (
104+ {
105+ to : "user" ,
106+ content : "secret=abcDEF123456 token: Bearer tok_1234567890" ,
107+ } ,
108+ makeCtx ( ) ,
109+ ) ;
110+
111+ expect ( result ) . toBeDefined ( ) ;
112+ expect ( result ! . content ) . toContain ( "[SECRET_1]" ) ;
113+ expect ( result ! . content ) . toContain ( "[TOKEN_1]" ) ;
114+ expect ( result ! . content ) . not . toContain ( "abcDEF123456" ) ;
115+ expect ( result ! . content ) . not . toContain ( "tok_1234567890" ) ;
116+ } ) ;
117+
82118 it ( "returns void when no PII found" , async ( ) => {
83119 const config = makeConfig ( ) ;
84120 const scanner = new Scanner ( config ) ;
0 commit comments