|
| 1 | +Approval Testing (Golden-Master Baselines) |
| 2 | +========================================== |
| 3 | + |
| 4 | +Approval testing (a.k.a. golden-master / snapshot testing) reframes "is this |
| 5 | +output still correct?" as "does it still match the version a human approved?". |
| 6 | +:func:`verify_artifact` compares produced content to a stored |
| 7 | +``<name>.approved.<ext>`` baseline: |
| 8 | + |
| 9 | +* **match** → the check passes; |
| 10 | +* **mismatch or missing baseline** → the produced bytes are written to |
| 11 | + ``<name>.received.<ext>`` and the check fails, so a reviewer can diff the two |
| 12 | + and, if the change is intended, promote it with :func:`approve_artifact`. |
| 13 | + |
| 14 | +It works for *any* artifact — rendered text, JSON, OCR output, screenshot bytes |
| 15 | +— so it complements pixel diffing with a review-gated baseline you commit |
| 16 | +alongside the test. Pure standard library; imports no ``PySide6``. Names are |
| 17 | +validated against path traversal. |
| 18 | + |
| 19 | +Headless API |
| 20 | +------------ |
| 21 | + |
| 22 | +.. code-block:: python |
| 23 | +
|
| 24 | + from je_auto_control import verify_artifact, approve_artifact |
| 25 | +
|
| 26 | + result = verify_artifact("invoice_render", produced_text, |
| 27 | + approvals_dir="tests/.approvals") |
| 28 | + if not result.match: |
| 29 | + # first run is "new", a changed output is "mismatch"; review the |
| 30 | + # .received file, then bless it: |
| 31 | + approve_artifact("invoice_render", approvals_dir="tests/.approvals") |
| 32 | +
|
| 33 | +``content`` may be ``str`` or ``bytes`` (pass ``extension="png"`` for binary |
| 34 | +snapshots). A verified run clears any stale received file. |
| 35 | +``pending_artifacts(dir)`` lists names still awaiting approval. ``ApprovalResult`` |
| 36 | +carries ``status`` (``verified`` / ``mismatch`` / ``new``), ``match``, and both |
| 37 | +file paths. |
| 38 | + |
| 39 | +Executor commands |
| 40 | +----------------- |
| 41 | + |
| 42 | +================================ =================================================== |
| 43 | +Command Effect |
| 44 | +================================ =================================================== |
| 45 | +``AC_verify_artifact`` Compare ``content`` to the approved baseline. |
| 46 | +``AC_approve_artifact`` Promote the received artifact to the baseline. |
| 47 | +``AC_pending_artifacts`` List artifacts awaiting approval. |
| 48 | +================================ =================================================== |
| 49 | + |
| 50 | +The same operations are exposed as MCP tools (``ac_verify_artifact`` / |
| 51 | +``ac_approve_artifact`` / ``ac_pending_artifacts``) and as Script Builder |
| 52 | +commands under **Testing**. |
0 commit comments