Merge pull request #163 from openqj/feat-docker-timeout-evidence
feat(docker): 超时不再只剩一句 docker run timeout,留存 partial 与容器日志
This commit is contained in:
2 files changed
+132
-15
No files matched your search
@@ -218,6 +218,41 @@ class DockerCommandTestCase(unittest.TestCase):
|
||||
self.assertIn(("rm", "-f"), [(c[1], c[2]) for c in seen
|
||||
if len(c) > 2])
|
||||
|
||||
def test_timeout_keeps_partial_stdout_and_container_logs(self):
|
||||
# 旧超时路径只剩一句 'docker run timeout':TimeoutExpired
|
||||
# 自带的 partial stdout 与 kill 后抓的 docker logs 尾都
|
||||
# 被丢了。新路径:先 kill 不 rm,抓 logs,再 rm。
|
||||
seen = []
|
||||
|
||||
def fake(cmd, timeout=None):
|
||||
seen.append(list(cmd))
|
||||
if len(cmd) > 1 and cmd[1] == "run":
|
||||
exc = subprocess.TimeoutExpired(cmd, timeout)
|
||||
exc.stdout = "partial-host-output"
|
||||
exc.stderr = "partial-err"
|
||||
raise exc
|
||||
if len(cmd) > 1 and cmd[1] == "logs":
|
||||
return SimpleNamespace(returncode=0,
|
||||
stdout="container-tail-log",
|
||||
stderr="")
|
||||
return SimpleNamespace(returncode=0, stdout="", stderr="")
|
||||
|
||||
with mock.patch("cloud.sandbox.shutil.which",
|
||||
return_value="/usr/bin/docker"):
|
||||
ex = DockerExecutor("/fake/host.py", runner=fake,
|
||||
env={"XCM_API_KEY": "placeholder"},
|
||||
timeout=5)
|
||||
result = ex.dispatch_task(
|
||||
{"id": "t10", "prompt": "slow", "worktree": "/tmp/wt"})
|
||||
self.assertEqual(result["status"], "failed")
|
||||
self.assertIn("partial-host-output", result["stdout"])
|
||||
# partial 已有内容时 stdout 优先用 partial,logs 另存字段。
|
||||
self.assertEqual(result["container_log_tail"],
|
||||
"container-tail-log")
|
||||
# 顺序:kill → logs → rm,logs 必须在 rm 之前抓到。
|
||||
kinds = [c[1] for c in seen if len(c) > 1]
|
||||
self.assertLess(kinds.index("logs"), kinds.index("rm"))
|
||||
|
||||
def test_kill_container_calls_kill_and_rm(self):
|
||||
seen = []
|
||||
with mock.patch("cloud.sandbox.shutil.which",
|
||||
|
||||
Reference in new issue
Block a user