diff --git a/libs/cli/langgraph_cli/deploy.py b/libs/cli/langgraph_cli/deploy.py index 4e5346a5f..97d339759 100644 --- a/libs/cli/langgraph_cli/deploy.py +++ b/libs/cli/langgraph_cli/deploy.py @@ -1604,11 +1604,15 @@ def _deploy_cmd( # -- 1. Preflight -- validate_deploy_commands(install_command, build_command) if not config.exists(): - raise click.ClickException( + message = ( "We couldn't find a langgraph.json file. Run `langgraph deploy` from " "the root of a LangSmith Deployment project. To get started, visit " "https://docs.langchain.com/langsmith/application-structure." ) + if json_output: + em.error(message) + raise click.exceptions.Exit(1) + raise click.ClickException(message) config_json = langgraph_cli.config.validate_config_file(config) warn_non_wolfi_distro(config_json, emit=em.note) diff --git a/libs/cli/tests/unit_tests/cli/test_cli.py b/libs/cli/tests/unit_tests/cli/test_cli.py index 8f964f97b..fe2b77ed0 100644 --- a/libs/cli/tests/unit_tests/cli/test_cli.py +++ b/libs/cli/tests/unit_tests/cli/test_cli.py @@ -333,6 +333,18 @@ def test_deploy_missing_config_shows_actionable_error(tmp_path, monkeypatch) -> assert "Traceback" not in result.output +def test_deploy_missing_config_emits_json_error(tmp_path, monkeypatch) -> None: + runner = CliRunner() + monkeypatch.chdir(tmp_path) + + result = runner.invoke(cli, ["deploy", "--json"]) + + assert result.exit_code == 1 + events = [json.loads(line) for line in result.output.splitlines()] + assert events[-1]["event"] == "error" + assert "We couldn't find a langgraph.json file." in events[-1]["message"] + + def test_dev_command_requires_ssl_certfile_and_keyfile_together(tmp_path) -> None: config_path = tmp_path / "langgraph.json" config_path.write_text(