Skill: frhn9/code-tester (version 1.0.0)

--- name: code-tester description: Build, run, and test code projects for Rust, Go, and Java. Automatically detect project type, run unit tests if available, and report build status. Use after code changes to verify that project builds successfully, unit tests pass if they exist, and application runs without errors. Communicate results back to the requesting agent for fixing and re-testing. metadata: {"clawdbot":{"command":"test_repo"}} --- # Code Tester Test code projects to verify builds and tests pass. ## Workflow When asked to test changes: 1. **Detect project type** in specified directory: - Rust: `Cargo.toml` + `src/` directory - Go: `go.mod`, `go.sum`, or `main.go` - Java: `pom.xml` or `build.gradle` / `build.gradle.kts` 2. **Run tests** (only if tests exist): - Skip if no tests found - Run project-specific test commands - Capture test results 3. **Build the project**: - Run build commands - Capture build output and errors 4. **Report results**: - Clear summary of what happened - Test results (if run) - Build status - Any errors encountered ## Communication Protocol When testing for another agent: **Format your report like:** ``` Testing: <directory> Project type: <rust|go|java> Detected tests: <yes|no> === Results === ✓ Tests: <passed/skipped/failed> ✓/✗ Build: <passed/failed> <Relevant error messages if any> ``` **If everything passes:** - Report success clearly - Provide next steps if needed **If something fails:** - Report what failed (tests or build) - Include error logs - Suggest what to fix ## Running Tests Execute the test script: ```bash /root/.openclaw/workspace/skills/code-tester/scripts/test.sh <directory> ``` The script will: - Auto-detect project type - Run tests (if available) - Build the project - Return exit code 0 on success, 1 on failure ## Testing Strategy - **Rust**: `cargo test` → `cargo build` - **Go**: `go test ./...` → `go build` - **Java Maven**: `mvn test` → `mvn compile` - **Java Gradle**: `./gradlew test` → `./gradlew build -x test` Always run from the project directory. The script handles detection automatically.

path: scripts/resolve_project.sh
content: #!/bin/bash
set -e

INPUT="$1"

if [ -z "$INPUT" ]; then
    echo "Error: Project name or path required" >&2
    exit 1
fi

# 1. Check if it's a path
if [[ "$INPUT" =~ ^/ ]] || [[ "$INPUT" =~ ^~ ]] || [[ "$INPUT" =~ ^\.\./ ]] || [[ "$INPUT" =~ ^\./ ]]; then
    # It's a path, expand and validate
    EXPANDED=$(eval echo "$INPUT")
    if [ -d "$EXPANDED" ]; then
        echo "$EXPANDED"
        exit 0
    else
        echo "Error: Directory not found: $EXPANDED" >&2
        exit 1
    fi
fi

# 2. Workspace exact match
WORKSPACE="/root/.openclaw/workspace"
if [ -d "$WORKSPACE/$INPUT" ]; then
    echo "$WORKSPACE/$INPUT"
    exit 0
fi

# 3. Workspace fuzzy match
MATCHES=$(find "$WORKSPACE" -maxdepth 1 -type d -iname "*$INPUT*" 2>/dev/null | grep -v "^$WORKSPACE$" || true)

if [ -n "$MATCHES" ]; then
    MATCH_COUNT=$(echo "$MATCHES" | wc -l)

    if [ "$MATCH_COUNT" -eq 1 ]; then
        echo "$MATCHES"
        exit 0
    else
        echo "Error: Multiple matches found for '$INPUT':" >&2
        echo "" >&2
        echo "$MATCHES" | while read -r match; do
            echo "  - $match" >&2
        done
        echo "" >&2
        echo "Please be more specific." >&2
        exit 1
    fi
fi

# 4. Git repository search
GIT_REPOS=$(find "$WORKSPACE" -maxdepth 2 -type d -name ".git" 2>/dev/null | while read gitdir; do
    dirname "$gitdir"
done | grep -i "$INPUT" || true)

if [ -n "$GIT_REPOS" ]; then
    REPO_COUNT=$(echo "$GIT_REPOS" | wc -l)

    if [ "$REPO_COUNT" -eq 1 ]; then
        echo "$GIT_REPOS"
        exit 0
    else
        echo "Error: Multiple git repos found for '$INPUT':" >&2
        echo "" >&2
        echo "$GIT_REPOS" | while read -r repo; do
            echo "  - $repo" >&2
        done
        exit 1
    fi
fi

# 5. Project marker search
for marker in Cargo.toml go.mod pom.xml build.gradle build.gradle.kts; do
    PROJ_DIRS=$(find "$WORKSPACE" -name "$marker" 2>/dev/null | while read markerfile; do
        dirname "$markerfile"
    done | grep -i "$INPUT" || true)

    if [ -n "$PROJ_DIRS" ]; then
        PROJ_COUNT=$(echo "$PROJ_DIRS" | wc -l)

        if [ "$PROJ_COUNT" -eq 1 ]; then
            echo "$PROJ_DIRS"
            exit 0
        fi
    fi
done

# 6. Home directory search
HOME_DIR="/root"
HOME_MATCHES=$(find "$HOME_DIR" -maxdepth 2 -type d -iname "*$INPUT*" 2>/dev/null | grep -v "^$HOME_DIR$" || true)

if [ -n "$HOME_MATCHES" ]; then
    HOME_COUNT=$(echo "$HOME_MATCHES" | wc -l)

    if [ "$HOME_COUNT" -eq 1 ]; then
        echo "$HOME_MATCHES"
        exit 0
    fi
fi

# 7. Not found
echo "Error: Could not find project '$INPUT'" >&2
echo "" >&2
echo "Searched in:" >&2
echo "  - Workspace: $WORKSPACE" >&2
echo "  - Home: $HOME_DIR" >&2
echo "  - Git repositories" >&2
echo "  - Project directories (with Cargo.toml, go.mod, pom.xml, etc.)" >&2
echo "" >&2
echo "Found 0 matches." >&2
exit 1


path: scripts/test.sh
content: #!/bin/bash
# Code Tester Script
# Supports: Rust, Go, Java
# Usage: test.sh <directory>

set -e

DIR="$1"
if [ -z "$DIR" ]; then
    echo "Error: Directory not provided"
    echo "Usage: test.sh <directory>"
    exit 1
fi

cd "$DIR"

# Detect project type
PROJECT_TYPE="unknown"

if [ -f "Cargo.toml" ] && [ -d "src" ]; then
    PROJECT_TYPE="rust"
elif [ -f "go.mod" ] || [ -f "go.sum" ] || [ -f "main.go" ]; then
    PROJECT_TYPE="go"
elif [ -f "pom.xml" ] || [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then
    PROJECT_TYPE="java"
fi

echo "Detected project type: $PROJECT_TYPE"

if [ "$PROJECT_TYPE" = "unknown" ]; then
    echo "Error: Could not detect supported project type"
    echo "Supported types: Rust (Cargo.toml), Go (go.mod, main.go), Java (pom.xml, build.gradle)"
    exit 1
fi

# Run tests based on project type
case "$PROJECT_TYPE" in
    rust)
        echo "--- Rust Project ---"
        echo "Running: cargo test"

        # Check if tests exist
        if grep -r "#\[test\]" src/ 2>/dev/null > /dev/null; then
            cargo test 2>&1 | tee /tmp/code-tester-tests.log
            TEST_RESULT=${PIPESTATUS[0]}
            echo "Test result: $TEST_RESULT"
        else
            echo "No tests found, skipping tests"
            TEST_RESULT=0
        fi

        # Try to build and run
        echo ""
        echo "Running: cargo build"
        cargo build 2>&1 | tee /tmp/code-tester-build.log
        BUILD_RESULT=${PIPESTATUS[0]}

        echo ""
        echo "Build result: $BUILD_RESULT"
        ;;
    go)
        echo "--- Go Project ---"

        # Check if tests exist
        if find . -name "*_test.go" -type f | grep -q .; then
            echo "Running: go test ./..."
            go test ./... 2>&1 | tee /tmp/code-tester-tests.log
            TEST_RESULT=${PIPESTATUS[0]}
            echo "Test result: $TEST_RESULT"
        else
            echo "No tests found, skipping tests"
            TEST_RESULT=0
        fi

        echo ""
        echo "Running: go build"
        go build 2>&1 | tee /tmp/code-tester-build.log
        BUILD_RESULT=${PIPESTATUS[0]}

        echo ""
        echo "Build result: $BUILD_RESULT"
        ;;
    java)
        echo "--- Java Project ---"

        if [ -f "pom.xml" ]; then
            echo "Detected: Maven project"

            # Check if tests exist
            if [ -d "src/test" ] && [ "$(find src/test -name "*.java" 2>/dev/null | wc -l)" -gt 0 ]; then
                echo "Running: mvn test"
                mvn test 2>&1 | tee /tmp/code-tester-tests.log
                TEST_RESULT=${PIPESTATUS[0]}
                echo "Test result: $TEST_RESULT"
            else
                echo "No tests found, skipping tests"
                TEST_RESULT=0
            fi

            echo ""
            echo "Running: mvn compile"
            mvn compile 2>&1 | tee /tmp/code-tester-build.log
            BUILD_RESULT=${PIPESTATUS[0]}
        elif [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then
            echo "Detected: Gradle project"

            # Check if tests exist
            if [ -d "src/test" ] && [ "$(find src/test -name "*.java" 2>/dev/null | wc -l)" -gt 0 ]; then
                echo "Running: ./gradlew test"
                ./gradlew test 2>&1 | tee /tmp/code-tester-tests.log
                TEST_RESULT=${PIPESTATUS[0]}
                echo "Test result: $TEST_RESULT"
            else
                echo "No tests found, skipping tests"
                TEST_RESULT=0
            fi

            echo ""
            echo "Running: ./gradlew build -x test"
            ./gradlew build -x test 2>&1 | tee /tmp/code-tester-build.log
            BUILD_RESULT=${PIPESTATUS[0]}
        fi

        echo ""
        echo "Build result: $BUILD_RESULT"
        ;;
esac

# Overall result
echo ""
echo "=== SUMMARY ==="
echo "Project type: $PROJECT_TYPE"
echo "Tests: $TEST_RESULT"
echo "Build: $BUILD_RESULT"

if [ "$TEST_RESULT" -eq 0 ] && [ "$BUILD_RESULT" -eq 0 ]; then
    echo "✓ All checks passed"
    exit 0
else
    echo "✗ Some checks failed"
    exit 1
fi


Security scan verdicts — ClawScan: suspicious | static analysis:  | VirusTotal: suspicious | SkillSpector:  ()