From ddf34944e04d0b9d3f6d4c15e85754863a42bfbc Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Fri, 5 Jun 2026 10:37:09 +0200 Subject: [PATCH] feat: improve index-append.py frontmatter self-healing --- skills/ingest/scripts/index-append.py | 10 +++++++++- tests/scripts.bats | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/skills/ingest/scripts/index-append.py b/skills/ingest/scripts/index-append.py index bb91238..89070e4 100644 --- a/skills/ingest/scripts/index-append.py +++ b/skills/ingest/scripts/index-append.py @@ -41,18 +41,26 @@ def main() -> int: # 1. Bump last_updated inside the first frontmatter block fm_open = False + fm_close_idx = None + bumped = False for i, ln in enumerate(lines): if ln.strip() == "---": if not fm_open: fm_open = True continue - break # end of frontmatter + fm_close_idx = i # the closing --- + break if fm_open and ln.startswith("last_updated:"): lines[i] = f"last_updated: {today}" + bumped = True if not fm_open: print("index-append: warning: no frontmatter found, last_updated not bumped", file=sys.stderr) + elif not bumped and fm_close_idx is not None: + # self-heal: frontmatter present but missing the key — insert it before the close + lines.insert(fm_close_idx, f"last_updated: {today}") + print("index-append: last_updated key was missing — inserted", file=sys.stderr) # 2. Locate the target section [start, end) start = None diff --git a/tests/scripts.bats b/tests/scripts.bats index 86d18cd..19f758e 100644 --- a/tests/scripts.bats +++ b/tests/scripts.bats @@ -66,3 +66,23 @@ load helpers [ "$status" -ne 0 ] [ -z "$output" ] || [[ "$output" != *"feat/ai-ingest-"* ]] } + +@test "index-append: self-heals a frontmatter missing last_updated" { + G="$(make_fixture_genome)"; cd "$G" + cat > wiki/index.md <<'EOF' +--- +title: "Index" +type: index +domain: genome-test +maturity: stable +private: false +--- + +# Index + +## Sources (`wiki/sources/`) +*x* +EOF + python3 "$SKILL_SCRIPTS/index-append.py" --section Sources --entry '- [[sources/foo]] — s. `maturity: draft`' + grep -q "^last_updated: $(date +%F)$" wiki/index.md +}