From 4a63df4aba1a834bfbd997c55d1f061897915c5c Mon Sep 17 00:00:00 2001 From: David Fridrich Date: Fri, 3 Apr 2026 19:39:47 +0200 Subject: [PATCH] e2e: add testing framework for templates --- .github/workflows/e2e-tests.yaml | 92 ++++++++++++++ .testing/README.md | 102 +++++++++++++++ .testing/python/mcp-ollama-rag/test.sh | 116 ++++++++++++++++++ .../python/mcp-ollama-rag/test_mcp_client.py | 103 ++++++++++++++++ .testing/run-e2e.sh | 116 ++++++++++++++++++ Makefile | 5 +- README.md | 11 ++ python/mcp-ollama-rag/client/client.py | 4 +- 8 files changed, 546 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/e2e-tests.yaml create mode 100644 .testing/README.md create mode 100755 .testing/python/mcp-ollama-rag/test.sh create mode 100644 .testing/python/mcp-ollama-rag/test_mcp_client.py create mode 100755 .testing/run-e2e.sh diff --git a/.github/workflows/e2e-tests.yaml b/.github/workflows/e2e-tests.yaml new file mode 100644 index 0000000..b146523 --- /dev/null +++ b/.github/workflows/e2e-tests.yaml @@ -0,0 +1,92 @@ +name: E2E Tests + +on: + pull_request: + types: [opened, synchronize, reopened] + workflow_dispatch: + +jobs: + discover: + runs-on: ubuntu-latest + outputs: + tests: ${{ steps.find-tests.outputs.tests }} + has_tests: ${{ steps.find-tests.outputs.has_tests }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Find e2e tests to run + id: find-tests + run: | + # Get changed files vs base branch + if [ "${{ github.event_name }}" = "pull_request" ]; then + git fetch origin ${{ github.base_ref }} --depth=1 + changed=$(git diff --name-only FETCH_HEAD...HEAD) + else + # workflow_dispatch: run all + changed="RUN_ALL" + fi + + # Collect all available e2e tests + all_tests=$(find .testing -mindepth 3 -maxdepth 3 -name "test.sh" | while read -r f; do + rel="${f#.testing/}" + dirname "$rel" + done | sort) + + if [ "$changed" = "RUN_ALL" ]; then + matched="$all_tests" + else + matched="" + for test in $all_tests; do + # Check if any changed file is under the template dir or the test dir + if echo "$changed" | grep -qE "^${test}/|^\.testing/${test}/"; then + matched="$matched $test" + fi + done + fi + + # Build JSON array + if [ -n "$matched" ]; then + json=$(echo "$matched" | xargs -n1 | jq -R -s -c 'split("\n") | map(select(length > 0))') + echo "tests=$json" >> $GITHUB_OUTPUT + echo "has_tests=true" >> $GITHUB_OUTPUT + echo "Will run e2e tests: $matched" + else + echo "tests=[]" >> $GITHUB_OUTPUT + echo "has_tests=false" >> $GITHUB_OUTPUT + echo "No e2e tests to run" + fi + + e2e: + needs: discover + if: needs.discover.outputs.has_tests == 'true' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + test: ${{ fromJSON(needs.discover.outputs.tests) }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install func + uses: functions-dev/action@main + with: + version: 'latest' + name: func + + - name: Setup Ollama + run: | + curl -fsSL https://ollama.com/install.sh | sh + ollama serve & + # Wait for server + for i in $(seq 1 30); do + curl -sf http://localhost:11434/api/tags && break + sleep 2 + done + + - name: Run e2e test + run: | + ./.testing/run-e2e.sh ${{ matrix.test }} --verbose diff --git a/.testing/README.md b/.testing/README.md new file mode 100644 index 0000000..9951f47 --- /dev/null +++ b/.testing/README.md @@ -0,0 +1,102 @@ +# E2E Testing Framework + +End-to-end tests for templates that need external services (Ollama, databases, etc.) +and can't be tested with a simple `func invoke`. + +## Usage + +```bash +# Run all e2e tests +make e2e + +# Run a specific test +make e2e ARGS="python/mcp-ollama-rag" + +# Verbose output +make e2e ARGS="--verbose" + +# Or run directly +./.testing/run-e2e.sh python/mcp-ollama-rag --verbose +``` + +## Structure + +``` +.testing/ + run-e2e.sh # runner script + README.md + / +