From c3314b91259bf1fa9f613ab87b1363974c11e75a Mon Sep 17 00:00:00 2001 From: Gros Frumos Date: Tue, 17 Mar 2026 16:37:42 +0200 Subject: [PATCH] kin: auto-commit after pipeline --- tests/test_watchdog.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/test_watchdog.py b/tests/test_watchdog.py index cc7ec44..44694e6 100644 --- a/tests/test_watchdog.py +++ b/tests/test_watchdog.py @@ -399,3 +399,50 @@ def test_check_parent_alive_process_lookup_error_aborts(conn): task = models.get_task(conn, "VDOL-001") assert task["status"] == "blocked" assert str(dead_ppid) in (task.get("blocked_reason") or "") + + +# --------------------------------------------------------------------------- +# KIN-OBS-019: регрессионные тесты через inspect.getsource() — decision #367 +# --------------------------------------------------------------------------- + +def test_watchdog_source_has_no_sqlite3_connect(): + """Регрессия: watchdog не должен содержать прямой вызов sqlite3.connect() (decision #367).""" + import core.watchdog as wd + source = inspect.getsource(wd) + assert "sqlite3.connect" not in source, ( + "REGRESSION: core/watchdog.py содержит sqlite3.connect() — " + "должен использовать get_connection() из core.db" + ) + + +def test_watchdog_source_has_no_explicit_process_lookup_error(): + """Регрессия: watchdog не должен явно упоминать ProcessLookupError (decision #357). + + Обработка мёртвых процессов унифицирована через OSError + errno.ESRCH. + """ + import core.watchdog as wd + source = inspect.getsource(wd) + assert "ProcessLookupError" not in source, ( + "REGRESSION: core/watchdog.py явно использует ProcessLookupError — " + "должен использовать OSError + errno.ESRCH" + ) + + +def test_check_dead_pipelines_kill_succeeds_no_change(tmp_path): + """os.kill успешно (нет исключения) → процесс жив, статус задачи не меняется.""" + fake_pid = 54323 + db_path, task_id, pipeline_id = _db_with_running_pipeline(tmp_path, fake_pid) + + # os.kill returns None (no exception) — process is alive + with patch("core.watchdog.os.kill", return_value=None): + _check_dead_pipelines(db_path) + + conn = init_db(db_path=str(db_path)) + task = models.get_task(conn, task_id) + pipeline_row = conn.execute( + "SELECT status FROM pipelines WHERE id=?", (pipeline_id,) + ).fetchone() + conn.close() + + assert task["status"] != "blocked" + assert pipeline_row["status"] == "running"