fix: preserve optional task instruction variables for OpenCode

This commit is contained in:
Xin Wang
2026-10-24 09:23:32 +08:00
parent 7db737d161
commit 7600a297b3
3 changed files with 10 additions and 4 deletions
@@ -82,8 +82,12 @@ class OpenCodeExecutor:
if self.config.get("model_provider_id") and self.config.get("model_id"):
payload["model"] = {"providerID": self.config["model_provider_id"], "modelID": self.config["model_id"]}
backend = self.config.get("_backend") or {}
from models import AssistantConfig
from services.runtime_variables import DynamicVariableStore
store = DynamicVariableStore(self.config.get("_variables") or {})
store = DynamicVariableStore.from_config(AssistantConfig(
dynamic_variables=self.config.get("_variables") or {},
dynamic_variable_definitions=self.config.get("_variable_definitions") or {},
))
assistant_instructions = store.render(str(backend.get("instructions") or ""))
instructions = "\n\n".join(value for value in (self.config.get("instructions"), assistant_instructions) if value)
if instructions:
+4 -3
View File
@@ -36,7 +36,7 @@ class OpenCodeTaskTest(unittest.IsolatedAsyncioTestCase):
self.assertEqual(payload["messageID"], "msg_test")
self.assertEqual(payload["agent"], "build")
self.assertEqual(payload["model"], {"providerID": "test-provider", "modelID": "test-model"})
self.assertEqual(payload["system"], "通用说明\n\n项目 demo")
self.assertEqual(payload["system"], "通用说明\n\n项目 demo;可选信息:")
submitted = True
return httpx.Response(204)
if request.url.path.endswith("/message"):
@@ -48,8 +48,9 @@ class OpenCodeTaskTest(unittest.IsolatedAsyncioTestCase):
raise AssertionError(request.url)
executor = OpenCodeExecutor({"url": "https://remote.test", "directory": "/workspace/demo", "agent": "build",
"model_provider_id": "test-provider", "model_id": "test-model",
"instructions": "通用说明", "_backend": {"instructions": "项目 {{project}}"},
"_variables": {"project": "demo"}}, {}, transport=httpx.MockTransport(respond))
"instructions": "通用说明", "_backend": {"instructions": "项目 {{project}};可选信息:{{optional}}"},
"_variables": {"project": "demo"},
"_variable_definitions": {"optional": {"type": "string", "required": False}}}, {}, transport=httpx.MockTransport(respond))
async def emit(event):
updates.append(event)
result = await executor.run(handle, "修复测试", emit)