#!/bin/bash

# Test script to verify the checkpoint system works

echo "Testing Claude Code Checkpoint installation..."

# Clean up any previous test install
rm -rf ~/.claude/checkpoint/hooks/checkpoint-hook.sh 2>/dev/null

# Run the installer
node bin/claude-checkpoint.js --yes --max-checkpoints 10

# Check if the hook was created
if [ -f ~/.claude/checkpoint/hooks/checkpoint-hook.sh ]; then
    echo "✓ Checkpoint hook created successfully"
else
    echo "✗ Checkpoint hook was not created"
    exit 1
fi

# Check if settings.json was updated correctly
if grep -q "checkpoint-hook.sh" ~/.claude/settings.json; then
    echo "✓ Claude settings updated correctly"
    
    # Verify the format is correct (should be in an array)
    if grep -q '"Stop":\s*\[' ~/.claude/settings.json; then
        echo "✓ Stop hook format is correct (array)"
    else
        echo "✗ Stop hook format is incorrect (not an array)"
        exit 1
    fi
else
    echo "✗ Claude settings were not updated"
    exit 1
fi

echo ""
echo "✅ All tests passed! The checkpoint system should now work correctly."
echo ""
echo "To verify it's working:"
echo "1. Make a change to any file in a git repository"
echo "2. Run any Claude Code command"
echo "3. Check if a checkpoint was created: checkpoint list"