Skip to content

Multi-tier framework for evaluating AI agent skills and plugins with quality gates, security scanning, harness compatibility checks, semantic overlap detection, synthetic evaluation dataset generation, and live agent evaluation that measures how skills affect agent behavior. Ships reusable CI templates that bring every check to any repository.

Keep fenced code within its Markdown section during chunking (#165)

Sylvester Kaczmarek00c97f880cc8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6fccc0ef..a32b8171 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ All notable changes to SkillEvaluator are documented in this file.
### Fixed
+- Keep headings and comments inside fenced code examples in their enclosing Markdown
+ section during Tier 2 content chunking, preserving original source line numbers.
- Run the public Docker image as an unprivileged user, with writable default report and home directories.
Document UID/GID overrides for host-owned output mounts.
- Pin the HTML report Chart.js dependency and verify its integrity before browser execution.
diff --git a/src/skillevaluator/deduplication/utils/chunker.py b/src/skillevaluator/deduplication/utils/chunker.py
index 5740fbb8..f88340e7 100644
--- a/src/skillevaluator/deduplication/utils/chunker.py
+++ b/src/skillevaluator/deduplication/utils/chunker.py
@@ -17,6 +17,8 @@ import re
from dataclasses import dataclass, field
from typing import TYPE_CHECKING
+from markdown_it import MarkdownIt
+
from skillevaluator.constants import CONTENT_DEDUP_MIN_CHUNK_CHARS
from skillevaluator.spdx import is_spdx_only_html_comment
@@ -67,13 +69,20 @@ def chunk_markdown(
) -> list[ContentChunk]:
"""Split markdown into heading-level sections with line tracking."""
lines = collected.content.splitlines(keepends=True)
+ # A heading-like line in a fenced example is literal content, not a section.
+ fenced_lines = {
+ line + collected.line_offset + 1
+ for token in MarkdownIt("commonmark").parse(collected.content)
+ if token.type == "fence" and token.map is not None
+ for line in range(*token.map)
+ }
sections: list[ContentChunk] = []
current_heading = "(preamble)"
current_start = collected.line_offset + 1
current_lines: list[str] = []
for i, line in enumerate(lines, start=collected.line_offset + 1):
- match = HEADING_PATTERN.match(line)
+ match = None if i in fenced_lines else HEADING_PATTERN.match(line)
if match:
if current_lines:
text = "".join(current_lines).strip()
diff --git a/tests/deduplication/utils/test_chunker_fences.py b/tests/deduplication/utils/test_chunker_fences.py
new file mode 100644
index 00000000..0395f52c
--- /dev/null
+++ b/tests/deduplication/utils/test_chunker_fences.py
@@ -0,0 +1,89 @@
+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+
+"""Keep literal fenced-code headings within their parent deduplication section."""
+
+from pathlib import Path
+
+import pytest
+
+from skillevaluator.deduplication.utils.chunker import chunk_file
+from skillevaluator.deduplication.utils.skill_collector import CollectedFile, collect_files
+
+
+def collected(content: str, offset: int = 0) -> CollectedFile:
+ return CollectedFile(
+ path=Path("SKILL.md"),
+ rel_path="SKILL.md",
+ extension=".md",
+ content=content,
+ line_count=len(content.splitlines()) + offset,
+ line_offset=offset,
+ )
+
+
[email protected]("offset", [0, 5])
+ "opener, code, closer",
+ [
+ ("```python", "# A comment\n## Another comment\nprint(1)", "```"),
+ ("~~~sh", "# A comment\nprintf done", "~~~"),
+ ("````markdown", "```\n# Nested example heading\n```", "````"),
+ ("~~~~", "~~~\n# Still code", "~~~~~"),
+ ("```", "~~~\n# Different fence marker", "```"),
+ (" ```python", "# Zero-indent content\nprint(1)", " ```"),
+ ],
+)
+def test_fenced_headings_remain_literal(opener: str, code: str, closer: str, offset: int) -> None:
+ section = f"## Usage\n{opener}\n{code}\n{closer}\n"
+ content = section + "## Next\nDone\n"
+ chunks = chunk_file(collected(content, offset), min_chars=1)
+ assert [chunk.heading for chunk in chunks] == ["## Usage", "## Next"]
+ assert chunks[0].text == section.strip()
+ assert chunks[0].start_line == offset + 1
+ assert chunks[0].end_line == offset + len(section.splitlines())
+ assert chunks[1].start_line == chunks[0].end_line + 1
+ assert chunks[1].end_line == offset + len(content.splitlines())
+ assert all(chunk.source_file == "SKILL.md" for chunk in chunks)
+
+
[email protected]("opener", ["```python", "~~~"])
+def test_unclosed_fence_keeps_all_remaining_lines(opener: str) -> None:
+ content = f"## Usage\n{opener}\n# A comment\n## Not a new section\nprint(1)\n"
+ chunks = chunk_file(collected(content), min_chars=1)
+ assert len(chunks) == 1
+ assert chunks[0].heading == "## Usage"
+ assert chunks[0].text == content.strip()
+ assert chunks[0].end_line == len(content.splitlines())
+
+
[email protected]("line", ["``not a fence``", "Text with ``` inline backticks"])
+def test_inline_delimiters_do_not_hide_real_headings(line: str) -> None:
+ content = f"## Usage\n{line}\n## Next\nDone\n"
+ chunks = chunk_file(collected(content), min_chars=1)
+ assert [chunk.heading for chunk in chunks] == ["## Usage", "## Next"]
+
+
+def test_code_comment_does_not_drop_a_short_parent_section() -> None:
+ content = "## Usage\n```python\n# A long explanatory comment that belongs to Usage\nprint(1)\n```"
+ chunks = chunk_file(collected(content), min_chars=40)
+ assert len(chunks) == 1
+ assert chunks[0].heading == "## Usage"
+ assert chunks[0].text == content
+
+
[email protected]("newline", ["\n", "\r\n"], ids=["lf", "crlf"])
+def test_file_collection_preserves_original_lines_and_fence_content(tmp_path: Path, newline: str) -> None:
+ frontmatter = "---\nname: example\ndescription: A simple example\n---\n"
+ section = "## Usage\n```python\n# Literal comment\nprint(1)\n```\n"
+ content = (frontmatter + section + "## Next\nDone\n").replace("\n", newline)
+ (tmp_path / "SKILL.md").write_bytes(content.encode("utf-8"))
+ files = collect_files(tmp_path)
+ assert len(files) == 1
+ chunks = chunk_file(files[0], min_chars=1)
+ assert [chunk.heading for chunk in chunks] == ["## Usage", "## Next"]
+ original_lines = content.splitlines(keepends=True)
+ for chunk in chunks:
+ assert "".join(original_lines[chunk.start_line - 1 : chunk.end_line]).strip() == chunk.text
+ assert chunks[0].start_line == 5
+ assert chunks[0].text == section.replace("\n", newline).strip()