From bc7357d857741cb57b4c9eff0e3543060d691a3b Mon Sep 17 00:00:00 2001 From: passionworkeer <17820577270@163.com> Date: Thu, 25 Jun 2026 15:56:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(okf):=20align=20required=20frontmatter=20ke?= =?UTF-8?q?ys=20with=20OKF=20SPEC=20=C2=A74.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OKF v0.1 §4.1 explicitly states that only `type` is REQUIRED; `title`, `description`, and `timestamp` are listed as Recommended. The reference implementation treated all four as REQUIRED, so any spec-minimal bundle whose concepts only declared `type` would be incorrectly rejected by OKFDocument.validate(). This hurts programmatic producers in particular — they often have no human-readable title/description available at generation time. This PR is a rebase of upstream #64 onto the post-#129 `enrichment_agent` → `reference_agent` rename: change one constant, update the corresponding test, and add a minimal-frontmatter acceptance test. --- okf/src/reference_agent/bundle/document.py | 2 +- okf/tests/test_document.py | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/okf/src/reference_agent/bundle/document.py b/okf/src/reference_agent/bundle/document.py index f0280b9..9da8ed4 100644 --- a/okf/src/reference_agent/bundle/document.py +++ b/okf/src/reference_agent/bundle/document.py @@ -5,7 +5,7 @@ import yaml -REQUIRED_FRONTMATTER_KEYS = ("type", "title", "description", "timestamp") +REQUIRED_FRONTMATTER_KEYS = ("type",) _FRONTMATTER_DELIM = "---" diff --git a/okf/tests/test_document.py b/okf/tests/test_document.py index f3bb829..771a49e 100644 --- a/okf/tests/test_document.py +++ b/okf/tests/test_document.py @@ -43,12 +43,24 @@ def test_unterminated_frontmatter_raises(): OKFDocument.parse(src) -def test_validate_rejects_missing_required_keys(): - doc = OKFDocument(frontmatter={"type": "X", "title": "Y"}) +def test_validate_rejects_missing_type(): + """Only 'type' is REQUIRED per OKF §4.1.""" + doc = OKFDocument( + frontmatter={ + "title": "Y", + "description": "Z", + "timestamp": "2026-05-27T00:00:00+00:00", + } + ) with pytest.raises(OKFDocumentError) as exc: doc.validate() - assert "description" in str(exc.value) - assert "timestamp" in str(exc.value) + assert "type" in str(exc.value) + + +def test_validate_accepts_minimal_frontmatter(): + """Only 'type' is required — all other fields are optional per OKF §4.1.""" + doc = OKFDocument(frontmatter={"type": "X"}) + doc.validate() def test_validate_accepts_full_frontmatter():