-
Notifications
You must be signed in to change notification settings - Fork 147
feat(cli): bootstrap default configs on CLI startup #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c383f3f
dd51f5e
5714a1a
64e105a
cddb978
db0a66f
4bfb63d
e6df11b
9fb5b38
efa2eef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from data_designer.cli.ui import print_warning | ||
| from data_designer.config.default_model_settings import resolve_seed_default_model_settings | ||
|
|
||
|
|
||
| def ensure_cli_default_model_settings() -> None: | ||
| """Best-effort bootstrap for CLI default model settings. | ||
|
|
||
| Repeated calls are safe because ``resolve_seed_default_model_settings()`` | ||
| only writes missing files/directories. | ||
| """ | ||
| try: | ||
| resolve_seed_default_model_settings() | ||
| except Exception as e: | ||
| print_warning( | ||
| "Could not initialize default model providers and model configs automatically. " | ||
| f"The command will continue. Error: {e}. " | ||
| "You will need to configure providers and models manually with " | ||
| "`data-designer config providers` and `data-designer config models`." | ||
| ) | ||
|
johnnygreco marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import Mock, call, patch | ||
|
|
||
| from typer.testing import CliRunner | ||
|
|
||
| from data_designer.cli.main import app, main | ||
| from data_designer.config.utils.constants import DEFAULT_NUM_RECORDS | ||
|
|
||
| runner = CliRunner() | ||
|
|
||
|
|
||
| @patch("data_designer.cli.main.app") | ||
| @patch("data_designer.cli.main.ensure_cli_default_model_settings") | ||
| def test_main_bootstraps_before_running_app(mock_bootstrap: Mock, mock_app: Mock) -> None: | ||
| """The CLI entrypoint bootstraps defaults before invoking Typer.""" | ||
| call_order = Mock() | ||
| call_order.attach_mock(mock_bootstrap, "bootstrap") | ||
| call_order.attach_mock(mock_app, "app") | ||
|
|
||
| main() | ||
|
|
||
| assert call_order.mock_calls == [call.bootstrap(), call.app()] | ||
|
|
||
|
|
||
| @patch("data_designer.cli.commands.create.GenerationController") | ||
| def test_app_dispatches_lazy_create_command(mock_controller_cls: Mock) -> None: | ||
| """The Typer app dispatches lazy-loaded commands through the resolved callback.""" | ||
| mock_controller = Mock() | ||
| mock_controller_cls.return_value = mock_controller | ||
|
|
||
| result = runner.invoke(app, ["create", "config.yaml"]) | ||
|
|
||
| assert result.exit_code == 0 | ||
| mock_controller.run_create.assert_called_once_with( | ||
| config_source="config.yaml", | ||
| num_records=DEFAULT_NUM_RECORDS, | ||
| dataset_name="dataset", | ||
| artifact_path=None, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import patch | ||
|
|
||
| import data_designer.cli.runtime as runtime_mod | ||
|
|
||
|
|
||
| def test_ensure_cli_default_model_settings_attempts_default_setup() -> None: | ||
| """CLI bootstrap delegates to default setup when the CLI starts.""" | ||
| with ( | ||
| patch("data_designer.cli.runtime.print_warning") as mock_print_warning, | ||
| patch("data_designer.cli.runtime.resolve_seed_default_model_settings") as mock_resolve, | ||
| ): | ||
| runtime_mod.ensure_cli_default_model_settings() | ||
|
|
||
| mock_resolve.assert_called_once_with() | ||
| mock_print_warning.assert_not_called() | ||
|
|
||
|
|
||
| def test_ensure_cli_default_model_settings_warns_and_continues() -> None: | ||
| """CLI bootstrap prints an actionable warning when setup fails.""" | ||
| with ( | ||
| patch("data_designer.cli.runtime.print_warning") as mock_print_warning, | ||
| patch( | ||
| "data_designer.cli.runtime.resolve_seed_default_model_settings", | ||
| side_effect=RuntimeError("boom"), | ||
| ) as mock_resolve, | ||
| ): | ||
| runtime_mod.ensure_cli_default_model_settings() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (AR) Suggestion: Explicitly document the no-raise contract What: This test verifies the warning message content when Why: The core behavioral contract is that this function swallows exceptions and continues — the CLI must not crash if bootstrap fails. If someone accidentally narrows the Suggestion: Add a comment making the implicit assertion explicit: # Must not raise — the function swallows exceptions and warns instead
runtime_mod.ensure_cli_default_model_settings()
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am leaving this one as-is. If |
||
|
|
||
| mock_resolve.assert_called_once_with() | ||
| mock_print_warning.assert_called_once() | ||
| warning = mock_print_warning.call_args[0][0] | ||
| assert "Could not initialize default model providers and model configs automatically." in warning | ||
| assert "The command will continue." in warning | ||
| assert "boom" in warning | ||
| assert "data-designer config providers" in warning | ||
| assert "data-designer config models" in warning | ||
Uh oh!
There was an error while loading. Please reload this page.