From 5b58efc8d72a76aeb6c02e1f15b8376a40c11304 Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Tue, 8 Apr 2025 17:08:24 -0700 Subject: [PATCH] Update tests --- libs/cli/tests/unit_tests/cli/test_cli.py | 4 +- libs/cli/tests/unit_tests/test_config.py | 84 +++++++++++++++-------- 2 files changed, 60 insertions(+), 28 deletions(-) diff --git a/libs/cli/tests/unit_tests/cli/test_cli.py b/libs/cli/tests/unit_tests/cli/test_cli.py index 53954da5e..4140ee9a5 100644 --- a/libs/cli/tests/unit_tests/cli/test_cli.py +++ b/libs/cli/tests/unit_tests/cli/test_cli.py @@ -2,13 +2,14 @@ import json import pathlib import shutil import tempfile +import textwrap from contextlib import contextmanager from pathlib import Path from click.testing import CliRunner from langgraph_cli.cli import cli, prepare_args_and_stdin -from langgraph_cli.config import Config, validate_config +from langgraph_cli.config import PIP_CLEANUP_LINES, Config, validate_config from langgraph_cli.docker import DEFAULT_POSTGRES_URI, DockerCapabilities, Version from langgraph_cli.util import clean_empty_lines @@ -143,6 +144,7 @@ services: RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- ENV LANGSERVE_GRAPHS='{{"agent": "agent.py:graph"}}' +{textwrap.indent(textwrap.dedent(PIP_CLEANUP_LINES), " ")} WORKDIR /deps/cli develop: diff --git a/libs/cli/tests/unit_tests/test_config.py b/libs/cli/tests/unit_tests/test_config.py index dfa8cbbef..cb27b0d0c 100644 --- a/libs/cli/tests/unit_tests/test_config.py +++ b/libs/cli/tests/unit_tests/test_config.py @@ -2,11 +2,13 @@ import json import os import pathlib import tempfile +import textwrap import click import pytest from langgraph_cli.config import ( + PIP_CLEANUP_LINES, config_to_compose, config_to_docker, validate_config, @@ -208,7 +210,7 @@ def test_config_to_docker_simple(): ), "langchain/langgraph-api", ) - expected_docker_stdin = """\ + expected_docker_stdin = f"""\ FROM langchain/langgraph-api:3.11 # -- Installing local requirements -- COPY --from=__outer_requirements.txt requirements.txt /deps/__outer_graphs_reqs_a/graphs_reqs_a/requirements.txt @@ -242,8 +244,9 @@ RUN set -ex && \\ # -- Installing all local dependencies -- RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- -ENV LANGGRAPH_HTTP='{"app": "/deps/examples/my_app.py:app"}' -ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}' +ENV LANGGRAPH_HTTP='{{"app": "/deps/examples/my_app.py:app"}}' +ENV LANGSERVE_GRAPHS='{{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}}' +{PIP_CLEANUP_LINES} WORKDIR /deps/__outer_unit_tests/unit_tests\ """ assert clean_empty_lines(actual_docker_stdin) == expected_docker_stdin @@ -263,7 +266,8 @@ def test_config_to_docker_outside_path(): validate_config({"dependencies": [".", ".."], "graphs": graphs}), "langchain/langgraph-api", ) - expected_docker_stdin = """\ + expected_docker_stdin = ( + """\ FROM langchain/langgraph-api:3.11 # -- Adding non-package dependency unit_tests -- ADD . /deps/__outer_unit_tests/unit_tests @@ -291,8 +295,12 @@ RUN set -ex && \\ RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}' +""" + + PIP_CLEANUP_LINES + + """ WORKDIR /deps/__outer_unit_tests/unit_tests\ """ + ) assert clean_empty_lines(actual_docker_stdin) == expected_docker_stdin assert additional_contexts == { "__outer_tests": str(pathlib.Path(__file__).parent.parent.absolute()), @@ -312,7 +320,8 @@ def test_config_to_docker_pipconfig(): ), "langchain/langgraph-api", ) - expected_docker_stdin = """\ + expected_docker_stdin = ( + """\ FROM langchain/langgraph-api:3.11 ADD pipconfig.txt /pipconfig.txt # -- Adding non-package dependency unit_tests -- @@ -330,8 +339,12 @@ RUN set -ex && \\ RUN PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}' +""" + + PIP_CLEANUP_LINES + + """ WORKDIR /deps/__outer_unit_tests/unit_tests\ """ + ) assert clean_empty_lines(actual_docker_stdin) == expected_docker_stdin assert additional_contexts == {} @@ -368,7 +381,7 @@ def test_config_to_docker_local_deps(): ), "langchain/langgraph-api-custom", ) - expected_docker_stdin = """\ + expected_docker_stdin = f"""\ FROM langchain/langgraph-api-custom:3.11 # -- Adding non-package dependency graphs -- ADD ./graphs /deps/__outer_graphs/src @@ -384,7 +397,8 @@ RUN set -ex && \\ # -- Installing all local dependencies -- RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- -ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_graphs/src/agent.py:graph"}'\ +ENV LANGSERVE_GRAPHS='{{"agent": "/deps/__outer_graphs/src/agent.py:graph"}}' +{PIP_CLEANUP_LINES}\ """ assert clean_empty_lines(actual_docker_stdin) == expected_docker_stdin assert additional_contexts == {} @@ -411,7 +425,8 @@ dependencies = ["langchain"]""" "langchain/langgraph-api", ) os.remove(pyproject_path) - expected_docker_stdin = """FROM langchain/langgraph-api:3.11 + expected_docker_stdin = ( + """FROM langchain/langgraph-api:3.11 # -- Adding local package . -- ADD . /deps/unit_tests # -- End of local package . -- @@ -419,7 +434,12 @@ ADD . /deps/unit_tests RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- ENV LANGSERVE_GRAPHS='{"agent": "/deps/unit_tests/graphs/agent.py:graph"}' -WORKDIR /deps/unit_tests""" +""" + + PIP_CLEANUP_LINES + + "\n" + + "WORKDIR /deps/unit_tests" + "" + ) assert clean_empty_lines(actual_docker_stdin) == expected_docker_stdin assert additional_contexts == {} @@ -439,7 +459,7 @@ def test_config_to_docker_end_to_end(): ), "langchain/langgraph-api", ) - expected_docker_stdin = """FROM langchain/langgraph-api:3.12 + expected_docker_stdin = f"""FROM langchain/langgraph-api:3.12 ARG meow ARG foo ADD pipconfig.txt /pipconfig.txt @@ -458,7 +478,8 @@ RUN set -ex && \\ # -- Installing all local dependencies -- RUN PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- -ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_graphs/src/agent.py:graph"}'""" +ENV LANGSERVE_GRAPHS='{{"agent": "/deps/__outer_graphs/src/agent.py:graph"}}' +{PIP_CLEANUP_LINES}""" assert clean_empty_lines(actual_docker_stdin) == expected_docker_stdin assert additional_contexts == {} @@ -509,7 +530,7 @@ def test_config_to_docker_gen_ui_python(): "langchain/langgraph-api", ) - expected_docker_stdin = """FROM langchain/langgraph-api:3.11 + expected_docker_stdin = f"""FROM langchain/langgraph-api:3.11 RUN /storage/install-node.sh # -- Adding non-package dependency unit_tests -- ADD . /deps/__outer_unit_tests/unit_tests @@ -525,12 +546,13 @@ RUN set -ex && \\ # -- Installing all local dependencies -- RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- -ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}' +ENV LANGSERVE_GRAPHS='{{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}}' # -- Installing UI dependencies -- -ENV LANGGRAPH_UI='{"agent": "./graphs/agent.ui.jsx"}' -ENV LANGGRAPH_UI_CONFIG='{"shared": ["nuqs"]}' +ENV LANGGRAPH_UI='{{"agent": "./graphs/agent.ui.jsx"}}' +ENV LANGGRAPH_UI_CONFIG='{{"shared": ["nuqs"]}}' RUN cd /deps/__outer_unit_tests/unit_tests && npm i && tsx /api/langgraph_api/js/build.mts # -- End of UI dependencies install -- +{PIP_CLEANUP_LINES} WORKDIR /deps/__outer_unit_tests/unit_tests""" assert clean_empty_lines(actual_docker_stdin) == expected_docker_stdin @@ -540,8 +562,8 @@ WORKDIR /deps/__outer_unit_tests/unit_tests""" # config_to_compose def test_config_to_compose_simple_config(): graphs = {"agent": "./agent.py:graph"} - expected_compose_stdin = """\ - + # Create a properly indented version of PIP_CLEANUP_LINES for compose files + expected_compose_stdin = f""" pull_policy: build build: context: . @@ -561,7 +583,8 @@ def test_config_to_compose_simple_config(): # -- Installing all local dependencies -- RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- - ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}' + ENV LANGSERVE_GRAPHS='{{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}}' +{textwrap.indent(textwrap.dedent(PIP_CLEANUP_LINES), " ")} WORKDIR /deps/__outer_unit_tests/unit_tests """ actual_compose_stdin = config_to_compose( @@ -569,12 +592,15 @@ def test_config_to_compose_simple_config(): validate_config({"dependencies": ["."], "graphs": graphs}), "langchain/langgraph-api", ) - assert clean_empty_lines(actual_compose_stdin) == expected_compose_stdin + assert ( + clean_empty_lines(actual_compose_stdin).strip() + == expected_compose_stdin.strip() + ) def test_config_to_compose_env_vars(): graphs = {"agent": "./agent.py:graph"} - expected_compose_stdin = """ OPENAI_API_KEY: "key" + expected_compose_stdin = f""" OPENAI_API_KEY: "key" pull_policy: build build: @@ -595,7 +621,8 @@ def test_config_to_compose_env_vars(): # -- Installing all local dependencies -- RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- - ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}' + ENV LANGSERVE_GRAPHS='{{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}}' +{textwrap.indent(textwrap.dedent(PIP_CLEANUP_LINES), " ")} WORKDIR /deps/__outer_unit_tests/unit_tests """ openai_api_key = "key" @@ -615,7 +642,7 @@ def test_config_to_compose_env_vars(): def test_config_to_compose_env_file(): graphs = {"agent": "./agent.py:graph"} - expected_compose_stdin = """\ + expected_compose_stdin = f"""\ env_file: .env pull_policy: build build: @@ -636,7 +663,8 @@ def test_config_to_compose_env_file(): # -- Installing all local dependencies -- RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- - ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}' + ENV LANGSERVE_GRAPHS='{{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}}' +{textwrap.indent(textwrap.dedent(PIP_CLEANUP_LINES), " ")} WORKDIR /deps/__outer_unit_tests/unit_tests """ actual_compose_stdin = config_to_compose( @@ -649,7 +677,7 @@ def test_config_to_compose_env_file(): def test_config_to_compose_watch(): graphs = {"agent": "./agent.py:graph"} - expected_compose_stdin = """\ + expected_compose_stdin = f"""\ pull_policy: build build: @@ -670,7 +698,8 @@ def test_config_to_compose_watch(): # -- Installing all local dependencies -- RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- - ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}' + ENV LANGSERVE_GRAPHS='{{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}}' +{textwrap.indent(textwrap.dedent(PIP_CLEANUP_LINES), " ")} WORKDIR /deps/__outer_unit_tests/unit_tests develop: @@ -692,7 +721,7 @@ def test_config_to_compose_watch(): def test_config_to_compose_end_to_end(): # test all of the above + langgraph API path graphs = {"agent": "./agent.py:graph"} - expected_compose_stdin = """\ + expected_compose_stdin = f"""\ env_file: .env pull_policy: build build: @@ -713,7 +742,8 @@ def test_config_to_compose_end_to_end(): # -- Installing all local dependencies -- RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -c /api/constraints.txt -e /deps/* # -- End of local dependencies install -- - ENV LANGSERVE_GRAPHS='{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}' + ENV LANGSERVE_GRAPHS='{{"agent": "/deps/__outer_unit_tests/unit_tests/agent.py:graph"}}' +{textwrap.indent(textwrap.dedent(PIP_CLEANUP_LINES), " ")} WORKDIR /deps/__outer_unit_tests/unit_tests develop: