v0.47.0 — SLICE-1: metadata sidecars — storage + dual-read + migration tool
§22.4a SLICE-1 of docs/design/2026-06-06-configurable-collection-metadata.md (§7.2). Entry metadata can live in a per-entry `<slug>.meta.yaml` sidecar with the `.md` kept as pure prose (INV-2). Additive and non-breaking — with no sidecars present every corpus stays on the legacy frontmatter path, byte-identical (N=1 unchanged). - Dual-read (app/metadata.py `read_entry`) — sidecar-else-legacy-frontmatter, identical records (INV-6); unknown/forward-compat keys ride along through parse→serialize and migration (INV-7, `Entry.extra`). A degenerate sidecar (malformed/empty/slug-less) never drops the entry — slug backstopped from the filename stem, flagged not lost (INV-3). - Migration tool (`metadata.migrate_collection`) — idempotent, one ChangeFiles commit per collection (new `gitea.change_files`). Tested as a function; its Owner-gated operator trigger is DEFERRED to SLICE-4 (write paths must become sidecar-aware first — see the design's SLICE-4 note + INV-8). No production trigger ships here, so no corpus is rewritten. - Malformed flag — migration 033 adds `cached_rfcs.metadata_malformed` (additive); the corpus mirror derives it; catalog list + entry-detail APIs surface `metadata_malformed`. - INV-7 at graduation — graduation now carries `Entry.extra` through the rebuild instead of dropping forward-compat keys. Gate: backend 575 passed (28 new: test_metadata / _migration / _cache + graduation extra-preservation). Frontend untouched. CHANGELOG 0.47.0 + upgrade-steps; VERSION + frontend/package.json -> 0.47.0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+44
-2
@@ -58,6 +58,20 @@ class Entry:
|
||||
reviewed_at: str | None = None
|
||||
reviewed_by: str | None = None
|
||||
body: str = ""
|
||||
# §22.4a (configurable collection metadata, SLICE-1): frontmatter / sidecar
|
||||
# keys outside the known set above are preserved here verbatim so they ride
|
||||
# along untouched through a parse→serialize round-trip and the
|
||||
# frontmatter→sidecar migration (INV-7). Includes future collection-`fields:`
|
||||
# schema values, which the engine does not interpret.
|
||||
extra: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
|
||||
# Frontmatter keys the Entry models explicitly; everything else is `extra`.
|
||||
KNOWN_KEYS = {
|
||||
"slug", "title", "state", "id", "repo", "proposed_by", "proposed_at",
|
||||
"graduated_at", "graduated_by", "owners", "arbiters", "tags", "models",
|
||||
"funder", "unreviewed", "reviewed_at", "reviewed_by",
|
||||
}
|
||||
|
||||
|
||||
def parse(text: str) -> Entry:
|
||||
@@ -66,6 +80,16 @@ def parse(text: str) -> Entry:
|
||||
raise ValueError("Entry file missing frontmatter")
|
||||
fm = yaml.safe_load(match.group(1)) or {}
|
||||
body = match.group(2).lstrip("\n")
|
||||
return from_frontmatter(fm, body)
|
||||
|
||||
|
||||
def from_frontmatter(fm: dict[str, Any], body: str = "") -> Entry:
|
||||
"""Build an Entry from an already-parsed metadata mapping + body.
|
||||
|
||||
Shared by `parse()` (legacy `.md` frontmatter) and the SLICE-1 dual-read
|
||||
sidecar path (`metadata.read_entry`), so both produce identical records
|
||||
(INV-6). `fm` keys outside `KNOWN_KEYS` are preserved on `Entry.extra`.
|
||||
"""
|
||||
raw_models = fm.get("models", _ABSENT)
|
||||
if raw_models is _ABSENT or raw_models is None:
|
||||
models: list[str] | None = None
|
||||
@@ -74,6 +98,7 @@ def parse(text: str) -> Entry:
|
||||
raw_funder = fm.get("funder")
|
||||
funder = str(raw_funder).strip() if raw_funder else None
|
||||
unreviewed = bool(fm.get("unreviewed") or False)
|
||||
extra = {k: v for k, v in fm.items() if k not in KNOWN_KEYS}
|
||||
return Entry(
|
||||
slug=str(fm.get("slug") or ""),
|
||||
title=str(fm.get("title") or ""),
|
||||
@@ -93,11 +118,18 @@ def parse(text: str) -> Entry:
|
||||
reviewed_at=fm.get("reviewed_at") or None,
|
||||
reviewed_by=fm.get("reviewed_by") or None,
|
||||
body=body,
|
||||
extra=extra,
|
||||
)
|
||||
|
||||
|
||||
def serialize(entry: Entry) -> str:
|
||||
"""Emit canonical entry file text — frontmatter then body."""
|
||||
def to_frontmatter_dict(entry: Entry) -> dict[str, Any]:
|
||||
"""The canonical ordered metadata mapping for an entry.
|
||||
|
||||
Shared by `serialize()` (which wraps it in `---` fences over the body) and
|
||||
the SLICE-1 sidecar writer (`metadata.sidecar_yaml`, which emits the same
|
||||
mapping as a standalone `<slug>.meta.yaml`). Known keys first in canonical
|
||||
order, then `extra` (INV-7).
|
||||
"""
|
||||
fm: dict[str, Any] = {
|
||||
"slug": entry.slug,
|
||||
"title": entry.title,
|
||||
@@ -129,6 +161,16 @@ def serialize(entry: Entry) -> str:
|
||||
fm["reviewed_at"] = entry.reviewed_at
|
||||
if entry.reviewed_by:
|
||||
fm["reviewed_by"] = entry.reviewed_by
|
||||
# INV-7: forward-compat / unknown keys ride along after the known ones.
|
||||
for k, v in entry.extra.items():
|
||||
if k not in fm:
|
||||
fm[k] = v
|
||||
return fm
|
||||
|
||||
|
||||
def serialize(entry: Entry) -> str:
|
||||
"""Emit canonical entry file text — frontmatter then body."""
|
||||
fm = to_frontmatter_dict(entry)
|
||||
yaml_text = yaml.safe_dump(fm, sort_keys=False, default_flow_style=False).rstrip()
|
||||
body = entry.body.lstrip("\n")
|
||||
if body:
|
||||
|
||||
Reference in New Issue
Block a user