Skip to content

test: validate emitted result JSON against result.schema.json#127

Merged
mertsatilmaz merged 1 commit into
mainfrom
test/result-schema-validation
May 17, 2026
Merged

test: validate emitted result JSON against result.schema.json#127
mertsatilmaz merged 1 commit into
mainfrom
test/result-schema-validation

Conversation

@mertsatilmaz
Copy link
Copy Markdown
Collaborator

Summary

Adds `tests/test_result_schema.py` enforcing the contract between `HarnessResult.to_dict()` and `schemas/result.schema.json`.

7 positive tests cover every (mode × result) combination the harness can produce: `dry_run/not_run`, `trace/pass`, `trace/fail`, `live/pass`, `trace/error`, plus `assertion-without-evidence` and `empty-assertions-list` edge cases.

8 negative tests confirm the schema actually rejects bad shapes — invalid `mode`/`result` enums, extra top-level / assertion / trace properties, missing required fields. Without these, the positive tests alone would still pass if someone accidentally loosened `additionalProperties` or dropped an enum.

The validator uses `Draft202012Validator` matching the schema's declared draft, and calls `check_schema()` at fixture load so schema syntax errors fail loudly.

Why this matters for v0.1.0

The result JSON shape is part of the public contract (downstream CI gates parse it). Without these tests, schema and dataclass can drift silently — particularly easy when adding a new field to `HarnessResult` but forgetting the schema, or vice versa.

Dependencies

Adds `jsonschema>=4` to `[project.optional-dependencies].dev`. CI already installs `[dev]`, so no workflow change needed.

Test plan

  • `python -m pytest -q` — 250 passed (235 + 15 new)
  • `ruff check src tests` — clean
  • `mypy` — clean

Closes #87

Add tests/test_result_schema.py with 15 tests enforcing the contract
between HarnessResult.to_dict() and schemas/result.schema.json.

- 7 positive tests covering every (mode, result) combination the
  harness can produce: dry_run/not_run, trace/pass, trace/fail,
  live/pass, trace/error, plus assertion-without-evidence and
  empty-assertions-list edge cases.
- 8 negative tests confirming the schema actually rejects bad shapes
  (invalid mode/result enums, extra top-level/assertion/trace
  properties, missing required fields). Without these the positive
  tests alone would still pass if someone accidentally loosened
  additionalProperties or dropped an enum.

The fixture validator uses Draft202012Validator (matching the schema's
declared draft) and calls check_schema() on load to catch schema
syntax errors.

Adds jsonschema>=4 to dev dependencies. CI already runs the dev
extras so this works in CI without further changes.

Closes #87
@mertsatilmaz mertsatilmaz merged commit e3f53ec into main May 17, 2026
3 checks passed
@mertsatilmaz mertsatilmaz deleted the test/result-schema-validation branch May 17, 2026 18:16
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.

Validate emitted result JSON against result.schema.json in tests

1 participant