fix(lint): resolve lint errors in structural validation module
CI / lint (pull_request) Failing after 1m14s
CI / helm (pull_request) Successful in 47s
CI / push-validation (pull_request) Successful in 36s
CI / build (pull_request) Successful in 1m11s
CI / quality (pull_request) Successful in 1m52s
CI / typecheck (pull_request) Successful in 1m54s
CI / security (pull_request) Successful in 1m57s
CI / integration_tests (pull_request) Successful in 5m24s
CI / unit_tests (pull_request) Successful in 6m32s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 3s
CI / lint (pull_request) Failing after 1m14s
CI / helm (pull_request) Successful in 47s
CI / push-validation (pull_request) Successful in 36s
CI / build (pull_request) Successful in 1m11s
CI / quality (pull_request) Successful in 1m52s
CI / typecheck (pull_request) Successful in 1m54s
CI / security (pull_request) Successful in 1m57s
CI / integration_tests (pull_request) Successful in 5m24s
CI / unit_tests (pull_request) Successful in 6m32s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 3s
Fix E501 line length violations in validators.py by breaking long lines. Fix B007 unused loop variable by renaming check to _check_type. Fix isort __all__ sort order in cli/output/__init__.py. ISSUES CLOSED: #8164
This commit is contained in:
@@ -209,8 +209,8 @@ from cleveragents.cli.output.validators import (
|
||||
PLAN_TREE_NODE_KEYS,
|
||||
STRUCTURED_OUTPUT_KEYS,
|
||||
VALID_STATUS_VALUES,
|
||||
OutputValidationResult,
|
||||
OutputValidationError,
|
||||
OutputValidationResult,
|
||||
validate_decision_dict,
|
||||
validate_plan_tree,
|
||||
validate_structured_component_output,
|
||||
@@ -266,11 +266,11 @@ __all__ = [
|
||||
"TreeHandle",
|
||||
"TreeNode",
|
||||
"YamlMaterializer",
|
||||
"detect_terminal_capabilities",
|
||||
"select_materializer",
|
||||
"strip_terminal_escapes",
|
||||
"validate_decision_dict",
|
||||
"validate_plan_tree",
|
||||
"validate_structured_component_output",
|
||||
"validate_structured_output",
|
||||
"detect_terminal_capabilities",
|
||||
"select_materializer",
|
||||
"strip_terminal_escapes",
|
||||
]
|
||||
|
||||
@@ -217,7 +217,9 @@ def _check_node(node: Any, prefix: str) -> list[str]:
|
||||
if not type_missing and dtype is not None and dtype not in _VALID_DECISION_TYPES:
|
||||
errors.append(f"{prefix}.type: unexpected {dtype!r}")
|
||||
seq = node.get("sequence")
|
||||
if not ("sequence" in set(node.keys()) or seq is None) and not _is_valid_sequence(seq):
|
||||
if (
|
||||
not ("sequence" in set(node.keys()) or seq is None)
|
||||
) and not _is_valid_sequence(seq):
|
||||
pass # Missing already reported above
|
||||
elif not type_missing or "sequence" not in missing:
|
||||
seq_val = node.get("sequence")
|
||||
@@ -231,11 +233,17 @@ def _check_node(node: Any, prefix: str) -> list[str]:
|
||||
children = node.get("children")
|
||||
c_miss = "children" in missing or children is None
|
||||
if not c_miss and not isinstance(children, list):
|
||||
errors.append(f"{prefix}.children: expected list, got {type(children).__name__}")
|
||||
children_type = type(children).__name__
|
||||
errors.append(f"{prefix}.children: expected list, got {children_type}")
|
||||
return errors
|
||||
|
||||
|
||||
def _validate_children(nodes: list[dict[str, Any]], parent_path: str, check_ordering: bool, errors: list[str]) -> None:
|
||||
def _validate_children(
|
||||
nodes: list[dict[str, Any]],
|
||||
parent_path: str,
|
||||
check_ordering: bool,
|
||||
errors: list[str],
|
||||
) -> None:
|
||||
"""Recursively validate children of plan tree nodes."""
|
||||
for idx, node in enumerate(nodes):
|
||||
if not isinstance(node, dict):
|
||||
@@ -257,7 +265,9 @@ def _validate_children(nodes: list[dict[str, Any]], parent_path: str, check_orde
|
||||
for idx, node in enumerate(nodes):
|
||||
ch = node.get("children")
|
||||
if isinstance(ch, list) and ch:
|
||||
_validate_children(ch, _path(parent_path, f"[{idx}].children"), check_ordering, errors)
|
||||
_validate_children(
|
||||
ch, _path(parent_path, f"[{idx}].children"), check_ordering, errors,
|
||||
)
|
||||
|
||||
|
||||
# --- Decision dict validator ---
|
||||
@@ -266,7 +276,12 @@ def _validate_children(nodes: list[dict[str, Any]], parent_path: str, check_orde
|
||||
def validate_decision_dict(data: Any) -> OutputValidationResult:
|
||||
"""Validate a decision CLI dict."""
|
||||
if not isinstance(data, dict):
|
||||
return OutputValidationResult(valid=False, message="Decision output must be a dict", errors=[f"Expected dict, got {type(data).__name__}"], schema_name="decision_cli_dict")
|
||||
return OutputValidationResult(
|
||||
valid=False,
|
||||
message="Decision output must be a dict",
|
||||
errors=[f"Expected dict, got {type(data).__name__}"],
|
||||
schema_name="decision_cli_dict",
|
||||
)
|
||||
|
||||
missing = sorted(DECISION_CLI_KEYS - set(data.keys()))
|
||||
errors: list[str] = []
|
||||
@@ -291,7 +306,8 @@ def validate_decision_dict(data: Any) -> OutputValidationResult:
|
||||
if not _is_valid_sequence(seq):
|
||||
errors.append("sequence: expected non-negative int")
|
||||
|
||||
for key, check in [("question", str), ("chosen", str)]:
|
||||
_STR = str
|
||||
for key, _check_type in [("question", _STR), ("chosen", _STR)]:
|
||||
val = data.get(key)
|
||||
if not isinstance(val, (str, type(None))) and val is not None:
|
||||
errors.append(f"{key}: expected string or null")
|
||||
@@ -329,7 +345,12 @@ def validate_decision_dict(data: Any) -> OutputValidationResult:
|
||||
def validate_structured_output(data: Any) -> OutputValidationResult:
|
||||
"""Validate a structured session output envelope."""
|
||||
if not isinstance(data, dict):
|
||||
return OutputValidationResult(valid=False, message="Structured output must be a dict", errors=[f"Expected dict, got {type(data).__name__}"], schema_name="structured_output_root")
|
||||
return OutputValidationResult(
|
||||
valid=False,
|
||||
message="Structured output must be a dict",
|
||||
errors=[f"Expected dict, got {type(data).__name__}"],
|
||||
schema_name="structured_output_root",
|
||||
)
|
||||
|
||||
missing = sorted(STRUCTURED_OUTPUT_KEYS - set(data.keys()))
|
||||
errors: list[str] = []
|
||||
@@ -385,7 +406,9 @@ def validate_structured_output(data: Any) -> OutputValidationResult:
|
||||
# --- Unified validator ---
|
||||
|
||||
|
||||
def validate_structured_component_output(data: Any, target_type: str) -> OutputValidationResult:
|
||||
def validate_structured_component_output(
|
||||
data: Any, target_type: str,
|
||||
) -> OutputValidationResult:
|
||||
"""Validate structured output for a given target type."""
|
||||
if target_type == "plan_tree":
|
||||
return validate_plan_tree(data)
|
||||
|
||||
Reference in New Issue
Block a user