Skip to content
Closed

WIP #67

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Integration Tests

on:
# Run on pushes to main branch
push:
branches:
- main
# Run on pull requests
pull_request:
branches:
- main
# Allow manual trigger
workflow_dispatch:
# Optional: Run nightly
# schedule:
# - cron: '0 2 * * *' # 2 AM UTC daily

jobs:
integration-test:
runs-on: ubuntu-latest

# Only run if INTEGRATION_TEST_TOKEN secret is set
if: ${{ secrets.INTEGRATION_TEST_TOKEN }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
run: |
pip install pytest

- name: Install GitHub CLI
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh -y

- name: Configure Git
run: |
git config --global user.name "ACP Integration Test"
git config --global user.email "[email protected]"

- name: Run integration tests
env:
GITHUB_TOKEN: ${{ secrets.INTEGRATION_TEST_TOKEN }}
# Override these if your test repos are different
# ACP_TEST_ORG: acp-integration-test
# ACP_TEST_REPO: test-repo
# ACP_TEST_UPSTREAM: upstream-repo
# ACP_TEST_FORK_OWNER: test-user
run: |
pytest test_integration.py -v -m integration --tb=short

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: integration-test-results
path: |
.pytest_cache/
test-results/
138 changes: 138 additions & 0 deletions QUICKSTART_INTEGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Quick Start: Integration Tests

Simple guide to run integration tests with your test repository.

## Prerequisites

1. ✅ Test repository created: `vbvictor/acp-integrational-testing`
2. ✅ GitHub personal access token with `repo` scope
3. ✅ `gh` CLI installed and authenticated

## Step 1: Authenticate GitHub CLI

```bash
gh auth login
# Follow prompts to authenticate
```

## Step 2: Set Your GitHub Token

```bash
export GITHUB_TOKEN=$(gh auth token)
```

Or use your personal token directly:
```bash

Check failure on line 25 in QUICKSTART_INTEGRATION.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines

QUICKSTART_INTEGRATION.md:25 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```bash"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md
export GITHUB_TOKEN="ghp_your_token_here"
```

## Step 3: Run Integration Tests

```bash
# Run all integration tests
pytest -m integration -v

# Run specific test
pytest test_integration.py::TestIntegrationNonFork::test_create_pr_interactive_non_fork -v -m integration

# Run with detailed output
pytest -m integration -v -s
```

## What the Tests Do

1. **test_create_pr_interactive_non_fork**:
- Clones your test repo
- Makes a change to `test_file.txt`
- Runs `acp pr` in interactive mode (`-i`)
- Verifies branch created
- Cleans up the branch

2. **test_create_pr_non_fork**:
- Clones your test repo
- Makes a change
- Runs `acp pr` to auto-create PR with `gh`
- Verifies PR created
- Closes the PR and cleans up

3. **test_verbose_output**:
- Tests verbose mode (`-v` flag)
- Verifies expected output messages

4. **test_commit_with_hook**:
- Creates a pre-commit hook
- Verifies it runs successfully

## Expected Output

```

Check failure on line 68 in QUICKSTART_INTEGRATION.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should have a language specified

QUICKSTART_INTEGRATION.md:68 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md040.md
test_integration.py::TestIntegrationNonFork::test_create_pr_interactive_non_fork PASSED
test_integration.py::TestIntegrationNonFork::test_create_pr_non_fork PASSED
test_integration.py::TestIntegrationVerbose::test_verbose_output PASSED
test_integration.py::TestIntegrationHooks::test_commit_with_hook PASSED

4 passed in 15.23s
```

## Troubleshooting

### "GITHUB_TOKEN not set"

Check failure on line 79 in QUICKSTART_INTEGRATION.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Headings should be surrounded by blank lines

QUICKSTART_INTEGRATION.md:79 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### "GITHUB_TOKEN not set""] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md022.md
```bash

Check failure on line 80 in QUICKSTART_INTEGRATION.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines

QUICKSTART_INTEGRATION.md:80 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```bash"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md
echo $GITHUB_TOKEN # Should print your token
export GITHUB_TOKEN="your_token"
```

### "Clone failed"

Check failure on line 85 in QUICKSTART_INTEGRATION.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Headings should be surrounded by blank lines

QUICKSTART_INTEGRATION.md:85 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### "Clone failed""] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md022.md
Make sure the repo exists:
```bash

Check failure on line 87 in QUICKSTART_INTEGRATION.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines

QUICKSTART_INTEGRATION.md:87 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```bash"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md
gh repo view vbvictor/acp-integrational-testing
```

### Authentication errors

Check failure on line 91 in QUICKSTART_INTEGRATION.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Headings should be surrounded by blank lines

QUICKSTART_INTEGRATION.md:91 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Authentication errors"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md022.md
Re-authenticate:
```bash

Check failure on line 93 in QUICKSTART_INTEGRATION.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines

QUICKSTART_INTEGRATION.md:93 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```bash"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md
gh auth login
gh auth status
```

### Tests leave branches

Check failure on line 98 in QUICKSTART_INTEGRATION.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Headings should be surrounded by blank lines

QUICKSTART_INTEGRATION.md:98 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Tests leave branches"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md022.md
Clean up manually:
```bash

Check failure on line 100 in QUICKSTART_INTEGRATION.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines

QUICKSTART_INTEGRATION.md:100 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```bash"] https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md031.md
# List branches
gh api repos/vbvictor/acp-integrational-testing/git/refs | grep acp

# Delete a branch
gh api -X DELETE repos/vbvictor/acp-integrational-testing/git/refs/heads/acp/vbvictor/123456
```

## Using Different Repository

If you want to use a different test repository:

```bash
export ACP_TEST_REPO_FULL="your-username/your-test-repo"
pytest -m integration -v
```

## Next Steps

Once these tests pass:
1. ✅ Your `acp` tool works with real GitHub!
2. You can add more test scenarios
3. Later: set up fork testing (requires forking a repo)
4. Later: add CI/CD (GitHub Actions)

## Quick Commands

```bash
# Run tests
export GITHUB_TOKEN=$(gh auth token)
pytest -m integration -v

# Clean up all test branches
gh api repos/vbvictor/acp-integrational-testing/git/refs \
| jq -r '.[] | select(.ref | contains("acp/")) | .ref' \
| while read ref; do
gh api -X DELETE "repos/vbvictor/acp-integrational-testing/git/$ref"
done
```
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,17 @@ Create a virtual environment, install dev dependencies, and run tests:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e ".[dev]"
pytest test_acp.py -v

# Run unit tests (fast, no GitHub token needed)
pytest

# Run integration tests (requires GitHub token and test repos)
export GITHUB_TOKEN="your_token"
pytest -m integration
```

See [docs/INTEGRATION_TESTING.md](docs/INTEGRATION_TESTING.md) for setting up integration tests with real GitHub repositories.

### Submit your PR

Use `acp` itself to create your PR:
Expand Down
39 changes: 39 additions & 0 deletions docker/Dockerfile.integration
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Dockerfile for running acp integration tests
#
# Build: docker build -f docker/Dockerfile.integration -t acp-integration-test .
# Run: docker run --rm -e GITHUB_TOKEN=$GITHUB_TOKEN acp-integration-test

FROM python:3.11-slim

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
&& rm -rf /var/lib/apt/lists/*

# Install GitHub CLI
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& apt-get update \
&& apt-get install -y gh \
&& rm -rf /var/lib/apt/lists/*

# Set up working directory
WORKDIR /app

# Copy requirements (if any) and install Python dependencies
COPY requirements*.txt* ./
RUN pip install --no-cache-dir pytest || true

# Copy application code
COPY acp.py .
COPY test_integration.py .
COPY test_acp.py .

# Set git configuration
RUN git config --global user.name "ACP Integration Test" \
&& git config --global user.email "[email protected]"

# Run integration tests by default
CMD ["pytest", "test_integration.py", "-v", "-m", "integration", "--tb=short"]
69 changes: 69 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Docker Setup for ACP Integration Tests

This directory contains Docker configuration for running ACP integration tests in an isolated environment.

## Quick Start

```bash
# Set your GitHub token
export GITHUB_TOKEN="your_github_token"

# Run tests with Docker Compose
docker-compose -f docker/docker-compose.integration.yml up --build
```

## Files

- **Dockerfile.integration**: Docker image with Python, git, and gh CLI
- **docker-compose.integration.yml**: Compose configuration for easy test execution

## Usage

### Building the Image

```bash
docker build -f docker/Dockerfile.integration -t acp-integration-test .
```

### Running Tests

**With Docker:**
```bash
docker run --rm \
-e GITHUB_TOKEN="$GITHUB_TOKEN" \
-e ACP_TEST_ORG="your-test-org" \
-e ACP_TEST_FORK_OWNER="your-username" \
acp-integration-test
```

**With Docker Compose:**
```bash
# Run all tests
docker-compose -f docker/docker-compose.integration.yml up

# Run specific test
docker-compose -f docker/docker-compose.integration.yml run --rm integration-test \
pytest test_integration.py::TestIntegrationNonFork -v
```

## Environment Variables

- `GITHUB_TOKEN` (required): Your GitHub personal access token
- `ACP_TEST_ORG` (optional): Test organization name (default: acp-integration-test)
- `ACP_TEST_REPO` (optional): Non-fork test repo (default: test-repo)
- `ACP_TEST_UPSTREAM` (optional): Upstream repo for fork tests (default: upstream-repo)
- `ACP_TEST_FORK_OWNER` (optional): Fork owner username (default: test-user)

## Development

The docker-compose setup mounts source files as read-only volumes, so you can edit code locally and re-run tests without rebuilding:

```bash
# Edit acp.py or test_integration.py locally
vim acp.py

# Re-run tests (no rebuild needed)
docker-compose -f docker/docker-compose.integration.yml run --rm integration-test
```

For more information, see [docs/INTEGRATION_TESTING.md](../docs/INTEGRATION_TESTING.md).
20 changes: 20 additions & 0 deletions docker/docker-compose.integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.8'

services:
integration-test:
build:
context: ..
dockerfile: docker/Dockerfile.integration
environment:
# Pass GitHub token from host environment
- GITHUB_TOKEN=${GITHUB_TOKEN}
# Optionally override test repository configuration
- ACP_TEST_ORG=${ACP_TEST_ORG:-acp-integration-test}
- ACP_TEST_REPO=${ACP_TEST_REPO:-test-repo}
- ACP_TEST_UPSTREAM=${ACP_TEST_UPSTREAM:-upstream-repo}
- ACP_TEST_FORK_OWNER=${ACP_TEST_FORK_OWNER:-test-user}
volumes:
# Mount source code for development
- ../acp.py:/app/acp.py:ro
- ../test_integration.py:/app/test_integration.py:ro
command: pytest test_integration.py -v -m integration --tb=short
Loading
Loading