kin: auto-commit after pipeline

This commit is contained in:
Gros Frumos 2026-03-17 15:40:31 +02:00
parent f805aff86b
commit 6c2da26b6c
6 changed files with 138 additions and 10 deletions

View file

@ -2122,3 +2122,32 @@ def test_run_kin085_parallel_different_tasks_not_blocked(client):
# Запуск второй задачи должен быть успешным
r = client.post("/api/tasks/P1-002/run")
assert r.status_code == 202
# ---------------------------------------------------------------------------
# KIN-ARCH-008: test_command на уровне проекта — API
# ---------------------------------------------------------------------------
def test_patch_project_test_command(client):
"""KIN-ARCH-008: PATCH /api/projects/{id} с test_command сохраняет значение."""
r = client.patch("/api/projects/p1", json={"test_command": "pytest -v"})
assert r.status_code == 200
assert r.json()["test_command"] == "pytest -v"
def test_create_project_with_test_command(client):
"""KIN-ARCH-008: POST /api/projects с test_command сохраняет значение в БД."""
r = client.post("/api/projects", json={
"id": "p_tc",
"name": "TC Project",
"path": "/tmp/tc",
"test_command": "npm test",
})
assert r.status_code == 200
from core.db import init_db
conn = init_db(api_module.DB_PATH)
row = conn.execute("SELECT test_command FROM projects WHERE id = 'p_tc'").fetchone()
conn.close()
assert row is not None
assert row[0] == "npm test"

View file

@ -176,6 +176,43 @@ class TestRunProjectTests:
assert result["success"] is False
assert result["returncode"] == 124
def test_custom_test_command_used(self):
"""KIN-ARCH-008: _run_project_tests вызывает subprocess с переданной командой."""
from agents.runner import _run_project_tests
mock_result = MagicMock()
mock_result.returncode = 0
mock_result.stdout = "2 passed"
mock_result.stderr = ""
with patch("agents.runner.subprocess.run", return_value=mock_result) as mock_sp, \
patch("agents.runner.shutil.which", return_value=None):
_run_project_tests("/fake/path", test_command="pytest -v")
called_cmd = mock_sp.call_args[0][0]
assert called_cmd[0] == "pytest"
assert "-v" in called_cmd
def test_default_test_command_is_make_test(self):
"""KIN-ARCH-008: без test_command параметра вызывается 'make test'."""
from agents.runner import _run_project_tests
mock_result = MagicMock()
mock_result.returncode = 0
mock_result.stdout = "OK"
mock_result.stderr = ""
with patch("agents.runner.subprocess.run", return_value=mock_result) as mock_sp, \
patch("agents.runner.shutil.which", return_value=None):
_run_project_tests("/fake/path")
called_cmd = mock_sp.call_args[0][0]
assert called_cmd[0] == "make"
assert "test" in called_cmd
def test_custom_command_not_found_returns_127(self):
"""KIN-ARCH-008: кастомная команда не найдена → returncode 127."""
from agents.runner import _run_project_tests
with patch("agents.runner.subprocess.run", side_effect=FileNotFoundError), \
patch("agents.runner.shutil.which", return_value=None):
result = _run_project_tests("/fake/path", test_command="nonexistent-cmd --flag")
assert result["success"] is False
assert result["returncode"] == 127
def _mock_success(output="done"):
m = MagicMock()
@ -302,6 +339,26 @@ class TestAutoTestInPipeline:
mock_tests.assert_not_called()
@patch("agents.runner._run_autocommit")
@patch("agents.runner._run_project_tests")
@patch("agents.runner.subprocess.run")
def test_auto_test_uses_project_test_command(
self, mock_run, mock_tests, mock_autocommit, conn
):
"""KIN-ARCH-008: pipeline передаёт project.test_command в _run_project_tests."""
from agents.runner import run_pipeline
from core import models
mock_run.return_value = _mock_success()
mock_tests.return_value = {"success": True, "output": "OK", "returncode": 0}
models.update_project(conn, "vdol", auto_test_enabled=True, test_command="npm test")
steps = [{"role": "backend_dev", "brief": "implement"}]
run_pipeline(conn, "VDOL-001", steps)
mock_tests.assert_called_once()
called_test_command = mock_tests.call_args[0][1]
assert called_test_command == "npm test"
# ---------------------------------------------------------------------------
# (3) Spec-driven workflow route

View file

@ -734,3 +734,26 @@ def test_delete_attachment_returns_true(task_conn):
def test_delete_attachment_not_found_returns_false(task_conn):
"""KIN-090: delete_attachment возвращает False если запись не найдена."""
assert models.delete_attachment(task_conn, 99999) is False
# ---------------------------------------------------------------------------
# KIN-ARCH-008: test_command на уровне проекта
# ---------------------------------------------------------------------------
def test_schema_project_has_test_command_column(conn):
"""KIN-ARCH-008: таблица projects содержит колонку test_command."""
cols = {row["name"] for row in conn.execute("PRAGMA table_info(projects)")}
assert "test_command" in cols
def test_test_command_default_is_make_test(conn):
"""KIN-ARCH-008: новый проект без test_command получает дефолт 'make test'."""
p = models.create_project(conn, "prj_tc", "TC Project", "/tmp/tc")
assert p["test_command"] == "make test"
def test_test_command_can_be_set(conn):
"""KIN-ARCH-008: update_project сохраняет кастомный test_command."""
models.create_project(conn, "prj_tc2", "TC Project 2", "/tmp/tc2")
updated = models.update_project(conn, "prj_tc2", test_command="pytest -v --tb=short")
assert updated["test_command"] == "pytest -v --tb=short"