@@ -73,6 +73,32 @@ describe('mapApiError', () => {
7373 expect ( err . exitCode ) . toBe ( ExitCode . QUOTA ) ;
7474 } ) ;
7575
76+ it ( 'maps output sensitivity (HTTP 200) to CONTENT_FILTER' , ( ) => {
77+ const err = mapApiError ( 200 , {
78+ base_resp : { status_code : 2001 , status_msg : 'output new_sensitive' } ,
79+ } ) ;
80+ expect ( err . exitCode ) . toBe ( ExitCode . CONTENT_FILTER ) ;
81+ expect ( err . message ) . toContain ( 'content moderation' ) ;
82+ expect ( err . message ) . toContain ( 'output new_sensitive' ) ;
83+ expect ( err . hint ) . toBeDefined ( ) ;
84+ } ) ;
85+
86+ it ( 'maps output sensitivity code 1027 to CONTENT_FILTER' , ( ) => {
87+ const err = mapApiError ( 200 , {
88+ base_resp : { status_code : 1027 , status_msg : '输出内容涉敏' } ,
89+ } ) ;
90+ expect ( err . exitCode ) . toBe ( ExitCode . CONTENT_FILTER ) ;
91+ } ) ;
92+
93+ it ( 'maps input sensitivity code 1026 to CONTENT_FILTER (not output)' , ( ) => {
94+ const err = mapApiError ( 200 , {
95+ base_resp : { status_code : 1026 , status_msg : 'input new_sensitive' } ,
96+ } ) ;
97+ expect ( err . exitCode ) . toBe ( ExitCode . CONTENT_FILTER ) ;
98+ expect ( err . message ) . toContain ( 'Input' ) ;
99+ expect ( err . message ) . not . toContain ( 'Output withheld' ) ;
100+ } ) ;
101+
76102 it ( 'maps unknown errors to GENERAL' , ( ) => {
77103 const err = mapApiError ( 500 , { base_resp : { status_code : 0 , status_msg : 'internal error' } } ) ;
78104 expect ( err . exitCode ) . toBe ( ExitCode . GENERAL ) ;
0 commit comments