feat: 文档/图片工具进任务镜像 + 结果截断从截断 JSON 改为提取 text 上限 20000 字
This commit is contained in:
1 parent
9ac0199eba
commit
c1d25d11b1
4 files changed
+93
-13
No files matched your search
@@ -20,7 +20,8 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(
|
||||
|
||||
from queue import TaskQueue, budget_exceeded, order_tasks, ready_tasks
|
||||
from sandbox import (CloudExecutor, DockerExecutor, Executor,
|
||||
LocalExecutor, _parse_goal_output)
|
||||
LocalExecutor, _parse_goal_output,
|
||||
_parse_host_result, _result_text)
|
||||
|
||||
|
||||
def _task(task_id, depends_on=None, priority=0, status="queued"):
|
||||
@@ -177,12 +178,38 @@ class TestExecutors(unittest.TestCase):
|
||||
self.assertEqual(result["stdout"], "boom")
|
||||
|
||||
def test_local_executor_truncates_stdout(self):
|
||||
# 20000 字上限:5000 字不再截断,25000 字截断并带标记。
|
||||
def fake_runner(cmd):
|
||||
return SimpleNamespace(returncode=0, stdout="x" * 5000)
|
||||
|
||||
result = LocalExecutor("/fake/host.py",
|
||||
runner=fake_runner).execute({"id": "t3"})
|
||||
self.assertEqual(len(result["stdout"]), 2000)
|
||||
self.assertEqual(len(result["stdout"]), 5000)
|
||||
|
||||
def long_runner(cmd):
|
||||
return SimpleNamespace(returncode=0, stdout="y" * 25000)
|
||||
|
||||
result = LocalExecutor("/fake/host.py",
|
||||
runner=long_runner).execute({"id": "t4"})
|
||||
self.assertIn("结果已截断", result["stdout"])
|
||||
self.assertTrue(result["stdout"].startswith("y" * 20000))
|
||||
|
||||
def test_result_text_extracts_long_json_text(self):
|
||||
# 2026-10-30 生产审计任务的复发:host.py JSON 的 text
|
||||
# 超过旧 2000 字截断时,存库的不能是截断的 JSON,
|
||||
# 必须是完整提取出的 text(本例 5000 字,全部保留)。
|
||||
text = "z" * 5000
|
||||
payload = json.dumps({"status": "completed", "text": text})
|
||||
result = _parse_host_result(
|
||||
"t5", SimpleNamespace(returncode=0, stdout=payload,
|
||||
stderr=""))
|
||||
self.assertEqual(result["stdout"], text)
|
||||
self.assertEqual(result["status"], "completed")
|
||||
|
||||
def test_result_text_marks_over_limit(self):
|
||||
text = "w" * 21000
|
||||
self.assertIn("结果已截断", _result_text(
|
||||
{"text": text}, "unused"))
|
||||
|
||||
def test_docker_executor_no_docker_raises_not_local(self):
|
||||
with mock.patch("sandbox.shutil.which", return_value=None):
|
||||
|
||||
Reference in new issue
Block a user