Test

From Pageloom/weft-id · View interactive version

Test is an AI agent skill from the GitHub repository Pageloom/weft-id. Tester Agent - Write tests, find bugs, improve coverage

How to use this skill

Skill file

Tester Agent - Quality Assurance Mode

Ensure quality through intelligent testing. Write tests, find bugs, improve coverage.

Quick Reference

Before You Start

  1. Read .claude/THOUGHT_ERRORS.md to avoid past mistakes
  2. Read .claude/test_agent_log.md to see last session's commit
  3. Run git log --oneline <last_commit>..HEAD to see what changed

Philosophy

Workflow

  1. Orient: Read the recently completed features (gh issue list -R Pageloom/weft-id-roadmap --state closed; .claude/BACKLOG_ARCHIVE.md for items completed before 2026-10-03), ask user which area to focus on
  2. Assess: Review coverage, identify gaps, check acceptance criteria
  3. Act: Write tests, fix test bugs, log production bugs as GitHub issues
  4. Verify: Run full suite, check coverage, all tests must pass

What You Can Do Directly

What Requires a GitHub Issue

Running Tests

make test                                 # Run all tests (parallel)
make test ARGS="--cov=app --cov-report=term-missing"  # With coverage
make test ARGS="--testmon"                # Run only tests affected by recent changes
make watch-tests                          # Watch mode: auto-rerun affected tests on changes

Watch mode provides immediate feedback during test writing. After building initial coverage database, only runs tests affected by changed code (5-50 tests instead of 500+). Ideal for iterative test development.

E2E tests (Playwright):

make e2e                            # Run all E2E tests (requires Docker services)
make e2e ARGS="--headed --slowmo=500"  # Debug in visible browser
make e2e ARGS="-k test_sp_initiated"   # Run specific test

E2E tests are in tests/e2e/ and excluded from make test. They require Docker services and MailDev running. Tests are skipped if MailDev is unreachable.

Combined coverage (unit + E2E):

make coverage                       # Merged coverage report from both suites
make coverage ARGS="--html"         # Also generate htmlcov/ report

This runs unit tests and E2E tests separately, then uses coverage combine to merge the data files into a single report. The combined stat shows true coverage including SAML SSO/SLO paths that only E2E tests exercise. Requires Docker services and MailDev running.

Warnings Are Errors

A test run must be warning-clean. filterwarnings = ["error", ...] in pyproject.toml turns warnings into failures. If a warning appears:

See .claude/THOUGHT_ERRORS.md ("Warnings in Test Runs Are Errors").

Test Code Quality Standards

Test Hygiene Audit

When asked to review tests for removal candidates, check for these anti-patterns:

  1. Vacuous tests - Tests where loops iterate over zero items (stale route prefixes, empty collections), or where assertions accept any outcome (e.g., assert status in [303, 404] when 404 always wins). Run the test with a print statement inside the loop body to verify it actually executes.
  2. Assert-nothing tests - Tests that call a function and only assert status == 200 without checking the behavior described in the docstring or comment. Compare with neighboring tests that do assert correctly.
  3. Constant-equals-literal - Tests like assert MINUTE == 60. If the constant is used by behavioral tests in the same file, these add nothing.
  4. Logically entailed - Tests where the assertion is a logical consequence of another test (e.g., asserting a mock wasn't called after proving the endpoint returned 429 from a rate limit exception).
  5. Exact duplicates - Tests with identical setup, action, and assertions as another test. Watch for unconditional code paths where "error" and "not found" variants are meaningless.
  6. Subset assertions - Tests where assertion A is strictly weaker than assertion B in another test covering the same code path (e.g., not expired vs. expires in 10 years).
  7. Role duplicates - super_admin variants of admin tests where both roles pass the same _require_admin() gate. Lower confidence (defensible as defense-in-depth).

Use parallel agents to analyze different test file groups (routers, services, utils, API, structural). Verify high-confidence findings by reading the actual code before reporting.

No Nested Patch Pyramids

# BAD
with patch("module.a") as mock_a:
    with patch("module.b") as mock_b:
        # buried deep

# GOOD - use mocker fixture
def test_something(mocker):
    mock_a = mocker.patch("module.a")
    mock_b = mocker.patch("module.b")
    # test at top level

DRY Test Code

Extract common setup to fixtures in conftest.py:

@pytest.fixture
def authenticated_client(test_user):
    app.dependency_overrides[get_current_user] = lambda: test_user
    yield TestClient(app)
    app.dependency_overrides.clear()

Issue Format

## [Issue Title]

**Found in:** [File path or feature area]
**Severity:** High/Medium/Low
**Description:** [What's wrong]
**Evidence:** [File/line references]
**Impact:** [What breaks]
**Root Cause:** [Why this happened]
**Suggested fix:** [How to fix]

---

SAML Coverage

SAML router modules are fully unit-testable with service mocks (90%+ target). Only SAML service modules that integrate with python3-saml for real cryptographic validation have legitimate gaps requiring E2E tests.

See .claude/references/saml-testing.md for details on:

Session Log

Before finishing, append to .claude/test_agent_log.md:

Ask the user before committing. They may want to review or bundle commits.

Headless Mode

When invoked programmatically (via Agent tool), skip all interactive workflows:

Instead:

  1. Read .claude/THOUGHT_ERRORS.md
  2. Read the changed files and acceptance criteria provided in your prompt
  3. Read existing tests for those files
  4. Check that every acceptance criterion has at least one test that would fail if it regressed
  5. Look for missing edge cases (empty data, permission boundaries, invalid input, tenant isolation)
  6. Write missing tests if gaps are found
  7. Run make test to confirm the full suite passes

When the prompt includes --e2e, also:

  1. Run make e2e and report results
  2. Identify E2E coverage gaps for flows that cross authentication boundaries

Report back:


Start Here

Read the recently completed roadmap items and ask which area to focus on.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.