oclaw/tests/test_frontmatter_yaml.py
oliver 420abac9f1 refactor: root-package imports (svc/runtime/interfaces) and fix PYTHONPATH
- Rename platform/ to svc/ to avoid shadowing stdlib platform.
- Replace from oclaw.* with from svc/runtime/interfaces; update -m CLI paths.
- tests/conftest: prepend repo root to sys.path (no parent-folder package name).
- CI: paths and offline_eval script under repo root.
- Ops scripts: PYTHONPATH must be repo root for python -m runtime.* (fixes gateway/WhatsApp sidecar startup).
- Fix default oclaw.json path in tabular/file attachment limits; stabilize attachment test config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 14:51:17 +08:00

29 lines
1 KiB
Python

from __future__ import annotations
import pytest
from runtime.prompt_templates.frontmatter import parse_frontmatter_dict, parse_markdown_document
def test_parse_yaml_frontmatter_nested_metadata() -> None:
fm = parse_frontmatter_dict(
"name: demo\ndescription: x\nmetadata:\n oclaw:\n install:\n - id: i1\n kind: node\n",
source="test",
)
assert fm.get("name") == "demo"
md = fm.get("metadata")
assert isinstance(md, dict)
assert isinstance(md.get("oclaw"), dict)
def test_parse_markdown_document_roundtrip() -> None:
raw = "---\ntitle: t\nsummary: s\nread_when: now\n---\n\n# Body\nhello"
meta, body = parse_markdown_document(raw, source="test")
assert meta.get("title") == "t"
assert "hello" in body
def test_strict_yaml_invalid_raises(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("AIA_PROMPT_FRONTMATTER_STRICT", "1")
with pytest.raises(ValueError):
parse_frontmatter_dict("*invalid\nfoo: bar", source="test")