langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
11.77k stars 1.97k forks source link

Unit Tests (LangChain Integrations) Workflow is Skipping Jobs #5913

Open rameshkrishna opened 1 week ago

rameshkrishna commented 1 week ago

Checked other resources

Example Code

Here is the current implementation that's causing integration test to skip the test cases even though there are changes

Example of Workflow skipping test jobs even though there are changes https://github.com/langchain-ai/langchainjs/actions/runs/9690868817

This is happening due to issue with below line in file .github/workflows/unit-tests-integrations.yml#L81

    if: ${{ fromJson(needs.prepare-matrix.outputs.matrix).include.length != 0 }}

The above issue can be fixed by add extra output for matrix_length in prepare-martix job with below code


# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Unit Tests (LangChain Integrations)

on:
  push:
    branches: ["main"]
  pull_request:
    # Only run when LangChain Core, or integration package code changes.
    paths:
      - 'langchain-core/**'
      - 'libs/**/**'
  workflow_dispatch:  # Allows triggering the workflow manually in GitHub UI

# If another push to the same PR or branch happens while this workflow is still running,
# cancel the earlier run in favor of the next run.
#
# There's no point in testing an outdated version of the code. GitHub only allows
# a limited number of job runners to be active at the same time, so it's better to cancel
# pointless jobs early so that more useful jobs can run sooner.
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  get-changed-files:
    runs-on: ubuntu-latest
    outputs:
      changed_files: ${{ steps.get_changes.outputs.changed_files }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 2
      - name: Get changes
        id: get_changes
        run: |
          echo "changed_files<<EOF" >> $GITHUB_OUTPUT
          git diff --name-only -r HEAD^1 HEAD | while read line; do printf "%s\n" "$line"; done >> $GITHUB_OUTPUT
          echo "EOF" >> $GITHUB_OUTPUT

  prepare-matrix:
    needs: get-changed-files
    runs-on: ubuntu-latest
    env:
      PACKAGES: "anthropic,azure-openai,cloudflare,cohere,core,community,exa,google-common,google-gauth,google-genai,google-vertexai,google-vertexai-web,google-webauth,groq,mistralai,mongo,nomic,openai,pinecone,qdrant,redis,textsplitters,weaviate,yandex"
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
      matrix_length: ${{ steps.set-matrix.outputs.matrix_length }}    
    steps:
      - id: set-matrix
        run: |
          changed_files="${{ needs.get-changed-files.outputs.changed_files }}"
          echo "Changed files: $changed_files"
          # Convert PACKAGES environment variable into an array
          IFS=',' read -r -a packages <<< "$PACKAGES"
          echo "Packages: ${packages[*]}"
          matrix="{\"include\": ["
          first_entry=true
          for package in "${packages[@]}"; do
            echo "Checking package: $package"
            if echo "$changed_files" | grep -q "$package"; then
              echo "Package $package found in changed files."
              if [ "$first_entry" = true ]; then
              matrix="$matrix{\"os\": \"ubuntu-latest\", \"node-version\": \"18\", \"package\": \"$package\"},{\"os\": \"ubuntu-latest\", \"node-version\": \"20\", \"package\": \"$package\"}"
              first_entry=false
            else
              matrix="$matrix, {\"os\": \"ubuntu-latest\", \"node-version\": \"18\", \"package\": \"$package\"},{\"os\": \"ubuntu-latest\", \"node-version\": \"20\", \"package\": \"$package\"}"
            fi
            fi
          done
          matrix="$matrix]}"
          matrix_length=$(echo $matrix | jq '.include | length')
          echo "Matrix: $matrix"
          echo "Matrix length: $matrix_length"
          echo "matrix_length=$matrix_length" >> $GITHUB_OUTPUT
          echo "matrix=$matrix" >> $GITHUB_OUTPUT

  unit-tests:
    name: Unit Tests
    needs: prepare-matrix
    # Only run this job if there are packages to test
    if: needs.prepare-matrix.outputs.matrix_length > 0
    runs-on: ubuntu-latest
    strategy:
      matrix: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
    env:
      PUPPETEER_SKIP_DOWNLOAD: "true"
      PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: "yarn"
      - name: Install dependencies
        run: yarn install --immutable
      - name: Test '@langchain/${{ matrix.package }}' package
        run: yarn test:unit:ci --filter=@langchain/${{ matrix.package }}

Error Message and Stack Trace (if applicable)

No response

Description

System Info



yarn info
├─ @tsconfig/recommended@npm:1.0.2
│  └─ Version: 1.0.2
│
├─ @types/jest@npm:29.5.3
│  ├─ Version: 29.5.3
│  │
│  └─ Dependencies
│     ├─ expect@npm:^29.0.0 → npm:29.6.1
│     └─ pretty-format@npm:^29.0.0 → npm:29.6.1
│
├─ @types/semver@npm:7.5.6
│  └─ Version: 7.5.6
│
├─ commander@npm:11.1.0
│  └─ Version: 11.1.0
│
├─ dotenv@npm:16.0.3
│  └─ Version: 16.0.3
│
├─ langchainjs@workspace:.
│  ├─ Version: 0.0.4
│  │
│  └─ Dependencies
│     ├─ @tsconfig/recommended@npm:^1.0.2 → npm:1.0.2
│     ├─ @types/jest@npm:^29.5.3 → npm:29.5.3
│     ├─ @types/semver@npm:^7 → npm:7.5.6
│     ├─ commander@npm:^11.1.0 → npm:11.1.0
│     ├─ dotenv@npm:^16.0.3 → npm:16.0.3
│     ├─ lint-staged@npm:^13.1.1 → npm:13.1.4
│     ├─ prettier@npm:^2.8.3 → npm:2.8.4
│     ├─ semver@npm:^7.5.4 → npm:7.5.4
│     ├─ turbo@npm:^1.13.3 → npm:1.13.3
│     └─ typescript@patch:typescript@~5.1.6#~builtin<compat/typescript> → patch:typescript@npm%3A5.1.6#~builtin<compat/typescript>::version=5.1.6&hash=1f5320
│
├─ lint-staged@npm:13.1.4
│  ├─ Version: 13.1.4
│  │
│  ├─ Exported Binaries
│  │  └─ lint-staged
│  │
│  └─ Dependencies
│     ├─ chalk@npm:5.2.0 → npm:5.2.0
│     ├─ cli-truncate@npm:^3.1.0 → npm:3.1.0
│     ├─ commander@npm:^10.0.0 → npm:10.0.0
│     ├─ execa@npm:^7.0.0 → npm:7.0.0
│     ├─ lilconfig@npm:2.1.0 → npm:2.1.0
│     ├─ micromatch@npm:^4.0.5 → npm:4.0.5
│     ├─ normalize-path@npm:^3.0.0 → npm:3.0.0
│     ├─ object-inspect@npm:^1.12.3 → npm:1.12.3
│     ├─ pidtree@npm:^0.6.0 → npm:0.6.0
│     ├─ string-argv@npm:^0.3.1 → npm:0.3.1
│     ├─ supports-color@npm:9.3.1 → npm:9.3.1
│     ├─ yaml@npm:^2.2.1 → npm:2.2.1
│     ├─ debug@npm:^4.3.4 → npm:4.3.4 [d0f46]
│     └─ listr2@npm:^5.0.7 → npm:5.0.7 [d0f46]
│
├─ prettier@npm:2.8.4
│  ├─ Version: 2.8.4
│  │
│  └─ Exported Binaries
│     └─ prettier
│
├─ semver@npm:7.5.4
│  ├─ Version: 7.5.4
│  │
│  ├─ Exported Binaries
│  │  └─ semver
│  │
│  └─ Dependencies
│     └─ lru-cache@npm:^6.0.0 → npm:6.0.0
│
├─ turbo@npm:1.13.3
│  ├─ Version: 1.13.3
│  │
│  ├─ Exported Binaries
│  │  └─ turbo
│  │
│  └─ Dependencies
│     ├─ turbo-darwin-64@npm:1.13.3 → npm:1.13.3
│     ├─ turbo-darwin-arm64@npm:1.13.3 → npm:1.13.3
│     ├─ turbo-linux-64@npm:1.13.3 → npm:1.13.3
│     ├─ turbo-linux-arm64@npm:1.13.3 → npm:1.13.3
│     ├─ turbo-windows-64@npm:1.13.3 → npm:1.13.3
│     └─ turbo-windows-arm64@npm:1.13.3 → npm:1.13.3
│
└─ typescript@patch:typescript@npm%3A5.1.6#~builtin<compat/typescript>::version=5.1.6&hash=1f5320
   ├─ Version: 5.1.6
   │
   └─ Exported Binaries
      ├─ tsc
      └─ tsserver
dosubot[bot] commented 1 week ago

To fix the issue with the GitHub workflow for unit tests in LangChain.js integrations, you need to modify the prepare-matrix job to include an extra output for matrix_length. This will ensure that the unit-tests job only runs if there are packages to test.

Here is the updated workflow configuration:

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Unit Tests (LangChain Integrations)

on:
  push:
    branches: ["main"]
  pull_request:
    # Only run when LangChain Core, or integration package code changes.
    paths:
      - 'langchain-core/**'
      - 'libs/**/**'
  workflow_dispatch:  # Allows triggering the workflow manually in GitHub UI

# If another push to the same PR or branch happens while this workflow is still running,
# cancel the earlier run in favor of the next run.
#
# There's no point in testing an outdated version of the code. GitHub only allows
# a limited number of job runners to be active at the same time, so it's better to cancel
# pointless jobs early so that more useful jobs can run sooner.
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  get-changed-files:
    runs-on: ubuntu-latest
    outputs:
      changed_files: ${{ steps.get_changes.outputs.changed_files }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 2
      - name: Get changes
        id: get_changes
        run: |
          echo "changed_files<<EOF" >> $GITHUB_OUTPUT
          git diff --name-only -r HEAD^1 HEAD | while read line; do printf "%s\n" "$line"; done >> $GITHUB_OUTPUT
          echo "EOF" >> $GITHUB_OUTPUT

  prepare-matrix:
    needs: get-changed-files
    runs-on: ubuntu-latest
    env:
      PACKAGES: "anthropic,azure-openai,cloudflare,cohere,core,community,exa,google-common,google-gauth,google-genai,google-vertexai,google-vertexai-web,google-webauth,groq,mistralai,mongo,nomic,openai,pinecone,qdrant,redis,textsplitters,weaviate,yandex"
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
      matrix_length: ${{ steps.set-matrix.outputs.matrix_length }}    
    steps:
      - id: set-matrix
        run: |
          changed_files="${{ needs.get-changed-files.outputs.changed_files }}"
          echo "Changed files: $changed_files"
          # Convert PACKAGES environment variable into an array
          IFS=',' read -r -a packages <<< "$PACKAGES"
          echo "Packages: ${packages[*]}"
          matrix="{\"include\": ["
          first_entry=true
          for package in "${packages[@]}"; do
            echo "Checking package: $package"
            if echo "$changed_files" | grep -q "$package"; then
              echo "Package $package found in changed files."
              if [ "$first_entry" = true ]; then
                matrix="$matrix{\"os\": \"ubuntu-latest\", \"node-version\": \"18\", \"package\": \"$package\"},{\"os\": \"ubuntu-latest\", \"node-version\": \"20\", \"package\": \"$package\"}"
                first_entry=false
              else
                matrix="$matrix, {\"os\": \"ubuntu-latest\", \"node-version\": \"18\", \"package\": \"$package\"},{\"os\": \"ubuntu-latest\", \"node-version\": \"20\", \"package\": \"$package\"}"
              fi
            fi
          done
          matrix="$matrix]}"
          matrix_length=$(echo $matrix | jq '.include | length')
          echo "Matrix: $matrix"
          echo "Matrix length: $matrix_length"
          echo "matrix_length=$matrix_length" >> $GITHUB_OUTPUT
          echo "matrix=$matrix" >> $GITHUB_OUTPUT

  unit-tests:
    name: Unit Tests
    needs: prepare-matrix
    # Only run this job if there are packages to test
    if: needs.prepare-matrix.outputs.matrix_length > 0
    runs-on: ubuntu-latest
    strategy:
      matrix: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
    env:
      PUPPETEER_SKIP_DOWNLOAD: "true"
      PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: "yarn"
      - name: Install dependencies
        run: yarn install --immutable
      - name: Test '@langchain/${{ matrix.package }}' package
        run: yarn test:unit:ci --filter=@langchain/${{ matrix.package }}

This modification ensures that the unit-tests job only runs if there are packages to test by checking the matrix_length output from the prepare-matrix job [1].

To continue talking to Dosu, mention @dosu.