chore: consolidate check helpers into resources/_check_helpers#87
Conversation
There was a problem hiding this comment.
Code Review
This pull request centralizes the logic for converting check parameters into the wire format by introducing a new helper module, _check_helpers.py. It replaces several redundant internal implementations across the checks, evaluations, and test_cases resources and updates the corresponding tests. A bug was identified in the check_params_to_specs function where the flat=True branch fails to handle Pydantic models, which would lead to an AttributeError at runtime.
| result.append({"identifier": identifier, **{k: v for k, v in params.items() if k != "type"}}) | ||
| else: | ||
| entry: Dict[str, Any] = {"identifier": identifier, "enabled": check.get("enabled", True)} | ||
| if params: | ||
| entry["spec"] = check_param_to_spec(identifier, params) | ||
| result.append(entry) |
There was a problem hiding this comment.
The flat=True branch currently assumes params is a dictionary and calls .items(). However, params can also be a Pydantic BaseModel (as handled in check_param_to_spec). This will cause an AttributeError at runtime if a model is passed. Reusing check_param_to_spec ensures consistent handling of both dictionaries and models while also correctly stripping the type key.
| result.append({"identifier": identifier, **{k: v for k, v in params.items() if k != "type"}}) | |
| else: | |
| entry: Dict[str, Any] = {"identifier": identifier, "enabled": check.get("enabled", True)} | |
| if params: | |
| entry["spec"] = check_param_to_spec(identifier, params) | |
| result.append(entry) | |
| if flat: | |
| spec = check_param_to_spec(identifier, params) | |
| spec.pop("kind", None) | |
| result.append({"identifier": identifier, **spec}) | |
| else: | |
| entry: Dict[str, Any] = {"identifier": identifier, "enabled": check.get("enabled", True)} | |
| if params: | |
| entry["spec"] = check_param_to_spec(identifier, params) | |
| result.append(entry) |
Summary
Consolidates the request-side check helpers that were spread between
types/check.pyandresources/evaluations/evaluations.pyinto a single sharedresources/_check_helpers.pymodule. Merges the two list-builders into one parametrized function. No behavior change.What changed
resources/_check_helpers.pyhousingIDENTIFIER_TO_KIND,check_param_to_spec, andcheck_params_to_specs(..., flat: bool)._check_params_to_api(test-cases shape) and_check_params_to_flat_specs(run-single shape) merged intocheck_params_to_specs(..., flat=False/True).resources/_included.py. Removes a# pyright: ignoreworkaround._extract_check_paramsstays intypes/check.py— response-side helper used by theCheck/CheckConfigpydantic validators.