#!/bin/bash # CTO AI Delegation - Bootstrap Testing Framework # Tests the deterministic bootstrap process for consistency set -e TEST_DIR="/tmp/cto-bootstrap-test-$(date +%s)" PASSED_TESTS=0 TOTAL_TESTS=0 echo "๐Ÿงช CTO AI Delegation - Bootstrap Testing Framework" echo "==================================================" echo "Test directory: $TEST_DIR" # Colors for output GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Test tracking run_test() { local test_name="$1" local test_command="$2" TOTAL_TESTS=$((TOTAL_TESTS + 1)) echo "" echo -e "${BLUE}๐Ÿงช Test $TOTAL_TESTS: $test_name${NC}" echo "----------------------------------------" if eval "$test_command"; then echo -e "${GREEN}โœ… PASSED: $test_name${NC}" PASSED_TESTS=$((PASSED_TESTS + 1)) return 0 else echo -e "${RED}โŒ FAILED: $test_name${NC}" return 1 fi } # Cleanup function cleanup() { if [ -d "$TEST_DIR" ]; then echo -e "${YELLOW}๐Ÿงน Cleaning up test directory: $TEST_DIR${NC}" rm -rf "$TEST_DIR" fi } trap cleanup EXIT # Prepare test environment prepare_test_environment() { echo "๐Ÿ”ง Preparing test environment..." # Create test directory mkdir -p "$TEST_DIR" cd "$TEST_DIR" # Extract current template (simulating milestone download) echo "๐Ÿ“ฆ Extracting CTO template..." cp -r "$(dirname "$(realpath "$0")")"/* . 2>/dev/null || { echo "โŒ Could not copy template files" echo "๐Ÿ“ Run this test from the CTO template directory" exit 1 } # Remove git info to simulate fresh template rm -rf .git echo "โœ… Test environment ready" } # Test 1: Template file presence test_template_files() { echo "Checking for required template files..." [ -f "docs/AGENT-LLM.MD" ] || { echo "Missing: docs/AGENT-LLM.MD"; return 1; } [ -f "docs/WORKLOG-LLM.md" ] || { echo "Missing: docs/WORKLOG-LLM.md"; return 1; } [ -f "docs/CURRENTWORK-LLM.md" ] || { echo "Missing: docs/CURRENTWORK-LLM.md"; return 1; } [ -f "start-ai-delegation.sh" ] || { echo "Missing: start-ai-delegation.sh"; return 1; } [ -x "start-ai-delegation.sh" ] || { echo "start-ai-delegation.sh not executable"; return 1; } echo "All required template files present and executable" return 0 } # Test 2: Git initialization test_git_init() { echo "Testing git initialization..." git init git config user.name "Bootstrap Test" git config user.email "test@bootstrap.local" git add . git commit -m "Initial commit from CTO template" git branch -M main [ -d ".git" ] || { echo "Git repository not created"; return 1; } [ "$(git branch --show-current)" == "main" ] || { echo "Main branch not current"; return 1; } echo "Git repository initialized successfully" return 0 } # Test 3: Branch creation test_branch_creation() { echo "Testing branch creation..." # Create bootstrap branch git checkout -b bootstrap [ "$(git branch --show-current)" == "bootstrap" ] || { echo "Bootstrap branch creation failed"; return 1; } # Create workflow branches git checkout -b INTEGRATION-WIP [ "$(git branch --show-current)" == "INTEGRATION-WIP" ] || { echo "INTEGRATION-WIP branch creation failed"; return 1; } git checkout -b RELEASE [ "$(git branch --show-current)" == "RELEASE" ] || { echo "RELEASE branch creation failed"; return 1; } # Return to bootstrap git checkout bootstrap [ "$(git branch --show-current)" == "bootstrap" ] || { echo "Return to bootstrap failed"; return 1; } # Verify all branches exist git branch | grep -q "main" || { echo "Main branch missing"; return 1; } git branch | grep -q "bootstrap" || { echo "Bootstrap branch missing"; return 1; } git branch | grep -q "INTEGRATION-WIP" || { echo "INTEGRATION-WIP branch missing"; return 1; } git branch | grep -q "RELEASE" || { echo "RELEASE branch missing"; return 1; } echo "All branches created successfully" return 0 } # Test 4: Template placeholder detection test_template_placeholders() { echo "Testing template placeholder detection..." # Check for bracketed placeholders grep -q "\[.*\]" docs/WORKLOG-LLM.md || { echo "No placeholders in WORKLOG-LLM.md"; return 1; } grep -q "\[.*\]" docs/CURRENTWORK-LLM.md || { echo "No placeholders in CURRENTWORK-LLM.md"; return 1; } # Count placeholders local worklog_placeholders=$(grep -o "\[.*\]" docs/WORKLOG-LLM.md | wc -l) local currentwork_placeholders=$(grep -o "\[.*\]" docs/CURRENTWORK-LLM.md | wc -l) [ "$worklog_placeholders" -gt 5 ] || { echo "Too few placeholders in WORKLOG-LLM.md ($worklog_placeholders)"; return 1; } [ "$currentwork_placeholders" -gt 10 ] || { echo "Too few placeholders in CURRENTWORK-LLM.md ($currentwork_placeholders)"; return 1; } echo "Template placeholders detected: WORKLOG($worklog_placeholders), CURRENTWORK($currentwork_placeholders)" return 0 } # Test 5: AI agent instructions validation test_agent_instructions() { echo "Testing AI agent instructions..." # Check for critical sections in AGENT-LLM.MD grep -q "MANDATORY FIRST STEP" docs/AGENT-LLM.MD || { echo "Missing mandatory first step section"; return 1; } grep -q "CRITICAL RULES" docs/AGENT-LLM.MD || { echo "Missing critical rules section"; return 1; } grep -q "DETERMINISTIC COMMANDS" docs/AGENT-LLM.MD || { echo "Missing deterministic commands section"; return 1; } grep -q "NEVER TOUCH.*main.*BRANCH" docs/AGENT-LLM.MD || { echo "Missing main branch protection"; return 1; } # Check for exact command sequences grep -q "git init" docs/AGENT-LLM.MD || { echo "Missing git init command"; return 1; } grep -q "git checkout -b bootstrap" docs/AGENT-LLM.MD || { echo "Missing bootstrap branch creation"; return 1; } echo "AI agent instructions validated" return 0 } # Test 6: Milestone tagging simulation test_milestone_tagging() { echo "Testing milestone tagging..." # Create a test commit for tagging echo "# Test Bootstrap Complete" > BOOTSTRAP_TEST.md git add BOOTSTRAP_TEST.md git commit -m "Bootstrap: Test completion marker" # Create and verify tag git tag -a bootstrap-test-complete -m "Test milestone: Bootstrap process validation complete" # Verify tag exists git tag | grep -q "bootstrap-test-complete" || { echo "Tag creation failed"; return 1; } # Verify tag has annotation local tag_message=$(git tag -n1 bootstrap-test-complete) echo "Tag message: $tag_message" echo "Milestone tagging successful" return 0 } # Test 7: Automation script validation test_automation_script() { echo "Testing automation script..." # Check script exists and is executable [ -x "start-ai-delegation.sh" ] || { echo "Automation script not executable"; return 1; } # Check script contains expected elements grep -q "Claude CLI" start-ai-delegation.sh || { echo "Missing Claude CLI reference"; return 1; } grep -q "AGENT-LLM.MD" start-ai-delegation.sh || { echo "Missing AGENT-LLM.MD reference"; return 1; } grep -q "bootstrap" start-ai-delegation.sh || { echo "Missing bootstrap reference"; return 1; } # Test script help/validation (without actually running Claude) bash -n start-ai-delegation.sh || { echo "Script has syntax errors"; return 1; } echo "Automation script validated" return 0 } # Test 8: Integration automation setup test_integration_setup() { echo "Testing integration automation setup..." [ -x "setup-integration-automation.sh" ] || { echo "Integration setup script not executable"; return 1; } # Test Gitea workflow creation (dry run) bash setup-integration-automation.sh gitea <<< "" || { # Script might exit with error if no remote, that's ok for testing echo "Script executed (exit code expected in test environment)" } # Check if workflow file was created [ -f ".gitea/workflows/auto-integrate.yml" ] || { echo "Gitea workflow not created"; return 1; } # Validate workflow syntax grep -q "Auto-Merge to Integration" .gitea/workflows/auto-integrate.yml || { echo "Invalid workflow content"; return 1; } echo "Integration automation setup validated" return 0 } # Run all tests main() { echo "Starting bootstrap testing framework..." prepare_test_environment echo "" echo "๐Ÿงช Running Bootstrap Tests" echo "==========================" run_test "Template File Presence" "test_template_files" run_test "Git Initialization" "test_git_init" run_test "Branch Creation" "test_branch_creation" run_test "Template Placeholders" "test_template_placeholders" run_test "AI Agent Instructions" "test_agent_instructions" run_test "Milestone Tagging" "test_milestone_tagging" run_test "Automation Script" "test_automation_script" run_test "Integration Setup" "test_integration_setup" echo "" echo "๐Ÿงช Bootstrap Test Results" echo "==========================" echo -e "Total Tests: $TOTAL_TESTS" echo -e "${GREEN}Passed: $PASSED_TESTS${NC}" echo -e "${RED}Failed: $((TOTAL_TESTS - PASSED_TESTS))${NC}" if [ $PASSED_TESTS -eq $TOTAL_TESTS ]; then echo "" echo -e "${GREEN}๐ŸŽ‰ ALL TESTS PASSED!${NC}" echo -e "${GREEN}โœ… Bootstrap framework is working correctly${NC}" echo -e "${GREEN}โœ… Template is ready for production use${NC}" return 0 else echo "" echo -e "${RED}โŒ SOME TESTS FAILED!${NC}" echo -e "${RED}๐Ÿ”ง Bootstrap framework needs attention${NC}" return 1 fi } # Run main function main "$@"