|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | + |
| 4 | +SCENARIO="${SCENARIO:-fresh}" |
| 5 | +STATE_DIR="/tmp/mock-claude-state" |
| 6 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 7 | +REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 8 | + |
| 9 | +pass() { printf '\033[0;32mPASS\033[0m %s\n' "$1"; } |
| 10 | +fail() { printf '\033[0;31mFAIL\033[0m %s\n' "$1" >&2; exit 1; } |
| 11 | + |
| 12 | +# Clean state |
| 13 | +rm -rf "$STATE_DIR" |
| 14 | +mkdir -p "$STATE_DIR" |
| 15 | + |
| 16 | +# Prepend mock claude to PATH |
| 17 | +export PATH="$SCRIPT_DIR:$PATH" |
| 18 | +export STATE_DIR |
| 19 | + |
| 20 | +# Create a "claude" wrapper that calls mock-claude.sh |
| 21 | +cat > "$SCRIPT_DIR/claude" <<'WRAPPER' |
| 22 | +#!/bin/sh |
| 23 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 24 | +exec sh "$SCRIPT_DIR/mock-claude.sh" "$@" |
| 25 | +WRAPPER |
| 26 | +chmod +x "$SCRIPT_DIR/claude" |
| 27 | + |
| 28 | +# Set up scenario |
| 29 | +case "$SCENARIO" in |
| 30 | + fresh) |
| 31 | + echo "=== Scenario: fresh install ===" |
| 32 | + ;; |
| 33 | + idempotent) |
| 34 | + echo "=== Scenario: idempotent re-run ===" |
| 35 | + touch "$STATE_DIR/marketplace" |
| 36 | + touch "$STATE_DIR/plugin" |
| 37 | + echo "0.5.0" > "$STATE_DIR/plugin_version" |
| 38 | + ;; |
| 39 | + update) |
| 40 | + echo "=== Scenario: update from older version ===" |
| 41 | + touch "$STATE_DIR/marketplace" |
| 42 | + touch "$STATE_DIR/plugin" |
| 43 | + echo "0.3.0" > "$STATE_DIR/plugin_version" |
| 44 | + ;; |
| 45 | + *) |
| 46 | + fail "Unknown scenario: $SCENARIO" |
| 47 | + ;; |
| 48 | +esac |
| 49 | + |
| 50 | +# Run installer |
| 51 | +output="$(sh "$REPO_DIR/install.sh" 2>&1)" || fail "install.sh exited with error" |
| 52 | +echo "$output" |
| 53 | + |
| 54 | +# Assertions |
| 55 | +case "$SCENARIO" in |
| 56 | + fresh) |
| 57 | + [ -f "$STATE_DIR/marketplace" ] || fail "Marketplace was not added" |
| 58 | + [ -f "$STATE_DIR/plugin" ] || fail "Plugin was not installed" |
| 59 | + echo "$output" | grep -q "Adding marketplace" || fail "Expected 'Adding marketplace' in output" |
| 60 | + echo "$output" | grep -q "Installing plugin" || fail "Expected 'Installing plugin' in output" |
| 61 | + pass "Fresh install succeeded" |
| 62 | + ;; |
| 63 | + idempotent) |
| 64 | + echo "$output" | grep -q "Updating" || fail "Expected 'Updating' in output" |
| 65 | + echo "$output" | grep -q "v0.5.0" || fail "Expected version 0.5.0 in output" |
| 66 | + pass "Idempotent re-run succeeded" |
| 67 | + ;; |
| 68 | + update) |
| 69 | + version="$(cat "$STATE_DIR/plugin_version")" |
| 70 | + [ "$version" = "0.5.0" ] || fail "Expected version 0.5.0 after update, got $version" |
| 71 | + echo "$output" | grep -q "v0.5.0" || fail "Expected version 0.5.0 in output" |
| 72 | + pass "Update from older version succeeded" |
| 73 | + ;; |
| 74 | +esac |
| 75 | + |
| 76 | +# Cleanup wrapper |
| 77 | +rm -f "$SCRIPT_DIR/claude" |
0 commit comments