Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ All notable changes to SkillEvaluator are documented in this file.

### Fixed

- Script lint measures control-flow nesting without recursively walking expression
nodes, so valid long operator or attribute chains no longer abort advisory
checks for that script and subsequent files.

- GitLab JUnit collection includes nested skill folders in catalog reports.
- API caller now percent-encodes scalar OpenAPI path values as individual segments and rejects `.` and `..` values with a JSON input error.
- Direct Tier 1 validates the target, selected checks and LLM configuration before
Expand Down
12 changes: 5 additions & 7 deletions src/skillevaluator/validators/script_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@
def _calculate_nesting_depth(tree: ast.AST) -> int:
"""Calculate maximum nesting depth of control flow statements."""
max_depth = 0

def _walk(node: ast.AST, depth: int) -> None:
nonlocal max_depth
pending = [(tree, 0)]
while pending:
node, depth = pending.pop()
if isinstance(node, _NESTING_NODES):
depth += 1
max_depth = max(max_depth, depth)
for child in ast.iter_child_nodes(node):
_walk(child, depth)

_walk(tree, 0)
# Expression depth can exceed Python's call stack even when control flow is shallow.
pending.extend((child, depth) for child in ast.iter_child_nodes(node))
return max_depth


Expand Down
54 changes: 53 additions & 1 deletion tests/validators/test_script_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

"""Tests for ScriptLintValidator -- AST-based advisory lint checks."""

import ast
from pathlib import Path

import pytest

from skillevaluator.models.result import Severity, ValidationResult
from skillevaluator.validators.script_lint import ScriptLintValidator
from skillevaluator.validators.script_lint import ScriptLintValidator, _calculate_nesting_depth


@pytest.fixture
Expand Down Expand Up @@ -230,3 +231,54 @@ def test_validator_name(self):
v = ScriptLintValidator()
assert "Lint" in v.name
assert "Advisory" in v.name


@pytest.mark.parametrize("directory", ["scripts", "tools"])
@pytest.mark.parametrize(
"expression",
[" + ".join(["value"] * 1500), "value" + ".next" * 1500],
ids=["binary-expression", "attribute-chain"],
)
def test_deep_expression_does_not_abort_other_script_checks(tmp_path, directory, expression):
(tmp_path / "SKILL.md").write_text("# Example\n", encoding="utf-8")
scripts = tmp_path / directory
scripts.mkdir()
(scripts / "first.py").write_text(
"#!/usr/bin/env python3\nimport argparse\ndef calculate(value):\n if value:\n return "
+ expression
+ "\n return 42\n",
encoding="utf-8",
)
(scripts / "second.py").write_text("print('example')\n", encoding="utf-8")

result = ScriptLintValidator().validate(tmp_path)

findings = {(Path(f.file_path).name, f.check_name) for f in result.findings}
assert ("first.py", "magic_numbers") in findings
assert ("second.py", "flat_script") in findings
assert ("second.py", "missing_shebang") in findings
assert not any(f.check_name == "deep_nesting" for f in result.findings)
assert result.passed


def test_deep_expression_keeps_actual_control_flow_depth():
source = "def calculate(value):\n"
for depth in range(1, 8):
source += " " * depth + "if value:\n"
source += " " * 8 + "return " + " + ".join(["value"] * 1500) + "\n"

assert _calculate_nesting_depth(ast.parse(source)) == 7


@pytest.mark.parametrize(
("source", "expected"),
[
("value = 42\n", 0),
("if first:\n if second:\n pass\nif third:\n pass\n", 2),
("try:\n with context():\n pass\nexcept Exception:\n while condition:\n pass\n", 2),
("async def work():\n async for item in items:\n async with item:\n pass\n", 2),
],
ids=["flat", "siblings", "try-branches", "async"],
)
def test_control_flow_depth_keeps_existing_branch_semantics(source, expected):
assert _calculate_nesting_depth(ast.parse(source)) == expected
Loading