worker: cover goal docker paths with prestart stage logging

PR #145 added docker_run_* lines only to _run_in_container, but
goal/goal-resume/goal-resume-breakpoint call _call_runner directly
(to keep full stdout for goal conclusions), so the production live
test (a goal task) produced zero docker_run_ lines. Extract a
_docker_call_staged helper and route all four task paths through it;
error lines log the class name then re-raise so each caller's
kill+failed handling is unchanged.

Also fix audit attribution: audit_log has no task_id column, and
worker_exec_done/error details carried no task id, so per-task
queries missed them (the rows existed). All three exec details now
start with task_id=. Tests: 2 new goal-path stage cases + a done
detail task-id assertion (8 total in test_prestart_stages).
This commit is contained in:
host committed 2026-10-29 17:46:12 +08:00
1 parent a17f0c7412
commit 6f0eec71b6
3 files changed
+76 -28

No files matched your search

+31
View File
@@ -85,6 +85,15 @@ class PrestartStagesTestCase(unittest.TestCase):
self.assertIn("worker_exec_start", actions)
self.assertIn("worker_exec_done", actions)
self.assertNotIn("worker_exec_error", actions)
# 审计表没有任务 id 列,detail 必须自带任务 id 才能对应。
conn = sqlite3.connect(self.db_path)
try:
detail = conn.execute(
"SELECT detail FROM audit_log"
" WHERE action = 'worker_exec_done'").fetchone()[0]
finally:
conn.close()
self.assertIn("T1", detail)
def test_exec_error_audited_not_done(self):
self.worker.executor = FakeExecutor(
@@ -159,6 +168,28 @@ class DockerRunStagesTestCase(unittest.TestCase):
self.assertTrue(any("docker_run_error" in r
for r in logs.output))
def test_goal_task_stage_lines_logged(self):
# goal 路径不走 _run_in_container(直接调 runner 保完整
# stdout 结论),上一批的标记漏了这条真正在用的路径。
def runner(cmd, timeout=None, env=None):
return SimpleNamespace(returncode=0, stdout="", stderr="")
ex = self._executor(runner)
with self.assertLogs("cloud.docker", level="INFO") as logs:
ex.goal_task(self._task())
joined = "\n".join(logs.output)
self.assertIn("docker_run_start", joined)
self.assertIn("docker_run_done", joined)
def test_goal_resume_breakpoint_stage_lines_logged(self):
def runner(cmd, timeout=None, env=None):
return SimpleNamespace(returncode=0, stdout="", stderr="")
ex = self._executor(runner)
with self.assertLogs("cloud.docker", level="INFO") as logs:
ex.goal_resume_breakpoint_task(self._task())
joined = "\n".join(logs.output)
self.assertIn("docker_run_start", joined)
self.assertIn("docker_run_done", joined)
if __name__ == "__main__":
unittest.main()