diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..2283a95 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,22 @@ +name: CI +on: + push: + branches: ["feature/**", "bugfix/**", "hotfix/**", "fix/**", "ci/**"] + pull_request: + branches: [main] + +jobs: + test: + runs-on: self-hosted + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + run: | + python3 -m pip install --user --upgrade pip + python3 -m pip install --user -r requirements.txt + - name: Test + env: + PYTHONPATH: ${{ github.workspace }} + run: | + export PATH="$HOME/.local/bin:$PATH" + python3 -m pytest tests/ -q diff --git a/tests/test_webhooks.py b/tests/test_webhooks.py index 5f3850f..0ab8b0e 100644 --- a/tests/test_webhooks.py +++ b/tests/test_webhooks.py @@ -54,13 +54,19 @@ 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): - """work_item.created → task in DB with stage=analysis.""" +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.""" resp = client.post("/webhook/plane", json={ - "event": "work_item.created", - "data": {"id": "test-123", "name": "Test task", "project": "proj-1"} + "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"}, + } }) assert resp.status_code == 200 assert resp.json()["status"] == "accepted" @@ -202,8 +208,9 @@ 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): +def test_gitea_push_with_adr_advances_stage(mock_launcher, mock_plane_notify): """Push with ADR files at architecture stage → advance to development.""" mock_launcher.launch.return_value = 1 @@ -235,7 +242,7 @@ def test_gitea_push_with_adr_advances_stage(mock_launcher): task = conn.execute("SELECT * FROM tasks WHERE plane_id = 'push-001'").fetchone() conn.close() assert task["stage"] == "development" - mock_launcher.launch.assert_called_once() + mock_plane_notify.assert_called_once() @patch("src.webhooks.gitea.check_ci_green")