From 31f8ad458957e2642eefc30e69230ecb47c7ac36 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 6 Nov 2026 09:16:53 +0000 Subject: [PATCH 1/3] fix(reporting): give exact LLM setup fixes and count named Tier 1 checks When only the LLM stage of a check could not run, what to fix now prints the export lines for the missing provider or key, the scanners row keeps the scanner version, and the summary counts the named checks plus sub-checks instead of validators. Signed-off-by: Christopher Kevin --- CHANGELOG.md | 10 +++ src/skillevaluator/reporting/console_ui.py | 65 +++++++++++--- tests/reporting/test_tier3_validate_cases.py | 92 +++++++++++++++++++- tests/test_skip_checks.py | 3 +- 4 files changed, 157 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c01638e3..20126eee8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,16 @@ All notable changes to SkillEvaluator are documented in this file. - When CI redaction masks a credential inside a reported PII value, remove the finding's digest as well. +### Fixed + +- `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`). The summary row now counts the named checks shown above it, plus + their sub-checks (`9/9 checks passed (24 sub-checks)`), instead of + validators (`11/11 passed`). + ## 0.8.0 - 2026-11-05 ### Added diff --git a/src/skillevaluator/reporting/console_ui.py b/src/skillevaluator/reporting/console_ui.py index 61f00bd17..5462fc9fa 100644 --- a/src/skillevaluator/reporting/console_ui.py +++ b/src/skillevaluator/reporting/console_ui.py @@ -813,7 +813,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] @@ -1037,7 +1038,6 @@ def summarize_tier1(results: list[ValidationResult], lineup: list[str] | None = section with each check's final state (failed checks in red). """ 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)] incomplete = [r for r in failed if r.is_incomplete] broken = [r for r in failed if not r.is_incomplete] @@ -1054,13 +1054,26 @@ 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 the named checks the lineup shows, not validators: code-integrity alone is three. + def check_of(r: ValidationResult) -> str: + return _check_key(r.validator_name) or _short_name(r.validator_name) + + ran = [r for r in results if not _is_user_skipped(r)] + checks = set(map(check_of, ran)) + broken_checks = set(map(check_of, broken)) + incomplete_checks = set(map(check_of, incomplete)) - broken_checks + skipped_checks = set(map(check_of, user_skipped)) - checks + passed_checks = len(checks) - len(broken_checks) - len(incomplete_checks) + checks_segments: list[tuple[str, str]] = [(f"{passed_checks}/{len(checks)} checks passed", TEXT)] + if sub_checks := sum(r.summary.checks_performed for r in ran): + checks_segments.append((f" ({sub_checks} sub-checks)", MUTED)) + if broken_checks: + checks_segments += [(" · ", FAINT), (f"{len(broken_checks)} failed", f"bold {RED}")] + if incomplete_checks: + checks_segments += [(" · ", FAINT), (f"{len(incomplete_checks)} didn't run", f"bold {RED}")] + if skipped_checks: + checks_segments += [(" · ", FAINT), (f"{len(skipped_checks)} 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)) @@ -1095,8 +1108,10 @@ def summarize_tier1(results: list[ValidationResult], lineup: list[str] | None = grade, score = quality rows.append(TierRow("quality", [(grade, f"bold {GREEN}"), (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) @@ -1141,6 +1156,34 @@ 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.""" + scans = result.incomplete_scans + return bool(scans) and all(s.endswith("-llm") or s.startswith("llm-") for s in scans) + + +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.""" + from skillevaluator.provider_config import resolve_llm_provider + + 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 + ) + try: + resolve_llm_provider() + except ValueError as exc: + reason, *setup = str(exc).splitlines() or [""] + exports = [line.strip().removeprefix("export ") for line in setup if line.strip().startswith("export ")] + problem = f"{checks} LLM review didn't run: {reason.rstrip('.')}" + action = f"export {' '.join(exports)}" if exports else "set up an LLM provider and key, then rerun" + else: + problem = f"{checks} LLM review didn't run: the LLM provider call failed" + action = "check the key and model with: skillevaluator doctor --tier 2 --verify-models" + return FixItem("setup", problem, [action, f"or rerun without {flags or '--llm'}"]) + + 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 15f891541..91926e6f7 100644 --- a/tests/reporting/test_tier3_validate_cases.py +++ b/tests/reporting/test_tier3_validate_cases.py @@ -5,6 +5,8 @@ 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 @@ -107,7 +109,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" @@ -212,3 +214,91 @@ def test_setup_fix_names_failed_skillspector_setup(): "or install it yourself: uv tool install skillspector.whl", "or skip it: --skip security", ] + + +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_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_named_checks_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 "1/3 checks passed (13 sub-checks) · 1 failed · 1 didn't run" in _text(rows) diff --git a/tests/test_skip_checks.py b/tests/test_skip_checks.py index 1a12457f4..854d99e1f 100644 --- a/tests/test_skip_checks.py +++ b/tests/test_skip_checks.py @@ -46,7 +46,8 @@ 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 From 319647f042d5caf46cdfd2d24cd1671b1c5227b1 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Thu, 12 Nov 2026 22:23:28 -0800 Subject: [PATCH 2/3] fix(reporting): route Tier 1 setup advice and counts by what actually ran A missing SkillSpector or rejected baseline under --llm records skillspector-llm before any scan runs, so it was treated as an LLM-only failure and asked for a provider instead of the scanner. Treat the stage as LLM-only only when the static scan recorded its version. Also: - name SKILLSPECTOR_PROVIDER's own key when it picks an adapter directly, instead of advising on the public provider - give export lines for OPENAI_API_KEY / SKILL_EVAL_LLM_API_KEY when both are unset - count a --skip inside a check that still ran (secrets in code-integrity) as skipped - after --fail-fast stops the run, count the lineup checks it never reached as not run, so the denominator matches the ticker - keep the changelog entry under the existing Fixed heading Signed-off-by: Christopher Kevin --- CHANGELOG.md | 13 ++- src/skillevaluator/cli.py | 4 +- src/skillevaluator/reporting/console_ui.py | 87 +++++++++++++--- tests/reporting/test_tier3_validate_cases.py | 103 +++++++++++++++++++ tests/test_skip_checks.py | 17 +++ 5 files changed, 204 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cbf5a6cf..04c2f5640 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -141,15 +141,18 @@ All notable changes to SkillEvaluator are documented in this file. `Use HTTP POST to create an item.` in a here-document or an unpiped `echo` still does not warn. -### Fixed - - `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`). The summary row now counts the named checks shown above it, plus - their sub-checks (`9/9 checks passed (24 sub-checks)`), instead of - validators (`11/11 passed`). + 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 counts the named checks shown above it, plus their sub-checks + (`9/9 checks passed (24 sub-checks)`), instead of validators (`11/11 + passed`). After `--fail-fast` stops the run, the checks it never reached + count as `not run`, and `--skip secrets` inside a check that still ran + counts as skipped. ## 0.8.0 - 2026-11-05 diff --git a/src/skillevaluator/cli.py b/src/skillevaluator/cli.py index 622940959..845bc7f79 100644 --- a/src/skillevaluator/cli.py +++ b/src/skillevaluator/cli.py @@ -2383,7 +2383,9 @@ def _on_check(name: str) -> None: tier1_raw_failed = any(not r.passed for r in results) if quiet: apply_policy(results, policy) - tier1_ok, tier1_rows = summarize_tier1(results, lineup=check_lineup) + tier1_ok, tier1_rows = summarize_tier1( + results, lineup=check_lineup, stopped_early=fail_fast and not continue_on_failure and tier1_raw_failed + ) view.tier_done(0, failed=not tier1_ok, rows=tier1_rows) tier1_gate_results = list(results) tier2_gate_results: list[ValidationResult] = [] diff --git a/src/skillevaluator/reporting/console_ui.py b/src/skillevaluator/reporting/console_ui.py index 0b820d0dd..5ec2a793c 100644 --- a/src/skillevaluator/reporting/console_ui.py +++ b/src/skillevaluator/reporting/console_ui.py @@ -1125,11 +1125,15 @@ def _quality_stats(results: list[ValidationResult]) -> tuple[str, float] | None: return None -def summarize_tier1(results: list[ValidationResult], lineup: list[str] | None = None) -> tuple[bool, list[TierRow]]: +def summarize_tier1( + results: list[ValidationResult], lineup: list[str] | None = None, *, stopped_early: bool = False +) -> tuple[bool, list[TierRow]]: """Build the Tier 1 section rows from its validator results. When *lineup* is given, the per-check ticker stays in the completed - section with each check's final state (failed checks in red). + section with each check's final state (failed checks in red). When + *stopped_early* is set (``--fail-fast`` ended the run at its first failure), + the lineup checks that have no result are counted as not run. """ user_skipped = [r for r in results if _is_user_skipped(r)] failed = [r for r in results if not r.passed and not _is_skipped(r)] @@ -1157,15 +1161,21 @@ def check_of(r: ValidationResult) -> str: checks = set(map(check_of, ran)) broken_checks = set(map(check_of, broken)) incomplete_checks = set(map(check_of, incomplete)) - broken_checks - skipped_checks = set(map(check_of, user_skipped)) - checks + # A --skip inside a check that still ran (secrets within code-integrity) counts under its own name. + skipped_checks = {_skip_name(r.validator_name) if check_of(r) in checks else check_of(r) for r in user_skipped} + # --fail-fast returns before the later checks produce a result; the lineup above still lists them. + seen = set(map(check_of, results)) + not_run = [name for name in lineup or () if name not in seen] if stopped_early else [] passed_checks = len(checks) - len(broken_checks) - len(incomplete_checks) - checks_segments: list[tuple[str, str]] = [(f"{passed_checks}/{len(checks)} checks passed", TEXT)] + checks_segments: list[tuple[str, str]] = [(f"{passed_checks}/{len(checks) + len(not_run)} checks passed", TEXT)] if sub_checks := sum(r.summary.checks_performed for r in ran): checks_segments.append((f" ({sub_checks} sub-checks)", MUTED)) if broken_checks: checks_segments += [(" · ", FAINT), (f"{len(broken_checks)} failed", f"bold {RED}")] if incomplete_checks: checks_segments += [(" · ", FAINT), (f"{len(incomplete_checks)} didn't run", f"bold {RED}")] + if not_run: + checks_segments += [(" · ", FAINT), (f"{len(not_run)} not run", MUTED)] if skipped_checks: checks_segments += [(" · ", FAINT), (f"{len(skipped_checks)} skipped", MUTED)] if warnings: @@ -1257,31 +1267,80 @@ def _setup_fix(results: list[ValidationResult]) -> FixItem: def _only_llm_stages_missing(result: ValidationResult) -> bool: - """True when the check itself ran and only its ``--llm`` / ``--llm-verify`` stage did not.""" + """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 - return bool(scans) and all(s.endswith("-llm") or s.startswith("llm-") for s in 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.""" - from skillevaluator.provider_config import resolve_llm_provider - 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 ")] - problem = f"{checks} LLM review didn't run: {reason.rstrip('.')}" - action = f"export {' '.join(exports)}" if exports else "set up an LLM provider and key, then rerun" - else: - problem = f"{checks} LLM review didn't run: the LLM provider call failed" - action = "check the key and model with: skillevaluator doctor --tier 2 --verify-models" - return FixItem("setup", problem, [action, f"or rerun without {flags or '--llm'}"]) + # 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: diff --git a/tests/reporting/test_tier3_validate_cases.py b/tests/reporting/test_tier3_validate_cases.py index 4e7c030eb..b6d640eba 100644 --- a/tests/reporting/test_tier3_validate_cases.py +++ b/tests/reporting/test_tier3_validate_cases.py @@ -11,6 +11,11 @@ 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) @@ -279,6 +284,90 @@ def test_llm_fix_points_at_doctor_when_the_provider_call_fails(monkeypatch): ] +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 + + +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_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 @@ -302,3 +391,17 @@ def test_tier1_summary_counts_named_checks_and_their_sub_checks(): results.append(secrets) _ok, rows = summarize_tier1(results, lineup=["code-integrity", "schema", "security"]) assert "1/3 checks passed (13 sub-checks) · 1 failed · 1 didn't run" in _text(rows) + + +def test_tier1_summary_after_fail_fast_counts_the_checks_that_never_ran(): + from skillevaluator.models.result import ValidationResult + from skillevaluator.reporting.console_ui import summarize_tier1 + + lineup = ["schema", "version", "security", "pii", "license", "code-integrity", "unicode", "quality", "lint"] + schema = ValidationResult(validator_name="Schema & Repository Governance", passed=False) + schema.errors.append("Author not specified in metadata") + _ok, rows = summarize_tier1([schema], lineup=lineup, stopped_early=True) + assert "0/9 checks passed · 1 failed · 8 not run" in _text(rows) + # A full run, or a call without a lineup, still counts only the checks that returned results. + assert "0/1 checks passed · 1 failed" in _text(summarize_tier1([schema], lineup=lineup)[1]) + assert "0/1 checks passed · 1 failed" in _text(summarize_tier1([schema], stopped_early=True)[1]) diff --git a/tests/test_skip_checks.py b/tests/test_skip_checks.py index 854d99e1f..7cd2922b8 100644 --- a/tests/test_skip_checks.py +++ b/tests/test_skip_checks.py @@ -51,6 +51,23 @@ def test_skipped_check_is_visible_in_tier1_summary(): assert "unicode with --skip, not checked" in text +def test_skip_inside_a_check_that_ran_still_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 "1/1 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") From 10ee7f42d6348fb41e9cb75f746a8fb40cfa940a Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 13 Nov 2026 00:43:47 -0800 Subject: [PATCH 3/3] fix(reporting): count Tier 1 validators in the summary row, like the verdict line The summary row counted named checks while the verdict line under it (and the HTML Tier 1 chip) count validators, so a plain run showed 9/9 above and "11 of 11" below. With --skip and --fail-fast the two also drifted, and the named-check count needed special cases for partial skips and for checks that are not applicable. Count validators with the verdict's own classification instead, keep the sub-check count, and drop the lineup-based not-run count. The ticker above still lists the named checks. Add tests that compare the row with TierPresentation, and real-validator tests for --llm without a usable SkillSpector (not installed, bad path override, bad baseline) and for SKILLSPECTOR_PROVIDER=bedrock. Signed-off-by: Christopher Kevin --- CHANGELOG.md | 9 +- src/skillevaluator/cli.py | 4 +- src/skillevaluator/reporting/console_ui.py | 48 +++----- tests/reporting/test_tier3_validate_cases.py | 116 +++++++++++++++++-- tests/test_skip_checks.py | 4 +- 5 files changed, 130 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5182e8bc8..f2e0ff719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -439,11 +439,10 @@ All notable changes to SkillEvaluator are documented in this file. 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 counts the named checks shown above it, plus their sub-checks - (`9/9 checks passed (24 sub-checks)`), instead of validators (`11/11 - passed`). After `--fail-fast` stops the run, the checks it never reached - count as `not run`, and `--skip secrets` inside a check that still ran - counts as skipped. + 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`. - `skillevaluator view` no longer asks the LLM again when it regenerates a missing `report.html` for a Tier 3 run that saved its report feedback in diff --git a/src/skillevaluator/cli.py b/src/skillevaluator/cli.py index 2450f466a..3727f80b0 100644 --- a/src/skillevaluator/cli.py +++ b/src/skillevaluator/cli.py @@ -2561,9 +2561,7 @@ def _on_check(name: str) -> None: tier1_raw_failed = any(not r.passed for r in results) if quiet: apply_policy(results, policy) - tier1_ok, tier1_rows = summarize_tier1( - results, lineup=check_lineup, stopped_early=fail_fast and not continue_on_failure and tier1_raw_failed - ) + tier1_ok, tier1_rows = summarize_tier1(results, lineup=check_lineup) view.tier_done(0, failed=not tier1_ok, rows=tier1_rows) tier1_gate_results = list(results) tier2_gate_results: list[ValidationResult] = [] diff --git a/src/skillevaluator/reporting/console_ui.py b/src/skillevaluator/reporting/console_ui.py index 9b4c8c24c..8da81655a 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, @@ -1132,15 +1134,11 @@ def _quality_stats(results: list[ValidationResult]) -> tuple[str, float] | None: return None -def summarize_tier1( - results: list[ValidationResult], lineup: list[str] | None = None, *, stopped_early: bool = False -) -> tuple[bool, list[TierRow]]: +def summarize_tier1(results: list[ValidationResult], lineup: list[str] | None = None) -> tuple[bool, list[TierRow]]: """Build the Tier 1 section rows from its validator results. When *lineup* is given, the per-check ticker stays in the completed - section with each check's final state (failed checks in red). When - *stopped_early* is set (``--fail-fast`` ended the run at its first failure), - the lineup checks that have no result are counted as not run. + section with each check's final state (failed checks in red). """ # A check recorded as not applicable did not run: it is neither a pass nor # a failure, so it is listed on its own row and left out of the counts. @@ -1165,31 +1163,21 @@ def summarize_tier1( rows.append(final_check_ticker_row(lineup, results)) rows += scanners - # Count the named checks the lineup shows, not validators: code-integrity alone is three. - def check_of(r: ValidationResult) -> str: - return _check_key(r.validator_name) or _short_name(r.validator_name) - - ran = [r for r in results if not _is_user_skipped(r)] - checks = set(map(check_of, ran)) - broken_checks = set(map(check_of, broken)) - incomplete_checks = set(map(check_of, incomplete)) - broken_checks - # A --skip inside a check that still ran (secrets within code-integrity) counts under its own name. - skipped_checks = {_skip_name(r.validator_name) if check_of(r) in checks else check_of(r) for r in user_skipped} - # --fail-fast returns before the later checks produce a result; the lineup above still lists them. - seen = set(map(check_of, results)) - not_run = [name for name in lineup or () if name not in seen] if stopped_early else [] - passed_checks = len(checks) - len(broken_checks) - len(incomplete_checks) - checks_segments: list[tuple[str, str]] = [(f"{passed_checks}/{len(checks) + len(not_run)} checks passed", TEXT)] - if sub_checks := sum(r.summary.checks_performed for r in ran): + # 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 broken_checks: - checks_segments += [(" · ", FAINT), (f"{len(broken_checks)} failed", f"bold {RED}")] - if incomplete_checks: - checks_segments += [(" · ", FAINT), (f"{len(incomplete_checks)} didn't run", f"bold {RED}")] - if not_run: - checks_segments += [(" · ", FAINT), (f"{len(not_run)} not run", MUTED)] - if skipped_checks: - checks_segments += [(" · ", FAINT), (f"{len(skipped_checks)} skipped", 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)) diff --git a/tests/reporting/test_tier3_validate_cases.py b/tests/reporting/test_tier3_validate_cases.py index b6d640eba..f80b76c7b 100644 --- a/tests/reporting/test_tier3_validate_cases.py +++ b/tests/reporting/test_tier3_validate_cases.py @@ -302,6 +302,49 @@ def test_missing_skillspector_with_llm_still_gets_the_install_fix(): 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 @@ -345,6 +388,33 @@ def test_llm_fix_follows_a_skillspector_adapter_chosen_directly(monkeypatch): 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 @@ -378,7 +448,7 @@ def test_scanners_row_keeps_the_version_when_only_the_llm_stage_failed(): assert not _only_llm_stages_missing(security) -def test_tier1_summary_counts_named_checks_and_their_sub_checks(): +def test_tier1_summary_counts_validators_and_their_sub_checks(): from skillevaluator.models.result import ValidationResult from skillevaluator.reporting.console_ui import summarize_tier1 @@ -390,18 +460,42 @@ def test_tier1_summary_counts_named_checks_and_their_sub_checks(): secrets.errors.append("leaked token") results.append(secrets) _ok, rows = summarize_tier1(results, lineup=["code-integrity", "schema", "security"]) - assert "1/3 checks passed (13 sub-checks) · 1 failed · 1 didn't run" in _text(rows) + assert "2/4 checks passed (13 sub-checks) · 1 failed · 1 didn't run" in _text(rows) -def test_tier1_summary_after_fail_fast_counts_the_checks_that_never_ran(): +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 - lineup = ["schema", "version", "security", "pii", "license", "code-integrity", "unicode", "quality", "lint"] - schema = ValidationResult(validator_name="Schema & Repository Governance", passed=False) - schema.errors.append("Author not specified in metadata") - _ok, rows = summarize_tier1([schema], lineup=lineup, stopped_early=True) - assert "0/9 checks passed · 1 failed · 8 not run" in _text(rows) - # A full run, or a call without a lineup, still counts only the checks that returned results. - assert "0/1 checks passed · 1 failed" in _text(summarize_tier1([schema], lineup=lineup)[1]) - assert "0/1 checks passed · 1 failed" in _text(summarize_tier1([schema], stopped_early=True)[1]) + 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 7cd2922b8..4ccf0c6c1 100644 --- a/tests/test_skip_checks.py +++ b/tests/test_skip_checks.py @@ -51,7 +51,7 @@ def test_skipped_check_is_visible_in_tier1_summary(): assert "unicode with --skip, not checked" in text -def test_skip_inside_a_check_that_ran_still_counts_as_skipped(): +def test_skip_secrets_inside_code_integrity_counts_as_skipped(): from skillevaluator.models.result import ValidationResult results = [ @@ -64,7 +64,7 @@ def test_skip_inside_a_check_that_ran_still_counts_as_skipped(): ] _ok, rows = summarize_tier1(results, lineup=["code-integrity"]) text = "\n".join("".join(seg for seg, _style in row.segments) for row in rows) - assert "1/1 checks passed · 1 skipped" in text + assert "2/2 checks passed · 1 skipped" in text assert "secrets with --skip, not checked" in text