test(cli): TDD failing tests for init --yes non-interactive (bug #783) #1049
No reviewers
Labels
No labels
auto/needs-reevaluation
controller-managed
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Blocks
#842 TDD:
agents init --yes should not require user input (bug #783)
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core!1049
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "tdd/m3-init-yes-no-input"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds TDD bug-capture tests proving that
agents init --yesfails to bypass themigration approval prompt in a TTY environment (bug #783). These tests follow the
mandatory TDD bug-fix workflow defined in CONTRIBUTING.md §Bug Fix Workflow.
Changes
Behave feature (
features/tdd_init_yes_no_input.feature): Two scenariostagged
@tdd_expected_fail @tdd_bug @tdd_bug_783that invokeagents init --yesin a fresh environment with the migration prompt simulated as declining (TTY with
no input). The tests verify the command exits successfully and does not display the
"Apply migrations now?" prompt.
Behave steps (
features/steps/tdd_init_yes_no_input_steps.py): Step definitionsthat create an isolated temp directory, clear auto-apply and database-URL environment
variables, patch
sys.stdinon the realsysmodule (correct mock target per projectconvention), and replace
MigrationRunner._default_prompt_for_migrationwith afunction that returns
False(simulating a TTY prompt where the user declines).Temp directory and env var cleanup is registered via
context.add_cleanup().Robot Framework test (
robot/tdd_init_yes_no_input.robot): Two integration testcases tagged
tdd_bug,tdd_bug_783,tdd_expected_failmatching the Behave scenarios.Robot helper (
robot/helper_tdd_init_yes_no_input.py): Helper script that exercisesthe same code path using the same mock strategy as the Behave steps.
Bug Reproduction Mechanism
The core challenge is that
CliRunnerreplacessys.stdinduringinvoke(), makingdirect
isatty()patching ineffective for controlling the prompt path. The mock strategyaddresses this with a two-pronged approach:
patch.object(sys, "stdin", mock_stdin)— Patchessys.stdindirectly on thereal
sysmodule (correct mock target per the project's established pattern infeatures/steps/migration_runner_steps.py). Documents the intent of simulating a TTY.patch.object(MigrationRunner, "_default_prompt_for_migration", ...)— Replacesthe prompt function with one that returns
False(simulating a TTY user decliningmigration). This is the mechanism that actually exercises the bug path, since
CliRunner's stdin replacement bypasses the
isatty()check.CLEVERAGENTS_DATABASE_URLwith non-template filename — Sets the database URLto a path whose filename does not match the
before_scenariotemplate-DB prefixes,forcing the real Alembic migration path instead of the test fast-path.
With bug #783 present,
require_confirmation=Trueis hardcoded inUnitOfWork._ensure_database_initialized(), so the prompt fires, returnsFalse,causing
MigrationNotApprovedErrorand a non-zero exit code. After the fix,--yesshould bypass the prompt entirely.
Root Cause (for the bug fix developer)
init_command()incleveragents.cli.commands.projectreceives the--yesflag butonly uses it to control output format. It does not forward
yesto the migration runner.The migration runner's
init_or_upgrade()is called viaunit_of_work._ensure_database_initialized()withrequire_confirmation=Truehardcoded.Scenario 2 Limitation
While the bug is present, Scenario 2's first assertion (exit code 0) fails and Behave
skips subsequent steps. The "contains Initialized" assertion is only evaluated after the
bug is fixed, providing distinct post-fix regression value.
Quality Gate Results
nox -s lint— ✅ passednox -s typecheck— ✅ passed (0 errors)nox -s unit_tests— ✅ passed (387 features, 11121 scenarios, 0 failed)nox -s integration_tests— ✅ passed (1561 tests, 0 failed)nox -s e2e_tests— ✅ passed (16 tests, 0 failed)nox -s coverage_report— ✅ passed (97% coverage)Closes #842
agents init --yesshould not require user input (bug #783)5f3158cf39c35e372a9cCode Review — PR #1049
test(cli): TDD failing tests for init --yes non-interactive (bug #783)Clean TDD test PR. Well-structured with 2 Behave scenarios + 2 Robot tests. The mock strategy is well-documented (patching
MigrationRunner._default_prompt_for_migrationsince CliRunner replacessys.stdin). TDD tags@tdd_expected_fail @tdd_bug @tdd_bug_783are correctly applied. Cleanup properly registered viacontext.add_cleanup().Approved. One very minor note: sibling PRs #1050-#1052 include CHANGELOG entries while this one does not. This is a minor inconsistency but not a blocker.