This commit is contained in:
Santh 2026-08-12 22:22:03 +07:00 • committed by GitHub
commit 28c7956fae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 5 deletions

1
.gitignore vendored
View file

@ -51,6 +51,7 @@ tests/skill_engine/*
!tests/skill_engine/test_evolver_length_recovery.py
!tests/skill_engine/test_evolution_retry_idempotency.py
!tests/skill_engine/test_analyzer_length_recovery.py
!tests/skill_engine/test_get_frontmatter_block_scalar.py
!tests/skill_engine/decision/
tests/skill_engine/decision/*
!tests/skill_engine/decision/test_analysis_adapter.py

View file

@ -113,17 +113,29 @@ def get_frontmatter_field(content: str, field_name: str) -> Optional[str]:
"""Extract a single field value from YAML frontmatter.
Returns ``None`` if the field is absent or content has no frontmatter.
Block scalars (``|`` / ``>``) include following indented lines.
"""
if not content.startswith("---"):
return None
match = _FRONTMATTER_RE.match(content)
if not match:
return None
for line in match.group(1).split("\n"):
if ":" in line:
key, value = line.split(":", 1)
if key.strip() == field_name:
return _yaml_unquote(value.strip())
lines = match.group(1).split("\n")
for i, line in enumerate(lines):
if ":" not in line:
continue
key, value = line.split(":", 1)
if key.strip() != field_name:
continue
rest = value.strip()
if re.fullmatch(r"[|>][+-]?", rest):
collected: List[str] = []
j = i + 1
while j < len(lines) and lines[j].startswith((" ", "\t")):
collected.append(re.sub(r"^[ \t]+", "", lines[j], count=1))
j += 1
return "\n".join(collected)
return _yaml_unquote(rest)
return None

View file

@ -0,0 +1,25 @@
"""Regression: get_frontmatter_field must read YAML block scalars."""
from __future__ import annotations
from openspace.skill_engine.skill_utils import get_frontmatter_field
def test_get_frontmatter_field_reads_block_scalar_description():
src = "---\nname: x\ndescription: |\n line1\n line2\n---\nbody\n"
assert get_frontmatter_field(src, "description") == "line1\nline2"
def test_get_frontmatter_field_reads_folded_scalar():
src = "---\nname: x\ndescription: >\n line1\n line2\n---\n"
assert get_frontmatter_field(src, "description") == "line1\nline2"
def test_get_frontmatter_field_missing_returns_none():
src = "---\nname: x\n---\n"
assert get_frontmatter_field(src, "description") is None
def test_get_frontmatter_field_keeps_plain_scalar_text():
src = "---\nenabled: true\n---\n"
assert get_frontmatter_field(src, "enabled") == "true"