From dafa56452c3b40ce97d5cbef42671eaa99b77fa6 Mon Sep 17 00:00:00 2001 From: Timothy Date: Sun, 23 Aug 2026 01:35:46 +0200 Subject: [PATCH] test(807): make "threaded through every branch" a checked property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `_resolve` returns three sets and the third has to reach every composition site. That was a claim in a docstring; each site is a separate opportunity to forget, and forgetting is silent — no error, just a smaller population. Ten sites enumerated and asserted: top level, `allOf` arm, `if`, `then`, `else`, `dependentSchemas`, `oneOf` arm, `anyOf` arm, `items`, `prefixItems`. All ten currently thread it. Witnessed load-bearing by dropping the threading at three of them — `allOf` reddens 1 case, `oneOf`/`anyOf` 2, `items` 2. The value is not today's ten passes; it is that a NEW composition keyword has one visible place to be added to, instead of the omission being spread across the resolver where nothing would report it. 956 passed 2 skipped, ruff check 0, ruff format 0. --- .../tests/test_optional_request_members.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/scripts/tests/test_optional_request_members.py b/scripts/tests/test_optional_request_members.py index fd7436694..c2d18148a 100644 --- a/scripts/tests/test_optional_request_members.py +++ b/scripts/tests/test_optional_request_members.py @@ -665,6 +665,43 @@ def test_composition_is_resolved_the_way_JSON_Schema_means_it(case: str, schema: assert sorted(_optional_of(schema)) == expected, case +_NESTED_PROBE = { + "properties": {"outer": {"properties": {"req": {}, "opt": {}}, "required": ["req"]}}, + "required": ["outer"], +} + + +@pytest.mark.parametrize( + ("site", "schema"), + [ + ("top level", _NESTED_PROBE), + ("allOf arm", {"allOf": [_NESTED_PROBE]}), + ("if", {"if": _NESTED_PROBE}), + ("then", {"then": _NESTED_PROBE}), + ("else", {"else": _NESTED_PROBE}), + ("dependentSchemas", {"dependentSchemas": {"trigger": _NESTED_PROBE}}), + ("oneOf arm", {"oneOf": [_NESTED_PROBE]}), + ("anyOf arm", {"anyOf": [_NESTED_PROBE]}), + ("items", {"type": "array", "items": _NESTED_PROBE}), + ("prefixItems", {"type": "array", "prefixItems": [_NESTED_PROBE]}), + ], +) +def test_a_nested_inline_object_survives_EVERY_composition_site(site: str, schema: dict) -> None: + """`_resolve` returns three sets, and the third has to be threaded through every branch. + + A composition site that unions `properties` and `required` but forgets `nested_optional` loses + the nested member silently — no error, just a smaller population — and each site is a separate + opportunity to forget. Enumerating the sites here is what makes "threaded through every branch" + a checked property instead of a claim in a docstring; a NEW composition keyword must be added + to this list, and if it is not, the omission is at least visible in one place rather than + spread across the resolver. + """ + assert "outer.opt" in _optional_of(schema), ( + f"a nested inline object under `{site}` lost its optional member — `nested_optional` is " + "not threaded through that branch of `_resolve`" + ) + + def test_a_ref_ARM_is_covered_by_the_component_walk_not_by_this_one() -> None: """The two walks COMPOSE; neither alone covers an inline body with a `$ref` arm.