Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions test/services/test_profile_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,60 @@ def iter_errors(self, metadata: dict):
assert len(findings) == _MAX_FINDINGS
assert findings[-1] == ValidationMessage("error", _OMISSION_MESSAGE)

@staticmethod
def _schema_validator_yielding(monkeypatch: pytest.MonkeyPatch, count: int) -> None:
"""Replace the schema validator with one yielding exactly ``count`` errors."""

class FakeError:
def __init__(self, index: int) -> None:
self.path = [f"field{index:04}"]
self.absolute_path = self.path
self.message = f"error {index:04}"

class FakeValidator:
def __init__(self, schema: dict) -> None:
del schema

def iter_errors(self, metadata: dict):
del metadata
yield from (FakeError(index) for index in range(count))

monkeypatch.setattr(profile_validator, "Draft202012Validator", FakeValidator)

def test_exactly_filling_the_budget_emits_no_marker(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
"""The ``+ 1`` lookahead must not fire the marker when nothing is omitted.

With a document producing no other findings, the regular budget is
``_MAX_FINDINGS - 1``. Exactly that many schema errors must surface in
full with no omission marker: the lookahead peeks one past the budget,
finds nothing, and stays silent.
"""
self._schema_validator_yielding(monkeypatch, _MAX_FINDINGS - 1)

findings = validate_frontmatter({"name": "agent"})

assert len(findings) == _MAX_FINDINGS - 1
assert not any(f.message == _OMISSION_MESSAGE for f in findings)

def test_one_error_past_the_budget_emits_exactly_one_marker(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] This one is mostly redundant — worth re-pointing its docstring at what it uniquely holds.

The docstring says dropping the + 1 "would silently stop reporting truncation," which is the justification I gave you and which turns out to be inaccurate: test_schema_iterator_consumes_only_remaining_plus_one, ~60 lines above in this same class, already fails on that mutation via assert consumed == remaining_after_key_findings + 1. So does test_schema_prefix_is_stable_across_hash_seeds.

I'd still keep the test — it asserts the observable contract (marker present, exactly once, last, error severity) where the older one asserts iterator mechanics, and those are worth pinning separately. But as written, someone auditing coverage later will read this docstring, believe it is the sole guard on the + 1, and may delete the older test as duplicative — which would drop the consumed assertion, the only check that the tail isn't drained.

Something like:

"""The omission marker's shape at the smallest truncating input.

Complements test_schema_iterator_consumes_only_remaining_plus_one:
that one pins how much of the iterator is consumed, this one pins
what the caller actually sees — exactly one marker, last, at error
severity.
"""

No change needed to the assertions themselves; they're right.

For contrast, test_exactly_filling_the_budget_emits_no_marker above genuinely stands alone — I confirmed >>= survives all 63 tests on main and is caught only by it. That one's docstring is accurate as written.

self, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Dropping the ``+ 1`` lookahead would silently stop reporting truncation.

One error beyond the regular budget is the smallest input where
truncation occurs, and the lookahead entry is the only evidence a tail
existed. The marker must appear exactly once, last, at error severity.
"""
self._schema_validator_yielding(monkeypatch, _MAX_FINDINGS)

findings = validate_frontmatter({"name": "agent"})

assert len(findings) == _MAX_FINDINGS
assert sum(f.message == _OMISSION_MESSAGE for f in findings) == 1
assert findings[-1] == ValidationMessage("error", _OMISSION_MESSAGE)

def test_ordered_additional_properties_is_lazy_with_real_validator(self) -> None:
"""The real keyword handler must not inspect the omitted tail."""
from itertools import islice
Expand Down
Loading