Skip to content

Commit f24475c

Browse files
committed
Add simulated binary replacement to smoke tests (Phase 6e)
Tests the update command's replacement flow without network calls: copy binary as "downloaded" version, unlink-then-replace the "installed" version, verify replaced binary runs --version. Also tests read-only binary replacement edge case (#114).
1 parent 20814e8 commit f24475c

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

scripts/smoke-test.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,59 @@ fi
397397
"$BINARY" config reset auto_index 2>/dev/null
398398
echo "OK: config set/get/reset round-trip"
399399

400+
# 6e: Simulated binary replacement (update flow without network)
401+
# Simulates the update command's Steps 3-6: extract, replace, verify.
402+
# Uses a copy of the test binary as the "downloaded" version.
403+
echo "--- Phase 6e: simulated binary replacement ---"
404+
REPLACE_DIR=$(mktemp -d)
405+
INSTALL_DIR="$REPLACE_DIR/install"
406+
mkdir -p "$INSTALL_DIR"
407+
408+
# 1. Copy binary to "install dir" as the "currently installed" version
409+
cp "$BINARY" "$INSTALL_DIR/codebase-memory-mcp"
410+
chmod 755 "$INSTALL_DIR/codebase-memory-mcp"
411+
412+
# Verify installed binary works
413+
INSTALLED_VER=$("$INSTALL_DIR/codebase-memory-mcp" --version 2>&1)
414+
if ! echo "$INSTALLED_VER" | grep -qE 'v?[0-9]+\.[0-9]+|dev'; then
415+
echo "FAIL: installed binary --version failed: $INSTALLED_VER"
416+
rm -rf "$REPLACE_DIR"
417+
exit 1
418+
fi
419+
420+
# 2. Copy binary as the "downloaded" new version
421+
cp "$BINARY" "$REPLACE_DIR/smoke-codebase-memory-mcp"
422+
423+
# 3. Simulate cbm_replace_binary: unlink old, copy new
424+
rm -f "$INSTALL_DIR/codebase-memory-mcp"
425+
cp "$REPLACE_DIR/smoke-codebase-memory-mcp" "$INSTALL_DIR/codebase-memory-mcp"
426+
chmod 755 "$INSTALL_DIR/codebase-memory-mcp"
427+
428+
# 4. Verify replaced binary works
429+
REPLACED_VER=$("$INSTALL_DIR/codebase-memory-mcp" --version 2>&1)
430+
if ! echo "$REPLACED_VER" | grep -qE 'v?[0-9]+\.[0-9]+|dev'; then
431+
echo "FAIL: replaced binary --version failed: $REPLACED_VER"
432+
rm -rf "$REPLACE_DIR"
433+
exit 1
434+
fi
435+
echo "OK: binary replacement succeeded (version: $REPLACED_VER)"
436+
437+
# 5. Test replacement of read-only binary (edge case — cbm_replace_binary
438+
# handles this via unlink-before-write, which works even on read-only files)
439+
chmod 444 "$INSTALL_DIR/codebase-memory-mcp"
440+
rm -f "$INSTALL_DIR/codebase-memory-mcp"
441+
cp "$REPLACE_DIR/smoke-codebase-memory-mcp" "$INSTALL_DIR/codebase-memory-mcp"
442+
chmod 755 "$INSTALL_DIR/codebase-memory-mcp"
443+
READONLY_VER=$("$INSTALL_DIR/codebase-memory-mcp" --version 2>&1)
444+
if ! echo "$READONLY_VER" | grep -qE 'v?[0-9]+\.[0-9]+|dev'; then
445+
echo "FAIL: read-only replacement --version failed: $READONLY_VER"
446+
rm -rf "$REPLACE_DIR"
447+
exit 1
448+
fi
449+
echo "OK: read-only binary replacement succeeded"
450+
451+
rm -rf "$REPLACE_DIR"
452+
400453
echo ""
401454
echo "=== Phase 7: MCP advanced tool calls ==="
402455

0 commit comments

Comments
 (0)