"""Интеграционные тесты бота-соавтора (нужен поднятый стенд): pytest -m stand tests/test_coauthor.py""" import json import subprocess import sys import time import pytest from perfkit import PERF_DIR, RESULTS_DIR from perfkit.manifest import load pytestmark = pytest.mark.stand def _sheet(): m = load(RESULTS_DIR / "manifest-s1.json") # соавтор - rf_coauthor, права только на листы owner=rf (FORM_1 принадлежит ССП) first = next(s for s in m.sheets if s.owner == "rf") return first def _run(*extra, timeout=30): s = _sheet() cmd = [sys.executable, "-m", "perfkit.coauthor", "--form-id", str(s.form_id), "--sheet", s.sheet, *extra] if s.direction: cmd += ["--direction", s.direction] t0 = time.monotonic() p = subprocess.run(cmd, cwd=PERF_DIR, capture_output=True, text=True, timeout=timeout) return p, time.monotonic() - t0 def test_coauthor_first_edit_echoed(): p, _ = _run("--rate", "1", "--duration", "3") assert p.returncode == 0, p.stderr stats = json.loads(p.stdout.strip().splitlines()[-1]) assert stats["echoed"] >= 1 assert stats["sent"] >= stats["echoed"] def test_coauthor_bad_token_fails_fast(): p, dt = _run("--rate", "1", "--duration", "3", "--token", "not-a-token") assert p.returncode == 2, p.stderr # 2 - нет эха первой правки (в т.ч. неверный токен) assert dt <= 5.5, f"бот завершился за {dt:.1f} с"