Skip to content

test: add schema and pure-logic test suites#6

Merged
rvw merged 2 commits into
mainfrom
add-test-suite
May 20, 2026
Merged

test: add schema and pure-logic test suites#6
rvw merged 2 commits into
mainfrom
add-test-suite

Conversation

@rvw
Copy link
Copy Markdown
Collaborator

@rvw rvw commented May 20, 2026

Summary

Adds the first two test layers for OpenHack, grounded in the project's existing architecture (schema-first artifacts, pure-logic routing modules):

  • Layer 1 — schema golden tests (tests/test_schemas.py): a minimum-valid baseline for each of the five durable artifact schemas (scenario, scenario-result, finding, finding-candidate, finding-triage), plus single-field mutations asserting the validator raises and points at the correct JSON path. Catches silent loosening of schema rules.
  • Layer 2 — pure-logic unit tests: deterministic, LLM-free coverage of the modules whose correctness gates the scenario→finding pipeline.
    • tests/test_paths.pyOPENHACK_ROOT resolution, walk-up fallback, ensure_run_dirs idempotency.
    • tests/test_coverage.py_path_class (27 cases), _tokens, _score_pair branch-by-branch (boundary-mandatory, supply-chain manifest, non-productive path-class, no-strong-terms, suggestion vs high), end-to-end routing_requirements / coverage_opportunities / coverage_suggestions.
    • tests/test_routing_units.py_kind_for_terms priority ordering, _compact_row truncation, _dedupe_rows cap, build_routing_units ID assignment + required/suggested separation + boundary-field preservation + mandatory-path fallback.
    • tests/test_backlog.py_scenario_paths, _scenario_covers_* predicates, _validate_decisions error cases, coverage_errors with on-disk coverage-gaps.json + routing-units.jsonl, and record_backlog happy-path + six error gates (unknown expert, duplicate id, duplicate obligation, missing required field, schema failure, coverage gap).

150 tests, ~0.16s, no network or LLM dependencies.

Wiring

  • pytest>=7.0 added to [project.optional-dependencies].dev and a [tool.pytest.ini_options] block set in pyproject.toml.
  • pytest step added to the existing CI workflow alongside ruff and mypy.
  • tests/conftest.py autouse-pins OPENHACK_ROOT to the repo root so the schema/expert lookups in schemas._schema and backlog.coverage_errors resolve deterministically regardless of the pytest invocation directory.

Test plan

  • pytest — 150 passed
  • ruff check . — clean
  • mypy — clean
  • CI green on the PR

rvw and others added 2 commits May 20, 2026 14:54
Adds the first two test layers for OpenHack: JSON Schema golden tests for
all five durable artifact shapes, and pure-logic unit tests for the
modules whose correctness gates the scenario→finding pipeline (paths,
coverage scoring, routing-unit clustering, backlog validation).

- 150 tests, runs in <0.2s, no LLM or network dependencies
- pytest added to dev extras and wired into CI alongside ruff/mypy
- conftest pins OPENHACK_ROOT so on-disk schema/expert lookups resolve
  deterministically regardless of where pytest is invoked from

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Gaps:
- Add coverage for write_coverage and write_routing_units (the disk-side
  entry points called from the CLI). They were the largest untested seam.
- Add record_backlog test for the expert_scope restriction path via
  run-config.yaml, plus an audit-event assertion on events.jsonl.
- Add full coverage of boundary_requirements in coverage_errors:
  flagged-when-missing, satisfied-by-scenario-boundary-id,
  satisfied-by-covered_boundary_ids list, satisfied-by-recon_item_id
  fallback, satisfied-by-boundary-id decision, and the negative case
  where a decision without a boundary_id does not satisfy.
- Rewrite scenario/decision predicate tests to go through coverage_errors
  rather than calling the private _scenario_covers_* / _validate_decisions
  helpers. Same coverage, resilient to internal refactors.

Cleanup:
- Fix test_kind_for_terms_first_match_wins to actually exercise priority
  (it now uses the 'template' overlap between html_template_dom_sink and
  parser_deserialization_integrity, plus the 'token' overlap).
- Drop test_baselines_are_independent — the helpers return fresh dicts
  by construction so the assertion was tautological.
- Replace the brittle bullet-count assertion in
  test_validator_reports_multiple_errors with field-name substring checks.
- Drop change-detector constants tests (DECISIONS, PRODUCTIVE_CLASSES,
  MAX_REQUIREMENTS_PER_PATH) — they only fired when someone updated the
  constant.

Nice-to-haves:
- CI now caches pip via setup-python's cache: pip.
- Split CI into a lint job (3.11) and a test job that matrixes pytest
  across 3.9, 3.11, 3.12 — pyproject declares requires-python>=3.9.
- Remove empty tests/__init__.py (pytest discovers without it).
- Hoist the ALL_RUN_DIRS import in conftest to module-level.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rvw rvw merged commit c7d0f56 into main May 20, 2026
4 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