Compare commits
33 Commits
docs/ORCH-
...
1f0929838a
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f0929838a | |||
| 7deb151ce5 | |||
| aff334e82b | |||
| fa9b96545c | |||
| 319b23b4fc | |||
| e54d1fc4ac | |||
| 77abfb399c | |||
| 05bd169b14 | |||
|
|
183e6d68bc | ||
|
|
befa2979ec | ||
|
|
d33e0ded2e | ||
| de70ee811d | |||
|
|
41da03470a | ||
| e1055861b5 | |||
| 2e84813c13 | |||
| 18f887c886 | |||
| 37ef58f21f | |||
| 0b9ae514c9 | |||
| c56672aabf | |||
| 0ed05417e6 | |||
| 7d99782673 | |||
| 59603f6e92 | |||
| d5f11e5caa | |||
| affbb259a1 | |||
|
|
9979eec168 | ||
| c991b9de1a | |||
| 3d7d751b7a | |||
| f330a580c4 | |||
| 896ecf6acb | |||
| 096c452230 | |||
| 9f176036f1 | |||
| 3e4191050f | |||
| 38e329f6f7 |
52
.env.example
52
.env.example
@@ -12,11 +12,25 @@ ORCH_GITEA_WEBHOOK_SECRET=
|
||||
ORCH_CLAUDE_BIN=/usr/bin/claude
|
||||
ORCH_REPOS_DIR=/home/slin/repos
|
||||
ORCH_DB_PATH=/app/data/orchestrator.db
|
||||
# ORCH-042: live-tracker mode. edit (DEFAULT) -> the task card is edited in place
|
||||
# (editMessageText). bump -> on every update the old card is deleted and a fresh
|
||||
# one is sent silently to the BOTTOM of the chat (deleteMessage + sendMessage +
|
||||
# repoint). One card per task in both modes. Any value other than "bump" -> edit.
|
||||
ORCH_TRACKER_MODE=edit
|
||||
# ORCH-042/ORCH-067: live-tracker mode. bump (DEFAULT since ORCH-067) -> on every
|
||||
# update the old card is deleted and a fresh one is sent silently to the BOTTOM of
|
||||
# the chat (deleteMessage + sendMessage + repoint), so the current status is always
|
||||
# the last message in an active chat. edit -> the task card is edited in place
|
||||
# (editMessageText). One card per task in both modes. Any value other than "bump"
|
||||
# (incl. empty/garbage) -> edit.
|
||||
ORCH_TRACKER_MODE=bump
|
||||
# ORCH-067: best-effort live-overlay for the card status line. The offline core
|
||||
# (stage -> Plane status, In Review from the brd-clock) always works without network;
|
||||
# the overlay only fills in branches indistinguishable offline (Needs Input / Blocked /
|
||||
# Rejected / Cancelled / Deploying / Monitoring after Deploy) by reading the LIVE Plane
|
||||
# status with a short timeout + per-issue TTL cache. It NEVER blocks the pipeline and
|
||||
# NEVER raises.
|
||||
# LIVE_STATUS -> kill-switch (false -> offline core only).
|
||||
# LIVE_STATUS_TTL_S -> TTL (seconds) of the per-issue live-uuid cache (hot-path guard).
|
||||
# LIVE_STATUS_TIMEOUT_S -> timeout (seconds) of a single live-GET on the render path.
|
||||
ORCH_TRACKER_LIVE_STATUS=true
|
||||
ORCH_TRACKER_LIVE_STATUS_TTL_S=60
|
||||
ORCH_TRACKER_LIVE_STATUS_TIMEOUT_S=3
|
||||
# ORCH-043: merge-gate (auto-rebase onto current origin/main + re-test + merge-lock)
|
||||
# on the deploy-staging -> deploy edge. Deterministic sub-gate (no LLM) that catches
|
||||
# the branch up to the CURRENT origin/main, re-tests it, and serialises merges so two
|
||||
@@ -36,6 +50,27 @@ ORCH_MERGE_RETEST_TARGET=tests/
|
||||
ORCH_MERGE_LOCK_TIMEOUT_S=300
|
||||
ORCH_MERGE_DEFER_DELAY_S=60
|
||||
ORCH_MERGE_DEFER_MAX_ATTEMPTS=5
|
||||
# ORCH-071/073: merge-verify under-gate on the `deploy -> done` edge (врезка in
|
||||
# advance_stage, NOT a new STAGE_TRANSITIONS edge / registered QG). A deterministic
|
||||
# merge-actor merges the feature code-PR via the Gitea PR-merge API (never push/
|
||||
# force-push to main), then `done` is allowed ONLY when the deployed SHA is proven an
|
||||
# ancestor of origin/main (ORCH-073 FR-1: SHA-in-main is the single criterion; a
|
||||
# merged PR alone no longer confirms). A secondary regression guard then checks a
|
||||
# declarative marker set (MAIN_REGRESSION_MARKERS) is still in origin/main; a missing
|
||||
# marker -> alert + HOLD (NOT done), a git error of the grep itself -> fail-open.
|
||||
# MERGE_VERIFY_ENABLED -> global kill-switch (false -> strictly pre-ORCH-071).
|
||||
# MERGE_VERIFY_REPOS -> CSV of repos where the under-gate is REAL; empty ->
|
||||
# only the self-hosting repo (orchestrator); non-self -> no-op.
|
||||
# MERGE_PR_TIMEOUT_S -> per Gitea list/merge HTTP call timeout.
|
||||
# MERGE_VERIFY_TIMEOUT_S -> git fetch/merge-base timeout for the ancestor + marker checks.
|
||||
# REGRESSION_GUARD_ENABLED -> kill-switch for the ORCH-073 main-integrity regression
|
||||
# guard (false -> SHA-in-main alone gates done); reuses the
|
||||
# merge-verify scope, so non-self repos are a no-op.
|
||||
ORCH_MERGE_VERIFY_ENABLED=true
|
||||
ORCH_MERGE_VERIFY_REPOS=
|
||||
ORCH_MERGE_PR_TIMEOUT_S=60
|
||||
ORCH_MERGE_VERIFY_TIMEOUT_S=60
|
||||
ORCH_REGRESSION_GUARD_ENABLED=true
|
||||
# ORCH-036: executable self-deploy of the `deploy` stage. For the self-hosting repo
|
||||
# (orchestrator) the stage REALLY restarts prod (8500) via a detached host hook;
|
||||
# deploy_status: SUCCESS means proven health-ok, not an LLM declaration. Three
|
||||
@@ -199,3 +234,10 @@ ORCH_POST_DEPLOY_FAIL_THRESHOLD=3
|
||||
ORCH_POST_DEPLOY_5XX_THRESHOLD=0.5
|
||||
ORCH_POST_DEPLOY_AUTO_ROLLBACK=false
|
||||
ORCH_POST_DEPLOY_BASE_URL=http://localhost:8500
|
||||
|
||||
# ── QG-0 entry validation (ORCH-069) ──────────────────────────────────────────
|
||||
# Upper title-length limit for the QG-0 entry gate (_qg0_errors). The old 80-char
|
||||
# cap was a hygiene limit, not structural (slug is cut to [:30] independently, the
|
||||
# DB title TEXT is unbounded). Default 200. An invalid/empty value gracefully
|
||||
# degrades to 200 (the process never crashes on startup).
|
||||
ORCH_QG0_TITLE_MAX=200
|
||||
|
||||
@@ -50,3 +50,6 @@ ORCH_QUEUE_POLL_INTERVAL=2.0
|
||||
DEPLOY_SSH_USER=slin
|
||||
DEPLOY_SSH_HOST=127.0.0.1
|
||||
DEPLOY_HOOK_SCRIPT=/home/slin/bin/enduro-deploy-hook.sh
|
||||
|
||||
# QG-0 entry title-length limit (ORCH-069). Default 200; invalid/empty -> 200.
|
||||
ORCH_QG0_TITLE_MAX=200
|
||||
|
||||
13
.gitattributes
vendored
Normal file
13
.gitattributes
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# ORCH-073 (ADR-001 Р-5 / FR-4): union merge for the append-only changelog.
|
||||
#
|
||||
# CHANGELOG.md is append-only at the top (## [Unreleased]). Without a merge driver,
|
||||
# two branches that both add an Unreleased entry collide on auto_rebase_onto_main
|
||||
# (merge_gate), which rolls the branch back to `development` and can drag in stale
|
||||
# neighbouring code (a phantom-merge amplifier — see ADR-001 root cause #3). The
|
||||
# built-in `union` driver keeps BOTH sides' lines instead of conflicting, so both
|
||||
# changelog entries survive and the branch is not rolled back.
|
||||
#
|
||||
# Scope is INTENTIONALLY limited to CHANGELOG.md: `union` only suits strictly
|
||||
# append-only files. docs/**/*.md (README, ADR, internals) are rewritten line-by-line,
|
||||
# where `union` would silently duplicate edited lines — so they are NOT included.
|
||||
CHANGELOG.md merge=union
|
||||
File diff suppressed because one or more lines are too long
16
CLAUDE.md
16
CLAUDE.md
@@ -41,6 +41,22 @@ created → analysis → architecture → development → review → testing →
|
||||
## Статусная модель Plane (ORCH-066) — индикация ≠ управление
|
||||
Статусы Plane — это **слой B (индикация)**, отдельный от **слоя A (машина стадий)** `src/stages.py::STAGE_TRANSITIONS`. Plane показывает наблюдателю осмысленную картину (`Backlog → Todo → Analysis → Architecture → Development → Code-Review → Testing → Awaiting Deploy → Deploying → Monitoring after Deploy → Done` + человеческие гейты `In Review/Approved`, `Confirm Deploy`), но НИКОГДА не управляет конвейером. Маппинг и сеттеры — `src/plane_sync.py` (6 новых ключей: `to_analyse/analysis/code_review/awaiting_deploy/deploying/monitoring`), с project-relative alias-fallback: на частично сконфигурированном проекте новый ключ деградирует на базовый UUID ТОГО ЖЕ проекта (нулевая регрессия для enduro-trails). Детали — `docs/architecture/README.md`.
|
||||
|
||||
## Нотификации / Telegram live-tracker (ORCH-042/066/067)
|
||||
Каждая задача = **одна карточка** в Telegram (`src/notifications.py`). Поведение карточки:
|
||||
- **Дефолт `tracker_mode` — `bump`** (ORCH-067; `edit` доступен через `ORCH_TRACKER_MODE=edit`).
|
||||
`bump` на каждом обновлении удаляет старую карточку и шлёт свежую вниз чата (тихо), `edit`
|
||||
редактирует на месте. Инвариант «одна карточка на задачу» — в обоих режимах.
|
||||
- **Статус-строка карточки** (`📍 <status_label>`) показывает текущий Plane-статус по модели
|
||||
ORCH-066 (`plane_status_label`). Оффлайн-ядро (`stage → статус`, In Review из brd-clock)
|
||||
работает всегда без сети; best-effort live-overlay (kill-switch `tracker_live_status`,
|
||||
TTL-кэш, короткий таймаут) лишь дорисовывает ветки, неотличимые offline (Needs Input /
|
||||
Blocked / Rejected / Cancelled / Deploying / Monitoring) и **никогда не блокирует конвейер**.
|
||||
- **Кликабельный номер задачи** (`plane_issue_link`) — `ORCH-NNN` в карточке И во всех
|
||||
уведомлениях (`notify_*`, alert'ы стадий) рендерится как `<a href=…>` на issue в Plane;
|
||||
fail-safe → просто `html.escape(номер)`, если ссылку построить нельзя. Никогда не падает.
|
||||
- Транспорт (`send_telegram`/`edit_telegram`/`delete_telegram`), `disable_notification`
|
||||
(карточка тихая, пингуют только alert-хелперы), схема БД — не трогаются.
|
||||
|
||||
## Конвенции
|
||||
- Conventional Commits (`feat:`, `fix:`, `docs:`, `refactor:`, `test:`)
|
||||
- Ветки: `feature/ORCH-NNN-slug`, `fix/ORCH-NNN-slug`
|
||||
|
||||
@@ -136,6 +136,7 @@ uvicorn src.main:app --reload --port 8500
|
||||
| `ORCH_RECONCILE_GRACE_OVERRIDES_JSON` | Per-stage пороги, напр. `{"development":300}` | `""` |
|
||||
| `ORCH_RECONCILE_NOTIFY_UNBLOCK` | Telegram при разблокировке застрявшей задачи | `true` |
|
||||
| `ORCH_RECONCILE_SKIP_BLOCKED_ENABLED` | F-1 Guard 2 (ORCH-060): пропуск задач в Plane-статусе Blocked / Needs Input; `false` глушит только сетевой Guard 2 (Guard 1 escalated всегда активен) | `true` |
|
||||
| `ORCH_QG0_TITLE_MAX` | Верхний лимит длины заголовка QG-0 (вход `_qg0_errors`); невалидное/пустое значение → дефолт (ORCH-069) | `200` |
|
||||
|
||||
## Очередь задач (ORCH-1 / F-2b)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
- **Queue** (`src/queue_worker.py`, ORCH-1) — персистентная очередь задач (SQLite `jobs`), atomic claim, max_concurrency, ретраи, restart-safe.
|
||||
- **Job-reaper** (`src/job_reaper.py`, ORCH-065 — [adr-0011](adr/adr-0011-job-reaper-lease-reclaim.md)) — фоновый daemon-поток (каркас `reconciler`), стартует/останавливается в `main.lifespan` (после `reconciler.start()` / перед `worker.stop()`). Детектирует «мёртвый» `running`-job **без рестарта** процесса (Tier-1 мёртвый `jobs.pid` после `reaper_dead_ticks` тиков; Tier-2 `agent_runs.exit_code` записан, а job ещё `running`; Tier-3 backstop `reaper_max_running_s`) и приводит строку к корректному статусу через те же контракты (`_try_advance_stage`/`_finalize_job`, gate-driven; exit≠0/неизвестно → `attempts<max`→`queued`, иначе `failed`+Telegram). Атомарный reap-claim (guard `status='running'`) совместим со стартовым `requeue_running_jobs`. Тот же поток периодически делает проактивный реклейм stale/dead merge-lease (см. ниже). never-raise; kill-switch `ORCH_REAPER_ENABLED`; снимок в `GET /queue` (блок `reaper`).
|
||||
- **Reconciler** (`src/reconciler.py`, ORCH-053 — реализовано, [adr-0007](adr/adr-0007-reconciler.md)) — фоновый daemon-поток (паттерн `queue_worker`), стартует/останавливается в `main.lifespan` (после `worker.start()` / перед `worker.stop()`). Реконсилирует рассинхрон «источник истины ≠ стадия задачи» при потерянном webhook. F-1 gate-side (продвигает застрявшую стадию по локальной БД через штатный `advance_stage(..., finished_agent=None)`), F-2 plane-side (опрос Plane API → `handle_*` из `plane.py`), F-3 (БД-fallback `sha→branch` в `handle_ci_status`). Источник истины — гейт/Plane, не событие; идемпотентность (active-job guard + atomic-claim + grace); kill-switch `ORCH_RECONCILE_ENABLED`. `analysis` F-1 не трогает (человеческий гейт). F-1 также пропускает escalated (retry≥лимита) и Blocked/Needs-Input задачи (ORCH-060). Наблюдаемость — блок `reconcile` в `GET /queue`.
|
||||
- **Notifications / Live-tracker** (`src/notifications.py`, ORCH-042/ORCH-067) — ОДНА live-карточка на задачу (`update_task_tracker`), обновляется на каждом переходе. Режим `ORCH_TRACKER_MODE` (дефолт `bump` с ORCH-067: delete+silent send+repoint внизу чата; `edit` — правка на месте). Карточка несёт строку Plane-статуса `📍 …` (оффлайн-ядро `plane_status_label` + best-effort live-overlay `_live_plane_branch_override`, kill-switch `ORCH_TRACKER_LIVE_STATUS`) и кликабельный номер задачи (`plane_issue_link`/`link_for` → ссылка в Plane, fail-safe на сырой номер). Все алерты, упоминающие `work_item_id`, делают номер кликабельным. Контракт всего компонента — never raises; карточка всегда silent. Детали — [internals.md](internals.md) §7.
|
||||
- **Project Registry** (`src/projects.py`, ORCH-6) — Plane project id → repo + prefix; фильтрация вебхуков по проекту.
|
||||
- **Plane Sync** (`src/plane_sync.py`) — синхронизация статусов/комментариев в Plane. Резолв статусов проекта `get_project_states` (ORCH-10) кэширует `{logical_key→uuid}` per-project; **ORCH-068** добавляет в кэш-запись `{uuid→group}` (для терминал-исключения F-2) и **TTL** `ORCH_PLANE_STATES_TTL_S` (дефолт 300с; `0` → прежний lifetime-кэш) — устаревший набор статусов самозалечивается без рестарта процесса через существующий `reload_project_states()` (баг кэша после появления нового Plane-статуса). Форма возврата `get_project_states` неизменна (обратная совместимость).
|
||||
|
||||
@@ -139,25 +140,44 @@ merge-в-main вообще**. Detached host-деплой лишь retag'ал о
|
||||
- **Merge в Phase C (после рестарта), НЕ в Phase B** — finalizer restart-surviving (claim воркером
|
||||
нового контейнера, re-drive reaper'ом), merge физически строго ПОСЛЕ рестарта прода → рестарт его
|
||||
не убивает (G3 «шаг, переживающий рестарт»; постмортем-урок №3).
|
||||
- **Merge-актор `merge_gate.merge_pr`** — `pr_already_merged` (no-op повтор, ORCH-065) → иначе
|
||||
Gitea `POST /repos/{owner}/{repo}/pulls/{index}/merge`. Никогда push/force-push в `main`.
|
||||
- **Верификатор `merge_gate.verify_merged_to_main`** — `PR.merged==true` ИЛИ
|
||||
`git merge-base --is-ancestor <validated_sha> origin/main` (`validated_revision` — тот же якорь,
|
||||
что у ORCH-058). never-raise → `False`.
|
||||
- **Merge-актор `merge_gate.merge_pr`** — `pr_already_merged` (idempotency no-op повтор) → иначе
|
||||
Gitea `POST /repos/{owner}/{repo}/pulls/{index}/merge`. Выбор PR строго по `head.ref==branch`
|
||||
И `base.ref=="main"`. Никогда push/force-push в `main`.
|
||||
- **Верификатор `merge_gate.verify_merged_to_main` (семантика ORCH-073, FR-1):** подтверждение —
|
||||
**ТОЛЬКО** `git merge-base --is-ancestor <validated_sha> origin/main` (`validated_revision` —
|
||||
якорь ORCH-058). PR-флаг `pr_already_merged` **больше НЕ подтверждает merge** (удалён из verify):
|
||||
он понижен до idempotency-guard `merge_pr` и засчитывает merged PR лишь при `head.ref==branch`
|
||||
И `base.ref=="main"` (исключает авто docs-PR). Пустой SHA / git-ошибка → `False` (fail-closed),
|
||||
never-raise.
|
||||
- **Регресс-гард целостности `main` (ORCH-073, FR-5):** `merge_gate.check_main_regression` в
|
||||
`_handle_merge_verify` ПОСЛЕ подтверждённого SHA-в-main и ДО `done` проверяет, что `origin/main`
|
||||
содержит декларативный набор маркеров ранее-merged задач (`MAIN_REGRESSION_MARKERS`,
|
||||
`git grep -c <marker> origin/main -- <path>` > 0). Маркер отсутствует → alert «main regressed» +
|
||||
HOLD (НЕ `done`, ALERT-only). Fail-open на git-ошибке грепа (регресс — только при `count==0`).
|
||||
Kill-switch `regression_guard_enabled`; non-self → no-op. Набор — append-only константа,
|
||||
значимая задача дописывает свой маркер.
|
||||
- **Не подтверждено → alert «deploy succeeded but not merged» (Telegram+Plane) + HOLD**
|
||||
(`set_issue_blocked`, задача НЕ `done`, БЕЗ авто-отката на `development` — not-merged есть
|
||||
инфра-дефект, реакция ALERT-only как ORCH-021 self-hosting). Подтверждено → штатный `deploy →
|
||||
done` + `merged_to_main: true` во frontmatter `14-deploy-log.md` (`deploy_status:` нетронут).
|
||||
- **Защита от CHANGELOG-затирания (ORCH-073, FR-4):** корневой `.gitattributes` с
|
||||
`CHANGELOG.md merge=union` → правки `## [Unreleased]` авто-сливаются при `auto_rebase_onto_main`
|
||||
без конфликта, ветка не откатывается в `development` и не тащит устаревший код-сосед. `docs/**`
|
||||
под union НЕ ставится (union только для append-only).
|
||||
- **Условность как ORCH-35/43/58:** `merge_verify_enabled` (kill-switch, дефолт `true`) +
|
||||
`merge_verify_repos` (пусто → только self-hosting); non-self — no-op, merge остаётся за `deployer`.
|
||||
never-raise; идемпотентность (`pr_already_merged`, INV-5); ручной approve сохранён (`Confirm Deploy`).
|
||||
never-raise; идемпотентность по **SHA-в-main** (INV-4, не «любой merged PR»); ручной approve
|
||||
сохранён (`Confirm Deploy`).
|
||||
- **Инварианты:** `STAGE_TRANSITIONS`, `check_deploy_status`/`_parse_deploy_status`, реестр
|
||||
`QG_CHECKS` (под-гейт — врезка в `advance_stage`, НЕ новый зарегистрированный QG), схема БД,
|
||||
БАГ-8, terminal-sync, merge-gate, image-freshness, exit-коды хука — **без изменений**.
|
||||
Диагностика фантома — runbook `docs/operations/PHANTOM_MERGE_RUNBOOK.md` (4 проверки постмортема).
|
||||
|
||||
Подробнее: [adr-0013](adr/adr-0013-merge-verify-gate.md), детально —
|
||||
`docs/work-items/ORCH-071/06-adr/ADR-001-merge-verify-gate.md`.
|
||||
Подробнее: [adr-0013](adr/adr-0013-merge-verify-gate.md) +
|
||||
[adr-0014](adr/adr-0014-merge-verify-sha-source-of-truth.md) (amends 0013 — SHA-в-main как
|
||||
единственный критерий + регресс-гард, ORCH-073); детально —
|
||||
`docs/work-items/ORCH-071/06-adr/ADR-001-merge-verify-gate.md`,
|
||||
`docs/work-items/ORCH-073/06-adr/ADR-001-merge-verify-sha-truth-and-regression-guard.md`.
|
||||
|
||||
### Post-deploy наблюдение прода + реакция на деградацию (ORCH-021 — реализовано)
|
||||
Конвейер заканчивался на `deploy → done` и **забывал про прод**: «успех» = health-check
|
||||
|
||||
@@ -17,11 +17,15 @@ Per-work-item решения живут в `docs/work-items/<id>/06-adr/ADR-NNN-
|
||||
| adr-0009 | Толерантность staging-вердикта к инфраструктурным FAIL | accepted | 2026-06-07 | ORCH-061 |
|
||||
| adr-0010 | Post-deploy мониторинг прода + реакция на деградацию | proposed | 2026-06-07 | ORCH-021 |
|
||||
| adr-0011 | Job-reaper + проактивный реклейм merge-lease | accepted | 2026-06-07 | ORCH-065 |
|
||||
| adr-0012 | Security-гейт (secrets/deps) | accepted | 2026-06-08 | ORCH-022 |
|
||||
| adr-0013 | Merge-в-main + пост-деплой верификация как условие `done` | accepted | 2026-06-08 | ORCH-071 |
|
||||
| adr-0014 | SHA-в-main — единственный критерий merge-verify + регресс-гард | accepted | 2026-06-08 | ORCH-073 |
|
||||
|
||||
> ⚠️ Историческая коллизия: номер `0007` занят двумя файлами —
|
||||
> `adr-0007-reconciler.md` (ORCH-053) и `adr-0007-executable-self-deploy.md`
|
||||
> (ORCH-036). Оба accepted; для новых сквозных ADR использовать следующий
|
||||
> свободный номер (текущий максимум — `0011`).
|
||||
> свободный номер (текущий максимум — `0014`).
|
||||
> adr-0014 **amends** adr-0013 (меняет критерий merge-verify на «SHA-в-main»).
|
||||
|
||||
## Формат
|
||||
**Контекст → Решение → Альтернативы → Последствия → Связи.** Статус: proposed / accepted / superseded.
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
# adr-0014: SHA-в-main — единственный критерий merge-verify + регресс-гард целостности `main`
|
||||
|
||||
- **Статус:** accepted
|
||||
- **Дата:** 2026-06-08
|
||||
- **Задача:** ORCH-073 (BUG CRITICAL — эрозия `main`)
|
||||
- **Amends:** [adr-0013](adr-0013-merge-verify-gate.md) (ORCH-071) — меняет КРИТЕРИЙ подтверждения merge.
|
||||
- **Детальный ADR:** `docs/work-items/ORCH-073/06-adr/ADR-001-merge-verify-sha-truth-and-regression-guard.md`
|
||||
- **Постмортем:** `docs/history/LESSONS_2026-06-08_phantom-merge.md`
|
||||
|
||||
## Контекст
|
||||
|
||||
adr-0013 (ORCH-071) ввёл под-гейт merge-verify на ребре `deploy → done`, но допускал
|
||||
подтверждение merge по **ИЛИ-критерию**: `verify_merged_to_main` возвращал `True`, если
|
||||
`pr_already_merged(repo, branch)` **ЛИБО** SHA — предок `origin/main`. `pr_already_merged`
|
||||
засчитывал **любой** merged PR ветки, включая авто docs-PR (staging/deploy-логи). У одной
|
||||
feature-ветки в `main` сливались только docs-PR, а code-PR — нет → `pr_already_merged`=`True` →
|
||||
verify `CONFIRMED` → `done`, хотя кода в `main` не было. Накопительно потеряны ORCH-067 (ссылки
|
||||
`plane_issue_link`) и ORCH-069 (`qg0_title_max`). Вторичный усилитель — CHANGELOG-ребейзы,
|
||||
откатывающие ветку и тащащие устаревший код-сосед. Восстановление кода (G1) выполнено вручную
|
||||
restore-PR #76; этот ADR устраняет корень навсегда.
|
||||
|
||||
## Решение
|
||||
|
||||
1. **SHA-в-main — единственный критерий (FR-1).** `verify_merged_to_main(repo, branch, sha)`
|
||||
подтверждает merge **ТОЛЬКО** прямым фактом `git merge-base --is-ancestor <sha> origin/main`
|
||||
(после `git fetch origin main`). OR-ветка `pr_already_merged` **удалена** из верификатора.
|
||||
Пустой `sha` / любая git-ошибка → `False` (fail-closed: alert + HOLD). never-raise (INV-1).
|
||||
2. **`pr_already_merged` → idempotency-guard, различающий code-PR/docs-PR (FR-2).** Засчитывает
|
||||
merged PR только при `head.ref==<feature-branch>` И `base.ref=="main"` (явный фильтр в цикле,
|
||||
не ненадёжный query-параметр `head`). Используется лишь как защита `merge_pr` от второго merge,
|
||||
НЕ как подтверждение `done`.
|
||||
3. **`merge_pr` сливает именно code-ветку (FR-3).** Выбор открытого PR по `head.ref==branch` И
|
||||
`base.ref=="main"`; merge только Gitea `POST /pulls/{index}/merge`, никогда push/force-push в
|
||||
`main`. Источник истины «слилось» — FR-1.
|
||||
4. **Регресс-гард целостности `main` (FR-5).** Новая `merge_gate.check_main_regression`,
|
||||
вызываемая в `_handle_merge_verify` ПОСЛЕ подтверждённого SHA-в-main и ДО `done`: проверяет, что
|
||||
`origin/main` содержит **декларативный набор маркеров** ключевых функций ранее-merged задач
|
||||
(`git grep -c <marker> origin/main -- <path>` > 0). Маркер отсутствует → **alert «main
|
||||
regressed» + HOLD** (НЕ `done`, БЕЗ авто-отката на `development` — инфра-дефект, ALERT-only как
|
||||
ORCH-021/071). Набор — append-only константа `MAIN_REGRESSION_MARKERS` в `merge_gate.py`
|
||||
(расширяется каждой значимой задачей). **Fail-open** на git-ошибке самого грепа (регресс
|
||||
утверждается только при детерминированном `count==0`); первичный фейл-клозед — SHA-в-main.
|
||||
Kill-switch `regression_guard_enabled` (дефолт `true`); non-self → no-op.
|
||||
5. **`.gitattributes CHANGELOG.md merge=union` (FR-4).** В корне репо; авто-слияние правок
|
||||
`## [Unreleased]` без конфликта → `auto_rebase_onto_main` не откатывает ветку и не тащит
|
||||
устаревший код-сосед. `docs/**/*.md` под union **НЕ** ставится (union только для append-only;
|
||||
доки переписываются построчно).
|
||||
|
||||
## Инварианты
|
||||
|
||||
never-raise на verify/merge/регресс-гарде (ошибка → alert/HOLD, не падение); прод 8500 не
|
||||
рестартится/не падает в рамках merge; merge только Gitea PR-API без force-push в `main`; ручной
|
||||
`Confirm Deploy` (ORCH-059) сохранён; идемпотентность по «SHA-в-main», а не по «любому merged PR»;
|
||||
non-self репо (enduro) — merge/verify/регресс-гард без изменений. `STAGE_TRANSITIONS`, реестр
|
||||
`QG_CHECKS`, `check_deploy_status`, схема БД, внешние HTTP-эндпоинты — **без изменений**.
|
||||
|
||||
## Альтернативы
|
||||
|
||||
- Сохранить PR-флаг как со-критерий verify (с фильтром head/base) — отклонено: PR можно слить и
|
||||
тут же откатить ребейзом-соседом; надёжен только факт «SHA в main».
|
||||
- `docs/**/*.md merge=union` — отклонено: тихая дубликация строк в переписываемых доках.
|
||||
- Регресс-гард с авто-откатом / хранением маркеров в БД/Plane — отклонено (Не-цель «не менять
|
||||
схему БД/Plane»; реакция ALERT-only).
|
||||
- Fail-closed на marker-grep — отклонено: ложный HOLD при git-сбое; marker-grep вторичен.
|
||||
|
||||
## Последствия
|
||||
|
||||
Невозможно «`done` + прод задеплоен, а code-PR не в `main`». Ложно-зелёный по docs-PR устранён в
|
||||
корне. CHANGELOG-конфликты больше не откатывают ветку. Регресс соседнего кода ловится отдельным
|
||||
гардом. Минус: при недоступной Gitea/git verify консервативно `False` → возможен ложный HOLD+alert
|
||||
(снимается повтором; fail-closed для `done` приоритетен). Набор маркеров требует дисциплины —
|
||||
значимая задача дописывает свой маркер.
|
||||
|
||||
## Связи
|
||||
|
||||
- Amends adr-0013 (ORCH-071), наследует adr-0006 (merge-gate), adr-0011 (job-reaper/lease).
|
||||
- Детально: `docs/work-items/ORCH-073/06-adr/ADR-001-merge-verify-sha-truth-and-regression-guard.md`.
|
||||
@@ -111,12 +111,12 @@ claude.exe --print --system-prompt --allowedTools Read,Write,Edit,Bash
|
||||
|
||||
Вместо ~15 отдельных сообщений на задачу оркестратор держит **ОДНУ** live-карточку на задачу (`update_task_tracker`), которая обновляется на каждом переходе стадии. Текст рендерится статически из БД (`render_task_tracker`: стадии, токены, стоимость, BRD-подтверждение, итоги). Карточка всегда тихая (`disable_notification=True`); отдельные пинги шлют только `notify_approve_requested` / `notify_error`. `message_id` хранится в `tasks.tracker_message_id`; helpers `get_tracker_message_id` / `set_tracker_message_id`. Контракт всего компонента — **never raises**.
|
||||
|
||||
**Режимы (ORCH-042, `ORCH_TRACKER_MODE` → `Settings.tracker_mode`).** Резолвится в `update_task_tracker` (case-insensitive, trim); всё, что ≠ `"bump"` (включая пустое/мусор/None), трактуется как `edit` → нулевая регрессия и безопасный фолбэк. Инвариант «одна карточка на задачу» сохраняется в обоих режимах.
|
||||
**Режимы (ORCH-042, `ORCH_TRACKER_MODE` → `Settings.tracker_mode`; дефолт переключён `edit → bump` в ORCH-067).** Резолвится в `update_task_tracker` (case-insensitive, trim); всё, что ≠ `"bump"` (включая пустое/мусор/None), трактуется как `edit` → безопасный фолбэк. Инвариант «одна карточка на задачу» сохраняется в обоих режимах.
|
||||
|
||||
| Режим | Поведение при обновлении |
|
||||
|-------|--------------------------|
|
||||
| `edit` (дефолт) | первый вызов → `send_telegram` (тихо) + сохранение `message_id`; далее → `edit_telegram` на сохранённый id. Новое сообщение шлётся ТОЛЬКО при `EDIT_GONE` (удалено/старше 48ч/невалидный id). `EDIT_NOT_MODIFIED` / `EDIT_FAILED` → нового сообщения нет (анти-дубль). |
|
||||
| `bump` | карточка пересоздаётся внизу чата: best-effort `delete_telegram(старый_id)` → `send_telegram(text, disable_notification=True)` → `set_tracker_message_id(new_id)` **только** при успешном send (`new_mid is not None`). За один вызов — не более одного нового сообщения. |
|
||||
| `bump` (дефолт, ORCH-067) | карточка пересоздаётся внизу чата: best-effort `delete_telegram(старый_id)` → `send_telegram(text, disable_notification=True)` → `set_tracker_message_id(new_id)` **только** при успешном send (`new_mid is not None`). За один вызов — не более одного нового сообщения. Живая карточка всегда «догоняет» переписку. |
|
||||
| `edit` | первый вызов → `send_telegram` (тихо) + сохранение `message_id`; далее → `edit_telegram` на сохранённый id. Новое сообщение шлётся ТОЛЬКО при `EDIT_GONE` (удалено/старше 48ч/невалидный id). `EDIT_NOT_MODIFIED` / `EDIT_FAILED` → нового сообщения нет (анти-дубль). |
|
||||
|
||||
**`delete_telegram(message_id) -> bool`** (low-level, never raises). Семантика возврата — «исчезло ли старое сообщение»:
|
||||
- `ok:true` → `True`;
|
||||
@@ -128,6 +128,12 @@ claude.exe --print --system-prompt --allowedTools Read,Write,Edit,Bash
|
||||
|
||||
**Текст карточки (оба режима, ORCH-042):** метка `Подтверждение BRD` (была «Ревью БРД»); после прохождения approve-gate строка BRD начинается с ✅ (ветка ожидания сохраняет ⏸️/⏳); русские display-labels стадий (`Анализ / Архитектура / Разработка / Код ревью / Тестирование / Внедрение`); финальная строка `📦 Внедрено` (было `deployed`). Меняются только отображаемые строки — ключи стадий и имена агентов (завязаны на `_STAGE_ACTIVE_AGENT`, `last_done`, БД) не трогаются.
|
||||
|
||||
**Строка Plane-статуса и кликабельный номер (ORCH-067, слой B — индикация).** Под заголовком карточка несёт строку `📍 <Plane-статус>` по модели ORCH-066. Источник — двухслойный, контракт **never raises**:
|
||||
- **Оффлайн-ядро** `plane_status_label(task_row)` — чистая функция БЕЗ сети: `stage → статус` (`created→To Analyse`, `analysis→Analysis`, `architecture→Architecture`, `development→Development`, `review→Code-Review`, `testing→Testing`, `deploy→⏸️ Awaiting Deploy`, `done→Done`) + `⏸️ In Review` из brd-часов (`brd_review_started_at` задан, `…_ended_at` пуст). Неизвестная/битая стадия → безопасный дефолт `To Analyse`.
|
||||
- **Live-overlay** `_live_plane_branch_override` — best-effort: дорисовывает ветви-статусы, неразличимые оффлайн (Needs Input / Blocked / Rejected / Cancelled / Deploying / Monitoring after Deploy), чтением живого Plane-статуса (`fetch_issue_state` с коротким `tracker_live_status_timeout_s`, TTL-кэш `tracker_live_status_ttl_s`, kill-switch `tracker_live_status`). Любой сбой / выключенный флаг / нехватка данных → оффлайн-метка; `⏸️ In Review` (авторитет brd-часов) overlay не консультирует. Анти-false-positive: `deploying/monitoring`, алиасящие базовый UUID на проекте без выделенного статуса (enduro), не вызывают override.
|
||||
|
||||
**Кликабельный номер задачи (ORCH-067).** Номер в заголовке карточки И во всех уведомлениях орка, где упоминается `work_item_id`, — HTML-ссылка на issue в Plane через общий `plane_issue_link` / `link_for` (URL строит `_plane_issue_url` с loopback/workspace/project-гардами, переиспользуя резолв ORCH-017). Fail-safe: при нехватке любого из (web-base/не-loopback, workspace, project_id, plane_issue_id) → `html.escape(work_item_id)` без `<a>`; динамические части экранируются, `<a>`-разметка валидна под `parse_mode=HTML`. Алерты `stage_engine`/`launcher`/`security_gate`/`reconciler` переведены на `link_for` (резолвит `repo`+`plane_issue_id` из БД по `task_id` или `work_item_id`).
|
||||
|
||||
## Database Schema
|
||||
|
||||
```sql
|
||||
|
||||
7
docs/work-items/ORCH-067/00-business-request.md
Normal file
7
docs/work-items/ORCH-067/00-business-request.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Business Request: [высокий] Telegram tracker: bump + статусы Plane + кликабельный номер задачи
|
||||
|
||||
Work Item ID: ORCH-067
|
||||
|
||||
## Description
|
||||
|
||||
TBD
|
||||
158
docs/work-items/ORCH-067/01-brd.md
Normal file
158
docs/work-items/ORCH-067/01-brd.md
Normal file
@@ -0,0 +1,158 @@
|
||||
# BRD — ORCH-067: Telegram tracker (bump + статусы Plane + кликабельный номер задачи)
|
||||
|
||||
Work Item: **ORCH-067**
|
||||
Тип: **Багфикс + enhancement**
|
||||
Приоритет: высокий
|
||||
Компонент: Telegram live-tracker и уведомления оркестратора (`src/notifications.py`)
|
||||
Расширяет: открытый баг seq=55 («bump не сработал, регресс ORCH-042»)
|
||||
|
||||
---
|
||||
|
||||
## 1. Бизнес-контекст и проблема
|
||||
|
||||
Оркестратор ведёт по одной «живой карточке» (live-tracker) на каждую задачу в Telegram
|
||||
(`src/notifications.py`). Карточка тихо обновляется на каждом переходе стадии, а отдельными
|
||||
пингами шлются только события, требующие внимания владельца (approve-gate, деплой-фейл,
|
||||
падение агента, ошибка задачи).
|
||||
|
||||
Сейчас есть четыре боли:
|
||||
|
||||
1. **bump не работает в проде.** Диагностика оператора: код режима `bump` в
|
||||
`update_task_tracker` корректен (delete старого → sendMessage вниз → repoint
|
||||
`tracker_message_id`), НО в проде `tracker_mode="edit"` (дефолт `src/config.py:408`),
|
||||
а `ORCH_TRACKER_MODE=bump` не выставлен. Карточка обновляется edit-in-place и остаётся
|
||||
«вверху» ленты, тонет под новыми сообщениями — наблюдатель не видит актуального
|
||||
состояния без скролла.
|
||||
|
||||
2. **Карточка показывает внутренние названия стадий, а не Plane-статусы.** После ввода
|
||||
осмысленной статусной модели Plane (ORCH-066) карточка по-прежнему рендерит внутренние
|
||||
ярлыки стадий (Анализ/Архитектура/…), а текущий статус задачи в терминах, понятных
|
||||
наблюдателю в Plane (To Analyse → Analysis → In Review → … → Done), в шапке карточки
|
||||
не отражён. Особенно теряется состояние **ожидания согласования BRD** = Plane-статус
|
||||
`In Review`: сейчас это лишь строка «✅/⏸️ Подтверждение BRD … ⏳», не выраженная как
|
||||
полноценный статус.
|
||||
|
||||
3. **Номер задачи в карточке некликабелен.** `ORCH-066` в карточке — обычный текст;
|
||||
чтобы открыть задачу в Plane, наблюдателю приходится искать её вручную.
|
||||
|
||||
4. **Номер задачи некликабелен и во всех остальных уведомлениях орка** (approve-requested,
|
||||
QG-fail, deploy SUCCESS/FAIL, Needs Input, прод-деплой и т. п.) — везде, где упоминается
|
||||
`work_item_id`, это просто текст.
|
||||
|
||||
## 2. Цель
|
||||
|
||||
Сделать live-tracker и уведомления орка наблюдаемыми «из коробки»:
|
||||
- bump работает по умолчанию (карточка падает вниз свежим сообщением при каждом обновлении,
|
||||
ровно одна карточка на задачу, без спама и дублей);
|
||||
- карточка явно показывает текущий Plane-статус по модели ORCH-066, включая человеческие
|
||||
гейты (`⏸️ In Review` — согласование BRD, `⏸️ Awaiting Deploy` — ожидание Confirm Deploy,
|
||||
`❓ Needs Input` — нужны уточнения);
|
||||
- номер задачи кликабелен в карточке и во всех Telegram-уведомлениях орка и ведёт на
|
||||
страницу задачи в Plane.
|
||||
|
||||
## 3. Заинтересованные стороны
|
||||
|
||||
- **Owner (Слава)** — основной потребитель карточки и уведомлений; источник 4 требований.
|
||||
- **Агенты конвейера** — косвенно (карточка отражает их прогресс; поведение агентов не меняется).
|
||||
- **Другие проекты (enduro-trails)** — общий инстанс/БД; изменения не должны вызывать регресс.
|
||||
|
||||
## 4. Объём работ (scope)
|
||||
|
||||
### 4.1. Требование 1 — bump по умолчанию
|
||||
- Режим `bump` должен быть поведением по умолчанию: при каждом обновлении карточка
|
||||
удаляется и пересоздаётся внизу ленты, одна карточка на задачу, тихо
|
||||
(`disable_notification`), без дублей.
|
||||
- Инвариант «одна карточка на задачу» сохраняется в обоих режимах (`edit` остаётся как
|
||||
опция через env).
|
||||
- Транзиентный фейл `send` не должен обнулять `tracker_message_id` и плодить дубли
|
||||
(инвариант уже заложен в коде — сохранить).
|
||||
|
||||
### 4.2. Требование 2 — статусы карточки как в Plane (модель ORCH-066)
|
||||
- В шапке/верхней части карточки явно отображается **текущий Plane-статус** задачи по
|
||||
модели ORCH-066.
|
||||
- Полный маппинг состояний (имена — финальные из модели ORCH-066):
|
||||
```
|
||||
To Analyse → Analysis → In Review (⏸️ ожидание согласования BRD) → Architecture →
|
||||
Development → Code-Review → Testing → Awaiting Deploy (⏸️ ожидание Confirm Deploy) →
|
||||
Deploying → Monitoring after Deploy → Done
|
||||
```
|
||||
Ветки: `Needs Input` (аналитик задал вопросы), `Blocked`, `Rejected`, `Cancelled`.
|
||||
- Человеческие гейты отражаются как ПОЛНОЦЕННЫЕ статусы с паузой:
|
||||
- согласование BRD → «⏸️ In Review — ожидание согласования BRD»;
|
||||
- ожидание прод-деплоя → «⏸️ Awaiting Deploy — ожидание Confirm Deploy»;
|
||||
- вопросы аналитика → «❓ Needs Input — нужны уточнения».
|
||||
- Существующая семантика строки «Подтверждение BRD» сохраняется (время ожидания/«твоё
|
||||
время»), но статус карточки при этом явно показывает In Review (approve-pending).
|
||||
|
||||
### 4.3. Требование 3 — кликабельный номер задачи в карточке
|
||||
- `work_item_id` (напр. `ORCH-066`) в карточке — гиперссылка на страницу задачи Plane:
|
||||
`https://<PLANE_WEB_BASE>/<workspace_slug>/projects/<project_id>/issues/<issue_id>/`.
|
||||
- Источники частей URL:
|
||||
- `PLANE_WEB_BASE` — из конфигурации (env, поле `plane_web_url` / `ORCH_PLANE_WEB_URL`;
|
||||
значение прод — `plane.mva154.duckdns.org`); fail-safe: не задан → номер без ссылки;
|
||||
- `workspace_slug` — `plane_workspace_slug` (уже есть в settings, прод — `ag_proj`);
|
||||
- `project_id` — резолвится per-task по репозиторию задачи (ORCH / Sandbox);
|
||||
- `issue_id` (UUID) — из БД: колонка `tasks.plane_issue_id`.
|
||||
- Рендер через `<a href="...">ORCH-NNN</a>` (`parse_mode=HTML` уже включён);
|
||||
HTML в title/тексте экранируется, чтобы не сломать разметку.
|
||||
|
||||
### 4.4. Требование 4 — кликабельный номер во ВСЕХ уведомлениях орка
|
||||
- Единый хелпер (напр. `plane_issue_link(work_item_id, plane_issue_id, project_id) -> html`)
|
||||
строит кликабельный номер с fail-safe; применяется во всех точках `send_telegram`/
|
||||
`notify_*`, где упоминается `work_item_id` (approve-requested, QG-fail, deploy
|
||||
SUCCESS/FAIL, Needs Input, прод-деплой, alert'ы launcher/merge_gate/job_reaper/
|
||||
security_gate/reconciler/main).
|
||||
|
||||
## 5. Вне объёма (out of scope)
|
||||
|
||||
- Транспорт `send_telegram` / `edit_telegram` / `delete_telegram` (parse_mode HTML уже есть) — не трогать.
|
||||
- Инвариант «одна карточка на задачу» — не нарушать (не плодить дубли).
|
||||
- Логика `disable_notification` (карточка тихая; пингуют только alert-хелперы) — не трогать.
|
||||
- `STAGE_TRANSITIONS`, Quality Gates, схема БД — НЕ менять.
|
||||
- Изменение поведения агентов/конвейера.
|
||||
|
||||
## 6. Зависимости
|
||||
|
||||
- Маппинг статусов (требование 2) опирается на статусную модель ORCH-066. ORCH-066 уже в
|
||||
конвейере на стадии deploy. Эту задачу делать ПОСЛЕ прода ORCH-066, чтобы имена статусов
|
||||
совпали. Если ORCH-066 ещё не в проде на момент разработки — использовать согласованные
|
||||
финальные имена из модели: To Analyse, Analysis, Code-Review, Awaiting Deploy, Deploying,
|
||||
Monitoring after Deploy, In Review, Needs Input, Blocked, Cancelled, Done.
|
||||
- Конфигурация `plane_web_url` / `plane_workspace_slug` уже существует в `src/config.py`
|
||||
(ORCH-017); реестр проектов `src/projects.py` (`get_project_by_repo().plane_project_id`)
|
||||
уже даёт per-task project_id.
|
||||
|
||||
## 7. Fail-safe (обязательно)
|
||||
|
||||
- Нет `PLANE_WEB_BASE` / нет `plane_issue_id` / нет `project_id` / loopback-база →
|
||||
показывать номер БЕЗ ссылки, **не падать**.
|
||||
- HTML-экранирование пользовательского текста (title и пр.) во всех сообщениях с
|
||||
`parse_mode=HTML`.
|
||||
- Bump: транзиентный фейл `send` не обнуляет `tracker_message_id` и не плодит дубли.
|
||||
- Любая ошибка построения статуса/ссылки никогда не должна ронять рендер карточки или
|
||||
отправку уведомления (degrade gracefully).
|
||||
|
||||
## 8. Критерии успеха (Definition of Done)
|
||||
|
||||
- Bump работает из коробки: карточка падает вниз при обновлении, одна на задачу.
|
||||
- Карточка показывает Plane-статус новой модели, включая `⏸️ In Review` (согласование BRD),
|
||||
`⏸️ Awaiting Deploy`, `❓ Needs Input`.
|
||||
- Номер задачи кликабелен в карточке И во всех уведомлениях орка (ведёт на страницу Plane).
|
||||
- Fail-safe покрыт тестами (нет URL/plane_id/project → без ссылки, не падает;
|
||||
HTML-экранирование).
|
||||
- `pytest tests/ -q` зелёный.
|
||||
- Документация обновлена в том же PR: `CLAUDE.md` (раздел нотификаций/tracker),
|
||||
`CHANGELOG.md`, ADR per-work-item.
|
||||
|
||||
## 9. Риски
|
||||
|
||||
- **Регресс enduro-trails.** Смена дефолта `tracker_mode` на bump меняет поведение для всех
|
||||
проектов. Митигация: bump уже реализован и протестирован концептуально; инвариант «одна
|
||||
карточка» сохранён; env-переключатель `edit` остаётся.
|
||||
- **Поломка HTML-разметки** при неэкранированном title → сообщение не доставится. Митигация:
|
||||
обязательное `html.escape` + тесты.
|
||||
- **Источник «истинного» Plane-статуса** для веток, не выводимых из `tasks.stage`
|
||||
(Needs Input/Blocked/Rejected/Cancelled, Deploying/Monitoring), при запрете на изменение
|
||||
схемы БД — архитектурное решение (ADR), с обязательным fail-safe (без сети не падать).
|
||||
- **Self-hosting.** Орк правит сам себя; обязательна страховка через staging (8501) перед
|
||||
прод-деплоем; прод-контейнер не ронять в рамках задачи.
|
||||
205
docs/work-items/ORCH-067/02-trz.md
Normal file
205
docs/work-items/ORCH-067/02-trz.md
Normal file
@@ -0,0 +1,205 @@
|
||||
# ТЗ — ORCH-067: Telegram tracker (bump + статусы Plane + кликабельный номер задачи)
|
||||
|
||||
Work Item: **ORCH-067**
|
||||
Документ описывает КОНКРЕТНЫЕ изменения кода/конфигурации/тестов и документации.
|
||||
Архитектурные развилки помечены `[ARCH]` — решение принимает архитектор (ADR), здесь
|
||||
зафиксированы только требования и ограничения к ним.
|
||||
|
||||
---
|
||||
|
||||
## 0. Задействованные модули `src/`
|
||||
|
||||
| Модуль | Роль в задаче |
|
||||
|---|---|
|
||||
| `src/config.py` | Дефолт `tracker_mode`; поле `plane_web_url`/`plane_workspace_slug` (уже есть). |
|
||||
| `src/notifications.py` | Основные изменения: bump-дефолт, статус-строка карточки, хелпер ссылки, применение хелпера в `notify_*`. |
|
||||
| `src/plane_sync.py` | Источник имён статусов/маппинга ORCH-066 (`_PLANE_NAME_TO_KEY`, `_STAGE_TO_STATE_KEY`); при необходимости reverse-map UUID→имя `[ARCH]`. |
|
||||
| `src/projects.py` | `get_project_by_repo(repo).plane_project_id` — per-task project_id для ссылки. |
|
||||
| `src/db.py` | Чтение `tasks.plane_issue_id`, `tasks.repo` (без изменений схемы). |
|
||||
| `src/stage_engine.py`, `src/agents/launcher.py`, `src/merge_gate.py`, `src/job_reaper.py`, `src/security_gate.py`, `src/reconciler.py`, `src/main.py` | Точки `send_telegram`, где есть `work_item_id` — применить хелпер ссылки (требование 4). |
|
||||
|
||||
Изменения API (HTTP endpoints) — **нет**. Изменения схемы БД — **нет**. Новые QG checks — **нет**.
|
||||
|
||||
---
|
||||
|
||||
## 1. Требование 1 — bump по умолчанию
|
||||
|
||||
### 1.1. Изменение
|
||||
- `src/config.py` (~стр. 408): сменить дефолт
|
||||
`tracker_mode: str = "edit"` → `tracker_mode: str = "bump"`.
|
||||
- Обновить docstring-комментарий рядом (ORCH-042): отметить, что **дефолт теперь `bump`**,
|
||||
`edit` остаётся доступен через `ORCH_TRACKER_MODE=edit`.
|
||||
|
||||
### 1.2. Без изменений (сохранить инвариант)
|
||||
- Логика `update_task_tracker` (`src/notifications.py`, ветка `if mode == "bump"`):
|
||||
`delete_telegram(old)` best-effort → `send_telegram(text, disable_notification=True)` →
|
||||
`set_tracker_message_id` ТОЛЬКО при `new_mid is not None`. Не менять.
|
||||
- `send_telegram`/`edit_telegram`/`delete_telegram` — не трогать.
|
||||
|
||||
### 1.3. Прод-аспект
|
||||
- Для прод-инстанса орка можно дополнительно выставить `ORCH_TRACKER_MODE=bump` в `.env`
|
||||
на хосте (как страховку), но код должен работать «из коробки» и без env. Канон env —
|
||||
`.env.example` (обновить, если там фигурирует tracker_mode).
|
||||
|
||||
---
|
||||
|
||||
## 2. Требование 2 — статус-строка карточки по модели ORCH-066
|
||||
|
||||
### 2.1. Новый чистый хелпер маппинга
|
||||
Добавить в `src/notifications.py` функцию, возвращающую отображаемый Plane-статус для
|
||||
карточки на основе доступных данных задачи. Сигнатура (ориентир):
|
||||
```python
|
||||
def plane_status_label(task_row) -> str:
|
||||
"""Вернуть строку текущего Plane-статуса для шапки карточки (с emoji).
|
||||
Никогда не падает: на неизвестном входе -> разумный дефолт по stage."""
|
||||
```
|
||||
Хелпер обязан быть чистым/детерминированным от входных данных и **никогда не бросать**
|
||||
исключения (любая ошибка → дефолт по `stage`, рендер карточки не ломается).
|
||||
|
||||
### 2.2. Маппинг внутреннее состояние → Plane-статус (обязательные строки)
|
||||
Имена статусов — финальные из модели ORCH-066 (см. `_PLANE_NAME_TO_KEY` в `plane_sync.py`).
|
||||
|
||||
| Источник (данные задачи в БД) | Plane-статус (отображение в карточке) |
|
||||
|---|---|
|
||||
| `stage == "created"` | `To Analyse` |
|
||||
| `stage == "analysis"`, BRD-clock не запущен | `Analysis` |
|
||||
| `stage == "analysis"`, `brd_review_started_at` есть, `brd_review_ended_at` пуст | `⏸️ In Review — ожидание согласования BRD` |
|
||||
| `stage == "architecture"` | `Architecture` |
|
||||
| `stage == "development"` | `Development` |
|
||||
| `stage == "review"` | `Code-Review` |
|
||||
| `stage == "testing"` | `Testing` |
|
||||
| `stage == "deploy"` (ожидание Confirm Deploy) | `⏸️ Awaiting Deploy — ожидание Confirm Deploy` |
|
||||
| `stage == "done"` | `Done` |
|
||||
|
||||
Ветки (Needs Input / Blocked / Rejected / Cancelled / Deploying / Monitoring after Deploy):
|
||||
- `❓ Needs Input — нужны уточнения` — состояние «аналитик задал вопросы»;
|
||||
- `Blocked`, `Rejected`, `Cancelled`, `Deploying`, `Monitoring after Deploy`.
|
||||
|
||||
`[ARCH]` **Источник сигнала для веток, не выводимых из `tasks.stage`** (Needs Input,
|
||||
Blocked, Rejected, Cancelled, Deploying, Monitoring after Deploy):
|
||||
- запрещено менять схему БД (нельзя добавлять колонку-флаг);
|
||||
- варианты для архитектора: (а) best-effort чтение живого Plane-статуса
|
||||
(`fetch_issue_state` + reverse-map UUID→имя через `get_project_states`/
|
||||
`_PLANE_NAME_TO_KEY`) с обязательным fail-safe (нет сети/ответа → деградация на
|
||||
stage-маппинг, без задержки, блокирующей конвейер); (б) только stage-выводимые статусы,
|
||||
а ветки — по уже имеющимся сигналам (например, In Review через brd-clock).
|
||||
- ОБЯЗАТЕЛЬНО к покрытию (DoD): `⏸️ In Review`, `⏸️ Awaiting Deploy`, `❓ Needs Input`.
|
||||
In Review полностью выводится из brd-clock (см. таблицу) и должен работать без сети.
|
||||
|
||||
### 2.3. Встраивание в `render_task_tracker`
|
||||
- В `render_task_tracker` (`src/notifications.py`) добавить в шапку/верх карточки отдельную
|
||||
СТРОКУ статуса (под заголовком `🛠️ ORCH-NNN · <title>` / над разделителем `bar`),
|
||||
напр.: `📍 <status_label>`.
|
||||
- Существующие строки по стадиям (`✅ done` / `🔄 active`), строка «Подтверждение BRD»,
|
||||
тоталы токенов/стоимости, done-строка с PR/⏱️ — СОХРАНИТЬ (семантику не ломать).
|
||||
- Семантика строки «Подтверждение BRD» (⏸️+⏳ при ожидании, ✅ при пройденном гейте)
|
||||
сохраняется; новая статус-строка дублирует её смысл в терминах Plane-статуса.
|
||||
|
||||
---
|
||||
|
||||
## 3. Требование 3 + 4 — кликабельный номер задачи
|
||||
|
||||
### 3.1. Единый хелпер
|
||||
Добавить в `src/notifications.py`:
|
||||
```python
|
||||
def plane_issue_link(work_item_id, plane_issue_id=None, project_id=None, repo=None) -> str:
|
||||
"""Вернуть HTML с кликабельным номером задачи (<a href=...>ORCH-NNN</a>),
|
||||
либо просто html.escape(work_item_id), если ссылку построить нельзя.
|
||||
Никогда не падает."""
|
||||
```
|
||||
Поведение:
|
||||
- База URL: `settings.plane_web_url` → fallback `settings.plane_api_url`; loopback-база
|
||||
(`localhost`/`127.0.0.1`/…) трактуется как «нет web URL» (переиспользовать
|
||||
`_is_loopback_base`).
|
||||
- `workspace_slug`: `settings.plane_workspace_slug`.
|
||||
- `project_id`: явный аргумент → иначе резолв по `repo` через
|
||||
`get_project_by_repo(repo).plane_project_id`.
|
||||
- `issue_id`: `plane_issue_id` (UUID из `tasks.plane_issue_id`).
|
||||
- URL-шаблон: `{web_base}/{workspace}/projects/{project_id}/issues/{issue_id}/`.
|
||||
- Текст ссылки = `html.escape(work_item_id)`; `href` = `html.escape(url, quote=True)`.
|
||||
- **Fail-safe:** если не хватает любого из (`web_base` валидный/не loopback, `workspace`,
|
||||
`project_id`, `plane_issue_id`) → вернуть `html.escape(work_item_id)` (номер без ссылки).
|
||||
- Логика построения URL уже существует в `_build_plane_issue_link` (ORCH-017) — допустимо
|
||||
переиспользовать/обобщить её, разнеся «текст-ссылки = номер» и «текст-ссылки = `✅ Задача
|
||||
в Plane`», чтобы не дублировать резолв проекта и loopback-guard.
|
||||
|
||||
### 3.2. Применение в карточке (требование 3)
|
||||
- В `render_task_tracker` заголовок строится из `work_item_id`. Заменить
|
||||
`html.escape(work_item_id)` в обоих вариантах заголовка (done / not-done) на
|
||||
`plane_issue_link(work_item_id, plane_issue_id, repo=repo)` — номер становится
|
||||
кликабельным.
|
||||
- Для этого `render_task_tracker` должен дополнительно выбрать из БД `repo` и
|
||||
`plane_issue_id` (расширить существующий `SELECT` по `tasks`). Схему НЕ менять — колонки
|
||||
уже есть.
|
||||
- `title` уже экранируется (`html.escape(title)`) — сохранить.
|
||||
|
||||
### 3.3. Применение во всех уведомлениях (требование 4)
|
||||
Во всех точках `send_telegram`/`notify_*`, где в тексте есть `work_item_id`, заменить
|
||||
«сырой» номер на `plane_issue_link(...)`. Перечень точек (из `src`):
|
||||
- `src/notifications.py`: `notify_approve_requested`, `notify_error`
|
||||
(и любые будущие notify_* с work_item_id);
|
||||
- `src/stage_engine.py`: все `send_telegram(...)` с `work_item_id`
|
||||
(≈ строки 613, 672, 719, 776, 820, 916, 971, 1057, 1134, 1192, 1228, 1257, 1355, 1367,
|
||||
1425, 1447, 1601 — проверить каждую: применять ТОЛЬКО где упоминается номер задачи);
|
||||
- `src/agents/launcher.py`: deploy-failed alert (≈685–686), agent-failed alert (≈698–699),
|
||||
alert ≈821–822;
|
||||
- `src/merge_gate.py` (≈431–432);
|
||||
- `src/job_reaper.py` (≈395–396);
|
||||
- `src/security_gate.py` (≈673–674);
|
||||
- `src/reconciler.py` (≈449);
|
||||
- `src/main.py` (≈45–47).
|
||||
|
||||
`[ARCH]` Способ доступа к `plane_issue_id`/`project_id` в каждой точке (часто там уже есть
|
||||
`work_item_id`, но не обязательно `plane_issue_id`): хелпер должен уметь резолвить
|
||||
недостающее по `repo`/БД, оставаясь fail-safe. Допустимо добавить тонкую обёртку, которая по
|
||||
`work_item_id`/`task_id` достаёт `repo`+`plane_issue_id` из БД и зовёт `plane_issue_link`
|
||||
(аналогично существующему `_get_task_link_fields`). Везде, где данных нет — деградация на
|
||||
просто номер, без падения.
|
||||
|
||||
### 3.4. HTML-экранирование
|
||||
- `parse_mode=HTML` уже стоит в `send_telegram`/`edit_telegram`. Любой пользовательский
|
||||
текст (title, описания, причины QG-fail, сообщения об ошибках), попадающий в сообщение с
|
||||
ссылками, должен экранироваться `html.escape`, чтобы не сломать `<a>`-разметку.
|
||||
|
||||
---
|
||||
|
||||
## 4. Конфигурация
|
||||
|
||||
- `plane_web_url` (env `ORCH_PLANE_WEB_URL`) — уже существует (`src/config.py`), значение
|
||||
прод — `plane.mva154.duckdns.org` (схему `https://` учесть при сборке URL).
|
||||
Дополнительных полей конфигурации не требуется.
|
||||
- `tracker_mode` — сменить дефолт на `bump` (раздел 1).
|
||||
- Обновить `.env.example`, если в нём фигурируют `ORCH_TRACKER_MODE` / `ORCH_PLANE_WEB_URL`
|
||||
(канон секретов/настроек — `.env.example`, не коммитить реальные секреты).
|
||||
|
||||
---
|
||||
|
||||
## 5. Артефакты pipeline, которые должны быть созданы/обновлены
|
||||
|
||||
- `docs/work-items/ORCH-067/06-adr/ADR-NNN-*.md` — архитектурное решение (минимум: источник
|
||||
«истинного» Plane-статуса для веток при запрете изменения схемы БД; дефолт bump; единый
|
||||
хелпер ссылки).
|
||||
- `CLAUDE.md` — раздел про нотификации/tracker (дефолт bump; статус-строка карточки;
|
||||
кликабельный номер в карточке и уведомлениях).
|
||||
- `CHANGELOG.md` — запись ORCH-067.
|
||||
- `docs/architecture/README.md` — при необходимости синхронизировать описание tracker'а.
|
||||
|
||||
---
|
||||
|
||||
## 6. Ограничения (что НЕ трогать)
|
||||
|
||||
- Транспорт `send_telegram`/`edit_telegram`/`delete_telegram`.
|
||||
- Инвариант «одна карточка на задачу».
|
||||
- Логику `disable_notification` (карточка тихая; пингуют только alert-хелперы).
|
||||
- `STAGE_TRANSITIONS`, Quality Gates, схему БД.
|
||||
- Поведение агентов/конвейера.
|
||||
|
||||
---
|
||||
|
||||
## 7. Замечания по самохостингу
|
||||
|
||||
Орк правит сам себя в проде (общий инстанс/БД с enduro-trails):
|
||||
- НЕ перезапускать прод-контейнер `orchestrator` в рамках задачи.
|
||||
- Обязательная страховка через `deploy-staging` (8501) до прод-деплоя.
|
||||
- Смена дефолта `tracker_mode` затрагивает ВСЕ проекты — проверить отсутствие регресса для
|
||||
enduro-trails (тесты + staging-наблюдение карточки).
|
||||
129
docs/work-items/ORCH-067/03-acceptance-criteria.md
Normal file
129
docs/work-items/ORCH-067/03-acceptance-criteria.md
Normal file
@@ -0,0 +1,129 @@
|
||||
# Acceptance Criteria — ORCH-067
|
||||
|
||||
Work Item: **ORCH-067**
|
||||
Каждый критерий формулирует чёткое условие PASS/FAIL. Привязка к тестам — в `04-test-plan.yaml`.
|
||||
|
||||
---
|
||||
|
||||
## Группа A — Bump по умолчанию (Требование 1)
|
||||
|
||||
### AC-1 — дефолт tracker_mode = bump
|
||||
- **PASS:** `Settings().tracker_mode == "bump"` без выставленного env `ORCH_TRACKER_MODE`.
|
||||
- **FAIL:** дефолт остался `"edit"` или иное.
|
||||
|
||||
### AC-2 — bump-поведение: одна карточка падает вниз
|
||||
- **PASS:** при втором (и последующем) вызове `update_task_tracker` для задачи с уже
|
||||
сохранённым `tracker_message_id` вызывается `delete_telegram(old_id)` (best-effort),
|
||||
затем `send_telegram(...)` с `disable_notification=True`, затем `set_tracker_message_id`
|
||||
на новый id. В чате остаётся ровно одна карточка на задачу.
|
||||
- **FAIL:** карточка редактируется на месте при дефолте; либо появляются дубли; либо новая
|
||||
карточка отправляется со звуком (`disable_notification` не True).
|
||||
|
||||
### AC-3 — bump fail-safe: транзиентный фейл send не обнуляет указатель
|
||||
- **PASS:** если `send_telegram` вернул `None` (нет креды/транзиентный фейл),
|
||||
`tracker_message_id` НЕ перезаписывается в `None` и дубликат в рамках вызова не создаётся.
|
||||
- **FAIL:** указатель обнулён или создан второй card-месседж в одном вызове.
|
||||
|
||||
### AC-4 — режим edit остаётся доступен через env
|
||||
- **PASS:** при `ORCH_TRACKER_MODE=edit` поведение прежнее (editMessageText, fallback на
|
||||
новый месседж только при EDIT_GONE).
|
||||
- **FAIL:** edit-режим сломан/недоступен.
|
||||
|
||||
---
|
||||
|
||||
## Группа B — Статус-строка карточки по модели ORCH-066 (Требование 2)
|
||||
|
||||
### AC-5 — статус-строка присутствует в карточке
|
||||
- **PASS:** `render_task_tracker(task_id)` содержит явную строку текущего Plane-статуса
|
||||
(напр. `📍 <status>`) в шапке/верхней части карточки.
|
||||
- **FAIL:** статус-строки нет.
|
||||
|
||||
### AC-6 — корректный маппинг stage → Plane-статус
|
||||
- **PASS:** для всех stage-выводимых состояний строка статуса соответствует таблице ТЗ §2.2:
|
||||
`created→To Analyse`, `analysis→Analysis`, `architecture→Architecture`,
|
||||
`development→Development`, `review→Code-Review`, `testing→Testing`,
|
||||
`deploy→Awaiting Deploy`, `done→Done`.
|
||||
- **FAIL:** хотя бы один stage маппится на неверное имя/внутренний ярлык.
|
||||
|
||||
### AC-7 — In Review (ожидание согласования BRD) как полноценный статус
|
||||
- **PASS:** при `stage == "analysis"`, `brd_review_started_at` задан и
|
||||
`brd_review_ended_at` пуст — статус-строка явно отражает `⏸️ In Review` с пометкой
|
||||
«ожидание согласования BRD»; при этом существующая строка «Подтверждение BRD …» с ⏸️/⏳
|
||||
сохранена. Работает без сетевых вызовов.
|
||||
- **FAIL:** In Review теряется/не показан как статус, либо строка «Подтверждение BRD» исчезла.
|
||||
|
||||
### AC-8 — Awaiting Deploy и Needs Input отражены
|
||||
- **PASS:** состояние ожидания Confirm Deploy показывается как
|
||||
`⏸️ Awaiting Deploy — ожидание Confirm Deploy`; состояние вопросов аналитика — как
|
||||
`❓ Needs Input — нужны уточнения`.
|
||||
- **FAIL:** любое из этих состояний не отражено в статус-строке.
|
||||
|
||||
### AC-9 — рендер карточки никогда не падает
|
||||
- **PASS:** при любой ошибке построения статуса (битые данные, недоступный источник)
|
||||
`render_task_tracker` возвращает корректную карточку (деградация на stage-маппинг или
|
||||
fallback-строку), исключение наружу не выходит.
|
||||
- **FAIL:** `render_task_tracker` бросает исключение.
|
||||
|
||||
---
|
||||
|
||||
## Группа C — Кликабельный номер в карточке (Требование 3)
|
||||
|
||||
### AC-10 — номер задачи в карточке — гиперссылка
|
||||
- **PASS:** при наличии `plane_web_url` (не loopback), `plane_workspace_slug`, `project_id`
|
||||
(резолв по repo) и `plane_issue_id` карточка содержит
|
||||
`<a href="https://<base>/<ws>/projects/<pid>/issues/<issue_id>/">ORCH-NNN</a>`.
|
||||
- **FAIL:** номер выводится сырым текстом при наличии всех данных, либо URL собран неверно.
|
||||
|
||||
### AC-11 — fail-safe ссылки в карточке
|
||||
- **PASS:** при отсутствии любого из (web_base/не-loopback, workspace, project_id,
|
||||
plane_issue_id) карточка показывает номер БЕЗ ссылки (`html.escape(work_item_id)`) и не
|
||||
падает.
|
||||
- **FAIL:** падение, пустая ссылка `<a href="">`, либо битый `<a>` тег.
|
||||
|
||||
---
|
||||
|
||||
## Группа D — Кликабельный номер во всех уведомлениях (Требование 4)
|
||||
|
||||
### AC-12 — единый хелпер ссылки
|
||||
- **PASS:** существует `plane_issue_link(...)`, возвращающий HTML-ссылку при достаточных
|
||||
данных и `html.escape(work_item_id)` при недостаточных; никогда не бросает.
|
||||
- **FAIL:** хелпера нет, либо он падает на неполных данных.
|
||||
|
||||
### AC-13 — хелпер применён во всех уведомлениях с work_item_id
|
||||
- **PASS:** во всех точках `send_telegram`/`notify_*` из ТЗ §3.3, где упоминается
|
||||
`work_item_id` (`notify_approve_requested`, `notify_error`, alert'ы stage_engine,
|
||||
launcher, merge_gate, job_reaper, security_gate, reconciler, main), номер задачи
|
||||
кликабелен (при наличии данных) и ведёт на ту же страницу Plane.
|
||||
- **FAIL:** хотя бы одна такая точка выводит номер сырым текстом при наличии данных.
|
||||
|
||||
### AC-14 — HTML-экранирование пользовательского текста
|
||||
- **PASS:** title/причины/сообщения с потенциальным HTML (`<`, `>`, `&`) экранируются
|
||||
`html.escape`; разметка `<a>` остаётся валидной; сообщение проходит `parse_mode=HTML`.
|
||||
- **FAIL:** неэкранированный текст ломает разметку (тест с title, содержащим `<b>`/`&`,
|
||||
обнаруживает поломку).
|
||||
|
||||
---
|
||||
|
||||
## Группа E — Нерегресс и качество
|
||||
|
||||
### AC-15 — инварианты транспорта/нотификаций сохранены
|
||||
- **PASS:** `send_telegram`/`edit_telegram`/`delete_telegram` не изменены по сигнатуре/
|
||||
семантике; карточка тихая (`disable_notification=True`); инвариант «одна карточка на
|
||||
задачу» соблюдён; `STAGE_TRANSITIONS`/QG/схема БД не тронуты.
|
||||
- **FAIL:** изменён транспорт, карточка пингует, появились дубли, тронута схема БД/QG.
|
||||
|
||||
### AC-16 — нет регресса для enduro-trails
|
||||
- **PASS:** существующие тесты нотификаций (`test_notify_approve_links.py`,
|
||||
`test_notify_done_regression.py` и др.) проходят; поведение карточки для не-ORCH проектов
|
||||
без новых Plane-статусов деградирует корректно (alias-fallback, без ссылки при нехватке
|
||||
данных).
|
||||
- **FAIL:** падение существующих тестов или сломанная карточка для enduro.
|
||||
|
||||
### AC-17 — весь набор тестов зелёный
|
||||
- **PASS:** `pytest tests/ -q` зелёный.
|
||||
- **FAIL:** любой упавший тест.
|
||||
|
||||
### AC-18 — документация обновлена в том же PR
|
||||
- **PASS:** обновлены `CLAUDE.md` (раздел нотификаций/tracker), `CHANGELOG.md`,
|
||||
создан ADR per-work-item.
|
||||
- **FAIL:** функционал изменён, документация — нет (reviewer → REQUEST_CHANGES).
|
||||
181
docs/work-items/ORCH-067/04-test-plan.yaml
Normal file
181
docs/work-items/ORCH-067/04-test-plan.yaml
Normal file
@@ -0,0 +1,181 @@
|
||||
work_item: ORCH-067
|
||||
description: >
|
||||
План тестов для ORCH-067 (Telegram tracker: bump по умолчанию, статус-строка
|
||||
карточки по модели Plane ORCH-066, кликабельный номер задачи в карточке и во
|
||||
всех уведомлениях орка). Сеть изолируется: send_telegram/edit_telegram/
|
||||
delete_telegram подменяются рекордерами (как в tests/conftest.py и
|
||||
tests/test_notify_approve_links.py); БД — временный SQLite, сидируемый фикстурой.
|
||||
|
||||
tests:
|
||||
# --- Группа A: bump по умолчанию (AC-1..AC-4) ---
|
||||
- id: TC-01
|
||||
type: unit
|
||||
description: "Дефолт Settings().tracker_mode == 'bump' без env ORCH_TRACKER_MODE"
|
||||
module: tests/test_tracker_bump_default.py
|
||||
asserts: "AC-1"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-02
|
||||
type: unit
|
||||
description: >
|
||||
bump-поведение: при повторном update_task_tracker с сохранённым
|
||||
tracker_message_id вызывается delete_telegram(old) -> send_telegram(...,
|
||||
disable_notification=True) -> set_tracker_message_id(new). Одна карточка.
|
||||
module: tests/test_tracker_bump_default.py
|
||||
asserts: "AC-2"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-03
|
||||
type: unit
|
||||
description: >
|
||||
bump fail-safe: send_telegram вернул None (нет креды/транзиент) ->
|
||||
tracker_message_id не обнуляется, дубликат в вызове не создаётся.
|
||||
module: tests/test_tracker_bump_default.py
|
||||
asserts: "AC-3"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-04
|
||||
type: unit
|
||||
description: "ORCH_TRACKER_MODE=edit -> прежнее edit-поведение (editMessageText)"
|
||||
module: tests/test_tracker_bump_default.py
|
||||
asserts: "AC-4"
|
||||
expected: PASS
|
||||
|
||||
# --- Группа B: статус-строка карточки (AC-5..AC-9) ---
|
||||
- id: TC-05
|
||||
type: unit
|
||||
description: "render_task_tracker содержит явную строку текущего Plane-статуса"
|
||||
module: tests/test_tracker_status_line.py
|
||||
asserts: "AC-5"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-06
|
||||
type: unit
|
||||
description: >
|
||||
Маппинг stage -> Plane-статус по таблице ТЗ §2.2: created->To Analyse,
|
||||
analysis->Analysis, architecture->Architecture, development->Development,
|
||||
review->Code-Review, testing->Testing, deploy->Awaiting Deploy, done->Done
|
||||
(параметризованный тест по всем stage).
|
||||
module: tests/test_tracker_status_line.py
|
||||
asserts: "AC-6"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-07
|
||||
type: unit
|
||||
description: >
|
||||
analysis + brd_review_started_at задан + brd_review_ended_at пуст ->
|
||||
статус '⏸️ In Review' (ожидание согласования BRD); строка 'Подтверждение
|
||||
BRD' с ⏸️/⏳ сохранена; без сетевых вызовов.
|
||||
module: tests/test_tracker_status_line.py
|
||||
asserts: "AC-7"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-08
|
||||
type: unit
|
||||
description: >
|
||||
Awaiting Deploy ('ожидание Confirm Deploy') и Needs Input ('нужны
|
||||
уточнения') корректно отражаются в статус-строке.
|
||||
module: tests/test_tracker_status_line.py
|
||||
asserts: "AC-8"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-09
|
||||
type: unit
|
||||
description: >
|
||||
render_task_tracker не падает при битых/недоступных данных статуса
|
||||
(деградация на stage-маппинг/fallback, исключение не наружу).
|
||||
module: tests/test_tracker_status_line.py
|
||||
asserts: "AC-9, AC-16"
|
||||
expected: PASS
|
||||
|
||||
# --- Группа C: кликабельный номер в карточке (AC-10..AC-11) ---
|
||||
- id: TC-10
|
||||
type: unit
|
||||
description: >
|
||||
При полных данных (plane_web_url не loopback, workspace, project_id по repo,
|
||||
plane_issue_id) карточка содержит <a href=".../issues/<id>/">ORCH-NNN</a>
|
||||
с корректным URL.
|
||||
module: tests/test_tracker_issue_link.py
|
||||
asserts: "AC-10"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-11
|
||||
type: unit
|
||||
description: >
|
||||
Fail-safe ссылки в карточке: при отсутствии любого из (web_base/не-loopback,
|
||||
workspace, project_id, plane_issue_id) номер выводится html.escape без <a>,
|
||||
рендер не падает. Параметризовать по каждому отсутствующему полю.
|
||||
module: tests/test_tracker_issue_link.py
|
||||
asserts: "AC-11"
|
||||
expected: PASS
|
||||
|
||||
# --- Группа D: единый хелпер и уведомления (AC-12..AC-14) ---
|
||||
- id: TC-12
|
||||
type: unit
|
||||
description: >
|
||||
plane_issue_link(...) возвращает HTML-ссылку при достаточных данных и
|
||||
html.escape(work_item_id) при недостаточных; никогда не бросает (в т.ч. на
|
||||
None-аргументах и loopback-базе).
|
||||
module: tests/test_plane_issue_link.py
|
||||
asserts: "AC-12"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-13
|
||||
type: unit
|
||||
description: >
|
||||
notify_approve_requested: номер задачи кликабелен (ведёт на страницу Plane),
|
||||
сохранён call-to-action 'Approved', ровно одно notifying-сообщение.
|
||||
module: tests/test_notify_issue_links.py
|
||||
asserts: "AC-13"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-14
|
||||
type: unit
|
||||
description: >
|
||||
notify_error: номер задачи кликабелен при наличии данных, деградирует на
|
||||
сырой номер без падения при их отсутствии.
|
||||
module: tests/test_notify_issue_links.py
|
||||
asserts: "AC-13, AC-12"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-15
|
||||
type: integration
|
||||
description: >
|
||||
Точки send_telegram в stage_engine/launcher/merge_gate/job_reaper/
|
||||
security_gate/reconciler/main, где есть work_item_id, используют
|
||||
plane_issue_link (или эквивалент) — номер кликабелен. Проверка рекордером
|
||||
send_telegram на представительных alert-путях (deploy fail, agent fail,
|
||||
QG fail, прод-деплой).
|
||||
module: tests/test_notify_issue_links.py
|
||||
asserts: "AC-13"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-16
|
||||
type: unit
|
||||
description: >
|
||||
HTML-экранирование: title с '<b>'/'&'/'>' экранируется, <a>-разметка
|
||||
остаётся валидной, сообщение не ломается под parse_mode=HTML (карточка и
|
||||
уведомления).
|
||||
module: tests/test_tracker_issue_link.py
|
||||
asserts: "AC-14"
|
||||
expected: PASS
|
||||
|
||||
# --- Группа E: нерегресс (AC-15..AC-18) ---
|
||||
- id: TC-17
|
||||
type: integration
|
||||
description: >
|
||||
Инварианты: карточка отправляется с disable_notification=True; одна карточка
|
||||
на задачу; транспорт send/edit/delete не изменён по семантике.
|
||||
module: tests/test_tracker_bump_default.py
|
||||
asserts: "AC-15"
|
||||
expected: PASS
|
||||
|
||||
- id: TC-18
|
||||
type: integration
|
||||
description: >
|
||||
Нерегресс существующих тестов нотификаций (test_notify_approve_links.py,
|
||||
test_notify_done_regression.py) и корректная деградация карточки для
|
||||
enduro-trails без новых Plane-статусов.
|
||||
module: tests/test_notify_done_regression.py
|
||||
asserts: "AC-16, AC-17"
|
||||
expected: PASS
|
||||
@@ -0,0 +1,224 @@
|
||||
# ADR-001: Источник Plane-статуса для live-карточки и кликабельный номер задачи
|
||||
|
||||
- **Статус:** Proposed
|
||||
- **Дата:** 2026-06-08
|
||||
- **Задача:** ORCH-067
|
||||
- **Слой:** B (индикация), НЕ слой A (машина стадий) — см. CLAUDE.md / ORCH-066
|
||||
- **Связи:** ORCH-066 (статусная модель Plane, `_PLANE_NAME_TO_KEY` / `_STAGE_TO_STATE_KEY`),
|
||||
ORCH-042 (live-tracker, режимы `edit`/`bump`), ORCH-017 (`_build_plane_issue_link`,
|
||||
`plane_web_url`/`plane_workspace_slug`, loopback-guard), ORCH-059 (Confirm Deploy),
|
||||
ORCH-060 (`fetch_issue_state`), ORCH-010 (`get_project_states` per-project + кэш),
|
||||
adr-0001 (реестр проектов), adr-0010 (post-deploy monitor).
|
||||
|
||||
## Контекст
|
||||
|
||||
ТЗ ORCH-067 (`02-trz.md`) фиксирует объём изменений; данный ADR закрывает развилки,
|
||||
явно отданные архитектору метками `[ARCH]`:
|
||||
|
||||
1. **Источник «истинного» Plane-статуса для веток, не выводимых из `tasks.stage`**
|
||||
(Needs Input, Blocked, Rejected, Cancelled, Deploying, Monitoring after Deploy),
|
||||
при **запрете менять схему БД** (нельзя добавить колонку-флаг). TZ §2.2 предлагает
|
||||
два варианта: (а) best-effort чтение живого Plane-статуса с fail-safe;
|
||||
(б) только stage-выводимые статусы.
|
||||
2. **Способ доступа к `plane_issue_id`/`project_id`** в каждой точке `send_telegram`,
|
||||
где есть только `work_item_id` (требование 4), оставаясь fail-safe.
|
||||
3. Смена дефолта `tracker_mode` (`edit` → `bump`) для общего инстанса.
|
||||
|
||||
### Ключевая находка анализа (определяет развилку 1)
|
||||
|
||||
Когда аналитик задаёт вопросы, `stage_engine.start_pipeline` при наличии
|
||||
`01-questions.md` вызывает `set_issue_needs_input(work_item_id)` (Plane → Needs Input),
|
||||
но **DB-стадия остаётся `analysis`**, а BRD-часы (`brd_review_started_at`) **не
|
||||
запускаются** (они стартуют позже, в `notify_approve_requested`, когда BRD готов).
|
||||
Следовательно состояния **`Analysis` (аналитик работает)** и **`❓ Needs Input`
|
||||
(аналитик ждёт ответа)** **неразличимы** по offline-данным БД (`stage` + brd-clock).
|
||||
Единственный авторитетный источник этого различия — **живой Plane-статус**, который
|
||||
оркестратор сам выставил через `set_issue_needs_input`.
|
||||
|
||||
То же касается `Deploying` / `Monitoring after Deploy`: на стадии `deploy`/`done`
|
||||
конкретная фаза self-deploy видна только в Plane (ORCH-059/ORCH-066), не в `tasks.stage`.
|
||||
|
||||
Вывод: чисто-offline вариант (б) **не покрывает обязательный по DoD `❓ Needs Input`**
|
||||
(AC-8). Нужен гибрид.
|
||||
|
||||
## Решение
|
||||
|
||||
### Р-1. Гибрид: offline-first ядро + best-effort live-overlay
|
||||
|
||||
Статус карточки строится в два слоя; **offline-ядро авторитетно и всегда работает без
|
||||
сети**, live-overlay лишь дорисовывает ветки, неотличимые offline.
|
||||
|
||||
**Слой 1 — чистая offline-функция `plane_status_label(task_row) -> str`** в
|
||||
`src/notifications.py`. Детерминированная, **никогда не бросает**, **никогда не ходит в
|
||||
сеть**. Маппинг (имена статусов — финальные из ORCH-066 `_PLANE_NAME_TO_KEY`):
|
||||
|
||||
| Источник (DB) | Метка карточки |
|
||||
|---|---|
|
||||
| `stage == "created"` | `To Analyse` |
|
||||
| `stage == "analysis"`, brd-clock не запущен | `Analysis` |
|
||||
| `stage == "analysis"`, `brd_review_started_at` есть, `brd_review_ended_at` пуст | `⏸️ In Review — ожидание согласования BRD` |
|
||||
| `stage == "architecture"` | `Architecture` |
|
||||
| `stage == "development"` | `Development` |
|
||||
| `stage == "review"` | `Code-Review` |
|
||||
| `stage == "testing"` | `Testing` |
|
||||
| `stage == "deploy"` | `⏸️ Awaiting Deploy — ожидание Confirm Deploy` |
|
||||
| `stage == "done"` | `Done` |
|
||||
| неизвестный/битый `stage` | дефолт: `html`-безопасная строка по `stage` (или `To Analyse`) |
|
||||
|
||||
Этого слоя достаточно для **`⏸️ In Review`** и **`⏸️ Awaiting Deploy`** — оба
|
||||
обязательны по DoD и **работают без сети** (AC-7, AC-8). `In Review` выводится
|
||||
исключительно из brd-clock.
|
||||
|
||||
**Слой 2 — best-effort live-overlay** `_live_plane_branch_override(repo, plane_issue_id,
|
||||
base_label) -> str` для веток, неразличимых offline: **Needs Input, Blocked, Rejected,
|
||||
Cancelled, Deploying, Monitoring after Deploy**. Алгоритм:
|
||||
|
||||
1. Резолв `project_id` по `repo` (`get_project_by_repo(repo).plane_project_id`).
|
||||
2. `live_uuid = fetch_issue_state(plane_issue_id, project_id)` (ORCH-060) — **с коротким
|
||||
таймаутом** (см. Р-4), не дефолтным 10s.
|
||||
3. Сопоставление `live_uuid` с **конкретными** UUID веток из
|
||||
`get_project_states(project_id)` (кэш ORCH-010): `needs_input`, `blocked`,
|
||||
`cancelled`, `rejected`, `deploying`, `monitoring`.
|
||||
4. Override применяется **только** если `live_uuid` совпал с одним из этих ключей.
|
||||
Иначе возвращается `base_label` (offline-метка).
|
||||
|
||||
**Прецеденс (порядок приоритета):**
|
||||
1. Если offline-ядро дало **`⏸️ In Review`** (brd-clock) — overlay **не вызывается**:
|
||||
brd-clock авторитетнее возможно-устаревшего Plane-чтения для In Review.
|
||||
2. Иначе `base_label` = offline-метка, затем применяется overlay (если включён и удался).
|
||||
|
||||
**Анти-false-positive на enduro (важно):** на enduro-trails ключи `deploying`/
|
||||
`monitoring` алиасят UUID `in_progress`/`done` (`_STATE_ALIAS_FALLBACK`), поэтому прямое
|
||||
сравнение UUID дало бы ложный `Deploying` для любой `in_progress`-задачи. Поэтому для
|
||||
`deploying`/`monitoring` override применяется **только если** их UUID в
|
||||
`get_project_states` **отличается** от UUID базового ключа (т.е. проект реально завёл
|
||||
отдельный статус — это ORCH, не enduro). Ключи `needs_input/blocked/cancelled/rejected`
|
||||
имеют отдельные UUID и на enduro, и на ORCH (`_DEFAULT_STATES`), поэтому различимы всегда.
|
||||
|
||||
### Р-2. Fail-safe и невлияние на конвейер (overlay)
|
||||
|
||||
- `_live_plane_branch_override` обёрнут в `try/except` и **никогда не бросает**; любая
|
||||
ошибка/таймаут/нет сети/нет данных → возвращается `base_label`. Это удовлетворяет
|
||||
«без сети не падать» и AC-9 (рендер карточки никогда не падает).
|
||||
- Нет `plane_issue_id` / нет `project_id` / нет креды → overlay не вызывается, метка =
|
||||
offline-ядро.
|
||||
- **Kill-switch:** новый флаг конфигурации `tracker_live_status: bool = True`
|
||||
(env `ORCH_TRACKER_LIVE_STATUS`). При `False` overlay полностью отключён (никаких
|
||||
сетевых чтений в рендере) — карточка деградирует на offline-ядро. Это аварийный
|
||||
тумблер и страховка от регресса для не-ORCH проектов. **Дефолт `True`**, иначе
|
||||
обязательный по DoD `Needs Input` не отобразится из коробки.
|
||||
|
||||
### Р-3. Кэш live-статуса (защита hot-path)
|
||||
|
||||
`render_task_tracker` вызывается на КАЖДОМ обновлении трекера (старт/финиш агента,
|
||||
переход стадии), а в режиме `bump` — с delete+send каждый раз. Чтобы серия быстрых
|
||||
перерисовок не била по Plane:
|
||||
|
||||
- Добавить **TTL-кэш per-issue** для `live_uuid` (ключ — `plane_issue_id`, TTL
|
||||
`tracker_live_status_ttl_s: int = 60`). По образцу `_STATES_CACHE` в `plane_sync.py`.
|
||||
- На промахе кэша — один `fetch_issue_state` с коротким таймаутом; результат кладётся в
|
||||
кэш. На любой ошибке кэш не портится, возвращается offline-метка.
|
||||
|
||||
Это ограничивает сетевую нагрузку overlay ~одним GET в `TTL` на задачу.
|
||||
|
||||
### Р-4. Короткий таймаут live-чтения в рендере
|
||||
|
||||
`fetch_issue_state` (ORCH-060) хардкодит `timeout=10`. Для пути рендера это слишком
|
||||
долго (рендер синхронный, в линии переходов общего конвейера). Решение: добавить в
|
||||
`fetch_issue_state` **необязательный параметр `timeout`** (дефолт прежний `10` —
|
||||
обратная совместимость для reconciler), а overlay вызывает его с
|
||||
`settings.tracker_live_status_timeout_s` (дефолт **3** с). Поведение/сигнатуры
|
||||
существующих вызовов не меняются.
|
||||
|
||||
### Р-5. Единый хелпер кликабельного номера `plane_issue_link`
|
||||
|
||||
Добавить в `src/notifications.py`:
|
||||
|
||||
```python
|
||||
def plane_issue_link(work_item_id, plane_issue_id=None, project_id=None, repo=None) -> str:
|
||||
"""HTML с кликабельным номером (<a href=...>ORCH-NNN</a>) или html.escape(work_item_id).
|
||||
Никогда не падает."""
|
||||
```
|
||||
|
||||
- Переиспользовать логику и guard'ы `_build_plane_issue_link` (ORCH-017), **разнеся**
|
||||
«текст ссылки = номер задачи» и «текст ссылки = `✅ Задача в Plane`», чтобы не
|
||||
дублировать резолв проекта и loopback-guard. Рекомендуется выделить приватный
|
||||
`_plane_issue_url(repo, plane_issue_id, project_id) -> str | None` (сборка URL +
|
||||
loopback/workspace/project guard), который зовут оба: `plane_issue_link` (текст =
|
||||
номер) и `_build_plane_issue_link` (текст = «✅ Задача в Plane»).
|
||||
- База URL: `plane_web_url` → fallback `plane_api_url`; loopback → «нет web URL»
|
||||
(`_is_loopback_base`).
|
||||
- `project_id`: явный аргумент → иначе резолв по `repo`.
|
||||
- URL: `{web_base}/{workspace}/projects/{project_id}/issues/{plane_issue_id}/`.
|
||||
- Текст = `html.escape(work_item_id)`; `href` = `html.escape(url, quote=True)`.
|
||||
- **Fail-safe:** не хватает любого из (web_base/не-loopback, workspace, project_id,
|
||||
plane_issue_id) → вернуть `html.escape(work_item_id)` (номер без ссылки). Никогда не
|
||||
бросает (AC-11, AC-12).
|
||||
|
||||
### Р-6. Доступ к `plane_issue_id`/`project_id` в точках уведомлений (требование 4)
|
||||
|
||||
В большинстве точек `send_telegram` доступен только `work_item_id`. Решение —
|
||||
тонкая fail-safe обёртка по образцу `_get_task_link_fields`:
|
||||
|
||||
```python
|
||||
def link_for(work_item_id, task_id=None) -> str:
|
||||
"""По work_item_id (или task_id) достать repo+plane_issue_id из БД и вернуть
|
||||
plane_issue_link(...). На любой нехватке данных -> html.escape(work_item_id)."""
|
||||
```
|
||||
|
||||
- Если у точки есть `task_id` — читать `(repo, plane_issue_id)` напрямую из `tasks` по
|
||||
`id`. Если только `work_item_id` — `SELECT repo, plane_issue_id FROM tasks WHERE
|
||||
work_item_id=? ORDER BY id DESC LIMIT 1` (как в `_resolve_project_id`).
|
||||
- Везде, где данных нет — деградация на `html.escape(work_item_id)`, без падения.
|
||||
- Применить во всех точках из TZ §3.3 (`notify_approve_requested`, `notify_error`,
|
||||
`stage_engine`, `launcher`, `merge_gate`, `job_reaper`, `security_gate`, `reconciler`,
|
||||
`main`) — **только там, где упоминается номер задачи**.
|
||||
|
||||
### Р-7. `tracker_mode` дефолт → `bump`
|
||||
|
||||
`src/config.py`: `tracker_mode: str = "edit"` → `"bump"`. Инвариант «одна карточка на
|
||||
задачу» сохранён в обоих режимах (код `update_task_tracker` не меняется по сути).
|
||||
`edit` остаётся доступен через `ORCH_TRACKER_MODE=edit`. Транзиентный фейл `send` не
|
||||
обнуляет `tracker_message_id` (инвариант уже в коде — сохранить).
|
||||
|
||||
### Р-8. Чего НЕ делаем (границы)
|
||||
|
||||
- НЕ менять схему БД, `STAGE_TRANSITIONS`, Quality Gates, транспорт
|
||||
`send_telegram`/`edit_telegram`/`delete_telegram`, `disable_notification`-семантику.
|
||||
- НЕ менять поведение агентов/конвейера. Слой B (индикация) не управляет слоем A.
|
||||
- НЕ добавлять блокирующих сетевых ожиданий в линию переходов сверх одного короткого
|
||||
best-effort GET с кэшем (Р-3/Р-4).
|
||||
- НЕ создавать глобальный (сквозной) ADR: изменение локально для `notifications.py` +
|
||||
один config-дефолт, не вводит новую стадию/QG/компонент. Достаточно per-work-item ADR.
|
||||
|
||||
## Последствия
|
||||
|
||||
**Плюсы**
|
||||
- Обязательные по DoD `⏸️ In Review`, `⏸️ Awaiting Deploy` работают **без сети**
|
||||
(детерминированно, тестируемо offline — AC-6/AC-7).
|
||||
- `❓ Needs Input` (и Blocked/Rejected/Cancelled/Deploying/Monitoring) отражаются через
|
||||
авторитетный источник — живой Plane-статус, который иначе невосстановим из БД.
|
||||
- Единый хелпер ссылки убирает дублирование резолва проекта/loopback-guard (ORCH-017).
|
||||
- Kill-switch + кэш + короткий таймаут ограничивают риск для общего инстанса.
|
||||
|
||||
**Минусы / ограничения**
|
||||
- Overlay добавляет ≤1 короткий GET (3 с таймаут) на задачу в `TTL=60s` в путь рендера.
|
||||
Митигировано кэшем, таймаутом и kill-switch.
|
||||
- При недоступном Plane ветки `Needs Input`/`Blocked`/… деградируют на offline-метку
|
||||
(`Analysis`/stage). Это осознанный, безопасный компромисс (рендер важнее точности
|
||||
ветки; конвейер не блокируется).
|
||||
- На частично сконфигурированном проекте без отдельных статусов `Deploying`/`Monitoring`
|
||||
эти ветки не показываются (alias-guard) — корректная деградация, не баг.
|
||||
|
||||
**Риски** — см. `10-tech-risks.md`.
|
||||
|
||||
## Альтернативы (отклонены)
|
||||
|
||||
- **Только offline (вариант б TZ).** Отклонён: не отличает `Needs Input` от `Analysis`
|
||||
→ не покрывает обязательный AC-8.
|
||||
- **Чтение `01-questions.md` из worktree как offline-сигнал Needs Input.** Отклонён:
|
||||
хрупко (резолв пути worktree из `notifications.py`, файл может пережить ответ,
|
||||
гонки) — менее надёжно, чем авторитетный Plane-статус.
|
||||
- **Добавить DB-колонку-флаг для ветки.** Запрещено TZ (без изменения схемы).
|
||||
- **Асинхронный фон/демон для подтяжки статуса.** Избыточно для слоя индикации; кэш +
|
||||
короткий таймаут дешевле и проще, без нового компонента.
|
||||
46
docs/work-items/ORCH-067/07-infra-requirements.md
Normal file
46
docs/work-items/ORCH-067/07-infra-requirements.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Инфраструктурные требования — ORCH-067
|
||||
|
||||
Топология не меняется (никаких новых контейнеров/портов/сервисов). Изменения —
|
||||
**только конфигурация/env** и обязательный staging-гейт (self-hosting).
|
||||
|
||||
## 1. Изменения конфигурации (`src/config.py`)
|
||||
|
||||
| Поле | env | Старое | Новое | Назначение |
|
||||
|---|---|---|---|---|
|
||||
| `tracker_mode` | `ORCH_TRACKER_MODE` | `"edit"` | `"bump"` (дефолт) | Карточка падает вниз ленты при обновлении (ADR-001 Р-7). `edit` доступен через env. |
|
||||
| `tracker_live_status` | `ORCH_TRACKER_LIVE_STATUS` | — (нет) | `True` (дефолт) | Kill-switch live-overlay Plane-статуса (ADR-001 Р-2). `0/false` → только offline-метки, без сетевых чтений в рендере. |
|
||||
| `tracker_live_status_ttl_s` | `ORCH_TRACKER_LIVE_STATUS_TTL_S` | — | `60` | TTL per-issue кэша live-статуса (ADR-001 Р-3). |
|
||||
| `tracker_live_status_timeout_s` | `ORCH_TRACKER_LIVE_STATUS_TIMEOUT_S` | — | `3` | Короткий таймаут live-чтения в рендере (ADR-001 Р-4). |
|
||||
|
||||
Уже существующие (не менять, использовать): `plane_web_url`
|
||||
(`ORCH_PLANE_WEB_URL`, прод — `https://plane.mva154.duckdns.org`),
|
||||
`plane_workspace_slug` (прод — `ag_proj`), `plane_api_url`.
|
||||
|
||||
## 2. `.env` / `.env.example`
|
||||
|
||||
- Обновить `.env.example`: добавить `ORCH_TRACKER_MODE`, `ORCH_PLANE_WEB_URL`,
|
||||
`ORCH_TRACKER_LIVE_STATUS*` с дефолтами и комментариями (канон настроек —
|
||||
`.env.example`, реальные секреты не коммитить).
|
||||
- На прод-хосте допустимо явно выставить `ORCH_TRACKER_MODE=bump` как страховку, но код
|
||||
обязан работать «из коробки» и без env.
|
||||
- `ORCH_PLANE_WEB_URL` должен быть задан на проде (иначе номер задачи деградирует на
|
||||
текст без ссылки — fail-safe, не падение).
|
||||
|
||||
## 3. Self-hosting (обязательно)
|
||||
|
||||
- **НЕ перезапускать / не ронять** прод-контейнер `orchestrator` (8500) в рамках задачи —
|
||||
общий инстанс/БД с enduro-trails.
|
||||
- Обязательная страховка через `deploy-staging` (8501, изолированная БД) **до** прод-деплоя.
|
||||
На staging проверить:
|
||||
- режим `bump`: одна карточка на задачу, падает вниз, тихо (без звука), без дублей;
|
||||
- статус-строка: `⏸️ In Review`, `⏸️ Awaiting Deploy`, `❓ Needs Input` отображаются;
|
||||
- кликабельный номер ведёт на страницу Plane;
|
||||
- **нет регресса для enduro-trails** (карточка без новых статусов деградирует корректно).
|
||||
- Прод-деплой орка — только переводом задачи на стадии `deploy` в статус
|
||||
**«Confirm Deploy»** (ORCH-059), не `Approved`.
|
||||
|
||||
## 4. Сетевые требования
|
||||
|
||||
- Live-overlay требует доступности Plane API (`plane_api_url`) из контейнера — он уже
|
||||
есть (используется plane_sync). Недоступность Plane → graceful degrade на offline-метку,
|
||||
конвейер не блокируется (короткий таймаут + kill-switch).
|
||||
35
docs/work-items/ORCH-067/08-data-requirements.md
Normal file
35
docs/work-items/ORCH-067/08-data-requirements.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Требования к данным — ORCH-067
|
||||
|
||||
## Изменения схемы БД: НЕТ
|
||||
|
||||
`STAGE_TRANSITIONS`, таблицы и колонки `tasks`/`agent_runs` **не меняются**. Это жёсткое
|
||||
ограничение TZ §6 и предпосылка ADR-001 (запрет колонки-флага для веток статуса).
|
||||
|
||||
## Читаемые колонки `tasks` (существующие)
|
||||
|
||||
| Колонка | Использование в ORCH-067 |
|
||||
|---|---|
|
||||
| `id` | Ключ задачи. |
|
||||
| `work_item_id` | Текст номера (`ORCH-NNN`) + ключ резолва в `link_for`. |
|
||||
| `title` | Заголовок карточки (`html.escape`). |
|
||||
| `stage` | Offline-маппинг Plane-статуса (ADR-001 Р-1, слой 1). |
|
||||
| `brd_review_started_at`, `brd_review_ended_at` | Различение `Analysis` ↔ `⏸️ In Review` (offline, без сети). |
|
||||
| `repo` | Резолв `project_id` (`get_project_by_repo`) для ссылки и live-overlay. |
|
||||
| `plane_issue_id` (UUID) | `issue_id` в URL Plane + аргумент `fetch_issue_state` (live-overlay). |
|
||||
| `created_at`, `updated_at` | Тоталы времени в done-строке (без изменений). |
|
||||
|
||||
`render_task_tracker` **расширяет существующий `SELECT`** по `tasks`, добавляя `repo` и
|
||||
`plane_issue_id` к уже выбираемым полям. Схему это не трогает — колонки уже есть.
|
||||
|
||||
## Кэш в памяти (не БД)
|
||||
|
||||
Per-issue TTL-кэш live-статуса (ключ `plane_issue_id`, TTL
|
||||
`tracker_live_status_ttl_s=60`, ADR-001 Р-3) — **in-memory**, по образцу `_STATES_CACHE`
|
||||
в `plane_sync.py`. Не персистится, переживание рестарта не требуется (best-effort
|
||||
индикация). Очистка при рестарте — допустима.
|
||||
|
||||
## Источник имён статусов
|
||||
|
||||
Имена и логические ключи статусов берутся из существующих структур `src/plane_sync.py`
|
||||
(`_PLANE_NAME_TO_KEY`, `get_project_states`, `_DEFAULT_STATES`), вводимых ORCH-066.
|
||||
Новых статусов/ключей ORCH-067 **не добавляет**.
|
||||
21
docs/work-items/ORCH-067/10-tech-risks.md
Normal file
21
docs/work-items/ORCH-067/10-tech-risks.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Технические риски — ORCH-067
|
||||
|
||||
| # | Риск | Вероятность / Влияние | Митигация (ADR-001) | Остаточный риск |
|
||||
|---|---|---|---|---|
|
||||
| R-1 | **Регресс enduro-trails** при смене дефолта `tracker_mode` → `bump` (другое поведение карточки для всех проектов). | Сред / Сред | Инвариант «одна карточка на задачу» сохранён; `edit` доступен через env; проверка на staging + тесты нерегресса (AC-16). | Низкий |
|
||||
| R-2 | **Поломка HTML-разметки** неэкранированным `title`/причиной → сообщение с `parse_mode=HTML` не доставится. | Сред / Сред | Обязательный `html.escape` для всего пользовательского текста; `href` через `html.escape(url, quote=True)`; тест с `<b>`/`&` (AC-14). | Низкий |
|
||||
| R-3 | **Latency в hot-path конвейера**: live-overlay добавляет сетевой GET в синхронный рендер, вызываемый на каждом переходе/в bump. | Сред / Сред | Короткий таймаут 3 с (Р-4) + per-issue TTL-кэш 60 с (Р-3) + kill-switch `ORCH_TRACKER_LIVE_STATUS=0` (Р-2). ≤1 GET на задачу за TTL. | Низкий |
|
||||
| R-4 | **Рендер карточки падает** на битых данных/недоступном Plane. | Низк / Выс | `plane_status_label` чистая и never-raise; overlay в `try/except` → degrade на offline-метку; `render_task_tracker` уже never-raise (AC-9). | Очень низкий |
|
||||
| R-5 | **Ложный `Deploying`/`Monitoring` на enduro** (их UUID алиасит `in_progress`/`done`). | Сред / Низк | Override этих веток только если UUID статуса ≠ UUID базового ключа в `get_project_states` (Р-1, anti-false-positive). | Очень низкий |
|
||||
| R-6 | **Устаревший Plane-статус из кэша** показывает неактуальную ветку (например, `Needs Input` после ответа). | Сред / Низк | TTL 60 с самозаживает; offline-ядро авторитетно для In Review (brd-clock не оверрайдится). Индикация, не управление — расхождение косметическое. | Низкий |
|
||||
| R-7 | **Транзиентный фейл `send` плодит дубли / обнуляет указатель** в bump. | Низк / Сред | Инвариант уже в коде (`set_tracker_message_id` только при `new_mid is not None`); не менять; тест AC-3. | Низкий |
|
||||
| R-8 | **Self-hosting**: деплой орка ломает общий инстанс (enduro + ORCH, общая БД/очередь). | Низк / Выс | Обязательный staging-гейт (8501) до прода; прод-контейнер не ронять в задаче; прод-деплой только через «Confirm Deploy». | Низкий |
|
||||
| R-9 | **Пропущенная точка** уведомления с сырым номером (требование 4 — много call-sites). | Сред / Низк | Единый `link_for`/`plane_issue_link`; чек-лист точек из TZ §3.3; reviewer проверяет покрытие (AC-13). | Низкий |
|
||||
| R-10 | **Рассинхрон имён статусов** с ORCH-066, если та не в проде на момент разработки. | Низк / Низк | Имена берутся из `_PLANE_NAME_TO_KEY` (golden source); делать после прода ORCH-066 (BRD §6). | Низкий |
|
||||
|
||||
## Сводно
|
||||
|
||||
Все остаточные риски — низкие/очень низкие после митигаций. Главные защитные контуры:
|
||||
(1) offline-ядро статуса не требует сети и детерминировано; (2) live-overlay полностью
|
||||
best-effort с таймаутом+кэшем+kill-switch; (3) обязательный staging-гейт перед прод-деплоем
|
||||
общего инстанса (self-hosting).
|
||||
78
docs/work-items/ORCH-067/12-review.md
Normal file
78
docs/work-items/ORCH-067/12-review.md
Normal file
@@ -0,0 +1,78 @@
|
||||
---
|
||||
type: review
|
||||
work_item_id: ORCH-067
|
||||
verdict: APPROVED
|
||||
version: 2
|
||||
---
|
||||
|
||||
# Review ORCH-067
|
||||
|
||||
## Summary
|
||||
|
||||
Повторное ревью после фикса документации (коммит `7a88f39`). Реализация полностью
|
||||
соответствует ТЗ (`02-trz.md`), ADR-001 и всем acceptance criteria (`03-acceptance-criteria.md`).
|
||||
|
||||
**Код** (`src/notifications.py` — ядро):
|
||||
- **Req 1 (bump):** дефолт `tracker_mode` сменён `edit → bump` (`src/config.py`); логика
|
||||
`update_task_tracker`, транспорт `send/edit/delete_telegram`, `disable_notification` и
|
||||
инвариант «одна карточка на задачу» не тронуты (AC-1..AC-4, AC-15 ✓).
|
||||
- **Req 2 (статус-строка):** чистый never-raise `plane_status_label(task_row)` (offline-ядро:
|
||||
stage→статус + `⏸️ In Review` из brd-clock + `⏸️ Awaiting Deploy`, всё без сети) +
|
||||
best-effort `_live_plane_branch_override` для ветвей, неотличимых offline (Needs Input /
|
||||
Blocked / Rejected / Cancelled / Deploying / Monitoring). Kill-switch
|
||||
(`tracker_live_status`), per-issue TTL-кэш (`_LIVE_STATE_CACHE`), короткий таймаут
|
||||
(`fetch_issue_state(..., timeout=)`, дефолт 10 сохранён → нет регресса reconciler).
|
||||
Anti-false-positive guard для enduro (`_LIVE_BRANCH_BASE`: deploying/monitoring override
|
||||
только при отдельном UUID). Прецеденс In Review > overlay соблюдён. `_card_status_label`
|
||||
обёрнут в try/except → рендер никогда не падает (AC-5..AC-9 ✓).
|
||||
- **Req 3+4 (кликабельный номер):** единый `_plane_issue_url` устраняет дублирование
|
||||
резолва проекта/loopback-guard (ORCH-017); `plane_issue_link` (текст=номер) и
|
||||
`_build_plane_issue_link` (текст=«✅ Задача в Plane») оба зовут его. `link_for` fail-safe
|
||||
достаёт `repo`/`plane_issue_id` из БД. Применено в заголовке карточки и во ВСЕХ точках
|
||||
§3.3 с номером задачи (AC-10..AC-14 ✓).
|
||||
|
||||
**Точки §3.3 проверены пофайлово:** `notify_approve_requested`, `notify_error`,
|
||||
`stage_engine.py` (все alert'ы с номером), `agents/launcher.py`, `security_gate.py`,
|
||||
`reconciler.py` — номер кликабелен. `merge_gate.py`/`job_reaper.py`/`main.py` оставлены без
|
||||
ссылки **осознанно и корректно**: их тексты ссылаются на repo/job/run_id, а НЕ на
|
||||
`work_item_id` (проверено: merge_gate:432 — lease/repo, job_reaper:396 — job/agent/repo,
|
||||
main:47 — orphaned run_ids).
|
||||
|
||||
**Инварианты/нерегресс:** схема БД, `STAGE_TRANSITIONS`, QG, транспорт — не тронуты
|
||||
(AC-15 ✓). `get_db()` возвращает новое соединение на вызов, поэтому `conn.close()` в
|
||||
`link_for` корректен. `pytest tests/ -q` → **907 passed** (AC-16, AC-17 ✓).
|
||||
|
||||
**Документация (блокеры v1 закрыты):** `CHANGELOG.md`, `CLAUDE.md`, `.env.example`
|
||||
обновлены в коммите `7a88f39`; ADR-001 присутствует и полон; `README.md`/`internals.md`
|
||||
синхронизированы (AC-18 ✓).
|
||||
|
||||
## Findings
|
||||
|
||||
### P0 — Blocker
|
||||
- (нет)
|
||||
|
||||
### P1 — Must fix
|
||||
- (нет)
|
||||
|
||||
### P2 — Should fix
|
||||
- (нет)
|
||||
|
||||
### P3 — Nice to have (не блокирует)
|
||||
- [ ] Часть alert-сообщений в `stage_engine.py` (`_handle_self_deploy_phase_b`,
|
||||
`_handle_merge_verify`) встраивает «сырой» `{msg}`/`{e}`/`{reason}` рядом с новой
|
||||
`<a>`-ссылкой; под `parse_mode=HTML` редкий `<` в этих подстановках теоретически мог
|
||||
бы помешать рендеру. Это **пре-существующее поведение** (parse_mode=HTML стоял и
|
||||
раньше), не регресс данной задачи; `notify_error` свой `error` экранирует. Можно при
|
||||
случае обернуть прочие подстановки в `html.escape`.
|
||||
|
||||
## Документация
|
||||
|
||||
- `docs/architecture/README.md` — обновлён (компонент Notifications / live-tracker). ✓
|
||||
- `docs/architecture/internals.md` — обновлён (§7: bump/edit, Plane-статус, кликабельный номер). ✓
|
||||
- `06-adr/ADR-001-tracker-plane-status-and-link.md` — присутствует, полный, закрывает все `[ARCH]`. ✓
|
||||
- `CHANGELOG.md` — обновлён (запись ORCH-067). ✓
|
||||
- `CLAUDE.md` — обновлён (раздел «Нотификации / Telegram live-tracker»). ✓
|
||||
- `.env.example` — синхронизирован (`ORCH_TRACKER_MODE=bump` + новые флаги live-overlay). ✓
|
||||
|
||||
Документация = golden source: код и доку обновлены в одном PR. Блокеры предыдущего ревью
|
||||
(v1) закрыты. Замечаний уровня P0/P1/P2 нет → **APPROVED**.
|
||||
78
docs/work-items/ORCH-067/13-test-report.md
Normal file
78
docs/work-items/ORCH-067/13-test-report.md
Normal file
@@ -0,0 +1,78 @@
|
||||
---
|
||||
type: test-report
|
||||
work_item_id: ORCH-067
|
||||
result: PASS
|
||||
---
|
||||
|
||||
# Test Report — ORCH-067
|
||||
|
||||
Telegram tracker: bump по умолчанию, статус-строка карточки по модели Plane (ORCH-066),
|
||||
кликабельный номер задачи в карточке и во всех уведомлениях орка.
|
||||
|
||||
## Окружение
|
||||
- Python: 3.12.13
|
||||
- pytest: 8.3.3
|
||||
- Ветка: `feature/ORCH-067-telegram-tracker-bump-plane` (worktree)
|
||||
- Дата: 2026-06-08
|
||||
- Review-вердикт: APPROVED (`12-review.md`, version 2)
|
||||
|
||||
## Smoke test API (prod, :8500)
|
||||
| Endpoint | Результат |
|
||||
|----------|-----------|
|
||||
| `GET /health` | PASS — `{"status":"ok","service":"orchestrator"}` |
|
||||
| `GET /status` | PASS — отдаёт active_tasks (ORCH-067 на stage=testing) |
|
||||
| `GET /queue` | PASS — breaker closed, preflight_ok, counts корректны |
|
||||
|
||||
Прод-контейнер не перезапускался (self-hosting инвариант соблюдён).
|
||||
|
||||
## Результаты по тест-плану (04-test-plan.yaml)
|
||||
|
||||
| TC ID | Описание | Модуль | AC | Результат |
|
||||
|-------|----------|--------|----|-----------|
|
||||
| TC-01 | Дефолт `tracker_mode == "bump"` без env | test_tracker_bump_default.py | AC-1 | PASS |
|
||||
| TC-02 | bump: delete(old)→send(silent)→repoint, одна карточка | test_tracker_bump_default.py | AC-2 | PASS |
|
||||
| TC-03 | bump fail-safe: send=None не обнуляет указатель | test_tracker_bump_default.py | AC-3 | PASS |
|
||||
| TC-04 | `ORCH_TRACKER_MODE=edit` — прежнее поведение | test_tracker_bump_default.py | AC-4 | PASS |
|
||||
| TC-05 | Карточка содержит строку Plane-статуса | test_tracker_status_line.py | AC-5 | PASS |
|
||||
| TC-06 | Маппинг stage → Plane-статус (§2.2, параметризованный) | test_tracker_status_line.py | AC-6 | PASS |
|
||||
| TC-07 | In Review из brd-clock, без сети; строка «Подтверждение BRD» сохранена | test_tracker_status_line.py | AC-7 | PASS |
|
||||
| TC-08 | Awaiting Deploy + Needs Input отражены | test_tracker_status_line.py | AC-8 | PASS |
|
||||
| TC-09 | render_task_tracker не падает на битых данных | test_tracker_status_line.py | AC-9, AC-16 | PASS |
|
||||
| TC-10 | Кликабельный номер в карточке при полных данных | test_tracker_issue_link.py | AC-10 | PASS |
|
||||
| TC-11 | Fail-safe ссылки в карточке (параметризованный) | test_tracker_issue_link.py | AC-11 | PASS |
|
||||
| TC-12 | `plane_issue_link(...)` — ссылка/escape, никогда не бросает | test_plane_issue_link.py | AC-12 | PASS |
|
||||
| TC-13 | notify_approve_requested: номер кликабелен, одна нотификация | test_notify_issue_links.py | AC-13 | PASS |
|
||||
| TC-14 | notify_error: кликабелен/деградирует без падения | test_notify_issue_links.py | AC-13, AC-12 | PASS |
|
||||
| TC-15 | Точки send_telegram (stage_engine/launcher/merge_gate/job_reaper/security_gate/reconciler/main) используют хелпер | test_notify_issue_links.py | AC-13 | PASS |
|
||||
| TC-16 | HTML-экранирование title/`&`, валидность `<a>` | test_tracker_issue_link.py | AC-14 | PASS |
|
||||
| TC-17 | Инварианты транспорта: disable_notification, одна карточка | test_tracker_bump_default.py | AC-15 | PASS |
|
||||
| TC-18 | Нерегресс нотификаций + деградация для enduro-trails | test_notify_done_regression.py | AC-16, AC-17 | PASS |
|
||||
|
||||
Все 18 TC из тест-плана — PASS. Целевые модули: **57 passed**.
|
||||
|
||||
## Покрытие acceptance criteria
|
||||
AC-1..AC-18 — все покрыты соответствующими TC и зелёные. AC-17 (полный набор) подтверждён
|
||||
прогоном всего пакета.
|
||||
|
||||
## Вывод pytest (полный регресс)
|
||||
|
||||
```
|
||||
$ python -m pytest tests/ -v --tb=short
|
||||
...
|
||||
======================= 907 passed, 1 warning in 22.36s ========================
|
||||
```
|
||||
|
||||
Единственный warning — пре-существующий `PydanticDeprecatedSince20` в `src/config.py:4`
|
||||
(не относится к ORCH-067, не регресс).
|
||||
|
||||
Целевые модули задачи:
|
||||
```
|
||||
$ python -m pytest tests/test_tracker_bump_default.py tests/test_tracker_status_line.py \
|
||||
tests/test_tracker_issue_link.py tests/test_plane_issue_link.py \
|
||||
tests/test_notify_issue_links.py tests/test_notify_done_regression.py -q
|
||||
57 passed, 1 warning in 1.39s
|
||||
```
|
||||
|
||||
## Итог
|
||||
**PASS** — 907/907 тестов зелёные, все 18 TC и AC-1..AC-18 выполнены, smoke API OK,
|
||||
нерегресс для enduro-trails подтверждён. Задача готова к переходу на `deploy-staging`.
|
||||
12
docs/work-items/ORCH-067/14-deploy-log.md
Normal file
12
docs/work-items/ORCH-067/14-deploy-log.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
deploy_status: SUCCESS
|
||||
work_item: ORCH-067
|
||||
hook_exit_code: 0
|
||||
deployed_by: deploy-finalizer
|
||||
---
|
||||
|
||||
# Deploy log — ORCH-036 executable self-deploy
|
||||
|
||||
Прод-деплой завершён хост-хуком с exit-code `0` -> `deploy_status: SUCCESS`.
|
||||
|
||||
Вердикт зафиксирован детерминированным finalizer'ом (Фаза C), не LLM.
|
||||
14
docs/work-items/ORCH-067/16-post-deploy-log.md
Normal file
14
docs/work-items/ORCH-067/16-post-deploy-log.md
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
post_deploy_status: HEALTHY
|
||||
action_taken: NONE
|
||||
work_item: ORCH-067
|
||||
window_s: 900
|
||||
checks_total: 30
|
||||
checks_failed: 0
|
||||
---
|
||||
|
||||
# Post-deploy log — ORCH-021 post-deploy monitor
|
||||
|
||||
Наблюдение прода завершено: `post_deploy_status: HEALTHY`, `action_taken: NONE`.
|
||||
|
||||
Окно наблюдения: 900s; опросов всего: 30, из них с провалом: 0.
|
||||
7
docs/work-items/ORCH-069/00-business-request.md
Normal file
7
docs/work-items/ORCH-069/00-business-request.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Business Request: QG-0 title-лимит → параметр ORCH_QG0_TITLE_MAX (дефолт 200)
|
||||
|
||||
Work Item ID: ORCH-069
|
||||
|
||||
## Description
|
||||
|
||||
TBD
|
||||
76
docs/work-items/ORCH-069/01-brd.md
Normal file
76
docs/work-items/ORCH-069/01-brd.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# BRD — ORCH-069: QG-0 title-лимит → параметр ORCH_QG0_TITLE_MAX (дефолт 200)
|
||||
|
||||
Work Item ID: ORCH-069
|
||||
Тип: Enhancement (QoL / конфигурируемость)
|
||||
Источник: Слава, 2026-06-08
|
||||
Связано с: QG-0 (gate входа конвейера, `_qg0_errors`)
|
||||
|
||||
## 1. Проблема (As-Is)
|
||||
QG-0 — первый quality gate конвейера. Он валидирует заголовок и описание задачи
|
||||
до старта pipeline (`start_pipeline`) и в soft-режиме на `work_item.created`.
|
||||
|
||||
Верхний лимит длины заголовка задачи **захардкожен** в
|
||||
`src/webhooks/plane.py:362`:
|
||||
|
||||
```python
|
||||
if len(name) > 80:
|
||||
errors.append("Title слишком длинный (максимум 80 символов)")
|
||||
```
|
||||
|
||||
Лимит 80 — «гигиенический», а не структурный. Проверено, что **ниже по течению
|
||||
ничего от значения 80 не зависит**:
|
||||
- slug ветки режется независимо: `re.sub(...)[:30]` (`src/webhooks/plane.py:478`);
|
||||
- БД `tasks.title TEXT` — без ограничения длины;
|
||||
- Telegram-карточка использует `html.escape(title)` без обрезки;
|
||||
- Plane хранит `name` самостоятельно.
|
||||
|
||||
Следствие: вполне валидные осмысленные заголовки длиной 81–200 символов
|
||||
отклоняются на входе конвейера без бизнес-причины.
|
||||
|
||||
## 2. Цель (To-Be)
|
||||
Вынести верхний лимит длины заголовка QG-0 в конфигурируемый параметр со
|
||||
значением по умолчанию **200** (вместо текущего хардкода 80). Расширить лимит
|
||||
безопасно, сохранив возможность регулировать его через окружение, как и
|
||||
остальные `ORCH_*` настройки.
|
||||
|
||||
## 3. Бизнес-ценность
|
||||
- Меньше ложных отклонений валидных задач на входе конвейера (QoL для постановщика).
|
||||
- Лимит становится операционно настраиваемым без правки кода и редеплоя
|
||||
(изменение env-переменной).
|
||||
- Изменение чисто аддитивное и обратносовместимое: дефолт 200 > прежних 80, поэтому
|
||||
все заголовки, проходившие раньше, проходят и теперь.
|
||||
|
||||
## 4. Объём (Scope)
|
||||
### В объёме
|
||||
- Новый параметр Settings `qg0_title_max` (env `ORCH_QG0_TITLE_MAX`, дефолт 200).
|
||||
- Замена хардкода `> 80` на `> settings.qg0_title_max` в `_qg0_errors`.
|
||||
- Динамический текст ошибки с подстановкой актуального лимита.
|
||||
- Graceful-поведение при невалидном/пустом значении env → дефолт 200, без падения процесса.
|
||||
- Документация: `.env.example`, `.env.staging.example`, `CHANGELOG.md`,
|
||||
при необходимости README-таблица конфигов / `CLAUDE.md`.
|
||||
- Юнит-тесты на `_qg0_errors` с разными лимитами.
|
||||
|
||||
### Вне объёма (Out of scope)
|
||||
- Slug-логика `[:30]` (`src/webhooks/plane.py:478`) — самодостаточна, не трогать.
|
||||
- Нижний лимит заголовка (`< 5`) и лимит description (`< 20`) — оставить как есть.
|
||||
- Схема БД, реестры `STAGE_TRANSITIONS` / `QG_CHECKS`, контракты `handle_*`.
|
||||
- Soft-QG-0 на `work_item.created` (там только warning) — логика валидации общая
|
||||
(`_qg0_errors`), отдельных изменений не требует и не вносит.
|
||||
|
||||
## 5. Заинтересованные стороны
|
||||
- Owner / постановщик задач (Слава) — снижение ложных отклонений.
|
||||
- Агенты конвейера — поведение QG-0 при старте pipeline.
|
||||
|
||||
## 6. Ограничения и риски (self-hosting)
|
||||
- Правка касается работающего в проде инструмента (self-hosting). Прод-контейнер
|
||||
`orchestrator` в рамках задачи **не рестартить**; обязательна страховка
|
||||
`deploy-staging` (8501).
|
||||
- Риск минимален: изменение обратносовместимо, изолировано в одной функции и одном
|
||||
новом параметре config.
|
||||
|
||||
## 7. Допущения
|
||||
- Механизм чтения env — стандартный `pydantic_settings.BaseSettings` с
|
||||
`env_prefix = "ORCH_"`, как у остальных параметров.
|
||||
- «Невалидное/пустое значение → дефолт 200» — требование graceful-деградации:
|
||||
процесс не должен падать на старте из-за мусора в `ORCH_QG0_TITLE_MAX`
|
||||
(нюанс реализации pydantic-валидации передаётся архитектору, см. 02-trz §5).
|
||||
95
docs/work-items/ORCH-069/02-trz.md
Normal file
95
docs/work-items/ORCH-069/02-trz.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# ТЗ — ORCH-069: QG-0 title-лимит → параметр ORCH_QG0_TITLE_MAX (дефолт 200)
|
||||
|
||||
Work Item ID: ORCH-069
|
||||
|
||||
## 1. Задействованные модули `src/`
|
||||
| Файл | Текущее состояние | Требуемое изменение |
|
||||
|------|-------------------|---------------------|
|
||||
| `src/config.py` | `Settings(BaseSettings)`, `env_prefix = "ORCH_"` (строки 4, 347-349) | Добавить поле `qg0_title_max: int = 200` с комментарием-описанием. |
|
||||
| `src/webhooks/plane.py` | `_qg0_errors` (строки 357-367), хардкод `if len(name) > 80:` (строка 362); `from ..config import settings` уже импортирован (строка 11) | Заменить хардкод `> 80` на `> settings.qg0_title_max`; текст ошибки — динамический с подстановкой лимита. |
|
||||
|
||||
Других модулей изменение не затрагивает.
|
||||
|
||||
## 2. Изменение config.py
|
||||
Добавить в класс `Settings` новое поле (рядом с другими `ORCH_*` группами,
|
||||
рекомендуется отдельный блок с комментарием):
|
||||
|
||||
```python
|
||||
# ORCH-069: QG-0 upper title-length limit (entry gate _qg0_errors). The 80-char
|
||||
# cap was a hygiene limit, not structural (slug is cut to [:30] independently,
|
||||
# DB title TEXT is unbounded). Configurable via env ORCH_QG0_TITLE_MAX; default
|
||||
# 200 (was hardcoded 80). Invalid/empty value -> default (graceful, no crash).
|
||||
qg0_title_max: int = 200
|
||||
```
|
||||
|
||||
- Env-переменная: `ORCH_QG0_TITLE_MAX` (автоматически из `env_prefix = "ORCH_"`).
|
||||
- Тип `int`, дефолт `200`.
|
||||
|
||||
## 3. Изменение `_qg0_errors` (src/webhooks/plane.py)
|
||||
Текущий блок (строки 362-363):
|
||||
```python
|
||||
if len(name) > 80:
|
||||
errors.append("Title слишком длинный (максимум 80 символов)")
|
||||
```
|
||||
|
||||
Требуемое:
|
||||
```python
|
||||
if len(name) > settings.qg0_title_max:
|
||||
errors.append(
|
||||
f"Title слишком длинный (максимум {settings.qg0_title_max} символов)"
|
||||
)
|
||||
```
|
||||
|
||||
Требования:
|
||||
- Лимит берётся из `settings.qg0_title_max` (динамически, на каждый вызов — чтобы
|
||||
тесты могли подменять значение через мок/патч settings).
|
||||
- Текст ошибки содержит актуальное число лимита (для AC-1/AC-2: текст упоминает
|
||||
200 / 120 соответственно).
|
||||
- Нижний лимит заголовка `< 5` (строка 360-361) и проверка description `< 20`
|
||||
(строка 364-365) — **не трогать**.
|
||||
- Сигнатура `_qg0_errors(name, description) -> list` не меняется.
|
||||
|
||||
## 4. Поведение границы (точная семантика)
|
||||
- Условие fail — строго `len(name) > limit`. То есть `len == limit` → PASS,
|
||||
`len == limit + 1` → FAIL.
|
||||
- При дефолте: 200 символов → PASS, 201 → FAIL.
|
||||
- При `ORCH_QG0_TITLE_MAX=120`: 120 → PASS, 121 → FAIL.
|
||||
|
||||
## 5. Graceful-обработка невалидного значения (требование AC-3)
|
||||
Требование: невалидное/отсутствующее `ORCH_QG0_TITLE_MAX` → используется дефолт 200,
|
||||
процесс не падает.
|
||||
|
||||
Нюанс для архитектора/разработчика: `pydantic_settings` по умолчанию при
|
||||
непарсящемся в `int` значении env (например `ORCH_QG0_TITLE_MAX=abc` или пустая
|
||||
строка) выбрасывает `ValidationError` на инстанцировании `Settings()` —
|
||||
т.е. падение на старте процесса. Это противоречит требованию graceful.
|
||||
Реализация должна обеспечить, что:
|
||||
- отсутствие переменной → дефолт 200 (это стандартное поведение, ОК «из коробки»);
|
||||
- пустая строка / нечисловое значение → дефолт 200 без исключения.
|
||||
|
||||
Способ (на усмотрение архитектора, без предписания со стороны аналитика) —
|
||||
например field-validator с `mode="before"`, который при невалидном входе
|
||||
возвращает дефолт. Конкретный механизм фиксируется в ADR на стадии architecture.
|
||||
|
||||
## 6. Изменения API
|
||||
Нет. Эндпоинты не меняются.
|
||||
|
||||
## 7. Изменения схемы БД
|
||||
Нет. `tasks.title TEXT` остаётся без ограничения длины.
|
||||
|
||||
## 8. Новые QG checks
|
||||
Нет. Реестр `QG_CHECKS` и `STAGE_TRANSITIONS` не меняются. QG-0 — не зарегистрированный
|
||||
stage-gate, а inline-валидация входа (`_qg0_errors`), её контракт сохраняется.
|
||||
|
||||
## 9. Артефакты pipeline, которые должны быть созданы/обновлены
|
||||
- `.env.example` — добавить `ORCH_QG0_TITLE_MAX=200` с комментарием.
|
||||
- `.env.staging.example` — добавить `ORCH_QG0_TITLE_MAX` (дефолт/комментарий).
|
||||
- `CHANGELOG.md` — запись об ORCH-069.
|
||||
- README-таблица конфигов / `CLAUDE.md` — обновить при наличии релевантной таблицы
|
||||
параметров (по требованию reviewer; документация = golden source).
|
||||
- Юнит-тесты (`tests/`) — см. `04-test-plan.yaml`.
|
||||
|
||||
## 10. Обратная совместимость
|
||||
- Дефолт 200 > прежних 80 → все ранее проходившие заголовки проходят и теперь.
|
||||
- Поведение при не заданном env идентично «как было», но с порогом 200 вместо 80.
|
||||
- Изменение чисто аддитивное; откатов/миграций не требует.
|
||||
56
docs/work-items/ORCH-069/03-acceptance-criteria.md
Normal file
56
docs/work-items/ORCH-069/03-acceptance-criteria.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Критерии приёмки — ORCH-069
|
||||
|
||||
Work Item ID: ORCH-069
|
||||
|
||||
Формат: каждый критерий имеет чёткое условие PASS/FAIL.
|
||||
|
||||
## AC-1 — Дефолтный лимит 200, граница на 201
|
||||
**Дано:** env `ORCH_QG0_TITLE_MAX` не задан (используется дефолт 200), description валиден (≥ 20 символов).
|
||||
**Тогда:**
|
||||
- заголовок длиной 200 символов → `_qg0_errors` НЕ содержит ошибки про длину title (PASS);
|
||||
- заголовок длиной 201 символ → `_qg0_errors` содержит ошибку про длину title, и текст ошибки упоминает «200».
|
||||
**FAIL если:** на 200 появляется ошибка длины, либо на 201 ошибки нет, либо текст не упоминает 200.
|
||||
|
||||
## AC-2 — Настраиваемый лимит 120, граница на 121
|
||||
**Дано:** `ORCH_QG0_TITLE_MAX=120` (через мок/патч settings в тесте), description валиден.
|
||||
**Тогда:**
|
||||
- заголовок 120 символов → нет ошибки длины title (PASS);
|
||||
- заголовок 121 символ → есть ошибка длины title, текст упоминает «120».
|
||||
**FAIL если:** граница срабатывает не на 121, либо текст ошибки упоминает не 120.
|
||||
|
||||
## AC-3 — Graceful при невалидном/пустом значении
|
||||
**Дано:** `ORCH_QG0_TITLE_MAX` пустой (`""`) или нечисловой (`"abc"`).
|
||||
**Тогда:**
|
||||
- инстанцирование `Settings()` / импорт приложения НЕ выбрасывает исключение (процесс не падает);
|
||||
- эффективное значение лимита = дефолт 200 (поведение AC-1 сохраняется).
|
||||
**FAIL если:** старт процесса падает с `ValidationError`, либо лимит != 200.
|
||||
|
||||
## AC-4 — Нижние лимиты не сломаны
|
||||
**Дано:** любое валидное значение `ORCH_QG0_TITLE_MAX`.
|
||||
**Тогда:**
|
||||
- заголовок длиной < 5 символов → `_qg0_errors` содержит ошибку «Title слишком короткий»;
|
||||
- description длиной < 20 символов → `_qg0_errors` содержит ошибку «Description слишком короткий».
|
||||
**FAIL если:** нижний лимит title или лимит description перестал срабатывать.
|
||||
|
||||
## AC-5 — Юнит-тесты зелёные
|
||||
**Дано:** реализованные юнит-тесты на `_qg0_errors` с разными значениями лимита (мок settings).
|
||||
**Тогда:** `pytest tests/ -q` проходит полностью (зелёный), включая новые тесты ORCH-069 и существующий набор.
|
||||
**FAIL если:** хотя бы один тест падает.
|
||||
|
||||
## AC-6 — Документация обновлена в том же PR
|
||||
**Дано:** PR с изменениями кода.
|
||||
**Тогда в том же PR:**
|
||||
- `.env.example` содержит `ORCH_QG0_TITLE_MAX` с дефолтом и комментарием;
|
||||
- `.env.staging.example` содержит `ORCH_QG0_TITLE_MAX`;
|
||||
- `CHANGELOG.md` содержит запись об ORCH-069;
|
||||
- при наличии релевантной таблицы конфигов в README / `CLAUDE.md` — она обновлена.
|
||||
**FAIL если:** какой-либо из обязательных файлов документации не обновлён (reviewer → REQUEST_CHANGES).
|
||||
|
||||
## AC-7 — Обратная совместимость
|
||||
**Дано:** env не задан.
|
||||
**Тогда:** любой заголовок, который проходил QG-0 при прежнем лимите 80 (len ≤ 80), проходит и теперь (len ≤ 200).
|
||||
**FAIL если:** ранее валидный заголовок отклоняется.
|
||||
|
||||
## AC-8 — Изоляция изменений
|
||||
**Тогда:** не изменены slug-логика (`[:30]`), схема БД, реестры `STAGE_TRANSITIONS` / `QG_CHECKS`, контракты `handle_*`, soft-QG-0 поведение (warning на `work_item.created`).
|
||||
**FAIL если:** затронут любой из перечисленных вне-объёмных элементов.
|
||||
112
docs/work-items/ORCH-069/04-test-plan.yaml
Normal file
112
docs/work-items/ORCH-069/04-test-plan.yaml
Normal file
@@ -0,0 +1,112 @@
|
||||
work_item: ORCH-069
|
||||
description: >
|
||||
Юнит-тесты для конфигурируемого верхнего лимита длины заголовка QG-0
|
||||
(_qg0_errors) через параметр settings.qg0_title_max (env ORCH_QG0_TITLE_MAX,
|
||||
дефолт 200). Тесты патчат settings.qg0_title_max (monkeypatch на объекте
|
||||
src.config.settings, который импортирован в src.webhooks.plane) и проверяют
|
||||
границы и тексты ошибок. Файл тестов: tests/test_qg0_title_limit.py.
|
||||
|
||||
tests:
|
||||
- id: TC-01
|
||||
type: unit
|
||||
description: "Дефолтный лимит 200: заголовок ровно 200 символов -> нет ошибки длины title (PASS на границе)."
|
||||
module: tests/test_qg0_title_limit.py
|
||||
setup: "settings.qg0_title_max=200 (дефолт); name='x'*200; description валиден (>=20 символов)."
|
||||
assert: "В списке _qg0_errors нет элемента про длину title."
|
||||
covers: [AC-1]
|
||||
expected: PASS
|
||||
|
||||
- id: TC-02
|
||||
type: unit
|
||||
description: "Дефолтный лимит 200: заголовок 201 символ -> ошибка длины title, текст упоминает '200'."
|
||||
module: tests/test_qg0_title_limit.py
|
||||
setup: "settings.qg0_title_max=200; name='x'*201; description валиден."
|
||||
assert: "В _qg0_errors есть ошибка длины title и её текст содержит подстроку '200'."
|
||||
covers: [AC-1]
|
||||
expected: PASS
|
||||
|
||||
- id: TC-03
|
||||
type: unit
|
||||
description: "Настраиваемый лимит 120: заголовок 120 символов -> нет ошибки длины title."
|
||||
module: tests/test_qg0_title_limit.py
|
||||
setup: "monkeypatch settings.qg0_title_max=120; name='x'*120; description валиден."
|
||||
assert: "Нет ошибки длины title."
|
||||
covers: [AC-2]
|
||||
expected: PASS
|
||||
|
||||
- id: TC-04
|
||||
type: unit
|
||||
description: "Настраиваемый лимит 120: заголовок 121 символ -> ошибка длины title, текст упоминает '120'."
|
||||
module: tests/test_qg0_title_limit.py
|
||||
setup: "monkeypatch settings.qg0_title_max=120; name='x'*121; description валиден."
|
||||
assert: "Есть ошибка длины title и её текст содержит подстроку '120' (и НЕ '80')."
|
||||
covers: [AC-2]
|
||||
expected: PASS
|
||||
|
||||
- id: TC-05
|
||||
type: unit
|
||||
description: "Graceful: невалидное (нечисловое) значение env ORCH_QG0_TITLE_MAX не роняет инстанцирование Settings и даёт дефолт 200."
|
||||
module: tests/test_qg0_title_limit.py
|
||||
setup: "monkeypatch.setenv('ORCH_QG0_TITLE_MAX','abc'); создать новый экземпляр Settings()."
|
||||
assert: "Settings() не выбрасывает исключение; settings.qg0_title_max == 200."
|
||||
covers: [AC-3]
|
||||
expected: PASS
|
||||
|
||||
- id: TC-06
|
||||
type: unit
|
||||
description: "Graceful: пустая строка env ORCH_QG0_TITLE_MAX -> дефолт 200, без исключения."
|
||||
module: tests/test_qg0_title_limit.py
|
||||
setup: "monkeypatch.setenv('ORCH_QG0_TITLE_MAX',''); создать новый экземпляр Settings()."
|
||||
assert: "Settings() не падает; settings.qg0_title_max == 200."
|
||||
covers: [AC-3]
|
||||
expected: PASS
|
||||
|
||||
- id: TC-07
|
||||
type: unit
|
||||
description: "Корректное числовое env -> применяется заданное значение (sanity положительного пути)."
|
||||
module: tests/test_qg0_title_limit.py
|
||||
setup: "monkeypatch.setenv('ORCH_QG0_TITLE_MAX','150'); создать новый экземпляр Settings()."
|
||||
assert: "settings.qg0_title_max == 150."
|
||||
covers: [AC-2, AC-3]
|
||||
expected: PASS
|
||||
|
||||
- id: TC-08
|
||||
type: unit
|
||||
description: "Нижний лимит title не сломан: заголовок < 5 символов -> ошибка 'Title слишком короткий' при любом верхнем лимите."
|
||||
module: tests/test_qg0_title_limit.py
|
||||
setup: "settings.qg0_title_max=200; name='abc' (3 символа); description валиден."
|
||||
assert: "В _qg0_errors есть ошибка короткого title."
|
||||
covers: [AC-4]
|
||||
expected: PASS
|
||||
|
||||
- id: TC-09
|
||||
type: unit
|
||||
description: "Лимит description не сломан: description < 20 символов -> ошибка 'Description слишком короткий'."
|
||||
module: tests/test_qg0_title_limit.py
|
||||
setup: "settings.qg0_title_max=200; name валиден (>=5, <=200); description='short'."
|
||||
assert: "В _qg0_errors есть ошибка короткого description."
|
||||
covers: [AC-4]
|
||||
expected: PASS
|
||||
|
||||
- id: TC-10
|
||||
type: unit
|
||||
description: "Обратная совместимость: заголовок длиной 81-200 (ранее отклонялся лимитом 80) теперь проходит при дефолте."
|
||||
module: tests/test_qg0_title_limit.py
|
||||
setup: "settings.qg0_title_max=200; name='x'*100; description валиден."
|
||||
assert: "Нет ошибки длины title (раньше при лимите 80 была бы)."
|
||||
covers: [AC-7]
|
||||
expected: PASS
|
||||
|
||||
- id: TC-11
|
||||
type: unit
|
||||
description: "Полный набор тестов зелёный (регрессия не внесена)."
|
||||
module: tests/
|
||||
command: "pytest tests/ -q"
|
||||
assert: "Все тесты проходят."
|
||||
covers: [AC-5]
|
||||
expected: PASS
|
||||
|
||||
notes:
|
||||
- "settings импортирован в src.webhooks.plane как 'from ..config import settings', _qg0_errors читает settings.qg0_title_max динамически -> monkeypatch на src.config.settings.qg0_title_max (или импортируемом объекте) меняет поведение в рамках теста."
|
||||
- "Для TC-05/06/07 нужен СВЕЖИЙ экземпляр Settings(): глобальный src.config.settings создаётся один раз на импорт, поэтому env-тесты инстанцируют Settings() локально, а не полагаются на готовый синглтон."
|
||||
- "Тесты не требуют сети, БД, агентов или FastAPI TestClient — чистая проверка leaf-функции _qg0_errors и парсинга Settings."
|
||||
@@ -0,0 +1,143 @@
|
||||
# ADR-001: Конфигурируемый QG-0 title-лимит с graceful-деградацией env
|
||||
|
||||
## Статус
|
||||
Accepted
|
||||
|
||||
## Контекст
|
||||
QG-0 — inline-валидация входа конвейера (`_qg0_errors` в `src/webhooks/plane.py`),
|
||||
вызывается из `start_pipeline` (hard-блок) и из `handle_work_item_created`
|
||||
(soft-warning). Верхний лимит длины заголовка захардкожен: `if len(name) > 80`.
|
||||
|
||||
BRD/ТЗ (ORCH-069) установили, что лимит 80 — гигиенический, а не структурный:
|
||||
ниже по течению от него ничего не зависит (slug режется независимо `[:30]`,
|
||||
`tasks.title TEXT` без ограничения, Telegram/Plane хранят/экранируют сами).
|
||||
Валидные заголовки 81–200 символов отклоняются на входе без бизнес-причины.
|
||||
|
||||
Требуется:
|
||||
1. Вынести лимит в конфигурируемый параметр `ORCH_QG0_TITLE_MAX`, дефолт 200.
|
||||
2. **Graceful-деградация** (AC-3): пустое/нечисловое значение env → дефолт 200
|
||||
**без падения процесса**. Это и есть единственное нетривиальное архитектурное
|
||||
решение задачи: `pydantic_settings` v2 по умолчанию при непарсящемся в `int`
|
||||
значении env бросает `ValidationError` на инстанцировании `Settings()` —
|
||||
т.е. краш на старте контейнера (`settings = Settings()` на module-import,
|
||||
`src/config.py:352`). Для self-hosting это означало бы падение прод-инструмента
|
||||
из-за опечатки в env — недопустимо.
|
||||
|
||||
Стек подтверждён: `pydantic==2.13.4`, `pydantic-settings==2.5.0` (v2 API).
|
||||
|
||||
## Решение
|
||||
|
||||
### Р-1. Новый параметр Settings
|
||||
В `src/config.py`, в класс `Settings`, добавить поле (отдельный блок с
|
||||
комментарием, рядом с прочими `ORCH_*`):
|
||||
|
||||
```python
|
||||
# ORCH-069: QG-0 upper title-length limit (entry gate _qg0_errors).
|
||||
# 80-char cap was a hygiene limit, not structural. Env ORCH_QG0_TITLE_MAX;
|
||||
# default 200 (was hardcoded 80). Invalid/empty -> default (graceful, no crash).
|
||||
qg0_title_max: int = 200
|
||||
```
|
||||
Env-имя выводится автоматически из `env_prefix = "ORCH_"` → `ORCH_QG0_TITLE_MAX`.
|
||||
|
||||
### Р-2. Механизм graceful-деградации — `field_validator(mode="before")`
|
||||
Выбран **pydantic v2 `field_validator` с `mode="before"`** как
|
||||
минимально-инвазивный, локальный для одного поля механизм. Валидатор перехватывает
|
||||
сырое значение env ДО стандартного `int`-парсинга и при невалидном/пустом входе
|
||||
возвращает дефолт `200`, гася `ValidationError`:
|
||||
|
||||
```python
|
||||
from pydantic import field_validator
|
||||
|
||||
@field_validator("qg0_title_max", mode="before")
|
||||
@classmethod
|
||||
def _qg0_title_max_default(cls, v):
|
||||
# Graceful (ORCH-069 AC-3): empty / non-numeric env -> default 200,
|
||||
# process must not crash on startup. Never raises.
|
||||
try:
|
||||
if v is None or (isinstance(v, str) and v.strip() == ""):
|
||||
return 200
|
||||
return int(v)
|
||||
except (TypeError, ValueError):
|
||||
return 200
|
||||
```
|
||||
|
||||
Семантика:
|
||||
- переменная не задана → pydantic не вызывает validator с env, берётся дефолт поля
|
||||
`200` (стандартное поведение «из коробки»);
|
||||
- `""`, `"abc"`, мусор → validator возвращает `200`, исключения нет;
|
||||
- `"120"` → `int("120") == 120`.
|
||||
|
||||
**Почему именно так (рассмотренные альтернативы):**
|
||||
- *`Optional[int] + None-fallback на месте чтения`* — отвергнуто: размазывает
|
||||
дефолт по call-site'ам, легко забыть, тип поля перестаёт быть «честным `int`».
|
||||
- *try/except вокруг `Settings()` на module-level* — отвергнуто: глушит ВСЕ
|
||||
ошибки конфигурации (маскирует реальные проблемы других полей), слишком грубо.
|
||||
- *кастомный тип / `Annotated`-валидатор* — избыточно для одного поля.
|
||||
- `field_validator(mode="before")` локален, не трогает остальные поля, не меняет
|
||||
публичный тип `int`, тестируется напрямую через `Settings(qg0_title_max=...)` и
|
||||
env-патч. Контракт «never-raise» консистентен с общим стилем кодовой базы
|
||||
(`_qg0_errors`, парсеры — defensive).
|
||||
|
||||
### Р-3. Использование лимита в `_qg0_errors`
|
||||
Хардкод `> 80` → динамическое чтение `settings.qg0_title_max` **на каждый вызов**
|
||||
(чтобы тест мог патчить `settings`), текст ошибки — f-string с актуальным числом:
|
||||
|
||||
```python
|
||||
if len(name) > settings.qg0_title_max:
|
||||
errors.append(
|
||||
f"Title слишком длинный (максимум {settings.qg0_title_max} символов)"
|
||||
)
|
||||
```
|
||||
`settings` уже импортирован в `plane.py`. Сигнатура `_qg0_errors(name, description)
|
||||
-> list` не меняется. Нижние лимиты (`< 5` title, `< 20` description) — без правок.
|
||||
|
||||
Граница (ТЗ §4): fail строго при `len(name) > limit` → `len == limit` PASS,
|
||||
`limit + 1` FAIL.
|
||||
|
||||
### Р-4. Что НЕ меняется (инварианты)
|
||||
- `STAGE_TRANSITIONS`, `QG_CHECKS` — QG-0 не зарегистрированный stage-gate, а
|
||||
inline-валидация; реестры не трогаются.
|
||||
- Схема БД (`tasks.title TEXT`), API, контракты `handle_*`, slug-логика `[:30]`,
|
||||
soft-QG-0 поведение (общая функция `_qg0_errors`, отдельной правки не требует).
|
||||
- Топология/инфраструктура (`07-infra-requirements.md` — **N/A**) и схема данных
|
||||
(`08-data-requirements.md` — **N/A**) не затрагиваются.
|
||||
|
||||
## Последствия
|
||||
|
||||
### Плюсы
|
||||
- Лимит операционно настраивается через env без правки кода и редеплоя кода.
|
||||
- Чисто аддитивно и обратносовместимо: дефолт 200 > прежних 80 → все ранее
|
||||
проходившие заголовки проходят (AC-7).
|
||||
- Опечатка в `ORCH_QG0_TITLE_MAX` не роняет прод-процесс (критично для
|
||||
self-hosting): graceful-fallback на 200.
|
||||
- Изменение изолировано в одной функции + одном поле config + одном валидаторе.
|
||||
|
||||
### Минусы / ограничения
|
||||
- Невалидное env «тихо» проглатывается → оператор не сразу заметит опечатку
|
||||
(лимит молча станет 200). Принято как осознанный trade-off: устойчивость
|
||||
процесса важнее громкости (consistency с требованием AC-3). Рекомендация:
|
||||
при желании усилить наблюдаемость — `logger.warning` в validator; **не вводим**
|
||||
по умолчанию, т.к. на этапе валидации settings логгер может быть не сконфигурён,
|
||||
и это вне объёма ORCH-069 (можно отдельной QoL-задачей).
|
||||
- Дефолт 200 — тоже эвристика; структурного верхнего предела по-прежнему нет
|
||||
(его и не требуется — БД/slug/UI к длине устойчивы).
|
||||
|
||||
### Влияние на self-hosting
|
||||
Прод-контейнер `orchestrator` **не рестартить** в рамках задачи. Изменение
|
||||
прокатывается штатно через обязательный `deploy-staging`-гейт (8501) перед
|
||||
прод-деплоем. Риск отказа на старте после деплоя снят самим механизмом Р-2
|
||||
(graceful), что дополнительно снижает self-hosting-риск.
|
||||
|
||||
### Тестируемость (вход для стадий development/testing)
|
||||
- `_qg0_errors`: патч `settings.qg0_title_max` → проверка границ 200/201 (AC-1),
|
||||
120/121 (AC-2), нижних лимитов (AC-4).
|
||||
- validator: `Settings(qg0_title_max="abc")` / `=""` / env-патч → значение 200,
|
||||
без исключения (AC-3).
|
||||
|
||||
## Ссылки
|
||||
- BRD: `docs/work-items/ORCH-069/01-brd.md`
|
||||
- ТЗ: `docs/work-items/ORCH-069/02-trz.md`
|
||||
- Acceptance: `docs/work-items/ORCH-069/03-acceptance-criteria.md`
|
||||
- Тех-риски: `docs/work-items/ORCH-069/10-tech-risks.md`
|
||||
</content>
|
||||
</invoke>
|
||||
21
docs/work-items/ORCH-069/10-tech-risks.md
Normal file
21
docs/work-items/ORCH-069/10-tech-risks.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Технические риски — ORCH-069
|
||||
|
||||
Work Item ID: ORCH-069
|
||||
Уровень общего риска: **низкий** (аддитивное, обратносовместимое, изолированное изменение).
|
||||
|
||||
| # | Риск | Вероятность | Влияние | Митигация |
|
||||
|---|------|-------------|---------|-----------|
|
||||
| R-1 | `ValidationError` на старте при мусоре в `ORCH_QG0_TITLE_MAX` → краш прод-процесса (self-hosting) | Средняя (опечатка в env) | Высокое (падение инструмента всех проектов) | `field_validator(mode="before")` гасит невалидный вход → дефолт 200 (ADR Р-2, AC-3). never-raise. |
|
||||
| R-2 | Чтение лимита один раз на module-import вместо per-call → тесты не смогут патчить settings | Низкая | Среднее (нетестируемость AC-2) | `_qg0_errors` читает `settings.qg0_title_max` динамически на каждый вызов (ADR Р-3). |
|
||||
| R-3 | Off-by-one на границе (`>=` вместо `>`) | Низкая | Низкое (1 символ) | Явная семантика `len > limit` зафиксирована (ТЗ §4, AC-1/AC-2); тесты на 200/201, 120/121. |
|
||||
| R-4 | Регресс нижних лимитов (`< 5` title, `< 20` description) при правке функции | Низкая | Среднее | Трогать только верхний лимит; AC-4 покрывает нижние; диф минимален. |
|
||||
| R-5 | Тихое проглатывание невалидного env → оператор не заметит опечатку | Средняя | Низкое (лимит молча = 200, конвейер работает) | Осознанный trade-off (ADR «Минусы»): устойчивость > громкость. Опц. `logger.warning` — вне объёма. |
|
||||
| R-6 | Случайное затрагивание вне-объёмных элементов (slug `[:30]`, БД, реестры, `handle_*`, soft-QG-0) | Низкая | Среднее | AC-8 — изоляция; reviewer проверяет диф; ADR Р-4 фиксирует инварианты. |
|
||||
| R-7 | Документация не обновлена в том же PR (`.env.example`, `.env.staging.example`, `CHANGELOG.md`) | Средняя | Среднее (reviewer REQUEST_CHANGES) | AC-6 чек-лист; документация = golden source (правило 2 CLAUDE.md). |
|
||||
|
||||
## Не-риски (явно)
|
||||
- Схема БД — не меняется (`tasks.title TEXT` без ограничения).
|
||||
- API/эндпоинты — не меняются.
|
||||
- Топология/контейнеры/порты — не меняются.
|
||||
- Откат/миграция — не требуется (дефолт 200 > 80, чисто аддитивно).
|
||||
</content>
|
||||
68
docs/work-items/ORCH-069/12-review.md
Normal file
68
docs/work-items/ORCH-069/12-review.md
Normal file
@@ -0,0 +1,68 @@
|
||||
---
|
||||
type: review
|
||||
work_item_id: ORCH-069
|
||||
verdict: APPROVED
|
||||
version: 3
|
||||
---
|
||||
|
||||
# Review ORCH-069
|
||||
|
||||
## Summary
|
||||
Реализация конфигурируемого QG-0 title-лимита `ORCH_QG0_TITLE_MAX` (дефолт 200)
|
||||
выполнена **дословно по ТЗ/ADR** и качественно. Поле `Settings.qg0_title_max`,
|
||||
graceful `field_validator(mode="before")` (never-raise → дефолт 200), динамическое
|
||||
чтение `settings.qg0_title_max` в `_qg0_errors` с f-string-текстом ошибки. Код
|
||||
изолирован (затронуты только `src/config.py` и `src/webhooks/plane.py`), инварианты
|
||||
не нарушены, нижние лимиты сохранены. Свежий полный прогон на текущем состоянии
|
||||
ветки: `pytest tests/ -q` → **863 passed** (включая 10 новых тестов ORCH-069,
|
||||
файл `tests/test_qg0_title_limit.py`, все зелёные). Документация обновлена в том же
|
||||
PR полностью. Блокирующих и must-fix findings нет → **APPROVED**.
|
||||
|
||||
## Соответствие ТЗ / ADR
|
||||
- `src/config.py` — поле `qg0_title_max: int = 200` + валидатор `_qg0_title_max_default`
|
||||
(`mode="before"`, try/except → 200 при `None`/пустой/нечисловой): 1:1 с ADR Р-1/Р-2
|
||||
и ТЗ §2/§5. ✓
|
||||
- `src/webhooks/plane.py` — хардкод `> 80` заменён на `> settings.qg0_title_max`,
|
||||
текст ошибки динамический (f-string с актуальным числом); сигнатура `_qg0_errors`,
|
||||
нижний лимит title `< 5`, проверка description `< 20` не тронуты: ADR Р-3, ТЗ §3/§4. ✓
|
||||
- Граница строгая (`len == limit` PASS, `limit+1` FAIL) — подтверждена tc01–tc04. ✓
|
||||
- Инварианты (ADR Р-4 / AC-8): `STAGE_TRANSITIONS`, `QG_CHECKS`, схема БД, slug `[:30]`,
|
||||
soft-QG-0, API — НЕ изменены (diff `src/` = только 2 файла). ✓
|
||||
|
||||
## Acceptance criteria
|
||||
- AC-1 (дефолт 200, граница 201, текст упоминает 200) — tc01/tc02 ✓
|
||||
- AC-2 (лимит 120, граница 121, текст 120 не 80) — tc03/tc04 ✓
|
||||
- AC-3 (graceful пустое/`abc` → 200 без краха) — tc05/tc06 + позитив tc07 + валидатор ✓
|
||||
- AC-4 (нижние лимиты title<5 / desc<20) — tc08/tc09 ✓
|
||||
- AC-5 (pytest зелёный) — 863 passed ✓
|
||||
- AC-6 (документация в том же PR) — выполнен полностью ✓
|
||||
- AC-7 (обратная совместимость, ≤80 проходит при 200) — tc10 ✓
|
||||
- AC-8 (изоляция изменений) — ✓
|
||||
|
||||
## Findings
|
||||
|
||||
### P0 — Blocker
|
||||
- (нет)
|
||||
|
||||
### P1 — Must fix
|
||||
- (нет)
|
||||
|
||||
### P2 — Should fix
|
||||
- (нет)
|
||||
|
||||
### P3 — Nice-to-have (не блокирует)
|
||||
- В конце `06-adr/ADR-001-configurable-qg0-title-limit.md` присутствуют артефактные
|
||||
хвостовые теги (`</content>`, `</invoke>`). Косметика в артефакте стадии architecture;
|
||||
на корректность кода/контракта не влияет. Править артефакт чужой стадии в рамках
|
||||
ревью не уполномочен — отмечено для будущей чистки.
|
||||
|
||||
## Документация
|
||||
- `.env.example` — добавлен `ORCH_QG0_TITLE_MAX=200` с комментарием. ✓
|
||||
- `.env.staging.example` — добавлен `ORCH_QG0_TITLE_MAX=200`. ✓
|
||||
- `CHANGELOG.md` — подробная запись об ORCH-069 (раздел Added). ✓
|
||||
- `README.md` — таблица env-конфигов дополнена строкой `ORCH_QG0_TITLE_MAX`. ✓
|
||||
- ADR `06-adr/ADR-001-configurable-qg0-title-limit.md` — присутствует, согласован
|
||||
с кодом. ✓
|
||||
- `docs/architecture/README.md` / `CLAUDE.md` — обновления не требуют (QG-0 — inline
|
||||
soft/hard-валидация входа, не зарегистрированный stage-gate; API/стадии/QG-реестр
|
||||
не менялись). ОК.
|
||||
98
docs/work-items/ORCH-069/13-test-report.md
Normal file
98
docs/work-items/ORCH-069/13-test-report.md
Normal file
@@ -0,0 +1,98 @@
|
||||
---
|
||||
type: test-report
|
||||
work_item_id: ORCH-069
|
||||
result: PASS
|
||||
---
|
||||
|
||||
# Test Report — ORCH-069
|
||||
|
||||
QG-0 title-лимит → параметр `ORCH_QG0_TITLE_MAX` (дефолт 200)
|
||||
|
||||
## Окружение
|
||||
- Python: 3.12.13
|
||||
- pytest: 8.3.3 (plugins: anyio-4.13.0, asyncio-0.23.8; asyncio mode=auto)
|
||||
- Ветка: `feature/ORCH-069-qg-0-title-orch-qg0-title-max-`
|
||||
- Worktree: `/repos/_wt/orchestrator/feature_ORCH-069-qg-0-title-orch-qg0-title-max-`
|
||||
- Prod-health (8500): `{"status":"ok","service":"orchestrator"}` — не трогался (self-hosting safety)
|
||||
- Дата: 2026-06-08
|
||||
|
||||
## Предусловия
|
||||
- Review-вердикт `12-review.md`: **APPROVED** (version 3) ✓
|
||||
- Изменения изолированы: `src/config.py`, `src/webhooks/plane.py` (+ тесты, + документация)
|
||||
|
||||
## Результаты по тест-плану (04-test-plan.yaml)
|
||||
|
||||
| TC ID | Описание | Покрывает | Результат |
|
||||
|-------|----------|-----------|-----------|
|
||||
| TC-01 | Дефолт 200: title=200 → нет ошибки длины (граница PASS) | AC-1 | PASS |
|
||||
| TC-02 | Дефолт 200: title=201 → ошибка длины, текст упоминает «200» | AC-1 | PASS |
|
||||
| TC-03 | Лимит 120: title=120 → нет ошибки длины | AC-2 | PASS |
|
||||
| TC-04 | Лимит 120: title=121 → ошибка, текст «120» (не «80») | AC-2 | PASS |
|
||||
| TC-05 | Graceful: env `abc` → дефолт 200, без краха `Settings()` | AC-3 | PASS |
|
||||
| TC-06 | Graceful: пустой env `""` → дефолт 200, без исключения | AC-3 | PASS |
|
||||
| TC-07 | Валидный env `150` → применяется 150 (позитивный путь) | AC-2, AC-3 | PASS |
|
||||
| TC-08 | Нижний лимит title < 5 не сломан | AC-4 | PASS |
|
||||
| TC-09 | Лимит description < 20 не сломан | AC-4 | PASS |
|
||||
| TC-10 | Обратная совместимость: title 81–200 проходит при дефолте | AC-7 | PASS |
|
||||
| TC-11 | Полный набор тестов зелёный (нет регрессии) | AC-5 | PASS |
|
||||
|
||||
## Сопоставление с критериями приёмки (03-acceptance-criteria.md)
|
||||
|
||||
| AC | Критерий | Статус |
|
||||
|----|----------|--------|
|
||||
| AC-1 | Дефолт 200, граница на 201, текст упоминает 200 | PASS (TC-01/02) |
|
||||
| AC-2 | Настраиваемый лимит 120, граница 121, текст 120 | PASS (TC-03/04/07) |
|
||||
| AC-3 | Graceful при пустом/нечисловом значении → 200 | PASS (TC-05/06) |
|
||||
| AC-4 | Нижние лимиты title<5 / description<20 не сломаны | PASS (TC-08/09) |
|
||||
| AC-5 | Юнит-тесты зелёные (весь набор) | PASS (863 passed) |
|
||||
| AC-6 | Документация в том же PR (.env.example, .env.staging.example, CHANGELOG, README) | PASS (подтверждено review) |
|
||||
| AC-7 | Обратная совместимость (≤80 проходит при 200) | PASS (TC-10) |
|
||||
| AC-8 | Изоляция: slug `[:30]`, БД, STAGE_TRANSITIONS/QG_CHECKS, handle_* не тронуты | PASS (diff = 2 файла src/) |
|
||||
|
||||
## Smoke test API (prod 8500, read-only)
|
||||
- `GET /health` → `{"status":"ok","service":"orchestrator"}` — OK
|
||||
- `GET /status` → отдаёт активные задачи (ORCH-069 в стадии `testing`) — OK
|
||||
- `GET /queue` → `counts: queued=0 running=1 done=459 failed=4 cancelled=1`; breaker `closed`, preflight ok — OK
|
||||
|
||||
## Целевой прогон ORCH-069 (tests/test_qg0_title_limit.py)
|
||||
```
|
||||
collected 10 items
|
||||
|
||||
tests/test_qg0_title_limit.py::test_tc01_default_limit_200_boundary_pass PASSED
|
||||
tests/test_qg0_title_limit.py::test_tc02_default_limit_200_boundary_fail PASSED
|
||||
tests/test_qg0_title_limit.py::test_tc03_custom_limit_120_boundary_pass PASSED
|
||||
tests/test_qg0_title_limit.py::test_tc04_custom_limit_120_boundary_fail PASSED
|
||||
tests/test_qg0_title_limit.py::test_tc05_graceful_non_numeric_env PASSED
|
||||
tests/test_qg0_title_limit.py::test_tc06_graceful_empty_env PASSED
|
||||
tests/test_qg0_title_limit.py::test_tc07_valid_numeric_env PASSED
|
||||
tests/test_qg0_title_limit.py::test_tc08_short_title_still_errors PASSED
|
||||
tests/test_qg0_title_limit.py::test_tc09_short_description_still_errors PASSED
|
||||
tests/test_qg0_title_limit.py::test_tc10_backward_compat_titles_81_to_200 PASSED
|
||||
|
||||
======================== 10 passed, 1 warning in 0.31s =========================
|
||||
```
|
||||
|
||||
## Полный прогон (pytest tests/ -q)
|
||||
```
|
||||
........................................................................ [ 8%]
|
||||
........................................................................ [ 16%]
|
||||
........................................................................ [ 25%]
|
||||
........................................................................ [ 33%]
|
||||
........................................................................ [ 41%]
|
||||
........................................................................ [ 50%]
|
||||
........................................................................ [ 58%]
|
||||
........................................................................ [ 66%]
|
||||
........................................................................ [ 75%]
|
||||
........................................................................ [ 83%]
|
||||
........................................................................ [ 91%]
|
||||
....................................................................... [100%]
|
||||
863 passed, 1 warning in 21.49s
|
||||
```
|
||||
|
||||
(Единственный warning — PydanticDeprecatedSince20 в `src/config.py:5`, существующий
|
||||
class-based config; к ORCH-069 не относится, не является ошибкой.)
|
||||
|
||||
## Итог
|
||||
**PASS** — все 11 TC из тест-плана пройдены, все 8 критериев приёмки выполнены,
|
||||
полный регресс зелёный (863 passed), smoke-тесты API OK. Регрессии не внесены.
|
||||
Задача готова к переходу на стадию `deploy-staging`.
|
||||
12
docs/work-items/ORCH-069/14-deploy-log.md
Normal file
12
docs/work-items/ORCH-069/14-deploy-log.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
deploy_status: SUCCESS
|
||||
work_item: ORCH-069
|
||||
hook_exit_code: 0
|
||||
deployed_by: deploy-finalizer
|
||||
---
|
||||
|
||||
# Deploy log — ORCH-036 executable self-deploy
|
||||
|
||||
Прод-деплой завершён хост-хуком с exit-code `0` -> `deploy_status: SUCCESS`.
|
||||
|
||||
Вердикт зафиксирован детерминированным finalizer'ом (Фаза C), не LLM.
|
||||
25
docs/work-items/ORCH-069/17-security-report.md
Normal file
25
docs/work-items/ORCH-069/17-security-report.md
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
security_status: PASS
|
||||
secrets_found: 0
|
||||
deps_blocking: 0
|
||||
deps_warning: 4
|
||||
deps_audit_degraded: false
|
||||
---
|
||||
# Security Report — ORCH-069
|
||||
|
||||
Детерминированный security-гейт (ORCH-022): secret-scanning (gitleaks, offline) + dependency audit (pip-audit). Машинный вердикт читается ТОЛЬКО из frontmatter выше.
|
||||
|
||||
## Verdict
|
||||
clean: 0 secrets, 0 blocking CVE(s)
|
||||
|
||||
## Secrets
|
||||
- None
|
||||
|
||||
## Dependencies (blocking)
|
||||
- None
|
||||
|
||||
## Dependencies (warning)
|
||||
- `pytest==8.3.3` — GHSA-6w46-j5rx-g56g severity=UNKNOWN fix=9.0.3
|
||||
- `starlette==0.38.6` — PYSEC-2026-161 severity=UNKNOWN fix=1.0.1
|
||||
- `starlette==0.38.6` — GHSA-f96h-pmfr-66vw severity=UNKNOWN fix=0.40.0
|
||||
- `starlette==0.38.6` — GHSA-2c2j-9gv5-cj73 severity=UNKNOWN fix=0.47.2
|
||||
7
docs/work-items/ORCH-073/00-business-request.md
Normal file
7
docs/work-items/ORCH-073/00-business-request.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Business Request: CRIT: эрозия main — код ORCH-067/069 затёрт ребейзами, не доехал
|
||||
|
||||
Work Item ID: ORCH-073
|
||||
|
||||
## Description
|
||||
|
||||
TBD
|
||||
98
docs/work-items/ORCH-073/01-brd.md
Normal file
98
docs/work-items/ORCH-073/01-brd.md
Normal file
@@ -0,0 +1,98 @@
|
||||
# 01 — BRD: ORCH-073 — CRIT: эрозия main (код ORCH-067/069 затёрт ребейзами, не доехал)
|
||||
|
||||
- **Work Item:** ORCH-073
|
||||
- **Тип:** BUG CRITICAL — целостность `main`, накопительный регресс/эрозия
|
||||
- **Репозиторий:** orchestrator (self-hosting)
|
||||
- **Ветка:** `feature/ORCH-073-crit-main-orch-067-069`
|
||||
- **Связь:** усиливает/чинит ORCH-071 (merge-verify); НЕ покрыт ORCH-071.
|
||||
|
||||
## 1. Бизнес-проблема
|
||||
|
||||
Код успешно «задеплоенных» и переведённых в `done` задач **ORCH-067** (tracker bump,
|
||||
Plane-статусы, кликабельные ссылки `plane_issue_link`) и **ORCH-069** (`qg0_title_max`)
|
||||
**физически отсутствовал в `origin/main`**, хотя обе прошли весь конвейер, Confirm Deploy,
|
||||
merge-verify `CONFIRMED` и стали `done`. В `main` попадали только их **docs-коммиты**
|
||||
(staging-log / verdict через отдельные авто docs-PR), но НЕ код feature-веток.
|
||||
|
||||
Внешнее проявление (нашёл Слава, 08.06): «ссылок на задачу в Plane нет», карточка Telegram
|
||||
показывает сырой номер задачи вместо кликабельной ссылки — потому что код ссылок есть в ветке
|
||||
ORCH-067, но не в `main`.
|
||||
|
||||
**Накопительный характер:** каждая новая задача срезает ветку от УСТАРЕВШЕГО `main` и при merge
|
||||
тихо (без конфликт-маркеров) затирает код предшественника. Уже потеряны ORCH-067 и ORCH-069;
|
||||
без системного фикса теряется код каждой следующей задачи с правкой `CHANGELOG.md`.
|
||||
|
||||
## 2. Подтверждённый root cause (git-аудит 08.06, не гипотеза)
|
||||
|
||||
1. **`verify_merged_to_main` подтверждает merge по ложному признаку.**
|
||||
`src/merge_gate.py::verify_merged_to_main` возвращает `True`, если выполнено **ЛИБО**
|
||||
`pr_already_merged(repo, branch)`, **ЛИБО** `git merge-base --is-ancestor <sha> origin/main`.
|
||||
Первая ветка (`pr_already_merged`) и есть дыра.
|
||||
2. **`pr_already_merged` засчитывает ЛЮБОЙ merged PR ветки.**
|
||||
`src/merge_gate.py::pr_already_merged` делает `GET /pulls?state=all&head=<branch>` и
|
||||
возвращает `True`, если **хоть один** PR `merged==True`. У одной ветки несколько PR
|
||||
(code-PR + авто docs-PR со staging/deploy-логами). Сливается docs-PR → функция говорит
|
||||
«already-merged» → `verify_merged_to_main`=`True` → merge-verify `CONFIRMED` → `done`,
|
||||
хотя code-PR НЕ слит. **Ложно-зелёный.**
|
||||
3. **CHANGELOG.md-ребейзы — вторичный усилитель.**
|
||||
Merge-gate `auto_rebase_onto_main` при конфликте `CHANGELOG.md` откатывает `deploy-staging →
|
||||
development`; повторный ребейз ветки от старого `main` несёт устаревшие версии файлов
|
||||
(`notifications.py`/`config.py`/`webhooks/plane.py`), которые при merge тихо затирают
|
||||
соседний код (фантом-эффект, как в ORCH-071, без конфликт-маркеров).
|
||||
|
||||
> Уточнение для архитектора: в ТЗ упомянута «инвертированная проверка `merge-base --is-ancestor
|
||||
> origin/main HEAD` (merge_gate.py ~76)» — это `branch_is_behind_main` (детектор «ветка
|
||||
> свежая»), он корректен для своей цели. Фактический дефект merge-verify — это OR-ветка
|
||||
> `pr_already_merged` в `verify_merged_to_main` (строка ~649), которая засчитывает docs-PR.
|
||||
|
||||
## 3. Состояние на момент анализа (G1)
|
||||
|
||||
Аудит `origin/main` показал, что **восстановительный PR #76** (`restore(main): re-merge
|
||||
ORCH-067 + ORCH-069 (ORCH-073)`) уже вернул код в `main`:
|
||||
- `plane_issue_link` присутствует (`src/notifications.py`), `qg0_title_max` присутствует
|
||||
(`src/config.py`, `src/webhooks/plane.py`), `verify_merged_to_main` присутствует.
|
||||
|
||||
Таким образом **G1 (восстановление кода) фактически выполнено** ручным restore-PR. Задача
|
||||
ORCH-073 должна **подтвердить и зафиксировать** это в критериях приёмки (AC-1) и сосредоточиться
|
||||
на **системном фиксе навсегда** (G2–G5 / FR-1…FR-5), иначе регресс повторится.
|
||||
|
||||
## 4. Цели (Goals)
|
||||
|
||||
- **G1.** КОД ORCH-067 и ORCH-069 присутствует в `origin/main` одновременно с ORCH-071
|
||||
(подтвердить restore-PR #76, зафиксировать маркеры > 0). Pytest зелёный. Прод задеплоен.
|
||||
- **G2 (FR-2/FR-3).** `merge`/`pr_already_merged` различают **code-PR** и **docs-PR** — merge
|
||||
засчитывается только за PR с кодом ветки (`base==main`, `head==<feature-branch>`).
|
||||
- **G3 (FR-1, ядро).** `verify_merged_to_main` подтверждает merge **ТОЛЬКО** по факту «deployed
|
||||
SHA — предок `origin/main`». PR-флаги вспомогательны, не достаточны.
|
||||
- **G4 (FR-4).** Защита от CHANGELOG-затирания: `.gitattributes` с `CHANGELOG.md merge=union`
|
||||
(+ опц. `docs/*.md merge=union` для append-only).
|
||||
- **G5 (FR-5, регресс-гард навсегда).** После деплоя — sanity-проверка целостности `main`:
|
||||
deployed SHA в `main` И набор маркеров ранее-merged задач не уменьшился. Откат соседнего кода
|
||||
→ alert «main regressed», задача НЕ `done`.
|
||||
|
||||
## 5. Не-цели (Out of scope)
|
||||
|
||||
- Не менять Plane / схему БД.
|
||||
- Не отменять self-hosting safety (не ронять прод, merge только через PR-API, без force-push в `main`).
|
||||
- Не менять ручной гейт `Confirm Deploy`.
|
||||
- Не менять поведение merge/verify для non-self репозиториев (enduro-trails) — обратная совместимость.
|
||||
|
||||
## 6. Инварианты
|
||||
|
||||
- **INV-1.** never-raise на верификации (alert, не падение).
|
||||
- **INV-2.** self-hosting safety: прод не падает; merge только PR-API, без force-push в `main`.
|
||||
- **INV-3.** ручной `Confirm Deploy` сохранён.
|
||||
- **INV-4.** Идемпотентность: повторный прогон / reaper не делает второй merge; idempotency
|
||||
опирается на «SHA-в-main», а не на «любой merged PR».
|
||||
- **INV-5.** Обратная совместимость non-self (enduro): поведение merge/verify без изменений.
|
||||
|
||||
## 7. Заинтересованные стороны
|
||||
|
||||
- **Owner / Слава** — потребитель (видит кликабельные ссылки в карточке; доверие к merge-verify).
|
||||
- **Все проекты на инстансе** (enduro-trails) — общий `main`/очередь/БД; регресс орка = групповой риск.
|
||||
|
||||
## 8. Срочность
|
||||
|
||||
КРИТИКАЛ. Без FR-1/FR-4/FR-5 каждая новая задача с правкой `CHANGELOG.md` продолжает терять код
|
||||
предшественников (уже потеряны 067, 069). Ложно-зелёный merge-verify подрывает само ядро
|
||||
автономности конвейера.
|
||||
129
docs/work-items/ORCH-073/02-trz.md
Normal file
129
docs/work-items/ORCH-073/02-trz.md
Normal file
@@ -0,0 +1,129 @@
|
||||
# 02 — ТЗ: ORCH-073 — системный фикс эрозии main + восстановление кода 067/069
|
||||
|
||||
> ТЗ описывает ТРЕБУЕМОЕ ПОВЕДЕНИЕ и точки изменения. Выбор конкретного дизайна
|
||||
> (где именно резать docs-PR от code-PR, формат набора регресс-маркеров) — за архитектором (`06-adr`).
|
||||
> Запрещено комментировать ТЗ задним числом: если требование не годится — вернуть в Анализ.
|
||||
|
||||
## 1. Задействованные модули `src/`
|
||||
|
||||
| Модуль | Роль в фиксе | FR |
|
||||
| --- | --- | --- |
|
||||
| `src/merge_gate.py` | `verify_merged_to_main`, `pr_already_merged`, `merge_pr`, новый регресс-гард | FR-1, FR-2, FR-3, FR-5 |
|
||||
| `src/stage_engine.py` | `_handle_merge_verify` (под-гейт `deploy → done`) — точка вызова FR-1/FR-5 | FR-1, FR-5 |
|
||||
| `src/config.py` | (опц.) настройки регресс-гарда: kill-switch + набор маркеров/таймаут | FR-5 |
|
||||
| `.gitattributes` (корень репо, новый) | `CHANGELOG.md merge=union` (+ опц. `docs/*.md merge=union`) | FR-4 |
|
||||
| `docs/architecture/README.md` | раздел merge-verify — обновить под новую семантику | AC-8 |
|
||||
| `CHANGELOG.md` | запись Unreleased | AC-8 |
|
||||
| `docs/work-items/ORCH-073/06-adr/` | ADR на новую семантику merge-verify + регресс-гард | AC-8 |
|
||||
|
||||
## 2. Требуемые изменения по коду
|
||||
|
||||
### FR-1 (G3, ядро) — `verify_merged_to_main` чинит семантику
|
||||
**Текущее (баг):** `src/merge_gate.py::verify_merged_to_main(repo, branch, sha)` возвращает `True`,
|
||||
если `pr_already_merged(...)` **ИЛИ** `git merge-base --is-ancestor <sha> origin/main`.
|
||||
OR-ветка `pr_already_merged` засчитывает docs-PR → ложно-зелёный.
|
||||
|
||||
**Требование:** подтверждение merge — **ТОЛЬКО** прямой факт «deployed commit является предком
|
||||
`origin/main`»:
|
||||
- после `git fetch origin main` выполнить `git merge-base --is-ancestor <deployed_sha> origin/main`;
|
||||
- `rc==0` → `True` (код в main), иначе → `False`.
|
||||
- `pr_already_merged` **НЕ может быть единственным/достаточным** условием `True`. Допустимо
|
||||
оставить PR-флаг только как **вспомогательный** сигнал (idempotency / диагностика), но он НЕ
|
||||
должен подтверждать merge при отсутствии SHA в main.
|
||||
- Пустой `sha` → неопределённо → `False` (fail-closed: alert + HOLD), как сейчас.
|
||||
- never-raise: любая git/HTTP-ошибка → `False` (INV-1).
|
||||
|
||||
### FR-2 (G2) — `pr_already_merged` различает code-PR и docs-PR
|
||||
**Текущее (баг):** `src/merge_gate.py::pr_already_merged` возвращает `True` за ЛЮБОЙ
|
||||
`merged==True` PR из `GET /pulls?state=all&head=<branch>` — включая авто docs-PR.
|
||||
|
||||
**Требование (на выбор архитектора, предпочтителен вариант «б»):**
|
||||
- **(а)** засчитывать merged только для PR, реально несущего код ветки: `base.ref==main`
|
||||
И `head.ref==<feature-branch>` (исключить docs/* ветки и docs-only PR); **или**
|
||||
- **(б, предпочтительно)** понизить роль `pr_already_merged` до **idempotency-guard**: единственный
|
||||
критерий «merged/done» — SHA-предок-`main` (FR-1); PR-флаги вспомогательны.
|
||||
- Поведение для non-self репо (enduro) не меняется (INV-5).
|
||||
- never-raise → `False` (консервативно).
|
||||
|
||||
### FR-3 (G2) — `merge_pr` реально сливает code-ветку
|
||||
**Требование:** `src/merge_gate.py::merge_pr` мержит ИМЕННО feature-PR с кодом (`base==main`,
|
||||
`head==<feature-branch>`), а не полагается на docs-PR. После merge — обязательная верификация
|
||||
по FR-1 (SHA в main) как единственный источник истины. Merge только через Gitea PR-merge API,
|
||||
никогда push/force-push в `main` (INV-2).
|
||||
|
||||
### FR-5 (G3 регресс-гард, защита навсегда) — sanity-проверка целостности main
|
||||
**Требование:** перед фиксацией `done` (в `_handle_merge_verify`, ПОСЛЕ зелёного
|
||||
`check_deploy_status`, до `update_task_stage`):
|
||||
1. Подтвердить FR-1 (deployed SHA — предок `origin/main`).
|
||||
2. (опц., по дизайну) Проверить, что в `origin/main` присутствует **набор маркеров** ключевых
|
||||
функций недавно-merged задач (regression marker set) — merge не уменьшил его.
|
||||
3. При откате соседнего кода / отсутствии маркера → **alert** «main regressed: code of <prev
|
||||
tasks> missing» (Telegram + Plane), задача **НЕ `done`** (HOLD), как ветка not-merged в ORCH-071.
|
||||
- Реакция — **ALERT-only + HOLD**, без авто-отката на `development` (это инфра-дефект, не код-фолт).
|
||||
- never-raise (INV-1); kill-switch (как `merge_verify_enabled`); условность только для self-hosting
|
||||
/ `merge_verify_repos` (INV-5).
|
||||
- Набор маркеров — конфигурируемый/декларативный (например, в `src/config.py` или рядом), чтобы
|
||||
следующие задачи могли его расширять. Точный формат — за архитектором.
|
||||
|
||||
### FR-4 (G2/G4 корень) — `.gitattributes` с `merge=union`
|
||||
**Требование:** в корне репо завести `.gitattributes`:
|
||||
```
|
||||
CHANGELOG.md merge=union
|
||||
# опционально для append-only документов:
|
||||
# docs/**/*.md merge=union # ВНИМАНИЕ: union НЕ годится для файлов, где правки
|
||||
# переписывают строки — применять только к append-only
|
||||
```
|
||||
- `merge=union` встроен в git (драйвер по умолчанию), доп. конфиг хоста не требуется — но
|
||||
проверить, что атрибут реально применяется в worktree агентов (`git check-attr merge CHANGELOG.md`).
|
||||
- Эффект: при `auto_rebase_onto_main` правки `## [Unreleased]` авто-сливаются (обе записи
|
||||
сохраняются) без конфликта → ветка не откатывается в `development` и не затирает соседний код.
|
||||
|
||||
## 3. Изменения API
|
||||
|
||||
- **Внешних HTTP API оркестратора (`src/main.py` endpoints) НЕ менять.**
|
||||
- Внутренние сигнатуры:
|
||||
- `verify_merged_to_main(repo, branch, sha) -> bool` — семантика меняется, сигнатура сохраняется.
|
||||
- `pr_already_merged(repo, branch) -> bool` — семантика/назначение уточняется.
|
||||
- `merge_pr(repo, branch) -> tuple[bool, str]` — поведение уточняется (фильтр code-PR).
|
||||
- (опц.) новая функция регресс-гарда в `merge_gate.py` — `tuple[bool, str]`/`bool`, never-raise.
|
||||
- `GET /queue` `merge_verify_status()` — допустимо дополнить счётчиком регресс-алертов (read-only,
|
||||
не источник истины).
|
||||
- Внешние вызовы Gitea — те же эндпоинты (`/pulls`, `/pulls/{index}/merge`).
|
||||
|
||||
## 4. Изменения схемы БД
|
||||
|
||||
- **НЕТ.** Схема БД (`src/db.py`) не трогается (Не-цель). Регресс-гард опирается на git/`origin/main`,
|
||||
не на новые таблицы.
|
||||
|
||||
## 5. Требования к новым/изменённым QG checks
|
||||
|
||||
- **Новых зарегистрированных QG-checks не вводить.** Логика остаётся **под-гейтом** в
|
||||
`advance_stage` (`_handle_merge_verify`), как ORCH-071 — не новый элемент реестра `QG_CHECKS`.
|
||||
- Реестр `QG_CHECKS`, `check_deploy_status`, `_parse_deploy_status`, merge-gate
|
||||
(`check_branch_mergeable`), image-freshness — **без изменений**.
|
||||
|
||||
## 6. Конфигурация (`src/config.py` / `.env.example`)
|
||||
|
||||
- Существующие `merge_verify_enabled` (kill-switch, дефолт `true`), `merge_verify_repos` (пусто →
|
||||
только self-hosting), `merge_pr_timeout_s`, `merge_verify_timeout_s` — переиспользовать.
|
||||
- (опц., по дизайну) новые: kill-switch регресс-гарда и декларация набора маркеров. Дефолты —
|
||||
безопасные (для non-self — no-op). Любой новый ключ задокументировать в `.env.example`.
|
||||
|
||||
## 7. Артефакты pipeline, которые должны быть созданы/обновлены
|
||||
|
||||
- `docs/work-items/ORCH-073/06-adr/ADR-001-*.md` — решение по новой семантике merge-verify
|
||||
(FR-1/FR-2/FR-3) + регресс-гард (FR-5) + `.gitattributes` (FR-4).
|
||||
- `docs/architecture/README.md` — обновить раздел «Merge-в-main + пост-деплой верификация»
|
||||
(ORCH-071) под FR-1 (SHA как единственный критерий) и добавить регресс-гард FR-5.
|
||||
- `CHANGELOG.md` — запись в `## [Unreleased]`.
|
||||
- `docs/work-items/ORCH-073/10-tech-risks.md`, `12-review.md`, `13-test-report.md`,
|
||||
`14-deploy-log.md`, `15-staging-log.md` — по ходу конвейера.
|
||||
- `04-test-plan.yaml` (этот пакет) — реализовать тесты в `tests/`.
|
||||
|
||||
## 8. Аудит G4 (зафиксировать в ADR / 06-adr)
|
||||
|
||||
Зафиксировать подтверждённую причину docs-only merge: у feature-ветки 067/069 в `main` попадали
|
||||
только авто docs-PR (staging-log / deploy-log / CLAUDE.md / CHANGELOG), а code-PR не сливался,
|
||||
при этом `pr_already_merged` засчитывал docs-PR → merge-verify ложно `CONFIRMED` → `done`.
|
||||
Корень устранён FR-1+FR-2+FR-3. Восстановление кода (G1) уже выполнено restore-PR #76 —
|
||||
подтвердить маркеры в `origin/main` (AC-1).
|
||||
77
docs/work-items/ORCH-073/03-acceptance-criteria.md
Normal file
77
docs/work-items/ORCH-073/03-acceptance-criteria.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# 03 — Критерии приёмки: ORCH-073
|
||||
|
||||
Каждый критерий — однозначный PASS/FAIL. Reviewer/Tester проверяют буквально.
|
||||
|
||||
## AC-1 — Код 067/069/071 одновременно в main (G1)
|
||||
`origin/main` содержит **одновременно**: `plane_issue_link` + кликабельный заголовок (ORCH-067),
|
||||
`qg0_title_max` (ORCH-069), `verify_merged_to_main` (ORCH-071).
|
||||
- **PASS:** все три маркера присутствуют, счётчики > 0:
|
||||
`git grep -c plane_issue_link origin/main -- src/notifications.py` > 0;
|
||||
`git grep -c qg0_title_max origin/main -- src/` > 0;
|
||||
`git grep -c verify_merged_to_main origin/main -- src/merge_gate.py` > 0.
|
||||
- **FAIL:** хотя бы один маркер == 0.
|
||||
|
||||
## AC-2 — `verify_merged_to_main` подтверждает merge ТОЛЬКО по SHA-в-main (FR-1)
|
||||
`verify_merged_to_main(repo, branch, sha)` возвращает `True` **только** когда `sha` — реальный
|
||||
предок `origin/main`.
|
||||
- **PASS:** unit-тест: `sha` НЕ в `main` → `False`, **даже если** существует merged docs-PR той же
|
||||
ветки (mock `pr_already_merged`/Gitea возвращает merged docs-PR). `sha` в `main` → `True`.
|
||||
- **FAIL:** функция возвращает `True` при `sha` не в `main` из-за merged docs-PR.
|
||||
|
||||
## AC-3 — Воспроизведение исходного бага → НЕ done + alert (FR-1/FR-2)
|
||||
Задача с merged **docs-PR**, но БЕЗ merged **code-PR** (SHA не в main): merge-verify НЕ
|
||||
`CONFIRMED`.
|
||||
- **PASS:** `_handle_merge_verify` возвращает HOLD (intervened) → задача остаётся на `deploy`,
|
||||
НЕ `done`, отправлен alert «not merged» (Telegram + Plane `set_issue_blocked`). Mock
|
||||
воспроизводит сценарий ORCH-067/069.
|
||||
- **FAIL:** задача доходит до `done` / нет alert.
|
||||
|
||||
## AC-4 — `.gitattributes CHANGELOG.md merge=union` (FR-4)
|
||||
В корне репо есть `.gitattributes` с `CHANGELOG.md merge=union`.
|
||||
- **PASS:** файл существует, `git check-attr merge CHANGELOG.md` → `merge: union`; тест: два
|
||||
последовательных ребейза/слияния с правкой `## [Unreleased]` НЕ дают конфликта, обе записи
|
||||
сохранены в результирующем `CHANGELOG.md`.
|
||||
- **FAIL:** атрибут отсутствует/не применяется ИЛИ возникает конфликт-маркер при ребейзе.
|
||||
|
||||
## AC-5 — Регресс-гард ловит откат соседнего кода (FR-5)
|
||||
После деплоя `main` без маркера ранее-merged задачи → alert, задача НЕ `done`.
|
||||
- **PASS:** тест: симуляция `main`, где deployed SHA есть, но набор маркеров уменьшился (или
|
||||
deployed SHA НЕ предок main) → `_handle_merge_verify` HOLD + alert «main regressed», НЕ `done`.
|
||||
- **FAIL:** регресс соседнего кода не пойман, задача `done`.
|
||||
|
||||
## AC-6 — Happy-path без ложных alert (INV-5 / AC-5 ТЗ)
|
||||
Код реально в `main` (deployed SHA — предок `origin/main`) → задача `done` штатно, без ложного
|
||||
alert; для non-self репо (enduro) merge/verify без изменений.
|
||||
- **PASS:** тест happy-path: SHA в main → `verify_merged_to_main`=`True`, `_handle_merge_verify`
|
||||
возвращает «advance» (не intervened); non-self репо → под-гейт no-op.
|
||||
- **FAIL:** ложный alert на корректном merge ИЛИ изменение поведения для enduro.
|
||||
|
||||
## AC-7 — Идемпотентность по SHA-в-main (INV-4)
|
||||
Повторный прогон/reaper уже-слитой задачи (SHA в main) → no-op, без второго merge.
|
||||
- **PASS:** тест: re-drive задачи с SHA-в-main → `merge_pr` no-op («already-merged»/idempotent),
|
||||
второго Gitea POST merge нет; задача остаётся `done`.
|
||||
- **FAIL:** второй merge / дубликат / ошибка.
|
||||
|
||||
## AC-8 — Документация и тесты обновлены (правило агентов §2/§6)
|
||||
- **PASS:** обновлены `CHANGELOG.md` (Unreleased), `docs/architecture/README.md` (раздел
|
||||
merge-verify под FR-1 + регресс-гард FR-5), создан ADR в `docs/work-items/ORCH-073/06-adr/`;
|
||||
pytest зелёный (`pytest tests/ -q`).
|
||||
- **FAIL:** доки/ADR не обновлены ИЛИ pytest красный.
|
||||
|
||||
## AC-9 — G4 аудит задокументирован
|
||||
Причина docs-only merge (code-PR не слит, `pr_already_merged` засчитал docs-PR) зафиксирована в
|
||||
ADR/06-adr, корень устранён (FR-1+FR-2+FR-3).
|
||||
- **PASS:** ADR содержит раздел «Root cause / G4 audit» с воспроизведением и устранением.
|
||||
- **FAIL:** аудит отсутствует.
|
||||
|
||||
## AC-10 — Воспроизведение на staging «исправлено навсегда» (G3/AC-9 ТЗ)
|
||||
2 задачи, обе с правкой `CHANGELOG.md`, прогнаны через staging → обе доезжают в `main` без потери
|
||||
кода друг друга.
|
||||
- **PASS:** зафиксировано в `15-staging-log.md`: оба набора маркеров присутствуют в `main` после
|
||||
обоих merge; ни одна правка CHANGELOG не вызвала конфликт/откат.
|
||||
- **FAIL:** код одной задачи затёрт другой ИЛИ конфликт CHANGELOG.
|
||||
|
||||
## AC-11 — self-hosting safety сохранена (INV-2/INV-3)
|
||||
- **PASS:** merge только через PR-API (без force-push в `main`); прод-контейнер не падал в рамках
|
||||
задачи; ручной `Confirm Deploy` сохранён.
|
||||
- **FAIL:** force-push в main / рестарт прод-контейнера в рамках merge / обход Confirm Deploy.
|
||||
117
docs/work-items/ORCH-073/04-test-plan.yaml
Normal file
117
docs/work-items/ORCH-073/04-test-plan.yaml
Normal file
@@ -0,0 +1,117 @@
|
||||
work_item: ORCH-073
|
||||
title: "CRIT: эрозия main — системный фикс merge-verify + восстановление кода 067/069"
|
||||
notes: >
|
||||
Покрытие FR-1..FR-5 / AC-1..AC-11. Все верификаторы — never-raise (INV-1):
|
||||
при ошибке git/HTTP → False (fail-closed), не падение. Gitea/git вызовы мокаются
|
||||
(monkeypatch httpx + subprocess), как в существующих тестах merge_gate/stage_engine.
|
||||
Тесты регресс-гарда и .gitattributes используют временный git-репозиторий (tmp_path).
|
||||
|
||||
tests:
|
||||
# ---- FR-1: verify_merged_to_main — SHA-в-main как единственный критерий ----
|
||||
- id: TC-01
|
||||
type: unit
|
||||
description: "verify_merged_to_main: sha — предок origin/main → True (happy-path, AC-6)."
|
||||
module: tests/test_orch073_merge_verify.py
|
||||
expected: PASS
|
||||
- id: TC-02
|
||||
type: unit
|
||||
description: "verify_merged_to_main: sha НЕ предок main И существует merged docs-PR ветки → False (баг 067/069, AC-2)."
|
||||
module: tests/test_orch073_merge_verify.py
|
||||
expected: PASS
|
||||
- id: TC-03
|
||||
type: unit
|
||||
description: "verify_merged_to_main: пустой sha → False (неопределённо, fail-closed)."
|
||||
module: tests/test_orch073_merge_verify.py
|
||||
expected: PASS
|
||||
- id: TC-04
|
||||
type: unit
|
||||
description: "verify_merged_to_main: git fetch/merge-base бросает исключение → False (never-raise, INV-1)."
|
||||
module: tests/test_orch073_merge_verify.py
|
||||
expected: PASS
|
||||
|
||||
# ---- FR-2: pr_already_merged различает code-PR / docs-PR ----
|
||||
- id: TC-05
|
||||
type: unit
|
||||
description: "pr_already_merged/идентификация PR: merged docs-PR (head=docs/*, base=main) НЕ засчитывается как merge кода ветки."
|
||||
module: tests/test_orch073_pr_classify.py
|
||||
expected: PASS
|
||||
- id: TC-06
|
||||
type: unit
|
||||
description: "merged code-PR (head=<feature-branch>, base=main) корректно распознаётся как code-merge."
|
||||
module: tests/test_orch073_pr_classify.py
|
||||
expected: PASS
|
||||
- id: TC-07
|
||||
type: unit
|
||||
description: "pr_already_merged: HTTP-ошибка/не-200 → False (never-raise, консервативно)."
|
||||
module: tests/test_orch073_pr_classify.py
|
||||
expected: PASS
|
||||
|
||||
# ---- FR-3: merge_pr сливает именно code-ветку ----
|
||||
- id: TC-08
|
||||
type: unit
|
||||
description: "merge_pr выбирает open PR с head==<feature-branch> и base==main (не docs/*), вызывает Gitea POST merge."
|
||||
module: tests/test_orch073_merge_pr.py
|
||||
expected: PASS
|
||||
- id: TC-09
|
||||
type: unit
|
||||
description: "merge_pr: нет open code-PR → (False, 'no open PR'); никогда не push/force-push main (INV-2)."
|
||||
module: tests/test_orch073_merge_pr.py
|
||||
expected: PASS
|
||||
- id: TC-10
|
||||
type: unit
|
||||
description: "merge_pr идемпотентен: уже-слитый code-PR (SHA в main) → no-op, без второго POST merge (AC-7/INV-4)."
|
||||
module: tests/test_orch073_merge_pr.py
|
||||
expected: PASS
|
||||
|
||||
# ---- FR-4: .gitattributes CHANGELOG.md merge=union ----
|
||||
- id: TC-11
|
||||
type: integration
|
||||
description: ".gitattributes в корне репо содержит 'CHANGELOG.md merge=union'; git check-attr подтверждает driver=union (AC-4)."
|
||||
module: tests/test_orch073_gitattributes.py
|
||||
expected: PASS
|
||||
- id: TC-12
|
||||
type: integration
|
||||
description: "Во временном git-репо два ребейза/слияния с правкой '## [Unreleased]' НЕ дают конфликта; обе записи в CHANGELOG сохранены (AC-4)."
|
||||
module: tests/test_orch073_gitattributes.py
|
||||
expected: PASS
|
||||
|
||||
# ---- FR-5: регресс-гард целостности main + интеграция в _handle_merge_verify ----
|
||||
- id: TC-13
|
||||
type: unit
|
||||
description: "_handle_merge_verify: SHA в main И маркеры на месте → return False (advance к done, happy-path AC-6)."
|
||||
module: tests/test_orch073_regression_guard.py
|
||||
expected: PASS
|
||||
- id: TC-14
|
||||
type: unit
|
||||
description: "_handle_merge_verify: SHA НЕ в main (docs-only merge) → return True (HOLD), alert + set_issue_blocked, НЕ done (AC-3)."
|
||||
module: tests/test_orch073_regression_guard.py
|
||||
expected: PASS
|
||||
- id: TC-15
|
||||
type: unit
|
||||
description: "Регресс-гард: deployed SHA есть, но набор маркеров ранее-merged задач уменьшился → HOLD + alert 'main regressed', НЕ done (AC-5)."
|
||||
module: tests/test_orch073_regression_guard.py
|
||||
expected: PASS
|
||||
- id: TC-16
|
||||
type: unit
|
||||
description: "_handle_merge_verify: внутренняя ошибка верификатора → HOLD + alert, без проброса исключения в advance_stage (never-raise, INV-1)."
|
||||
module: tests/test_orch073_regression_guard.py
|
||||
expected: PASS
|
||||
|
||||
# ---- Условность / обратная совместимость ----
|
||||
- id: TC-17
|
||||
type: unit
|
||||
description: "merge_verify_applies: non-self репо (enduro) или kill-switch off → под-гейт no-op, поведение merge/verify без изменений (AC-6/INV-5)."
|
||||
module: tests/test_orch073_conditionality.py
|
||||
expected: PASS
|
||||
- id: TC-18
|
||||
type: unit
|
||||
description: "Регресс-гард уважает kill-switch (merge_verify_enabled=False) → no-op; для non-self → no-op (INV-5)."
|
||||
module: tests/test_orch073_conditionality.py
|
||||
expected: PASS
|
||||
|
||||
# ---- Регресс существующего поведения ----
|
||||
- id: TC-19
|
||||
type: integration
|
||||
description: "Существующие тесты merge_gate/stage_engine (ORCH-065/071) остаются зелёными; полный pytest tests/ -q green (AC-8)."
|
||||
module: tests/
|
||||
expected: PASS
|
||||
@@ -0,0 +1,214 @@
|
||||
# ADR-001 (ORCH-073): SHA-в-main как единственный критерий merge-verify + регресс-гард + `.gitattributes`
|
||||
|
||||
- **Статус:** Accepted
|
||||
- **Дата:** 2026-06-08
|
||||
- **Задача:** ORCH-073 (BUG CRITICAL — эрозия `main`)
|
||||
- **Связь:** усиливает/чинит ORCH-071 (merge-verify под-гейт). Сквозной аналог — `docs/architecture/adr/adr-0014-merge-verify-sha-source-of-truth.md` (amends adr-0013).
|
||||
- **Источники:** `01-brd.md` (root-cause git-аудит 08.06), `02-trz.md` (FR-1…FR-5), `03-acceptance-criteria.md` (AC-1…AC-11).
|
||||
|
||||
## Контекст
|
||||
|
||||
Код «задеплоенных» и переведённых в `done` задач **ORCH-067** (`plane_issue_link`, кликабельные
|
||||
ссылки, tracker bump) и **ORCH-069** (`qg0_title_max`) физически отсутствовал в `origin/main`,
|
||||
хотя обе прошли весь конвейер, Confirm Deploy, merge-verify `CONFIRMED` и стали `done`. В `main`
|
||||
попадали только их **docs-коммиты** (staging/deploy-логи через отдельные авто docs-PR), но НЕ
|
||||
код feature-веток. Внешнее проявление (нашёл Слава, 08.06): в карточке Telegram сырой номер
|
||||
задачи вместо кликабельной ссылки — код ссылок есть в ветке ORCH-067, но не в `main`.
|
||||
|
||||
### Root cause (G4 audit) — подтверждён git-аудитом, НЕ гипотеза
|
||||
|
||||
1. **`verify_merged_to_main` подтверждает merge по ложному признаку.** Возвращает `True`, если
|
||||
`pr_already_merged(repo, branch)` **ЛИБО** `git merge-base --is-ancestor <sha> origin/main`.
|
||||
OR-ветка `pr_already_merged` — и есть дыра.
|
||||
2. **`pr_already_merged` засчитывает ЛЮБОЙ merged PR.** `GET /pulls?state=all&head=<branch>` и
|
||||
`True`, если **хоть один** PR `merged==True`. Параметр `head` у Gitea для одиночной строки-ветки
|
||||
фильтрует ненадёжно → в выборку попадают авто docs-PR (staging/deploy-логи) с других веток
|
||||
(`docs/*`). Сливается docs-PR → `pr_already_merged`=`True` → `verify_merged_to_main`=`True` →
|
||||
merge-verify `CONFIRMED` → `done`, хотя **code-PR НЕ слит**. Ложно-зелёный.
|
||||
3. **CHANGELOG-ребейзы — вторичный усилитель.** `auto_rebase_onto_main` при конфликте
|
||||
`CHANGELOG.md` откатывает `deploy-staging → development`; повторный ребейз ветки от старого
|
||||
`main` несёт устаревшие версии соседних файлов, которые при merge тихо затирают код-сосед
|
||||
(фантом-эффект как в ORCH-071, без конфликт-маркеров).
|
||||
|
||||
**G1 (восстановление кода) выполнено вручную** restore-PR #76 — `git grep` подтверждает в
|
||||
`origin/main` одновременно `plane_issue_link` (8), `qg0_title_max` (3+2), `verify_merged_to_main`
|
||||
(4). ORCH-073 фиксирует это в AC-1 и устраняет корень навсегда (FR-1…FR-5).
|
||||
|
||||
## Решение
|
||||
|
||||
Меняется **семантика merge-verify** (под-гейт ребра `deploy → done`, врезка `_handle_merge_verify`
|
||||
в `advance_stage`, введён ORCH-071). `STAGE_TRANSITIONS`, реестр `QG_CHECKS`,
|
||||
`check_deploy_status`/`_parse_deploy_status`, merge-gate (`check_branch_mergeable`),
|
||||
image-freshness, схема БД (`src/db.py`) — **НЕ меняются**. Внешние HTTP-эндпоинты `src/main.py` —
|
||||
**НЕ меняются**.
|
||||
|
||||
### Р-1 (FR-1, ядро) — `verify_merged_to_main`: SHA-в-main — единственный критерий
|
||||
|
||||
Подтверждение merge — **ТОЛЬКО** прямой факт «deployed commit является предком `origin/main`»:
|
||||
|
||||
```
|
||||
verify_merged_to_main(repo, branch, sha) -> bool:
|
||||
if not sha: # пустой SHA -> неопределённо
|
||||
log warning; return False # fail-closed (alert + HOLD)
|
||||
git fetch origin main (timeout merge_verify_timeout_s)
|
||||
rc = git merge-base --is-ancestor <sha> origin/main
|
||||
return rc == 0
|
||||
```
|
||||
|
||||
- **OR-ветка `pr_already_merged` удаляется** из `verify_merged_to_main`. PR-флаг больше **не
|
||||
подтверждает** merge.
|
||||
- Пустой `sha` → `False` (fail-closed: alert + HOLD), как сейчас.
|
||||
- never-raise: любая git-ошибка → `False` (INV-1) — фейл-клозед для `done`.
|
||||
|
||||
> Дизайн-выбор: вариант (б) из ТЗ §2 FR-2 — единственный источник истины «merged/done» — это
|
||||
> SHA-в-main. PR-флаги остаются только как **idempotency-guard** в `merge_pr` (Р-3), не как
|
||||
> подтверждение.
|
||||
|
||||
### Р-2 (FR-2/G2) — `pr_already_merged`: различает code-PR и docs-PR
|
||||
|
||||
`pr_already_merged` понижается до **idempotency-guard для `merge_pr`** (не источник истины для
|
||||
`done`). Но guard обязан быть **корректным**: «слит ли именно code-PR ЭТОЙ ветки», иначе merged
|
||||
docs-PR заставил бы `merge_pr` ошибочно сделать no-op и пропустить реальный merge кода.
|
||||
Поэтому в цикле явный фильтр (НЕ полагаться на ненадёжный query-параметр `head`):
|
||||
|
||||
```
|
||||
for pr in resp.json():
|
||||
if pr.merged is True
|
||||
and pr.head.ref == branch # код именно этой feature-ветки
|
||||
and pr.base.ref == "main": # таргет — main, не docs-база
|
||||
return True
|
||||
return False
|
||||
```
|
||||
|
||||
- Исключает авто docs-PR (другой `head.ref`, напр. `docs/*`) и PR на не-`main` базу.
|
||||
- never-raise → `False` (консервативно).
|
||||
- Поведение для non-self репо (enduro) не меняется (INV-5) — `merge_pr`/verify для них как раньше.
|
||||
|
||||
### Р-3 (FR-3/G2) — `merge_pr`: сливает именно code-ветку
|
||||
|
||||
`merge_pr` уже выбирает открытый PR по `head.ref==branch`; добавляется фильтр `base.ref=="main"`
|
||||
при выборе PR (защита от слияния PR на чужую базу). Idempotency-guard `pr_already_merged` (Р-2,
|
||||
теперь корректный) перед merge оставляем — повторный прогон не делает второй POST. Merge —
|
||||
ТОЛЬКО Gitea `POST /pulls/{index}/merge`, никогда push/force-push в `main` (INV-2). После merge
|
||||
единственный источник истины «слилось» — FR-1 (SHA-в-main), его проверяет `_handle_merge_verify`.
|
||||
|
||||
### Р-4 (FR-5/G5) — регресс-гард целостности `main` (защита навсегда)
|
||||
|
||||
Новая детерминированная (no-LLM) функция в `merge_gate.py`, вызывается в `_handle_merge_verify`
|
||||
**ПОСЛЕ** подтверждённого SHA-в-main (Р-1) и **ДО** `update_task_stage(done)`:
|
||||
|
||||
```
|
||||
check_main_regression(repo, branch) -> tuple[bool, str]
|
||||
# ok=True -> регресса нет (набор маркеров цел) -> пропустить к done
|
||||
# ok=False -> маркер отсутствует -> "main regressed: <task/marker> missing"
|
||||
```
|
||||
|
||||
**Декларативный набор маркеров** — константа в `merge_gate.py` (append-only, расширяется каждой
|
||||
будущей задачей; НЕ БД, НЕ Plane — Не-цель):
|
||||
|
||||
```python
|
||||
MAIN_REGRESSION_MARKERS = [
|
||||
# (task, marker_substring, path)
|
||||
("ORCH-067", "plane_issue_link", "src/notifications.py"),
|
||||
("ORCH-069", "qg0_title_max", "src/config.py"),
|
||||
("ORCH-071", "verify_merged_to_main", "src/merge_gate.py"),
|
||||
("ORCH-073", "check_main_regression", "src/merge_gate.py"),
|
||||
]
|
||||
```
|
||||
|
||||
Проверка (в worktree после `git fetch origin main`): для каждого маркера
|
||||
`git grep -c <marker> origin/main -- <path>`; счётчик `0` → регресс.
|
||||
|
||||
- **Реакция при регрессе: ALERT-only + HOLD** (`set_issue_blocked` + Telegram + Plane-коммент
|
||||
«main regressed: code of `<task>` missing»), задача **НЕ `done`**, остаётся на `deploy`. БЕЗ
|
||||
авто-отката на `development` (это инфра-дефект, не код-фолт), симметрично not-merged ветке
|
||||
ORCH-071.
|
||||
- **Fail-OPEN на инфра-ошибке грепа** (намеренный trade-off): любая git/OS-ошибка самого грепа →
|
||||
`(True, "guard inconclusive: …")` → НЕ блокировать `done`. Обоснование: первичный фейл-клозед
|
||||
гейт — это SHA-в-main (Р-1); вторичный marker-grep не должен давать ложный HOLD на git-сбое.
|
||||
«Регресс» утверждается только при **детерминированном `count==0`**, не при «не смог определить».
|
||||
- never-raise (INV-1). Kill-switch — новый `regression_guard_enabled` (дефолт `true`,
|
||||
переиспользует область self-hosting через `merge_verify_applies`). Non-self репо — no-op (INV-5).
|
||||
|
||||
### Р-5 (FR-4/G4 корень) — `.gitattributes` с `merge=union`
|
||||
|
||||
В корне репозитория новый файл `.gitattributes`:
|
||||
|
||||
```
|
||||
CHANGELOG.md merge=union
|
||||
```
|
||||
|
||||
- `merge=union` — встроенный git-драйвер, доп. конфиг хоста не требуется; проверяется
|
||||
`git check-attr merge CHANGELOG.md` → `merge: union`.
|
||||
- Эффект: при `auto_rebase_onto_main` правки `## [Unreleased]` авто-сливаются (обе записи
|
||||
сохраняются) без конфликт-маркера → ветка не откатывается в `development` и не тащит устаревшие
|
||||
версии соседних файлов.
|
||||
- **Решено НЕ добавлять `docs/**/*.md merge=union`:** union годится только для строго
|
||||
append-only файлов; docs-артефакты (README, ADR, internals) регулярно **переписываются**
|
||||
построчно — union там тихо задублировал бы строки. Ограничиваемся `CHANGELOG.md`.
|
||||
- Оговорка о самозагрузке: задача, ВПЕРВЫЕ вносящая `.gitattributes`, при собственном ребейзе
|
||||
ещё не получает эффект union (атрибут попадёт в `main` только после её merge). Это допустимо —
|
||||
гард действует для всех последующих задач.
|
||||
|
||||
## Конфигурация
|
||||
|
||||
| Ключ | Дефолт | Назначение |
|
||||
|---|---|---|
|
||||
| `merge_verify_enabled` (есть) | `true` | kill-switch всего под-гейта |
|
||||
| `merge_verify_repos` (есть) | `""` | CSV; пусто → только self-hosting |
|
||||
| `merge_pr_timeout_s` / `merge_verify_timeout_s` (есть) | `60` | таймауты Gitea/git |
|
||||
| `regression_guard_enabled` (новый) | `true` | kill-switch регресс-гарда (Р-4); non-self → no-op |
|
||||
|
||||
Новый ключ задокументировать в `.env.example`. Дефолты безопасны (для non-self — no-op).
|
||||
|
||||
## Сигнатуры (внутренние; внешний API не меняется)
|
||||
|
||||
- `verify_merged_to_main(repo, branch, sha) -> bool` — семантика меняется (Р-1), сигнатура та же.
|
||||
- `pr_already_merged(repo, branch) -> bool` — назначение/фильтр уточняются (Р-2), сигнатура та же.
|
||||
- `merge_pr(repo, branch) -> tuple[bool, str]` — фильтр `base==main` (Р-3), сигнатура та же.
|
||||
- `check_main_regression(repo, branch) -> tuple[bool, str]` — **новая**, never-raise, fail-open.
|
||||
- `merge_verify_status()` — допустимо дополнить счётчиком регресс-алертов (read-only, не источник истины).
|
||||
|
||||
## Инварианты
|
||||
|
||||
- **INV-1** never-raise: ошибка верификации → alert/HOLD, не падение конвейера.
|
||||
- **INV-2** self-hosting safety: прод 8500 не падает/не рестартится в рамках merge; merge только
|
||||
Gitea PR-API, без force-push в `main`.
|
||||
- **INV-3** ручной `Confirm Deploy` (ORCH-059) сохранён.
|
||||
- **INV-4** идемпотентность опирается на «SHA-в-main», а не на «любой merged PR».
|
||||
- **INV-5** обратная совместимость non-self (enduro): merge/verify/регресс-гард — no-op.
|
||||
|
||||
## Альтернативы (отклонены)
|
||||
|
||||
1. **Оставить `pr_already_merged` как со-критерий verify, но фильтровать по `head/base`** —
|
||||
отклонено: PR-флаг всё равно слабее факта «SHA в main» (PR можно слить и тут же откатить
|
||||
ребейзом-соседом). Единственный надёжный критерий — предок-`main`. PR-флаг → только idempotency.
|
||||
2. **`docs/**/*.md merge=union`** — отклонено (см. Р-5): тихая дубликация строк в переписываемых
|
||||
доках.
|
||||
3. **Регресс-гард с авто-откатом на `development`** — отклонено: регресс соседнего кода —
|
||||
инфра-дефект merge, не код-фолт текущей задачи; реакция ALERT-only + HOLD (как ORCH-021/071).
|
||||
4. **Хранить набор маркеров в БД/Plane** — отклонено (Не-цель «не менять схему БД/Plane»);
|
||||
декларативная append-only константа в коде проще и версионируется вместе с фиксом.
|
||||
5. **Fail-closed на marker-grep** — отклонено: дало бы ложный HOLD при git-сбое; первичный
|
||||
фейл-клозед — SHA-в-main (Р-1), marker-grep вторичен → fail-open.
|
||||
|
||||
## Последствия
|
||||
|
||||
- **Плюс:** невозможно «`done` + прод задеплоен, а code-PR не в `main`» — единственный критерий
|
||||
`done` теперь «SHA-в-main». Ложно-зелёный по docs-PR устранён в корне (Р-1+Р-2+Р-3).
|
||||
- **Плюс:** CHANGELOG-конфликты больше не откатывают ветку и не тащат устаревший код-сосед (Р-5).
|
||||
- **Плюс:** регресс-гард ловит откат соседнего кода даже если SHA-в-main прошёл (Р-4).
|
||||
- **Минус:** при недоступной Gitea/git verify консервативно `False` → возможен ложный HOLD+alert
|
||||
(снимается повтором; fail-closed для `done` приоритетен). Регресс-гард при git-сбое наоборот
|
||||
fail-open (не блокирует) — осознанный trade-off, SHA-в-main остаётся первичным гейтом.
|
||||
- **Минус:** набор маркеров требует дисциплины — каждая значимая задача дописывает свой маркер
|
||||
(иначе гард его не защитит). Документируется в `CLAUDE.md`/README.
|
||||
|
||||
## Связи
|
||||
|
||||
- Amends: `docs/architecture/adr/adr-0013-merge-verify-gate.md` (ORCH-071) — меняет критерий verify.
|
||||
- Сквозной: `docs/architecture/adr/adr-0014-merge-verify-sha-source-of-truth.md`.
|
||||
- Постмортем: `docs/history/LESSONS_2026-06-08_phantom-merge.md`, runbook
|
||||
`docs/operations/PHANTOM_MERGE_RUNBOOK.md`.
|
||||
- AC: AC-1 (G1 markers), AC-2/AC-3 (Р-1/Р-2), AC-4 (Р-5), AC-5 (Р-4), AC-6 (happy-path),
|
||||
AC-7 (idempotency), AC-8/AC-9 (docs+audit), AC-10 (staging), AC-11 (self-hosting safety).
|
||||
32
docs/work-items/ORCH-073/07-infra-requirements.md
Normal file
32
docs/work-items/ORCH-073/07-infra-requirements.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# 07 — Инфра-требования: ORCH-073
|
||||
|
||||
## Топология
|
||||
**Без изменений.** Один сервер (mva154), prod `orchestrator` (8500), staging
|
||||
`orchestrator-staging` (8501), общая SQLite, общая очередь. Новых контейнеров/портов/сервисов нет.
|
||||
|
||||
## Git / worktree
|
||||
- Новый корневой файл **`.gitattributes`** (`CHANGELOG.md merge=union`). Драйвер `union` —
|
||||
встроенный в git, **доп. конфигурация хоста НЕ требуется**.
|
||||
- Проверка применения в worktree агентов: `git check-attr merge CHANGELOG.md` → `merge: union`.
|
||||
Атрибут действует при 3-way merge/rebase, когда `.gitattributes` присутствует в дереве
|
||||
(`auto_rebase_onto_main` выполняет `git rebase origin/main` в per-branch worktree).
|
||||
- Самозагрузка: первая задача с `.gitattributes` своего ребейза не ускоряет (атрибут попадёт в
|
||||
`main` после её merge); эффект — для последующих задач. Допустимо.
|
||||
- Регресс-гард (`check_main_regression`) использует уже существующий per-branch worktree
|
||||
(`ensure_worktree` + `git fetch origin main` + `git grep origin/main`). Новых клонов/worktree нет.
|
||||
|
||||
## Сеть / внешние интеграции
|
||||
- Те же Gitea-эндпоинты: `GET /pulls`, `POST /pulls/{index}/merge`. Новых внешних вызовов нет.
|
||||
- Telegram/Plane — существующие хелперы alert (`send_telegram`, `set_issue_blocked`,
|
||||
`plane_add_comment`). Новых интеграций нет.
|
||||
|
||||
## Деплой self (self-hosting safety)
|
||||
- Прод-контейнер `orchestrator` (8500) **НЕ рестартить/не ронять** в рамках задачи.
|
||||
- Обязательный staging-гейт (8501) перед прод-деплоем; прод-деплой — только переводом на
|
||||
`Confirm Deploy` (ORCH-059). Ручной гейт не меняется.
|
||||
- Merge — только Gitea PR-API, без force-push в `main`.
|
||||
|
||||
## Конфигурация (хост `.env` / `.env.example`)
|
||||
- Новый ключ `regression_guard_enabled` (дефолт `true`) — задокументировать в `.env.example`.
|
||||
- Существующие `merge_verify_enabled`/`merge_verify_repos`/`merge_pr_timeout_s`/
|
||||
`merge_verify_timeout_s` — переиспользуются, без изменений значений.
|
||||
23
docs/work-items/ORCH-073/08-data-requirements.md
Normal file
23
docs/work-items/ORCH-073/08-data-requirements.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# 08 — Требования к данным/схеме БД: ORCH-073
|
||||
|
||||
## Схема БД
|
||||
**Без изменений.** `src/db.py` не трогается (Не-цель BRD §5, ТЗ §4). Новых таблиц/колонок/
|
||||
миграций нет.
|
||||
|
||||
## Источник истины merge-verify
|
||||
- Подтверждение `done` опирается **только на git** (`origin/main`: `git merge-base
|
||||
--is-ancestor <sha> origin/main`), НЕ на состояние БД и НЕ на Plane-статусы.
|
||||
- Регресс-гард (`check_main_regression`) опирается на `git grep origin/main` по декларативному
|
||||
набору маркеров — **не на БД**.
|
||||
- Набор маркеров `MAIN_REGRESSION_MARKERS` — **append-only константа в коде** (`src/merge_gate.py`),
|
||||
версионируется вместе с фиксом. Сознательно НЕ в БД и НЕ в Plane (Не-цель).
|
||||
|
||||
## Состояние в БД (читается, не меняется)
|
||||
- `tasks.stage` — переходы через существующий `update_task_stage`/`advance_stage`; HOLD = задача
|
||||
остаётся на `deploy` (не записывается `done`). Семантика та же, что у ORCH-071.
|
||||
- Счётчики `_MERGE_VERIFY_COUNTERS` — **in-process**, не БД; read-only через `GET /queue`.
|
||||
Допустимо дополнить счётчиком регресс-алертов (наблюдаемость, не источник истины).
|
||||
|
||||
## Plane
|
||||
**Без изменений** (Не-цель). Используются существующие сеттеры (`set_issue_blocked`,
|
||||
`plane_add_comment`) для alert/HOLD. Новых статусов/маппингов нет.
|
||||
19
docs/work-items/ORCH-073/10-tech-risks.md
Normal file
19
docs/work-items/ORCH-073/10-tech-risks.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# 10 — Технические риски: ORCH-073
|
||||
|
||||
| # | Риск | Вероятность | Влияние | Митигация |
|
||||
|---|------|-------------|---------|-----------|
|
||||
| R-1 | **Ложный HOLD на сбое Gitea/git** — verify консервативно `False` при недоступности → задача не доходит до `done`, нужен повтор. | средняя | среднее | Осознанный fail-closed для `done` (приоритет: не дать ложно-зелёный). Снимается re-drive (reaper/reconciler/re-approve). Документировано в ADR «Последствия». |
|
||||
| R-2 | **`pr_already_merged` всё ещё ловит docs-PR** при иной структуре head/base в Gitea (cross-repo `owner:branch`). | низкая | высокое (возврат бага) | Явный фильтр в цикле `head.ref==branch И base.ref=="main"` (не полагаться на query-param). Тест AC-2/AC-3 мокает merged docs-PR и проверяет, что verify=`False`. |
|
||||
| R-3 | **Регресс-гард fail-open пропустит реальный регресс** во время git-сбоя грепа. | низкая | среднее | Первичный гейт `done` — SHA-в-main (fail-closed). Marker-grep вторичен; «регресс» — только при детерминированном `count==0`. Trade-off зафиксирован в ADR. |
|
||||
| R-4 | **Набор маркеров устаревает/неполный** — будущая задача не добавила свой маркер → гард её не защищает. | средняя | среднее | Append-only константа в коде + правило в `CLAUDE.md`/README «значимая задача дописывает маркер». Reviewer проверяет. Не регресс существующего поведения (только недозащита нового). |
|
||||
| R-5 | **`merge=union` тихо дублирует строки** при применении к не-append-only файлам. | низкая | среднее | Union строго ограничен `CHANGELOG.md`; `docs/**` под union НЕ ставится (решение Р-5 ADR). |
|
||||
| R-6 | **Самозагрузка `.gitattributes`** — первая задача не получает эффект union на своём ребейзе. | высокая (одноразово) | низкое | Принято: атрибут попадёт в `main` после merge ORCH-073, действует для последующих задач. Для самой ORCH-073 CHANGELOG-конфликт разрешается вручную при необходимости. |
|
||||
| R-7 | **Ложный «main regressed» при легитимном рефакторе**, переименовавшем маркер-функцию. | низкая | среднее | Маркеры выбираются как стабильные публичные имена; при намеренном переименовании задача обновляет `MAIN_REGRESSION_MARKERS` в том же PR (правило документации). |
|
||||
| R-8 | **Регресс на non-self репо (enduro)** из-за нового кода. | низкая | высокое | Вся врезка под `merge_verify_applies` (kill-switch + self-hosting scope); регресс-гард — отдельный `regression_guard_enabled`; non-self → no-op (INV-5). Тест AC-6 (enduro no-op). |
|
||||
| R-9 | **Self-hosting: рестарт/падение прода** при ошибке в merge_gate. | низкая | высокое (групповой риск) | never-raise контракт (INV-1); merge только PR-API без force-push; staging-гейт обязателен; прод не рестартится в рамках merge. Тест AC-11. |
|
||||
|
||||
## Сводный вывод
|
||||
Изменения локализованы в `src/merge_gate.py` + врезка в `_handle_merge_verify`
|
||||
(`src/stage_engine.py`) + новый ключ конфигурации + корневой `.gitattributes`. Схема БД, Plane,
|
||||
внешние HTTP-эндпоинты, реестр QG, `STAGE_TRANSITIONS` — не затронуты. Главный остаточный риск —
|
||||
ложный HOLD на инфра-сбое (R-1), сознательно принят ради устранения ложно-зелёного merge-verify.
|
||||
75
docs/work-items/ORCH-073/12-review.md
Normal file
75
docs/work-items/ORCH-073/12-review.md
Normal file
@@ -0,0 +1,75 @@
|
||||
---
|
||||
type: review
|
||||
work_item_id: ORCH-073
|
||||
verdict: APPROVED
|
||||
version: 1
|
||||
---
|
||||
|
||||
# Review ORCH-073
|
||||
|
||||
## Summary
|
||||
Системный фикс эрозии `main` (фантомный merge ORCH-067/069) реализован строго по
|
||||
ТЗ (FR-1…FR-5) и ADR-001. Все 11 критериев приёмки выполнены, документация обновлена
|
||||
в том же PR, `pytest tests/ -q` → **941 passed**. Self-hosting-инварианты соблюдены
|
||||
(merge только через Gitea PR-API, без force-push в `main`; non-self репо — no-op).
|
||||
Блокирующих и must-fix замечаний нет.
|
||||
|
||||
## Проверка по осям
|
||||
|
||||
### 1. Соответствие ТЗ (02-trz.md)
|
||||
- **FR-1** — `verify_merged_to_main` подтверждает merge ТОЛЬКО `git merge-base --is-ancestor <sha> origin/main`; OR-ветка `pr_already_merged` удалена; пустой SHA / git-ошибка → `False` (fail-closed, never-raise). ✓
|
||||
- **FR-2** — `pr_already_merged` понижен до idempotency-guard, явный in-loop фильтр `merged & head.ref==branch & base.ref=="main"` (не ненадёжный query `head`). ✓
|
||||
- **FR-3** — `merge_pr` выбирает open PR по `head.ref==branch` И `base.ref=="main"`; merge только `POST /pulls/{n}/merge`. ✓
|
||||
- **FR-4** — корневой `.gitattributes` с `CHANGELOG.md merge=union`; `docs/**` намеренно НЕ включён. ✓
|
||||
- **FR-5** — `check_main_regression` (детерминированный, no-LLM) + декларативный append-only `MAIN_REGRESSION_MARKERS`; вызов в `_handle_merge_verify` ПОСЛЕ SHA-в-main и ДО `done`; ALERT-only + HOLD; fail-open на git-ошибке грепа; kill-switch `regression_guard_enabled`. ✓
|
||||
|
||||
### 2. Соответствие ADR (06-adr/ADR-001 + adr-0014)
|
||||
Реализация 1:1 соответствует Р-1…Р-5. G4-аудит и root-cause зафиксированы в ADR
|
||||
(раздел «Root cause (G4 audit)»). Сквозной ADR-0014 заведён, `adr/README.md` обновлён,
|
||||
`adr-0013` помечен как amended. Нарушений глобальных ADR не обнаружено.
|
||||
**AC-1 подтверждён в `origin/main`:** `plane_issue_link`(8), `qg0_title_max`(config.py 3),
|
||||
`verify_merged_to_main`(4). **AC-4 подтверждён:** `git check-attr merge CHANGELOG.md → merge: union`.
|
||||
|
||||
### 3. Качество кода
|
||||
- Строгий never-raise на всех публичных функциях merge_gate; INV-1…INV-5 соблюдены.
|
||||
- Docstrings содержательные, со ссылками на FR/AC/INV; обоснован осознанный trade-off
|
||||
fail-open для marker-grep против fail-closed SHA-в-main.
|
||||
- `_hold_main_regressed` симметричен not-merged-HOLD; уведомления Plane/Telegram best-effort,
|
||||
не ломают HOLD.
|
||||
- Схема БД, реестр `QG_CHECKS`, `STAGE_TRANSITIONS`, внешние HTTP-эндпоинты — не тронуты (как и заявлено).
|
||||
|
||||
### 4. Качество тестов
|
||||
18 тест-кейсов (TC-01…18) в 6 файлах `tests/test_orch073_*.py`, не тривиальные:
|
||||
- TC-02 воспроизводит исходный баг (merged docs-PR не подтверждает merge), проверяет, что
|
||||
PR-флаг verify-ом более не запрашивается.
|
||||
- TC-14/15 различают HOLD по «not-merged» и по «main-regressed».
|
||||
- TC-10 — идемпотентность (нет второго POST merge). TC-17/18 — conditionality/kill-switch.
|
||||
- TC-12 в throwaway-репо реально проверяет union-merge без конфликта.
|
||||
|
||||
## Findings
|
||||
|
||||
### P0 — Blocker
|
||||
- нет
|
||||
|
||||
### P1 — Must fix
|
||||
- нет
|
||||
|
||||
### P2 — Should fix
|
||||
- нет
|
||||
|
||||
### P3 — Nice-to-have
|
||||
- Маркер `("ORCH-073", "check_main_regression", "src/merge_gate.py")` самозагрузочный
|
||||
(попадёт в `origin/main` только после merge этой задачи) — поведение корректное и
|
||||
оговорено в ADR (self-bootstrap), замечание чисто информационное.
|
||||
|
||||
## Документация
|
||||
Полностью обновлена в этом же PR (правило агентов §2/§6, AC-8):
|
||||
- `docs/architecture/README.md` — раздел merge-verify переписан под FR-1 + добавлены регресс-гард (FR-5) и `.gitattributes` (FR-4).
|
||||
- `CHANGELOG.md` — запись в `## [Unreleased]`.
|
||||
- `docs/work-items/ORCH-073/06-adr/ADR-001-*.md` — новый ADR с G4-аудитом; `docs/architecture/adr/adr-0014-*.md` — сквозной ADR; `adr/README.md` обновлён.
|
||||
- `.env.example` — задокументирован новый ключ `ORCH_REGRESSION_GUARD_ENABLED` + блок merge-verify.
|
||||
|
||||
Требование «изменён `src/` → обновлена документация» выполнено. Блокеров по документации нет.
|
||||
|
||||
## Вердикт
|
||||
**APPROVED** — нет P0/P1; код, тесты и документация соответствуют ТЗ/ADR; self-hosting-страховки сохранены.
|
||||
83
docs/work-items/ORCH-073/13-test-report.md
Normal file
83
docs/work-items/ORCH-073/13-test-report.md
Normal file
@@ -0,0 +1,83 @@
|
||||
---
|
||||
type: test-report
|
||||
work_item_id: ORCH-073
|
||||
result: PASS
|
||||
---
|
||||
|
||||
# Test Report — ORCH-073
|
||||
|
||||
CRIT: системный фикс эрозии `main` (фантомный merge ORCH-067/069) + восстановление кода.
|
||||
|
||||
## Окружение
|
||||
- Python: 3.12.13
|
||||
- pytest: 8.3.3
|
||||
- Дата: 2026-06-08
|
||||
- Worktree: `feature/ORCH-073-crit-main-orch-067-069`
|
||||
- Prod health (8500): `{"status":"ok","service":"orchestrator"}` — контейнер не тронут
|
||||
|
||||
## Smoke-тесты API (prod 8500, read-only)
|
||||
| Endpoint | Результат |
|
||||
|----------|-----------|
|
||||
| `GET /health` | `{"status":"ok"}` — PASS |
|
||||
| `GET /status` | active_tasks отдаётся, ORCH-073 на стадии `testing` — PASS |
|
||||
| `GET /queue` | counts/reconcile/reaper/post_deploy снимок отдаётся, breaker `closed` — PASS |
|
||||
|
||||
## Результаты по тест-плану (04-test-plan.yaml)
|
||||
|
||||
| TC ID | Описание | Тест-функция | Результат |
|
||||
|-------|----------|--------------|-----------|
|
||||
| TC-01 | verify_merged_to_main: sha — предок main → True (AC-6) | test_tc01_true_when_sha_is_ancestor | PASS |
|
||||
| TC-02 | sha НЕ в main + merged docs-PR → False (баг 067/069, AC-2) | test_tc02_false_when_sha_not_in_main_even_with_merged_docs_pr | PASS |
|
||||
| TC-03 | пустой sha → False (fail-closed) | test_tc03_empty_sha_is_false | PASS |
|
||||
| TC-04 | git error → False (never-raise, INV-1) | test_tc04_never_raises_on_git_error / _worktree_error | PASS |
|
||||
| TC-05 | merged docs-PR не засчитан как code-merge (FR-2) | test_tc05_merged_docs_pr_not_counted | PASS |
|
||||
| TC-06 | merged code-PR распознан (base=main, head=branch) | test_tc06_merged_code_pr_recognised / _onto_non_main_base_not_counted | PASS |
|
||||
| TC-07 | HTTP-ошибка/не-200 → False (never-raise) | test_tc07_non_200_is_false / _http_exception_is_false | PASS |
|
||||
| TC-08 | merge_pr выбирает code-PR, не docs/* (FR-3) | test_tc08_merges_code_pr_not_docs_pr / _skips_pr_onto_non_main_base | PASS |
|
||||
| TC-09 | нет open code-PR → (False,...), без push main (INV-2) | test_tc09_no_open_pr_no_shell_out | PASS |
|
||||
| TC-10 | merge_pr идемпотентен, без второго POST (AC-7/INV-4) | test_tc10_idempotent_already_merged | PASS |
|
||||
| TC-11 | .gitattributes: CHANGELOG.md merge=union (AC-4) | test_tc11_gitattributes_declares_union | PASS |
|
||||
| TC-12 | union-merge сохраняет обе записи Unreleased без конфликта | test_tc12_union_merge_keeps_both_entries | PASS |
|
||||
| TC-13 | _handle_merge_verify: SHA в main + маркеры → advance (AC-6) | test_tc13_confirmed_and_intact_advances | PASS |
|
||||
| TC-14 | docs-only merge → HOLD + alert, НЕ done (AC-3) | test_tc14_sha_not_in_main_holds | PASS |
|
||||
| TC-15 | регресс-гард: маркер ранее-merged задачи пропал → HOLD + alert (AC-5) | test_tc15_marker_missing_holds | PASS |
|
||||
| TC-16 | внутр. ошибка верификатора → HOLD + alert, never-raise (INV-1) | test_tc16_internal_error_holds_never_raises | PASS |
|
||||
| TC-17 | conditionality: non-self/kill-switch → под-гейт no-op (AC-6/INV-5) | test_tc17_merge_verify_applies_scope / _under_gate_noop_for_non_self | PASS |
|
||||
| TC-18 | регресс-гард уважает kill-switch / non-self → no-op (INV-5) | test_tc18_guard_kill_switch_skips_guard / _guard_noop_for_non_self_repo | PASS |
|
||||
| TC-19 | полный pytest tests/ -q зелёный (AC-8) | весь набор tests/ | PASS |
|
||||
|
||||
Все 19 TC из тест-плана покрыты (24 тест-функции в 6 файлах `tests/test_orch073_*.py`).
|
||||
|
||||
## Проверка критериев приёмки (03-acceptance-criteria.md)
|
||||
|
||||
| AC | Проверка | Результат |
|
||||
|----|----------|-----------|
|
||||
| AC-1 | Маркеры в origin/main: plane_issue_link=8, qg0_title_max=3, verify_merged_to_main=4 (все >0) | PASS |
|
||||
| AC-2 | TC-02: sha не в main + merged docs-PR → False | PASS |
|
||||
| AC-3 | TC-14: docs-only merge → HOLD + alert, НЕ done | PASS |
|
||||
| AC-4 | `git check-attr merge CHANGELOG.md` → `merge: union`; TC-11/12 | PASS |
|
||||
| AC-5 | TC-15: уменьшение набора маркеров → HOLD + alert «main regressed» | PASS |
|
||||
| AC-6 | TC-01/13/17: happy-path done без ложного alert; enduro no-op | PASS |
|
||||
| AC-7 | TC-10: re-drive слитой задачи → no-op, без второго merge | PASS |
|
||||
| AC-8 | 941 passed; доки/ADR/CHANGELOG обновлены (см. 12-review) | PASS |
|
||||
| AC-9 | G4-аудит в ADR-001 (root cause docs-only merge) — подтверждён reviewer | PASS |
|
||||
| AC-10 | staging-проверка — стадия deploy-staging (вне scope tester) | — |
|
||||
| AC-11 | merge только PR-API; прод-контейнер не падал в рамках тестов | PASS |
|
||||
|
||||
## Вывод pytest
|
||||
|
||||
```
|
||||
tests/ -q --tb=short:
|
||||
........................................................................ [100%]
|
||||
941 passed, 1 warning in 25.37s
|
||||
|
||||
tests/test_orch073_*.py -v:
|
||||
24 passed, 1 warning in 0.54s
|
||||
```
|
||||
(1 warning — PydanticDeprecatedSince20 в src/config.py, не относится к ORCH-073, не блокирует.)
|
||||
|
||||
## Итог
|
||||
**PASS** — полный регресс зелёный (941 passed), все 24 теста ORCH-073 PASS, smoke API OK,
|
||||
маркеры AC-1 присутствуют в `origin/main`, прод-контейнер не затронут. Задача готова к
|
||||
переходу на стадию `deploy-staging` (где будет проверен AC-10 — воспроизведение «исправлено
|
||||
навсегда» на двух задачах с правкой CHANGELOG).
|
||||
36
docs/work-items/ORCH-073/15-staging-log.md
Normal file
36
docs/work-items/ORCH-073/15-staging-log.md
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
staging_status: SUCCESS
|
||||
timestamp: 2026-06-08T13:29:31Z
|
||||
base_url: http://localhost:8501
|
||||
---
|
||||
|
||||
# Staging Gate Log
|
||||
|
||||
Staging test suite completed. All REAL pipeline checks passed (8/10).
|
||||
|
||||
Run canonically inside the `orchestrator-staging` container (ORCH-048, ADR-001):
|
||||
|
||||
```
|
||||
docker exec orchestrator-staging \
|
||||
python3 /repos/orchestrator/scripts/staging_check.py \
|
||||
--base-url http://localhost:8501 --mode stub
|
||||
```
|
||||
|
||||
Exit code: **0** → advance.
|
||||
|
||||
## Results
|
||||
|
||||
- **Block A (SMOKE)**: A1 /health, A2 /queue, A3 ORCH_STAGING=true — all PASS
|
||||
- **Block B (ACCESS)**: B4 Plane sandbox, B5 Gitea sandbox (push=true), B6 registry isolation (sandbox present, prod ET/ORCH absent) — all PASS
|
||||
- **Block C (E2E, stub)**: C7 create issue, C8 trigger pipeline — PASS; C9a/C9b — waived sandbox-infra
|
||||
|
||||
REAL failed: none.
|
||||
|
||||
## Infra waiver (ORCH-061)
|
||||
|
||||
```
|
||||
INFRA-WAIVED: C9a Branch appears in orchestrator-sandbox, C9b Analyst job enqueued in staging queue (known sandbox-infra; real checks green)
|
||||
VERDICT: SUCCESS (exit 0) — SUCCESS (infra-waived): ['C9a Branch appears in orchestrator-sandbox', 'C9b Analyst job enqueued in staging queue'] are known sandbox-infra checks; all real checks green
|
||||
```
|
||||
|
||||
The two waived checks (C9a branch, C9b analyst-job) depend on SANDBOX bot accounts being members of the sandbox Plane project — infra-only, not pipeline regression. Tolerated under `staging_infra_tolerance_enabled=true` since every REAL check is green. Exit code remains the source of truth (fail-closed: any REAL failure still yields exit 1).
|
||||
@@ -682,8 +682,8 @@ class AgentLauncher:
|
||||
"\u274c Deploy FAILED (smoke/healthcheck). Rolled back. Developer \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0444\u0438\u043a\u0441\u0430.",
|
||||
author="deployer",
|
||||
)
|
||||
from ..notifications import send_telegram
|
||||
send_telegram(f"\U0001f6a8 {_wid}: Deploy failed! Rolled back. Needs fix.")
|
||||
from ..notifications import send_telegram, link_for
|
||||
send_telegram(f"\U0001f6a8 {link_for(_wid)}: Deploy failed! Rolled back. Needs fix.")
|
||||
|
||||
# Notify on startup timeout (exit_code from kill = -9 or 137)
|
||||
if exit_code != 0 and exit_code not in (None,):
|
||||
@@ -695,8 +695,8 @@ class AgentLauncher:
|
||||
conn.close()
|
||||
if task_row and agent != "deployer": # deployer handled above
|
||||
_tid, _wid = task_row
|
||||
from ..notifications import send_telegram
|
||||
send_telegram(f"\u26a0\ufe0f {_wid}: Agent {agent} failed (exit_code={exit_code}). Check logs: /app/data/runs/{run_id}.log")
|
||||
from ..notifications import send_telegram, link_for
|
||||
send_telegram(f"\u26a0\ufe0f {link_for(_wid, _tid)}: Agent {agent} failed (exit_code={exit_code}). Check logs: /app/data/runs/{run_id}.log")
|
||||
|
||||
# Feature 4 + ORCH-016: post the unified per-agent status comment under
|
||||
# that agent's bot, threading the wall-clock duration we just measured
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from pydantic import field_validator
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
@@ -395,17 +396,63 @@ class Settings(BaseSettings):
|
||||
merge_pr_timeout_s: int = 60
|
||||
merge_verify_timeout_s: int = 60
|
||||
|
||||
# ORCH-073 (ADR-001 Р-4): main-integrity regression guard. After the merge-verify
|
||||
# under-gate confirms the deployed SHA is an ancestor of origin/main (FR-1), a
|
||||
# secondary deterministic (no-LLM) guard checks that a declarative set of markers
|
||||
# for recently-merged tasks (MAIN_REGRESSION_MARKERS in merge_gate.py) is still
|
||||
# present in origin/main — i.e. a CHANGELOG-rebase or phantom-merge did not silently
|
||||
# roll back a neighbouring task's code. A missing marker (deterministic count==0) ->
|
||||
# ALERT + HOLD (task stays on `deploy`, NOT done); an infra/git error on the grep
|
||||
# itself -> fail-OPEN (do not block done; SHA-in-main remains the primary gate).
|
||||
# regression_guard_enabled -> kill-switch (env ORCH_REGRESSION_GUARD_ENABLED);
|
||||
# reuses the merge_verify_applies scope (self-hosting /
|
||||
# merge_verify_repos), so non-self repos are a no-op.
|
||||
regression_guard_enabled: bool = True
|
||||
|
||||
# Telegram notifications
|
||||
telegram_bot_token: str = ""
|
||||
telegram_chat_id: str = ""
|
||||
|
||||
# ORCH-042: режим live-трекера задачи.
|
||||
# edit -> карточка редактируется на месте (editMessageText), ДЕФОЛТ (как было).
|
||||
# bump -> при обновлении старое сообщение удаляется и карточка отправляется
|
||||
# заново вниз чата (deleteMessage + sendMessage + repoint message_id),
|
||||
# тихо (disable_notification). Одна карточка на задачу в обоих режимах.
|
||||
# Неизвестное/пустое значение трактуется как edit (см. notifications).
|
||||
tracker_mode: str = "edit"
|
||||
# bump (ДЕФОЛТ с ORCH-067) -> при обновлении старое сообщение удаляется и
|
||||
# карточка отправляется заново вниз чата (deleteMessage + sendMessage
|
||||
# + repoint message_id), тихо (disable_notification).
|
||||
# edit -> карточка редактируется на месте (editMessageText); доступен через
|
||||
# ORCH_TRACKER_MODE=edit.
|
||||
# Одна карточка на задачу в обоих режимах. Неизвестное/пустое значение
|
||||
# трактуется как edit (см. notifications).
|
||||
tracker_mode: str = "bump"
|
||||
|
||||
# ORCH-067 (ADR Р-2/Р-3/Р-4): best-effort live-overlay для статус-строки
|
||||
# карточки. Дорисовывает ветки Plane-статуса, неотличимые offline по
|
||||
# tasks.stage (Needs Input / Blocked / Rejected / Cancelled / Deploying /
|
||||
# Monitoring after Deploy) — читая ЖИВОЙ Plane-статус с коротким таймаутом и
|
||||
# TTL-кэшем. Offline-ядро (stage -> статус, In Review из brd-clock) работает
|
||||
# всегда без сети; overlay лишь дополняет его и НИКОГДА не блокирует конвейер.
|
||||
# tracker_live_status -> kill-switch (False -> только offline-ядро).
|
||||
# tracker_live_status_ttl_s -> TTL per-issue кэша live-uuid (защита hot-path).
|
||||
# tracker_live_status_timeout_s -> таймаут одного live-GET в пути рендера.
|
||||
tracker_live_status: bool = True
|
||||
tracker_live_status_ttl_s: int = 60
|
||||
tracker_live_status_timeout_s: int = 3
|
||||
|
||||
# ORCH-069: QG-0 upper title-length limit (entry gate _qg0_errors). The 80-char
|
||||
# cap was a hygiene limit, not structural (slug is cut to [:30] independently,
|
||||
# DB title TEXT is unbounded). Configurable via env ORCH_QG0_TITLE_MAX; default
|
||||
# 200 (was hardcoded 80). Invalid/empty value -> default (graceful, no crash).
|
||||
qg0_title_max: int = 200
|
||||
|
||||
@field_validator("qg0_title_max", mode="before")
|
||||
@classmethod
|
||||
def _qg0_title_max_default(cls, v):
|
||||
# Graceful (ORCH-069 AC-3): empty / non-numeric env -> default 200, the
|
||||
# process must not crash on startup. Never raises (self-hosting safety).
|
||||
try:
|
||||
if v is None or (isinstance(v, str) and v.strip() == ""):
|
||||
return 200
|
||||
return int(v)
|
||||
except (TypeError, ValueError):
|
||||
return 200
|
||||
|
||||
class Config:
|
||||
env_prefix = "ORCH_"
|
||||
|
||||
@@ -445,25 +445,30 @@ def reclaim_stale_lease(repo: str) -> bool:
|
||||
# ORCH-065: idempotent merge finalization guard (Problem C)
|
||||
# ---------------------------------------------------------------------------
|
||||
def pr_already_merged(repo: str, branch: str) -> bool:
|
||||
"""Return True iff the PR for ``branch`` is ALREADY merged (ADR-001 Р-3, FR-3.2).
|
||||
"""Return True iff the **code-PR of ``branch``** is ALREADY merged (idempotency-guard).
|
||||
|
||||
A deterministic, read-only guard the merge path consults BEFORE attempting a
|
||||
(second) merge so a re-driven / reaped task is idempotent: an already-merged
|
||||
PR -> no-op, never a duplicate merge and never an error. This is the ONLY new
|
||||
merge-related helper and it does NOT merge — it only READS the PR state via
|
||||
the existing Gitea client, so it does not introduce duplicate merge logic.
|
||||
ORCH-073 ADR-001 Р-2 (FR-2): this is an **idempotency-guard for ``merge_pr``**, NOT
|
||||
a source of truth for ``done`` (the only proof of merge is SHA-in-main, FR-1 /
|
||||
``verify_merged_to_main``). It lets a re-driven / reaped ``merge_pr`` be idempotent:
|
||||
the code-PR is already merged -> no-op, never a duplicate merge.
|
||||
|
||||
Consultation point: the actual merge actor is the **deployer agent** (it merges
|
||||
the feature PR at the start of the ``deploy`` stage — see webhooks/gitea.py),
|
||||
so the wiring lives in the deployer prompt (``.openclaw/agents/deployer.md``),
|
||||
which runs this exact function before any (re-)merge. The merge-gate quality
|
||||
check (``qg.checks.check_branch_mergeable``) is intentionally NOT modified
|
||||
(ORCH-065 AC-13: ``check_*`` behaviour unchanged) — it runs on the FIRST
|
||||
deploy-staging -> deploy edge and does not re-run on a ``deploy``-stage re-drive,
|
||||
which is exactly where the second-merge risk lives.
|
||||
Root-cause fix (G4 audit): the previous implementation returned True for ANY
|
||||
``merged == True`` PR returned by ``GET /pulls?state=all&head=<branch>``. Gitea's
|
||||
``head`` query-param filters unreliably for a bare branch name, so auto docs-PRs
|
||||
(staging/deploy logs, ``head=docs/*``) leaked into the result and were counted as
|
||||
"merged" — the ORCH-067/069 phantom-merge. We now apply an EXPLICIT in-loop filter
|
||||
instead of trusting the query-param: a PR counts only when it carries the code of
|
||||
THIS feature-branch into ``main``:
|
||||
|
||||
* ``pr.merged is True`` AND
|
||||
* ``pr.head.ref == branch`` (the code of exactly this feature-branch) AND
|
||||
* ``pr.base.ref == "main"`` (target is main, not a docs/other base).
|
||||
|
||||
This excludes auto docs-PRs (different ``head.ref``) and PRs onto a non-``main``
|
||||
base, so a merged docs-PR can no longer make ``merge_pr`` skip a real code merge.
|
||||
|
||||
Queries Gitea ``GET /repos/{owner}/{repo}/pulls?state=all&head=<branch>`` and
|
||||
reports True when any matching PR has ``merged == True``. Never raises (AC-9):
|
||||
reports True only when a matching PR passes the filter above. Never raises (AC-9):
|
||||
any HTTP/parse error -> ``False`` (conservative: "not known-merged" lets the
|
||||
normal gate re-evaluate rather than silently skipping a real merge).
|
||||
"""
|
||||
@@ -479,7 +484,11 @@ def pr_already_merged(repo: str, branch: str) -> bool:
|
||||
if resp.status_code != 200:
|
||||
return False
|
||||
for pr in resp.json() or []:
|
||||
if pr.get("merged") is True:
|
||||
if (
|
||||
pr.get("merged") is True
|
||||
and pr.get("head", {}).get("ref") == branch
|
||||
and pr.get("base", {}).get("ref") == "main"
|
||||
):
|
||||
return True
|
||||
return False
|
||||
except Exception as e: # noqa: BLE001 - never-raise contract
|
||||
@@ -505,6 +514,7 @@ def pr_already_merged(repo: str, branch: str) -> bool:
|
||||
_MERGE_VERIFY_COUNTERS: dict = {
|
||||
"merge_verified_total": 0,
|
||||
"not_merged_alerts_total": 0,
|
||||
"main_regressed_alerts_total": 0, # ORCH-073 Р-4: regression-guard HOLD+alert count.
|
||||
"last_alert_wi": None,
|
||||
}
|
||||
|
||||
@@ -526,6 +536,15 @@ def note_not_merged_alert(work_item_id: str | None) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def note_main_regressed_alert(work_item_id: str | None) -> None:
|
||||
"""Bump the 'main regressed (marker missing)' counter (ORCH-073 Р-4). Never raises."""
|
||||
try:
|
||||
_MERGE_VERIFY_COUNTERS["main_regressed_alerts_total"] += 1
|
||||
_MERGE_VERIFY_COUNTERS["last_alert_wi"] = work_item_id
|
||||
except Exception: # noqa: BLE001 - observability must never break a decision
|
||||
pass
|
||||
|
||||
|
||||
def merge_verify_status() -> dict:
|
||||
"""Snapshot of the merge-verify under-gate for GET /queue. Never raises."""
|
||||
try:
|
||||
@@ -534,6 +553,7 @@ def merge_verify_status() -> dict:
|
||||
"repos": settings.merge_verify_repos or "",
|
||||
"merge_verified_total": _MERGE_VERIFY_COUNTERS["merge_verified_total"],
|
||||
"not_merged_alerts_total": _MERGE_VERIFY_COUNTERS["not_merged_alerts_total"],
|
||||
"main_regressed_alerts_total": _MERGE_VERIFY_COUNTERS["main_regressed_alerts_total"],
|
||||
"last_alert_wi": _MERGE_VERIFY_COUNTERS["last_alert_wi"],
|
||||
}
|
||||
except Exception as e: # noqa: BLE001 - never-raise contract
|
||||
@@ -578,7 +598,10 @@ def merge_pr(repo: str, branch: str) -> tuple[bool, str]:
|
||||
Algorithm:
|
||||
1. ``pr_already_merged`` -> True -> no-op ``(True, "already-merged")`` (INV-5/AC-9).
|
||||
2. ``GET /repos/{owner}/{repo}/pulls?state=open`` -> the open PR whose head ref
|
||||
== ``branch`` -> its index. No open PR -> ``(False, "no open PR")``.
|
||||
== ``branch`` AND base ref == ``main`` -> its index. ORCH-073 ADR-001 Р-3
|
||||
(FR-3) adds the ``base == main`` filter so the actor merges exactly the
|
||||
feature code-PR and never an auto docs-PR / a PR onto a foreign base. No
|
||||
such open PR -> ``(False, "no open PR")``.
|
||||
3. ``POST /repos/{owner}/{repo}/pulls/{index}/merge`` (Do: ``merge``) ->
|
||||
200/201 -> ``(True, "merged PR #<n>")``; otherwise ``(False, "<reason>")``.
|
||||
|
||||
@@ -602,7 +625,10 @@ def merge_pr(repo: str, branch: str) -> tuple[bool, str]:
|
||||
return False, f"list PRs failed: HTTP {resp.status_code}"
|
||||
index = None
|
||||
for pr in resp.json() or []:
|
||||
if pr.get("head", {}).get("ref") == branch:
|
||||
if (
|
||||
pr.get("head", {}).get("ref") == branch
|
||||
and pr.get("base", {}).get("ref") == "main"
|
||||
):
|
||||
index = pr.get("number")
|
||||
break
|
||||
if index is None:
|
||||
@@ -631,26 +657,32 @@ def merge_pr(repo: str, branch: str) -> tuple[bool, str]:
|
||||
def verify_merged_to_main(repo: str, branch: str, sha: str) -> bool:
|
||||
"""Return True iff the deployed commit is confirmed merged into ``origin/main``.
|
||||
|
||||
Post-deploy verification (FR-2 / D4): the merge is confirmed when EITHER
|
||||
* ``pr_already_merged(repo, branch)`` is True (Gitea ``PR.merged == true``), OR
|
||||
* ``git merge-base --is-ancestor <sha> origin/main`` succeeds in the per-branch
|
||||
worktree (after ``git fetch origin main``), i.e. the validated SHA is an
|
||||
ancestor of the current ``origin/main``.
|
||||
Post-deploy verification — ORCH-073 ADR-001 Р-1 (FR-1): the merge is confirmed by
|
||||
the SINGLE, authoritative fact "the deployed commit IS an ancestor of the current
|
||||
``origin/main``":
|
||||
|
||||
* after ``git fetch origin main`` (in the per-branch worktree),
|
||||
``git merge-base --is-ancestor <sha> origin/main`` returns ``rc == 0``.
|
||||
|
||||
The former OR-branch ``pr_already_merged(repo, branch)`` was REMOVED: a merged
|
||||
``PR.merged == true`` is no longer sufficient to confirm a merge. That branch was
|
||||
the ORCH-067/069 phantom-merge root cause — an auto docs-PR (staging/deploy logs)
|
||||
counted as "merged" via the unreliable Gitea ``head`` query, turning merge-verify
|
||||
falsely GREEN while the code-PR was never merged. ``pr_already_merged`` now serves
|
||||
ONLY as an idempotency-guard inside ``merge_pr`` (Р-2/Р-3), never as proof of merge.
|
||||
|
||||
``sha`` is the validated commit (``image_freshness.validated_revision`` =
|
||||
worktree ``git rev-parse HEAD``). An empty ``sha`` makes the git branch
|
||||
inconclusive (only the PR-merged branch can then confirm).
|
||||
worktree ``git rev-parse HEAD``). An empty ``sha`` is inconclusive -> ``False``
|
||||
(fail-closed: alert + HOLD), since the SHA-in-main check cannot run without it.
|
||||
|
||||
Never-raise (INV-1/AC-7 / TC-04): any git/HTTP error -> ``False`` (= "not
|
||||
confirmed" -> fail-closed for ``done``: alert + HOLD). The exception is NEVER
|
||||
propagated into ``advance_stage``.
|
||||
"""
|
||||
try:
|
||||
if pr_already_merged(repo, branch):
|
||||
return True
|
||||
if not sha:
|
||||
logger.warning(
|
||||
"verify_merged_to_main: empty SHA for %s/%s and PR not known-merged",
|
||||
"verify_merged_to_main: empty SHA for %s/%s -> cannot confirm SHA-in-main",
|
||||
repo, branch,
|
||||
)
|
||||
return False
|
||||
@@ -675,3 +707,110 @@ def verify_merged_to_main(repo: str, branch: str, sha: str) -> bool:
|
||||
"verify_merged_to_main unexpected error for %s/%s: %s", repo, branch, e
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# ORCH-073 (ADR-001 Р-4): main-integrity regression guard.
|
||||
#
|
||||
# A secondary, deterministic (no-LLM) guard that runs in `_handle_merge_verify`
|
||||
# AFTER the SHA-in-main check (verify_merged_to_main, FR-1) confirms the deployed
|
||||
# commit, and BEFORE the task is stamped `done`. It checks that a DECLARATIVE set
|
||||
# of markers for recently-merged tasks is still present in `origin/main` — i.e. a
|
||||
# CHANGELOG-rebase / phantom-merge did not silently roll back a neighbouring task's
|
||||
# code (the ORCH-067/069 failure mode, which SHA-in-main alone would not catch when
|
||||
# the deployed SHA itself IS in main but a sibling's code is gone).
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Declarative, append-only marker set (ADR-001 Р-4). Each future task that lands
|
||||
# significant code SHOULD append its own (task, marker_substring, path) row so the
|
||||
# guard protects it from a later phantom-merge / rebase rollback. Kept in code (not
|
||||
# DB / Plane — a non-goal) so it versions together with the fix it protects.
|
||||
MAIN_REGRESSION_MARKERS: list[tuple[str, str, str]] = [
|
||||
("ORCH-067", "plane_issue_link", "src/notifications.py"),
|
||||
("ORCH-069", "qg0_title_max", "src/config.py"),
|
||||
("ORCH-071", "verify_merged_to_main", "src/merge_gate.py"),
|
||||
("ORCH-073", "check_main_regression", "src/merge_gate.py"),
|
||||
]
|
||||
|
||||
|
||||
def check_main_regression(repo: str, branch: str) -> tuple[bool, str]:
|
||||
"""Verify the declarative marker set is still present in ``origin/main``.
|
||||
|
||||
ORCH-073 ADR-001 Р-4 (FR-5). For each ``(task, marker, path)`` in
|
||||
``MAIN_REGRESSION_MARKERS`` run ``git grep -c <marker> origin/main -- <path>`` in
|
||||
the per-branch worktree (after ``git fetch origin main``). A DETERMINISTIC count
|
||||
of ``0`` for any marker means a neighbouring task's code was rolled back ->
|
||||
regression.
|
||||
|
||||
Returns ``(ok, reason)``:
|
||||
* ``(True, "markers intact (<n>)")`` — every marker present -> proceed.
|
||||
* ``(False, "main regressed: <task> ...")`` — a marker is deterministically
|
||||
absent (count==0) -> caller HOLDs the task (NOT done) + alerts.
|
||||
|
||||
**Fail-OPEN on infra error** (intentional trade-off, ADR-001 Р-4): any git/OS
|
||||
error on the grep itself -> ``(True, "guard inconclusive: <reason>")`` so a flaky
|
||||
git never produces a false HOLD. "Regressed" is asserted ONLY on a deterministic
|
||||
``count == 0``, never on "could not determine". The PRIMARY fail-closed gate is
|
||||
SHA-in-main (FR-1); this marker-grep is a secondary, best-effort guard.
|
||||
|
||||
Never raises (INV-1): any unexpected error -> ``(True, "guard error: ...")``.
|
||||
"""
|
||||
try:
|
||||
try:
|
||||
wt = ensure_worktree(repo, branch)
|
||||
except Exception as e: # noqa: BLE001 - never-raise contract -> fail-open
|
||||
logger.warning(
|
||||
"check_main_regression: worktree error for %s/%s: %s (fail-open)",
|
||||
repo, branch, e,
|
||||
)
|
||||
return True, f"guard inconclusive: worktree error: {e}"
|
||||
|
||||
try:
|
||||
subprocess.run(
|
||||
["git", "-C", wt, "fetch", "origin", "main"],
|
||||
capture_output=True, timeout=settings.merge_verify_timeout_s,
|
||||
)
|
||||
except (subprocess.SubprocessError, OSError) as e:
|
||||
logger.warning(
|
||||
"check_main_regression: fetch error for %s/%s: %s (fail-open)",
|
||||
repo, branch, e,
|
||||
)
|
||||
return True, f"guard inconclusive: fetch error: {e}"
|
||||
|
||||
for task, marker, path in MAIN_REGRESSION_MARKERS:
|
||||
try:
|
||||
r = subprocess.run(
|
||||
["git", "-C", wt, "grep", "-c", marker, "origin/main", "--", path],
|
||||
capture_output=True, text=True, timeout=_SHORT_TIMEOUT,
|
||||
)
|
||||
except (subprocess.SubprocessError, OSError) as e:
|
||||
# Infra error on this marker -> fail-open (do NOT assert regression).
|
||||
logger.warning(
|
||||
"check_main_regression: grep error for %s (%s @ %s): %s (fail-open)",
|
||||
task, marker, path, e,
|
||||
)
|
||||
return True, f"guard inconclusive: grep error for {task}: {e}"
|
||||
# git grep exit codes: 0 = match(es) found, 1 = no match, >1 = real error.
|
||||
if r.returncode == 0:
|
||||
continue
|
||||
if r.returncode == 1:
|
||||
# Deterministic absence -> regression of a neighbouring task's code.
|
||||
logger.warning(
|
||||
"check_main_regression: marker MISSING in origin/main for %s "
|
||||
"(%s @ %s) -> main regressed", task, marker, path,
|
||||
)
|
||||
return False, f"main regressed: {task} code missing ({marker} @ {path})"
|
||||
# rc > 1 -> git error (e.g. bad path/ref) -> inconclusive -> fail-open.
|
||||
logger.warning(
|
||||
"check_main_regression: ambiguous git grep rc=%s for %s (%s @ %s) "
|
||||
"(fail-open)", r.returncode, task, marker, path,
|
||||
)
|
||||
return True, f"guard inconclusive: git grep rc={r.returncode} for {task}"
|
||||
|
||||
return True, f"markers intact ({len(MAIN_REGRESSION_MARKERS)})"
|
||||
except Exception as e: # noqa: BLE001 - never-raise contract -> fail-open
|
||||
logger.warning(
|
||||
"check_main_regression unexpected error for %s/%s: %s (fail-open)",
|
||||
repo, branch, e,
|
||||
)
|
||||
return True, f"guard error: {e}"
|
||||
|
||||
@@ -307,7 +307,7 @@ def render_task_tracker(task_id: int) -> str:
|
||||
conn = get_db()
|
||||
task = conn.execute(
|
||||
"SELECT id, work_item_id, title, stage, created_at, updated_at, "
|
||||
"brd_review_started_at, brd_review_ended_at "
|
||||
"brd_review_started_at, brd_review_ended_at, repo, plane_issue_id "
|
||||
"FROM tasks WHERE id=?",
|
||||
(task_id,),
|
||||
).fetchone()
|
||||
@@ -358,13 +358,27 @@ def render_task_tracker(task_id: int) -> str:
|
||||
agent_seconds += d
|
||||
|
||||
esc_title = html.escape(title)
|
||||
# ORCH-067 (req 3): the issue number in the header is now a clickable link to
|
||||
# the Plane issue (degrades to the escaped number when no web URL \u2014 fail-safe).
|
||||
task_repo = _row_get(task, "repo")
|
||||
task_issue_id = _row_get(task, "plane_issue_id")
|
||||
num_html = plane_issue_link(work_item_id, plane_issue_id=task_issue_id, repo=task_repo)
|
||||
header = (
|
||||
f"\U0001f389 {html.escape(work_item_id)} \u00b7 {esc_title} \u2014 \u0413\u041e\u0422\u041e\u0412\u041e"
|
||||
f"\U0001f389 {num_html} \u00b7 {esc_title} \u2014 \u0413\u041e\u0422\u041e\u0412\u041e"
|
||||
if done
|
||||
else f"\U0001f6e0\ufe0f {html.escape(work_item_id)} \u00b7 {esc_title}"
|
||||
else f"\U0001f6e0\ufe0f {num_html} \u00b7 {esc_title}"
|
||||
)
|
||||
bar = "\u2501" * 22
|
||||
lines = [header, bar]
|
||||
# ORCH-067 (req 2): a Plane-status line (model ORCH-066) under the header.
|
||||
# Built fail-safe: any error degrades to a stage default, never breaks render.
|
||||
try:
|
||||
status_label = _card_status_label(
|
||||
task, repo=task_repo, plane_issue_id=task_issue_id
|
||||
)
|
||||
except Exception:
|
||||
status_label = _DEFAULT_STATUS_LABEL
|
||||
status_line = f"\U0001f4cd {status_label}"
|
||||
lines = [header, status_line, bar]
|
||||
|
||||
def _stage_line(label, run):
|
||||
usage = {
|
||||
@@ -704,38 +718,276 @@ def _build_brd_link(repo, branch, work_item_id) -> str | None:
|
||||
)
|
||||
|
||||
|
||||
def _plane_issue_url(repo, plane_issue_id, project_id=None) -> str | None:
|
||||
"""ORCH-067 (Р-5): build the Plane issue browser URL, or None if unbuildable.
|
||||
|
||||
Single source of the URL + guards, shared by ``plane_issue_link`` (link text =
|
||||
issue number) and ``_build_plane_issue_link`` (link text = '✅ Задача в Plane'),
|
||||
so the project resolution and loopback-guard live in ONE place (ORCH-017 Р-2).
|
||||
|
||||
Full path: ``{web_base}/{workspace}/projects/{project_id}/issues/{issue_id}/``.
|
||||
web_base = plane_web_url or plane_api_url; a loopback base counts as "no web
|
||||
URL" -> None. ``project_id`` is taken explicitly when given, else resolved from
|
||||
``repo``. Never raises.
|
||||
"""
|
||||
try:
|
||||
s = _get_settings()
|
||||
web_base = (
|
||||
getattr(s, "plane_web_url", "") or getattr(s, "plane_api_url", "")
|
||||
).rstrip("/")
|
||||
workspace = getattr(s, "plane_workspace_slug", "")
|
||||
if not (web_base and workspace and plane_issue_id) or _is_loopback_base(web_base):
|
||||
return None
|
||||
if not project_id:
|
||||
try:
|
||||
from .projects import get_project_by_repo
|
||||
project = get_project_by_repo(repo) if repo else None
|
||||
except Exception:
|
||||
project = None
|
||||
project_id = getattr(project, "plane_project_id", "") if project else ""
|
||||
if not project_id:
|
||||
return None
|
||||
return (
|
||||
f"{web_base}/{workspace}/projects/{project_id}/issues/{plane_issue_id}/"
|
||||
)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def _build_plane_issue_link(repo, plane_issue_id) -> str | None:
|
||||
"""ORCH-017: '<a>' to the Plane issue browser page, or None if unusable.
|
||||
|
||||
Full path per ADR-001 Р-2:
|
||||
``{web_base}/{workspace_slug}/projects/{project_id}/issues/{issue_id}/``.
|
||||
web_base = plane_web_url or plane_api_url (AC-3); a loopback base is treated
|
||||
as "no web URL" and the link is omitted (loopback-guard, AC-2/AC-6).
|
||||
Link text = '✅ Задача в Plane'. URL built by the shared ``_plane_issue_url``
|
||||
(loopback / workspace / project guards, ADR-001 Р-2 / ORCH-067 Р-5).
|
||||
"""
|
||||
s = _get_settings()
|
||||
web_base = (
|
||||
getattr(s, "plane_web_url", "") or getattr(s, "plane_api_url", "")
|
||||
).rstrip("/")
|
||||
workspace = getattr(s, "plane_workspace_slug", "")
|
||||
if not (web_base and workspace and plane_issue_id) or _is_loopback_base(web_base):
|
||||
url = _plane_issue_url(repo, plane_issue_id)
|
||||
if not url:
|
||||
return None
|
||||
try:
|
||||
from .projects import get_project_by_repo
|
||||
project = get_project_by_repo(repo) if repo else None
|
||||
except Exception:
|
||||
project = None
|
||||
if not project or not getattr(project, "plane_project_id", ""):
|
||||
return None
|
||||
url = (
|
||||
f"{web_base}/{workspace}/projects/{project.plane_project_id}"
|
||||
f"/issues/{plane_issue_id}/"
|
||||
)
|
||||
return (
|
||||
f'<a href="{html.escape(url, quote=True)}">'
|
||||
f"✅ Задача в Plane</a>"
|
||||
)
|
||||
|
||||
|
||||
def plane_issue_link(work_item_id, plane_issue_id=None, project_id=None, repo=None) -> str:
|
||||
"""ORCH-067 (Р-5): clickable issue number for cards / alerts.
|
||||
|
||||
Returns ``<a href=...>ORCH-NNN</a>`` when a Plane web URL can be built, else
|
||||
``html.escape(work_item_id)`` (number without a link). Never raises.
|
||||
|
||||
Link text is always ``html.escape(work_item_id)``; the href is built by the
|
||||
shared ``_plane_issue_url`` (same loopback / workspace / project guards as the
|
||||
'✅ Задача в Plane' link). On any missing piece -> the escaped number.
|
||||
"""
|
||||
label = html.escape(str(work_item_id)) if work_item_id is not None else ""
|
||||
try:
|
||||
url = _plane_issue_url(repo, plane_issue_id, project_id)
|
||||
if not url:
|
||||
return label
|
||||
return f'<a href="{html.escape(url, quote=True)}">{label}</a>'
|
||||
except Exception:
|
||||
return label
|
||||
|
||||
|
||||
def link_for(work_item_id, task_id=None) -> str:
|
||||
"""ORCH-067 (Р-6): clickable issue number for alert points that hold only a
|
||||
``work_item_id`` (or ``task_id``).
|
||||
|
||||
Resolves ``(repo, plane_issue_id)`` from the DB (by ``task_id`` when given,
|
||||
else the latest task row for ``work_item_id``) and delegates to
|
||||
``plane_issue_link``. On any missing data -> ``html.escape(work_item_id)``.
|
||||
Never raises.
|
||||
"""
|
||||
if not work_item_id:
|
||||
return html.escape(str(work_item_id)) if work_item_id is not None else ""
|
||||
repo = None
|
||||
plane_issue_id = None
|
||||
try:
|
||||
from .db import get_db
|
||||
conn = get_db()
|
||||
if task_id is not None:
|
||||
row = conn.execute(
|
||||
"SELECT repo, plane_issue_id FROM tasks WHERE id=?", (task_id,)
|
||||
).fetchone()
|
||||
else:
|
||||
row = conn.execute(
|
||||
"SELECT repo, plane_issue_id FROM tasks WHERE work_item_id=? "
|
||||
"ORDER BY id DESC LIMIT 1",
|
||||
(work_item_id,),
|
||||
).fetchone()
|
||||
conn.close()
|
||||
if row:
|
||||
repo = row["repo"]
|
||||
plane_issue_id = row["plane_issue_id"]
|
||||
except Exception as e:
|
||||
logger.debug(f"link_for({work_item_id}) DB lookup failed: {e}")
|
||||
return plane_issue_link(work_item_id, plane_issue_id=plane_issue_id, repo=repo)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# ORCH-067: Plane status label for the live card (layer B indication, ADR Р-1)
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
# Offline stage -> Plane status label. Names are the final ORCH-066 status names
|
||||
# (_PLANE_NAME_TO_KEY). Pure / deterministic — derived entirely from tasks.stage
|
||||
# (+ the brd-clock for In Review), NEVER from the network.
|
||||
_STAGE_STATUS_LABEL = {
|
||||
"created": "To Analyse",
|
||||
"analysis": "Analysis",
|
||||
"architecture": "Architecture",
|
||||
"development": "Development",
|
||||
"review": "Code-Review",
|
||||
"testing": "Testing",
|
||||
"deploy": "⏸️ Awaiting Deploy — ожидание Confirm Deploy",
|
||||
"done": "Done",
|
||||
}
|
||||
_DEFAULT_STATUS_LABEL = "To Analyse"
|
||||
_IN_REVIEW_LABEL = (
|
||||
"⏸️ In Review — ожидание "
|
||||
"согласования BRD"
|
||||
)
|
||||
|
||||
# Live-overlay branch labels (keys not derivable offline from tasks.stage).
|
||||
_LIVE_BRANCH_LABELS = {
|
||||
"needs_input": "❓ Needs Input — нужны уточнения",
|
||||
"blocked": "Blocked",
|
||||
"rejected": "Rejected",
|
||||
"cancelled": "Cancelled",
|
||||
"deploying": "Deploying",
|
||||
"monitoring": "Monitoring after Deploy",
|
||||
}
|
||||
# ORCH-066 (Р-1 anti-false-positive): deploying/monitoring alias their BASE key's
|
||||
# UUID on a project without dedicated statuses (enduro). Override is applied ONLY
|
||||
# when the project really defined a SEPARATE UUID for the branch key.
|
||||
_LIVE_BRANCH_BASE = {
|
||||
"deploying": "in_progress",
|
||||
"monitoring": "done",
|
||||
}
|
||||
|
||||
|
||||
def _row_get(row, key, default=None):
|
||||
"""Safe sqlite3.Row / dict / object getter. Never raises."""
|
||||
try:
|
||||
return row[key]
|
||||
except Exception:
|
||||
try:
|
||||
return getattr(row, key, default)
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
def plane_status_label(task_row) -> str:
|
||||
"""ORCH-067 (Р-1, layer 1): current Plane status label for the card header.
|
||||
|
||||
Pure / deterministic from the task row, NEVER hits the network, NEVER raises.
|
||||
On unknown / broken input -> a safe stage default. ``⏸️ In Review`` and
|
||||
``⏸️ Awaiting Deploy`` are produced here (offline), so both work without a
|
||||
network connection (AC-7, AC-8). Branch statuses that are indistinguishable
|
||||
offline (Needs Input / Blocked / …) are drawn by ``_live_plane_branch_override``.
|
||||
"""
|
||||
try:
|
||||
stage = _row_get(task_row, "stage") or "created"
|
||||
except Exception:
|
||||
return _DEFAULT_STATUS_LABEL
|
||||
try:
|
||||
if stage == "analysis":
|
||||
started = _row_get(task_row, "brd_review_started_at")
|
||||
ended = _row_get(task_row, "brd_review_ended_at")
|
||||
if started and not ended:
|
||||
return _IN_REVIEW_LABEL
|
||||
return _STAGE_STATUS_LABEL.get(stage, _DEFAULT_STATUS_LABEL)
|
||||
except Exception:
|
||||
return _DEFAULT_STATUS_LABEL
|
||||
|
||||
|
||||
# ORCH-067 (Р-3): per-issue TTL cache of the live state uuid -> {issue_id: (ts, uuid)}.
|
||||
_LIVE_STATE_CACHE: dict[str, tuple] = {}
|
||||
|
||||
|
||||
def _live_state_uuid_cached(plane_issue_id, project_id):
|
||||
"""ORCH-067 (Р-3/Р-4): TTL-cached single live-state read for the render path.
|
||||
|
||||
At most one ``fetch_issue_state`` per issue per ``tracker_live_status_ttl_s``
|
||||
with a SHORT timeout. Never raises -> None on any failure.
|
||||
"""
|
||||
try:
|
||||
import time
|
||||
s = _get_settings()
|
||||
ttl = getattr(s, "tracker_live_status_ttl_s", 60)
|
||||
now = time.monotonic()
|
||||
hit = _LIVE_STATE_CACHE.get(plane_issue_id)
|
||||
if hit is not None and (now - hit[0]) <= ttl:
|
||||
return hit[1]
|
||||
from .plane_sync import fetch_issue_state
|
||||
timeout = getattr(s, "tracker_live_status_timeout_s", 3)
|
||||
uuid = fetch_issue_state(plane_issue_id, project_id, timeout=timeout)
|
||||
_LIVE_STATE_CACHE[plane_issue_id] = (now, uuid)
|
||||
return uuid
|
||||
except Exception as e:
|
||||
logger.debug(f"_live_state_uuid_cached({plane_issue_id}) failed: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def _live_plane_branch_override(repo, plane_issue_id, base_label) -> str:
|
||||
"""ORCH-067 (Р-1 layer 2 / Р-2): best-effort live-status overlay.
|
||||
|
||||
Draws the branch statuses that are indistinguishable from ``tasks.stage``
|
||||
offline (Needs Input / Blocked / Rejected / Cancelled / Deploying / Monitoring
|
||||
after Deploy) by reading the LIVE Plane status (short timeout, TTL cache). Any
|
||||
failure / disabled kill-switch / missing data -> ``base_label`` (offline). The
|
||||
pipeline is NEVER blocked. Never raises.
|
||||
"""
|
||||
try:
|
||||
s = _get_settings()
|
||||
if not getattr(s, "tracker_live_status", True):
|
||||
return base_label
|
||||
if not plane_issue_id:
|
||||
return base_label
|
||||
try:
|
||||
from .projects import get_project_by_repo
|
||||
project = get_project_by_repo(repo) if repo else None
|
||||
except Exception:
|
||||
project = None
|
||||
project_id = getattr(project, "plane_project_id", "") if project else ""
|
||||
if not project_id:
|
||||
return base_label
|
||||
live_uuid = _live_state_uuid_cached(plane_issue_id, project_id)
|
||||
if not live_uuid:
|
||||
return base_label
|
||||
from .plane_sync import get_project_states
|
||||
states = get_project_states(project_id)
|
||||
for key, label in _LIVE_BRANCH_LABELS.items():
|
||||
uuid = states.get(key)
|
||||
if not uuid or uuid != live_uuid:
|
||||
continue
|
||||
base_key = _LIVE_BRANCH_BASE.get(key)
|
||||
if base_key and states.get(base_key) == uuid:
|
||||
# deploying/monitoring just alias their base key on this project
|
||||
# (enduro / no dedicated status) -> not a real branch, don't override.
|
||||
continue
|
||||
return label
|
||||
return base_label
|
||||
except Exception as e:
|
||||
logger.debug(f"_live_plane_branch_override failed: {e}")
|
||||
return base_label
|
||||
|
||||
|
||||
def _card_status_label(task_row, repo=None, plane_issue_id=None) -> str:
|
||||
"""ORCH-067: full status label for the card = offline core + live overlay.
|
||||
|
||||
Precedence (Р-1): if the offline core resolved ``⏸️ In Review`` (brd-clock,
|
||||
authoritative) the overlay is NOT consulted; otherwise the overlay may draw a
|
||||
branch status. Never raises (AC-9).
|
||||
"""
|
||||
try:
|
||||
base = plane_status_label(task_row)
|
||||
if base == _IN_REVIEW_LABEL:
|
||||
return base
|
||||
return _live_plane_branch_override(repo, plane_issue_id, base)
|
||||
except Exception:
|
||||
return _DEFAULT_STATUS_LABEL
|
||||
|
||||
|
||||
def notify_approve_requested(task_id: int):
|
||||
"""ALERT (separate, notifying): BRD/TZ/AC ready -> flip Plane to Approved.
|
||||
|
||||
@@ -749,7 +1001,7 @@ def notify_approve_requested(task_id: int):
|
||||
except Exception as e:
|
||||
logger.warning(f"notify_approve_requested: brd clock start failed: {e}")
|
||||
msg = (
|
||||
f"\U0001f4cb {html.escape(work_item_id)}: BRD/\u0422\u0417/AC \u0433\u043e\u0442\u043e\u0432\u044b. "
|
||||
f"\U0001f4cb {link_for(work_item_id, task_id)}: BRD/\u0422\u0417/AC \u0433\u043e\u0442\u043e\u0432\u044b. "
|
||||
f"\u041f\u0435\u0440\u0435\u0432\u0435\u0434\u0438\u0442\u0435 \u0437\u0430\u0434\u0430\u0447\u0443 \u0432 \u0441\u0442\u0430\u0442\u0443\u0441 Approved "
|
||||
f"\u0432 Plane \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f."
|
||||
)
|
||||
@@ -783,8 +1035,14 @@ def notify_done(task_id: int):
|
||||
|
||||
|
||||
def notify_error(task_id: int, error: str):
|
||||
"""ALERT (separate, notifying): task error."""
|
||||
"""ALERT (separate, notifying): task error.
|
||||
|
||||
ORCH-067 (req 4): the issue number is a clickable Plane link (fail-safe ->
|
||||
raw number) and the error text is html-escaped so it cannot break the <a>
|
||||
markup under parse_mode=HTML (AC-14).
|
||||
"""
|
||||
work_item_id = _get_work_item_id(task_id) if task_id else "system"
|
||||
msg = f"\U0001f534 {work_item_id}: ERROR \u2014 {error}"
|
||||
num = link_for(work_item_id, task_id) if task_id else html.escape(work_item_id)
|
||||
msg = f"\U0001f534 {num}: ERROR \u2014 {html.escape(str(error))}"
|
||||
logger.error(msg)
|
||||
send_telegram(msg) # separate, notifying
|
||||
|
||||
@@ -402,7 +402,7 @@ def fetch_issue_sequence_id(issue_id: str, project_id: str) -> int | None:
|
||||
return None
|
||||
|
||||
|
||||
def fetch_issue_state(issue_id: str, project_id: str) -> str | None:
|
||||
def fetch_issue_state(issue_id: str, project_id: str, timeout: int = 10) -> str | None:
|
||||
"""ORCH-060 (F-1 Guard 2): GET the Plane issue and return its current state uuid.
|
||||
|
||||
Used by the reconciler to honour an explicit human gate: an issue a person
|
||||
@@ -413,12 +413,16 @@ def fetch_issue_state(issue_id: str, project_id: str) -> str | None:
|
||||
Plane returns ``state`` as a bare uuid string; older shapes may nest it as a
|
||||
``{"id": ...}`` dict — both are handled.
|
||||
|
||||
ORCH-067 (Р-4): ``timeout`` is optional (default 10s — unchanged for the
|
||||
reconciler) so the tracker live-overlay can read with a SHORT timeout
|
||||
(settings.tracker_live_status_timeout_s) on the synchronous render path.
|
||||
|
||||
Returns None on network error, non-2xx, or a missing field — never raises, so
|
||||
the caller can apply its conservative fallback (treat as "possibly blocked").
|
||||
"""
|
||||
url = f"{PLANE_BASE}/workspaces/{WORKSPACE}/projects/{project_id}/issues/{issue_id}/"
|
||||
try:
|
||||
resp = httpx.get(url, headers=PLANE_HEADERS, timeout=10)
|
||||
resp = httpx.get(url, headers=PLANE_HEADERS, timeout=timeout)
|
||||
resp.raise_for_status()
|
||||
state = resp.json().get("state")
|
||||
if isinstance(state, dict):
|
||||
|
||||
@@ -67,7 +67,7 @@ from .plane_sync import (
|
||||
list_issues_by_state,
|
||||
)
|
||||
from .webhooks.plane import handle_status_start, handle_verdict
|
||||
from .notifications import send_telegram
|
||||
from .notifications import send_telegram, link_for
|
||||
from . import projects
|
||||
|
||||
logger = logging.getLogger("orchestrator.reconciler")
|
||||
@@ -447,7 +447,7 @@ class Reconciler:
|
||||
if settings.reconcile_notify_unblock:
|
||||
try:
|
||||
send_telegram(
|
||||
f"\U0001f527 reconciler: {work_item_id} {stage} "
|
||||
f"\U0001f527 reconciler: {link_for(work_item_id)} {stage} "
|
||||
f"разблокирована (потерян webhook)"
|
||||
)
|
||||
except Exception as e: # noqa: BLE001 - never break the tick
|
||||
|
||||
@@ -670,9 +670,9 @@ def check_security_gate(repo: str, work_item_id: str, branch: str) -> tuple[bool
|
||||
dep_result.detail,
|
||||
)
|
||||
try:
|
||||
from .notifications import send_telegram
|
||||
from .notifications import send_telegram, link_for
|
||||
send_telegram(
|
||||
f"⚠️ {work_item_id}: dep-audit недоступен фид CVE "
|
||||
f"⚠️ {link_for(work_item_id)}: dep-audit недоступен фид CVE "
|
||||
f"({dep_result.detail}). "
|
||||
+ ("Гейт fail-closed → FAIL." if settings.security_dep_audit_fail_closed
|
||||
else "Гейт fail-open → warning (секреты проверены оффлайн).")
|
||||
|
||||
@@ -44,6 +44,7 @@ from .notifications import (
|
||||
notify_qg_failure,
|
||||
notify_approve_requested,
|
||||
send_telegram,
|
||||
link_for,
|
||||
)
|
||||
from .plane_sync import (
|
||||
notify_stage_change as plane_notify_stage,
|
||||
@@ -611,7 +612,7 @@ def _handle_analysis_approved_flow(
|
||||
author="analyst",
|
||||
)
|
||||
send_telegram(
|
||||
f"\u2753 {work_item_id}: Analyst \u0437\u0430\u0434\u0430\u0451\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b. \u041e\u0442\u0432\u0435\u0442\u044c \u0432 Plane."
|
||||
f"\u2753 {link_for(work_item_id)}: Analyst \u0437\u0430\u0434\u0430\u0451\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b. \u041e\u0442\u0432\u0435\u0442\u044c \u0432 Plane."
|
||||
)
|
||||
result.note = "analysis-needs-input"
|
||||
return
|
||||
@@ -670,7 +671,7 @@ def _handle_qg_failure_rollbacks(
|
||||
)
|
||||
else:
|
||||
send_telegram(
|
||||
f"\u26a0\ufe0f {work_item_id}: Max developer retries (3) reached. "
|
||||
f"\u26a0\ufe0f {link_for(work_item_id)}: Max developer retries (3) reached. "
|
||||
f"Manual intervention needed."
|
||||
)
|
||||
result.alerted = True
|
||||
@@ -717,7 +718,7 @@ def _handle_qg_failure_rollbacks(
|
||||
else:
|
||||
set_issue_blocked(work_item_id)
|
||||
send_telegram(
|
||||
f"\U0001f6a8 {work_item_id}: Tests still failing after 3 developer "
|
||||
f"\U0001f6a8 {link_for(work_item_id)}: Tests still failing after 3 developer "
|
||||
f"retries. Manual intervention needed."
|
||||
)
|
||||
result.alerted = True
|
||||
@@ -774,7 +775,7 @@ def _handle_qg_failure_rollbacks(
|
||||
author="deployer",
|
||||
)
|
||||
send_telegram(
|
||||
f"\U0001f6a8 {work_item_id}: Staging FAILED ({reason}). "
|
||||
f"\U0001f6a8 {link_for(work_item_id)}: Staging FAILED ({reason}). "
|
||||
f"Rolled back to development. Needs fix."
|
||||
)
|
||||
result.alerted = True
|
||||
@@ -818,7 +819,7 @@ def _handle_qg_failure_rollbacks(
|
||||
author="deployer",
|
||||
)
|
||||
send_telegram(
|
||||
f"\U0001f6a8 {work_item_id}: Deploy FAILED ({reason}). "
|
||||
f"\U0001f6a8 {link_for(work_item_id)}: Deploy FAILED ({reason}). "
|
||||
f"Rolled back to development. Needs fix."
|
||||
)
|
||||
result.alerted = True
|
||||
@@ -914,7 +915,7 @@ def _handle_merge_gate_defer(
|
||||
else:
|
||||
set_issue_blocked(work_item_id)
|
||||
send_telegram(
|
||||
f"\U0001f6a8 {work_item_id}: merge-gate defer limit "
|
||||
f"\U0001f6a8 {link_for(work_item_id)}: merge-gate defer limit "
|
||||
f"({settings.merge_defer_max_attempts}) reached (merge-lock busy). "
|
||||
f"Manual intervention needed."
|
||||
)
|
||||
@@ -969,7 +970,7 @@ def _handle_merge_gate_rollback(
|
||||
else:
|
||||
set_issue_blocked(work_item_id)
|
||||
send_telegram(
|
||||
f"\U0001f6a8 {work_item_id}: Merge-gate still failing after "
|
||||
f"\U0001f6a8 {link_for(work_item_id)}: Merge-gate still failing after "
|
||||
f"{MAX_DEVELOPER_RETRIES} developer retries ({reason}). "
|
||||
f"Manual intervention needed."
|
||||
)
|
||||
@@ -1055,7 +1056,7 @@ def _handle_security_gate(
|
||||
else:
|
||||
set_issue_blocked(work_item_id)
|
||||
send_telegram(
|
||||
f"\U0001f6a8 {work_item_id}: Security-гейт still failing after "
|
||||
f"\U0001f6a8 {link_for(work_item_id)}: Security-гейт still failing after "
|
||||
f"{MAX_DEVELOPER_RETRIES} developer retries ({reason}). "
|
||||
f"Manual intervention needed."
|
||||
)
|
||||
@@ -1132,7 +1133,7 @@ def _handle_image_freshness(
|
||||
else:
|
||||
set_issue_blocked(work_item_id)
|
||||
send_telegram(
|
||||
f"\U0001f6a8 {work_item_id}: Staging image freshness still failing after "
|
||||
f"\U0001f6a8 {link_for(work_item_id)}: Staging image freshness still failing after "
|
||||
f"{MAX_DEVELOPER_RETRIES} developer retries ({reason}). "
|
||||
f"Manual intervention needed."
|
||||
)
|
||||
@@ -1190,7 +1191,7 @@ def _handle_self_deploy_phase_a(
|
||||
author="deployer",
|
||||
)
|
||||
send_telegram(
|
||||
f"\U0001f7e1 {work_item_id}: staging OK. Ждёт подтверждения ПРОД-деплоя "
|
||||
f"\U0001f7e1 {link_for(work_item_id)}: staging OK. Ждёт подтверждения ПРОД-деплоя "
|
||||
f"(смените статус на «Confirm Deploy»)."
|
||||
)
|
||||
logger.info(
|
||||
@@ -1225,7 +1226,7 @@ def _handle_self_deploy_phase_b(task_id, repo, work_item_id, branch, result: Adv
|
||||
"Повторите approve после устранения причины.",
|
||||
author="deployer",
|
||||
)
|
||||
send_telegram(f"⚠️ {work_item_id}: прод-деплой не запустился: {msg}")
|
||||
send_telegram(f"⚠️ {link_for(work_item_id)}: прод-деплой не запустился: {msg}")
|
||||
logger.error(f"Task {task_id}: self-deploy initiate failed: {msg}")
|
||||
return
|
||||
|
||||
@@ -1254,7 +1255,7 @@ def _handle_self_deploy_phase_b(task_id, repo, work_item_id, branch, result: Adv
|
||||
"Вердикт будет зафиксирован после health-check.",
|
||||
author="deployer",
|
||||
)
|
||||
send_telegram(f"\U0001f680 {work_item_id}: прод-деплой стартовал. Жду результат.")
|
||||
send_telegram(f"\U0001f680 {link_for(work_item_id)}: прод-деплой стартовал. Жду результат.")
|
||||
logger.info(
|
||||
f"Task {task_id}: self-deploy Phase B — detached deploy initiated, "
|
||||
f"finalizer enqueued (job_id={new_job})"
|
||||
@@ -1276,6 +1277,50 @@ def _deploy_finalize_defer_count(task_id: int) -> int:
|
||||
return n
|
||||
|
||||
|
||||
def _hold_main_regressed(
|
||||
task_id, repo, work_item_id, branch, guard_msg: str, result: AdvanceResult
|
||||
) -> bool:
|
||||
"""HOLD the task because the regression guard found neighbouring code missing.
|
||||
|
||||
ORCH-073 Р-4 (FR-5 / AC-5): the deployed SHA IS in `main` (FR-1 passed) but a
|
||||
declarative marker of a recently-merged task is gone -> a phantom-merge / rebase
|
||||
rolled back sibling code. Reaction is ALERT-only + HOLD (Telegram + Plane
|
||||
``set_issue_blocked`` + comment), task stays on `deploy` (NOT done), NO rollback
|
||||
to development (an infra defect, not a code fault — symmetric to the not-merged
|
||||
HOLD). Returns ``True`` (INTERVENED). Never breaks the HOLD on a notify error.
|
||||
"""
|
||||
merge_gate.note_main_regressed_alert(work_item_id)
|
||||
msg = (
|
||||
f"main regressed: {guard_msg} (repo={repo}, branch={branch}, "
|
||||
f"wi={work_item_id}). Соседний код пропал из `main` — задача удержана на "
|
||||
f"`deploy` (НЕ done). Нужно ручное восстановление кода."
|
||||
)
|
||||
logger.warning(f"Task {task_id}: {msg}")
|
||||
if work_item_id:
|
||||
try:
|
||||
set_issue_blocked(work_item_id)
|
||||
except Exception as e: # noqa: BLE001 - never break the HOLD
|
||||
logger.warning(f"Task {task_id}: set_issue_blocked failed: {e}")
|
||||
try:
|
||||
plane_add_comment(
|
||||
work_item_id,
|
||||
"\U0001f6a8 Регресс `main`: " + guard_msg + ". Код соседней задачи "
|
||||
"пропал из `main`. Задача удержана на `deploy` (НЕ done) — нужно "
|
||||
"восстановить код и повторить approve.",
|
||||
author="deployer",
|
||||
)
|
||||
except Exception as e: # noqa: BLE001 - never break the HOLD
|
||||
logger.warning(f"Task {task_id}: plane regressed comment failed: {e}")
|
||||
try:
|
||||
send_telegram(f"\U0001f6a8 {msg}")
|
||||
except Exception as e: # noqa: BLE001 - never break the HOLD
|
||||
logger.warning(f"Task {task_id}: main-regressed telegram failed: {e}")
|
||||
result.alerted = True
|
||||
result.note = "main-regressed-hold"
|
||||
result.advanced = False
|
||||
return True
|
||||
|
||||
|
||||
def _handle_merge_verify(task_id, repo, work_item_id, branch, result: AdvanceResult) -> bool:
|
||||
"""ORCH-071 merge-verify under-gate on the `deploy -> done` edge.
|
||||
|
||||
@@ -1316,6 +1361,20 @@ def _handle_merge_verify(task_id, repo, work_item_id, branch, result: AdvanceRes
|
||||
|
||||
confirmed = merge_gate.verify_merged_to_main(repo, branch, sha)
|
||||
if confirmed:
|
||||
# ORCH-073 Р-4 (FR-5): secondary main-integrity regression guard. The
|
||||
# deployed SHA is in main (FR-1), but a CHANGELOG-rebase / phantom-merge
|
||||
# could still have rolled back a NEIGHBOURING task's code. Verify the
|
||||
# declarative marker set is intact; a deterministic miss -> HOLD + alert
|
||||
# (NOT done, no rollback — an infra defect, not a code fault). Fail-OPEN
|
||||
# on a git error of the guard itself (SHA-in-main remains the primary
|
||||
# gate). Honours the same scope/kill-switch as the under-gate.
|
||||
if settings.regression_guard_enabled:
|
||||
guard_ok, guard_msg = merge_gate.check_main_regression(repo, branch)
|
||||
if not guard_ok:
|
||||
return _hold_main_regressed(
|
||||
task_id, repo, work_item_id, branch, guard_msg, result
|
||||
)
|
||||
|
||||
merge_gate.note_merge_verified()
|
||||
try:
|
||||
self_deploy.record_merged_to_main(repo, work_item_id, branch, True)
|
||||
@@ -1365,7 +1424,7 @@ def _handle_merge_verify(task_id, repo, work_item_id, branch, result: AdvanceRes
|
||||
try:
|
||||
merge_gate.note_not_merged_alert(work_item_id)
|
||||
send_telegram(
|
||||
f"\U0001f6a8 {work_item_id}: ошибка merge-verify ({e}). "
|
||||
f"\U0001f6a8 {link_for(work_item_id)}: ошибка merge-verify ({e}). "
|
||||
f"Задача удержана на `deploy` (НЕ done)."
|
||||
)
|
||||
except Exception: # noqa: BLE001 - best-effort alert
|
||||
@@ -1423,7 +1482,7 @@ def run_deploy_finalizer(job: dict):
|
||||
if work_item_id:
|
||||
set_issue_blocked(work_item_id)
|
||||
send_telegram(
|
||||
f"\U0001f6a8 {work_item_id}: deploy result не появился после "
|
||||
f"\U0001f6a8 {link_for(work_item_id)}: deploy result не появился после "
|
||||
f"{settings.deploy_finalize_max_attempts} попыток. Нужно ручное вмешательство."
|
||||
)
|
||||
logger.error(
|
||||
@@ -1444,7 +1503,7 @@ def run_deploy_finalizer(job: dict):
|
||||
f"✅ Прод-деплой успешен (health-check OK, exit {code}).",
|
||||
author="deployer",
|
||||
)
|
||||
send_telegram(f"✅ {work_item_id}: прод-деплой успешен (exit {code}).")
|
||||
send_telegram(f"✅ {link_for(work_item_id)}: прод-деплой успешен (exit {code}).")
|
||||
|
||||
# Drive the EXISTING deploy contracts via the gate verdict we just wrote.
|
||||
advance_stage(
|
||||
|
||||
@@ -416,8 +416,11 @@ def _qg0_errors(name: str, description: str) -> list:
|
||||
errors = []
|
||||
if not name or len(name) < 5:
|
||||
errors.append("Title \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 (\u043d\u0443\u0436\u043d\u043e >= 5 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432)")
|
||||
if len(name) > 80:
|
||||
errors.append("Title \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u044b\u0439 (\u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c 80 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432)")
|
||||
if len(name) > settings.qg0_title_max:
|
||||
errors.append(
|
||||
f"Title \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u044b\u0439 "
|
||||
f"(\u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c {settings.qg0_title_max} \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432)"
|
||||
)
|
||||
if not description or len(description.strip()) < 20:
|
||||
errors.append("Description \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 (\u043d\u0443\u0436\u043d\u043e >= 20 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432)")
|
||||
|
||||
|
||||
@@ -94,4 +94,8 @@ def _disable_merge_verify(monkeypatch):
|
||||
"""
|
||||
from src import config as _cfg
|
||||
monkeypatch.setattr(_cfg.settings, "merge_verify_enabled", False, raising=False)
|
||||
# ORCH-073: the regression guard (check_main_regression) runs real git in
|
||||
# _handle_merge_verify's confirmed branch. Default it OFF too so unrelated
|
||||
# deploy->done tests stay 1:1; the dedicated ORCH-073 tests re-enable it.
|
||||
monkeypatch.setattr(_cfg.settings, "regression_guard_enabled", False, raising=False)
|
||||
yield
|
||||
|
||||
@@ -8,9 +8,17 @@ builds a FRESH Settings() (the process-wide singleton is not mutated).
|
||||
from src.config import Settings
|
||||
|
||||
|
||||
def test_tracker_mode_defaults_to_edit(monkeypatch):
|
||||
# No env var -> default "edit" (TC-01 / AC-1).
|
||||
def test_tracker_mode_defaults_to_bump(monkeypatch):
|
||||
# ORCH-067 (TC-01 / AC-1): the default flipped edit -> bump. With no env var
|
||||
# the card now re-creates at the bottom of the chat out of the box; edit
|
||||
# stays available via ORCH_TRACKER_MODE=edit (see test below).
|
||||
monkeypatch.delenv("ORCH_TRACKER_MODE", raising=False)
|
||||
assert Settings().tracker_mode == "bump"
|
||||
|
||||
|
||||
def test_tracker_mode_reads_env_edit(monkeypatch):
|
||||
# ORCH-067 (AC-4): edit mode is still available through the env var.
|
||||
monkeypatch.setenv("ORCH_TRACKER_MODE", "edit")
|
||||
assert Settings().tracker_mode == "edit"
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ def test_tc07_merge_actor_calls_gitea_merge(monkeypatch):
|
||||
|
||||
def fake_get(url, params=None, headers=None, timeout=None):
|
||||
get_calls.append((url, params))
|
||||
return _Resp(200, [{"head": {"ref": branch}, "number": 7}])
|
||||
return _Resp(200, [{"head": {"ref": branch}, "base": {"ref": "main"}, "number": 7}])
|
||||
|
||||
def fake_post(url, json=None, headers=None, timeout=None):
|
||||
post_calls.append((url, json))
|
||||
@@ -104,7 +104,7 @@ def test_tc09_never_raise_on_http_error(monkeypatch):
|
||||
def test_tc09_merge_endpoint_non_2xx_is_false(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate, "pr_already_merged", lambda r, b: False)
|
||||
monkeypatch.setattr(
|
||||
httpx, "get", lambda *a, **k: _Resp(200, [{"head": {"ref": "feature/ORCH-071-x"}, "number": 3}])
|
||||
httpx, "get", lambda *a, **k: _Resp(200, [{"head": {"ref": "feature/ORCH-071-x"}, "base": {"ref": "main"}, "number": 3}])
|
||||
)
|
||||
monkeypatch.setattr(httpx, "post", lambda *a, **k: _Resp(409, text="conflict"))
|
||||
ok, msg = merge_gate.merge_pr("orchestrator", "feature/ORCH-071-x")
|
||||
@@ -119,7 +119,7 @@ def test_tc09_merge_endpoint_non_2xx_is_false(monkeypatch):
|
||||
def test_tc13_no_shell_out_no_force_push(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate, "pr_already_merged", lambda r, b: False)
|
||||
monkeypatch.setattr(
|
||||
httpx, "get", lambda *a, **k: _Resp(200, [{"head": {"ref": "feature/ORCH-071-x"}, "number": 9}])
|
||||
httpx, "get", lambda *a, **k: _Resp(200, [{"head": {"ref": "feature/ORCH-071-x"}, "base": {"ref": "main"}, "number": 9}])
|
||||
)
|
||||
monkeypatch.setattr(httpx, "post", lambda *a, **k: _Resp(200))
|
||||
|
||||
|
||||
@@ -315,10 +315,17 @@ class _FakeResp:
|
||||
|
||||
|
||||
def test_tc16_pr_already_merged_true(monkeypatch):
|
||||
"""A merged PR -> True so a re-driven/reaped task is a no-op (no second merge)."""
|
||||
"""A merged code-PR -> True so a re-driven/reaped task is a no-op (no second merge).
|
||||
|
||||
ORCH-073 FR-2: the guard now counts a PR only when it carries THIS branch's code
|
||||
into main (merged & head.ref==branch & base.ref=="main").
|
||||
"""
|
||||
monkeypatch.setattr(
|
||||
httpx, "get",
|
||||
lambda *a, **k: _FakeResp(200, [{"number": 7, "merged": True}]),
|
||||
lambda *a, **k: _FakeResp(
|
||||
200,
|
||||
[{"number": 7, "merged": True, "head": {"ref": "feature/x"}, "base": {"ref": "main"}}],
|
||||
),
|
||||
)
|
||||
assert merge_gate.pr_already_merged("orchestrator", "feature/x") is True
|
||||
|
||||
|
||||
@@ -204,7 +204,9 @@ def test_tc17_pr_already_merged_makes_redrive_a_noop(race_repo, monkeypatch):
|
||||
|
||||
@staticmethod
|
||||
def json():
|
||||
return [{"merged": True}]
|
||||
# ORCH-073 FR-2: the guard counts a PR only when it carries THIS branch's
|
||||
# code into main (merged & head.ref==branch & base.ref=="main").
|
||||
return [{"merged": True, "head": {"ref": "feature/B"}, "base": {"ref": "main"}}]
|
||||
|
||||
monkeypatch.setattr(httpx, "get", lambda *a, **k: _R())
|
||||
assert merge_gate.pr_already_merged(repo, "feature/B") is True
|
||||
|
||||
@@ -49,17 +49,22 @@ def test_tc01_verify_true_when_sha_is_ancestor(monkeypatch):
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-02: PR.merged==true short-circuits to True even if git is unavailable.
|
||||
# TC-02 (ORCH-073 FR-1): PR.merged==true NO LONGER confirms a merge. The former
|
||||
# OR-branch was the phantom-merge root cause (a merged docs-PR turned verify green).
|
||||
# SHA-in-main is now the SINGLE criterion; an empty SHA -> inconclusive -> False.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc02_verify_true_when_pr_merged_even_without_git(monkeypatch):
|
||||
def test_tc02_pr_merged_does_not_confirm_without_sha_in_main(monkeypatch):
|
||||
# Even if a (docs-)PR is reported merged, that must NOT short-circuit to True.
|
||||
monkeypatch.setattr(merge_gate, "pr_already_merged", lambda r, b: True)
|
||||
|
||||
def boom(*a, **k):
|
||||
raise RuntimeError("git must NOT be consulted when PR is already merged")
|
||||
|
||||
monkeypatch.setattr(merge_gate, "ensure_worktree", boom)
|
||||
monkeypatch.setattr(merge_gate.subprocess, "run", boom)
|
||||
assert merge_gate.verify_merged_to_main("orchestrator", "feature/ORCH-071-x", "") is True
|
||||
monkeypatch.setattr(merge_gate, "ensure_worktree", lambda r, b: "/wt")
|
||||
# SHA not an ancestor of origin/main (rc=1) -> not confirmed despite merged PR.
|
||||
monkeypatch.setattr(
|
||||
merge_gate.subprocess, "run",
|
||||
lambda cmd, *a, **k: _R(1) if "merge-base" in cmd else _R(0),
|
||||
)
|
||||
assert merge_gate.verify_merged_to_main("orchestrator", "feature/ORCH-071-x", "abc123") is False
|
||||
# And an empty SHA is inconclusive -> False (cannot prove SHA-in-main).
|
||||
assert merge_gate.verify_merged_to_main("orchestrator", "feature/ORCH-071-x", "") is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -93,11 +98,13 @@ def test_tc04_verify_never_raises_on_git_error(monkeypatch):
|
||||
assert merge_gate.verify_merged_to_main("orchestrator", "feature/ORCH-071-x", "abc123") is False
|
||||
|
||||
|
||||
def test_tc04_verify_never_raises_on_http_error(monkeypatch):
|
||||
def boom(r, b):
|
||||
raise RuntimeError("gitea down")
|
||||
def test_tc04_verify_never_raises_on_worktree_error(monkeypatch):
|
||||
# ORCH-073: verify no longer consults pr_already_merged; a worktree/git error
|
||||
# on the SHA-in-main path is the failure to swallow -> conservative False.
|
||||
def boom(*a, **k):
|
||||
raise RuntimeError("worktree exploded")
|
||||
|
||||
monkeypatch.setattr(merge_gate, "pr_already_merged", boom)
|
||||
monkeypatch.setattr(merge_gate, "ensure_worktree", boom)
|
||||
assert merge_gate.verify_merged_to_main("orchestrator", "feature/ORCH-071-x", "abc123") is False
|
||||
|
||||
|
||||
|
||||
206
tests/test_notify_issue_links.py
Normal file
206
tests/test_notify_issue_links.py
Normal file
@@ -0,0 +1,206 @@
|
||||
"""ORCH-067 — Group D: clickable issue number in ALL alerts (AC-13, AC-12).
|
||||
|
||||
Every orchestrator alert that mentions a work_item_id now renders it as a Plane
|
||||
hyperlink via the shared ``link_for`` / ``plane_issue_link`` helpers, and degrades
|
||||
fail-safe to the raw (escaped) number when data is missing. This covers the
|
||||
dedicated notify_* helpers (notify_approve_requested, notify_error) and asserts
|
||||
the engine/launcher/security_gate/reconciler alert sites are wired to ``link_for``
|
||||
— the single DB-resolving helper those sites call. Network is isolated:
|
||||
send_telegram is replaced with a recorder; the DB is a temp SQLite.
|
||||
|
||||
Test ids TC-13, TC-14, TC-15 from 04-test-plan.yaml.
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
os.environ.setdefault("ORCH_PLANE_API_TOKEN", "test-token")
|
||||
os.environ.setdefault("ORCH_GITEA_TOKEN", "test-token")
|
||||
|
||||
_test_db = os.path.join(tempfile.gettempdir(), "test_orchestrator_notify_links.db")
|
||||
os.environ["ORCH_DB_PATH"] = _test_db
|
||||
|
||||
from types import SimpleNamespace # noqa: E402
|
||||
|
||||
import pytest # noqa: E402
|
||||
|
||||
import src.db as db_module # noqa: E402
|
||||
import src.projects as projects_mod # noqa: E402
|
||||
from src.db import init_db, get_db # noqa: E402
|
||||
from src import notifications as N # noqa: E402
|
||||
|
||||
_ORCH_PROJECT_ID = "8da6aa25-a60e-44d6-a1e2-d8ae59aa7d6a"
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_db(monkeypatch):
|
||||
monkeypatch.setattr(db_module.settings, "db_path", _test_db, raising=False)
|
||||
if os.path.exists(_test_db):
|
||||
os.unlink(_test_db)
|
||||
init_db()
|
||||
# Pin repo->project resolution so cross-file registry reloads can't strip
|
||||
# 'orchestrator' and break the expected issue URL.
|
||||
monkeypatch.setattr(
|
||||
projects_mod, "get_project_by_repo",
|
||||
lambda repo: (SimpleNamespace(plane_project_id=_ORCH_PROJECT_ID)
|
||||
if repo == "orchestrator" else None),
|
||||
)
|
||||
yield
|
||||
if os.path.exists(_test_db):
|
||||
os.unlink(_test_db)
|
||||
|
||||
|
||||
def _set(monkeypatch, **kw):
|
||||
s = N._get_settings()
|
||||
for k, v in kw.items():
|
||||
monkeypatch.setattr(s, k, v, raising=False)
|
||||
|
||||
|
||||
def _mk_task(wid="ORCH-067", repo="orchestrator", title="notify links",
|
||||
plane_issue_id="iss-1", stage="development"):
|
||||
conn = get_db()
|
||||
cur = conn.execute(
|
||||
"INSERT INTO tasks (plane_id, work_item_id, repo, branch, stage, title, "
|
||||
"plane_issue_id) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
("p1", wid, repo, "feature/ORCH-067-x", stage, title, plane_issue_id),
|
||||
)
|
||||
tid = cur.lastrowid
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return tid
|
||||
|
||||
|
||||
def _record_send(monkeypatch):
|
||||
calls = []
|
||||
|
||||
def _fake(text, disable_notification=False):
|
||||
calls.append({"text": text, "silent": disable_notification})
|
||||
return 1
|
||||
|
||||
monkeypatch.setattr(N, "send_telegram", _fake)
|
||||
monkeypatch.setattr(N, "update_task_tracker", lambda task_id: None)
|
||||
return calls
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-13 / AC-13 — notify_approve_requested: number clickable, CTA + single ping
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc13_approve_requested_number_clickable(monkeypatch):
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme", gitea_public_url="https://git.example.org",
|
||||
gitea_owner="orchteam")
|
||||
tid = _mk_task(plane_issue_id="iss-1")
|
||||
calls = _record_send(monkeypatch)
|
||||
|
||||
N.notify_approve_requested(tid)
|
||||
|
||||
assert len(calls) == 1 # exactly one notifying ping
|
||||
assert calls[0]["silent"] is not True
|
||||
text = calls[0]["text"]
|
||||
expected = (
|
||||
f"https://plane.example.org/acme/projects/{_ORCH_PROJECT_ID}"
|
||||
f"/issues/iss-1/"
|
||||
)
|
||||
assert f'<a href="{expected}">ORCH-067</a>' in text # clickable number
|
||||
assert "Approved" in text # call-to-action preserved
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-14 / AC-13, AC-12 — notify_error: clickable when data present, else raw
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc14_notify_error_clickable(monkeypatch):
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
tid = _mk_task(plane_issue_id="iss-1")
|
||||
calls = _record_send(monkeypatch)
|
||||
|
||||
N.notify_error(tid, "boom happened")
|
||||
|
||||
assert len(calls) == 1
|
||||
text = calls[0]["text"]
|
||||
assert ">ORCH-067</a>" in text # number is a link
|
||||
assert "ERROR" in text and "boom happened" in text
|
||||
|
||||
|
||||
def test_tc14_notify_error_degrades_raw_number(monkeypatch):
|
||||
# No usable Plane base -> raw (unlinked) number, alert still sent, no crash.
|
||||
_set(monkeypatch, plane_web_url="", plane_api_url="")
|
||||
tid = _mk_task(plane_issue_id="iss-1")
|
||||
calls = _record_send(monkeypatch)
|
||||
|
||||
N.notify_error(tid, "boom")
|
||||
|
||||
text = calls[0]["text"]
|
||||
assert "ORCH-067" in text
|
||||
assert "<a href=" not in text
|
||||
|
||||
|
||||
def test_tc14_notify_error_escapes_error_text(monkeypatch):
|
||||
# The error string is html-escaped so it can't break the <a>/HTML markup.
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
tid = _mk_task(plane_issue_id="iss-1")
|
||||
calls = _record_send(monkeypatch)
|
||||
|
||||
N.notify_error(tid, "<script> & </script>")
|
||||
|
||||
text = calls[0]["text"]
|
||||
assert "<script>" not in text
|
||||
assert "<script>" in text and "&" in text
|
||||
# The clickable number's anchor is still well-formed.
|
||||
assert text.count("<a href=") == text.count("</a>")
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-15 / AC-13 — link_for is the DB-resolving helper the alert sites call
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc15_link_for_by_work_item_id(monkeypatch):
|
||||
# Sites holding only a work_item_id (launcher deploy-fail, security_gate,
|
||||
# reconciler, engine QG-fail) call link_for(wid) -> resolves repo + issue id
|
||||
# from the DB and returns a clickable number.
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
_mk_task(wid="ORCH-067", plane_issue_id="iss-1")
|
||||
|
||||
out = N.link_for("ORCH-067")
|
||||
expected = (
|
||||
f"https://plane.example.org/acme/projects/{_ORCH_PROJECT_ID}"
|
||||
f"/issues/iss-1/"
|
||||
)
|
||||
assert out == f'<a href="{expected}">ORCH-067</a>'
|
||||
|
||||
|
||||
def test_tc15_link_for_by_task_id(monkeypatch):
|
||||
# Sites holding a task_id (launcher agent-fail, engine) call link_for(wid, tid).
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
tid = _mk_task(wid="ORCH-067", plane_issue_id="iss-7")
|
||||
|
||||
out = N.link_for("ORCH-067", tid)
|
||||
assert ">ORCH-067</a>" in out and "/issues/iss-7/" in out
|
||||
|
||||
|
||||
def test_tc15_link_for_unknown_task_degrades(monkeypatch):
|
||||
# No matching DB row -> raw number, never raises.
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
out = N.link_for("ORCH-999")
|
||||
assert out == "ORCH-999"
|
||||
assert "<a href=" not in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("module_name", [
|
||||
"src.stage_engine",
|
||||
"src.agents.launcher",
|
||||
"src.security_gate",
|
||||
"src.reconciler",
|
||||
])
|
||||
def test_tc15_alert_modules_wire_link_for(module_name):
|
||||
"""The representative alert modules call the shared link_for helper, so their
|
||||
work_item_id alerts render a clickable number (not a bare string). Checked at
|
||||
source level since some sites import link_for function-locally."""
|
||||
import importlib
|
||||
import inspect
|
||||
mod = importlib.import_module(module_name)
|
||||
src = inspect.getsource(mod)
|
||||
assert "link_for(" in src, f"{module_name} must use link_for in its alerts"
|
||||
93
tests/test_orch073_conditionality.py
Normal file
93
tests/test_orch073_conditionality.py
Normal file
@@ -0,0 +1,93 @@
|
||||
"""ORCH-073 — conditionality / backward-compat (INV-5).
|
||||
|
||||
Covers TC-17/18 / AC-6. The whole under-gate and the regression guard are no-ops for
|
||||
non-self repos and when their kill-switches are off, so enduro-trails and a disabled
|
||||
self-host behave exactly as before.
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
os.environ.setdefault("ORCH_GITEA_TOKEN", "test-token")
|
||||
os.environ.setdefault("ORCH_PLANE_API_TOKEN", "test-token")
|
||||
os.environ.setdefault("ORCH_DB_PATH", os.path.join(tempfile.gettempdir(), "test_orch073_cond.db"))
|
||||
|
||||
from unittest.mock import MagicMock # noqa: E402
|
||||
|
||||
from src import merge_gate, stage_engine, image_freshness # noqa: E402
|
||||
from src.stage_engine import AdvanceResult, _handle_merge_verify # noqa: E402
|
||||
|
||||
REPO = "orchestrator"
|
||||
WI = "ORCH-073"
|
||||
BRANCH = "feature/ORCH-073-x"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-17 (AC-6/INV-5): non-self repo / kill-switch off -> under-gate is a no-op.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc17_merge_verify_applies_scope(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate.settings, "merge_verify_enabled", True)
|
||||
monkeypatch.setattr(merge_gate.settings, "merge_verify_repos", "")
|
||||
# Empty CSV -> only the self-hosting repo.
|
||||
assert merge_gate.merge_verify_applies("orchestrator") is True
|
||||
assert merge_gate.merge_verify_applies("enduro-trails") is False
|
||||
# Kill-switch off -> no-op for everyone.
|
||||
monkeypatch.setattr(merge_gate.settings, "merge_verify_enabled", False)
|
||||
assert merge_gate.merge_verify_applies("orchestrator") is False
|
||||
|
||||
|
||||
def test_tc17_under_gate_noop_for_non_self(monkeypatch):
|
||||
# When the under-gate does not apply, _handle_merge_verify advances (False) and
|
||||
# never touches the merge-actor / verifier / guard.
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "merge_verify_applies", lambda r: False)
|
||||
|
||||
def must_not_call(*a, **k):
|
||||
raise AssertionError("under-gate must be a no-op for non-self repos")
|
||||
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "merge_pr", must_not_call)
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "verify_merged_to_main", must_not_call)
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "check_main_regression", must_not_call)
|
||||
|
||||
res = AdvanceResult()
|
||||
assert _handle_merge_verify(1, "enduro-trails", WI, BRANCH, res) is False
|
||||
assert res.alerted is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-18 (INV-5): regression guard respects its kill-switch -> no-op; SHA-in-main
|
||||
# alone still advances the task.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc18_guard_kill_switch_skips_guard(monkeypatch):
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "merge_verify_applies", lambda r: True)
|
||||
monkeypatch.setattr(stage_engine.settings, "regression_guard_enabled", False)
|
||||
monkeypatch.setattr(image_freshness, "validated_revision", lambda r, b: "deadbeef")
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "merge_pr", lambda r, b: (True, "merged PR #1"))
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "verify_merged_to_main", lambda r, b, s: True)
|
||||
monkeypatch.setattr(
|
||||
stage_engine.merge_gate, "check_main_regression",
|
||||
lambda r, b: (_ for _ in ()).throw(AssertionError("guard must not run when disabled")),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
stage_engine.self_deploy, "record_merged_to_main", MagicMock(return_value=True)
|
||||
)
|
||||
for name in ("set_issue_blocked", "plane_add_comment", "send_telegram", "link_for"):
|
||||
monkeypatch.setattr(stage_engine, name, MagicMock())
|
||||
|
||||
res = AdvanceResult()
|
||||
# Guard disabled -> confirmed SHA-in-main advances straight to done (return False).
|
||||
assert _handle_merge_verify(1, REPO, WI, BRANCH, res) is False
|
||||
assert res.alerted is False
|
||||
assert not stage_engine.set_issue_blocked.called
|
||||
|
||||
|
||||
def test_tc18_guard_noop_for_non_self_repo(monkeypatch):
|
||||
# check_main_regression is only invoked inside the confirmed branch which itself
|
||||
# only runs when merge_verify_applies is True (self-hosting / CSV). For a non-self
|
||||
# repo the guard is never reached.
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "merge_verify_applies", lambda r: False)
|
||||
monkeypatch.setattr(
|
||||
stage_engine.merge_gate, "check_main_regression",
|
||||
lambda r, b: (_ for _ in ()).throw(AssertionError("guard must not run for non-self")),
|
||||
)
|
||||
res = AdvanceResult()
|
||||
assert _handle_merge_verify(1, "enduro-trails", WI, BRANCH, res) is False
|
||||
85
tests/test_orch073_gitattributes.py
Normal file
85
tests/test_orch073_gitattributes.py
Normal file
@@ -0,0 +1,85 @@
|
||||
"""ORCH-073 FR-4 — .gitattributes: CHANGELOG.md merge=union.
|
||||
|
||||
Covers TC-11/TC-12 / AC-4. TC-11 asserts the repo-root .gitattributes declares the
|
||||
union driver (git check-attr). TC-12 proves, in a throwaway git repo, that two
|
||||
branches both editing '## [Unreleased]' merge WITHOUT a conflict and BOTH entries
|
||||
survive — exactly what stops auto_rebase_onto_main from rolling a branch back.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def _git(cwd, *args, env=None):
|
||||
return subprocess.run(
|
||||
["git", *args], cwd=str(cwd), capture_output=True, text=True, env=env,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-11 (AC-4): the repo-root .gitattributes declares CHANGELOG.md merge=union.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc11_gitattributes_declares_union():
|
||||
ga = REPO_ROOT / ".gitattributes"
|
||||
assert ga.is_file(), ".gitattributes must exist at the repo root"
|
||||
assert "CHANGELOG.md merge=union" in ga.read_text(encoding="utf-8")
|
||||
|
||||
r = _git(REPO_ROOT, "check-attr", "merge", "CHANGELOG.md")
|
||||
assert r.returncode == 0, r.stderr
|
||||
# Output form: 'CHANGELOG.md: merge: union'
|
||||
assert "merge: union" in r.stdout, r.stdout
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-12 (AC-4): two Unreleased edits merge with no conflict; both kept.
|
||||
# ---------------------------------------------------------------------------
|
||||
def _init_repo(tmp_path):
|
||||
env = {
|
||||
"GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t",
|
||||
"GIT_COMMITTER_NAME": "t", "GIT_COMMITTER_EMAIL": "t@t",
|
||||
"GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_SYSTEM": "/dev/null",
|
||||
"PATH": __import__("os").environ.get("PATH", ""),
|
||||
"HOME": str(tmp_path),
|
||||
}
|
||||
repo = tmp_path / "repo"
|
||||
repo.mkdir()
|
||||
assert _git(repo, "init", "-b", "main", env=env).returncode == 0
|
||||
(repo / ".gitattributes").write_text("CHANGELOG.md merge=union\n", encoding="utf-8")
|
||||
base = (
|
||||
"# Changelog\n\n## [Unreleased]\n\n### Common\n\n## [0.1.0]\n- initial\n"
|
||||
)
|
||||
(repo / "CHANGELOG.md").write_text(base, encoding="utf-8")
|
||||
_git(repo, "add", ".", env=env)
|
||||
assert _git(repo, "commit", "-m", "base", env=env).returncode == 0
|
||||
return repo, env
|
||||
|
||||
|
||||
def test_tc12_union_merge_keeps_both_entries(tmp_path):
|
||||
repo, env = _init_repo(tmp_path)
|
||||
|
||||
# Branch A adds its Unreleased line.
|
||||
_git(repo, "checkout", "-b", "task-a", env=env)
|
||||
txt = (repo / "CHANGELOG.md").read_text(encoding="utf-8")
|
||||
(repo / "CHANGELOG.md").write_text(
|
||||
txt.replace("### Common\n", "### Common\n- ORCH-A: feature A\n"), encoding="utf-8"
|
||||
)
|
||||
_git(repo, "commit", "-am", "task A changelog", env=env)
|
||||
|
||||
# Branch B (from main) adds a DIFFERENT Unreleased line at the same spot.
|
||||
_git(repo, "checkout", "main", env=env)
|
||||
_git(repo, "checkout", "-b", "task-b", env=env)
|
||||
txt = (repo / "CHANGELOG.md").read_text(encoding="utf-8")
|
||||
(repo / "CHANGELOG.md").write_text(
|
||||
txt.replace("### Common\n", "### Common\n- ORCH-B: feature B\n"), encoding="utf-8"
|
||||
)
|
||||
_git(repo, "commit", "-am", "task B changelog", env=env)
|
||||
|
||||
# Merge A into B — union must avoid a conflict and keep BOTH lines.
|
||||
m = _git(repo, "merge", "--no-edit", "task-a", env=env)
|
||||
result = (repo / "CHANGELOG.md").read_text(encoding="utf-8")
|
||||
assert m.returncode == 0, f"union merge must not conflict: {m.stdout}\n{m.stderr}"
|
||||
assert "<<<<<<<" not in result and ">>>>>>>" not in result
|
||||
assert "ORCH-A: feature A" in result
|
||||
assert "ORCH-B: feature B" in result
|
||||
106
tests/test_orch073_merge_pr.py
Normal file
106
tests/test_orch073_merge_pr.py
Normal file
@@ -0,0 +1,106 @@
|
||||
"""ORCH-073 FR-3 — merge_pr merges exactly the feature code-PR (base==main).
|
||||
|
||||
Covers TC-08..10 / AC-7 / INV-2/INV-4. The actor selects the open PR with
|
||||
head==branch AND base==main (never an auto docs-PR / foreign base), merges via the
|
||||
Gitea PR-merge API only (no push/force-push), and is idempotent on an already-merged
|
||||
code-PR. Gitea HTTP is mocked; never-raise -> (False, reason).
|
||||
"""
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from src import merge_gate
|
||||
|
||||
BRANCH = "feature/ORCH-073-x"
|
||||
|
||||
|
||||
class _Resp:
|
||||
def __init__(self, status_code, payload=None, text=""):
|
||||
self.status_code = status_code
|
||||
self._payload = payload if payload is not None else []
|
||||
self.text = text
|
||||
|
||||
def json(self):
|
||||
return self._payload
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _settings(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate.settings, "gitea_url", "http://gitea.test")
|
||||
monkeypatch.setattr(merge_gate.settings, "gitea_owner", "admin")
|
||||
monkeypatch.setattr(merge_gate.settings, "gitea_token", "tok")
|
||||
monkeypatch.setattr(merge_gate.settings, "merge_pr_timeout_s", 5)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-08: open code-PR (head==branch, base==main) -> POST /pulls/{n}/merge.
|
||||
# A concurrently-open docs-PR (head=docs/*) must be skipped.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc08_merges_code_pr_not_docs_pr(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate, "pr_already_merged", lambda r, b: False)
|
||||
post_calls = []
|
||||
|
||||
def fake_get(url, params=None, headers=None, timeout=None):
|
||||
return _Resp(200, [
|
||||
{"head": {"ref": "docs/ORCH-073-log"}, "base": {"ref": "main"}, "number": 4},
|
||||
{"head": {"ref": BRANCH}, "base": {"ref": "main"}, "number": 7},
|
||||
])
|
||||
|
||||
def fake_post(url, json=None, headers=None, timeout=None):
|
||||
post_calls.append((url, json))
|
||||
return _Resp(200)
|
||||
|
||||
monkeypatch.setattr(httpx, "get", fake_get)
|
||||
monkeypatch.setattr(httpx, "post", fake_post)
|
||||
|
||||
ok, msg = merge_gate.merge_pr("orchestrator", BRANCH)
|
||||
assert ok is True and "PR #7" in msg
|
||||
assert len(post_calls) == 1
|
||||
url, body = post_calls[0]
|
||||
assert url.endswith("/repos/admin/orchestrator/pulls/7/merge")
|
||||
assert body == {"Do": "merge"}
|
||||
|
||||
|
||||
def test_tc08_skips_pr_onto_non_main_base(monkeypatch):
|
||||
# Right head but base != main -> not a merge-to-main code-PR -> no open PR.
|
||||
monkeypatch.setattr(merge_gate, "pr_already_merged", lambda r, b: False)
|
||||
monkeypatch.setattr(
|
||||
httpx, "get",
|
||||
lambda *a, **k: _Resp(200, [{"head": {"ref": BRANCH}, "base": {"ref": "develop"}, "number": 9}]),
|
||||
)
|
||||
monkeypatch.setattr(httpx, "post", lambda *a, **k: (_ for _ in ()).throw(
|
||||
AssertionError("must not POST merge for a non-main base PR")))
|
||||
ok, msg = merge_gate.merge_pr("orchestrator", BRANCH)
|
||||
assert ok is False and msg == "no open PR"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-09 (INV-2): no open code-PR -> (False, "no open PR"); never shells out.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc09_no_open_pr_no_shell_out(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate, "pr_already_merged", lambda r, b: False)
|
||||
monkeypatch.setattr(httpx, "get", lambda *a, **k: _Resp(200, []))
|
||||
subprocess_calls = []
|
||||
monkeypatch.setattr(
|
||||
merge_gate.subprocess, "run",
|
||||
lambda cmd, *a, **k: subprocess_calls.append(cmd),
|
||||
)
|
||||
ok, msg = merge_gate.merge_pr("orchestrator", BRANCH)
|
||||
assert ok is False and msg == "no open PR"
|
||||
# No git push/force-push (or any subprocess) for the merge-actor.
|
||||
assert subprocess_calls == []
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-10 (AC-7/INV-4): already-merged code-PR -> no-op, no second POST merge.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc10_idempotent_already_merged(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate, "pr_already_merged", lambda r, b: True)
|
||||
|
||||
def must_not_call(*a, **k):
|
||||
raise AssertionError("no Gitea call when the code-PR is already merged")
|
||||
|
||||
monkeypatch.setattr(httpx, "get", must_not_call)
|
||||
monkeypatch.setattr(httpx, "post", must_not_call)
|
||||
ok, msg = merge_gate.merge_pr("orchestrator", BRANCH)
|
||||
assert ok is True and msg == "already-merged"
|
||||
99
tests/test_orch073_merge_verify.py
Normal file
99
tests/test_orch073_merge_verify.py
Normal file
@@ -0,0 +1,99 @@
|
||||
"""ORCH-073 FR-1 — verify_merged_to_main: SHA-in-main is the SINGLE criterion.
|
||||
|
||||
Covers TC-01..04 / AC-2 / AC-6. The former OR-branch `pr_already_merged` was the
|
||||
phantom-merge root cause and is removed: a merged docs-PR must NOT confirm a merge.
|
||||
git/HTTP are mocked; the verifier honours the never-raise contract (INV-1).
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from src import merge_gate
|
||||
|
||||
|
||||
class _R:
|
||||
"""Minimal completed-subprocess stand-in (returncode only)."""
|
||||
|
||||
def __init__(self, rc):
|
||||
self.returncode = rc
|
||||
self.stdout = ""
|
||||
self.stderr = ""
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _settings(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate.settings, "merge_verify_enabled", True)
|
||||
monkeypatch.setattr(merge_gate.settings, "merge_verify_timeout_s", 5)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-01 (AC-6): sha is an ancestor of origin/main (merge-base rc=0) -> True.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc01_true_when_sha_is_ancestor(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate, "ensure_worktree", lambda r, b: "/wt")
|
||||
calls = []
|
||||
|
||||
def fake_run(cmd, *a, **k):
|
||||
calls.append(cmd)
|
||||
return _R(0) # fetch ok; merge-base --is-ancestor -> 0 (ancestor)
|
||||
|
||||
monkeypatch.setattr(merge_gate.subprocess, "run", fake_run)
|
||||
assert merge_gate.verify_merged_to_main("orchestrator", "feature/ORCH-073-x", "abc123") is True
|
||||
assert any(
|
||||
"merge-base" in c and "--is-ancestor" in c and "origin/main" in c for c in calls
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-02 (AC-2): sha NOT in main AND a merged docs-PR exists -> False.
|
||||
# This is the exact ORCH-067/069 bug: a merged docs-PR must not confirm.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc02_false_when_sha_not_in_main_even_with_merged_docs_pr(monkeypatch):
|
||||
# A merged docs-PR is present (mock returns True), but it must be IGNORED.
|
||||
called = {"pr": False}
|
||||
|
||||
def fake_pr_already_merged(r, b):
|
||||
called["pr"] = True
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(merge_gate, "pr_already_merged", fake_pr_already_merged)
|
||||
monkeypatch.setattr(merge_gate, "ensure_worktree", lambda r, b: "/wt")
|
||||
monkeypatch.setattr(
|
||||
merge_gate.subprocess, "run",
|
||||
lambda cmd, *a, **k: _R(1) if "merge-base" in cmd else _R(0),
|
||||
)
|
||||
assert merge_gate.verify_merged_to_main("orchestrator", "feature/ORCH-073-x", "abc123") is False
|
||||
# The merged-PR signal is no longer consulted by the verifier at all.
|
||||
assert called["pr"] is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-03: empty sha -> inconclusive -> False (fail-closed), no git consulted.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc03_empty_sha_is_false(monkeypatch):
|
||||
def boom(*a, **k):
|
||||
raise AssertionError("git must NOT run for an empty SHA")
|
||||
|
||||
monkeypatch.setattr(merge_gate, "ensure_worktree", boom)
|
||||
monkeypatch.setattr(merge_gate.subprocess, "run", boom)
|
||||
assert merge_gate.verify_merged_to_main("orchestrator", "feature/ORCH-073-x", "") is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-04 (INV-1): a git/OS error -> False, exception never propagated.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc04_never_raises_on_git_error(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate, "ensure_worktree", lambda r, b: "/wt")
|
||||
|
||||
def boom(*a, **k):
|
||||
raise OSError("git exploded")
|
||||
|
||||
monkeypatch.setattr(merge_gate.subprocess, "run", boom)
|
||||
assert merge_gate.verify_merged_to_main("orchestrator", "feature/ORCH-073-x", "abc123") is False
|
||||
|
||||
|
||||
def test_tc04_never_raises_on_worktree_error(monkeypatch):
|
||||
def boom(*a, **k):
|
||||
raise RuntimeError("worktree down")
|
||||
|
||||
monkeypatch.setattr(merge_gate, "ensure_worktree", boom)
|
||||
assert merge_gate.verify_merged_to_main("orchestrator", "feature/ORCH-073-x", "abc123") is False
|
||||
78
tests/test_orch073_pr_classify.py
Normal file
78
tests/test_orch073_pr_classify.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""ORCH-073 FR-2 — pr_already_merged distinguishes code-PR from docs-PR.
|
||||
|
||||
Covers TC-05..07. pr_already_merged is now an idempotency-guard: it counts a PR as
|
||||
"merged" ONLY when it carries the code of THIS feature-branch into main
|
||||
(merged & head.ref==branch & base.ref=="main"), excluding auto docs-PRs. Gitea HTTP
|
||||
is mocked; never-raise -> False (INV-1).
|
||||
"""
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from src import merge_gate
|
||||
|
||||
BRANCH = "feature/ORCH-073-x"
|
||||
|
||||
|
||||
class _Resp:
|
||||
def __init__(self, status_code, payload=None):
|
||||
self.status_code = status_code
|
||||
self._payload = payload if payload is not None else []
|
||||
|
||||
def json(self):
|
||||
return self._payload
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _settings(monkeypatch):
|
||||
monkeypatch.setattr(merge_gate.settings, "gitea_url", "http://gitea.test")
|
||||
monkeypatch.setattr(merge_gate.settings, "gitea_owner", "admin")
|
||||
monkeypatch.setattr(merge_gate.settings, "gitea_token", "tok")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-05: a merged docs-PR (head=docs/*, base=main) is NOT counted as code-merge.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc05_merged_docs_pr_not_counted(monkeypatch):
|
||||
payload = [
|
||||
{"merged": True, "head": {"ref": "docs/ORCH-073-staging-log"}, "base": {"ref": "main"}},
|
||||
{"merged": False, "head": {"ref": BRANCH}, "base": {"ref": "main"}},
|
||||
]
|
||||
monkeypatch.setattr(httpx, "get", lambda *a, **k: _Resp(200, payload))
|
||||
assert merge_gate.pr_already_merged("orchestrator", BRANCH) is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-06: a merged code-PR (head==branch, base==main) IS recognised.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc06_merged_code_pr_recognised(monkeypatch):
|
||||
payload = [
|
||||
{"merged": True, "head": {"ref": BRANCH}, "base": {"ref": "main"}},
|
||||
]
|
||||
monkeypatch.setattr(httpx, "get", lambda *a, **k: _Resp(200, payload))
|
||||
assert merge_gate.pr_already_merged("orchestrator", BRANCH) is True
|
||||
|
||||
|
||||
def test_tc06_merged_code_pr_onto_non_main_base_not_counted(monkeypatch):
|
||||
# Right head but a foreign base (not main) must NOT count.
|
||||
payload = [
|
||||
{"merged": True, "head": {"ref": BRANCH}, "base": {"ref": "develop"}},
|
||||
]
|
||||
monkeypatch.setattr(httpx, "get", lambda *a, **k: _Resp(200, payload))
|
||||
assert merge_gate.pr_already_merged("orchestrator", BRANCH) is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-07: HTTP error / non-200 -> False (never-raise, conservative).
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc07_non_200_is_false(monkeypatch):
|
||||
monkeypatch.setattr(httpx, "get", lambda *a, **k: _Resp(500, []))
|
||||
assert merge_gate.pr_already_merged("orchestrator", BRANCH) is False
|
||||
|
||||
|
||||
def test_tc07_http_exception_is_false(monkeypatch):
|
||||
def boom(*a, **k):
|
||||
raise httpx.ConnectError("gitea unreachable")
|
||||
|
||||
monkeypatch.setattr(httpx, "get", boom)
|
||||
assert merge_gate.pr_already_merged("orchestrator", BRANCH) is False
|
||||
114
tests/test_orch073_regression_guard.py
Normal file
114
tests/test_orch073_regression_guard.py
Normal file
@@ -0,0 +1,114 @@
|
||||
"""ORCH-073 FR-5 — main-integrity regression guard wired into _handle_merge_verify.
|
||||
|
||||
Covers TC-13..16 / AC-3 / AC-5 / AC-6 / INV-1. Calls the under-gate handler directly
|
||||
with mocked merge_gate primitives + side effects (Plane/Telegram). Asserts the
|
||||
return contract: False == advance to `done`, True == HOLD (alert, NOT done).
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
os.environ.setdefault("ORCH_GITEA_TOKEN", "test-token")
|
||||
os.environ.setdefault("ORCH_PLANE_API_TOKEN", "test-token")
|
||||
os.environ.setdefault("ORCH_DB_PATH", os.path.join(tempfile.gettempdir(), "test_orch073_rg.db"))
|
||||
|
||||
from unittest.mock import MagicMock # noqa: E402
|
||||
|
||||
import pytest # noqa: E402
|
||||
|
||||
from src import stage_engine, image_freshness # noqa: E402
|
||||
from src.stage_engine import AdvanceResult, _handle_merge_verify # noqa: E402
|
||||
|
||||
REPO = "orchestrator"
|
||||
WI = "ORCH-073"
|
||||
BRANCH = "feature/ORCH-073-x"
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _wire(monkeypatch):
|
||||
# Under-gate is in scope for the self-hosting repo; guard enabled.
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "merge_verify_applies", lambda r: True)
|
||||
monkeypatch.setattr(stage_engine.settings, "regression_guard_enabled", True)
|
||||
monkeypatch.setattr(image_freshness, "validated_revision", lambda r, b: "deadbeef")
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "merge_pr", lambda r, b: (True, "merged PR #1"))
|
||||
# Silence Plane/Telegram side effects (assert on .called where relevant).
|
||||
for name in ("set_issue_blocked", "plane_add_comment", "send_telegram", "link_for"):
|
||||
monkeypatch.setattr(stage_engine, name, MagicMock())
|
||||
monkeypatch.setattr(
|
||||
stage_engine.self_deploy, "record_merged_to_main", MagicMock(return_value=True)
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-13 (AC-6): SHA in main AND markers intact -> advance (return False), no alert.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc13_confirmed_and_intact_advances(monkeypatch):
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "verify_merged_to_main", lambda r, b, s: True)
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "check_main_regression", lambda r, b: (True, "markers intact (4)"))
|
||||
|
||||
res = AdvanceResult()
|
||||
intervened = _handle_merge_verify(1, REPO, WI, BRANCH, res)
|
||||
|
||||
assert intervened is False # advance to done
|
||||
assert res.alerted is False
|
||||
assert not stage_engine.set_issue_blocked.called
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-14 (AC-3): SHA NOT in main (docs-only merge) -> HOLD + alert + Blocked.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc14_sha_not_in_main_holds(monkeypatch):
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "verify_merged_to_main", lambda r, b, s: False)
|
||||
# Guard must never even run when SHA is not confirmed.
|
||||
monkeypatch.setattr(
|
||||
stage_engine.merge_gate, "check_main_regression",
|
||||
lambda r, b: (_ for _ in ()).throw(AssertionError("guard must not run when not confirmed")),
|
||||
)
|
||||
|
||||
res = AdvanceResult()
|
||||
intervened = _handle_merge_verify(1, REPO, WI, BRANCH, res)
|
||||
|
||||
assert intervened is True # HOLD
|
||||
assert res.advanced is False
|
||||
assert res.note == "merge-not-verified-hold"
|
||||
assert stage_engine.set_issue_blocked.called
|
||||
assert stage_engine.send_telegram.called
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-15 (AC-5): SHA in main BUT a marker missing -> HOLD + 'main regressed' alert.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc15_marker_missing_holds(monkeypatch):
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "verify_merged_to_main", lambda r, b, s: True)
|
||||
monkeypatch.setattr(
|
||||
stage_engine.merge_gate, "check_main_regression",
|
||||
lambda r, b: (False, "main regressed: ORCH-067 code missing (plane_issue_link @ src/notifications.py)"),
|
||||
)
|
||||
|
||||
res = AdvanceResult()
|
||||
intervened = _handle_merge_verify(1, REPO, WI, BRANCH, res)
|
||||
|
||||
assert intervened is True # HOLD, NOT done
|
||||
assert res.advanced is False
|
||||
assert res.note == "main-regressed-hold"
|
||||
assert stage_engine.set_issue_blocked.called
|
||||
assert stage_engine.send_telegram.called
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TC-16 (INV-1): an internal verifier error -> HOLD + alert, no exception escapes.
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_tc16_internal_error_holds_never_raises(monkeypatch):
|
||||
def boom(r, b, s):
|
||||
raise RuntimeError("verifier exploded")
|
||||
|
||||
monkeypatch.setattr(stage_engine.merge_gate, "verify_merged_to_main", boom)
|
||||
|
||||
res = AdvanceResult()
|
||||
# Must NOT raise.
|
||||
intervened = _handle_merge_verify(1, REPO, WI, BRANCH, res)
|
||||
|
||||
assert intervened is True # HOLD
|
||||
assert res.advanced is False
|
||||
assert res.alerted is True
|
||||
assert "merge-verify-error" in (res.note or "")
|
||||
101
tests/test_plane_issue_link.py
Normal file
101
tests/test_plane_issue_link.py
Normal file
@@ -0,0 +1,101 @@
|
||||
"""ORCH-067 — Group D: the shared plane_issue_link helper (AC-12).
|
||||
|
||||
``plane_issue_link(work_item_id, plane_issue_id=None, project_id=None, repo=None)``
|
||||
is the single source of the clickable issue number for cards AND alerts. It
|
||||
returns ``<a href=...>ORCH-NNN</a>`` when a usable Plane browser URL can be built,
|
||||
and ``html.escape(work_item_id)`` otherwise. It must NEVER raise — including on
|
||||
None arguments and a loopback base. No DB and no network are touched by this unit
|
||||
(project_id is passed explicitly here), so these are pure settings-driven cases.
|
||||
|
||||
Test id TC-12 from 04-test-plan.yaml.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
os.environ.setdefault("ORCH_PLANE_API_TOKEN", "test-token")
|
||||
os.environ.setdefault("ORCH_GITEA_TOKEN", "test-token")
|
||||
|
||||
import pytest # noqa: E402
|
||||
|
||||
from src import notifications as N # noqa: E402
|
||||
|
||||
|
||||
def _set(monkeypatch, **kw):
|
||||
s = N._get_settings()
|
||||
for k, v in kw.items():
|
||||
monkeypatch.setattr(s, k, v, raising=False)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-12 / AC-12 — full data -> HTML link wrapping the number
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc12_full_data_returns_anchor(monkeypatch):
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
out = N.plane_issue_link("ORCH-067", plane_issue_id="iss-1",
|
||||
project_id="proj-9")
|
||||
expected = "https://plane.example.org/acme/projects/proj-9/issues/iss-1/"
|
||||
assert out == f'<a href="{expected}">ORCH-067</a>'
|
||||
|
||||
|
||||
def test_tc12_web_url_fallbacks_to_api_url(monkeypatch):
|
||||
# plane_web_url empty -> non-loopback plane_api_url is used as the base.
|
||||
_set(monkeypatch, plane_web_url="",
|
||||
plane_api_url="https://plane-fallback.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
out = N.plane_issue_link("ORCH-067", plane_issue_id="iss-1",
|
||||
project_id="proj-9")
|
||||
assert 'href="https://plane-fallback.example.org/acme/' in out
|
||||
assert ">ORCH-067</a>" in out
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-12 / AC-12 — insufficient data -> escaped number, NEVER an anchor
|
||||
# --------------------------------------------------------------------------- #
|
||||
@pytest.mark.parametrize("settings_kw,call_kw,reason", [
|
||||
({"plane_web_url": "", "plane_api_url": ""},
|
||||
{"plane_issue_id": "iss-1", "project_id": "proj-9"}, "no web base"),
|
||||
({"plane_web_url": "http://localhost:8091", "plane_api_url": ""},
|
||||
{"plane_issue_id": "iss-1", "project_id": "proj-9"}, "loopback base"),
|
||||
({"plane_web_url": "https://plane.example.org", "plane_workspace_slug": ""},
|
||||
{"plane_issue_id": "iss-1", "project_id": "proj-9"}, "no workspace"),
|
||||
({"plane_web_url": "https://plane.example.org", "plane_workspace_slug": "acme"},
|
||||
{"plane_issue_id": None, "project_id": "proj-9"}, "no issue id"),
|
||||
({"plane_web_url": "https://plane.example.org", "plane_workspace_slug": "acme"},
|
||||
{"plane_issue_id": "iss-1", "project_id": ""}, "no project id"),
|
||||
])
|
||||
def test_tc12_insufficient_data_returns_plain_number(monkeypatch, settings_kw,
|
||||
call_kw, reason):
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_api_url="http://localhost:8091", plane_workspace_slug="acme")
|
||||
_set(monkeypatch, **settings_kw)
|
||||
out = N.plane_issue_link("ORCH-067", repo=None, **call_kw)
|
||||
assert out == "ORCH-067", reason
|
||||
assert "<a href=" not in out
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-12 / AC-12 — html-escaping + never raises on hostile / None input
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc12_escapes_work_item_id_in_link(monkeypatch):
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
out = N.plane_issue_link("ORCH&<67>", plane_issue_id="iss-1",
|
||||
project_id="proj-9")
|
||||
assert ">ORCH&<67></a>" in out # label escaped inside the anchor
|
||||
assert "<a href=" in out
|
||||
|
||||
|
||||
def test_tc12_escapes_work_item_id_unlinked(monkeypatch):
|
||||
_set(monkeypatch, plane_web_url="", plane_api_url="")
|
||||
out = N.plane_issue_link("ORCH&<67>", plane_issue_id="iss-1",
|
||||
project_id="proj-9")
|
||||
assert out == "ORCH&<67>" # escaped, no anchor
|
||||
|
||||
|
||||
def test_tc12_none_args_never_raise(monkeypatch):
|
||||
# All-None must not raise and must yield a (possibly empty) string.
|
||||
out = N.plane_issue_link(None)
|
||||
assert isinstance(out, str)
|
||||
# None work_item_id -> empty label, no anchor.
|
||||
assert "<a href=" not in out
|
||||
117
tests/test_qg0_title_limit.py
Normal file
117
tests/test_qg0_title_limit.py
Normal file
@@ -0,0 +1,117 @@
|
||||
"""ORCH-069: unit tests for the configurable QG-0 title-length limit.
|
||||
|
||||
Covers `_qg0_errors` (src/webhooks/plane.py) reading the upper title limit
|
||||
dynamically from `settings.qg0_title_max` (env `ORCH_QG0_TITLE_MAX`, default 200),
|
||||
plus the graceful env-degradation field-validator on `Settings`.
|
||||
|
||||
The tests patch `src.config.settings.qg0_title_max` (the same object imported into
|
||||
`src.webhooks.plane`) and assert boundary behaviour and error texts. For env-driven
|
||||
cases a FRESH `Settings()` instance is created locally, since the module-level
|
||||
singleton is built once on import.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
from src.config import Settings, settings
|
||||
from src.webhooks.plane import _qg0_errors
|
||||
|
||||
VALID_DESCRIPTION = "x" * 30 # >= 20 chars, always passes the description check
|
||||
|
||||
|
||||
def _title_length_error(errors):
|
||||
"""Return the title length-limit error string, or None if absent.
|
||||
|
||||
The short-title error ('нужно >= 5') and the description error are excluded;
|
||||
only the 'too long' title error is matched (it contains 'максимум').
|
||||
"""
|
||||
for e in errors:
|
||||
if "Title" in e and "максимум" in e:
|
||||
return e
|
||||
return None
|
||||
|
||||
|
||||
# --- AC-1: default limit 200, boundary at 201 ------------------------------
|
||||
|
||||
def test_tc01_default_limit_200_boundary_pass(monkeypatch):
|
||||
"""TC-01: title of exactly 200 chars -> no title length error (PASS)."""
|
||||
monkeypatch.setattr(settings, "qg0_title_max", 200)
|
||||
errors = _qg0_errors("x" * 200, VALID_DESCRIPTION)
|
||||
assert _title_length_error(errors) is None
|
||||
|
||||
|
||||
def test_tc02_default_limit_200_boundary_fail(monkeypatch):
|
||||
"""TC-02: title of 201 chars -> length error mentioning '200'."""
|
||||
monkeypatch.setattr(settings, "qg0_title_max", 200)
|
||||
errors = _qg0_errors("x" * 201, VALID_DESCRIPTION)
|
||||
err = _title_length_error(errors)
|
||||
assert err is not None
|
||||
assert "200" in err
|
||||
|
||||
|
||||
# --- AC-2: configurable limit 120, boundary at 121 -------------------------
|
||||
|
||||
def test_tc03_custom_limit_120_boundary_pass(monkeypatch):
|
||||
"""TC-03: with limit 120, a 120-char title passes."""
|
||||
monkeypatch.setattr(settings, "qg0_title_max", 120)
|
||||
errors = _qg0_errors("x" * 120, VALID_DESCRIPTION)
|
||||
assert _title_length_error(errors) is None
|
||||
|
||||
|
||||
def test_tc04_custom_limit_120_boundary_fail(monkeypatch):
|
||||
"""TC-04: with limit 120, a 121-char title fails; text mentions 120 not 80."""
|
||||
monkeypatch.setattr(settings, "qg0_title_max", 120)
|
||||
errors = _qg0_errors("x" * 121, VALID_DESCRIPTION)
|
||||
err = _title_length_error(errors)
|
||||
assert err is not None
|
||||
assert "120" in err
|
||||
assert "80" not in err
|
||||
|
||||
|
||||
# --- AC-3: graceful handling of invalid/empty env --------------------------
|
||||
|
||||
def test_tc05_graceful_non_numeric_env(monkeypatch):
|
||||
"""TC-05: non-numeric env -> Settings() does not raise, limit == 200."""
|
||||
monkeypatch.setenv("ORCH_QG0_TITLE_MAX", "abc")
|
||||
s = Settings()
|
||||
assert s.qg0_title_max == 200
|
||||
|
||||
|
||||
def test_tc06_graceful_empty_env(monkeypatch):
|
||||
"""TC-06: empty-string env -> default 200, no exception."""
|
||||
monkeypatch.setenv("ORCH_QG0_TITLE_MAX", "")
|
||||
s = Settings()
|
||||
assert s.qg0_title_max == 200
|
||||
|
||||
|
||||
def test_tc07_valid_numeric_env(monkeypatch):
|
||||
"""TC-07: valid numeric env -> the given value is applied (positive path)."""
|
||||
monkeypatch.setenv("ORCH_QG0_TITLE_MAX", "150")
|
||||
s = Settings()
|
||||
assert s.qg0_title_max == 150
|
||||
|
||||
|
||||
# --- AC-4: lower limits unchanged ------------------------------------------
|
||||
|
||||
def test_tc08_short_title_still_errors(monkeypatch):
|
||||
"""TC-08: title < 5 chars still raises the short-title error."""
|
||||
monkeypatch.setattr(settings, "qg0_title_max", 200)
|
||||
errors = _qg0_errors("abc", VALID_DESCRIPTION)
|
||||
assert any("Title" in e and "нужно >= 5" in e for e in errors)
|
||||
|
||||
|
||||
def test_tc09_short_description_still_errors(monkeypatch):
|
||||
"""TC-09: description < 20 chars still raises the short-description error."""
|
||||
monkeypatch.setattr(settings, "qg0_title_max", 200)
|
||||
errors = _qg0_errors("Valid title", "short")
|
||||
assert any("Description" in e for e in errors)
|
||||
|
||||
|
||||
# --- AC-7: backward compatibility ------------------------------------------
|
||||
|
||||
def test_tc10_backward_compat_titles_81_to_200(monkeypatch):
|
||||
"""TC-10: a title previously rejected by the 80-char cap now passes at 200."""
|
||||
monkeypatch.setattr(settings, "qg0_title_max", 200)
|
||||
errors = _qg0_errors("x" * 100, VALID_DESCRIPTION)
|
||||
assert _title_length_error(errors) is None
|
||||
@@ -241,6 +241,9 @@ def test_first_call_sends_message_and_stores_id(monkeypatch):
|
||||
|
||||
|
||||
def test_second_call_edits_existing_message(monkeypatch):
|
||||
# ORCH-067: the default flipped to bump; this case asserts the edit-mode
|
||||
# contract, so pin edit mode explicitly.
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_mode", "edit", raising=False)
|
||||
tid = _mk_task(stage="development")
|
||||
_mk_run(tid, "analyst", "2026-06-04 09:00:00", "2026-06-04 09:10:00",
|
||||
in_tok=10, out_tok=5, cost=0.1)
|
||||
@@ -602,9 +605,15 @@ def test_render_stage_labels_are_russian():
|
||||
for ru in ("Анализ", "Архитектура", "Разработка", "Код ревью",
|
||||
"Тестирование", "Внедрение"):
|
||||
assert ru in text, f"missing russian label {ru!r}"
|
||||
# ORCH-067: the new '📍 <Plane-status>' line intentionally carries the ENGLISH
|
||||
# ORCH-066 Plane status name (e.g. 'Awaiting Deploy'); the russian-only rule
|
||||
# (BR-11) applies to the STAGE label lines, so exclude the status line here.
|
||||
stage_lines = "\n".join(
|
||||
ln for ln in text.splitlines() if not ln.startswith("\U0001f4cd")
|
||||
)
|
||||
for en in ("Analysis", "Architecture", "Development", "Review",
|
||||
"Testing", "Deploy"):
|
||||
assert en not in text, f"english label leaked: {en!r}"
|
||||
assert en not in stage_lines, f"english label leaked: {en!r}"
|
||||
|
||||
|
||||
def test_render_done_says_vnedreno_not_deployed():
|
||||
|
||||
159
tests/test_tracker_bump_default.py
Normal file
159
tests/test_tracker_bump_default.py
Normal file
@@ -0,0 +1,159 @@
|
||||
"""ORCH-067 — Group A: bump is the DEFAULT tracker mode (AC-1..AC-4, AC-15).
|
||||
|
||||
The default flipped edit -> bump: out of the box the live card is re-created at
|
||||
the BOTTOM of the chat (delete old + send new silent + repoint id), one card per
|
||||
task. edit stays available via ORCH_TRACKER_MODE=edit. Network is isolated: the
|
||||
low-level send/edit/delete helpers are patched per case; the DB is a temp SQLite.
|
||||
|
||||
Test ids TC-01..TC-04 + TC-17 from 04-test-plan.yaml.
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
os.environ.setdefault("ORCH_PLANE_API_TOKEN", "test-token")
|
||||
os.environ.setdefault("ORCH_GITEA_TOKEN", "test-token")
|
||||
|
||||
_test_db = os.path.join(tempfile.gettempdir(), "test_orchestrator_bump_default.db")
|
||||
os.environ["ORCH_DB_PATH"] = _test_db
|
||||
|
||||
import pytest # noqa: E402
|
||||
|
||||
import src.db as db_module # noqa: E402
|
||||
from src.config import Settings # noqa: E402
|
||||
from src.db import ( # noqa: E402
|
||||
init_db, get_db, get_tracker_message_id, set_tracker_message_id,
|
||||
)
|
||||
from src import notifications as N # noqa: E402
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_db(monkeypatch):
|
||||
monkeypatch.setattr(db_module.settings, "db_path", _test_db, raising=False)
|
||||
if os.path.exists(_test_db):
|
||||
os.unlink(_test_db)
|
||||
init_db()
|
||||
yield
|
||||
if os.path.exists(_test_db):
|
||||
os.unlink(_test_db)
|
||||
|
||||
|
||||
def _mk_task(stage="development", wid="ORCH-067"):
|
||||
conn = get_db()
|
||||
cur = conn.execute(
|
||||
"INSERT INTO tasks (plane_id, work_item_id, repo, branch, stage, title) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?)",
|
||||
("p1", wid, "orchestrator", "feature/ORCH-067-x", stage, "bump default"),
|
||||
)
|
||||
tid = cur.lastrowid
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return tid
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-01 / AC-1 — default tracker_mode == "bump"
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc01_default_tracker_mode_is_bump(monkeypatch):
|
||||
monkeypatch.delenv("ORCH_TRACKER_MODE", raising=False)
|
||||
assert Settings().tracker_mode == "bump"
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-02 / AC-2, AC-15 — repeat update: delete(old) -> send(silent) -> repoint
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc02_repeat_delete_send_silent_repoint(monkeypatch):
|
||||
# No env -> resolves to the new bump default (no explicit mode pin).
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_mode", "bump", raising=False)
|
||||
tid = _mk_task()
|
||||
set_tracker_message_id(tid, 100)
|
||||
|
||||
order = []
|
||||
monkeypatch.setattr(N, "delete_telegram",
|
||||
lambda mid: order.append(("delete", mid)) or True)
|
||||
monkeypatch.setattr(N, "send_telegram",
|
||||
lambda text, disable_notification=False:
|
||||
order.append(("send", disable_notification)) or 200)
|
||||
|
||||
N.update_task_tracker(tid)
|
||||
|
||||
# delete(old) strictly before send; the new card is SILENT (disable=True).
|
||||
assert order == [("delete", 100), ("send", True)]
|
||||
assert get_tracker_message_id(tid) == 200 # one card -> repointed
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-03 / AC-3 — transient send None must NOT wipe the pointer / duplicate
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc03_send_none_keeps_pointer_no_dupe(monkeypatch):
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_mode", "bump", raising=False)
|
||||
tid = _mk_task()
|
||||
set_tracker_message_id(tid, 100)
|
||||
|
||||
sends = []
|
||||
monkeypatch.setattr(N, "delete_telegram", lambda mid: True)
|
||||
monkeypatch.setattr(N, "send_telegram",
|
||||
lambda text, disable_notification=False:
|
||||
sends.append(1) or None)
|
||||
|
||||
N.update_task_tracker(tid) # must not raise
|
||||
|
||||
assert len(sends) == 1 # exactly one (failed) attempt, no retry
|
||||
assert get_tracker_message_id(tid) == 100 # pointer preserved, not None
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-04 / AC-4 — edit mode still reachable via env -> editMessageText path
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc04_edit_mode_still_available(monkeypatch):
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_mode", "edit", raising=False)
|
||||
tid = _mk_task()
|
||||
set_tracker_message_id(tid, 777)
|
||||
|
||||
edited = {}
|
||||
monkeypatch.setattr(N, "edit_telegram",
|
||||
lambda mid, text: edited.update(mid=mid) or N.EDIT_OK)
|
||||
monkeypatch.setattr(
|
||||
N, "send_telegram",
|
||||
lambda *a, **k: (_ for _ in ()).throw(
|
||||
AssertionError("edit mode must not send when edit succeeds")),
|
||||
)
|
||||
|
||||
N.update_task_tracker(tid)
|
||||
assert edited["mid"] == 777 # edited in place, no new card
|
||||
|
||||
|
||||
def test_tc04b_edit_mode_resolution_case_insensitive(monkeypatch):
|
||||
"""Anything other than 'bump' resolves to edit (e.g. 'EDIT')."""
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_mode", "EDIT", raising=False)
|
||||
tid = _mk_task()
|
||||
set_tracker_message_id(tid, 5)
|
||||
edited = {}
|
||||
monkeypatch.setattr(N, "edit_telegram",
|
||||
lambda mid, text: edited.update(mid=mid) or N.EDIT_OK)
|
||||
monkeypatch.setattr(N, "send_telegram",
|
||||
lambda *a, **k: (_ for _ in ()).throw(
|
||||
AssertionError("should edit, not send")))
|
||||
N.update_task_tracker(tid)
|
||||
assert edited["mid"] == 5
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-17 / AC-15 — first bump call: NO delete, silent send, id stored
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc17_first_call_silent_no_delete(monkeypatch):
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_mode", "bump", raising=False)
|
||||
tid = _mk_task(stage="analysis")
|
||||
|
||||
sends = []
|
||||
monkeypatch.setattr(N, "send_telegram",
|
||||
lambda text, disable_notification=False:
|
||||
sends.append(disable_notification) or 555)
|
||||
monkeypatch.setattr(N, "delete_telegram",
|
||||
lambda mid: (_ for _ in ()).throw(
|
||||
AssertionError("delete must not run on first call")))
|
||||
|
||||
N.update_task_tracker(tid)
|
||||
|
||||
assert sends == [True] # exactly one SILENT send
|
||||
assert get_tracker_message_id(tid) == 555 # id stored
|
||||
158
tests/test_tracker_issue_link.py
Normal file
158
tests/test_tracker_issue_link.py
Normal file
@@ -0,0 +1,158 @@
|
||||
"""ORCH-067 — Group C: clickable issue number in the live card (AC-10/AC-11/AC-14).
|
||||
|
||||
The issue number in the card header is now a Plane hyperlink
|
||||
(``<a href=".../issues/<id>/">ORCH-NNN</a>``) when a usable browser URL can be
|
||||
built, and degrades fail-safe to the html-escaped raw number when any piece is
|
||||
missing (web base / non-loopback / workspace / project_id / plane_issue_id). The
|
||||
card must NEVER break under parse_mode=HTML: a title with '<'/'&'/'>' stays
|
||||
escaped while the <a> markup stays valid. Network is isolated (no HTTP from the
|
||||
render path here); the DB is a temp SQLite.
|
||||
|
||||
Test ids TC-10, TC-11, TC-16 from 04-test-plan.yaml.
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
os.environ.setdefault("ORCH_PLANE_API_TOKEN", "test-token")
|
||||
os.environ.setdefault("ORCH_GITEA_TOKEN", "test-token")
|
||||
|
||||
_test_db = os.path.join(tempfile.gettempdir(), "test_orchestrator_card_link.db")
|
||||
os.environ["ORCH_DB_PATH"] = _test_db
|
||||
|
||||
from types import SimpleNamespace # noqa: E402
|
||||
|
||||
import pytest # noqa: E402
|
||||
|
||||
import src.db as db_module # noqa: E402
|
||||
import src.projects as projects_mod # noqa: E402
|
||||
from src.db import init_db, get_db # noqa: E402
|
||||
from src import notifications as N # noqa: E402
|
||||
|
||||
# orchestrator repo -> default project registry uuid (src/projects.py).
|
||||
_ORCH_PROJECT_ID = "8da6aa25-a60e-44d6-a1e2-d8ae59aa7d6a"
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_db(monkeypatch):
|
||||
monkeypatch.setattr(db_module.settings, "db_path", _test_db, raising=False)
|
||||
if os.path.exists(_test_db):
|
||||
os.unlink(_test_db)
|
||||
init_db()
|
||||
# Keep the render path fully offline (no live overlay HTTP).
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_live_status", False,
|
||||
raising=False)
|
||||
# Pin the repo->project resolution so cross-file tests that reload the
|
||||
# ORCH_PROJECTS_JSON registry can't strip 'orchestrator' out from under us.
|
||||
monkeypatch.setattr(
|
||||
projects_mod, "get_project_by_repo",
|
||||
lambda repo: (SimpleNamespace(plane_project_id=_ORCH_PROJECT_ID)
|
||||
if repo == "orchestrator" else None),
|
||||
)
|
||||
yield
|
||||
if os.path.exists(_test_db):
|
||||
os.unlink(_test_db)
|
||||
|
||||
|
||||
def _set(monkeypatch, **kw):
|
||||
s = N._get_settings()
|
||||
for k, v in kw.items():
|
||||
monkeypatch.setattr(s, k, v, raising=False)
|
||||
|
||||
|
||||
def _mk_task(wid="ORCH-067", repo="orchestrator", title="card link",
|
||||
plane_issue_id="issue-uuid-1", stage="development"):
|
||||
conn = get_db()
|
||||
cur = conn.execute(
|
||||
"INSERT INTO tasks (plane_id, work_item_id, repo, branch, stage, title, "
|
||||
"plane_issue_id) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
("p1", wid, repo, "feature/ORCH-067-x", stage, title, plane_issue_id),
|
||||
)
|
||||
tid = cur.lastrowid
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return tid
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-10 / AC-10 — full data -> clickable <a> wrapping the issue number
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc10_card_number_is_clickable(monkeypatch):
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_api_url="http://localhost:8091", plane_workspace_slug="acme")
|
||||
tid = _mk_task(plane_issue_id="abcd-issue-uuid")
|
||||
|
||||
text = N.render_task_tracker(tid)
|
||||
expected_url = (
|
||||
f"https://plane.example.org/acme/projects/{_ORCH_PROJECT_ID}"
|
||||
f"/issues/abcd-issue-uuid/"
|
||||
)
|
||||
assert f'<a href="{expected_url}">ORCH-067</a>' in text
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-11 / AC-11 — fail-safe: any missing piece -> escaped number, no <a>, no crash
|
||||
# --------------------------------------------------------------------------- #
|
||||
@pytest.mark.parametrize("override,reason", [
|
||||
({"plane_web_url": "", "plane_api_url": ""}, "no web base"),
|
||||
({"plane_web_url": "http://localhost:8091", "plane_api_url": ""}, "loopback base"),
|
||||
({"plane_workspace_slug": ""}, "no workspace"),
|
||||
])
|
||||
def test_tc11_card_number_degrades_settings(monkeypatch, override, reason):
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_api_url="http://localhost:8091", plane_workspace_slug="acme")
|
||||
_set(monkeypatch, **override)
|
||||
tid = _mk_task(plane_issue_id="abcd-issue-uuid")
|
||||
|
||||
text = N.render_task_tracker(tid)
|
||||
assert "ORCH-067" in text # raw number still shown
|
||||
assert "<a href=" not in text, reason # but NOT a link
|
||||
assert "localhost" not in text # never leak a loopback URL
|
||||
|
||||
|
||||
def test_tc11_card_number_degrades_no_issue_id(monkeypatch):
|
||||
# Missing plane_issue_id -> the number is shown unlinked, render survives.
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
tid = _mk_task(plane_issue_id=None)
|
||||
text = N.render_task_tracker(tid)
|
||||
assert "ORCH-067" in text
|
||||
assert "<a href=" not in text
|
||||
|
||||
|
||||
def test_tc11_card_number_degrades_unknown_repo(monkeypatch):
|
||||
# repo not in the registry -> no project_id -> number unlinked, no crash.
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
tid = _mk_task(repo="not-a-real-repo", plane_issue_id="abcd-issue-uuid")
|
||||
text = N.render_task_tracker(tid)
|
||||
assert "ORCH-067" in text
|
||||
assert "<a href=" not in text
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-16 / AC-14 — HTML escaping: title with '<b>'/'&'/'>' stays safe + valid <a>
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc16_title_escaped_link_valid(monkeypatch):
|
||||
_set(monkeypatch, plane_web_url="https://plane.example.org",
|
||||
plane_workspace_slug="acme")
|
||||
tid = _mk_task(title="<b>drop & </b> table >", plane_issue_id="iss-1")
|
||||
|
||||
text = N.render_task_tracker(tid)
|
||||
# Raw title markup is escaped -> cannot break parse_mode=HTML.
|
||||
assert "<b>" not in text
|
||||
assert "<b>" in text
|
||||
assert "&" in text
|
||||
# The card's own anchor markup stays well-formed (balanced tags).
|
||||
assert text.count("<a href=") == text.count("</a>")
|
||||
assert text.count("<a href=") >= 1 # the clickable number is present
|
||||
|
||||
|
||||
def test_tc16_ampersand_in_work_item_id_escaped(monkeypatch):
|
||||
# A '&' in the work_item_id is escaped in the (unlinked) fail-safe path too.
|
||||
_set(monkeypatch, plane_web_url="", plane_api_url="",
|
||||
plane_workspace_slug="acme")
|
||||
tid = _mk_task(wid="ORCH&67", plane_issue_id="iss-1")
|
||||
text = N.render_task_tracker(tid)
|
||||
assert "ORCH&67" in text
|
||||
assert "<a href=" not in text # no link (no web base)
|
||||
216
tests/test_tracker_status_line.py
Normal file
216
tests/test_tracker_status_line.py
Normal file
@@ -0,0 +1,216 @@
|
||||
"""ORCH-067 — Group B: the Plane-status line on the live card (AC-5..AC-9).
|
||||
|
||||
The card now carries an explicit '📍 <Plane status>' line under the header that
|
||||
follows the ORCH-066 status model. The OFFLINE core (stage->status + In Review
|
||||
from the brd-clock + Awaiting Deploy) is pure/deterministic and never touches the
|
||||
network; a best-effort LIVE overlay draws the branch statuses that are
|
||||
indistinguishable offline (Needs Input / Blocked / …). Everything degrades to the
|
||||
stage default and NEVER raises (AC-9). Network is isolated: the live-state read
|
||||
(`_live_state_uuid_cached`) and `get_project_states` are patched per case; the DB
|
||||
is a temp SQLite.
|
||||
|
||||
Test ids TC-05..TC-09 from 04-test-plan.yaml.
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
os.environ.setdefault("ORCH_PLANE_API_TOKEN", "test-token")
|
||||
os.environ.setdefault("ORCH_GITEA_TOKEN", "test-token")
|
||||
|
||||
_test_db = os.path.join(tempfile.gettempdir(), "test_orchestrator_status_line.db")
|
||||
os.environ["ORCH_DB_PATH"] = _test_db
|
||||
|
||||
from types import SimpleNamespace # noqa: E402
|
||||
|
||||
import pytest # noqa: E402
|
||||
|
||||
import src.db as db_module # noqa: E402
|
||||
import src.projects as projects_mod # noqa: E402
|
||||
from src.db import init_db, get_db # noqa: E402
|
||||
from src import notifications as N # noqa: E402
|
||||
import src.plane_sync as plane_sync # noqa: E402
|
||||
|
||||
_ORCH_PROJECT_ID = "8da6aa25-a60e-44d6-a1e2-d8ae59aa7d6a"
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_db(monkeypatch):
|
||||
monkeypatch.setattr(db_module.settings, "db_path", _test_db, raising=False)
|
||||
if os.path.exists(_test_db):
|
||||
os.unlink(_test_db)
|
||||
init_db()
|
||||
# Live overlay OFF by default for the offline-core tests; cases that need it
|
||||
# turn it back on explicitly. Keep the per-issue cache clean between cases.
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_live_status", False, raising=False)
|
||||
N._LIVE_STATE_CACHE.clear()
|
||||
# Pin repo->project resolution (cross-file ORCH_PROJECTS_JSON reloads must not
|
||||
# strip 'orchestrator' and disable the live overlay under us).
|
||||
monkeypatch.setattr(
|
||||
projects_mod, "get_project_by_repo",
|
||||
lambda repo: (SimpleNamespace(plane_project_id=_ORCH_PROJECT_ID)
|
||||
if repo == "orchestrator" else None),
|
||||
)
|
||||
yield
|
||||
if os.path.exists(_test_db):
|
||||
os.unlink(_test_db)
|
||||
|
||||
|
||||
def _mk_task(stage="development", wid="ORCH-067", repo="orchestrator",
|
||||
plane_issue_id="issue-uuid-1", brd_started=None, brd_ended=None,
|
||||
title="status line"):
|
||||
conn = get_db()
|
||||
cur = conn.execute(
|
||||
"INSERT INTO tasks (plane_id, work_item_id, repo, branch, stage, title, "
|
||||
"plane_issue_id, brd_review_started_at, brd_review_ended_at) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
("p1", wid, repo, "feature/ORCH-067-x", stage, title, plane_issue_id,
|
||||
brd_started, brd_ended),
|
||||
)
|
||||
tid = cur.lastrowid
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return tid
|
||||
|
||||
|
||||
def _status_line(text):
|
||||
"""Extract the single '📍 ...' status line from rendered card text."""
|
||||
for ln in text.splitlines():
|
||||
if ln.startswith("\U0001f4cd"):
|
||||
return ln
|
||||
return None
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-05 / AC-5 — render carries an explicit Plane-status line
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc05_render_has_status_line():
|
||||
tid = _mk_task(stage="development")
|
||||
text = N.render_task_tracker(tid)
|
||||
line = _status_line(text)
|
||||
assert line is not None # '📍 ...' present
|
||||
assert line == "\U0001f4cd Development" # stage -> Plane status
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-06 / AC-6 — stage -> Plane status mapping (ТЗ §2.2), parametrized
|
||||
# --------------------------------------------------------------------------- #
|
||||
@pytest.mark.parametrize("stage,expected", [
|
||||
("created", "To Analyse"),
|
||||
("analysis", "Analysis"),
|
||||
("architecture", "Architecture"),
|
||||
("development", "Development"),
|
||||
("review", "Code-Review"),
|
||||
("testing", "Testing"),
|
||||
("deploy", "⏸️ Awaiting Deploy — ожидание Confirm Deploy"),
|
||||
("done", "Done"),
|
||||
])
|
||||
def test_tc06_stage_to_plane_status(stage, expected):
|
||||
# plane_status_label is pure/offline -> assert directly off a row-like dict.
|
||||
assert N.plane_status_label({"stage": stage}) == expected
|
||||
|
||||
|
||||
def test_tc06_unknown_stage_degrades_to_default():
|
||||
# Anything unknown -> the safe stage default (To Analyse), never an error.
|
||||
assert N.plane_status_label({"stage": "weird-stage"}) == "To Analyse"
|
||||
assert N.plane_status_label({}) == "To Analyse"
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-07 / AC-7 — In Review from the brd-clock, OFFLINE (no network)
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc07_in_review_from_brd_clock(monkeypatch):
|
||||
# analysis + brd started + not ended -> '⏸️ In Review' (waiting BRD approve).
|
||||
# Guard: any network read would fail this test -> prove it stays offline.
|
||||
def _boom(*a, **k):
|
||||
raise AssertionError("In Review must be resolved OFFLINE (no network)")
|
||||
monkeypatch.setattr(N, "_live_state_uuid_cached", _boom)
|
||||
|
||||
tid = _mk_task(stage="analysis", brd_started="2026-06-08 10:00:00",
|
||||
brd_ended=None)
|
||||
text = N.render_task_tracker(tid)
|
||||
|
||||
assert _status_line(text) == "\U0001f4cd " + N._IN_REVIEW_LABEL
|
||||
# The human-gate 'Подтверждение BRD' line with ⏸️/⏳ is still rendered.
|
||||
assert N._BRD_LABEL in text
|
||||
assert "⏳" in text # ⏳ still-waiting marker
|
||||
|
||||
|
||||
def test_tc07b_in_review_clears_once_brd_ended():
|
||||
# Once the BRD review ended, analysis is back to the plain 'Analysis' status.
|
||||
tid = _mk_task(stage="analysis", brd_started="2026-06-08 10:00:00",
|
||||
brd_ended="2026-06-08 10:30:00")
|
||||
assert _status_line(N.render_task_tracker(tid)) == "\U0001f4cd Analysis"
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-08 / AC-8 — Awaiting Deploy (offline) + Needs Input (live overlay)
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc08_awaiting_deploy_offline():
|
||||
# stage=deploy -> '⏸️ Awaiting Deploy' purely offline (no overlay needed).
|
||||
tid = _mk_task(stage="deploy")
|
||||
line = _status_line(N.render_task_tracker(tid))
|
||||
assert line == "\U0001f4cd ⏸️ Awaiting Deploy — ожидание Confirm Deploy"
|
||||
|
||||
|
||||
def test_tc08_needs_input_via_live_overlay(monkeypatch):
|
||||
# Needs Input is NOT derivable offline -> drawn by the best-effort overlay
|
||||
# reading the LIVE Plane status. Patch the live read + the state map.
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_live_status", True,
|
||||
raising=False)
|
||||
monkeypatch.setattr(N, "_live_state_uuid_cached",
|
||||
lambda issue_id, project_id: "uuid-needs-input")
|
||||
monkeypatch.setattr(
|
||||
plane_sync, "get_project_states",
|
||||
lambda project_id: {"needs_input": "uuid-needs-input"},
|
||||
)
|
||||
# repo='orchestrator' resolves to a real registry project_id -> overlay runs.
|
||||
tid = _mk_task(stage="development", repo="orchestrator")
|
||||
line = _status_line(N.render_task_tracker(tid))
|
||||
assert line == "\U0001f4cd ❓ Needs Input — нужны уточнения"
|
||||
|
||||
|
||||
def test_tc08b_overlay_no_match_keeps_offline_base(monkeypatch):
|
||||
# Live status maps to no branch key -> the offline stage base is kept.
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_live_status", True,
|
||||
raising=False)
|
||||
monkeypatch.setattr(N, "_live_state_uuid_cached",
|
||||
lambda issue_id, project_id: "uuid-in-progress")
|
||||
monkeypatch.setattr(
|
||||
plane_sync, "get_project_states",
|
||||
lambda project_id: {"in_progress": "uuid-in-progress",
|
||||
"needs_input": "uuid-needs-input"},
|
||||
)
|
||||
tid = _mk_task(stage="development", repo="orchestrator")
|
||||
assert _status_line(N.render_task_tracker(tid)) == "\U0001f4cd Development"
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# TC-09 / AC-9, AC-16 — render never raises on broken/unreachable status data
|
||||
# --------------------------------------------------------------------------- #
|
||||
def test_tc09_render_survives_overlay_exception(monkeypatch):
|
||||
# The live overlay blowing up must NOT escape render -> degrade to stage base.
|
||||
monkeypatch.setattr(N._get_settings(), "tracker_live_status", True,
|
||||
raising=False)
|
||||
|
||||
def _boom(*a, **k):
|
||||
raise RuntimeError("plane down")
|
||||
monkeypatch.setattr(N, "_live_state_uuid_cached", _boom)
|
||||
|
||||
tid = _mk_task(stage="development", repo="orchestrator")
|
||||
text = N.render_task_tracker(tid) # must not raise
|
||||
assert _status_line(text) == "\U0001f4cd Development"
|
||||
|
||||
|
||||
def test_tc09b_card_status_label_never_raises(monkeypatch):
|
||||
# _card_status_label swallows everything -> a usable default, never an error.
|
||||
def _boom(*a, **k):
|
||||
raise RuntimeError("boom")
|
||||
monkeypatch.setattr(N, "plane_status_label", _boom)
|
||||
assert N._card_status_label({"stage": "development"}) == "To Analyse"
|
||||
|
||||
|
||||
def test_tc09c_plane_status_label_never_raises():
|
||||
# Garbage row (None / object without keys) -> safe default, no exception.
|
||||
assert N.plane_status_label(None) == "To Analyse"
|
||||
assert N.plane_status_label(object()) == "To Analyse"
|
||||
Reference in New Issue
Block a user