From 5a79f7385be991233f66ef01c9300a1b394d81dc Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Tue, 22 Sep 2026 21:10:13 -0700 Subject: [PATCH] kb-test: exercise the git-path ledger and HEAD baseline in a throwaway repo Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01VdfEGXA7aJ6ftMsCc9PJze --- scripts/kb-test.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/scripts/kb-test.sh b/scripts/kb-test.sh index fd54fae9..4960d0a4 100755 --- a/scripts/kb-test.sh +++ b/scripts/kb-test.sh @@ -709,5 +709,39 @@ else ok "a recorded rm stays excused across the tool's later writes" fi +# 25. The production paths, which every case above bypasses by setting KB_FILE: +# the baseline is `git show HEAD` and the ledger is `git rev-parse +# --git-path`. Run in a throwaway repo holding a copy of the tool. +r="$work/repo" +mkdir -p "$r/scripts" "$r/prolog-sessions" +cp "$here/kb" "$here/kb-merge.pl" "$r/scripts/" +cp "$KB" "$r/prolog-sessions/kb.pl" +g() { git -C "$r" -c user.name=kb-test -c user.email=kb-test@invalid "$@"; } +rkb() { (unset KB_FILE KB_BASELINE; "$r/scripts/kb" "$@"); } +if ! { g init -q && g add -A && g commit -qm base; } >/dev/null 2>&1; then + bad "could not build the throwaway repo -- case 25 proves nothing" +elif ! rkb rm "$work/drop-x.pl" >"$work/out" 2>&1; then + bad "rm in a real repo was refused: $(tail -1 "$work/out")" +else + ledger="$(g rev-parse --path-format=absolute --git-path kb-removed.pl)" + if ! grep -q "^location(cli_args," "$ledger" 2>/dev/null; then + bad "rm in a real repo did not record its removal at the git-path ledger" + elif [ "$(g status --porcelain --untracked-files=all)" != " M prolog-sessions/kb.pl" ]; then + bad "the real-repo write left something git sees: $(g status --porcelain --untracked-files=all | tr '\n' ' ')" + elif ! rkb add "$work/new.pl" >"$work/out" 2>&1; then + bad "the git-path ledger did not excuse its own rm: $(tail -1 "$work/out")" + else + g checkout -q -- prolog-sessions/kb.pl + cp "$work/lost-x.pl" "$r/prolog-sessions/kb.pl" + if rkb add "$work/new.pl" >"$work/out" 2>&1; then + bad "after git checkout restored the kb, the git-path ledger excused a new loss" + elif said "$work/out" "location(cli_args,'src/main.rs',clap)"; then + ok "the git-path ledger and HEAD baseline work, and a loss after a restore is refused" + else + bad "the real-repo loss was refused, but not by naming it" + fi + fi +fi + printf '\nkb-test: %d passed, %d failed\n' "$pass" "$fail" [ "$fail" -eq 0 ]