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)
@@ -13,6 +13,7 @@
- F1:12项资源专项测试通过,连同原生主线、桥接、生命周期累计33项通过,exit 0;真实隔离 PostgreSQL 17 完成0026旧数据→0027迁移及CRUD/助手复制/运行时解析,见database-smoke.json。
- F2:make test-backend,391项测试通过,exit 0;包含真实 Pipecat BackendLLMWorker 与模拟模型的13项Reasoner/服务主线检查、绑定指令来源、OpenCode固定agent/model/system负载及现有回归。
- F3:TypeScript、lint及4项前端契约测试通过,exit 0;lint保留既有BatchTestPage警告。生产构建并入F4。
- F4自动检查:`make test` exit 0(391项后端、4项前端契约、lint、production build、5项契约快照);隔离数据库验证通过。补齐OpenCode可选变量行为后,再次运行391项后端检查,exit 0。浏览器验收和独立审阅正在补齐。
## Deferred
- 真实模型/OpenCode联调:尚无服务地址与凭据。