Skip to content

test(watermark): characterise the current tool before the redesign - #209

Merged
nelsonduarte merged 2 commits into
mainfrom
test/watermark-characterization
Oct 17, 2026
Merged

nelsonduarte merged 2 commits into
mainfrom
test/watermark-characterization

Conversation

@nelsonduarte

Copy link
Copy Markdown
Owner

Summary

Characterisation tests for the watermark tool (TabMarcaDagua), written before the redesign so that every behaviour change it makes is deliberate and visible. No production change: the PR adds three files under tests/ only.

  • tests/test_watermark_characterization.py: 37 tests that drive the real TabMarcaDagua through _load_input and _run, with the background work run inline and every modal and file dialog replaced by fail-closed stand-ins.
  • tests/_inline_background.py: the helper that runs the background work inline.
  • tests/conftest.py: new and suite-wide. It only registers the known_defect marker.

The tests pin:

  • the affected pages;
  • the above/below layer order;
  • the placement, measured by rendering, on A4, landscape A4, A5, /Rotate 90 and a shifted CropBox;
  • the document structure that is lost today (outline, title, page labels, AcroForm, attachments);
  • the output name and the unencrypted output;
  • a multi-page watermark;
  • cancellation.

13 of the 37 tests carry the new known_defect marker: they characterise known defects as they behave today, and the redesign will change them on purpose. List them with pytest -m known_defect.

A widget census and a top-level window guard make sure a new warning does not go unseen. What is left out is declared in the test file itself.

Verification

Windows, base 01dcb6a, PyMuPDF 1.28.2 venv, --strict-markers:

Run Result
Full suite, normal order 1023 passed, 2 skipped
Full suite, reverse order 1023 passed, 2 skipped
restore_probe plugin (22 patch targets, 1025 tests), both orders 0 not restored
Module alone, 4 runs plus 1 reversed 37 passed each

Mutation run, 80 entries, almost all edits to app/tools/watermark.py plus a few test-side edits to the harness, each run on a throwaway copy:

Outcome Count
Killed 70
Survived, declared as not covered in the test file 7
Controls (baseline with no edit, load slot that does nothing) 2
Hangs by design (R8 without the contract test's safety net, killed at 60 s) 1
Total 80

WSL, Ubuntu 26.04, Python 3.14.4, fresh clone of this branch at 0e6f509, throwaway venv with requirements.txt and requirements-dev.txt (pypdf 6.21.0, PyMuPDF 1.28.2, PySide6 6.11.2, pytest 9.1.1), --strict-markers:

Run Result
Full suite, normal order 1022 passed, 3 skipped
Full suite, reverse order 1022 passed, 3 skipped
Module alone, 3 runs 37 passed each
-m known_defect 13 passed, 1012 deselected

The 3 skips are platform skips that already exist (one Windows-only test, two that need DejaVuSans.ttf).

🤖 Generated with Claude Code

37 tests drive the real TabMarcaDagua through _load_input and _run,
with the background work run inline and every modal and file dialog
replaced by fail-closed stand-ins.

They pin the affected pages, the above/below layer order, the
placement measured by rendering on A4, landscape A4, A5, /Rotate 90
and a shifted CropBox, the document structure that is lost (outline,
title, page labels, AcroForm, attachments), the output name, the
unencrypted output, a multi-page watermark and cancellation.

13 tests carry the new known_defect marker (registered in
tests/conftest.py): they characterise known defects that the redesign
will change on purpose.

A widget census and a top-level window guard make sure a new warning
does not go unseen. What is left out is declared in the test itself.

No production change.

Mutations: 80 entries; 70 killed; 7 survive and are declared as not
covered; 2 are controls; 1 hangs by design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gitguardian

gitguardian Bot commented Oct 16, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
38298628 Triggered Generic Password 0e6f509 tests/test_watermark_characterization.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

The GitGuardian check on the pull request flagged a "Generic Password"
(incident 38298628) in tests/test_watermark_characterization.py, on
the line rec = run_tool(src, wm, out=out, src_password=src_pw).

The only password literal in the file is "segredo-ç", a parameter that
encrypts a PDF generated in tmp_path.

The exclusion is per individual file, as the header of .gitguardian.yaml
asks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Deploying pdfapps with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3b7d936
Status: ✅  Deploy successful!
Preview URL: https://7f75844f.pdfapps.pages.dev
Branch Preview URL: https://test-watermark-characterizat.pdfapps.pages.dev

View logs

@nelsonduarte
nelsonduarte merged commit 6160b92 into main Oct 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant