kin: auto-commit after pipeline

This commit is contained in:
Gros Frumos 2026-03-17 20:21:52 +02:00
parent 35d258935a
commit e270d10832
3 changed files with 155 additions and 3 deletions

View file

@ -2342,3 +2342,102 @@ def test_get_pipeline_logs_since_id_returns_pm_entries(client):
done_log = next(log for log in logs if "PM done" in log["message"])
assert done_log["extra_json"]["steps_count"] == 2
assert done_log["extra_json"]["tokens_used"] == 1000
# ---------------------------------------------------------------------------
# KIN-103 — PATCH /api/projects/{id} — worktrees_enabled toggle
# ---------------------------------------------------------------------------
def test_patch_project_worktrees_enabled_true(client):
"""PATCH с worktrees_enabled=true → 200, поле установлено в 1."""
r = client.patch("/api/projects/p1", json={"worktrees_enabled": True})
assert r.status_code == 200
assert r.json()["worktrees_enabled"] == 1
def test_patch_project_worktrees_enabled_false(client):
"""После включения PATCH с worktrees_enabled=false → 200, поле установлено в 0."""
client.patch("/api/projects/p1", json={"worktrees_enabled": True})
r = client.patch("/api/projects/p1", json={"worktrees_enabled": False})
assert r.status_code == 200
assert r.json()["worktrees_enabled"] == 0
def test_patch_project_worktrees_enabled_true_persisted_via_sql(client):
"""После PATCH worktrees_enabled=True прямой SQL подтверждает значение 1."""
client.patch("/api/projects/p1", json={"worktrees_enabled": True})
from core.db import init_db
conn = init_db(api_module.DB_PATH)
row = conn.execute("SELECT worktrees_enabled FROM projects WHERE id = 'p1'").fetchone()
conn.close()
assert row is not None
assert row[0] == 1
def test_patch_project_worktrees_enabled_false_persisted_via_sql(client):
"""После PATCH worktrees_enabled=False прямой SQL подтверждает значение 0."""
client.patch("/api/projects/p1", json={"worktrees_enabled": True})
client.patch("/api/projects/p1", json={"worktrees_enabled": False})
from core.db import init_db
conn = init_db(api_module.DB_PATH)
row = conn.execute("SELECT worktrees_enabled FROM projects WHERE id = 'p1'").fetchone()
conn.close()
assert row is not None
assert row[0] == 0
def test_patch_project_worktrees_enabled_null_before_first_update(client):
"""Новый проект имеет worktrees_enabled=0 (DEFAULT) до первого обновления."""
client.post("/api/projects", json={"id": "p_new", "name": "New", "path": "/new"})
from core.db import init_db
conn = init_db(api_module.DB_PATH)
row = conn.execute("SELECT worktrees_enabled FROM projects WHERE id = 'p_new'").fetchone()
conn.close()
assert row is not None
assert not row[0] # DEFAULT 0 или NULL — в любом случае falsy
def test_patch_project_worktrees_enabled_get_includes_field(client):
"""GET проекта включает worktrees_enabled в ответе."""
r = client.get("/api/projects/p1")
assert r.status_code == 200
data = r.json()
assert "worktrees_enabled" in data
def test_patch_project_worktrees_enabled_and_autocommit_together(client):
"""PATCH с worktrees_enabled и autocommit_enabled → оба поля обновлены."""
r = client.patch("/api/projects/p1", json={
"worktrees_enabled": True,
"autocommit_enabled": True,
})
assert r.status_code == 200
data = r.json()
assert data["worktrees_enabled"] == 1
assert data["autocommit_enabled"] == 1
def test_patch_project_worktrees_enabled_no_change_when_not_in_patch(client):
"""PATCH без worktrees_enabled → поле не меняется."""
# Сначала установим worktrees_enabled=1
client.patch("/api/projects/p1", json={"worktrees_enabled": True})
# Потом патч без worktrees_enabled не должен его менять
r = client.patch("/api/projects/p1", json={"autocommit_enabled": True})
assert r.status_code == 200
assert r.json()["worktrees_enabled"] == 1
def test_patch_project_worktrees_enabled_toggle_sequence(client):
"""Последовательные включение/выключение worktrees_enabled."""
# Включаем
r1 = client.patch("/api/projects/p1", json={"worktrees_enabled": True})
assert r1.json()["worktrees_enabled"] == 1
# Отключаем
r2 = client.patch("/api/projects/p1", json={"worktrees_enabled": False})
assert r2.json()["worktrees_enabled"] == 0
# Снова включаем
r3 = client.patch("/api/projects/p1", json={"worktrees_enabled": True})
assert r3.json()["worktrees_enabled"] == 1