fix: imagegen MCP env 必须写死本地网关 base URL
首轮生产验收失败根因:_prepare_tenant 只把 IMAGE_GEN_* 透传 进 MCP env,没写 IMAGE_GEN_BASE_URL,也没带 SUB2API_BASE_URL, 于是 imagegen.py 回落到公网 sub2.diante.me,而它不在 Tinyproxy 白名单里,API 调用 403 Filtered。 修法:worker 在写 MCP env 前用 imagegen.build_mcp_env 算好 base(显式 IMAGE_GEN_BASE_URL > SUB2API_BASE_URL),并把 网关 host 加进 NO_PROXY;组装逻辑抽成可单测 helper,新增 2 项回归测试(本地网关解析、显式 base 优先)。
This commit is contained in:
1 parent
da7b8e3a4f
commit
7a920cee59
3 files changed
+68
-16
No files matched your search
@@ -108,6 +108,31 @@ class ImageGenTests(unittest.TestCase):
|
||||
"arguments": {}}})
|
||||
self.assertEqual(resp["error"]["code"], -32602)
|
||||
|
||||
def test_build_mcp_env_resolves_local_gateway_base(self):
|
||||
# Regression: first production verification failed 403
|
||||
# Filtered because MCP env had no base URL and imagegen.py
|
||||
# fell back to the public relay domain, which is not on
|
||||
# the Tinyproxy whitelist. The local gateway origin must
|
||||
# be resolved here and land in NO_PROXY.
|
||||
env = imagegen.build_mcp_env(
|
||||
{"SUB2API_BASE_URL": "http://172.17.0.1:28084",
|
||||
"IMAGE_GEN_API_KEY": "k"},
|
||||
{"HTTP_PROXY": "http://10.20.20.1:8888",
|
||||
"NO_PROXY": "localhost,127.0.0.1"})
|
||||
self.assertEqual(env["IMAGE_GEN_BASE_URL"],
|
||||
"http://172.17.0.1:28084")
|
||||
self.assertIn("172.17.0.1", env["NO_PROXY"])
|
||||
self.assertEqual(env["IMAGE_GEN_API_KEY"], "k")
|
||||
self.assertNotIn("SUB2API_API_KEY", env)
|
||||
|
||||
def test_build_mcp_env_explicit_base_wins(self):
|
||||
env = imagegen.build_mcp_env(
|
||||
{"IMAGE_GEN_BASE_URL": "https://relay.example",
|
||||
"SUB2API_BASE_URL": "http://172.17.0.1:28084"})
|
||||
self.assertEqual(env["IMAGE_GEN_BASE_URL"],
|
||||
"https://relay.example")
|
||||
self.assertIn("relay.example", env["NO_PROXY"])
|
||||
|
||||
def test_ensure_home_seeds_and_env(self):
|
||||
home = os.path.join(self._tmp.name, "home")
|
||||
os.makedirs(home)
|
||||
|
||||
Reference in new issue
Block a user