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 @@ -473,6 +473,10 @@ All notable changes to SkillEvaluator are documented in this file.

- 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.
- The calculator reference skill converts negative values (`-40 celsius to fahrenheit`) and takes negative
percentages, and no longer answers `10% of 50 + 5` with `Result: 5` by ignoring the rest of the input.
Such input, and a malformed number like `1.2.3 km to miles`, now gets the usual `Error:` line instead
of a wrong result or a traceback.
- Direct Tier 1 validates the target, selected checks and LLM configuration before
preparing scanners, so configuration errors do not trigger downloads or stdout noise.
- Documentation-only CI follows imports through collected test modules and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def _eval(node):
return _eval(tree)


# A signed decimal number: "-40", "+2", "3.5", ".5" or "5.".
NUMBER = r"[-+]?(?:\d+(?:\.\d*)?|\.\d+)"

CONVERSIONS = {
("celsius", "fahrenheit"): lambda c: c * 9 / 5 + 32,
("fahrenheit", "celsius"): lambda f: (f - 32) * 5 / 9,
Expand All @@ -58,8 +61,8 @@ def _eval(node):


def try_conversion(expr: str) -> str | None:
m = re.match(
r"([\d.]+)\s+(\w+)\s+to\s+(\w+)",
m = re.fullmatch(
rf"({NUMBER})\s+(\w+)\s+to\s+(\w+)",
expr.strip(),
re.IGNORECASE,
)
Expand All @@ -76,7 +79,7 @@ def try_conversion(expr: str) -> str | None:


def try_percentage(expr: str) -> str | None:
m = re.match(r"([\d.]+)%\s+of\s+([\d.]+)", expr.strip(), re.IGNORECASE)
m = re.fullmatch(rf"({NUMBER})%\s+of\s+({NUMBER})", expr.strip(), re.IGNORECASE)
if not m:
return None
pct = float(m.group(1))
Expand Down
55 changes: 55 additions & 0 deletions tests/test_reference_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Behavior tests for the packaged calculator reference script."""

from __future__ import annotations

import subprocess
import sys
from pathlib import Path

import pytest

CALC = Path(__file__).resolve().parents[1] / "src/skillevaluator/tier3/reference_skills/calculator/scripts/calc.py"


def _calc(expression: str) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[sys.executable, str(CALC), expression],
check=False,
capture_output=True,
text=True,
)


@pytest.mark.parametrize(
("expression", "expected"),
[
("-40 celsius to fahrenheit", "-40 celsius = -40 fahrenheit"),
("-4 fahrenheit to celsius", "-4 fahrenheit = -20 celsius"),
(".5 kg to lbs", "0.5 kg = 1.102 lbs"),
("-10% of 50", "Result: -5"),
("12.5% of -80", "Result: -10"),
("100 celsius to fahrenheit", "100 celsius = 212 fahrenheit"),
("15% of 200", "Result: 30"),
],
)
def test_conversions_and_percentages_accept_signed_numbers(expression: str, expected: str) -> None:
result = _calc(expression)

assert result.returncode == 0, result.stderr
assert result.stdout.strip() == expected


@pytest.mark.parametrize(
"expression",
["10% of 50 + 5", "5 km to miles please", "1.2.3 km to miles"],
)
def test_input_beyond_a_conversion_or_percentage_is_rejected(expression: str) -> None:
result = _calc(expression)

assert result.returncode == 1
assert result.stdout == ""
assert result.stderr.startswith("Error: ")
assert "Traceback" not in result.stderr
Loading