* Enable binary downloads on timeout/cancellation
When code execution times out or is cancelled, the compiled binary
may still be available. This change ensures displayExecutionResults()
is called for timeout/cancelled jobs, allowing users to download
the binary artifact even when execution doesn't complete normally.
* Fix partial output display for timeout/cancellation
Previous commit broke partial output display by passing job.result
directly to displayExecutionResults(), but for timeout/cancelled jobs
the output is in partial_output field, not stdout.
Now properly maps partial_output to stdout before displaying, so users
see both the error message and any output that was captured before
timeout/cancellation, plus binary downloads if available.
* Add debugging for missing artifact on timeout/cancel
Check multiple possible locations for artifact:
- job.artifact (top level)
- job.result.artifact (nested)
Add console logging to see full job structure when timeout/cancel
occurs so we can understand why the binary isn't appearing.
* Try fetching artifact from separate endpoint on timeout/cancel
When timeout/cancel occurs, the artifact isn't in the job response.
Try fetching from /jobs/{job_id}/artifact endpoint as a fallback.
This explores whether the executor service has a separate artifact
endpoint that we can use to retrieve compiled binaries even when
execution is cancelled or times out.
* Remove debug logging, document artifact limitation
Removed console.log debugging statements now that we've confirmed
the executor service doesn't include artifacts in timeout/cancelled
responses and doesn't have a /jobs/{job_id}/artifact endpoint.
Kept the artifact fetching code with comments for future compatibility
if the executor service adds this feature.
Current limitation: Binary downloads only work for completed executions,
not for timeout/cancelled ones. The binary exists but the executor
service doesn't return it.
* Try multiple artifact endpoint patterns for timeout/cancel
When artifact isn't in the job response, try fetching from:
- /artifacts/{job_id}
- /jobs/{job_id}/artifact
- /jobs/{job_id}/download
- /jobs/{job_id}/binary
- /download/{job_id}
- /binary/{job_id}
Handles both JSON responses and direct binary responses. Logs
each attempt to console so we can see which endpoint (if any) works.
* Revert endpoint searching - artifact should be in /jobs/{id}
According to OpenAPI spec, there are no separate artifact endpoints.
The artifact should be included in GET /jobs/{id} response for ALL
job statuses (completed, cancelled, timeout).
Current limitation: The executor service only includes result.artifact
for "completed" status, not for "cancelled" or "timeout" status.
The frontend code is correct - it checks job.artifact and
job.result.artifact. The issue is the executor service needs to
include the artifact in cancelled/timeout responses.
* Add debug logging for cancelled/timeout artifact checks
Since the executor service was supposedly patched to include artifacts
in GET /jobs/{id} responses even for cancelled/timeout jobs, add
detailed logging to verify:
1. What the full job response looks like
2. Whether artifact is at job.artifact or job.result.artifact
3. Artifact details if found
This will help determine if the patch is deployed and working.
* Add test-artifact Makefile target for testing executor API
Tests binary artifact retrieval from code executor service:
- Compiles C code with return_artifact=true
- Extracts base64 artifact from response
- Decodes and executes the binary
Can test against different URLs:
make test-artifact URL=https://code.ai.unturf.com
Tested against production and confirmed:
- Artifacts ARE included for completed jobs
- Artifacts are NOT included for cancelled/timeout jobs (even with
return_artifact=true). Exit code 137 indicates SIGKILL.
* Document confirmed limitation - no artifacts for cancelled jobs
Tested against production executor API (make test-artifact) and confirmed:
- Cancelled jobs return exit_code 137 (SIGKILL)
- NO artifact field in response (neither job.artifact nor job.result.artifact)
- Artifacts only returned for fully completed jobs
Code still checks for artifacts in case this limitation is fixed
in the future, but currently binary downloads will not work for
cancelled/timeout executions.
To fix: Executor service needs to include compiled binary in
response even when execution is killed (compilation succeeded).
---------
Co-authored-by: Claude <noreply@anthropic.com>
282 lines
10 KiB
Makefile
282 lines
10 KiB
Makefile
# Makefile for OpenCompletion Testing Framework
|
|
|
|
.PHONY: help
|
|
help:
|
|
@echo "OpenCompletion Testing Framework"
|
|
@echo "================================"
|
|
@echo ""
|
|
@echo "🧪 Test Commands:"
|
|
@echo " test - Run all tests (unit, integration, functional)"
|
|
@echo " test-unit - Run only unit tests"
|
|
@echo " test-integration - Run only integration tests"
|
|
@echo " test-functional - Run only functional tests"
|
|
@echo " test-validator - Run YAML validator tests"
|
|
@echo " test-yaml-loading - Run YAML loading/parsing tests"
|
|
@echo " test-activity-flows - Run activity flow tests"
|
|
@echo " test-battleship - Run battleship game tests"
|
|
@echo " test-guarded-ai - Run guarded_ai.py functionality tests"
|
|
@echo " test-multiple-files - Run integration tests across all activity files"
|
|
@echo ""
|
|
@echo "📋 Validation Commands:"
|
|
@echo " validate-yaml - Validate all YAML files in research/"
|
|
@echo ""
|
|
@echo "🛠️ Development Commands:"
|
|
@echo " venv - Create virtual environment and install dependencies"
|
|
@echo " dev-setup - Install development dependencies"
|
|
@echo " lint - Run code linting and formatting"
|
|
@echo " clean - Clean up generated files"
|
|
@echo " clean-all - Remove virtual environment"
|
|
|
|
# Setup virtual environment
|
|
.PHONY: venv
|
|
venv:
|
|
@if [ ! -d "venv" ]; then \
|
|
echo "🚀 Creating virtual environment..."; \
|
|
python3 -m venv venv; \
|
|
echo "📦 Installing basic dependencies..."; \
|
|
venv/bin/pip install --upgrade pip; \
|
|
venv/bin/pip install -r requirements.txt || echo "⚠️ Failed to install basic dependencies"; \
|
|
echo "✅ Virtual environment ready!"; \
|
|
else \
|
|
echo "✅ Virtual environment already exists"; \
|
|
fi
|
|
|
|
# ============================================================================
|
|
# MAIN TEST COMMANDS
|
|
# ============================================================================
|
|
|
|
# Run all tests
|
|
.PHONY: test
|
|
test: test-unit test-integration test-functional test-validator test-yaml-loading test-activity-flows test-battleship test-guarded-ai test-multiple-files validate-yaml
|
|
@echo ""
|
|
@echo "🎉 All tests completed!"
|
|
@echo "📊 Test Summary:"
|
|
@echo " ✅ Unit tests - Core functionality"
|
|
@echo " ✅ Integration tests - Cross-component testing"
|
|
@echo " ✅ Functional tests - End-to-end workflows"
|
|
@echo " ✅ YAML validation - All activity files"
|
|
@echo " ✅ All specific test targets completed"
|
|
|
|
# Run unit tests only
|
|
.PHONY: test-unit
|
|
test-unit: venv
|
|
@echo "🔬 Running unit tests..."
|
|
@if command -v pytest >/dev/null 2>&1; then \
|
|
python -m pytest tests/unit/ -v --tb=short; \
|
|
else \
|
|
echo "📝 Running unit tests directly..."; \
|
|
python tests/unit/test_yaml_loading.py; \
|
|
python tests/unit/test_activity_yaml_validator.py; \
|
|
fi
|
|
|
|
# Run integration tests only
|
|
.PHONY: test-integration
|
|
test-integration: venv
|
|
@echo "🔗 Running integration tests..."
|
|
@if command -v pytest >/dev/null 2>&1; then \
|
|
python -m pytest tests/integration/ -v --tb=short; \
|
|
else \
|
|
echo "📝 Running integration tests directly..."; \
|
|
python tests/integration/test_multiple_activities.py; \
|
|
fi
|
|
|
|
# Run functional tests only
|
|
.PHONY: test-functional
|
|
test-functional: venv
|
|
@echo "⚡ Running functional tests..."
|
|
@if command -v pytest >/dev/null 2>&1; then \
|
|
python -m pytest tests/functional/ -v --tb=short; \
|
|
else \
|
|
echo "📝 Running functional tests directly..."; \
|
|
python tests/functional/test_activity_flows.py; \
|
|
python tests/functional/test_battleship_pre_script.py; \
|
|
fi
|
|
|
|
# ============================================================================
|
|
# SPECIFIC TEST COMMANDS
|
|
# ============================================================================
|
|
|
|
# Run YAML validator tests only
|
|
.PHONY: test-validator
|
|
test-validator: venv
|
|
@echo "📋 Running YAML validator tests..."
|
|
python tests/unit/test_activity_yaml_validator.py
|
|
|
|
# Run YAML loading tests only
|
|
.PHONY: test-yaml-loading
|
|
test-yaml-loading: venv
|
|
@echo "📄 Running YAML loading/parsing tests..."
|
|
python tests/unit/test_yaml_loading.py
|
|
|
|
# Run activity flow tests
|
|
.PHONY: test-activity-flows
|
|
test-activity-flows: venv
|
|
@echo "🔄 Running activity flow tests..."
|
|
python tests/functional/test_activity_flows.py
|
|
|
|
# Run battleship game tests
|
|
.PHONY: test-battleship
|
|
test-battleship: venv
|
|
@echo "🚢 Running battleship game tests..."
|
|
python tests/functional/test_battleship_pre_script.py
|
|
|
|
# Run guarded_ai functionality tests
|
|
.PHONY: test-guarded-ai
|
|
test-guarded-ai: venv
|
|
@echo "🛡️ Running guarded_ai.py functionality tests..."
|
|
python tests/integration/test_regression_fixes.py
|
|
|
|
# Run integration tests across all activity files
|
|
.PHONY: test-multiple-files
|
|
test-multiple-files: venv
|
|
@echo "📁 Running integration tests across all activity files..."
|
|
python tests/integration/test_multiple_activities.py
|
|
|
|
# ============================================================================
|
|
# VALIDATION COMMANDS
|
|
# ============================================================================
|
|
|
|
# Validate all YAML files
|
|
.PHONY: validate-yaml
|
|
validate-yaml: venv
|
|
@echo "📋 Validating all YAML files..."
|
|
python activity_yaml_validator.py research/*.yaml
|
|
|
|
# ============================================================================
|
|
# DEVELOPMENT AND CI/CD COMMANDS
|
|
# ============================================================================
|
|
|
|
# Run tests with coverage (requires pytest and coverage)
|
|
.PHONY: test-cov
|
|
test-cov: dev-setup
|
|
@echo "📊 Running tests with coverage..."
|
|
venv/bin/pip install pytest-cov
|
|
venv/bin/python -m pytest tests/ --cov=. --cov-report=html --cov-report=term-missing -v
|
|
|
|
|
|
# Format and lint code
|
|
.PHONY: format
|
|
format: dev-setup
|
|
@echo "🎨 Formatting code..."
|
|
venv/bin/black .
|
|
venv/bin/isort .
|
|
|
|
.PHONY: lint
|
|
lint: dev-setup
|
|
@echo "🔍 Linting code..."
|
|
venv/bin/black --check .
|
|
venv/bin/isort --check-only .
|
|
venv/bin/flake8 .
|
|
# Install development dependencies
|
|
.PHONY: dev-setup
|
|
dev-setup: venv
|
|
@echo "🛠️ Installing development dependencies..."
|
|
venv/bin/pip install black flake8 isort pytest coverage
|
|
@echo "✅ Development environment ready!"
|
|
|
|
# ============================================================================
|
|
# CI/CD AND AUTOMATION COMMANDS
|
|
# ============================================================================
|
|
|
|
# Full CI pipeline
|
|
.PHONY: ci
|
|
ci: clean test validate-yaml lint
|
|
@echo ""
|
|
@echo "🎯 CI Pipeline Results:"
|
|
@echo " ✅ Tests passed"
|
|
@echo " ✅ YAML validation passed"
|
|
@echo " ✅ Code linting completed"
|
|
@echo "🚀 Ready for deployment!"
|
|
|
|
|
|
# ============================================================================
|
|
# UTILITY COMMANDS
|
|
# ============================================================================
|
|
|
|
# Clean generated files
|
|
.PHONY: clean
|
|
clean:
|
|
@echo "🧹 Cleaning generated files..."
|
|
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
|
|
find . -name "*.pyc" -delete 2>/dev/null || true
|
|
find . -name "*.pyo" -delete 2>/dev/null || true
|
|
find . -name "*~" -delete 2>/dev/null || true
|
|
|
|
.PHONY: init-db
|
|
init-db:
|
|
@echo "🗄️ Initializing database tables..."
|
|
@if [ -f vars.sh ]; then \
|
|
. ./vars.sh && python init_db.py; \
|
|
echo "✅ Database tables created successfully"; \
|
|
else \
|
|
echo "❌ Error: vars.sh not found. Please create it from vars.sh.sample"; \
|
|
exit 1; \
|
|
fi
|
|
|
|
clean-cache:
|
|
rm -rf .pytest_cache/ 2>/dev/null || true
|
|
rm -rf htmlcov/ 2>/dev/null || true
|
|
rm -rf .coverage 2>/dev/null || true
|
|
rm -rf *.tmp 2>/dev/null || true
|
|
|
|
# Remove virtual environment
|
|
.PHONY: clean-all
|
|
clean-all: clean
|
|
@echo "💣 Removing virtual environment..."
|
|
rm -rf venv
|
|
|
|
# Show test structure
|
|
.PHONY: test-info
|
|
test-info:
|
|
@echo "📁 Test Structure:"
|
|
@echo " tests/"
|
|
@echo " ├── unit/ - Unit tests for individual components"
|
|
@echo " │ ├── test_yaml_loading.py - YAML loading/parsing tests"
|
|
@echo " │ └── test_activity_yaml_validator.py - Validator functionality tests"
|
|
@echo " ├── integration/ - Integration tests across components"
|
|
@echo " │ ├── test_multiple_activities.py - Tests across all activity files"
|
|
@echo " │ └── test_regression_fixes.py - Regression and fix validation"
|
|
@echo " └── functional/ - End-to-end functional tests"
|
|
@echo " ├── test_activity_flows.py - Complete activity workflows"
|
|
@echo " └── test_battleship_pre_script.py - Battleship game functionality"
|
|
@echo ""
|
|
@echo "🎯 Key Test Commands:"
|
|
@echo " make test - Run all tests"
|
|
@echo " make validate-yaml - Validate all YAML files"
|
|
# ============================================================================
|
|
# CODE EXECUTOR API TESTING
|
|
# ============================================================================
|
|
|
|
# Test artifact retrieval - compile C code, get base64 binary, decode and test execution
|
|
# URL can be overridden: make test-artifact URL=https://code.ai.unturf.com
|
|
.PHONY: test-artifact
|
|
test-artifact:
|
|
$(eval URL ?= http://127.0.0.1:8080)
|
|
@echo "=========================================="
|
|
@echo "Testing Binary Artifact Retrieval"
|
|
@echo "=========================================="
|
|
@echo "API: $(URL)"
|
|
@echo ""
|
|
@echo "Step 1: Compiling C code and retrieving base64 binary..."
|
|
@curl -s -X POST $(URL)/execute \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"language": "c", "code": "#include <stdio.h>\nint main() { printf(\"Hello from artifact!\\n\"); return 0; }", "return_artifact": true}' \
|
|
| jq -r '.stdout.artifact.data' > /tmp/artifact.b64
|
|
@echo "✓ Base64 artifact saved to /tmp/artifact.b64"
|
|
@echo " Size: $$(wc -c < /tmp/artifact.b64) bytes (base64)"
|
|
@echo ""
|
|
@echo "Step 2: Decoding base64 to binary..."
|
|
@base64 -d /tmp/artifact.b64 > /tmp/artifact_binary
|
|
@chmod +x /tmp/artifact_binary
|
|
@echo "✓ Binary decoded to /tmp/artifact_binary"
|
|
@echo " Size: $$(wc -c < /tmp/artifact_binary) bytes (ELF binary)"
|
|
@echo ""
|
|
@echo "Step 3: Verifying ELF binary..."
|
|
@file /tmp/artifact_binary
|
|
@echo ""
|
|
@echo "Step 4: Executing binary..."
|
|
@/tmp/artifact_binary
|
|
@echo ""
|
|
@echo "✓ Artifact test complete!"
|
|
@echo ""
|
|
@echo "Cleanup: rm /tmp/artifact.b64 /tmp/artifact_binary"
|