diff --git a/CHANGELOG.md b/CHANGELOG.md index cd95119ae..3154bceb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,18 @@ All notable changes to SkillEvaluator are documented in this file. instead of the bare command. Searches inside a wrapper (`bash -c 'grep SKILL config.json'`) are still not counted. +- `validate` Tier 1 output: when only the `--llm` / `--llm-verify` stage + can't run, `what to fix` gives the exact `export` lines for the missing + provider or key instead of a scanner install or `--skip security`, and the + scanners row keeps the scanner version (`SkillSpector 2.12.0, LLM didn't + run`). A missing SkillSpector or a rejected baseline under `--llm` still + gets the scanner fix, and a `SKILLSPECTOR_PROVIDER` adapter set directly + gets advice for its own key instead of the public provider's. The summary + row now also gives the sub-check count (`9/10 checks passed (22 + sub-checks)`). It counts validators, as the `Tier 1: 9 of 10 checks passed` + verdict line under it does, so the two agree, including with `--skip` and + `--fail-fast`. + ## 0.9.0 - 2026-11-13 ### Fixed diff --git a/src/skillevaluator/reporting/console_ui.py b/src/skillevaluator/reporting/console_ui.py index 909b3dd89..3ddcadefd 100644 --- a/src/skillevaluator/reporting/console_ui.py +++ b/src/skillevaluator/reporting/console_ui.py @@ -34,6 +34,7 @@ import threading import time import unicodedata +from collections import Counter from dataclasses import dataclass, field from pathlib import Path from typing import TYPE_CHECKING, TextIO @@ -51,6 +52,7 @@ source_validation_errors, source_validation_preview, ) +from skillevaluator.reporting.presentation import result_execution_status from skillevaluator.reporting.terminal_styles import ( AMBER, BRIGHT, @@ -910,7 +912,8 @@ def _scanners_row(results: list[ValidationResult]) -> list[TierRow]: states[scanner] = (version, MUTED) for scan in r.incomplete_scans: if (scanner := scan.removesuffix("-llm")) in _SCANNER_NAMES: - states[scanner] = ("didn't run", f"bold {RED}") + version = r.scanners.get(scanner) if scan != scanner else None + states[scanner] = (f"{version}, LLM didn't run" if version else "didn't run", f"bold {RED}") segments: list[tuple[str, str]] = [] for scanner in [name for name in _SCANNER_NAMES if name in states]: state, style = states[scanner] @@ -1146,7 +1149,6 @@ def summarize_tier1(results: list[ValidationResult], lineup: list[str] | None = results = [r for r in results if not _is_not_applicable(r)] user_skipped = [r for r in results if _is_user_skipped(r)] - total = len(results) - len(user_skipped) failed = [r for r in results if not r.passed and not _is_skipped(r)] # A blocking finding or failed gate outranks an incomplete scan, as on every other surface. incomplete = [r for r in failed if result_status(r) is Status.INCOMPLETE] @@ -1164,13 +1166,22 @@ def summarize_tier1(results: list[ValidationResult], lineup: list[str] | None = if lineup: rows.append(final_check_ticker_row(lineup, results)) rows += scanners - checks_segments: list[tuple[str, str]] = [(f"{total - len(failed)}/{total} passed", TEXT)] - if broken: - checks_segments += [(" · ", FAINT), (f"{len(broken)} failed", f"bold {RED}")] - if incomplete: - checks_segments += [(" · ", FAINT), (f"{len(incomplete)} didn't run", f"bold {RED}")] - if user_skipped: - checks_segments += [(" · ", FAINT), (f"{len(user_skipped)} skipped", MUTED)] + + # Count validators with the verdict line's own classification (TierPresentation), so the two agree. + outcome = {id(r): result_execution_status(r) for r in results} + count = Counter(outcome.values()) + executed = count["pass"] + count["fail"] + count["incomplete"] + checks_segments: list[tuple[str, str]] = [(f"{count['pass']}/{executed} checks passed", TEXT)] + if sub_checks := sum( + r.summary.checks_performed for r in results if outcome[id(r)] in {"pass", "fail", "incomplete"} + ): + checks_segments.append((f" ({sub_checks} sub-checks)", MUTED)) + if count["fail"]: + checks_segments += [(" · ", FAINT), (f"{count['fail']} failed", f"bold {RED}")] + if count["incomplete"]: + checks_segments += [(" · ", FAINT), (f"{count['incomplete']} didn't run", f"bold {RED}")] + if count["skipped"]: + checks_segments += [(" · ", FAINT), (f"{count['skipped']} skipped", MUTED)] if warnings: checks_segments += [(" · ", FAINT), (f"{warnings} warning{'s' if warnings != 1 else ''}", MUTED)] rows.append(TierRow("summary" if lineup else "checks", checks_segments)) @@ -1218,8 +1229,10 @@ def summarize_tier1(results: list[ValidationResult], lineup: list[str] | None = TierRow("quality", [(grade, f"bold {grade_style(grade, status=status)}"), (f" {score:.1f} / 100", TEXT)]) ) items = [_tier1_fix(r) for r in broken] - if incomplete: - items.append(_setup_fix(incomplete)) + if setup := [r for r in incomplete if not _only_llm_stages_missing(r)]: + items.append(_setup_fix(setup)) + if llm := [r for r in incomplete if _only_llm_stages_missing(r)]: + items.append(_llm_fix(llm)) return not failed, rows + fix_section_rows(items) @@ -1264,6 +1277,83 @@ def _setup_fix(results: list[ValidationResult]) -> FixItem: return FixItem("setup", problem, [*actions, f"or skip it: --skip {skip}"]) +def _only_llm_stages_missing(result: ValidationResult) -> bool: + """True when the check itself ran and only its ``--llm`` / ``--llm-verify`` stage did not. + + ``skillspector-llm`` is also recorded when SkillSpector is missing or its baseline is + rejected, before any scan runs; only a recorded SkillSpector version shows its static + scan completed. + """ + scans = result.incomplete_scans + if not scans or not all(s.endswith("-llm") or s.startswith("llm-") for s in scans): + return False + return "skillspector-llm" not in scans or "skillspector" in result.scanners + + +def _llm_fix(results: list[ValidationResult]) -> FixItem: + """One item for checks whose LLM stage could not run: a missing key or a failed provider call.""" + checks = ", ".join(dict.fromkeys(_short_name(r.validator_name) for r in results)) + scans = {s for r in results for s in r.incomplete_scans} + flags = " / ".join( + f for f, on in (("--llm", "skillspector-llm" in scans), ("--llm-verify", "llm-verification" in scans)) if on + ) + # SkillSpector reads its own provider settings when SKILLSPECTOR_PROVIDER names an adapter, so the + # public provider matters only for the other stages. + direct = _skillspector_adapter_fix() if "skillspector-llm" in scans else None + parts = [direct] if direct else [] + if direct is None or "llm-verification" in scans: + reason, fixes = _public_provider_fix() + parts.append((f"--llm-verify: {reason}" if direct else reason, fixes)) + reasons = "; ".join(reason for reason, _ in parts) + actions = [action for _, fixes in parts for action in fixes] + return FixItem( + "setup", f"{checks} LLM review didn't run: {reasons}", [*actions, f"or rerun without {flags or '--llm'}"] + ) + + +def _public_provider_fix() -> tuple[str, list[str]]: + """The problem and actions for the provider behind ``SKILL_EVAL_LLM_*``: a missing key or a failed call.""" + from skillevaluator.provider_config import resolve_llm_provider + + try: + resolve_llm_provider() + except ValueError as exc: + reason, *setup = str(exc).splitlines() or [""] + reason = reason.rstrip(".") + exports = [line.strip().removeprefix("export ") for line in setup if line.strip().startswith("export ")] + # Some errors name the accepted keys without an export line ("OPENAI_API_KEY or SKILL_EVAL_LLM_API_KEY ..."). + keys = list(dict.fromkeys(re.findall(r"\b[A-Z][A-Z0-9_]*_KEY\b", reason))) + if exports: + return reason, [f"export {' '.join(exports)}"] + if keys: + return reason, [f"{'or ' if i else ''}export {key}='your-api-key'" for i, key in enumerate(keys)] + return reason, ["set up an LLM provider and key, then rerun"] + return "the LLM provider call failed", [ + "check the key and model with: skillevaluator doctor --tier 2 --verify-models" + ] + + +def _skillspector_adapter_fix() -> tuple[str, list[str]] | None: + """The problem and actions for a failed SkillSpector LLM stage when ``SKILLSPECTOR_PROVIDER`` names its adapter. + + ``None`` when it does not: SkillSpector then runs on the provider bridged from ``SKILL_EVAL_LLM_*``. + """ + from skillevaluator.validators.security import _SKILLSPECTOR_EXPLICIT_PROVIDER_ENV + + adapter = os.environ.get("SKILLSPECTOR_PROVIDER", "").strip().lower() + if adapter not in _SKILLSPECTOR_EXPLICIT_PROVIDER_ENV: + return None + key = next( + (name for name in sorted(_SKILLSPECTOR_EXPLICIT_PROVIDER_ENV[adapter]) if name.endswith("_API_KEY")), None + ) + if key is not None and not os.environ.get(key, "").strip(): + return f"{key} is not set for SKILLSPECTOR_PROVIDER={adapter}", [f"export {key}='your-api-key'"] + credentials = key or "your AWS credentials" + return f"SkillSpector's {adapter} provider call failed", [ + f"check {credentials} and SKILLSPECTOR_MODEL for SKILLSPECTOR_PROVIDER={adapter}" + ] + + def _skip_name(validator_name: str) -> str: """The ``--skip`` value that leaves out the check producing *validator_name*.""" if validator_name == "Secrets Detection": diff --git a/tests/reporting/test_tier3_validate_cases.py b/tests/reporting/test_tier3_validate_cases.py index a09db3f2d..4d87f4c56 100644 --- a/tests/reporting/test_tier3_validate_cases.py +++ b/tests/reporting/test_tier3_validate_cases.py @@ -5,10 +5,17 @@ from pathlib import Path from types import SimpleNamespace +import pytest + from skillevaluator.reporting.console_ui import ViewProgressReporter, _fit_row, tier3_case_rows, tier3_fix_rows from skillevaluator.tier3.case_summary import live_case_marks +@pytest.fixture(autouse=True) +def _no_skillspector_provider(monkeypatch): + monkeypatch.delenv("SKILLSPECTOR_PROVIDER", raising=False) + + def _text(rows): return "\n".join(f"{r.label:<12}" + "".join(chunk for chunk, _ in r.segments) for r in rows) @@ -107,7 +114,7 @@ def test_fix_section_for_tier1_and_tier2(): clean = ValidationResult(validator_name="Version Check", passed=True) _ok, rows = summarize_tier1([schema, secrets, clean]) text = _text(rows) - assert "1/3 passed · 1 failed · 1 didn't run" in text + assert "1/3 checks passed · 1 failed · 1 didn't run" in text assert "Author not specified in metadata\n" + " " * 12 + "→ Add 'metadata.author'" in text assert "secrets didn't run: gitleaks not installed\n" + " " * 12 + "→ brew install gitleaks" in text assert [r.label for r in rows if r.glyph in {"1", "2"}][1] == "setup" @@ -158,7 +165,7 @@ def test_failed_hook_gate_with_incomplete_scan_is_listed_as_failed_not_as_setup( ok, rows = summarize_tier1([security], lineup=["security"]) text = _text(rows) assert not ok - assert "0/1 passed · 1 failed" in text + assert "0/1 checks passed · 1 failed" in text assert "1 didn't run" not in text assert f"{'security':<12}{gate}" in text assert not any(r.label == "setup" for r in rows) @@ -271,3 +278,283 @@ def test_live_case_marks_reads_nemo_gym_rollouts(tmp_path): marks, running = live_case_marks(tmp_path, ["codex"], pass_threshold=0.5) assert marks == {"codex": {"with_skill": {"case-1": [PASS, FAIL, ERROR], "case-2": []}}} assert running == set() + + +def _security_without_llm(): + from skillevaluator.models.result import ValidationResult + + security = ValidationResult( + validator_name="Security Scan", + passed=False, + metadata={"incomplete_scans": ["skillspector-llm", "llm-verification"], "scanners": {"skillspector": "2.13.3"}}, + ) + security.errors.append("skillspector-llm failed with unexpected exit code 2: scanner diagnostics were redacted") + return security + + +def test_llm_fix_asks_for_the_key_not_a_scanner_install(monkeypatch): + from skillevaluator import provider_config + from skillevaluator.reporting.console_ui import _llm_fix + + def no_key(): + raise provider_config.ProviderConfigurationError( + "SKILL_EVAL_LLM_API_KEY is required for the selected provider.\n\n" + "Set it in your shell:\n export SKILL_EVAL_LLM_API_KEY='your-api-key'\n" + ) + + monkeypatch.setattr(provider_config, "resolve_llm_provider", no_key) + item = _llm_fix([_security_without_llm()]) + assert item.problem == ( + "security LLM review didn't run: SKILL_EVAL_LLM_API_KEY is required for the selected provider" + ) + assert item.actions == [ + "export SKILL_EVAL_LLM_API_KEY='your-api-key'", + "or rerun without --llm / --llm-verify", + ] + + +def test_llm_fix_without_a_provider_gives_every_export(monkeypatch): + from skillevaluator import provider_config + from skillevaluator.reporting.console_ui import _llm_fix + + monkeypatch.delenv("SKILL_EVAL_LLM_PROVIDER", raising=False) + monkeypatch.delenv("SKILL_EVAL_LLM_API_KEY", raising=False) + for name in ("NVIDIA_API_KEY", "OPENAI_API_KEY", "ANTHROPIC_API_KEY"): + monkeypatch.delenv(name, raising=False) + with pytest.raises(provider_config.ProviderConfigurationError): + provider_config.resolve_llm_provider() + item = _llm_fix([_security_without_llm()]) + assert item.problem == "security LLM review didn't run: No provider is configured" + assert item.actions[0] == "export SKILL_EVAL_LLM_PROVIDER=nv_build NVIDIA_API_KEY='your-api-key'" + + +def test_llm_fix_points_at_doctor_when_the_provider_call_fails(monkeypatch): + from skillevaluator import provider_config + from skillevaluator.reporting.console_ui import _llm_fix + + monkeypatch.setattr(provider_config, "resolve_llm_provider", object) + security = _security_without_llm() + security.metadata["incomplete_scans"] = ["llm-verification"] + item = _llm_fix([security]) + assert item.problem == "security LLM review didn't run: the LLM provider call failed" + assert item.actions == [ + "check the key and model with: skillevaluator doctor --tier 2 --verify-models", + "or rerun without --llm-verify", + ] + + +def test_missing_skillspector_with_llm_still_gets_the_install_fix(): + from skillevaluator.models.result import ValidationResult + from skillevaluator.reporting.console_ui import _only_llm_stages_missing, summarize_tier1 + + security = ValidationResult( + validator_name="Security Scan", passed=False, metadata={"incomplete_scans": ["skillspector-llm"]} + ) + security.add_warning( + "skillspector not installed - skipping security scan. Install with: uv tool install skillspector." + ) + assert not _only_llm_stages_missing(security) + text = _text(summarize_tier1([security])[1]) + assert "security didn't run" in text + assert "→ uv tool install skillspector" in text + assert "→ or skip it: --skip security" in text + assert "LLM review" not in text + + +@pytest.mark.parametrize("nvidia_key", [None, "set-for-the-test"]) +@pytest.mark.parametrize("how", ["not-installed", "bad-path-override", "bad-baseline"]) +def test_llm_scan_that_never_started_gets_the_scanner_fix_not_a_provider_fix(monkeypatch, tmp_path, how, nvidia_key): + """``--llm`` records skillspector-llm before any scan runs; the real validator paths must not read as LLM-only.""" + from skillevaluator.reporting.console_ui import summarize_tier1 + from skillevaluator.utils.tool_runner import Tools + from skillevaluator.validators.security import SecurityValidator + + for name in ("SKILL_EVAL_LLM_PROVIDER", "SKILL_EVAL_LLM_API_KEY", "OPENAI_API_KEY", "ANTHROPIC_API_KEY"): + monkeypatch.delenv(name, raising=False) + monkeypatch.delenv("NVIDIA_API_KEY", raising=False) + if nvidia_key: + monkeypatch.setenv("NVIDIA_API_KEY", nvidia_key) + skill = tmp_path / "demo" + skill.mkdir() + (skill / "SKILL.md").write_text("---\nname: demo\ndescription: A demo skill.\n---\n\nBody.\n", encoding="utf-8") + baseline = None + try: + if how == "bad-path-override": + monkeypatch.setenv("SKILLEVALUATOR_SKILLSPECTOR_PATH", str(tmp_path / "no-such-skillspector")) + Tools.skillspector.refresh() + elif how == "not-installed": + monkeypatch.setattr(Tools.skillspector, "_path", None) + else: + # Installed, but the baseline cannot be parsed, so no scan starts. + monkeypatch.setattr(Tools.skillspector, "_path", "/bin/true") + baseline = tmp_path / "baseline.yaml" + baseline.write_text("rules: [unclosed\n", encoding="utf-8") + result = SecurityValidator(use_llm=True, skillspector_baseline=baseline).validate_security_only(skill) + finally: + monkeypatch.undo() + Tools.skillspector.refresh() + + result.validator_name = "Security Scan" # run_validation names the result this way + assert result.incomplete_scans == ["skillspector-llm"] + assert "skillspector" not in result.scanners + text = _text(summarize_tier1([result])[1]) + assert "security didn't run" in text + assert "→ or skip it: --skip security" in text + for provider_advice in ("LLM review", "No provider is configured", "provider call failed", "doctor --tier 2"): + assert provider_advice not in text + + +def test_llm_fix_with_openai_and_no_key_names_both_accepted_variables(monkeypatch): + from skillevaluator.reporting.console_ui import _llm_fix + + monkeypatch.setenv("SKILL_EVAL_LLM_PROVIDER", "openai") + for name in ("SKILL_EVAL_LLM_API_KEY", "OPENAI_API_KEY"): + monkeypatch.delenv(name, raising=False) + item = _llm_fix([_security_without_llm()]) + assert item.actions == [ + "export OPENAI_API_KEY='your-api-key'", + "or export SKILL_EVAL_LLM_API_KEY='your-api-key'", + "or rerun without --llm / --llm-verify", + ] + + +def test_llm_fix_follows_a_skillspector_adapter_chosen_directly(monkeypatch): + from skillevaluator.reporting.console_ui import _llm_fix + + for name in ("SKILL_EVAL_LLM_PROVIDER", "SKILL_EVAL_LLM_API_KEY", "NVIDIA_API_KEY", "OPENAI_API_KEY"): + monkeypatch.delenv(name, raising=False) + monkeypatch.setenv("SKILLSPECTOR_PROVIDER", "anthropic") + monkeypatch.setenv("ANTHROPIC_API_KEY", "set-for-the-adapter") + security = _security_without_llm() + security.metadata["incomplete_scans"] = ["skillspector-llm"] + item = _llm_fix([security]) + assert item.problem == "security LLM review didn't run: SkillSpector's anthropic provider call failed" + assert item.actions == [ + "check ANTHROPIC_API_KEY and SKILLSPECTOR_MODEL for SKILLSPECTOR_PROVIDER=anthropic", + "or rerun without --llm", + ] + + monkeypatch.delenv("ANTHROPIC_API_KEY") + item = _llm_fix([security]) + assert ( + item.problem + == "security LLM review didn't run: ANTHROPIC_API_KEY is not set for SKILLSPECTOR_PROVIDER=anthropic" + ) + assert item.actions == ["export ANTHROPIC_API_KEY='your-api-key'", "or rerun without --llm"] + + monkeypatch.setenv("SKILLSPECTOR_PROVIDER", "bedrock") + item = _llm_fix([security]) + assert item.actions[0] == "check your AWS credentials and SKILLSPECTOR_MODEL for SKILLSPECTOR_PROVIDER=bedrock" + + +def test_llm_fix_for_bedrock_set_through_skillspector_gives_no_public_provider_advice(monkeypatch): + from skillevaluator.reporting.console_ui import _llm_fix + + for name in ("SKILL_EVAL_LLM_PROVIDER", "SKILL_EVAL_LLM_API_KEY", "NVIDIA_API_KEY", "OPENAI_API_KEY"): + monkeypatch.delenv(name, raising=False) + monkeypatch.setenv("SKILLSPECTOR_PROVIDER", "bedrock") + monkeypatch.setenv("AWS_ACCESS_KEY_ID", "set-for-the-test") + monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "set-for-the-test") + security = _security_without_llm() + security.metadata["incomplete_scans"] = ["skillspector-llm"] + item = _llm_fix([security]) + assert item.problem == "security LLM review didn't run: SkillSpector's bedrock provider call failed" + assert item.actions == [ + "check your AWS credentials and SKILLSPECTOR_MODEL for SKILLSPECTOR_PROVIDER=bedrock", + "or rerun without --llm", + ] + + # With both stages failed, both lines appear: --llm-verify still runs on the public provider. + item = _llm_fix([_security_without_llm()]) + assert item.problem.startswith("security LLM review didn't run: SkillSpector's bedrock provider call failed; ") + assert item.actions == [ + "check your AWS credentials and SKILLSPECTOR_MODEL for SKILLSPECTOR_PROVIDER=bedrock", + "export SKILL_EVAL_LLM_PROVIDER=nv_build NVIDIA_API_KEY='your-api-key'", + "or rerun without --llm / --llm-verify", + ] + + +def test_llm_fix_still_covers_the_public_provider_for_llm_verify_with_a_direct_adapter(monkeypatch): + from skillevaluator.reporting.console_ui import _llm_fix + + for name in ("SKILL_EVAL_LLM_PROVIDER", "SKILL_EVAL_LLM_API_KEY", "NVIDIA_API_KEY", "OPENAI_API_KEY"): + monkeypatch.delenv(name, raising=False) + monkeypatch.setenv("SKILLSPECTOR_PROVIDER", "anthropic") + monkeypatch.delenv("ANTHROPIC_API_KEY", raising=False) + item = _llm_fix([_security_without_llm()]) + assert item.problem == ( + "security LLM review didn't run: ANTHROPIC_API_KEY is not set for SKILLSPECTOR_PROVIDER=anthropic; " + "--llm-verify: No provider is configured" + ) + assert item.actions == [ + "export ANTHROPIC_API_KEY='your-api-key'", + "export SKILL_EVAL_LLM_PROVIDER=nv_build NVIDIA_API_KEY='your-api-key'", + "or rerun without --llm / --llm-verify", + ] + + security = _security_without_llm() + security.metadata["incomplete_scans"] = ["llm-verification"] + assert "SkillSpector" not in _llm_fix([security]).problem + + +def test_scanners_row_keeps_the_version_when_only_the_llm_stage_failed(): + from skillevaluator.reporting.console_ui import _only_llm_stages_missing, _scanners_row + + security = _security_without_llm() + assert _only_llm_stages_missing(security) + assert "SkillSpector 2.13.3, LLM didn't run" in _text(_scanners_row([security])) + security.metadata["incomplete_scans"] = ["skillspector"] + assert not _only_llm_stages_missing(security) + + +def test_tier1_summary_counts_validators_and_their_sub_checks(): + from skillevaluator.models.result import ValidationResult + from skillevaluator.reporting.console_ui import summarize_tier1 + + results = [ValidationResult(validator_name=name, passed=True) for name in ("Code Risk Analysis", "Schema")] + results.append(_security_without_llm()) + for result, performed in zip(results, (2, 10, 1), strict=True): + result.summary.checks_performed = performed + secrets = ValidationResult(validator_name="Secrets Detection", passed=False) + secrets.errors.append("leaked token") + results.append(secrets) + _ok, rows = summarize_tier1(results, lineup=["code-integrity", "schema", "security"]) + assert "2/4 checks passed (13 sub-checks) · 1 failed · 1 didn't run" in _text(rows) + + +def test_tier1_summary_row_agrees_with_the_verdict_line(): + from skillevaluator.models.result import ValidationResult + from skillevaluator.reporting.console_ui import summarize_tier1 + from skillevaluator.reporting.presentation import build_final_render_context + from skillevaluator.tier1.commands import run_validation + + skill = Path(__file__).resolve().parents[2] / "src/skillevaluator/tier3/reference_skills/text-analyzer" + # A pass, a check that is not applicable (no previous version), and a user-skipped check ... + results = run_validation(skill, checks="schema,version,unicode", skip="unicode") + # ... plus a failure and an incomplete scan, so every count has a value. + broken = ValidationResult(validator_name="Secrets Detection", passed=False) + broken.errors.append("leaked token") + results += [broken, _security_without_llm()] + + tier = build_final_render_context(results, requested_tiers=[1]).tiers[1] + assert (tier.passed, tier.failed, tier.incomplete, tier.skipped, tier.not_applicable) == (1, 1, 1, 1, 1) + text = _text(summarize_tier1(results, lineup=["schema", "version", "unicode"])[1]) + assert f"{tier.passed}/{tier.executed} checks passed" in text + assert f"{tier.failed} failed · {tier.incomplete} didn't run · {tier.skipped} skipped" in text + assert tier.summary.startswith(f"{tier.passed} of {tier.executed} checks passed; {tier.failed} failed, ") + + +def test_tier1_summary_after_a_whole_check_skip_counts_its_validators_once_each(): + from skillevaluator.models.result import ValidationResult + from skillevaluator.reporting.console_ui import summarize_tier1 + + def skipped(name): + meta = {"skipped": True, "skipped_by_user": True, "skip_reason": "skipped with --skip"} + return ValidationResult(validator_name=name, metadata=meta) + + results = [ValidationResult(validator_name="Schema & Repository Governance")] + results += [skipped(n) for n in ("Code Risk Analysis", "Secrets Detection", "Code Integrity & Hygiene")] + text = _text(summarize_tier1(results, lineup=["schema", "code-integrity"])[1]) + # The same three validators the verdict line counts and the skipped row names. + assert "1/1 checks passed · 3 skipped" in text + assert "code, secrets, integrity with --skip, not checked" in text diff --git a/tests/test_skip_checks.py b/tests/test_skip_checks.py index 1a12457f4..4ccf0c6c1 100644 --- a/tests/test_skip_checks.py +++ b/tests/test_skip_checks.py @@ -46,10 +46,28 @@ def test_skipped_check_is_visible_in_tier1_summary(): _ok, rows = summarize_tier1(results, lineup=["schema", "unicode"]) text = "\n".join("".join(seg for seg, _style in row.segments) for row in rows) assert "\N{EN DASH} unicode" in text - assert "1/1 passed · 1 skipped" in text + assert "1/1 checks passed" in text + assert " · 1 skipped" in text assert "unicode with --skip, not checked" in text +def test_skip_secrets_inside_code_integrity_counts_as_skipped(): + from skillevaluator.models.result import ValidationResult + + results = [ + ValidationResult(validator_name="Code Risk Analysis"), + ValidationResult( + validator_name="Secrets Detection", + metadata={"skipped": True, "skipped_by_user": True, "skip_reason": "skipped with --skip"}, + ), + ValidationResult(validator_name="Code Integrity & Hygiene"), + ] + _ok, rows = summarize_tier1(results, lineup=["code-integrity"]) + text = "\n".join("".join(seg for seg, _style in row.segments) for row in rows) + assert "2/2 checks passed · 1 skipped" in text + assert "secrets with --skip, not checked" in text + + def test_runs_secrets_scan(): assert runs_secrets_scan(None, None) assert not runs_secrets_scan(None, "secrets")