From c742b1f322e63566807ad4d94e1683a7ed989bfd Mon Sep 17 00:00:00 2001 From: bchanot Date: Wed, 28 Oct 2026 16:23:33 +0100 Subject: [PATCH] fix(memory): upgrade-side v1 reader skips status lines inside code fences --- lib/memory.sh | 8 ++++---- lib/tests/memory.test.sh | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/memory.sh b/lib/memory.sh index 0d13231..e97722f 100755 --- a/lib/memory.sh +++ b/lib/memory.sh @@ -591,11 +591,11 @@ memory_legacy_status() { # [] → the v1 lexical status line | tail -1 return fi - RE="$_MEM_LEGACY_RE" awk -v id="$2" -v end="$end" ' - /^```/ { fence = !fence } - !fence && $0 ~ end { on = 0 } + RE="$_MEM_LEGACY_RE" END_RE="$end" awk -v id="$2" ' + /^```/ { fence = !fence; next } + !fence && $0 ~ ENVIRON["END_RE"] { on = 0 } !fence && $0 ~ "^## " id " " { on = 1; next } - on && tolower($0) ~ tolower(ENVIRON["RE"]) { last = $0 } + on && !fence && tolower($0) ~ tolower(ENVIRON["RE"]) { last = $0 } END { if (last != "") print last }' "$1" } diff --git a/lib/tests/memory.test.sh b/lib/tests/memory.test.sh index 654d079..ba55950 100755 --- a/lib/tests/memory.test.sh +++ b/lib/tests/memory.test.sh @@ -428,6 +428,16 @@ v1blk d15/fenced '## BLK-003 — three' 'Status: resolved' '```' \ 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 +# status words inside a ``` fence are not the entry's status +v1blk d15/fstat-a '## BLK-003 — three' 'Status: open' '```' 'Status: resolved' '```' +bash "$MEM" upgrade d15/fstat-a >/dev/null 2>&1 +check T15-fenced-status-a-no-repair "$(grep -c 'upgrade)' d15/fstat-a/blockers.md)" 0 +check T15-fenced-status-a "$(memory_word_of d15/fstat-a/blockers.md BLK-003)" open +v1blk d15/fstat-b '## BLK-003 — three' 'Status: open' '```' \ + '## BLK-009 — quoted' 'Status: resolved' '```' +bash "$MEM" upgrade d15/fstat-b >/dev/null 2>&1 +check T15-fenced-status-b-no-repair "$(grep -c 'upgrade)' d15/fstat-b/blockers.md)" 0 +check T15-fenced-status-b "$(memory_word_of d15/fstat-b/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'