fix(memory): upgrade-side v1 range ignores headings inside code fences

This commit is contained in:
bchanot committed 2026-10-28 16:01:22 +01:00
1 parent 7b26000f48
commit 197b899c3f
2 files changed
+23 -8

No files matched your search

+17 -8
View File
@@ -580,14 +580,23 @@ _mem_heading_ids() { # <file> <PREFIX> → the entry IDs, any heading level
_MEM_LEGACY_RE='status|RESOLVED|REVERTED|upstream|resolved|[^a-z]open'
memory_legacy_status() { # <file> <ID> [<end>] → the v1 lexical status line
# (reconcile reads it on a v1 blockers file; `upgrade` proves its verdicts
# against it). The range ends at the next line matching <end> (BRE,
# default `^## BLK-`, reconcile's own). v1: drop every <end> line first: the
# range is inclusive of the NEXT entry's header, which may carry a status.
local end="${3:-^## BLK-}"
sed -n "/^## ${2} /,/$end/p" "$1" \
| "$MEM_GREP" -v "$end" \
| "$MEM_GREP" -iE "$_MEM_LEGACY_RE" \
| tail -1
# against it). Default range: `## ID` to the next `## BLK-`, reconcile's
# own. With <end> (ERE) the range is fence-aware: it stops at the next
# heading matching <end> outside a ``` fence, and that header is not read.
local end="${3:-}"
if [ -z "$end" ]; then
sed -n "/^## ${2} /,/^## BLK-/p" "$1" \
| "$MEM_GREP" -v '^## BLK-' \
| "$MEM_GREP" -iE "$_MEM_LEGACY_RE" \
| tail -1
return
fi
RE="$_MEM_LEGACY_RE" awk -v id="$2" -v end="$end" '
/^```/ { fence = !fence }
!fence && $0 ~ end { on = 0 }
!fence && $0 ~ "^## " id " " { on = 1; next }
on && tolower($0) ~ tolower(ENVIRON["RE"]) { last = $0 }
END { if (last != "") print last }' "$1"
}
_mem_legacy_open() { # <old file> <ID> → rc 0 when reconcile's v1 reader
+6
View File
@@ -422,6 +422,12 @@ v1blk d15/probed '## BLK-003 — three, open' 'Status: open' '' \
bash "$MEM" upgrade d15/probed >/dev/null 2>&1
check T15-probed-no-repair "$(grep -c 'upgrade)' d15/probed/blockers.md)" 0
check T15-probed-open "$(memory_word_of d15/probed/blockers.md BLK-003)" open
# a heading line quoted inside a ``` fence does not end the entry's range
v1blk d15/fenced '## BLK-003 — three' 'Status: resolved' '```' \
'### BLK-001 — quoted' '```' 'Status: open'
bash "$MEM" upgrade d15/fenced >/dev/null 2>&1
check T15-fenced-no-repair "$(grep -c 'upgrade)' d15/fenced/blockers.md)" 0
check T15-fenced-open "$(memory_word_of d15/fenced/blockers.md BLK-003)" open
# `## ID—x` (no space) is no v1-visible heading: no silent flip
v1blk d15/nospace '## BLK-001—x' 'Status: resolved' '' \
'## BLK-002 — y' 'Status: open'