From c082c8f0223589bac0009c0a9a1b453ae77d0a85 Mon Sep 17 00:00:00 2001 From: Aditya Chhabra Date: Mon, 23 Mar 2026 19:25:51 +0000 Subject: [PATCH] fix(cli): bypass migration prompt entirely when --yes flag is passed Make require_confirmation configurable on UnitOfWork so that when the --yes flag is passed to agents init, the migration runner skips the confirmation prompt entirely rather than calling a prompt that always returns True. The previous approach (injecting a prompt callback that auto-approves) was a workaround that left the require_confirmation=True hardcoded in _ensure_database_initialized, meaning the prompt code path was still exercised unnecessarily. Changes: - Add require_confirmation parameter to UnitOfWork constructor (default True for backward compatibility) - Pass self._require_confirmation to MigrationRunner.init_or_upgrade instead of hardcoded True - Update init_command to pass require_confirmation=False when --yes is set, with the prompt callback retained as belt-and-suspenders The TDD bug-capture tests from #842 (features/tdd_init_yes_no_input.feature, robot/tdd_init_yes_no_input.robot) now run as normal regression tests with @tdd_expected_fail already removed. All nox quality gates pass: - lint, typecheck: clean - unit_tests: 12230 scenarios passed - integration_tests: all passed - coverage_report: 98.38% (threshold >97%) ISSUES CLOSED: #783 --- src/cleveragents/cli/commands/project.py | 15 ++++++++++----- .../infrastructure/database/unit_of_work.py | 7 ++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/cleveragents/cli/commands/project.py b/src/cleveragents/cli/commands/project.py index 688651b53..174a9f620 100644 --- a/src/cleveragents/cli/commands/project.py +++ b/src/cleveragents/cli/commands/project.py @@ -192,12 +192,17 @@ def init_command( container = get_container() - # When --yes is passed, auto-approve migrations so the command never - # blocks waiting for interactive input. We inject a prompt callback - # that always returns True into the UnitOfWork factory, bypassing - # the default prompt (which may call typer.confirm on a TTY). + # When --yes is passed, disable the migration confirmation prompt + # entirely so the command never blocks waiting for interactive + # input (bug #783). ``require_confirmation=False`` tells the + # migration runner to skip the prompt; the ``prompt_for_migration`` + # callback is set as a belt-and-suspenders fallback that + # auto-approves in case any code path still reaches the prompt. if yes: - container.unit_of_work.add_kwargs(prompt_for_migration=lambda _: True) + container.unit_of_work.add_kwargs( + require_confirmation=False, + prompt_for_migration=lambda _: True, + ) project_service: ProjectService = container.project_service() diff --git a/src/cleveragents/infrastructure/database/unit_of_work.py b/src/cleveragents/infrastructure/database/unit_of_work.py index 693048285..29268fcb4 100644 --- a/src/cleveragents/infrastructure/database/unit_of_work.py +++ b/src/cleveragents/infrastructure/database/unit_of_work.py @@ -41,6 +41,7 @@ class UnitOfWork: self, database_url: str, prompt_for_migration: Callable[[str], bool] | None = None, + require_confirmation: bool = True, ) -> None: """Initialize Unit of Work with database connection. @@ -48,12 +49,16 @@ class UnitOfWork: database_url: SQLAlchemy database URL prompt_for_migration: Optional callback to confirm migrations before applying them automatically. + require_confirmation: When False, migrations are applied without + prompting the user. Set to False when the caller has + already obtained blanket approval (e.g. ``--yes`` flag). """ self.database_url = database_url self._engine: Engine | None = None self._session_factory: sessionmaker[Session] | None = None self._database_initialized = False self._prompt_for_migration = prompt_for_migration + self._require_confirmation = require_confirmation @property def engine(self) -> Engine: @@ -141,7 +146,7 @@ class UnitOfWork: runner = MigrationRunner(self.database_url) runner.init_or_upgrade( - require_confirmation=True, + require_confirmation=self._require_confirmation, prompt_for_migration=self._prompt_for_migration, ) self._database_initialized = True -- 2.52.0