fix: make default headers opt in

This commit is contained in:
69049ed6x 2026-03-08 13:53:35 +08:00
parent 9f62a305b1
commit 360ae6d604
2 changed files with 29 additions and 1 deletions

View File

@ -7,6 +7,7 @@ from pathlib import Path
MODULE_PATH = Path(__file__).resolve().parents[1] / "tradingagents" / "agents" / "utils" / "factor_rules.py"
GRAPH_SETUP_PATH = Path(__file__).resolve().parents[1] / "tradingagents" / "graph" / "setup.py"
DEFAULT_CONFIG_PATH = Path(__file__).resolve().parents[1] / "tradingagents" / "default_config.py"
SPEC = importlib.util.spec_from_file_location("factor_rules", MODULE_PATH)
factor_rules = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(factor_rules)
@ -397,5 +398,32 @@ class GraphSetupSourceTests(unittest.TestCase):
self.assertIn('selected_analysts = ["market", "social", "news", "fundamentals", "factor_rules"]', source)
class DefaultConfigSourceTests(unittest.TestCase):
def test_default_headers_is_opt_in_none(self):
source = DEFAULT_CONFIG_PATH.read_text(encoding="utf-8")
module = ast.parse(source)
default_config_value = None
for node in module.body:
if isinstance(node, ast.Assign):
for target in node.targets:
if isinstance(target, ast.Name) and target.id == "DEFAULT_CONFIG":
default_config_value = node.value
break
self.assertIsNotNone(default_config_value)
self.assertIsInstance(default_config_value, ast.Dict)
config_map = {}
for key_node, value_node in zip(default_config_value.keys, default_config_value.values):
if isinstance(key_node, ast.Constant):
config_map[key_node.value] = value_node
self.assertIn("default_headers", config_map)
self.assertIsInstance(config_map["default_headers"], ast.Constant)
self.assertIsNone(config_map["default_headers"].value)
self.assertIn('"default_headers": None', source)
if __name__ == "__main__":
unittest.main()

View File

@ -12,7 +12,7 @@ DEFAULT_CONFIG = {
"deep_think_llm": "gpt-5.2",
"quick_think_llm": "gpt-5-mini",
"backend_url": "https://api.openai.com/v1",
"default_headers": {"User-Agent": "curl/8.0"},
"default_headers": None, # Optional HTTP headers; override per endpoint if needed
"factor_rules_path": os.getenv("TRADINGAGENTS_FACTOR_RULES_PATH", ""),
# Provider-specific thinking configuration
"google_thinking_level": None, # "high", "minimal", etc.