fix: pass search env into Docker task containers (SEARXNG_URL was lost)

Docker tasks do not inherit the worker process environment, they only
get extra_env (-e). SEARXNG_URL in the worker unit EnvironmentFile
therefore never reached codex -> MCP inside the container, so the
auto chain skipped SearXNG and only DuckDuckGo was tried (live e2e:
'all search providers failed: duckduckgo (DNS)').

_docker_task_context now merges any set SEARXNG_URL /
PERPLEXITY_API_KEY / EXA_API_KEY / TAVILY_API_KEY / BRAVE_API_KEY
from the worker environment into extra_env (values never logged;
paid keys follow the same extra_env path as gateway keys).

Tests: 2 new docker-env tests; websearch + tenant isolation = 25
passing; full cloud suite 1038 passing (4 skipped).
This commit is contained in:
host committed 2026-10-28 22:17:19 +08:00
1 parent ffeed25f50
commit d7f0f1be96
3 files changed
+66

No files matched your search

+36
View File
@@ -99,6 +99,42 @@ class WorkerWebsearchTestCase(unittest.TestCase):
self.assertEqual(config.count("[mcp_servers.websearch]"), 1)
class DockerEnvTestCase(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.db_path = os.path.join(self.tmp.name, "control.db")
init_db(self.db_path)
def tearDown(self):
self.tmp.cleanup()
def _docker_context(self):
worker = Worker(self.db_path, "/fake/host.py",
env={"XCM_API_KEY": "test-placeholder"},
tenant_isolation=False, egress_proxy_port=None)
return worker._docker_task_context({"project_id": "projA"})
def test_searxng_url_passes_into_container_env(self):
from unittest import mock
with mock.patch.dict(os.environ,
{"SEARXNG_URL": "http://searx.diante.me"}):
ok, _, _, env, err = self._docker_context()
self.assertTrue(ok)
self.assertIsNone(err)
self.assertEqual(env.get("SEARXNG_URL"), "http://searx.diante.me")
def test_no_search_env_means_no_extra_env(self):
from unittest import mock
with mock.patch.dict(os.environ, {}, clear=False):
for k in ("SEARXNG_URL", "PERPLEXITY_API_KEY", "EXA_API_KEY",
"TAVILY_API_KEY", "BRAVE_API_KEY"):
os.environ.pop(k, None)
ok, _, _, env, err = self._docker_context()
self.assertTrue(ok)
self.assertIsNone(err)
self.assertIsNone(env)
class EgressFilterTestCase(unittest.TestCase):
def test_search_domains_present_in_basic_form(self):
lines = open(REPO_ROOT / "deploy" / "egress" /