diff --git a/.gitignore b/.gitignore index 27e8dfb..5661c60 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/openspace/skill_engine/skill_utils.py b/openspace/skill_engine/skill_utils.py index 555a2cf..c808248 100644 --- a/openspace/skill_engine/skill_utils.py +++ b/openspace/skill_engine/skill_utils.py @@ -113,18 +113,15 @@ 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. + Uses :func:`parse_frontmatter` so block scalars (``|`` / ``>``) round-trip. """ - if not content.startswith("---"): + fm = parse_frontmatter(content) + if field_name not in fm: return None - match = _FRONTMATTER_RE.match(content) - if not match: + value = fm[field_name] + if value is None: 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()) - return None + return value if isinstance(value, str) else str(value) def set_frontmatter_field(content: str, field_name: str, value: str) -> str: diff --git a/tests/skill_engine/test_get_frontmatter_block_scalar.py b/tests/skill_engine/test_get_frontmatter_block_scalar.py new file mode 100644 index 0000000..9587fd9 --- /dev/null +++ b/tests/skill_engine/test_get_frontmatter_block_scalar.py @@ -0,0 +1,15 @@ +"""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_missing_returns_none(): + src = "---\nname: x\n---\n" + assert get_frontmatter_field(src, "description") is None