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.