fix(slice4): make all entry write paths sidecar-aware (§22.4a carried from SLICE-1)
graduate, claim, retire/unretire, _read_meta_entry, mark_entry_reviewed, body extract/wrap (api_branches + api_prs replay) now dual-read and write metadata to the sidecar via write_entry_files + bot.commit_entry_files/ open_entry_pr — a migrated body-only .md no longer crashes entry.parse or re-grows frontmatter; legacy entries lazy-migrate on first metadata write. Existing tests updated to assert the sidecar (INV-2 clean docs). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+14
-9
@@ -23,7 +23,7 @@ from typing import Any
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from . import auth, cache, chat as chat_layer, db, entry as entry_mod, funder, models_resolver, projects as projects_mod, rfc_links
|
||||
from . import auth, cache, chat as chat_layer, db, entry as entry_mod, funder, metadata as metadata_mod, models_resolver, projects as projects_mod, rfc_links
|
||||
from .bot import Bot
|
||||
from .config import Config
|
||||
from .gitea import Gitea, GiteaError
|
||||
@@ -1009,20 +1009,25 @@ async def _replay_changes(
|
||||
|
||||
|
||||
def _extract_body_for_replay(is_super_draft: bool, content: str) -> str:
|
||||
# §22.4a SLICE-4: a meta-resident entry may be legacy (frontmatter+body) or
|
||||
# migrated (body-only). strip_frontmatter handles both without raising.
|
||||
if not is_super_draft:
|
||||
return content
|
||||
try:
|
||||
return entry_mod.parse(content).body
|
||||
except Exception:
|
||||
return content
|
||||
return metadata_mod.strip_frontmatter(content)
|
||||
|
||||
|
||||
def _wrap_body_for_replay(is_super_draft: bool, prior_content: str, new_body: str) -> str:
|
||||
# §22.4a SLICE-4: identity for body-only (migrated) files — never re-grow
|
||||
# frontmatter; preserve a legacy file's frontmatter until its next metadata
|
||||
# edit migrates it.
|
||||
nb = new_body if new_body.endswith("\n") else new_body + "\n"
|
||||
if not is_super_draft:
|
||||
return new_body
|
||||
entry = entry_mod.parse(prior_content)
|
||||
entry.body = new_body if new_body.endswith("\n") else new_body + "\n"
|
||||
return entry_mod.serialize(entry)
|
||||
return nb
|
||||
if entry_mod.FRONTMATTER_RE.match(prior_content):
|
||||
entry = entry_mod.parse(prior_content)
|
||||
entry.body = nb
|
||||
return entry_mod.serialize(entry)
|
||||
return nb
|
||||
|
||||
|
||||
def _resolution_branch_name(original_branch: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user