Test Environment Setup

This guide will help you set up a test environment for Arc Memory, allowing you to experiment with the tool without affecting your production repositories.

Overview

A proper test environment for Arc Memory includes:

  1. A test Git repository with realistic history
  2. A GitHub repository (optional, for GitHub integration)
  3. A virtual environment for Python dependencies
  4. Test data for various scenarios

Setting Up a Test Git Repository

Option 1: Create a New Repository

# Create a new directory
mkdir arc-test-repo
cd arc-test-repo

# Initialize Git repository
git init

# Create some initial files
echo "# Test Repository" > README.md
mkdir src
echo "def hello():\n    return 'Hello, world!'" > src/main.py
echo "from src.main import hello\n\ndef test_hello():\n    assert hello() == 'Hello, world!'" > test_main.py

# Create initial commit
git add .
git commit -m "Initial commit"

Option 2: Clone the Arc Memory Demo Repository

# Clone the demo repository
git clone https://github.com/Arc-Computer/arc-memory-demo.git
cd arc-memory-demo

Option 3: Use a Copy of an Existing Repository

# Create a copy of an existing repository
git clone --mirror https://github.com/your-org/your-repo.git repo-mirror
mkdir arc-test-repo
cd arc-test-repo
git init
git remote add origin ../repo-mirror
git fetch origin
git checkout -b main origin/main

Creating Test History

To create a realistic test history:

# Create a feature branch
git checkout -b feature/add-calculator

# Add a new file
mkdir -p src/calculator
cat > src/calculator/operations.py << EOF
def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

def divide(a, b):
    if b == 0:
        raise ValueError("Cannot divide by zero")
    return a / b
EOF

# Commit the new file
git add src/calculator/operations.py
git commit -m "Add basic calculator operations"

# Add tests
cat > test_calculator.py << EOF
from src.calculator.operations import add, subtract, multiply, divide
import pytest

def test_add():
    assert add(1, 2) == 3
    assert add(-1, 1) == 0

def test_subtract():
    assert subtract(5, 3) == 2
    assert subtract(3, 5) == -2

def test_multiply():
    assert multiply(2, 3) == 6
    assert multiply(-2, 3) == -6

def test_divide():
    assert divide(6, 3) == 2
    assert divide(5, 2) == 2.5
    
    with pytest.raises(ValueError):
        divide(1, 0)
EOF

# Commit the tests
git add test_calculator.py
git commit -m "Add tests for calculator operations"

# Update the main file to use the calculator
cat > src/main.py << EOF
from calculator.operations import add, subtract, multiply, divide

def hello():
    return 'Hello, world!'

def calculate(operation, a, b):
    if operation == 'add':
        return add(a, b)
    elif operation == 'subtract':
        return subtract(a, b)
    elif operation == 'multiply':
        return multiply(a, b)
    elif operation == 'divide':
        return divide(a, b)
    else:
        raise ValueError(f"Unknown operation: {operation}")
EOF

# Commit the update
git add src/main.py
git commit -m "Update main to use calculator operations"

# Merge the feature branch
git checkout main
git merge feature/add-calculator -m "Merge feature/add-calculator"

# Create another feature branch
git checkout -b feature/add-power-operation

# Add power operation
cat >> src/calculator/operations.py << EOF

def power(a, b):
    return a ** b
EOF

# Commit the new operation
git add src/calculator/operations.py
git commit -m "Add power operation"

# Add test for power operation
cat >> test_calculator.py << EOF

def test_power():
    assert power(2, 3) == 8
    assert power(3, 2) == 9
EOF

# Fix the import in the test file
sed -i '' '1s/from src.calculator.operations import add, subtract, multiply, divide/from src.calculator.operations import add, subtract, multiply, divide, power/' test_calculator.py

# Commit the test
git add test_calculator.py
git commit -m "Add test for power operation"

# Update main to use power operation
sed -i '' 's/from calculator.operations import add, subtract, multiply, divide/from calculator.operations import add, subtract, multiply, divide, power/' src/main.py
sed -i '' '/        return divide(a, b)/a\    elif operation == '\''power'\'':\n        return power(a, b)' src/main.py

# Commit the update
git add src/main.py
git commit -m "Update main to use power operation"

# Merge the feature branch
git checkout main
git merge feature/add-power-operation -m "Merge feature/add-power-operation"

Setting Up GitHub Integration (Optional)

If you want to test GitHub integration:

  1. Create a new repository on GitHub
  2. Add it as a remote to your local repository
  3. Push your local repository to GitHub
# Add GitHub remote
git remote add github https://github.com/your-username/arc-test-repo.git

# Push all branches and tags
git push -u github --all
git push github --tags
  1. Create some issues and pull requests on GitHub:
    • Create an issue for adding a new calculator feature
    • Create a pull request for a new feature branch
    • Reference issues in commit messages and pull requests

Setting Up a Python Virtual Environment

# Create a virtual environment
python -m venv venv

# Activate the virtual environment
# On Linux/macOS
source venv/bin/activate
# On Windows
venv\Scripts\activate

# Install Arc Memory
pip install arc-memory

# Install development dependencies
pip install pytest pytest-cov

Creating Test Data for Scenarios

Architecture Decision Records (ADRs)

Create some ADRs to test the ADR integration:

# Create ADR directory
mkdir -p docs/adr

# Create first ADR
cat > docs/adr/0001-calculator-architecture.md << EOF
# 1. Calculator Architecture

Date: 2023-01-15

## Status

Accepted

## Context

We need to implement a calculator with basic operations.

## Decision

We will implement the calculator with separate functions for each operation.

## Consequences

This will make the code more modular and testable.
EOF

# Create second ADR
cat > docs/adr/0002-add-power-operation.md << EOF
# 2. Add Power Operation

Date: 2023-01-20

## Status

Accepted

## Context

Users need to calculate powers in addition to basic operations.

## Decision

We will add a power operation to the calculator.

## Consequences

This will increase the functionality of the calculator.
EOF

# Commit the ADRs
git add docs/adr
git commit -m "Add ADRs for calculator architecture and power operation"

Running Arc Memory on the Test Repository

Now you can run Arc Memory on your test repository:

# Build the knowledge graph
arc build

# Check the status
arc doctor

# Trace the history of a file
arc trace file src/calculator/operations.py

# Show the decision trail for a line
arc why file src/calculator/operations.py 5

# Show related nodes for a commit
arc relate node commit:<commit-hash>

# Run a simulation
arc sim run

Testing Different Scenarios

Testing Incremental Builds

# Make some changes
echo "# More documentation" >> README.md
git commit -am "Update README"

# Run an incremental build
arc build --incremental

Testing GitHub Integration

# Authenticate with GitHub
arc auth gh

# Build with GitHub data
arc build --include-github

Testing Custom Plugins

# Create a custom plugin
mkdir -p plugins
cat > plugins/custom_plugin.py << EOF
from arc_memory.plugins import IngestorPlugin

class CustomPlugin(IngestorPlugin):
    def get_name(self):
        return "custom-plugin"
        
    def ingest(self, context):
        # Add custom nodes and edges
        context.add_node("custom", "test-node", {"name": "Test Node"})
        return True
EOF

# Install the plugin in development mode
pip install -e .

# Build with the custom plugin
arc build --plugins custom-plugin

Cleaning Up

When you’re done testing:

# Deactivate the virtual environment
deactivate

# Remove the Arc Memory database
rm -rf .arc

# Optionally, remove the test repository
cd ..
rm -rf arc-test-repo

See Also