From 62a666961bc3204a8ace39adf456f33fa6b81e36 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Thu, 12 Nov 2026 22:37:34 -0800 Subject: [PATCH 1/2] fix(tier1): keep SkillSpector reports with unmatched missing references INCOMPLETE The missing-reference rule only read the lines of reference_resolution ledger rows. A "missing" entry in analysis_completeness.references with no ledger row, and a report that flags a list as truncated (a key ending in _truncated), skipped that line check, so the scan passed with a warning even when the unread line names a file left out of the scanned copy, such as versions/install.sh. After the ledger rows are accepted, the rule now also returns None, which keeps the scan INCOMPLETE, when any _truncated key of analysis_completeness is set, when a "missing" reference is not on the line of an accepted row, or when any reference is "ambiguous". The truncation check shares one helper with the provider-outage rule. Signed-off-by: Christopher Kevin --- CHANGELOG.md | 10 ++ src/skillevaluator/validators/security.py | 74 +++++++++-- tests/validators/test_security.py | 150 ++++++++++++++++++++++ 3 files changed, 222 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b9d774a4..b60dfdc73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -726,6 +726,16 @@ All notable changes to SkillEvaluator are documented in this file. without its findings, as with `complete_with_caveats` from an earlier release. +- A Tier 1 security scan keeps a SkillSpector `partial` or + `complete_with_caveats` report `INCOMPLETE`, instead of passing with the + missing-reference warning above, when the report lists a `missing` reference + on a line that has no ledger row, lists an `ambiguous` reference on any + line, or flags one of its lists as truncated with a key that ends in + `_truncated`, such as `ledger_exceptions_truncated`. Only the line of a + ledger row is checked for a file left out of the scanned copy, so the line of + a reference without a row, or one that a truncated list left out, could name + a file such as `versions/install.sh` and pass unnoticed. + - A PII finding no longer keeps its `evidence_sha256` after CI redaction masks a credential inside the value the finding reports. In 0.8.0 the finding kept the digest of the unmasked value, so anyone holding the redacted report could diff --git a/src/skillevaluator/validators/security.py b/src/skillevaluator/validators/security.py index 6e6f5d0b1..10aa3f529 100644 --- a/src/skillevaluator/validators/security.py +++ b/src/skillevaluator/validators/security.py @@ -516,6 +516,18 @@ def _skillspector_provider_retry_row(row: object) -> bool: ) +def _skillspector_flags_truncation(container: Mapping[str, object]) -> bool: + """Return whether a report object has a ``*_truncated`` key that is neither ``false`` nor ``null``. + + SkillSpector flags a list it cut short this way, as in + ``ledger_exceptions_truncated``, and what it left out may be a different gap. + """ + return any( + isinstance(key, str) and key.endswith("_truncated") and value is not False and value is not None + for key, value in container.items() + ) + + def _skillspector_provider_retries_exhausted(data: object) -> bool: """Return whether a failed LLM-stage report shows only an LLM provider outage. @@ -547,10 +559,7 @@ def _skillspector_provider_retries_exhausted(data: object) -> bool: if any(container.get(key) for key in _SKILLSPECTOR_REPORT_FAILURE_MARKERS): return False # A truncated list may hide a different cause. - if any( - isinstance(key, str) and key.endswith("_truncated") and value is not False and value is not None - for key, value in container.items() - ): + if _skillspector_flags_truncation(container): return False rows = completeness.get("ledger_exceptions") @@ -2264,6 +2273,32 @@ def _skillspector_missing_reference_warning(rows: list[Mapping[str, object]]) -> ) +def _skillspector_missing_references_have_rows(references: list, rows: list[Mapping[str, object]]) -> bool: + """Whether each ``missing`` entry of *references* is on the line of a ledger row in *rows*, and none is ``ambiguous``. + + Only the line of a row is read for the names it holds + (:func:`_skillspector_reference_line_avoids`), so a ``missing`` entry on + any other line, which SkillSpector reported without a row, would never be. + """ + lines = {(row.get("path"), row.get("start_line")) for row in rows} + for reference in references: + if not isinstance(reference, dict): + continue + status = reference.get("status") + if status == "ambiguous": + return False + if status == "missing": + path, line = reference.get("source_path"), reference.get("line") + if ( + not isinstance(path, str) + or isinstance(line, bool) + or not isinstance(line, int) + or (path, line) not in lines + ): + return False + return True + + def _skillspector_missing_reference_notes( ledger_exceptions: list[dict], analyzer_statuses: list[dict], @@ -2273,6 +2308,7 @@ def _skillspector_missing_reference_notes( components: object, scanned_root: Path | None, *, + completeness: Mapping[str, object], references: object, skillspector_version: tuple[int, int, int] | None, reference_root: Path | None, @@ -2291,14 +2327,20 @@ def _skillspector_missing_reference_notes( skill that SkillSpector did not inspect (:func:`_skillspector_unscanned_names`, :func:`_skillspector_reference_line_avoids`, with one work budget for all of the report's lines), such as a link or a file in an artifact directory - left out of a staged scan, and there is no fatal scope exclusion. Any - other ledger rows must be referenced images that - :func:`_skillspector_passive_raster_note` accepts, which then accounts for - the counts, analyzers and limitations, and its note follows. Without them, - no file is partially or entirely uninspected, no finding was filtered out, - there is no limitation, every analyzer is ``completed``, ``not_applicable`` - or ``disabled``, and each universal analyzer completed one work item per - component. Anything else keeps the scan INCOMPLETE. + left out of a staged scan, and there is no fatal scope exclusion. Those rows + must also account for the report's ``references``: each ``missing`` entry is + on the line of one of them + (:func:`_skillspector_missing_references_have_rows`), none is ``ambiguous``, + and no ``*_truncated`` key of *completeness* (the report's + ``analysis_completeness``) is set, because a list that SkillSpector cut + short may hide a line that nothing here reads. Any other ledger rows must be + referenced images that :func:`_skillspector_passive_raster_note` accepts, + which then accounts for the counts, analyzers and limitations, and its note + follows. Without them, no file is partially or entirely uninspected, no + finding was filtered out, there is no limitation, every analyzer is + ``completed``, ``not_applicable`` or ``disabled``, and each universal + analyzer completed one work item per component. Anything else keeps the + scan INCOMPLETE. *reference_root* is the root of the artifact that the scan belongs to, and the gap is accepted only when it is *scanned_root* itself. Another @@ -2327,6 +2369,10 @@ def _skillspector_missing_reference_notes( row, skillspector_version, references ): return None + if _skillspector_flags_truncation(completeness) or not _skillspector_missing_references_have_rows( + references, reference_rows + ): + return None notes = [_skillspector_missing_reference_warning(reference_rows)] if other_rows: @@ -2413,6 +2459,7 @@ def _skillspector_reference_caveat_notes( components: object, scanned_root: Path | None, *, + completeness: Mapping[str, object], references: object, skillspector_version: tuple[int, int, int] | None, reference_root: Path | None, @@ -2438,6 +2485,7 @@ def _skillspector_reference_caveat_notes( scope_exclusions, components, scanned_root, + completeness=completeness, references=references, skillspector_version=skillspector_version, reference_root=reference_root, @@ -3650,6 +3698,7 @@ def _validate_skillspector_report( analysis_completeness.get("scope_exclusions", []), data.get("components"), scanned_root, + completeness=analysis_completeness, references=analysis_completeness.get("references"), skillspector_version=skillspector_version, reference_root=reference_root, @@ -3682,6 +3731,7 @@ def _validate_skillspector_report( analysis_completeness.get("scope_exclusions", []), data.get("components"), scanned_root, + completeness=analysis_completeness, references=analysis_completeness.get("references"), skillspector_version=skillspector_version, reference_root=reference_root, diff --git a/tests/validators/test_security.py b/tests/validators/test_security.py index 3a5d8640b..6d9e01736 100644 --- a/tests/validators/test_security.py +++ b/tests/validators/test_security.py @@ -9189,6 +9189,7 @@ def _missing_reference_notes(payload: dict, scanned_root: Path | None, **options completeness["scope_exclusions"], payload["components"], scanned_root, + completeness=completeness, references=completeness.get("references"), skillspector_version=version, **options, @@ -9521,6 +9522,154 @@ def test_report_accounting_must_match_a_fully_inspected_bundle(self, tmp_path: P payload["analysis_completeness"]["analyzer_statuses"].remove(universal) assert _missing_reference_notes(payload, skill) is None + @staticmethod + def _install_script_case(tmp_path: Path, version: str) -> tuple[Path, dict, str]: + """The notes writer with a second line that runs ``versions/install.sh``, which the scanned copy leaves out. + + The report is the capture for the first line only, with the line count of ``SKILL.md`` raised to match. + """ + line = "Also run `versions/install.sh` and write the log to `output/log.txt`." + skill = _write_skill( + tmp_path / "notes-writer", + { + **_NOTES_WRITER_FILES, + "SKILL.md": f"{_NOTES_WRITER_FILES['SKILL.md']}\n{line}\n", + "versions/install.sh": "#!/bin/sh\necho ready\n", + }, + ) + payload = _reference_report(version) + next(component for component in payload["components"] if component["path"] == "SKILL.md")["lines"] += 2 + return skill, payload, line + + @staticmethod + def _assert_refused(result: ValidationResult, version: str) -> None: + row = "SKILL.md:10 [reference_resolution; reference_missing]" + assert result.is_incomplete + assert result.incomplete_scans == ["skillspector"] + assert result.errors == [ + _caveat_error(row) + if version == "2.13.4" + else f"skillspector JSON field 'analysis_completeness' reports incomplete analysis (status 'partial'): " + f"{row}; security scan did not complete" + ] + assert not result.warnings + assert "skillspector_reference_caveats" not in result.metadata + + @pytest.mark.parametrize("version", ["2.12.0", "2.13.3", "2.13.4"]) + @patch("skillevaluator.validators.security.Tools") + def test_line_naming_a_file_left_out_of_the_scan_stays_incomplete_with_a_row( + self, mock_tools, tmp_path: Path, version: str + ) -> None: + """The second line of ``_install_script_case`` is refused once SkillSpector gives it a row.""" + skill, payload, line = self._install_script_case(tmp_path, version) + completeness = payload["analysis_completeness"] + completeness["ledger_exceptions"].append( + {**completeness["ledger_exceptions"][0], "start_line": 12, "end_line": 12} + ) + completeness["references"].append( + { + "source_path": "SKILL.md", + "line": 12, + "column": 11, + "evidence": line, + "target_path": None, + "status": "missing", + "disposition": "partial", + "reference_kind": "quoted_or_code", + } + ) + + result = _validate_skillspector_payload(mock_tools, skill, payload) + + assert mock_tools.skillspector.run.call_args.args[0][1] != str(skill.resolve()) + assert result.incomplete_scans == ["skillspector"] + assert not result.warnings + + @pytest.mark.parametrize("status", ["missing", "ambiguous"]) + @pytest.mark.parametrize("version", ["2.12.0", "2.13.3", "2.13.4"]) + @patch("skillevaluator.validators.security.Tools") + def test_reference_without_a_ledger_row_stays_incomplete( + self, mock_tools, tmp_path: Path, version: str, status: str + ) -> None: + """Nothing reads the line of a reference that has no row, so it could name a file the scan left out.""" + skill, payload, line = self._install_script_case(tmp_path, version) + payload["analysis_completeness"]["references"].append( + { + "source_path": "SKILL.md", + "line": 12, + "column": 11, + "evidence": line, + "target_path": None, + "status": status, + "disposition": "partial", + "reference_kind": "quoted_or_code", + } + ) + + result = _validate_skillspector_payload(mock_tools, skill, payload) + + self._assert_refused(result, version) + + @pytest.mark.parametrize("flag", ["ledger_exceptions_truncated", "references_truncated"]) + @pytest.mark.parametrize("version", ["2.12.0", "2.13.3", "2.13.4"]) + @patch("skillevaluator.validators.security.Tools") + def test_truncated_report_stays_incomplete(self, mock_tools, tmp_path: Path, version: str, flag: str) -> None: + """A list SkillSpector cut short may leave out the line that names a file the scan left out.""" + skill, payload, _line = self._install_script_case(tmp_path, version) + payload["analysis_completeness"][flag] = True + + result = _validate_skillspector_payload(mock_tools, skill, payload) + + self._assert_refused(result, version) + + @pytest.mark.parametrize("value", [False, None]) + @pytest.mark.parametrize("flag", ["ledger_exceptions_truncated", "references_truncated"]) + @pytest.mark.parametrize("version", ["2.12.0", "2.13.3", "2.13.4"]) + @patch("skillevaluator.validators.security.Tools") + def test_truncation_flag_that_is_not_set_does_not_block( + self, mock_tools, tmp_path: Path, version: str, flag: str, value: object + ) -> None: + skill = _write_skill(tmp_path / "notes-writer", _NOTES_WRITER_FILES) + payload = _reference_report(version) + payload["analysis_completeness"][flag] = value + + result = _validate_skillspector_payload(mock_tools, skill, payload) + + assert result.passed + assert result.incomplete_scans == [] + assert len(result.warnings) == 1 + + def test_every_missing_reference_needs_a_row_on_its_line_and_no_list_is_truncated(self, tmp_path: Path) -> None: + skill = _write_skill(tmp_path / "notes-writer", _NOTES_WRITER_FILES) + missing = {"source_path": "SKILL.md", "line": 8, "status": "missing"} + evidence = "Write the summary to `output/notes.md` and keep it short." + + def refused(*extra: object, **flags: object) -> bool: + payload = _reference_report("2.13.3") + payload["analysis_completeness"]["references"].extend(extra) + payload["analysis_completeness"].update(flags) + return _missing_reference_notes(payload, skill) is None + + assert not refused() + # Another reference on the line of the row needs no row of its own; a resolved or rejected one never does. + assert not refused({**missing, "line": 10, "evidence": evidence}) + assert not refused({**missing, "status": "resolved"}, {**missing, "line": 3, "status": "rejected"}) + # A missing reference on another line or in another file has no row, and nothing else reads its line. + assert refused(missing) + assert refused({**missing, "source_path": "scripts/summarize.py", "line": 10}) + assert refused({**missing, "source_path": None}) + for line in (None, True, "10", 10.0, [10], {"line": 10}): + assert refused({**missing, "line": line}), line + assert refused({**missing, "source_path": ["SKILL.md"], "line": 10}) + # No reference elsewhere may be ambiguous either. + assert refused({**missing, "status": "ambiguous"}) + assert refused({**missing, "line": 10, "status": "ambiguous"}) + for flag in ("ledger_exceptions_truncated", "references_truncated", "scope_exclusions_truncated"): + for value in (True, 1, "yes", ["x"]): + assert refused(**{flag: value}), (flag, value) + for value in (False, None): + assert not refused(**{flag: value}), (flag, value) + def test_pre_2_12_unresolved_row_needs_a_missing_reference_on_its_line(self) -> None: row = _reference_report("2.11.2")["analysis_completeness"]["ledger_exceptions"][0] missing = {"source_path": "SKILL.md", "line": 10, "status": "missing"} @@ -10992,6 +11141,7 @@ def notes(rows: list[dict]) -> list[str] | None: completeness["scope_exclusions"], payload["components"], skill, + completeness=completeness, references=completeness["references"], skillspector_version=(2, 13, 4), reference_root=skill, From 2ee2820f9e939b0b1b0b58fbdedb520f3a6fb244 Mon Sep 17 00:00:00 2001 From: Christopher Kevin Date: Fri, 13 Nov 2026 00:25:12 -0800 Subject: [PATCH 2/2] fix(tier1): keep image-only SkillSpector reports INCOMPLETE when a reference has no row A partial report whose only ledger rows were referenced images skipped the missing-reference checks, so a `missing` or `ambiguous` entry in `references` with no row, or a list flagged as truncated, still passed with only the image warning. Refuse that case the same way as a report with reference rows. The image-only test case now drops the missing reference together with its row, as SkillSpector does, and new cases cover an unmatched missing reference, an ambiguous one and a truncated list. Signed-off-by: Christopher Kevin --- CHANGELOG.md | 10 ++++--- docs/tier1-validation.mdx | 3 +- src/skillevaluator/validators/security.py | 35 +++++++++++++++++----- tests/validators/test_security.py | 36 +++++++++++++++++++++-- 4 files changed, 69 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b60dfdc73..91e1fbeee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -731,10 +731,12 @@ All notable changes to SkillEvaluator are documented in this file. missing-reference warning above, when the report lists a `missing` reference on a line that has no ledger row, lists an `ambiguous` reference on any line, or flags one of its lists as truncated with a key that ends in - `_truncated`, such as `ledger_exceptions_truncated`. Only the line of a - ledger row is checked for a file left out of the scanned copy, so the line of - a reference without a row, or one that a truncated list left out, could name - a file such as `versions/install.sh` and pass unnoticed. + `_truncated`, such as `ledger_exceptions_truncated`. A `partial` report whose + only listed gap is a referenced image no longer passes with the image + warning alone in those cases either. Only the line of a ledger row is checked + for a file left out of the scanned copy, so the line of a reference without a + row, or one that a truncated list left out, could name a file such as + `versions/install.sh` and pass unnoticed. - A PII finding no longer keeps its `evidence_sha256` after CI redaction masks a credential inside the value the finding reports. In 0.8.0 the finding kept diff --git a/docs/tier1-validation.mdx b/docs/tier1-validation.mdx index 18ba3c6c7..723aec8bc 100644 --- a/docs/tier1-validation.mdx +++ b/docs/tier1-validation.mdx @@ -219,6 +219,7 @@ For `validate`, the default set is `schema`, `version`, `security`, `pii`, `lice - It is a nonfatal `reference_resolution` row for one line of a file that the report lists once as a component and that is a regular, single-link file of at most 1,000,000 bytes inside the skill, not reached through a symlink. - The report's `references` list records a `missing` reference on that line, quotes part of the line, and records no `ambiguous` reference there. + - The report's `references` list records no `missing` reference on a line without a row of its own and no `ambiguous` reference on any line, and the report flags no list as truncated (a key of `analysis_completeness` that ends in `_truncated`). Only the line of a row is read, and a list that SkillSpector cut short may hide one. - The line, at most 10,000 characters long, names nothing in the skill that SkillSpector did not inspect: a symlink, a file the report does not list, a directory that holds no listed file, such as `versions/`, `node_modules/` or `evals/results/`, which SkillEvaluator leaves out of the scanned copy, anything inside such a directory, or a directory that holds any of these, even beside listed files. A `.git` directory counts by its own name, by its Git hooks other than `*.sample` templates, and by every other entry in it that is not part of Git's own layout, such as a script placed there, with everything inside that entry. Git's own files, such as `HEAD`, `config`, `index`, `packed-refs` or `ORIG_HEAD`, and what its `objects`, `refs`, `logs` and `info` directories hold, such as branch names, do not count. Names are compared without regard to case or Unicode normalization, in the line as written and as a Markdown renderer or a reader of file paths may read it: with backslash escapes of ASCII punctuation (such as `node\_modules`) removed, HTML character references (such as `v`) resolved and percent-escapes decoded, up to three of these steps in any order. A skill with more than 50,000 files and directories, or nested more than 64 directories deep, is not checked, and its scan stays `INCOMPLETE`. The work of checking a report's lines is also bounded: when it would take longer, such as for many long lines beside thousands of files left out of the scan, the scan stays `INCOMPLETE`. - A word in the line that a shell, cmd.exe, PowerShell or Windows would expand or unquote is read as a pattern, and none of those names may match it. In the pattern, quotes and escapes are removed, a group such as `(v)` stands for what it holds, also right after `]` as in `[v](e)rsions`, each expansion, set of alternatives, extended glob or numeric range may stand for any text, and each bracket expression for any one character. The word is read the way POSIX shells read globs, brace and parameter expansions, `$(...)` and quotes (`v*/*.sh`, `vers?ons`, `v[e]rsions`, `v{e,x}rsions`, `$DIR/run.sh`, `ver""sions`); the way zsh reads groups (`(v)ersions`, `(v|x)ersions`), numeric ranges (`run<1-9>.sh`), the `EXTENDED_GLOB` operators `^`, `#` and `~` (`ver^x`, `verr#sions`, and `v*~x`, read as `v*`), where `x#` as a whole part, such as `C#`, matches only names made of `x`, and globbing flags such as `(#a2)` or `(#c1)`, which make the whole word stand for any text (`(#a2)virsions/x`); the way bash and ksh read extended globs (`@(v)ersions`, `!(x)`); the way cmd.exe reads the `^` escape (`ver^sions`), variables (`%DIR%`, `!DIR!`) and batch parameters (`%1`, `%~dp0`); the way PowerShell reads backtick escapes; with `\` as a directory separator (`v*\i*.sh`); and with a Windows short (8.3) name or a Samba mangled name, a path part with text after a `~` such as `NODE_M~1/BOOTST~1.SH`, standing for any name that holds the part's first character, such as any name with an `n` for `NODE_M~1`. So `3~5` is read as written, as `3`, and as any name with a `3`. A span between backticks is read as Markdown code, as written and with its backticks removed, not as a command, so a plural written as `` `topic`s `` is read as `topics`. A word made only of `*`, such as a list marker, is not read this way. Prose with this syntax is read the same way: a price such as `$5`, a list such as `{a,b}`, `%APPDATA%` or a lone `^` stands for any text, so a line with one stays `INCOMPLETE` whenever anything is left out of the scan, and `approx~10` stays `INCOMPLETE` when a name left out holds an `a`. - The check reads names that are written in the reported line, in the spellings above. It does not read other lines and does not run commands, so it does not detect a name on another line, such as `DIR=node_modules` set on one line and used as `sh $DIR/run.sh` on the next, or a name that a command prints or builds, such as `printf` output in backticks, a list piped into `xargs sh`, `find -exec`, or a PowerShell string joined with `+`. It is meant to keep an instruction that names a left-out file `INCOMPLETE`, not to catch a skill written to hide one. Without this check, such a skill passes whenever SkillSpector reports no missing reference in it; with it, the skill also passes when every line SkillSpector reports is another missing reference, such as `output/notes.md`. SkillSpector's own analyzers, not this check, assess the instructions it scanned. @@ -226,7 +227,7 @@ For `validate`, the default set is `schema`, `version`, `security`, `pii`, `lice - Tier 3 output in its default location, `/evals/results`, is left out of the scanned copy too, so it counts as not inspected. The rest of `evals/`, such as `evals/evals.json` and input fixtures in `evals/files`, is scanned. After a Tier 3 run, a line that names `results`, a file the run leaves there, such as `report.html` or `summary.json`, or, when the run used `--harbor-keep-jobs`, any bundled file (the kept Harbor tasks hold a copy of the skill) keeps the scan `INCOMPLETE`, although the same line passed before the run. Writing Tier 3 results outside the skill, with `--results-dir` or `SKILLEVALUATOR_RESULTS_DIR`, keeps a run from changing the result. - The scan covers the whole target. When the target is a folder or a plugin that holds skills, such as `skillevaluator security-scan path/to/skills/`, `skillevaluator validate path/to/skills/` (which checks each skill as its own job) or `validate` on a plugin, each skill in it is scanned on its own, and a line may name a file elsewhere in the target that the skill's scan did not inspect, so those skills' missing references keep their scans `INCOMPLETE`. - Any other gap must be a referenced image that SkillEvaluator accepts as described above, and the scan then carries both warnings. Without such images, the report must also show no partially or entirely uninspected file, no limitation and no fatal scope exclusion, and every analyzer must have completed or be not applicable or disabled. In either case the report must count as many findings after filtering as before it. The warning names the file and line of up to three of the references; it does not quote the referenced path. Files not in the scan, including any outside the scanned path, are not inspected. + Any other gap must be a referenced image that SkillEvaluator accepts as described above, and the scan then carries both warnings. Without such images, the report must also show no partially or entirely uninspected file, no limitation and no fatal scope exclusion, and every analyzer must have completed or be not applicable or disabled. In either case the report must count as many findings after filtering as before it, and the references and truncation conditions above hold even when a referenced image is its only listed gap. The warning names the file and line of up to three of the references; it does not quote the referenced path. Files not in the scan, including any outside the scanned path, are not inspected. SkillSpector v2.12.0 to v2.13.3 report these references as `reference_missing`, and v2.10 and v2.11 as `reference_unresolved`, which SkillEvaluator accepts under the same conditions. A v2.13.3 report whose only gaps are such references is also accepted from the report alone as a missing-reference caveat: an INFO finding that keeps SkillSpector's `partial` status and is recorded as `skillspector_reference_caveats` in the JSON report. It replaces the warning above, and whenever the scan has a known target, as through `validate`, `tier1` or `security-scan`, it is accepted only when the conditions above hold too. A reference that matches several bundled files (`reference_unresolved` from v2.12.0, `ambiguous` in the `references` list before it) still leaves the scan `INCOMPLETE`. diff --git a/src/skillevaluator/validators/security.py b/src/skillevaluator/validators/security.py index 10aa3f529..701d4fb7c 100644 --- a/src/skillevaluator/validators/security.py +++ b/src/skillevaluator/validators/security.py @@ -2299,6 +2299,21 @@ def _skillspector_missing_references_have_rows(references: list, rows: list[Mapp return True +def _skillspector_reference_evidence_unmatched(completeness: Mapping[str, object]) -> bool: + """Whether a report whose ledger has no missing-reference row lists a gap that nothing reads. + + SkillSpector gives every ``missing`` or ``ambiguous`` reference a ledger + row, so with none, such an entry in the ``references`` of *completeness* + names a line that no check reads, and a ``*_truncated`` flag means a row + may have been cut off. The report is then not accepted on the strength of + its other gaps, such as a referenced image. + """ + references = completeness.get("references") + return _skillspector_flags_truncation(completeness) or ( + isinstance(references, list) and not _skillspector_missing_references_have_rows(references, []) + ) + + def _skillspector_missing_reference_notes( ledger_exceptions: list[dict], analyzer_statuses: list[dict], @@ -3745,14 +3760,18 @@ def _validate_skillspector_report( # incomplete. accepted_reference_caveats = None if gap_notes is None: - raster_note = _skillspector_passive_raster_note( - ledger_exceptions, - analyzer_statuses, - counts, - limitations, - analysis_completeness.get("scope_exclusions", []), - data.get("components"), - scanned_root, + raster_note = ( + None + if _skillspector_reference_evidence_unmatched(analysis_completeness) + else _skillspector_passive_raster_note( + ledger_exceptions, + analyzer_statuses, + counts, + limitations, + analysis_completeness.get("scope_exclusions", []), + data.get("components"), + scanned_root, + ) ) gap_notes = None if raster_note is None else [raster_note] if accepted_reference_caveats is not None: diff --git a/tests/validators/test_security.py b/tests/validators/test_security.py index 6d9e01736..347abc066 100644 --- a/tests/validators/test_security.py +++ b/tests/validators/test_security.py @@ -36,6 +36,7 @@ _skillspector_name_keys, _skillspector_reference_caveat_error, _skillspector_reference_caveat_notes, + _skillspector_reference_evidence_unmatched, _skillspector_reference_line_avoids, _skillspector_reference_row_is_advisory, _skillspector_report_path_is_bundled_file, @@ -9670,6 +9671,19 @@ def refused(*extra: object, **flags: object) -> bool: for value in (False, None): assert not refused(**{flag: value}), (flag, value) + def test_reference_evidence_without_a_row_is_unmatched(self) -> None: + resolved = {"source_path": "SKILL.md", "line": 8, "status": "resolved"} + missing = {"source_path": "SKILL.md", "line": 10, "status": "missing"} + + assert not _skillspector_reference_evidence_unmatched({}) + assert not _skillspector_reference_evidence_unmatched({"references": None}) + assert not _skillspector_reference_evidence_unmatched({"references": [resolved, {"status": "rejected"}, "x"]}) + assert not _skillspector_reference_evidence_unmatched({"references": [resolved], "references_truncated": False}) + assert _skillspector_reference_evidence_unmatched({"references": [resolved, missing]}) + assert _skillspector_reference_evidence_unmatched({"references": [{**missing, "status": "ambiguous"}]}) + assert _skillspector_reference_evidence_unmatched({"references": [], "ledger_exceptions_truncated": True}) + assert _skillspector_reference_evidence_unmatched({"ledger_exceptions_truncated": 1}) + def test_pre_2_12_unresolved_row_needs_a_missing_reference_on_its_line(self) -> None: row = _reference_report("2.11.2")["analysis_completeness"]["ledger_exceptions"][0] missing = {"source_path": "SKILL.md", "line": 10, "status": "missing"} @@ -10642,7 +10656,17 @@ def test_one_budget_serves_every_line_of_a_report( ] @pytest.mark.parametrize( - "case", ["both", "image-only", "not-an-image", "ambiguous-reference", "line-names-a-left-out-file"] + "case", + [ + "both", + "image-only", + "image-only-with-an-unmatched-missing-reference", + "image-only-with-an-ambiguous-reference", + "image-only-with-a-truncated-list", + "not-an-image", + "ambiguous-reference", + "line-names-a-left-out-file", + ], ) @patch("skillevaluator.validators.security.Tools") def test_missing_reference_with_a_referenced_image(self, mock_tools, tmp_path: Path, case: str) -> None: @@ -10658,8 +10682,16 @@ def test_missing_reference_with_a_referenced_image(self, mock_tools, tmp_path: P (skill / "assets" / "logo.png").write_bytes(b"not an image" if case == "not-an-image" else _png_bytes()) payload = _reference_report("2.13.3", "image-and-missing") completeness = payload["analysis_completeness"] - if case == "image-only": + if case.startswith("image-only"): completeness["ledger_exceptions"] = completeness["ledger_exceptions"][1:] + if case == "image-only": + # SkillSpector records every missing reference with a row, so no row means no such reference. + completeness["references"] = [r for r in completeness["references"] if r["status"] != "missing"] + elif case.endswith("ambiguous-reference"): + completeness["references"][1]["status"] = "ambiguous" + elif case.endswith("truncated-list"): + completeness["references"] = [r for r in completeness["references"] if r["status"] != "missing"] + completeness["ledger_exceptions_truncated"] = True elif case == "ambiguous-reference": completeness["ledger_exceptions"][0]["reason_code"] = "reference_unresolved"