kin: auto-commit after pipeline

This commit is contained in:
Gros Frumos 2026-03-17 18:26:19 +02:00
parent 40e1001cea
commit 62f0ccc292
3 changed files with 193 additions and 0 deletions

View file

@ -624,3 +624,103 @@ class TestBuildDeployStepsPythonRestartCmd:
assert steps[2] == "pm2 restart all"
assert steps[3] == "pm2 restart myservice"
assert len(steps) == 4
# ---------------------------------------------------------------------------
# 11. Migration: project_links indexes (KIN-INFRA-008)
# Convention #433: set-assert all columns/indexes after migration
# Convention #384: three test cases for conditional guard in _migrate()
# ---------------------------------------------------------------------------
def _schema_with_project_links_no_indexes():
"""Minimal schema: project_links table exists but its indexes are absent."""
import sqlite3 as _sqlite3
conn = _sqlite3.connect(":memory:")
conn.row_factory = _sqlite3.Row
conn.executescript("""
CREATE TABLE projects (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
path TEXT,
status TEXT DEFAULT 'active',
language TEXT DEFAULT 'ru',
execution_mode TEXT NOT NULL DEFAULT 'review',
project_type TEXT DEFAULT 'development'
);
CREATE TABLE tasks (
id TEXT PRIMARY KEY,
project_id TEXT NOT NULL,
title TEXT NOT NULL,
status TEXT DEFAULT 'pending'
);
CREATE TABLE project_links (
id INTEGER PRIMARY KEY AUTOINCREMENT,
from_project TEXT NOT NULL REFERENCES projects(id),
to_project TEXT NOT NULL REFERENCES projects(id),
type TEXT NOT NULL,
description TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
""")
conn.commit()
return conn
def _get_indexes(conn) -> set:
return {r[0] for r in conn.execute(
"SELECT name FROM sqlite_master WHERE type='index'"
).fetchall()}
class TestProjectLinksIndexMigration:
"""KIN-INFRA-008: индексы idx_project_links_to / idx_project_links_from."""
# --- fresh schema ---
def test_fresh_schema_has_idx_project_links_to(self):
conn = init_db(db_path=":memory:")
assert "idx_project_links_to" in _get_indexes(conn)
conn.close()
def test_fresh_schema_has_idx_project_links_from(self):
conn = init_db(db_path=":memory:")
assert "idx_project_links_from" in _get_indexes(conn)
conn.close()
# Convention #433: assert all columns of project_links after fresh init
def test_fresh_schema_project_links_columns(self):
conn = init_db(db_path=":memory:")
cols = {r["name"] for r in conn.execute("PRAGMA table_info(project_links)").fetchall()}
assert cols == {"id", "from_project", "to_project", "type", "description", "created_at"}
conn.close()
# --- Convention #384: три кейса для guard в _migrate() ---
# Кейс 1: без таблицы — guard не падает, индексы не создаются
def test_migrate_without_project_links_table_no_error(self):
conn = _old_schema_no_deploy() # project_links отсутствует
_migrate(conn) # не должно упасть
indexes = _get_indexes(conn)
assert "idx_project_links_to" not in indexes
assert "idx_project_links_from" not in indexes
conn.close()
# Кейс 2: таблица есть, индексов нет → _migrate() создаёт оба
def test_migrate_creates_both_indexes_when_table_exists(self):
conn = _schema_with_project_links_no_indexes()
_migrate(conn)
indexes = _get_indexes(conn)
assert "idx_project_links_to" in indexes
assert "idx_project_links_from" in indexes
conn.close()
# Кейс 3: таблица есть, индексы уже есть → _migrate() идемпотентен
def test_migrate_is_idempotent_when_indexes_already_exist(self):
conn = init_db(db_path=":memory:")
before = _get_indexes(conn)
_migrate(conn)
after = _get_indexes(conn)
assert "idx_project_links_to" in after
assert "idx_project_links_from" in after
assert before == after
conn.close()