From 54b749388fc1a0823de15898bec6fc6de4e79ef3 Mon Sep 17 00:00:00 2001 From: YMuskrat <101849520+YMuskrat@users.noreply.github.com> Date: Fri, 6 Nov 2026 01:19:08 +0000 Subject: [PATCH] fix(tier2): retain trailing shell comments in deduplication Signed-off-by: YMuskrat <101849520+YMuskrat@users.noreply.github.com> --- CHANGELOG.md | 4 +++ .../deduplication/utils/chunker.py | 4 ++- .../intra_skill/test_intra_skill_validator.py | 28 +++++++++++++++++++ tests/deduplication/utils/test_chunker.py | 24 ++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a4311dea..def8c1544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -467,6 +467,10 @@ All notable changes to SkillEvaluator are documented in this file. ### Fixed +- Tier 2 includes qualifying shell comment blocks at end of file in context + deduplication. Previously those blocks disappeared unless a blank line or + code followed them, which could hide repeated guidance across shell files. + - Tier 3 behavior-check evidence bundles now count a final answer cut by the final-response section limit as truncated. The omission check compared two renderings that both capped that section (800 characters diff --git a/src/skillevaluator/deduplication/utils/chunker.py b/src/skillevaluator/deduplication/utils/chunker.py index cbdfe5935..b2b64e3d0 100644 --- a/src/skillevaluator/deduplication/utils/chunker.py +++ b/src/skillevaluator/deduplication/utils/chunker.py @@ -15,6 +15,7 @@ import logging import re from dataclasses import dataclass, field, replace +from itertools import chain from typing import TYPE_CHECKING from markdown_it import MarkdownIt @@ -310,7 +311,8 @@ def chunk_shell( comment_start = None comment_lines: list[str] = [] - for i, line in enumerate(lines): + # A final empty sentinel flushes a trailing comment block at end of file. + for i, line in enumerate(chain(lines, ("",))): stripped = line.strip() if stripped.startswith("#") and not stripped.startswith("#!"): if comment_start is None: diff --git a/tests/deduplication/intra_skill/test_intra_skill_validator.py b/tests/deduplication/intra_skill/test_intra_skill_validator.py index d31691077..454167304 100644 --- a/tests/deduplication/intra_skill/test_intra_skill_validator.py +++ b/tests/deduplication/intra_skill/test_intra_skill_validator.py @@ -106,6 +106,34 @@ def test_rejects_invalid_budget(self, budget: object) -> None: class TestIntraSkillValidatorValidate: + @patch("skillevaluator.deduplication.intra_skill.intra_skill_validator.analyze_cluster") + @patch("skillevaluator.deduplication.intra_skill.intra_skill_validator.LLMClient") + @patch("skillevaluator.deduplication.intra_skill.intra_skill_validator.EmbeddingClient") + def test_duplicate_shell_comments_at_eof_are_compared( + self, mock_embed, _mock_llm, mock_analyze, tmp_path: Path + ) -> None: + comments = ( + "# Document the required setup before invoking this helper script.\n" + "# Use the configured workspace for every generated output file.\n" + "# Keep the source input unchanged while the helper processes it.\n" + ) + (tmp_path / "first.sh").write_text("#!/bin/sh\necho ready\n" + comments, encoding="utf-8") + (tmp_path / "second.sh").write_text("#!/bin/sh\necho ready\n" + comments, encoding="utf-8") + mock_embed.return_value.embed.side_effect = _unit_embeddings(2) + mock_analyze.return_value = LLMVerdict( + verdict="DUPLICATE", confidence=0.9, reasoning="Repeated instructions", suggestion="Consolidate comments" + ) + + result = IntraSkillValidator().validate(tmp_path) + + mock_embed.return_value.embed.assert_called_once() + assert len(mock_embed.return_value.embed.call_args.args[0]) == 2 + mock_analyze.assert_called_once() + assert result.passed is False + assert len(result.findings) == 1 + assert "first.sh" in result.findings[0].message + assert "second.sh" in result.findings[0].message + def test_collection_log_uses_target_label_without_host_path(self, tmp_path: Path, caplog) -> None: skill_dir = tmp_path / "nested" / "external-skill" skill_dir.mkdir(parents=True) diff --git a/tests/deduplication/utils/test_chunker.py b/tests/deduplication/utils/test_chunker.py index 568ef64d0..d8c5d26c0 100644 --- a/tests/deduplication/utils/test_chunker.py +++ b/tests/deduplication/utils/test_chunker.py @@ -5,6 +5,8 @@ from __future__ import annotations +import pytest + from skillevaluator.deduplication.utils.chunker import ( ContentChunk, chunk_file, @@ -191,6 +193,28 @@ def test_short_function_excluded(self) -> None: class TestChunkShell: + @pytest.mark.parametrize("prefix", ["", "#!/bin/sh\necho ready\n"]) + @pytest.mark.parametrize("ending", ["", "\n", "\n\n"]) + def test_comment_block_at_eof(self, prefix: str, ending: str) -> None: + comments = [ + "Document the required setup before invoking this helper script.", + "Use the configured workspace for every generated output file.", + "Keep the source input unchanged while the helper processes it.", + ] + content = prefix + "\n".join(f"# {line}" for line in comments) + ending + + chunks = chunk_shell(_cf(content, ".sh", "run.sh"), min_chars=80) + + assert len(chunks) == 1 + assert chunks[0].heading == "(comment)" + assert chunks[0].text == "\n".join(comments) + first_line = len(prefix.splitlines()) + 1 + assert (chunks[0].start_line, chunks[0].end_line) == (first_line, first_line + 2) + + @pytest.mark.parametrize("content", ["", "#!/bin/sh\n", "# Short\n# Two lines", "# A\n# B\n# C"]) + def test_eof_comments_keep_existing_filters(self, content: str) -> None: + assert chunk_shell(_cf(content, ".sh", "run.sh"), min_chars=80) == [] + def test_function_body(self) -> None: body = "setup() {\n" + " echo step\n" * 15 + "}\n" chunks = chunk_shell(_cf(body, ".sh", "run.sh"), min_chars=80)