From f23086171b1dd75278c56cf9bc04e1fa8259ac8f Mon Sep 17 00:00:00 2001 From: didericis Date: Mon, 27 Jul 2026 22:08:22 -0400 Subject: [PATCH] fix: make demo setup/teardown idempotent and guard on PATH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two failure modes found while validating the harness against a scratch config root: Teardown removed $dest unconditionally before restoring the backup, so a second run deleted the user's own file — the first run had already restored it, and a restored original is indistinguishable from an installed demo file except by content. Compare against the source before removing. Setup had the mirror-image bug: run twice without an intervening teardown it backed up its *own* copy, and teardown then "restored" that, leaving demo.md in the user's config permanently. Treat an already-identical destination as a no-op. Also fail fast when bot-bottle is not on PATH. The tape types the real console script, so without it a recording silently captures `command not found` instead of a bottle launching. Refs #540 Co-Authored-By: Claude Opus 5 --- scripts/demo-setup.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/demo-setup.sh b/scripts/demo-setup.sh index 707f715f..c03fcfe0 100755 --- a/scripts/demo-setup.sh +++ b/scripts/demo-setup.sh @@ -24,6 +24,16 @@ if ! docker info >/dev/null 2>&1; then exit 1 fi +# The tape types `bot-bottle start demo` verbatim, so the console +# script has to resolve in the recording shell. Without this guard a +# recording silently captures `command not found` instead of a bottle. +if ! command -v bot-bottle >/dev/null 2>&1; then + echo "demo-setup: bot-bottle is not on PATH. The demo runs the real" >&2 + echo " console script, not ./cli.py — install it first (bash install.sh," >&2 + echo " or 'pip install -e .' into an active venv), then re-run." >&2 + exit 1 +fi + config_root="${BOT_BOTTLE_ROOT:-$HOME/.bot-bottle}" mkdir -p "$config_root/bottles" "$config_root/agents" @@ -34,6 +44,13 @@ mkdir -p "$config_root/bottles" "$config_root/agents" install_demo_file() { src=$1 dest=$2 + # Already installed (setup run twice without an intervening + # teardown). Backing up our own copy here would make teardown + # "restore" it and leave the demo file in the user's config forever, + # so treat this as a no-op. + if [ -e "$dest" ] && cmp -s "$src" "$dest"; then + return 0 + fi if [ -e "$dest.demo-backup" ]; then echo "demo-setup: $dest.demo-backup already exists — a previous run" >&2 echo " did not tear down cleanly. Inspect it, then remove or restore" >&2