Elffuss BraidHub

kikocis/continue public

Reduce test flake (#7470)

* fix: reduce flake by retrying docs crawler test

* ci: only run llm tests when llm related files change
Changeset9875eaa07e45c8d5059aeac7e9a4e52a6957240fc7d31ddfc4d74eb5cfb7f3bb
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-08-29 15:21 -07:00
CommitterGitHub <noreply@github.com> · 2025-08-29 15:21 -07:00
Parents86e71fea71da

Browse the files at this changeset

3 files changed

added .github/actions/check-llm-changes/action.yml +55 −0
@@ -0,0 +1,55 @@
1+name: "Check LLM Changes"
2+description: "Check if LLM-related files have changed and set environment variable to control API tests"
3+outputs:
4+ llm_changed:
5+ description: "Whether LLM-related files have changed"
6+ value: ${{ steps.check-changes.outputs.llm_changed }}
7+ ignore_api_tests:
8+ description: "Whether to ignore API tests based on file changes and other conditions"
9+ value: ${{ steps.check-changes.outputs.ignore_api_tests }}
10+inputs:
11+ is_fork:
12+ description: "Whether this is a fork PR"
13+ required: false
14+ default: "false"
15+ is_dependabot:
16+ description: "Whether this is a dependabot PR"
17+ required: false
18+ default: "false"
19+
20+runs:
21+ using: "composite"
22+ steps:
23+ - name: Check if LLM-related files changed
24+ id: check-changes
25+ shell: bash
26+ run: |
27+ if [ "${{ github.event_name }}" = "push" ]; then
28+ # For push events, compare against the previous commit
29+ CHANGED_FILES=$(git diff --name-only HEAD~1...HEAD)
30+ else
31+ # For PR events, compare against the base branch
32+ git fetch origin ${{ github.event.pull_request.base.ref }}
33+ CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...HEAD)
34+ fi
35+
36+ echo "Changed files:"
37+ echo "$CHANGED_FILES"
38+
39+ # Check if any LLM-related files were changed
40+ LLM_CHANGED=false
41+ if echo "$CHANGED_FILES" | grep -E "(^core/llm/|^core/index\.ts|^core/package\.json|^core/jest\.config\.js|^packages/.*/(.*llm.*|.*openai.*|.*anthropic.*)|\.github/workflows/pr-checks\.yaml|\.github/actions/check-llm-changes/)" > /dev/null; then
42+ LLM_CHANGED=true
43+ fi
44+
45+ echo "LLM files changed: $LLM_CHANGED"
46+ echo "llm_changed=$LLM_CHANGED" >> $GITHUB_OUTPUT
47+
48+ # Determine whether to ignore API tests
49+ IGNORE_API_TESTS=false
50+ if [ "${{ inputs.is_fork }}" = "true" ] || [ "${{ inputs.is_dependabot }}" = "true" ] || [ "$LLM_CHANGED" = "false" ]; then
51+ IGNORE_API_TESTS=true
52+ fi
53+
54+ echo "Ignore API tests: $IGNORE_API_TESTS"
55+ echo "ignore_api_tests=$IGNORE_API_TESTS" >> $GITHUB_OUTPUT
modified .github/workflows/pr-checks.yaml +20 −2
@@ -44,6 +44,8 @@
4444 runs-on: ubuntu-latest
4545 steps:
4646 - uses: actions/checkout@v5
47+ with:
48+ fetch-depth: 0 # Needed for git diff to work
4749 - name: Setup packages
4850 uses: ./.github/actions/setup-packages
4951 - name: Setup core component
@@ -52,6 +54,13 @@
5254 component: core
5355 include-root: true
5456
57+ - name: Check if LLM-related files changed
58+ id: llm-changes
59+ uses: ./.github/actions/check-llm-changes
60+ with:
61+ is_fork: ${{ github.event.pull_request.head.repo.fork == true }}
62+ is_dependabot: ${{ github.actor == 'dependabot[bot]' }}
63+
5564 - name: Type check and lint
5665 run: |
5766 cd core
@@ -66,7 +75,7 @@
6675 npm test
6776 npm run vitest
6877 env:
69- IGNORE_API_KEY_TESTS: ${{ github.event.pull_request.head.repo.fork == true || github.actor == 'dependabot[bot]' }}
78+ IGNORE_API_KEY_TESTS: ${{ steps.llm-changes.outputs.ignore_api_tests }}
7079 OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
7180 ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
7281 GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
@@ -180,16 +189,25 @@
180189 package: ${{ fromJson(needs.get-packages-matrix.outputs.packages) }}
181190 steps:
182191 - uses: actions/checkout@v5
192+ with:
193+ fetch-depth: 0 # Needed for git diff to work
183194 - name: Setup packages
184195 uses: ./.github/actions/setup-packages
185196
197+ - name: Check if LLM-related files changed
198+ id: llm-changes
199+ uses: ./.github/actions/check-llm-changes
200+ with:
201+ is_fork: ${{ github.event.pull_request.head.repo.fork == true }}
202+ is_dependabot: ${{ github.actor == 'dependabot[bot]' }}
203+
186204 - name: Test and check ${{ matrix.package }}
187205 run: |
188206 cd packages/${{ matrix.package }}
189207 npm ci
190208 npm test
191209 env:
192- IGNORE_API_KEY_TESTS: ${{ github.event.pull_request.head.repo.fork == true || github.actor == 'dependabot[bot]' }}
210+ IGNORE_API_KEY_TESTS: ${{ steps.llm-changes.outputs.ignore_api_tests }}
193211 OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
194212 ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
195213 GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
modified core/indexing/docs/crawlers/DocsCrawler.test.ts +21 −3
@@ -155,9 +155,27 @@
155155 test(
156156 `Default crawler common site: ${url}`,
157157 async () => {
158- const { pages, crawler } = await runCrawl(url);
159- expect(pages.length).toBeGreaterThanOrEqual(1);
160- expect(crawler).toEqual("default");
158+ // Retry logic to handle flaky network requests to TRIAL_PROXY_URL
159+ let lastError;
160+ const maxRetries = 3;
161+
162+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
163+ try {
164+ const { pages, crawler } = await runCrawl(url);
165+ expect(pages.length).toBeGreaterThanOrEqual(1);
166+ expect(crawler).toEqual("default");
167+ return; // Test passed, exit retry loop
168+ } catch (error) {
169+ lastError = error;
170+ if (attempt === maxRetries) {
171+ throw error; // Final attempt failed, throw the error
172+ }
173+ // Wait before retrying (exponential backoff)
174+ await new Promise((resolve) =>
175+ setTimeout(resolve, 1000 * attempt),
176+ );
177+ }
178+ }
161179 },
162180 TIMEOUT_MS,
163181 );