Upload Scripts & Testing
Upload Scripts & Testing
Section titled “Upload Scripts & Testing”ERA Agent includes helper scripts for uploading multi-file projects and comprehensive testing tools. All scripts are production-ready and fully tested.
Upload Scripts
Section titled “Upload Scripts”Bash Upload Script
Section titled “Bash Upload Script”Fast, simple bash script for uploading projects. Works on macOS and Linux.
Location: era-upload.sh
Features:
- Sequential file uploads
- Color-coded progress output
- Automatic exclusion of build artifacts
- Error tracking and logging
- Works with all project types
Usage:
# Basic usage./era-upload.sh <session_id> <project_directory>
# With custom API URL./era-upload.sh my-session ./my-project https://era-agent.your-domain.workers.dev
# Using environment variable for APIexport ERA_API_URL="https://era-agent.your-domain.workers.dev"./era-upload.sh my-session ./my-projectExample Output:
📦 ERA Agent Project Upload━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Session ID: my-sessionDirectory: ./my-projectAPI URL: https://anewera.dev
🔍 Scanning for files...📁 Found 15 files to upload
📤 Uploading files...✅ [1/15] src/index.js✅ [2/15] src/utils/helpers.js✅ [3/15] src/utils/validators.js...✅ [15/15] README.md
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━✨ Upload complete! ✅ Successfully uploaded: 15 files
Next steps: 1. Check files: curl https://anewera.dev/api/sessions/my-session/files 2. Run code: curl -X POST https://anewera.dev/api/sessions/my-session/run -d '{"code": "..."}' 3. View logs: curl https://anewera.dev/api/sessions/my-sessionExcluded Patterns:
The script automatically excludes:
node_modules/,.git/,.venv/,venv/__pycache__/,dist/,build/,.next/.cache/,coverage/,.DS_Store.env,.env.local,.env.production,.env.developmentsecrets.*,credentials.json
Python Upload Script
Section titled “Python Upload Script”Advanced Python script with parallel uploads for faster deployment of large projects.
Location: era_upload.py
Features:
- 10 parallel uploads for speed
- Progress tracking with file sizes
- Upload speed metrics (MB/s)
- Comprehensive error reporting
- Cross-platform (Windows, macOS, Linux)
Requirements:
pip install requestsUsage:
# Basic usagepython3 era_upload.py <session_id> <project_directory>
# With custom API URLpython3 era_upload.py my-session ./my-project https://era-agent.your-domain.workers.dev
# Using environment variableexport ERA_API_URL="https://era-agent.your-domain.workers.dev"python3 era_upload.py my-session ./my-projectExample Output:
📦 ERA Agent Project Upload============================================================Session ID: my-sessionDirectory: ./my-projectAPI URL: https://anewera.dev
🔍 Scanning for files...📁 Found 47 files (2.3MB total)
📤 Uploading files...✅ [1/47] src/index.js✅ [2/47] src/utils/helpers.js✅ [3/47] package.json...✅ [47/47] README.md
============================================================✨ Upload complete! ✅ Successfully uploaded: 47 files (2.3MB)
⏱️ Duration: 12.3s📊 Average speed: 191.5KB/s
Next steps: 1. Check files: curl https://anewera.dev/api/sessions/my-session/files 2. Run code: curl -X POST https://anewera.dev/api/sessions/my-session/run -d '{"code": "..."}' 3. View logs: curl https://anewera.dev/api/sessions/my-sessionPerformance:
For large projects, the Python script is significantly faster due to parallel uploads:
- Small project (5-10 files): ~2-3 seconds
- Medium project (20-50 files): ~5-10 seconds
- Large project (100+ files): ~15-30 seconds
Testing Scripts
Section titled “Testing Scripts”Upload Scripts Test
Section titled “Upload Scripts Test”Validates that both upload scripts work correctly with all supported languages.
Location: test-upload-scripts.sh
What it tests:
- Bash script with JavaScript project
- Python script with TypeScript project
- Python script with Python project
- Bash script with Deno project
Usage:
chmod +x test-upload-scripts.sh./test-upload-scripts.shOutput:
========================================ERA Upload Scripts Test========================================Test 1: Bash Upload Script (JS)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━✅ Session created: test-bash-js-1234Uploading files...✅ Bash upload successful✅ Found 3 files uploaded
Test 2: Python Upload Script (TS)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━✅ Session created: test-py-ts-1234Uploading files...✅ Python upload successful✅ Found 3 files uploaded✅ Code executed successfully
...
========================================Test Results========================================✅ Passed: 4❌ Failed: 0🎉 All upload tests passed!Multi-Language Test Suite
Section titled “Multi-Language Test Suite”Comprehensive test suite that validates complete workflows with dependencies for all languages.
Location: test-multi-lang.sh
What it tests:
- JavaScript with npm dependencies (lodash)
- TypeScript with npm dependencies (axios)
- Python with pip dependencies (requests)
- Deno with native TypeScript
- Both bash and Python upload scripts
Usage:
chmod +x test-multi-lang.sh./test-multi-lang.shExample Test Projects
Section titled “Example Test Projects”Test projects are created in /tmp/era-tests/:
JavaScript Project
Section titled “JavaScript Project”/tmp/era-tests/js-project/├── package.json # lodash dependency├── index.js # Main entry point└── utils/ └── math.js # Utility functionsTypeScript Project
Section titled “TypeScript Project”/tmp/era-tests/ts-project/├── package.json # axios dependency├── index.ts # Main entry point└── utils/ └── string.ts # Type-safe utilitiesPython Project
Section titled “Python Project”/tmp/era-tests/py-project/├── requirements.txt # requests dependency├── main.py # Main entry point└── utils/ ├── __init__.py # Package init ├── math.py # Math utilities └── string.py # String utilitiesDeno Project
Section titled “Deno Project”/tmp/era-tests/deno-project/├── main.ts # Main entry point└── utils/ └── helpers.ts # Deno-style importsCreating Your Own Tests
Section titled “Creating Your Own Tests”Simple Test Template
Section titled “Simple Test Template”#!/bin/bash# test-my-project.sh
SESSION_ID="my-test-$(date +%s)"API_URL="https://anewera.dev"
echo "Creating session..."curl -X POST "$API_URL/api/sessions" \-H "Content-Type: application/json" \-d '{ "language": "node", "session_id": "'$SESSION_ID'", "persistent": true}'
echo "Uploading files..."./era-upload.sh "$SESSION_ID" ./my-project
echo "Running code..."curl -X POST "$API_URL/api/sessions/$SESSION_ID/run" \-H "Content-Type: application/json" \-d '{"code": "require("./index.js")"}' | jq '.'
echo "Test complete!"Test with Dependencies
Section titled “Test with Dependencies”#!/bin/bash# test-with-deps.sh
SESSION_ID="my-test-$(date +%s)"API_URL="https://anewera.dev"
# Create with dependenciesecho "Creating session with dependencies..."curl -X POST "$API_URL/api/sessions" \-H "Content-Type: application/json" \-d '{ "language": "node", "session_id": "'$SESSION_ID'", "persistent": true, "setup": { "npm": ["express", "lodash"] }}'
# Wait for setupecho "Waiting for package installation..."while true; doSTATUS=$(curl -s "$API_URL/api/sessions/$SESSION_ID" | jq -r '.setup_status')echo " Status: $STATUS"
if [ "$STATUS" = "completed" ]; then echo "✅ Setup complete!" breakelif [ "$STATUS" = "failed" ]; then echo "❌ Setup failed!" curl -s "$API_URL/api/sessions/$SESSION_ID" | jq '.setup_result' exit 1fi
sleep 5done
# Upload and run./era-upload.sh "$SESSION_ID" ./my-projectcurl -X POST "$API_URL/api/sessions/$SESSION_ID/run" \-H "Content-Type: application/json" \-d '{"code": "require("./server.js")"}' | jq '.'Continuous Integration
Section titled “Continuous Integration”GitHub Actions Example
Section titled “GitHub Actions Example”name: Deploy to ERA Agent
on:push: branches: [main]
jobs:deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
- name: Install Python uses: actions/setup-python@v4 with: python-version: '3.11'
- name: Install dependencies run: pip install requests
- name: Download upload script run: | curl -O https://raw.githubusercontent.com/your-org/era-tools/main/era_upload.py chmod +x era_upload.py
- name: Create session run: | curl -X POST ${{ secrets.ERA_API_URL }}/api/sessions \ -H "Content-Type: application/json" \ -d '{ "language": "node", "session_id": "prod-${{ github.sha }}", "persistent": true, "setup": { "npm": ["express", "body-parser"] } }'
- name: Wait for setup run: | while true; do STATUS=$(curl -s ${{ secrets.ERA_API_URL }}/api/sessions/prod-${{ github.sha }} | jq -r '.setup_status') [ "$STATUS" = "completed" ] && break sleep 5 done
- name: Upload project run: python3 era_upload.py prod-${{ github.sha }} .
- name: Update code run: | curl -X PUT ${{ secrets.ERA_API_URL }}/api/sessions/prod-${{ github.sha }}/code \ -H "Content-Type: application/json" \ -d '{"code": "require("./server.js")"}'
- name: Get deployment URL run: | curl ${{ secrets.ERA_API_URL }}/api/sessions/prod-${{ github.sha }}/host?port=3000Troubleshooting
Section titled “Troubleshooting”Upload Fails for Large Files
Section titled “Upload Fails for Large Files”Problem: Upload times out or fails for files > 10MB
Solution:
- Use Python script with parallel uploads
- Exclude unnecessary large files (videos, images, datasets)
- Upload large data files separately via API
Permission Denied
Section titled “Permission Denied”Problem: ./era-upload.sh: Permission denied
Solution:
chmod +x era-upload.shchmod +x era_upload.pyConnection Refused
Section titled “Connection Refused”Problem: Can’t connect to API URL
Solution:
# Test API connectivitycurl https://anewera.dev/health
# Verify API URL is correctecho $ERA_API_URLFiles Not Found After Upload
Section titled “Files Not Found After Upload”Problem: Files uploaded but not visible in session
Solution:
# List files to verifycurl https://anewera.dev/api/sessions/my-session/files
# Check if session is persistentcurl https://anewera.dev/api/sessions/my-session | jq '.persistent'Best Practices
Section titled “Best Practices”1. Test Locally First
Section titled “1. Test Locally First”Always test your project works locally before deploying:
cd my-projectnpm install # or pip install -r requirements.txtnode index.js # Verify it runs2. Use Version Control
Section titled “2. Use Version Control”Tag deployments for easy rollback:
# Create session with git commit hashSESSION_ID="prod-$(git rev-parse --short HEAD)"./era-upload.sh "$SESSION_ID" .3. Validate After Upload
Section titled “3. Validate After Upload”Always check files were uploaded correctly:
# Quick validationFILE_COUNT=$(curl -s "$API_URL/api/sessions/$SESSION_ID/files" | jq '.files | length')echo "Uploaded $FILE_COUNT files"
# List all filescurl -s "$API_URL/api/sessions/$SESSION_ID/files" | jq '.files[].path'4. Use Python Script for Large Projects
Section titled “4. Use Python Script for Large Projects”For projects with 50+ files, the Python script’s parallel uploads are significantly faster:
# Small projects (< 20 files): Either script works./era-upload.sh my-session ./small-project
# Large projects (50+ files): Use Python scriptpython3 era_upload.py my-session ./large-projectNext Steps
Section titled “Next Steps”- See Language Examples for complete project examples
- Learn about Multi-File Projects for deployment workflows
- Check Code Management for updating deployed code