Skip to main content

Project Vandal

PyPI version Python versions License: MIT Project Vandal CI

Proof that your AI written end to end tests actually catch bugs.

Vandal runs your pytest + Playwright tests against injected UI faults and measures which faults trigger assertions or Playwright action failures. Passing tests can still miss broken behavior. Vandal gives you a strength score and candidates for better assertions, including reports that coding agents can read. A score describes the mutations exercised; it is not a guarantee that a test catches every bug.

Two minute quick start

In your existing Python test project:

pip install project-vandal pytest-playwright
playwright install chromium
pytest --vandal

The page fixture from pytest-playwright works with the sync API. Custom sync and async Playwright tests work too; async tests need their usual async pytest plugin. Normal pytest runs are unchanged when --vandal is absent.

Vandal first runs the selected tests without mutations. For each passing baseline, it reruns the test in a fresh pytest process for each selected mutant, up to 20 per test by default. It writes vandal_report.json and vandal_report.html, and prints survivors and review hints. Each candidate also requires a passing unmutated replay before injection. Potential kills require another passing control afterward. Failed controls are reported as errors and excluded from strength. Controls cannot prove causality: intermittent external-state failures can still be mistaken for mutation kills. Use repeatable fixtures and isolated application state.

pytest tests/test_login.py --vandal --vandal-strategies=logic_sabotage,data_sabotage --vandal-max-mutants=10 --vandal-timeout=60
pytest -k login --vandal --vandal-min-score=80

Strength is 100 * killed / (killed + survived), overall and per test. Assertion failures and Playwright Error/TimeoutError in the test call count as killed only after confirmed mutation and passing unmutated controls. Reports distinguish kill_reason: assertion from action_failed. Worker deadlines, injection errors, setup/teardown failures, and failed controls remain errors and are excluded. Mutant errors do not fail the command by default; add --vandal-strict to fail for them. Baseline failures retain pytest's status. No scored mutants means null in JSON and N/A in the terminal; a minimum score gate fails in that case, including a gate of zero.

Targets are discovered when actions, reads or Locator assertions run. Constructing an unused locator does not create a target. By default, clicks, double-clicks, taps and checks use stealth_disable, ghost_element, and logic_sabotage; reads, assertions, fills and type use data_sabotage. Hover uses stealth_disable and ghost_element, which block the browser's hover action. Press, select_option, focus, dispatch_event and set_input_files have no default strategies: pointer blocking and click handlers do not reliably sabotage those operations. Targets used only through those actions are reported as untested. Observed targets without an inferred strategy appear in untested_targets with a terminal warning, separately from cap omissions. ui_shift and slow_load require explicit selection. Candidates alternate across targets before the cap; skipped_by_cap reports candidates omitted by that cap. Data sabotage is refreshed when targets are resolved again, so later app text changes do not silently undo it. For focused runs, specify targets with normal Playwright selectors:

import pytest

@pytest.mark.vandal(targets=["#login-btn"])
def test_login(page):
    page.goto("http://localhost:8000")
    page.locator("#login-btn").click()
    assert page.locator("#message").inner_text() == "Logged in"

The marker supplies targets; use normal pytest paths, -k, or -m vandal to select tests. See limits and outcome rules before treating a survivor as a missing assertion.

See a weak and strong test

From this repository after pip install -e ".[test]":

pytest examples/test_strength.py --vandal --vandal-strategies=logic_sabotage

Both tests click the same button in a local HTML app. The weak test only clicks. The strong test asserts the resulting message, so it detects the swallowed click. Use the generated report to compare their measured scores.

Coding agents and MCP

On Python 3.10 or newer:

pip install "project-vandal[mcp]"
vandal-mcp

Configure your MCP client to launch vandal-mcp with the trusted test repository as its working directory. The stdio server exposes:

  • run_vandal(test_path, strategies, max_mutants, deadline_seconds, pytest_args): runs pytest and returns the JSON report, with an optional deadline_seconds (maximum 600), 30 seconds per worker, and a maximum of 100 mutants per test. pytest_args permits only -k, -m, and node IDs inside the working folder. A deadline returns completed mutants in a partial report with timed_out: true.
  • get_surviving_mutants(report_path): reads survivors and review hints from a report inside that working directory.

Tests and conftest files execute project code. Run the server only in trusted checkouts, against isolated test data. Paths cannot escape the working directory; commands use argument arrays without shell interpolation. See the agent skill and versioned report schema.

Learn more: Project Vandal: UI mutation testing · Project page · Tester's Guide · Follow @dkkkkd on X

Installation

Ensure you have Playwright installed:

# Install the engine from PyPI
pip install project-vandal

# Or clone for local development
git clone https://github.com/godhiraj-code/vandal.git
cd vandal
pip install .

# Setup Playwright
playwright install chromium

Usage

You can use the Vandal class as a context manager in your Playwright tests (Vandal uses Playwright's async API):

from vandal import Vandal

async with Vandal(page) as v:
    # Apply a mutation to an element
    await v.apply_mutation("stealth_disable", "#login-btn")
    
    # Run your test logic
    await page.click("#login-btn")
    
    # Assert the outcome
    assert await page.inner_text("#msg") == "Success"

If the test fails inside the async with block, the mutant is recorded as killed (your test noticed the sabotage). If it passes, the mutant survived, which points to a gap in your assertions. Call v.report() to print the results or v.save_report() to write vandal_report.json and vandal_report.html.

Features

  • Mutation Strategies:
    • stealth_disable: Disables pointer events on elements, making them unclickable while remaining visually present.
    • ghost_element: Makes elements invisible and unclickable.
    • data_sabotage: Replaces text or input values with junk data.
    • logic_sabotage: Prevents event propagation (e.g., stopping click handlers from firing).
    • ui_shift: Moves elements 100px right and down with a CSS transform.
    • slow_load: Hides elements for 5 seconds, then shows them again.
  • Playwright Integration: Easy-to-use context manager (Vandal) for wrapping test logic.
  • Shadow DOM and navigation: Mutations reach elements inside open shadow roots. By default (persistent=True) they are also registered as an init script, so they are re-applied on every page loaded afterwards, including to elements added dynamically on those pages.
  • Reporting: Automated mutation report showing which "mutants" were killed (detected by tests) or survived.
  • Detailed Guide: See TESTER_GUIDE.md for advanced usage and customization.

Project Structure

  • vandal/core.py: The heart of the mutation engine (JavaScript-based strategies).
  • vandal/playwright_ext.py: Playwright wrapper and context manager.
  • vandal/pytest_plugin.py: Suite baselines, mutation workers, selection and scoring gates.
  • vandal/instrumentation.py: Playwright target discovery and mutation timing.
  • vandal/reporting.py: Versioned JSON reports, summaries and HTML rendering.
  • vandal/runner.py: Bounded subprocess execution and process cleanup.
  • vandal/mcp_server.py: Optional stdio tools for coding agents.
  • demo_vandal.py: A demonstration script showing Vandal in action.
  • vandal_demo_app.html: A simple demo application for testing.

Running the Demo

The project includes a demo script that tests a simple login button.

Headless Mode

python demo_vandal.py --headless

Headed Mode

python demo_vandal.py --headed

In headed mode, the script includes a slow_mo delay and holds the browser open for 5 seconds after completion so you can see the results.

When to use Vandal (vs code mutation testing)

Tool What it mutates What it tells you
mutmut, cosmic-ray Your Python source code (operators, constants, conditions) Whether your unit/integration tests notice code changes
Project Vandal The rendered UI in a live browser page (pointer events, visibility, text/values, click handlers, position) Whether your Playwright end-to-end tests notice a broken UI

They answer different questions and work well together. Use Vandal when:

  • you want evidence that a critical E2E test (login, checkout, a primary CTA) actually fails when that UI breaks
  • you suspect tests are "too loose", for example they click with force=True or never assert on the outcome
  • you are reviewing a new critical test before trusting it in CI

Vandal is not a good fit if you use Selenium or Cypress (only Playwright for Python is supported today), or if you want to measure unit-test quality (use a source-code mutation tool for that).

FAQ and Troubleshooting

Does it work with pytest? Yes. Install the package and use pytest --vandal for automatic baseline and mutation runs. Normal pytest selection still applies.

Does it support Playwright's sync API? The automatic pytest plugin supports sync and async Playwright, including the pytest-playwright page fixture. The existing manual Vandal context manager remains async and fully compatible with its previous API.

Why did my test raise an exception when the mutant was killed? Vandal records the result but does not swallow the exception: a killed mutant means your test failed, and the failure propagates. Catch it around the async with block if you want the run to continue, as demo_vandal.py does.

"Warning: No elements found for selector" The selector matched nothing on the current page when the mutation was applied. On the current page a mutation is applied once, immediately, so wait for the element first (await page.wait_for_selector(selector)). Alternatively, apply the mutation before page.goto(): persistent mutations then watch the new page and also hit elements that appear later.

My mutant survived but the UI was clearly broken. Check the hint, force=True, and assertions about the visible outcome. A survivor is a candidate for review, not proof that an assertion is missing. The automatic runner records controlled Playwright call failures as action_failed kills; worker deadlines and infrastructure failures remain excluded errors.

Can I undo a mutation? revert_mutation() reverts stealth_disable, ghost_element, data_sabotage and ui_shift on the current page. logic_sabotage and slow_load have no revert script. Persistent mutations are registered with page.add_init_script(), which Playwright can't remove, so use a fresh page or context for the next test.

Why "Vandal"?

Unlike traditional mutation testing that modifies source code, Project Vandal sabotages the UI layer directly in the browser. This is particularly effective for catching:

  • CSS regressions that block interactions.
  • Event listener bugs.
  • Data binding failures.

License

MIT. See LICENSE.

Metadata

Release files for project-vandal 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for project-vandal 0.3.0
File Size Uploaded Provenance Actions
project_vandal-0.3.0.tar.gz 42.0 kB Without provenance Details for project_vandal-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for project-vandal 0.3.0
File Interpreter ABI Platform Actions
project_vandal-0.3.0-py3-none-any.whl Python 3 none any Details for project_vandal-0.3.0-py3-none-any.whl

Total release size: 70.7 kB

Release files / project_vandal-0.3.0.tar.gz

Download URL project_vandal-0.3.0.tar.gz
Size 42.0 kB
Tags Source
SHA-256 checksum
How to use checksums
337aa12386ca383e182ff149bbf4b1d503fb3ef6e6723f3c18425584a91034c8
BLAKE2b-256 checksum
How to use checksums
020c6447ddd7367b206f2a1c326720e3a1d9ccbf448a3055b3ca07a2cd77fb93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / project_vandal-0.3.0-py3-none-any.whl

Download URL project_vandal-0.3.0-py3-none-any.whl
Size 28.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
398ac472328d9a11c92816170f267ddd72b66c3ca8efb0947c2710ca2391b084
BLAKE2b-256 checksum
How to use checksums
9746240c5aad8c99123bb969384f863a76afc1b4d2c57b2aa5fdaecbc74443ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for project-vandal 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page