Compare commits

...
7 changed files with 160 additions and 0 deletions
+3
View File
@@ -4,3 +4,6 @@ __pycache__/
build/
dist/
.venv/
.meduza/CONTRACT.md
.meduza/.budget-fired
.meduza/.stub-script.json
+22
View File
@@ -0,0 +1,22 @@
# Plan
<!-- Zadania: "- [ ] N.M opis". Jedno zadanie = jedna iteracja (maks ~25% okna kontekstu). -->
## Etap 1: moduł dredd_core/workflow_contract.py
- [ ] 1.1 Utwórz opt-in `dredd_core/workflow_contract.py` (bez klienta HTTP) wg `.meduza/SPEC-workflow-contract.md`: stałe `SOURCE_MODULE`, pięć `KINDS`, `SUBJECT_KINDS`, `payload(...)` (DocumentRef → pola z `document_ref.to_dict` mieszczące się w `events.check_payload`; FileRef → tylko `file_id` + `sha256`, bez nazwy; `None` → `request_type` `[a-z0-9_]{1,40}`; oba albo żaden → `ValidationError` z `code`; `stage` nieujemny int), frozen `WorkflowEvent`, `parse(...)` (każdy błąd → `ValidationError` z `code`, nigdy `KeyError`/`TypeError`) oraz docstring modułu w stylu `events.py`/`stats_contract.py`. Najpierw przeczytaj `dredd_core/events.py` (`check_kind`, `check_payload`), `dredd_core/document_ref.py`, `dredd_core/errors.py`. W `tests/test_workflow_contract.py` dopisz testy ze specu: `test_kinds_are_valid_event_kinds`, `test_payload_document_roundtrip`, `test_payload_file_has_no_name`, `test_payload_request`, `test_payload_refuses_subject_and_request_type_together`, `test_payload_refuses_subject_and_request_type_neither`, `test_parse_refuses_malformed` (parametryzowany: nieznany `subject_kind`, brak `run_id`, zły uuid, zły sha256, ujemny stage), `test_import_dredd_core_does_not_load_workflow_contract` (lustro testu z `tests/test_events_unit.py`). Gotowe gdy: te testy przechodzą i cały `python -m pytest -q` (komenda z configu) jest zielony.
- [ ] 1.2 Dopisz do `dredd_core/workflow_contract.py` frozen `StartResult(run_id, link)` i frozen `WorkflowClient(client: ModuleClient)` z `start(self, *, token, subject, template_id=None, note=None)`: `POST /runs`, body `{"subject": document_ref.to_dict(subject), "template_id", "note"}` bez `None`ów, token osoby jako bearer, keyword-only bez domyślnej wartości; pusty token → `ValidationError`; non-2xx → ścieżka `raise_for_status` z `module_client.ModuleResponse`; 2xx bez poprawnego `run_id`/`link` → `ModuleCallError`. Najpierw przeczytaj `dredd_core/module_client.py` i wzorzec stub-serwera w `tests/test_module_client.py`. W `tests/test_workflow_contract.py` dopisz `test_client_start_posts_with_person_token` (ścieżka `/api/v1/runs`, nagłówek `Authorization: Bearer <token>`, subject w body, link zaczyna się od `#/runs/`), `test_client_start_refuses_bad_2xx_body` (200 z `{}` → `ModuleCallError`), `test_client_start_requires_token` (`token=""` → `ValidationError`, brak `token` → `TypeError`). Uzupełnij docstring modułu o klienta. Gotowe gdy: nowe testy przechodzą, testy z 1.1 dalej przechodzą i cały `python -m pytest -q` jest zielony.
## Etap 2: wydanie 0.24.0
- [ ] 2.1 W `dredd_core/events.py` zmień w `FIRST_EVENTS` komentarz przy `"workflow.approved"` z `# Compass (later Workflow): ...` na `# Workflow: ...` (tylko komentarz, zero zmian zachowania) i w `pyproject.toml` ustaw `version = "0.24.0"`. Nie twórz tagu git. Gotowe gdy: `git diff` pokazuje wyłącznie te dwie linie i cały `python -m pytest -q` jest zielony.
- [ ] 2.2 W `README.md` dodaj sekcję `## Workflow contract (0.24.0)` po sekcji „Stats contract (0.23.0)” i jej notach, w formacie sąsiednich sekcji opt-in (events, document_ref, stats contract): co to jest, kto emituje (rola modułu Workflow, odbiorcy `sources={kind: {"workflow_app"}}`), reguła payloadu (bez nazw i treści), API (`payload`, `parse`, `WorkflowClient.start`), dlaczego silnik nie jest w core; plus `### 0.24.0 notes` (nowy opt-in moduł, bez zmian schematu i migracji, poprawiony komentarz w `events.py`). Popraw notę 0.23.0 mówiącą, że K4 (czat) zostaje 0.24.0 — dopisz, że 0.24.0 zajął kontrakt Workflow (bez przesądzania nowego numeru K4). Zaktualizuj pin w sekcji Install z `v0.23.1` na `v0.24.0`, jeśli poprzednie wydania też go podbijały (sprawdź `git log -p -- README.md`). Opis API ma się zgadzać z faktycznymi sygnaturami w `dredd_core/workflow_contract.py`. Gotowe gdy: sekcja i noty istnieją, każda wymieniona w README nazwa istnieje w module, a cały `python -m pytest -q` jest zielony.
## Zależności
1.2 <- 1.1 : klient dopisuje do tego samego modułu i pliku testów co 1.1 i korzysta z jego walidacji
2.2 <- 1.2 : README opisuje gotowe API modułu, łącznie z WorkflowClient.start z 1.2
2.2 <- 2.1 : noty 0.24.0 opisują zmianę komentarza i wersji z 2.1
## Pliki
1.1: dredd_core/workflow_contract.py, tests/test_workflow_contract.py
1.2: dredd_core/workflow_contract.py, tests/test_workflow_contract.py
2.1: dredd_core/events.py, pyproject.toml
2.2: README.md
+1
View File
@@ -0,0 +1 @@
# Pytania
+107
View File
@@ -0,0 +1,107 @@
# dredd-core 0.24.0 - Workflow contract
Part A of the Workflow module plan (Tobiasz's vault: `Compass/Compass - Workflow - plan wdrożenia (2026-11-18).md`,
spec `Compass/Compass - Workflow - spec modułu (2026-11-18).md`, both under
`C:\Users\badur\OneDrive\Dokumenty\Vaults\Misc`). Read both before starting; this file is the
binding scope for this repository.
## Why
The platform gets a new module, **Workflow** (slug `workflow`), that holds every approval run: on
Galena documents, on plain uploaded files and on requests (e.g. an expense). Other modules talk to
it in two ways only: they **read its events** from the shared `module_event` log (Galena moves a
contract card to "zatwierdzona"/"podpisana") and they **start a run** on a subject with the acting
person's token (Galena's "Wyślij do akceptacji" button, later Agora). Both sides must share one
definition of the event kinds and the payload shape, so it lives here, in core. The engine itself
does NOT live in core: it lives in the Workflow module (decided 2026-11-18).
## Scope
One new opt-in module `dredd_core/workflow_contract.py`, its tests, a version bump, a README
section. Nothing else in core changes, except one comment in `dredd_core/events.py`.
### `dredd_core/workflow_contract.py`
- Opt-in like `events`, `document_ref`, `stats_contract`: `import dredd_core` never loads it; it
registers no tables.
- Constants: `SOURCE_MODULE = "workflow"`; `STARTED = "workflow.started"`,
`APPROVED = "workflow.approved"`, `REJECTED = "workflow.rejected"`,
`CANCELLED = "workflow.cancelled"`, `SIGNED_ON_PAPER = "workflow.signed_on_paper"`;
`KINDS: tuple[str, ...]` = all five, each passing `events.check_kind`.
- `SUBJECT_KINDS = ("document", "file", "request")`.
- `def payload(*, run_id: uuid.UUID, subject: document_ref.Ref | None, request_type: str | None,
actor_id: uuid.UUID, stage: int | None = None) -> dict[str, Any]`
- returns a dict that passes `events.check_payload` (identifiers and numbers only — check what
that function allows and stay inside it);
- `subject` a `DocumentRef` → `subject_kind="document"` plus the reference's identifying fields
(module, document id, path, commit sha, sha256 — reuse `document_ref.to_dict` where it fits the
payload rules);
- `subject` a `FileRef` → `subject_kind="file"`, `file_id`, `sha256` ONLY: a file's display name
never enters the shared log;
- `subject is None` → `subject_kind="request"` and `request_type` is required (a key matching
`[a-z0-9_]{1,40}`); passing both a subject and a request_type, or neither, is a
`ValidationError` with a `code`;
- `stage` optional non-negative int.
- `@dataclass(frozen=True) class WorkflowEvent`: `run_id: uuid.UUID`, `subject_kind: str`,
`document: DocumentRef | None`, `file_id: uuid.UUID | None`, `sha256: str | None`,
`request_type: str | None`, `actor_id: uuid.UUID`, `stage: int | None`.
- `def parse(event_payload: Mapping[str, Any]) -> WorkflowEvent` — the inverse of `payload`;
anything malformed (unknown `subject_kind`, missing ids, bad uuid, bad sha) is a
`ValidationError` with a `code`, never a `KeyError`/`TypeError`. Receivers call it on untrusted
rows.
- `@dataclass(frozen=True) class StartResult`: `run_id: uuid.UUID`, `link: str` (console route
relative to the module root, e.g. `"#/runs/<uuid>"`).
- `@dataclass(frozen=True) class WorkflowClient`: field `client: ModuleClient`;
`def start(self, *, token: str, subject: document_ref.Ref, template_id: uuid.UUID | None = None,
note: str | None = None) -> StartResult` — `POST /runs` with JSON
`{"subject": document_ref.to_dict(subject), "template_id": ..., "note": ...}` (omit `None`s),
the person's token as bearer (`module_client` rule: always a person's token, keyword-only, no
default). Non-2xx → raise via the response's own `raise_for_status` path (look at how
`module_client.ModuleResponse` does it); a 2xx body without a valid `run_id`/`link` →
`ModuleCallError`. `token` is required and must be a non-empty string.
- Module docstring in the house style of `events.py`/`stats_contract.py`: what the contract is,
who emits (only the role of the Workflow module; receivers should pass
`sources={kind: {"workflow_app"}}` to `events.receive`), the payload rule (no names, no content),
and that the engine is NOT here and why (one home for all runs, decided 2026-11-18).
### Other files
- `dredd_core/events.py`: in `FIRST_EVENTS` the comment on `"workflow.approved"` says
`# Compass (later Workflow): ...` → `# Workflow: ...`. No behaviour change.
- `pyproject.toml`: `version = "0.24.0"`.
- `README.md`: a short section for the new module next to the other opt-in modules (events,
document_ref, stats contract), in the same format they use, with a changelog line for 0.24.0 if
the README keeps one.
- Do NOT create a git tag. Roman tags after merging.
## Tests
`tests/test_workflow_contract.py`, no database. At least:
- `test_kinds_are_valid_event_kinds` — every `KINDS` entry passes `events.check_kind`.
- `test_payload_document_roundtrip` — `DocumentRef` → `payload` → `events.check_payload` →
`parse`: same document id, commit sha, sha256, stage.
- `test_payload_file_has_no_name` — `FileRef(name="tajne.pdf")`: `"tajne"` absent from
`json.dumps(payload(...))`; `parse` gives `subject_kind == "file"`, `file_id`, `sha256`,
`document is None`.
- `test_payload_request` — `request_type="wydatek"` roundtrips; `subject_kind == "request"`.
- `test_payload_refuses_subject_and_request_type_together` and `..._neither` — `ValidationError`.
- `test_parse_refuses_malformed` — parametrised: unknown `subject_kind`, missing `run_id`, bad
uuid, bad sha256, negative stage → `ValidationError`, never another exception type.
- `test_client_start_posts_with_person_token` — reuse the stub HTTP server pattern from
`tests/test_module_client.py` (`ThreadingHTTPServer` + `Stub` handler on `127.0.0.1:0`): the
request goes to `/api/v1/runs`, carries `Authorization: Bearer <token>`, the JSON body has the
subject; the result has the run id and a link starting with `#/runs/`.
- `test_client_start_refuses_bad_2xx_body` — 200 with `{}` → `ModuleCallError`.
- `test_client_start_requires_token` — `token=""` → `ValidationError`; calling without `token` is a
`TypeError` (keyword-only, no default).
- `test_import_dredd_core_does_not_load_workflow_contract` — the same check the other opt-in
modules have (find it and mirror it).
Run: `C:/Users/badur/projects/lw-venv-core-klucze/Scripts/python.exe -m pytest -q` — the whole
suite must stay green (database tests skip without a Postgres, that is fine).
## Out of scope
- The engine, the Workflow module, any table, any Galena or Atrium change.
- Grants for `workflow_app` in the event log (Atrium's `MODULE_EVENT_EMITTER_ROLES`, part D).
+3
View File
@@ -0,0 +1,3 @@
# Stan cząstkowy
(brak — ostatnia iteracja domknęła zadanie)
+23
View File
@@ -0,0 +1,23 @@
{
"threshold": 0.3,
"maxIterations": 25,
"branch": "meduza/work",
"notify": [
"toast"
],
"ntfyTopic": null,
"ntfyServer": "https://ntfy.sh",
"contextWindow": 1000000,
"model": null,
"iterationTimeoutMin": 30,
"thresholdInteractive": 0.25,
"ceilingInteractive": 0.35,
"maxWindows": 1,
"test": "C:/Users/badur/projects/lw-venv-core-klucze/Scripts/python.exe -m pytest -q",
"testTimeoutMin": 10,
"maxRedTests": 3,
"testWriter": false,
"testPaths": [
"tests/"
]
}
+1
View File
@@ -0,0 +1 @@
# Journal