From bee48bf4a5f7d9b51403f5a79ec86d3c43e808c6 Mon Sep 17 00:00:00 2001 From: Stommer Date: Sun, 25 Oct 2026 07:29:45 +0100 Subject: [PATCH] Behebe die fehlschlagenden Paperless-Tests und lasse test.yml nur noch nach dem Dev-Deploy laufen. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Der Hinweis zu Tags und Zusatzfeld sitzt wieder in paperless_documents, damit die Signatur von _paperless_get bleibt. Der Push-Trigger entfällt, weil er einen zweiten Lauf auf derselben Testdatenbank startete. Co-Authored-By: Claude Sonnet 5.5 --- .gitea/workflows/test.yml | 4 ++-- backend/app/sources.py | 15 ++++++++------ backend/tests/test_connector_followup.py | 26 +++++++++++++++++------- docs/DEPLOYMENT.md | 4 ++-- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index d7b5513..be0d1eb 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -1,8 +1,8 @@ name: Test Suite +# Runs once per push, after "Deploy Development" has updated the checkout it tests. +# A push trigger here would start a second run that races the deploy. on: - push: - branches: [develop] workflow_run: workflows: ["Deploy Development"] types: [completed] diff --git a/backend/app/sources.py b/backend/app/sources.py index 13f79ab..69ff207 100644 --- a/backend/app/sources.py +++ b/backend/app/sources.py @@ -418,9 +418,13 @@ def paperless_documents(conn, owner_id: UUID, query: str, connector_id: UUID | N names = _paperless_lookup(row["id"], base, row["secret"]) params = _paperless_params(query, options, names["custom_fields"]) # Observed on a real instance: all-tags together with a custom field makes Paperless answer 500. - clash = "," in params.get("tags__id__all", "") and "custom_field_query" in params - hint = "Das tritt auf, wenn „Alle gewählten Tags“ mit einem Zusatzfeld zusammentrifft. Wähle „Mindestens eines“ oder lass das Zusatzfeld weg." if clash else "" - payload = _paperless_get(base, row["secret"], "/api/documents/", params, hint) + try: + payload = _paperless_get(base, row["secret"], "/api/documents/", params) + except Problem as problem: + clash = "," in params.get("tags__id__all", "") and "custom_field_query" in params + if clash and "HTTP 5" in problem.detail: + raise unprocessable(f"{problem.detail} Das tritt auf, wenn „Alle gewählten Tags“ mit einem Zusatzfeld zusammentrifft. Wähle „Mindestens eines“ oder lass das Zusatzfeld weg.") from problem + raise assert_still_owned(conn, row["id"], owner_id) terms = _search_terms(query, (options or {}).get("title")) items = [] @@ -1008,7 +1012,7 @@ def _filename(disposition: str | None) -> str: return value.replace("\\", "").replace("/", "")[:180] -def _paperless_get(base: str, token: str, path: str, params: dict, hint: str = "") -> dict: +def _paperless_get(base: str, token: str, path: str, params: dict) -> dict: url = f"{base}{path}?{urlencode(params)}" request = Request(url, headers={"Authorization": f"Token {token}", "Accept": "application/json"}) try: @@ -1017,8 +1021,7 @@ def _paperless_get(base: str, token: str, path: str, params: dict, hint: str = " except HTTPError as exc: if exc.code in {401, 403}: raise unprocessable("Paperless hat den Schlüssel abgelehnt.") from exc - advice = f" {hint}" if hint and exc.code >= 500 else "" - raise unprocessable(f"Paperless hat die Anfrage nicht beantwortet ({_refusal(exc, path)}).{advice}") from exc + raise unprocessable(f"Paperless hat die Anfrage nicht beantwortet ({_refusal(exc, path)}).") from exc except (URLError, TimeoutError, json.JSONDecodeError) as exc: raise unprocessable("Paperless ist nicht erreichbar.") from exc diff --git a/backend/tests/test_connector_followup.py b/backend/tests/test_connector_followup.py index dbd57e6..dee705d 100644 --- a/backend/tests/test_connector_followup.py +++ b/backend/tests/test_connector_followup.py @@ -12,6 +12,7 @@ from email.parser import BytesParser import pytest +from app.core.errors import unprocessable from app.media.port import MemoryAdapter from app.sourceaccess import borrow_original, complete_borrow from app.sourceregistry import SourceModule, unregister_source, register_source @@ -593,9 +594,12 @@ def test_paperless_custom_field_filters_use_the_instance_fields(client, db, monk ] } if path == "/api/documents/": + if failing: + raise unprocessable(failing[0]) return {"count": 0, "results": []} return {"results": []} + failing = [] monkeypatch.setattr(sources, "_paperless_get", fake_get) ada = Actor(client, "ada-custom@example.test", "Ada Custom") register(db, ada.email, ada.name) @@ -652,6 +656,21 @@ def test_paperless_custom_field_filters_use_the_instance_fields(client, db, monk params={"connector_id": first["id"], "custom": "kein json"}, status=422, ) + # Paperless answers 500 for all-tags together with a custom field: the message names that pairing. + failing.append("Paperless hat die Anfrage nicht beantwortet (HTTP 500 auf /api/documents/).") + row = json.dumps([{"field": "2", "op": "exists", "value": True}]) + + def refused(extra): + return ada.request( + "GET", + "/api/v1/sources/paperless/documents", + params={"connector_id": first["id"], "custom": row, **extra}, + status=422, + ) + + assert "Alle gewählten Tags" in str(refused({"tag": "1,2"})) + assert "Alle gewählten Tags" not in str(refused({"tag": "1,2", "tag_mode": "any"})) + assert "Alle gewählten Tags" not in str(refused({"tag": "1"})) def test_paperless_refusal_names_the_status_and_reason(monkeypatch): @@ -677,13 +696,6 @@ def test_paperless_refusal_names_the_status_and_reason(monkeypatch): with pytest.raises(Problem) as caught: sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {}) assert caught.value.detail.endswith("(HTTP 500 auf /api/documents/).") - with pytest.raises(Problem) as caught: - sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {}, "Hinweis.") - assert caught.value.detail.endswith("(HTTP 500 auf /api/documents/). Hinweis.") - monkeypatch.setattr(sources, "urlopen", refuse(400, b"{}")) - with pytest.raises(Problem) as caught: - sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {}, "Hinweis.") - assert "Hinweis" not in caught.value.detail monkeypatch.setattr(sources, "urlopen", refuse(403, b"{}")) with pytest.raises(Problem) as caught: sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {}) diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index a6eef2b..ad1827c 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -30,7 +30,7 @@ Unter `/home/lars/docker/` legt der Lauf nur diese zwei Verzeichnisse an: |----------|---------|--------| | `deploy-dev.yml` | Push `develop` | Deploy nach `/home/lars/docker/tsumugu-dev`, Health `localhost:8094` und `localhost:3094` | | `deploy-prod.yml` | Push `main` | Deploy nach `/home/lars/docker/tsumugu`, Health `localhost:8007` und `localhost:3007` | -| `test.yml` | Push `develop`, nach erfolgreichem Dev-Deploy, manuell | Pytest gegen `tsumugu_test` auf der Dev-Postgres, Smoke der laufenden Dev-App, Frontend-Build | +| `test.yml` | Nach erfolgreichem Dev-Deploy (`workflow_run`), manuell | Pytest gegen `tsumugu_test` auf der Dev-Postgres, Smoke der laufenden Dev-App, Frontend-Build | Gearbeitet wird auf `develop`. Production entsteht nur durch einen Merge-Commit `develop` → `main` (`git merge --no-ff develop` auf `main`) und den anschließenden Push von `main`. Kein Fast-Forward, kein direkter Commit auf `main`, kein manuelles `git pull` auf dem Prod-Checkout. Gitea (`deploy-prod.yml`) ist der einzige Prod-Schreibpfad für Code. @@ -54,7 +54,7 @@ Diese Punkte sind im [Code-Review](review/06_BEFUNDE.md) beschrieben. Sie stehen | Datenbankzugang | Das Backend migriert beim Start mit dem Owner-Zugang. Die Runtime-Rolle `tsumugu_runtime` erhält dasselbe Passwort wie `DB_USER` | Ein Wechsel von `DB_PASSWORD` ändert beim nächsten Start beide Rollen | R-09 | | Quellen-Geheimnisse | Paperless-Token und IMAP-Passwörter stehen unverschlüsselt in der Tabelle `connectors` | Datenbank-Dumps wie Zugangsdaten schützen | R-05 | | Sessions | 14 Tage gültig, keine Leerlaufabmeldung, kein Passwortwechsel in der Anwendung | Passwort nur über die Datenbank oder ein neues Konto änderbar | R-08 | -| Testläufe | `test.yml` startet je Push zweimal auf derselben Datenbank `tsumugu_test` | Ein roter Lauf kann vom parallelen Lauf verursacht sein; Ergebnis des Einzellaufs prüfen | R-27 | +| Testläufe | `test.yml` startet je Push einmal, nach dem Dev-Deploy; alle Läufe teilen die Datenbank `tsumugu_test`, und das Image bleibt das Laufzeitimage | Zwei manuelle Läufe gleichzeitig vermeiden; sie würden sich die Datenbank wegnehmen | R-27 | ---