Compare commits
1 Commits
fix/isolat
...
ci/add-git
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6d6b53f39 |
@@ -38,36 +38,3 @@ def _no_telegram(monkeypatch):
|
||||
monkeypatch.setattr("src.agents.launcher.send_telegram", _noop, raising=False)
|
||||
monkeypatch.setattr("src.queue_worker.send_telegram", _noop, raising=False)
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_webhook_secrets(monkeypatch):
|
||||
"""Isolate settings singleton between test files (CI cross-file isolation).
|
||||
|
||||
settings is a process-wide Pydantic singleton read once at import. Different
|
||||
test modules set env variables differently at import-time, so those values leak
|
||||
across files when pytest collects them together (as CI does).
|
||||
|
||||
1. webhook secrets: reset to "" so HMAC is disabled by default. Tests that
|
||||
intentionally test the 401 path (test_webhook_dedup.py:268,278) re-apply
|
||||
their own monkeypatch AFTER this autouse fixture runs, which overrides the
|
||||
reset for the duration of that one test only.
|
||||
|
||||
2. db_path: reset to the value from ORCH_DB_PATH env var (last written by the
|
||||
last imported test module). Without this, test_webhook_dedup.py (imported
|
||||
first, alphabetically) seeds settings.db_path = dedup.db, while
|
||||
test_webhooks.py's setup_db fixture tries to remove test_orchestrator.db,
|
||||
leaving the DB dirty across tests that share a branch name and causing
|
||||
get_task_by_repo_branch() to return a stale row with the wrong stage.
|
||||
Per-test monkeypatches in test_webhook_dedup.setup_db override this reset.
|
||||
"""
|
||||
import os
|
||||
from src.webhooks import gitea as gitea_mod
|
||||
from src.webhooks import plane as plane_mod
|
||||
from src import db as db_mod
|
||||
monkeypatch.setattr(gitea_mod.settings, "gitea_webhook_secret", "", raising=False)
|
||||
monkeypatch.setattr(plane_mod.settings, "plane_webhook_secret", "", raising=False)
|
||||
db_path_env = os.environ.get("ORCH_DB_PATH", "")
|
||||
if db_path_env:
|
||||
monkeypatch.setattr(db_mod.settings, "db_path", db_path_env, raising=False)
|
||||
yield
|
||||
|
||||
@@ -54,19 +54,13 @@ def test_status_endpoint():
|
||||
assert "active_tasks" in resp.json()
|
||||
|
||||
|
||||
@patch("src.plane_sync.add_comment")
|
||||
@patch("src.plane_sync.fetch_issue_sequence_id", return_value=None)
|
||||
@patch("src.plane_sync.fetch_issue_fields", return_value=("Test task", "This is a detailed test description for the task"))
|
||||
@patch("src.webhooks.plane._create_gitea_branch", new_callable=AsyncMock)
|
||||
@patch("src.webhooks.plane._create_initial_docs", new_callable=AsyncMock)
|
||||
def test_plane_webhook_creates_task(mock_docs, mock_branch, mock_fetch_fields, mock_fetch_seq, mock_add_comment):
|
||||
"""work_item.created (via In Progress status) → task in DB with stage=analysis."""
|
||||
def test_plane_webhook_creates_task(mock_docs, mock_branch):
|
||||
"""work_item.created → task in DB with stage=analysis."""
|
||||
resp = client.post("/webhook/plane", json={
|
||||
"event": "issue", "action": "updated",
|
||||
"data": {
|
||||
"id": "test-123", "name": "Test task", "project": "proj-1",
|
||||
"state": {"id": "b873d9eb-993c-48cd-97ac-99a9b1623967", "name": "In Progress", "group": "started"},
|
||||
}
|
||||
"event": "work_item.created",
|
||||
"data": {"id": "test-123", "name": "Test task", "project": "proj-1"}
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["status"] == "accepted"
|
||||
@@ -81,37 +75,17 @@ def test_plane_webhook_creates_task(mock_docs, mock_branch, mock_fetch_fields, m
|
||||
assert "feature/" in task["branch"]
|
||||
|
||||
|
||||
@patch("src.plane_sync.add_comment")
|
||||
@patch("src.plane_sync.fetch_issue_sequence_id", return_value=None)
|
||||
@patch("src.plane_sync.fetch_issue_fields",
|
||||
side_effect=[
|
||||
("First task", "This is a detailed description for the first task item"),
|
||||
("Second task", "This is a detailed description for the second task item"),
|
||||
])
|
||||
@patch("src.webhooks.plane._create_gitea_branch", new_callable=AsyncMock)
|
||||
@patch("src.webhooks.plane._create_initial_docs", new_callable=AsyncMock)
|
||||
def test_plane_webhook_generates_sequential_ids(
|
||||
mock_docs, mock_branch, mock_fetch_fields, mock_fetch_seq, mock_add_comment
|
||||
):
|
||||
"""Multiple In Progress transitions get sequential IDs (ET-001, ET-002)."""
|
||||
in_progress_state = {
|
||||
"id": "b873d9eb-993c-48cd-97ac-99a9b1623967",
|
||||
"name": "In Progress",
|
||||
"group": "started",
|
||||
}
|
||||
def test_plane_webhook_generates_sequential_ids(mock_docs, mock_branch):
|
||||
"""Multiple work items get sequential IDs."""
|
||||
client.post("/webhook/plane", json={
|
||||
"event": "issue", "action": "updated",
|
||||
"data": {
|
||||
"id": "item-1", "name": "First task", "project": "proj-1",
|
||||
"state": in_progress_state,
|
||||
}
|
||||
"event": "work_item.created",
|
||||
"data": {"id": "item-1", "name": "First task", "project": "proj-1"}
|
||||
})
|
||||
client.post("/webhook/plane", json={
|
||||
"event": "issue", "action": "updated",
|
||||
"data": {
|
||||
"id": "item-2", "name": "Second task", "project": "proj-1",
|
||||
"state": in_progress_state,
|
||||
}
|
||||
"event": "work_item.created",
|
||||
"data": {"id": "item-2", "name": "Second task", "project": "proj-1"}
|
||||
})
|
||||
|
||||
conn = get_db()
|
||||
@@ -228,9 +202,8 @@ def test_gitea_webhook_push():
|
||||
assert resp.json()["status"] == "accepted"
|
||||
|
||||
|
||||
@patch("src.webhooks.gitea.plane_notify_stage")
|
||||
@patch("src.webhooks.gitea.launcher")
|
||||
def test_gitea_push_with_adr_advances_stage(mock_launcher, mock_plane_notify):
|
||||
def test_gitea_push_with_adr_advances_stage(mock_launcher):
|
||||
"""Push with ADR files at architecture stage → advance to development."""
|
||||
mock_launcher.launch.return_value = 1
|
||||
|
||||
@@ -262,7 +235,7 @@ def test_gitea_push_with_adr_advances_stage(mock_launcher, mock_plane_notify):
|
||||
task = conn.execute("SELECT * FROM tasks WHERE plane_id = 'push-001'").fetchone()
|
||||
conn.close()
|
||||
assert task["stage"] == "development"
|
||||
mock_plane_notify.assert_called_once()
|
||||
mock_launcher.launch.assert_called_once()
|
||||
|
||||
|
||||
@patch("src.webhooks.gitea.check_ci_green")
|
||||
|
||||
Reference in New Issue
Block a user