Skip to content

Testing and Validation

The test suite for pptcraft is organized to validate the full stack, from low-level OOXML manipulation to high-level server integration. The architecture relies heavily on mocking the LLM backend to ensure deterministic, fast, and offline-capable unit tests for the engine and rendering logic. Integration tests verify that the FastAPI server correctly handles authentication, origin validation, and returns valid binary artifacts.

The engine tests (tests/test_engine.py) cover the full Phase B path by mocking the Qwen LLM responses, eliminating the need for a live localhost:8010 instance 1.

  • Render Layer: Tests verify that the render_one_slide_pptx function produces valid PPTX files that can be reopened by python-pptx. This includes verifying title slides round-trip correctly and that chart slides contain the necessary embedded workbooks and chart XML parts.
  • Engine Phase A (Storyline): Tests confirm that engine.generate_storyline correctly parses JSON responses from the mocked LLM and returns a structured list of slide layouts.
  • Engine Phase B (Build One Slide): Tests validate engine.build_one_slide by checking that it produces valid slides, records iteration latency, and handles validation failures. Specifically, the engine is tested to ensure it re-prompts the LLM if the initial output contains placeholder residue (e.g., “Lorem ipsum”) 2.
  • Prompts: Tests ensure that system prompts are byte-stable across calls to support prefix-cache hits, and that JSON extraction handles both fenced and raw JSON formats.

The OOXML core tests (tests/test_ooxml_core.py) focus on the low-level manipulation of the PPTX ZIP structure, ensuring that edits are surgical and that the resulting files remain valid and editable.

  • Unpack/Repack: Tests verify that loading a PPTX and converting it back to bytes results in a file that python-pptx can reopen cleanly 3.
  • Theme Edits: Tests confirm that palette and font changes are applied to every theme part in the deck, not just the first one, ensuring multi-master safety.
  • Surgical Slide Edits: Tests validate that apply_paragraphs and set_run_text correctly modify XML nodes and that the changes round-trip through python-pptx.
  • Native Charts: Tests ensure that chart insertion produces both ppt/charts/*.xml and ppt/embeddings/*.xlsx files, with the chart XML referencing the embedded workbook via c:externalData. This guarantees “Edit Data” parity in PowerPoint.
  • Validation: Tests verify the validator correctly identifies blockers such as shapes outside the canvas bounds (out_of_bounds) and placeholder residue (placeholder_residue).

Integration tests (tests/test_server_routes.py and tests/test_smoke.py) ensure the server behaves correctly under various conditions, including authentication, origin validation, and CLI functionality.

  • Authentication and Origin: Tests verify that the /api/session endpoint requires a Bearer token and rejects requests from disallowed origins (e.g., evil.example.com), while accepting valid Office origins 4.
  • Manifest Endpoint: Tests confirm that /manifest.xml returns valid XML with the correct OfficeApp root, permissions, and minimum version requirements.
  • Health and Edit Routes: Tests check that the health route is accessible with valid auth and that the edit slide stub returns a base64-encoded PPTX that starts with the ZIP magic bytes PK.
  • CLI and Package Smoke Tests: Tests ensure the CLI exposes all expected subcommands (serve, manifest, cert, etc.) and that the manifest rendering produces valid XML. Additionally, schema round-trips and stub slide generation are verified to ensure data integrity 5.