diff --git a/lib/memory.sh b/lib/memory.sh index 5350cdc..f9c135c 100755 --- a/lib/memory.sh +++ b/lib/memory.sh @@ -577,19 +577,23 @@ _mem_heading_ids() { # → the entry IDs, any heading level "$MEM_GREP" -oE "^#+ *$2-[0-9]+" "$1" | sed 's/^#* *//' } -memory_legacy_status() { # → the v1 lexical status line (reconcile - # reads it on a v1 blockers file; `upgrade` proves its verdicts against it) - # v1: drop ALL `## BLK-` header lines first: the range is inclusive of the - # NEXT entry's header, and a sibling header may carry a status word. - sed -n "/^## ${2} /,/^## BLK-/p" "$1" \ - | "$MEM_GREP" -v '^## BLK-' \ - | "$MEM_GREP" -iE 'status|RESOLVED|REVERTED|upstream|resolved|[^a-z]open' \ +_MEM_LEGACY_RE='status|RESOLVED|REVERTED|upstream|resolved|[^a-z]open' +memory_legacy_status() { # [] → 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 (BRE, + # default `^## BLK-`, reconcile's own). v1: drop every 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 } _mem_legacy_open() { # → rc 0 when reconcile's v1 reader - local st # lists the blocker open (its status is not RESOLVED) - st=$(memory_legacy_status "$1" "$2") + local st # lists the blocker open (its status is not RESOLVED); + # upgrade reads the entry's own range, up to a heading of any level + st=$(memory_legacy_status "$1" "$2" '^##* *BLK-[0-9]') case "$st" in *RESOLVED*|*resolved*) return 1 ;; esac } @@ -609,7 +613,7 @@ _mem_verdict_diff() { # → "IDword" per blocker whose open / for id in $(_mem_heading_ids "$2" BLK); do printf '%s\n' "$ix" | "$MEM_GREP" -qx "$id" && continue # the v1 reader enumerates `## ID` headings only: no verdict to keep - "$MEM_GREP" -qE "^## $id([^0-9]|$)" "$1" || continue + "$MEM_GREP" -qE "^## $id( |$)" "$1" || continue _mem_legacy_open "$1" "$id" && was=open || was=resolved memory_closed "$(memory_status_word "$(memory_entry_status "$2" "$id")")" \ && now=resolved || now=open diff --git a/lib/tests/memory.test.sh b/lib/tests/memory.test.sh index c8fc8fa..434ad63 100755 --- a/lib/tests/memory.test.sh +++ b/lib/tests/memory.test.sh @@ -416,6 +416,20 @@ dialect hashes '^## BLK-001 — three hashes, resolved$' unseen check T15-hashes-no-repair "$(grep -c 'upgrade)' d15/hashes/blockers.md)" 0 check T15-hashes-1-resolved "$(memory_word_of d15/hashes/blockers.md BLK-001)" resolved check T15-hashes-2-open "$(memory_word_of d15/hashes/blockers.md BLK-002)" open +# probe d: a ### entry after a ## one must not leak its status into it +v1blk d15/probed '## BLK-003 — three, open' 'Status: open' '' \ + '### BLK-001 — x' 'Status: resolved' +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 +# `## 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' +sum=$(cksum < d15/nospace/blockers.md) +bash "$MEM" upgrade d15/nospace >/dev/null 2>&1 +check T15-nospace-refused "$?" 2 +check T15-nospace-untouched "$(cksum < d15/nospace/blockers.md)" "$sum" +check T15-nospace-no-repair "$(grep -c 'upgrade)' d15/nospace/blockers.md)" 0 # RECONCILE_GREP reaches reconcile's v1 pipeline v1blk d15/v1only '## BLK-001 — v1 file' 'Status: resolved' printf '#!/bin/sh\necho STUB >&2\nexec /usr/bin/grep "$@"\n' > gstub