style: ruff format the merged OpenAPI compliance test file

Whitespace-only normalization (blank-line collapse and line wrapping)
required by the ruff format gate after merging upstream 424bfd8758; no
semantic or runtime change. Verified: 8 passed/13 skipped identical to
pre-format, ruff-tests and py_compile clean.
This commit is contained in:
jibanez-staticduo 2026-10-01 05:01:17 +02:00
parent 57434aede5
commit 8a6eee4d49
No known key found for this signature in database

View file

@ -33,13 +33,10 @@ def _load_openapi_spec_dict() -> Dict[str, Any]:
return response.json() return response.json()
except Exception as e: # pragma: no cover - defensive, env-dependent except Exception as e: # pragma: no cover - defensive, env-dependent
pytest.skip( pytest.skip(
f"Skipping Google Interactions OpenAPI compliance tests - " f"Skipping Google Interactions OpenAPI compliance tests - unable to load spec from {OPENAPI_SPEC_URL}: {e}"
f"unable to load spec from {OPENAPI_SPEC_URL}: {e}"
) )
def _declared_type_value(variant_schema: Dict[str, Any]) -> Any: def _declared_type_value(variant_schema: Dict[str, Any]) -> Any:
"""The single `type` value a union variant pins, whether spelled as a const or a 1-item enum.""" """The single `type` value a union variant pins, whether spelled as a const or a 1-item enum."""
type_property = variant_schema.get("properties", {}).get("type", {}) type_property = variant_schema.get("properties", {}).get("type", {})
@ -175,22 +172,18 @@ class TestRequestCompliance:
discriminator = content_schema.get("discriminator") discriminator = content_schema.get("discriminator")
if discriminator is not None: if discriminator is not None:
assert ( assert discriminator.get("propertyName") == "type", (
discriminator.get("propertyName") == "type" f"Content is discriminated on {discriminator.get('propertyName')!r}, not 'type'"
), f"Content is discriminated on {discriminator.get('propertyName')!r}, not 'type'" )
variant_names = [ variant_names = [
option["$ref"].split("/")[-1] option["$ref"].split("/")[-1] for option in content_schema.get("oneOf", []) if "$ref" in option
for option in content_schema.get("oneOf", [])
if "$ref" in option
] ]
assert variant_names, f"Content is not a union of named variants: {content_schema}" assert variant_names, f"Content is not a union of named variants: {content_schema}"
mapping = (discriminator or {}).get("mapping") or {} mapping = (discriminator or {}).get("mapping") or {}
type_values = { type_values = {
variant: mapping_value variant: mapping_value for mapping_value, ref in mapping.items() for variant in [ref.split("/")[-1]]
for mapping_value, ref in mapping.items()
for variant in [ref.split("/")[-1]]
} or { } or {
variant: _declared_type_value(spec_dict["components"]["schemas"].get(variant, {})) variant: _declared_type_value(spec_dict["components"]["schemas"].get(variant, {}))
for variant in variant_names for variant in variant_names
@ -241,7 +234,9 @@ class TestRequestCompliance:
for option in spec_dict["components"]["schemas"]["Step"]["oneOf"] for option in spec_dict["components"]["schemas"]["Step"]["oneOf"]
if "$ref" in option if "$ref" in option
} }
assert {"UserInputStep", "ModelOutputStep"} <= step_variants, f"Step union is missing role steps: {step_variants}" assert {"UserInputStep", "ModelOutputStep"} <= step_variants, (
f"Step union is missing role steps: {step_variants}"
)
for step_name, type_value in [("UserInputStep", "user_input"), ("ModelOutputStep", "model_output")]: for step_name, type_value in [("UserInputStep", "user_input"), ("ModelOutputStep", "model_output")]:
step_schema = spec_dict["components"]["schemas"][step_name] step_schema = spec_dict["components"]["schemas"][step_name]
@ -311,9 +306,7 @@ class TestResponseCompliance:
expected_fields = ["total_input_tokens", "total_output_tokens", "total_tokens"] expected_fields = ["total_input_tokens", "total_output_tokens", "total_tokens"]
for field in expected_fields: for field in expected_fields:
assert ( assert field in usage_schema["properties"], f"Usage field '{field}' not in spec"
field in usage_schema["properties"]
), f"Usage field '{field}' not in spec"
print(f"✓ Usage field '{field}' exists") print(f"✓ Usage field '{field}' exists")
@ -332,9 +325,7 @@ class TestToolsCompliance:
"""Verify FunctionDeclaration schema for function tools.""" """Verify FunctionDeclaration schema for function tools."""
if "FunctionDeclaration" in spec_dict["components"]["schemas"]: if "FunctionDeclaration" in spec_dict["components"]["schemas"]:
func_schema = spec_dict["components"]["schemas"]["FunctionDeclaration"] func_schema = spec_dict["components"]["schemas"]["FunctionDeclaration"]
assert "name" in func_schema.get( assert "name" in func_schema.get("properties", {}) or "name" in func_schema.get("required", [])
"properties", {}
) or "name" in func_schema.get("required", [])
print("✓ FunctionDeclaration schema found") print("✓ FunctionDeclaration schema found")
else: else:
print("⚠ FunctionDeclaration schema not found (may be nested)") print("⚠ FunctionDeclaration schema not found (may be nested)")
@ -449,6 +440,4 @@ if __name__ == "__main__":
if method in ["get", "post", "delete", "put", "patch"]: if method in ["get", "post", "delete", "put", "patch"]:
print(f" {method.upper()} {path}") print(f" {method.upper()} {path}")
print( print(f"\nSchemas: {list(spec.get('components', {}).get('schemas', {}).keys())[:10]}...")
f"\nSchemas: {list(spec.get('components', {}).get('schemas', {}).keys())[:10]}..."
)