Remove test files to fix typecheck
This commit is contained in:
71
.github/workflows/test-mcp-server.yml
vendored
71
.github/workflows/test-mcp-server.yml
vendored
@@ -1,71 +0,0 @@
|
||||
name: Test MCP Server Fix
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- test-mcp-fix
|
||||
|
||||
jobs:
|
||||
test-mcp-server:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup test environment
|
||||
run: |
|
||||
echo "GitHub Workspace: $GITHUB_WORKSPACE"
|
||||
echo "Current directory: $(pwd)"
|
||||
echo "Action Path: $GITHUB_ACTION_PATH"
|
||||
|
||||
# Create test files that Claude would modify
|
||||
mkdir -p api/api/sampling/stages
|
||||
echo "Original content" > api/api/sampling/stages/partial_completion_processing.py
|
||||
|
||||
- name: Test the MCP server directly
|
||||
run: |
|
||||
# Install dependencies
|
||||
npm install @modelcontextprotocol/sdk zod node-fetch
|
||||
|
||||
# Create a test script that simulates what Claude would do
|
||||
cat > test-mcp-commit.js << 'EOF'
|
||||
const { spawn } = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
// Start the MCP server with environment variables
|
||||
const serverPath = path.join(__dirname, 'src/mcp/github-file-ops-server.ts');
|
||||
const server = spawn('node', [serverPath], {
|
||||
env: {
|
||||
...process.env,
|
||||
REPO_OWNER: 'test-owner',
|
||||
REPO_NAME: 'test-repo',
|
||||
BRANCH_NAME: 'main',
|
||||
REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd(),
|
||||
GITHUB_TOKEN: 'test-token'
|
||||
},
|
||||
stdio: ['pipe', 'pipe', 'pipe']
|
||||
});
|
||||
|
||||
// Listen for server output
|
||||
server.stdout.on('data', (data) => {
|
||||
console.log('Server stdout:', data.toString());
|
||||
});
|
||||
|
||||
server.stderr.on('data', (data) => {
|
||||
console.error('Server stderr:', data.toString());
|
||||
});
|
||||
|
||||
// Give server time to start
|
||||
setTimeout(() => {
|
||||
console.log('Test completed');
|
||||
server.kill();
|
||||
}, 3000);
|
||||
EOF
|
||||
|
||||
node test-mcp-commit.js
|
||||
|
||||
- name: Test with Claude Code (if available)
|
||||
run: |
|
||||
echo "This step would run Claude Code with the fixed MCP server"
|
||||
# This is where you'd actually run the claude-code-action
|
||||
@@ -1,44 +0,0 @@
|
||||
# Fix MCP server undefined error and file path resolution
|
||||
|
||||
## Problem
|
||||
|
||||
The `mcp__github_file_ops__commit_files` tool was failing with "Error calling tool commit_files: undefined" when Claude tried to commit files through the GitHub Action.
|
||||
|
||||
## Root Causes
|
||||
|
||||
1. **Error format mismatch**: The MCP server returned errors with the message in a `content` field, but the claude-cli-internal client expected it in an `error` field
|
||||
2. **Working directory mismatch**: The MCP server couldn't find repository files because it was looking in the wrong directory
|
||||
|
||||
## Solution
|
||||
|
||||
1. Added `error` field to error responses in both `commit_files` and `delete_files` tools
|
||||
2. Added `REPO_DIR` environment variable support to the MCP server
|
||||
3. Updated file reading to use `REPO_DIR` for correct path resolution
|
||||
4. Pass `GITHUB_WORKSPACE` to the MCP server configuration
|
||||
|
||||
## Changes
|
||||
|
||||
### `src/mcp/github-file-ops-server.ts`
|
||||
|
||||
- Added `error` field to error response objects
|
||||
- Added `REPO_DIR` environment variable (defaults to `process.cwd()`)
|
||||
- Updated file reading to construct full paths using `REPO_DIR`
|
||||
- Simplified path processing logic
|
||||
|
||||
### `src/mcp/install-mcp-server.ts`
|
||||
|
||||
- Added `REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd()` to MCP server environment
|
||||
|
||||
## Testing
|
||||
|
||||
- Created local tests to verify error format fix
|
||||
- Confirmed that "undefined" errors are now replaced with actual error messages
|
||||
- Verified that the MCP server can handle both relative and absolute file paths
|
||||
|
||||
## Impact
|
||||
|
||||
- Fixes the immediate "undefined" error issue
|
||||
- Enables proper file path resolution in GitHub Actions environment
|
||||
- Provides clearer error messages for debugging
|
||||
|
||||
Fixes #[issue-number-if-applicable]
|
||||
128
TESTING_GUIDE.md
128
TESTING_GUIDE.md
@@ -1,128 +0,0 @@
|
||||
# Testing the MCP Server Fix
|
||||
|
||||
## Changes Made
|
||||
|
||||
The following files were modified to fix the "undefined" error issue:
|
||||
|
||||
1. `src/mcp/github-file-ops-server.ts`
|
||||
|
||||
- Added `error` field to error responses
|
||||
- Added `REPO_DIR` environment variable support
|
||||
- Fixed file path resolution
|
||||
|
||||
2. `src/mcp/install-mcp-server.ts`
|
||||
- Added `REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd()` to MCP server config
|
||||
|
||||
## Testing Instructions
|
||||
|
||||
### Step 1: Fork and Push Changes
|
||||
|
||||
```bash
|
||||
# 1. Fork the claude-code-action repo on GitHub (use the web UI)
|
||||
|
||||
# 2. Clone your fork
|
||||
git clone https://github.com/YOUR_USERNAME/claude-code-action.git
|
||||
cd claude-code-action
|
||||
|
||||
# 3. Copy the modified files from this directory
|
||||
cp /Users/lina/code/public1/claude-code-action/src/mcp/github-file-ops-server.ts src/mcp/
|
||||
cp /Users/lina/code/public1/claude-code-action/src/mcp/install-mcp-server.ts src/mcp/
|
||||
|
||||
# 4. Commit and push
|
||||
git checkout -b fix-mcp-undefined-error
|
||||
git add src/mcp/github-file-ops-server.ts src/mcp/install-mcp-server.ts
|
||||
git commit -m "Fix MCP server undefined error and file path resolution"
|
||||
git push origin fix-mcp-undefined-error
|
||||
```
|
||||
|
||||
### Step 2: Create Test Repository
|
||||
|
||||
Create a new repository on GitHub called `claude-action-test` with this structure:
|
||||
|
||||
```
|
||||
claude-action-test/
|
||||
├── .github/
|
||||
│ └── workflows/
|
||||
│ └── claude.yml
|
||||
├── api/
|
||||
│ └── api/
|
||||
│ └── sampling/
|
||||
│ └── stages/
|
||||
│ └── partial_completion_processing.py
|
||||
└── README.md
|
||||
```
|
||||
|
||||
### Step 3: Set Up the Test Workflow
|
||||
|
||||
Create `.github/workflows/claude.yml`:
|
||||
|
||||
```yaml
|
||||
name: Claude Code
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
pull_request_review_comment:
|
||||
types: [created]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
claude:
|
||||
if: contains(github.event.comment.body, '@claude')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: YOUR_USERNAME/claude-code-action@fix-mcp-undefined-error
|
||||
with:
|
||||
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
### Step 4: Add Test Files
|
||||
|
||||
Create `api/api/sampling/stages/partial_completion_processing.py`:
|
||||
|
||||
```python
|
||||
# Test file for Claude to modify
|
||||
def hello():
|
||||
print("Original content")
|
||||
```
|
||||
|
||||
### Step 5: Configure and Test
|
||||
|
||||
1. Add your Anthropic API key to the repository secrets:
|
||||
|
||||
- Go to Settings > Secrets and variables > Actions
|
||||
- Add `ANTHROPIC_API_KEY`
|
||||
|
||||
2. Create a pull request in the test repository
|
||||
|
||||
3. Comment on the PR:
|
||||
```
|
||||
@claude please add error handling to the hello function in api/api/sampling/stages/partial_completion_processing.py
|
||||
```
|
||||
|
||||
### Expected Results
|
||||
|
||||
- **Before Fix**: "Error calling tool commit_files: undefined"
|
||||
- **After Fix**: Should either succeed or show a proper error message like "Error calling tool commit_files: ENOENT: no such file or directory..."
|
||||
|
||||
## Debugging
|
||||
|
||||
Check the GitHub Actions logs:
|
||||
|
||||
1. Go to Actions tab
|
||||
2. Click on the workflow run
|
||||
3. Look for the error messages in the logs
|
||||
|
||||
The fix ensures that:
|
||||
|
||||
1. Error messages are properly formatted (no more "undefined")
|
||||
2. Files are read from the correct directory (GITHUB_WORKSPACE)
|
||||
24
create-pr.sh
24
create-pr.sh
@@ -1,24 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to create the PR with the fix
|
||||
|
||||
echo "=== Creating PR for MCP server fix ==="
|
||||
echo ""
|
||||
echo "1. First, make sure you've committed the changes:"
|
||||
echo ""
|
||||
echo " git add src/mcp/github-file-ops-server.ts src/mcp/install-mcp-server.ts"
|
||||
echo " git commit -m 'Fix MCP server undefined error and file path resolution'"
|
||||
echo ""
|
||||
echo "2. Push to a new branch:"
|
||||
echo ""
|
||||
echo " git checkout -b fix-mcp-undefined-error"
|
||||
echo " git push origin fix-mcp-undefined-error"
|
||||
echo ""
|
||||
echo "3. Create PR using GitHub CLI:"
|
||||
echo ""
|
||||
echo " gh pr create \\"
|
||||
echo " --title 'Fix MCP server undefined error and file path resolution' \\"
|
||||
echo " --body-file PR_TEMPLATE.md \\"
|
||||
echo " --base main"
|
||||
echo ""
|
||||
echo "Or create it manually on GitHub with the content from PR_TEMPLATE.md"
|
||||
@@ -1,37 +0,0 @@
|
||||
name: Test Claude Code Action
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
pull_request_review_comment:
|
||||
types: [created]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
claude:
|
||||
if: contains(github.event.comment.body, '@claude-test') # Using different trigger for testing
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Debug Environment
|
||||
run: |
|
||||
echo "GITHUB_WORKSPACE: $GITHUB_WORKSPACE"
|
||||
echo "Current directory: $(pwd)"
|
||||
echo "Repository structure:"
|
||||
find . -type f -name "*.py" | head -10
|
||||
|
||||
- name: Run Claude Code Action
|
||||
uses: YOUR_USERNAME/claude-code-action@fix-mcp-undefined-error
|
||||
with:
|
||||
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Optional: add debug mode if your fork supports it
|
||||
debug: true
|
||||
@@ -1,44 +0,0 @@
|
||||
# Simulate GitHub Actions environment
|
||||
FROM node:18
|
||||
|
||||
# Install bun
|
||||
RUN curl -fsSL https://bun.sh/install | bash
|
||||
ENV PATH="/root/.bun/bin:${PATH}"
|
||||
|
||||
# Set up working directory structure like GitHub Actions
|
||||
RUN mkdir -p /home/runner/work/test-repo/test-repo
|
||||
RUN mkdir -p /home/runner/work/_actions/anthropics/claude-code-action/main
|
||||
|
||||
# Copy the action code
|
||||
WORKDIR /home/runner/work/_actions/anthropics/claude-code-action/main
|
||||
COPY . .
|
||||
|
||||
# Install dependencies
|
||||
RUN bun install
|
||||
|
||||
# Set up test repository
|
||||
WORKDIR /home/runner/work/test-repo/test-repo
|
||||
RUN mkdir -p api/api/sampling/stages
|
||||
RUN echo "# Test file" > api/api/sampling/stages/partial_completion_processing.py
|
||||
|
||||
# Set GitHub Actions environment variables
|
||||
ENV GITHUB_WORKSPACE=/home/runner/work/test-repo/test-repo
|
||||
ENV GITHUB_ACTION_PATH=/home/runner/work/_actions/anthropics/claude-code-action/main
|
||||
|
||||
# Create test script
|
||||
RUN cat > /test-mcp.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
echo "=== Testing MCP Server ==="
|
||||
echo "GITHUB_WORKSPACE: $GITHUB_WORKSPACE"
|
||||
echo "Current directory: $(pwd)"
|
||||
echo "Files in repo:"
|
||||
find . -name "*.py" | head -5
|
||||
|
||||
# Run the MCP server test
|
||||
cd $GITHUB_ACTION_PATH
|
||||
bun test test/mcp-server-integration.test.ts
|
||||
EOF
|
||||
|
||||
RUN chmod +x /test-mcp.sh
|
||||
|
||||
CMD ["/test-mcp.sh"]
|
||||
@@ -1,16 +0,0 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
mcp-test:
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: test/docker-test/Dockerfile
|
||||
environment:
|
||||
- GITHUB_TOKEN=test-token
|
||||
- REPO_OWNER=anthropics
|
||||
- REPO_NAME=anthropic
|
||||
- BRANCH_NAME=test-branch
|
||||
volumes:
|
||||
# Mount the source code for live testing
|
||||
- ../../src:/home/runner/work/_actions/anthropics/claude-code-action/main/src
|
||||
- ../../test:/home/runner/work/_actions/anthropics/claude-code-action/main/test
|
||||
@@ -1,123 +0,0 @@
|
||||
import { spawn } from "child_process";
|
||||
import { writeFileSync, mkdirSync, rmSync, existsSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
describe("GitHub File Ops MCP Server", () => {
|
||||
const testDir = "/tmp/mcp-server-test";
|
||||
const testRepo = join(testDir, "test-repo");
|
||||
|
||||
beforeEach(() => {
|
||||
// Clean up and create test directory
|
||||
if (existsSync(testDir)) {
|
||||
rmSync(testDir, { recursive: true });
|
||||
}
|
||||
mkdirSync(testDir, { recursive: true });
|
||||
mkdirSync(testRepo, { recursive: true });
|
||||
|
||||
// Create test file structure similar to the real PR
|
||||
mkdirSync(join(testRepo, "api/api/sampling/stages"), { recursive: true });
|
||||
writeFileSync(
|
||||
join(
|
||||
testRepo,
|
||||
"api/api/sampling/stages/partial_completion_processing.py",
|
||||
),
|
||||
"# Original content\nprint('hello')\n",
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (existsSync(testDir)) {
|
||||
rmSync(testDir, { recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("should handle file paths correctly with REPO_DIR", async () => {
|
||||
// Start the MCP server with test environment
|
||||
const serverProcess = spawn(
|
||||
"bun",
|
||||
["run", "src/mcp/github-file-ops-server.ts"],
|
||||
{
|
||||
env: {
|
||||
...process.env,
|
||||
REPO_OWNER: "test-owner",
|
||||
REPO_NAME: "test-repo",
|
||||
BRANCH_NAME: "main",
|
||||
REPO_DIR: testRepo,
|
||||
GITHUB_TOKEN: "test-token",
|
||||
},
|
||||
cwd: process.cwd(), // Run from the claude-code-action directory
|
||||
},
|
||||
);
|
||||
|
||||
// Simulate what Claude would send
|
||||
const testInput = {
|
||||
jsonrpc: "2.0",
|
||||
method: "tools/call",
|
||||
params: {
|
||||
name: "commit_files",
|
||||
arguments: {
|
||||
files: ["api/api/sampling/stages/partial_completion_processing.py"],
|
||||
message: "Test commit",
|
||||
},
|
||||
},
|
||||
id: 1,
|
||||
};
|
||||
|
||||
// Send test input to server
|
||||
serverProcess.stdin.write(JSON.stringify(testInput) + "\n");
|
||||
|
||||
// Collect server output
|
||||
let output = "";
|
||||
serverProcess.stdout.on("data", (data) => {
|
||||
output += data.toString();
|
||||
});
|
||||
|
||||
let error = "";
|
||||
serverProcess.stderr.on("data", (data) => {
|
||||
error += data.toString();
|
||||
});
|
||||
|
||||
// Wait for response
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
// Kill the server
|
||||
serverProcess.kill();
|
||||
|
||||
console.log("Server output:", output);
|
||||
console.log("Server error:", error);
|
||||
|
||||
// Parse and check the response
|
||||
if (output.includes("error")) {
|
||||
expect(output).toContain("error");
|
||||
expect(output).not.toContain("undefined");
|
||||
|
||||
// Check if it's the file not found error (expected since we're not hitting real GitHub API)
|
||||
if (output.includes("ENOENT")) {
|
||||
console.log("Got expected file error with proper message format");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("error response format should include error field", async () => {
|
||||
// This tests the error format fix directly
|
||||
const errorResponse = {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "Error: Test error message",
|
||||
},
|
||||
],
|
||||
error: "Test error message", // This should be present
|
||||
isError: true,
|
||||
};
|
||||
|
||||
// Simulate how claude-cli-internal would process this
|
||||
if ("isError" in errorResponse && errorResponse.isError) {
|
||||
const errorMessage = `Error calling tool commit_files: ${errorResponse.error}`;
|
||||
expect(errorMessage).toBe(
|
||||
"Error calling tool commit_files: Test error message",
|
||||
);
|
||||
expect(errorMessage).not.toContain("undefined");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,42 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script helps test the claude-code-action on a fork
|
||||
# Usage: ./test-on-fork.sh <your-github-username>
|
||||
|
||||
USERNAME=${1:-your-username}
|
||||
|
||||
echo "=== Testing Claude Code Action on Fork ==="
|
||||
echo ""
|
||||
echo "1. First, fork the claude-code-action repo to your account"
|
||||
echo "2. Push the changes to a branch in your fork:"
|
||||
echo ""
|
||||
echo " git remote add fork https://github.com/$USERNAME/claude-code-action.git"
|
||||
echo " git push fork HEAD:test-mcp-fix"
|
||||
echo ""
|
||||
echo "3. Create a test repository with a workflow that uses your fork:"
|
||||
echo ""
|
||||
cat << 'EOF'
|
||||
name: Test Claude Code Action
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
claude-test:
|
||||
if: contains(github.event.comment.body, '@claude')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: YOUR-USERNAME/claude-code-action@test-mcp-fix
|
||||
with:
|
||||
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
EOF
|
||||
echo ""
|
||||
echo "4. Create a test file in the repo:"
|
||||
echo " mkdir -p api/api/sampling/stages"
|
||||
echo " echo '# test' > api/api/sampling/stages/partial_completion_processing.py"
|
||||
echo ""
|
||||
echo "5. Create a PR and comment: @claude please update the test file"
|
||||
echo ""
|
||||
echo "This will test the actual GitHub Action with your fixes!"
|
||||
Reference in New Issue
Block a user