@@ -128,9 +128,30 @@ def test_fetch_source_internal_error_is_sanitized(self) -> None:
128128 self .assertEqual (fetch_resp .status_code , 500 )
129129 body = fetch_resp .json ()
130130 self .assertEqual (body ["error" ], "internal_error" )
131- self .assertTrue (body ["message" ].startswith ("Fetch intelligence source failed" ))
132- self .assertNotIn ("token=secret" , body ["message" ])
133- self .assertNotIn ("abc12345" , body ["message" ])
131+ self .assertEqual (body ["message" ], "Fetch intelligence source failed: internal intelligence service error" )
132+
133+ def test_fetch_source_internal_error_without_sensitive_pattern_is_generic (self ) -> None :
134+ create_resp = self .client .post ("/api/v1/intelligence/sources" , json = {"name" : "api-feed" , "url" : "https://feeds.example.com/rss.xml" , "source_type" : "rss" , "scope_type" : "market" , "market" : "cn" })
135+ self .assertEqual (create_resp .status_code , 200 )
136+ source_id = create_resp .json ()["id" ]
137+ with patch ("src.services.intelligence_service.IntelligenceService.fetch_source" , side_effect = RuntimeError ("unexpected runtime assertion failure: pipeline context exhausted" )):
138+ fetch_resp = self .client .post (f"/api/v1/intelligence/sources/{ source_id } /fetch" )
139+
140+ self .assertEqual (fetch_resp .status_code , 500 )
141+ body = fetch_resp .json ()
142+ self .assertEqual (body ["error" ], "internal_error" )
143+ self .assertEqual (body ["message" ], "Fetch intelligence source failed: internal intelligence service error" )
144+ self .assertNotIn ("pipeline context exhausted" , body ["message" ])
145+
146+ def test_create_builtin_default_sources_are_disabled_by_default (self ) -> None :
147+ default_resp = self .client .post ("/api/v1/intelligence/sources/defaults" )
148+ self .assertEqual (default_resp .status_code , 200 )
149+ newsnow_sources = [
150+ item ["source" ] for item in default_resp .json ()["items" ]
151+ if item ["source" ]["source_type" ] == "newsnow"
152+ ]
153+ self .assertGreaterEqual (len (newsnow_sources ), 5 )
154+ self .assertTrue (all (not item ["enabled" ] for item in newsnow_sources ))
134155
135156 def test_upstream_fetch_errors_do_not_expose_query_secret (self ) -> None :
136157 secret_url = "https://feeds.example.com/rss.xml?token=super-secret"
0 commit comments