From 1ec69cfe923974ba44d43c2397c336d8accc57bb Mon Sep 17 00:00:00 2001 From: bracesproul Date: Mon, 10 Jun 2024 15:53:30 -0700 Subject: [PATCH] refactor a lot of code into a shared script --- .../anthropic/test-with-latest-deps.sh | 43 ++------------- .../anthropic/test-with-lowest-deps.sh | 53 +++--------------- .../community/test-with-latest-deps.sh | 42 ++------------- .../community/test-with-lowest-deps.sh | 54 ++++--------------- .../openai/test-with-latest-deps.sh | 42 ++------------- .../openai/test-with-lowest-deps.sh | 54 ++++--------------- .../scripts/with_standard_tests/shared.sh | 50 +++++++++++++++++ 7 files changed, 85 insertions(+), 253 deletions(-) create mode 100644 dependency_range_tests/scripts/with_standard_tests/shared.sh diff --git a/dependency_range_tests/scripts/with_standard_tests/anthropic/test-with-latest-deps.sh b/dependency_range_tests/scripts/with_standard_tests/anthropic/test-with-latest-deps.sh index e5c707f85a7f..abd40845ab19 100644 --- a/dependency_range_tests/scripts/with_standard_tests/anthropic/test-with-latest-deps.sh +++ b/dependency_range_tests/scripts/with_standard_tests/anthropic/test-with-latest-deps.sh @@ -6,57 +6,22 @@ export CI=true # New monorepo directory paths monorepo_dir="/app/monorepo" -monorepo_libs_dir="$monorepo_dir/libs" -monorepo_anthropic_dir="$monorepo_libs_dir/langchain-anthropic" -monorepo_standard_tests_dir="$monorepo_libs_dir/langchain-standard-tests" +monorepo_anthropic_dir="/app/monorepo/libs/langchain-anthropic" # Updater script will not live inside the monorepo updater_script_dir="/app/updater_script" -standard_tests_updater_script_dir="/app/with_standard_script" # Original directory paths -original_anthropic_dir="/libs/langchain-anthropic" -original_standard_tests_dir="/libs/langchain-standard-tests" -original_package_json_dir="/package.json" -original_turbo_json_dir="/turbo.json" original_updater_script_dir="/scripts/with_standard_tests/anthropic/node" -original_standard_tests_updater_script_dir="/scripts/with_standard_tests/node" -# enable extended globbing for omitting build artifacts -shopt -s extglob - -# Create the top level monorepo directory -mkdir -p "$monorepo_dir" - -# Copy `@langchain/standard-tests` WITH build artifacts from the host. -# This is because we build @langchain/standard-tests before running this script. -mkdir -p "$monorepo_standard_tests_dir/" -cp -r "$original_standard_tests_dir"/* "$monorepo_standard_tests_dir/" - -# Copy `@langchain/anthropic` WITHOUT build artifacts from the host. -mkdir -p "$monorepo_anthropic_dir/" -cp -r "$original_anthropic_dir"/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) "$monorepo_anthropic_dir/" - -# Copy the turbo and package.json files for monorepo -cp "$original_turbo_json_dir" "$monorepo_dir/" -cp "$original_package_json_dir" "$monorepo_dir/" - -# Replace any workspace dependencies in `@langchain/standard-tests` -# with "latest" for the version. -mkdir -p "$standard_tests_updater_script_dir" -cp "$original_standard_tests_updater_script_dir"/* "$standard_tests_updater_script_dir/" -cd "$standard_tests_updater_script_dir" -# Run the updater script -node "update_workspace_dependencies.js" - -# Navigate back to root -cd "/app" +# Run the shared script to copy all necessary folders/files +bash /scripts/with_standard_tests/shared.sh anthropic mkdir -p "$updater_script_dir" cp "$original_updater_script_dir"/* "$updater_script_dir/" cd "$updater_script_dir" # Update any workspace dep to the latest version since not all workspaces are -# available in the test enviroment. +# available in the test enviroment. node "update_workspace_deps.js" # Navigate back to monorepo root and install dependencies diff --git a/dependency_range_tests/scripts/with_standard_tests/anthropic/test-with-lowest-deps.sh b/dependency_range_tests/scripts/with_standard_tests/anthropic/test-with-lowest-deps.sh index d473ff584a5f..97a603c9344d 100644 --- a/dependency_range_tests/scripts/with_standard_tests/anthropic/test-with-lowest-deps.sh +++ b/dependency_range_tests/scripts/with_standard_tests/anthropic/test-with-lowest-deps.sh @@ -4,69 +4,30 @@ set -euxo pipefail export CI=true -# New monorepo directory paths monorepo_dir="/app/monorepo" -monorepo_libs_dir="$monorepo_dir/libs" -monorepo_anthropic_dir="$monorepo_libs_dir/langchain-anthropic" -monorepo_standard_tests_dir="$monorepo_libs_dir/langchain-standard-tests" - -# Updater script will not live inside the monorepo +monorepo_openai_dir="/app/monorepo/libs/langchain-anthropic" updater_script_dir="/app/updater_script" -standard_tests_updater_script_dir="/app/with_standard_script" - -# Original directory paths -original_anthropic_dir="/libs/langchain-anthropic" -original_standard_tests_dir="/libs/langchain-standard-tests" -original_package_json_dir="/package.json" -original_turbo_json_dir="/turbo.json" original_updater_script_dir="/scripts/with_standard_tests/anthropic/node" -original_standard_tests_updater_script_dir="/scripts/with_standard_tests/node" - -# enable extended globbing for omitting build artifacts -shopt -s extglob - -# Create the top level monorepo directory -mkdir -p "$monorepo_dir" - -# Copy `@langchain/standard-tests` WITH build artifacts from the host. -# This is because we build @langchain/standard-tests before running this script. -mkdir -p "$monorepo_standard_tests_dir/" -cp -r "$original_standard_tests_dir"/* "$monorepo_standard_tests_dir/" -# Copy `@langchain/anthropic` WITHOUT build artifacts from the host. -mkdir -p "$monorepo_anthropic_dir/" -cp -r "$original_anthropic_dir"/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) "$monorepo_anthropic_dir/" - -# Copy the turbo and package.json files for monorepo -cp "$original_turbo_json_dir" "$monorepo_dir/" -cp "$original_package_json_dir" "$monorepo_dir/" - -# Replace any workspace dependencies in `@langchain/standard-tests` -# with "latest" for the version. -mkdir -p "$standard_tests_updater_script_dir" -cp "$original_standard_tests_updater_script_dir"/* "$standard_tests_updater_script_dir/" -cd "$standard_tests_updater_script_dir" -# Run the updater script -node "update_workspace_dependencies.js" - -# Navigate back to root -cd "/app" +# Run the shared script to copy all necessary folders/files +bash /scripts/with_standard_tests/shared.sh anthropic +# Copy the updater script to the monorepo mkdir -p "$updater_script_dir" cp "$original_updater_script_dir"/* "$updater_script_dir/" + # Install deps (e.g semver) for the updater script cd "$updater_script_dir" yarn # Run the updater script node "update_resolutions_lowest.js" -node "update_workspace_deps.js" # Navigate back to monorepo root and install dependencies cd "$monorepo_dir" yarn # Navigate into `@langchain/anthropic` to build and run tests -# We need to run inside the anthropic directory so turbo repo does +# We need to run inside the package directory so turbo repo does # not try to build the package/it's workspace dependencies. -cd "$monorepo_anthropic_dir" +cd "$monorepo_openai_dir" yarn test diff --git a/dependency_range_tests/scripts/with_standard_tests/community/test-with-latest-deps.sh b/dependency_range_tests/scripts/with_standard_tests/community/test-with-latest-deps.sh index 7787909d3233..78ffe93003ef 100644 --- a/dependency_range_tests/scripts/with_standard_tests/community/test-with-latest-deps.sh +++ b/dependency_range_tests/scripts/with_standard_tests/community/test-with-latest-deps.sh @@ -6,46 +6,10 @@ export CI=true # New monorepo directory paths monorepo_dir="/app/monorepo" -monorepo_libs_dir="$monorepo_dir/libs" -monorepo_community_dir="$monorepo_libs_dir/langchain-community" -monorepo_standard_tests_dir="$monorepo_libs_dir/langchain-standard-tests" +monorepo_community_dir="/app/monorepo/libs/langchain-community" -# Updater script will not live inside the monorepo -standard_tests_updater_script_dir="/app/with_standard_script" - -# Original directory paths -original_community_dir="/libs/langchain-community" -original_standard_tests_dir="/libs/langchain-standard-tests" -original_package_json_dir="/package.json" -original_turbo_json_dir="/turbo.json" -original_standard_tests_updater_script_dir="/scripts/with_standard_tests/node" - -# enable extended globbing for omitting build artifacts -shopt -s extglob - -# Create the top level monorepo directory -mkdir -p "$monorepo_dir" - -# Copy `@langchain/standard-tests` WITH build artifacts from the host. -# This is because we build @langchain/standard-tests before running this script. -mkdir -p "$monorepo_standard_tests_dir/" -cp -r "$original_standard_tests_dir"/* "$monorepo_standard_tests_dir/" - -# Copy `@langchain/community` WITHOUT build artifacts from the host. -mkdir -p "$monorepo_community_dir/" -cp -r "$original_community_dir"/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) "$monorepo_community_dir/" - -# Copy the turbo and package.json files for monorepo -cp "$original_turbo_json_dir" "$monorepo_dir/" -cp "$original_package_json_dir" "$monorepo_dir/" - -# Replace any workspace dependencies in `@langchain/standard-tests` -# with "latest" for the version. -mkdir -p "$standard_tests_updater_script_dir" -cp "$original_standard_tests_updater_script_dir"/* "$standard_tests_updater_script_dir/" -cd "$standard_tests_updater_script_dir" -# Run the updater script -node "update_workspace_dependencies.js" +# Run the shared script to copy all necessary folders/files +bash /scripts/with_standard_tests/shared.sh community # Navigate back to monorepo root and install dependencies cd "$monorepo_dir" diff --git a/dependency_range_tests/scripts/with_standard_tests/community/test-with-lowest-deps.sh b/dependency_range_tests/scripts/with_standard_tests/community/test-with-lowest-deps.sh index ebb9928bb86f..e0aa7adc7ef2 100644 --- a/dependency_range_tests/scripts/with_standard_tests/community/test-with-lowest-deps.sh +++ b/dependency_range_tests/scripts/with_standard_tests/community/test-with-lowest-deps.sh @@ -4,68 +4,32 @@ set -euxo pipefail export CI=true -# New monorepo directory paths monorepo_dir="/app/monorepo" -monorepo_libs_dir="$monorepo_dir/libs" -monorepo_community_dir="$monorepo_libs_dir/langchain-community" -monorepo_standard_tests_dir="$monorepo_libs_dir/langchain-standard-tests" - -# Updater script will not live inside the monorepo +monorepo_community_dir="/app/monorepo/libs/langchain-community" +updater_script_dir="/app/updater_script" updater_script_dir="/app/updater_script" -standard_tests_updater_script_dir="/app/with_standard_script" - -# Original directory paths -original_community_dir="/libs/langchain-community" -original_standard_tests_dir="/libs/langchain-standard-tests" -original_package_json_dir="/package.json" -original_turbo_json_dir="/turbo.json" original_updater_script_dir="/scripts/with_standard_tests/community/node" -original_standard_tests_updater_script_dir="/scripts/with_standard_tests/node" - -# enable extended globbing for omitting build artifacts -shopt -s extglob - -# Create the top level monorepo directory -mkdir -p "$monorepo_dir" - -# Copy `@langchain/standard-tests` WITH build artifacts from the host. -# This is because we build @langchain/standard-tests before running this script. -mkdir -p "$monorepo_standard_tests_dir/" -cp -r "$original_standard_tests_dir"/* "$monorepo_standard_tests_dir/" -# Copy `@langchain/community` WITHOUT build artifacts from the host. -mkdir -p "$monorepo_community_dir/" -cp -r "$original_community_dir"/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) "$monorepo_community_dir/" - -# Copy the turbo and package.json files for monorepo -cp "$original_turbo_json_dir" "$monorepo_dir/" -cp "$original_package_json_dir" "$monorepo_dir/" - -# Replace any workspace dependencies in `@langchain/standard-tests` -# with "latest" for the version. -mkdir -p "$standard_tests_updater_script_dir" -cp "$original_standard_tests_updater_script_dir"/* "$standard_tests_updater_script_dir/" -cd "$standard_tests_updater_script_dir" -# Run the updater script -node "update_workspace_dependencies.js" - -# Navigate back to root -cd "/app" +# Run the shared script to copy all necessary folders/files +bash /scripts/with_standard_tests/shared.sh community +# Copy the updater script to the monorepo mkdir -p "$updater_script_dir" cp "$original_updater_script_dir"/* "$updater_script_dir/" + # Install deps (e.g semver) for the updater script cd "$updater_script_dir" yarn # Run the updater script node "update_resolutions_lowest.js" + # Navigate back to monorepo root and install dependencies cd "$monorepo_dir" yarn -# Navigate into `@langchain/community` to build and run tests -# We need to run inside the community directory so turbo repo does +# Navigate into `@langchain/package` to build and run tests +# We need to run inside the package directory so turbo repo does # not try to build the package/it's workspace dependencies. cd "$monorepo_community_dir" yarn test diff --git a/dependency_range_tests/scripts/with_standard_tests/openai/test-with-latest-deps.sh b/dependency_range_tests/scripts/with_standard_tests/openai/test-with-latest-deps.sh index 8d7dcb56fab2..90cf98ab170f 100644 --- a/dependency_range_tests/scripts/with_standard_tests/openai/test-with-latest-deps.sh +++ b/dependency_range_tests/scripts/with_standard_tests/openai/test-with-latest-deps.sh @@ -6,46 +6,10 @@ export CI=true # New monorepo directory paths monorepo_dir="/app/monorepo" -monorepo_libs_dir="$monorepo_dir/libs" -monorepo_openai_dir="$monorepo_libs_dir/langchain-openai" -monorepo_standard_tests_dir="$monorepo_libs_dir/langchain-standard-tests" +monorepo_openai_dir="/app/monorepo/libs/langchain-openai" -# Updater script will not live inside the monorepo -standard_tests_updater_script_dir="/app/with_standard_script" - -# Original directory paths -original_openai_dir="/libs/langchain-openai" -original_standard_tests_dir="/libs/langchain-standard-tests" -original_package_json_dir="/package.json" -original_turbo_json_dir="/turbo.json" -original_standard_tests_updater_script_dir="/scripts/with_standard_tests/node" - -# enable extended globbing for omitting build artifacts -shopt -s extglob - -# Create the top level monorepo directory -mkdir -p "$monorepo_dir" - -# Copy `@langchain/standard-tests` WITH build artifacts from the host. -# This is because we build @langchain/standard-tests before running this script. -mkdir -p "$monorepo_standard_tests_dir/" -cp -r "$original_standard_tests_dir"/* "$monorepo_standard_tests_dir/" - -# Copy `@langchain/openai` WITHOUT build artifacts from the host. -mkdir -p "$monorepo_openai_dir/" -cp -r "$original_openai_dir"/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) "$monorepo_openai_dir/" - -# Copy the turbo and package.json files for monorepo -cp "$original_turbo_json_dir" "$monorepo_dir/" -cp "$original_package_json_dir" "$monorepo_dir/" - -# Replace any workspace dependencies in `@langchain/standard-tests` -# with "latest" for the version. -mkdir -p "$standard_tests_updater_script_dir" -cp "$original_standard_tests_updater_script_dir"/* "$standard_tests_updater_script_dir/" -cd "$standard_tests_updater_script_dir" -# Run the updater script -node "update_workspace_dependencies.js" +# Run the shared script to copy all necessary folders/files +bash /scripts/with_standard_tests/shared.sh openai # Navigate back to monorepo root and install dependencies cd "$monorepo_dir" diff --git a/dependency_range_tests/scripts/with_standard_tests/openai/test-with-lowest-deps.sh b/dependency_range_tests/scripts/with_standard_tests/openai/test-with-lowest-deps.sh index b9fbbd267334..42a401d9a996 100644 --- a/dependency_range_tests/scripts/with_standard_tests/openai/test-with-lowest-deps.sh +++ b/dependency_range_tests/scripts/with_standard_tests/openai/test-with-lowest-deps.sh @@ -4,68 +4,32 @@ set -euxo pipefail export CI=true -# New monorepo directory paths monorepo_dir="/app/monorepo" -monorepo_libs_dir="$monorepo_dir/libs" -monorepo_openai_dir="$monorepo_libs_dir/langchain-openai" -monorepo_standard_tests_dir="$monorepo_libs_dir/langchain-standard-tests" - -# Updater script will not live inside the monorepo +monorepo_openai_dir="/app/monorepo/libs/langchain-openai" +updater_script_dir="/app/updater_script" updater_script_dir="/app/updater_script" -standard_tests_updater_script_dir="/app/with_standard_script" - -# Original directory paths -original_openai_dir="/libs/langchain-openai" -original_standard_tests_dir="/libs/langchain-standard-tests" -original_package_json_dir="/package.json" -original_turbo_json_dir="/turbo.json" original_updater_script_dir="/scripts/with_standard_tests/openai/node" -original_standard_tests_updater_script_dir="/scripts/with_standard_tests/node" - -# enable extended globbing for omitting build artifacts -shopt -s extglob - -# Create the top level monorepo directory -mkdir -p "$monorepo_dir" - -# Copy `@langchain/standard-tests` WITH build artifacts from the host. -# This is because we build @langchain/standard-tests before running this script. -mkdir -p "$monorepo_standard_tests_dir/" -cp -r "$original_standard_tests_dir"/* "$monorepo_standard_tests_dir/" -# Copy `@langchain/openai` WITHOUT build artifacts from the host. -mkdir -p "$monorepo_openai_dir/" -cp -r "$original_openai_dir"/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) "$monorepo_openai_dir/" - -# Copy the turbo and package.json files for monorepo -cp "$original_turbo_json_dir" "$monorepo_dir/" -cp "$original_package_json_dir" "$monorepo_dir/" - -# Replace any workspace dependencies in `@langchain/standard-tests` -# with "latest" for the version. -mkdir -p "$standard_tests_updater_script_dir" -cp "$original_standard_tests_updater_script_dir"/* "$standard_tests_updater_script_dir/" -cd "$standard_tests_updater_script_dir" -# Run the updater script -node "update_workspace_dependencies.js" - -# Navigate back to root -cd "/app" +# Run the shared script to copy all necessary folders/files +bash /scripts/with_standard_tests/shared.sh openai +# Copy the updater script to the monorepo mkdir -p "$updater_script_dir" cp "$original_updater_script_dir"/* "$updater_script_dir/" + # Install deps (e.g semver) for the updater script cd "$updater_script_dir" yarn # Run the updater script node "update_resolutions_lowest.js" + # Navigate back to monorepo root and install dependencies cd "$monorepo_dir" yarn -# Navigate into `@langchain/openai` to build and run tests -# We need to run inside the openai directory so turbo repo does +# Navigate into `@langchain/package` to build and run tests +# We need to run inside the package directory so turbo repo does # not try to build the package/it's workspace dependencies. cd "$monorepo_openai_dir" yarn test diff --git a/dependency_range_tests/scripts/with_standard_tests/shared.sh b/dependency_range_tests/scripts/with_standard_tests/shared.sh new file mode 100644 index 000000000000..3a3eda1edb46 --- /dev/null +++ b/dependency_range_tests/scripts/with_standard_tests/shared.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Extract the package name from the first argument +package_name=$1 + +# New monorepo directory paths +monorepo_dir="/app/monorepo" +monorepo_libs_dir="$monorepo_dir/libs" +monorepo_package_dir="$monorepo_libs_dir/langchain-$package_name" +monorepo_standard_tests_dir="$monorepo_libs_dir/langchain-standard-tests" + +# Updater script will not live inside the monorepo +standard_tests_updater_script_dir="/app/with_standard_script" + +# Original directory paths +original_package_dir="/libs/langchain-$package_name" +original_standard_tests_dir="/libs/langchain-standard-tests" +original_package_json_dir="/package.json" +original_turbo_json_dir="/turbo.json" +original_standard_tests_updater_script_dir="/scripts/with_standard_tests/node" + +# enable extended globbing for omitting build artifacts +shopt -s extglob + +# Create the top level monorepo directory +mkdir -p "$monorepo_dir" + +# Copy `@langchain/standard-tests` WITH build artifacts from the host. +# This is because we build @langchain/standard-tests before running this script. +mkdir -p "$monorepo_standard_tests_dir/" +cp -r "$original_standard_tests_dir"/* "$monorepo_standard_tests_dir/" + +# Copy `@langchain/package` WITHOUT build artifacts from the host. +mkdir -p "$monorepo_package_dir/" +cp -r "$original_package_dir"/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) "$monorepo_package_dir/" + +# Copy the turbo and package.json files for monorepo +cp "$original_turbo_json_dir" "$monorepo_dir/" +cp "$original_package_json_dir" "$monorepo_dir/" + +# Replace any workspace dependencies in `@langchain/standard-tests` +# with "latest" for the version. +mkdir -p "$standard_tests_updater_script_dir" +cp "$original_standard_tests_updater_script_dir"/* "$standard_tests_updater_script_dir/" +cd "$standard_tests_updater_script_dir" +# Run the updater script +node "update_workspace_dependencies.js" + +# Navigate back to root +cd "/app"