Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
⛩️ ci: Gate Backend Jest on Codegraph Selection (Stage 1) (#15132)
Danny Avilae9a5b61f8c02
diff --git a/.github/workflows/backend-review.yml b/.github/workflows/backend-review.ymlindex 84a1590faf..ecc3cee867 100644--- a/.github/workflows/backend-review.yml+++ b/.github/workflows/backend-review.yml@@ -1,5 +1,20 @@name: Backend Unit Testson:+ # push-to-dev runs are the post-merge safety net: gating only ever narrows pull_request+ # synchronize runs, so every merged state still gets the full suite — which is also what+ # keeps ground-truth recall telemetry alive for the codegraph shadow evaluator once+ # selection hides skipped tests from PR runs.+ push:+ branches:+ - dev+ paths:+ - 'api/**'+ - 'packages/**'+ - 'package.json'+ - 'package-lock.json'+ - 'config/circular-deps.mjs'+ - '.github/workflows/backend-review.yml'+ - '!**.md'pull_request:paths:- 'api/**'@@ -104,6 +119,104 @@ jobs:path: packages/api/distretention-days: 2++ # Codegraph test selection — the GATE (stage 1: backend jest only).+ #+ # Paranoia policy: FULL on opened/reopened PRs and on every push to dev (see the push+ # trigger above); SELECTED only on pull_request synchronize. Fork PRs carry no secrets, so+ # the curl fails and everything falls back to FULL. Kill switch: set repo variable+ # CODEGRAPH_GATING=off and this job skips, which makes every output empty and every test+ # job behave exactly as before this workflow change. The server itself fails open (stale+ # graph, unclassifiable change, root/lockfile floors => mode FULL per workspace), and this+ # job emits nothing unless the response parses end to end — the worst case at every layer+ # is "CI runs everything", which is the pre-gating behavior.+ codegraph_select:+ name: Codegraph select+ runs-on: ubuntu-latest+ timeout-minutes: 5+ if: >-+ github.event_name == 'pull_request' &&+ github.event.action == 'synchronize' &&+ vars.CODEGRAPH_GATING != 'off'+ outputs:+ decided: ${{ steps.sel.outputs.decided }}+ api_run: ${{ steps.sel.outputs.api_run }}+ api_files: ${{ steps.sel.outputs.api_files }}+ pkgapi_run: ${{ steps.sel.outputs.pkgapi_run }}+ pkgapi_files: ${{ steps.sel.outputs.pkgapi_files }}+ dataprovider_run: ${{ steps.sel.outputs.dataprovider_run }}+ dataprovider_files: ${{ steps.sel.outputs.dataprovider_files }}+ dataschemas_run: ${{ steps.sel.outputs.dataschemas_run }}+ dataschemas_files: ${{ steps.sel.outputs.dataschemas_files }}+ steps:+ - name: Select tests, fail open on any doubt+ id: sel+ env:+ URL: ${{ secrets.CODEGRAPH_URL }}+ TOKEN: ${{ secrets.CODEGRAPH_TOKEN }}+ GH_TOKEN: ${{ github.token }}+ REPO: ${{ github.repository }}+ PR: ${{ github.event.pull_request.number }}+ BASE_SHA: ${{ github.event.pull_request.base.sha }}+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}+ run: |+ set +e+ note() { echo "$1" >> "$GITHUB_STEP_SUMMARY"; }+ note "### Codegraph select — GATING (backend jest)"+ if [ -z "$URL" ] || [ -z "$TOKEN" ]; then note "_no codegraph config; running FULL_"; exit 0; fi+ gh api "repos/$REPO/pulls/$PR/files" --paginate --jq '.[] | {path: .filename, status, patch}' | jq -s . > files.json+ if [ ! -s files.json ]; then note "_could not fetch changed files; running FULL_"; exit 0; fi+ jq -c --arg b "$BASE_SHA" --arg h "$HEAD_SHA" '{files: ., mode: "safe", lockBaseSha: $b, lockHeadSha: $h}' files.json > body.json+ RESP=$(curl -sS -m 45 -H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' --data-binary @body.json "$URL/v1/select")+ if [ -z "$RESP" ] || ! echo "$RESP" | jq -e '.selected.api.mode' >/dev/null 2>&1; then+ note "_codegraph unavailable (${RESP:0:120}); running FULL_"+ exit 0+ fi+ # Emit per-workspace run flag + workspace-relative file list. A workspace emits+ # run=false ONLY on an explicit NONE; FULL and FILES both run (FILES filtered).+ # Any selected path containing a space forces that workspace FULL (paths are+ # server-validated to exclude quotes/backslashes/control chars, so plain+ # interpolation into the test command below is safe; spaces are the one shape+ # that would split — refuse to filter rather than risk it).+ emit() {+ key="$1"; ws="$2"; ignore="$3"+ mode=$(echo "$RESP" | jq -r --arg w "$ws" '.selected[$w].mode')+ files=""+ if [ "$mode" = "FILES" ]; then+ files=$(echo "$RESP" | jq -r --arg w "$ws" --arg p "$ws/" --arg ig "$ignore" '.selected[$w].files // [] | map(select((test(" ") | not) and (($ig == "") or (test($ig) | not)))) | map(ltrimstr($p)) | join(" ")')+ spaced=$(echo "$RESP" | jq -r --arg w "$ws" '[.selected[$w].files // [] | .[] | select(test(" "))] | length')+ if [ "$spaced" != "0" ]; then mode="FULL"; files=""; fi+ if [ "$mode" = "FILES" ] && [ -z "$files" ]; then mode="NONE"; fi+ fi+ if [ "$mode" = "NONE" ]; then+ echo "${key}_run=false" >> "$GITHUB_OUTPUT"+ note "| $ws | skip (no reachable tests) |"+ elif [ "$mode" = "FILES" ]; then+ n=$(echo "$files" | wc -w | tr -d ' ')+ echo "${key}_run=true" >> "$GITHUB_OUTPUT"+ echo "${key}_files=$files" >> "$GITHUB_OUTPUT"+ note "| $ws | $n selected files |"+ else+ echo "${key}_run=true" >> "$GITHUB_OUTPUT"+ note "| $ws | FULL |"+ fi+ }+ note "| workspace | decision |"+ note "|---|---|"+ # Ignore regexes mirror what each workspace's own jest run excludes, because+ # --runTestsByPath BYPASSES testPathIgnorePatterns (verified empirically) — without+ # this, selection would newly run integration/manual/misc suites that full CI skips.+ # Character classes instead of backslashes: these strings cross YAML->bash->jq and+ # every escape layer is a chance to ship a filter that silently matches nothing.+ emit api api ""+ emit pkgapi packages/api 'integration|helper|__tests__/helpers/|manual[.]spec[.]'+ emit dataprovider packages/data-provider ""+ emit dataschemas packages/data-schemas 'misc/|dist/|node_modules/'+ echo "decided=true" >> "$GITHUB_OUTPUT"+ note ""+ note "kill switch: repo variable \`CODEGRAPH_GATING=off\`; full runs remain on PR open and on every dev push"+ exit 0+typecheck:name: TypeScript type checksneeds: build@@ -196,7 +309,8 @@ jobs:test-api:name: 'Tests: api (shard ${{ matrix.shard }}/3)'- needs: build+ needs: [build, codegraph_select]+ if: always() && needs.build.result == 'success' && needs.codegraph_select.outputs.api_run != 'false'runs-on: ubuntu-latesttimeout-minutes: 15strategy:@@ -276,11 +390,21 @@ jobs:restore-keys: |mongodb-binaries-${{ runner.os }}-- name: Run unit tests (shard ${{ matrix.shard }}/3)- run: cd api && npm run test:ci -- --shard=${{ matrix.shard }}/3+ env:+ SELECTED: ${{ needs.codegraph_select.outputs.api_files }}+ run: |+ cd api+ if [ -n "$SELECTED" ]; then+ echo "codegraph: $(echo $SELECTED | wc -w) selected test files (safe mode)"+ npm run test:ci -- --shard=${{ matrix.shard }}/3 --passWithNoTests --runTestsByPath $SELECTED+ else+ npm run test:ci -- --shard=${{ matrix.shard }}/3+ fitest-data-provider:name: 'Tests: data-provider'- needs: build+ needs: [build, codegraph_select]+ if: always() && needs.build.result == 'success' && needs.codegraph_select.outputs.dataprovider_run != 'false'runs-on: ubuntu-latesttimeout-minutes: 10steps:@@ -327,11 +451,21 @@ jobs:restore-keys: |mongodb-binaries-${{ runner.os }}-- name: Run unit tests- run: cd packages/data-provider && npm run test:ci+ env:+ SELECTED: ${{ needs.codegraph_select.outputs.dataprovider_files }}+ run: |+ cd packages/data-provider+ if [ -n "$SELECTED" ]; then+ echo "codegraph: $(echo $SELECTED | wc -w) selected test files (safe mode)"+ npm run test:ci -- --passWithNoTests --runTestsByPath $SELECTED+ else+ npm run test:ci+ fitest-data-schemas:name: 'Tests: data-schemas'- needs: build+ needs: [build, codegraph_select]+ if: always() && needs.build.result == 'success' && needs.codegraph_select.outputs.dataschemas_run != 'false'runs-on: ubuntu-latesttimeout-minutes: 10steps:@@ -384,11 +518,21 @@ jobs:restore-keys: |mongodb-binaries-${{ runner.os }}-- name: Run unit tests- run: cd packages/data-schemas && npm run test:ci+ env:+ SELECTED: ${{ needs.codegraph_select.outputs.dataschemas_files }}+ run: |+ cd packages/data-schemas+ if [ -n "$SELECTED" ]; then+ echo "codegraph: $(echo $SELECTED | wc -w) selected test files (safe mode)"+ npm run test:ci -- --passWithNoTests --runTestsByPath $SELECTED+ else+ npm run test:ci+ fitest-packages-api:name: 'Tests: @librechat/api (shard ${{ matrix.shard }}/4)'- needs: build+ needs: [build, codegraph_select]+ if: always() && needs.build.result == 'success' && needs.codegraph_select.outputs.pkgapi_run != 'false'runs-on: ubuntu-latest# Suite typically completes in ~5 min on a warm runner, but tail-latency# cancellations have started showing up: tests are actively passing right@@ -455,4 +599,13 @@ jobs:restore-keys: |mongodb-binaries-${{ runner.os }}-- name: Run unit tests (shard ${{ matrix.shard }}/4)- run: cd packages/api && npm run test:ci -- --shard=${{ matrix.shard }}/4+ env:+ SELECTED: ${{ needs.codegraph_select.outputs.pkgapi_files }}+ run: |+ cd packages/api+ if [ -n "$SELECTED" ]; then+ echo "codegraph: $(echo $SELECTED | wc -w) selected test files (safe mode)"+ npm run test:ci -- --shard=${{ matrix.shard }}/4 --passWithNoTests --runTestsByPath $SELECTED+ else+ npm run test:ci -- --shard=${{ matrix.shard }}/4+ fi