Skip to content

test: add PDF export endpoint coverage and run in CI (closes #72)#82

Merged
wpak-ai merged 2 commits into
masterfrom
feat/unit-test-for-pdf-export
May 27, 2026
Merged

test: add PDF export endpoint coverage and run in CI (closes #72)#82
wpak-ai merged 2 commits into
masterfrom
feat/unit-test-for-pdf-export

Conversation

@bradjin8
Copy link
Copy Markdown
Collaborator

@bradjin8 bradjin8 commented May 27, 2026

Summary

  • Add tests/test_pdf_export.py with 8 Flask test-client cases for POST /api/generate-pdf: normal markdown export, empty body defaults, unsafe title filename sanitization, empty markdown, long content, Unicode/emoji, simulated PDF engine failure (500), and malformed markdown payload (500).
  • Add a lightweight pdf_client fixture in conftest.py so PDF tests do not need the full workspace_storage setup.
  • Include tests/test_pdf_export.py in the CI pytest step so the new tests actually run in the matrix (previously only test_api_endpoints.py was executed).

Closes #72.

API note: The PDF route accepts { markdown, title } from the browser after client-side markdown conversion (download.js). It does not look up conversations by ID on the server; invalid tab IDs are handled by /api/workspaces/.../tabs (covered in test_api_endpoints.py). Server-side error coverage uses a mocked FPDF.output failure and a non-string markdown field.

Test plan

  • python -m pytest tests/test_pdf_export.py tests/test_api_endpoints.py -v
  • python -m pytest tests/ -q (full suite)
  • CI green on PR (ubuntu/windows/macos × Python 3.10–3.13)

Summary by CodeRabbit

  • Tests

    • Added comprehensive test suite for PDF export endpoint covering normal operation, edge cases (empty content, long content, unicode/emoji), and error handling scenarios.
  • Chores

    • Updated test automation workflow to include PDF export tests in CI pipeline.

Review Change Stack

@bradjin8 bradjin8 self-assigned this May 27, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0e80802c-e81d-4e24-b771-f78c2bd8311b

📥 Commits

Reviewing files that changed from the base of the PR and between adb75a4 and 67da983.

📒 Files selected for processing (3)
  • .github/workflows/tests.yml
  • tests/conftest.py
  • tests/test_pdf_export.py

📝 Walkthrough

Walkthrough

This PR adds comprehensive unit tests for the PDF export endpoint. It updates the CI workflow to run the new test module, introduces a pdf_client fixture for testing routes without workspace storage, and implements a full test suite with helpers, happy-path cases, edge-case handling, and error validation.

Changes

PDF Export Endpoint Tests

Layer / File(s) Summary
CI and test client setup
.github/workflows/tests.yml, tests/conftest.py
GitHub Actions pytest step now includes test_pdf_export.py alongside test_api_endpoints.py. New pdf_client fixture creates a Flask test client with testing mode enabled and exclusion rules disabled.
Test helpers and constants
tests/test_pdf_export.py (lines 1–40)
Module-level PDF_MAGIC constant and _post_pdf() helper support default or custom JSON payloads. _assert_pdf_response() validates HTTP 200, application/pdf content type, PDF magic bytes, and EOF marker.
Happy path and default behavior tests
tests/test_pdf_export.py (lines 41–86)
TestGeneratePdfHappyPath covers normal markdown export, empty JSON body with defaults (title "Chat"), and filename sanitization of unsafe title characters.
Edge case and error handling tests
tests/test_pdf_export.py (lines 87–126)
TestGeneratePdfEdgeCases validates empty markdown, very long content, and Unicode/emoji handling. TestGeneratePdfErrors asserts HTTP 500 with {"error": "Failed to generate PDF"} when the FPDF output call raises an exception (mocked) or the markdown field is non-string.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • cppalliance/cppa-cursor-browser#32: Extended test infrastructure by updating the CI pytest step to include the new PDF export test module alongside the existing API endpoint tests.

Suggested reviewers

  • wpak-ai

Poem

🐰 A fixture hops in, tests follow with glee,
PDF bytes dance where they're meant to be,
Happy paths, edge cases, errors held tight—
The export endpoint shines ever so bright! 📄✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding PDF export endpoint test coverage and integrating it into CI.
Linked Issues check ✅ Passed The PR meets all coding requirements from issue #72: test file created, 8 test cases covering normal export, empty/long/Unicode content, error handling, PDF validity checks with magic bytes, Flask test client used, and CI integration added.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #72: test file creation, fixture addition for PDF testing, and CI workflow update to run the new tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/unit-test-for-pdf-export

Comment @coderabbitai help to get the list of available commands and usage tips.

@bradjin8 bradjin8 requested a review from clean6378-max-it May 27, 2026 16:18
@clean6378-max-it
Copy link
Copy Markdown
Collaborator

models/from_dict_validation.py — add a small tests/test_from_dict_validation.py asserting message text for require_non_empty_str_fields / require_non_empty_str_field: absent key → missing required field, wrong type → invalid field. test_schema_error_message_distinguishes_missing_from_invalid covers the contract generically but not these helpers post-f846aaf.

models/from_dict_validation.py:69 — expand require_truthy docstring to note falsy values (None, "", 0) are treated as missing (matches prior CliSessionMeta behavior).

@bradjin8
Copy link
Copy Markdown
Collaborator Author

bradjin8 commented May 27, 2026

models/from_dict_validation.py — add a small tests/test_from_dict_validation.py asserting message text for require_non_empty_str_fields / require_non_empty_str_field: absent key → missing required field, wrong type → invalid field. test_schema_error_message_distinguishes_missing_from_invalid covers the contract generically but not these helpers post-f846aaf.

models/from_dict_validation.py:69 — expand require_truthy docstring to note falsy values (None, "", 0) are treated as missing (matches prior CliSessionMeta behavior).

both findings are already satisfied on the current tree

  • tests/test_from_dict_validation.py exists and includes focused helper coverage:
    require_non_empty_str_field: absent key → "missing required field", wrong type → "invalid field".
    require_non_empty_str_fields: absent key → "missing required field", wrong type → "invalid field".
  • models/from_dict_validation.py has the expanded require_truthy docstring at line ~69 explicitly stating falsy values (None, "", 0, etc.) are treated as missing.

@clean6378-max-it
Copy link
Copy Markdown
Collaborator

Agree with this option in the scope of PR.

@clean6378-max-it clean6378-max-it requested a review from wpak-ai May 27, 2026 18:01
@wpak-ai wpak-ai merged commit 46bda64 into master May 27, 2026
16 checks passed
@wpak-ai wpak-ai deleted the feat/unit-test-for-pdf-export branch May 27, 2026 18:15
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.

Add unit tests for PDF export endpoint

3 participants