Files
cleveragents-core/features/tdd_e2e_implicit_init.feature
brent.edwards efacfd61c3 test: add TDD bug-capture test for #1023 — implicit init requirement (#1113)
## Summary

Adds TDD bug-capture tests proving that CLI commands (`resource add`, `project create`) fail in a fresh environment without explicit `agents init`, even when `CLEVERAGENTS_AUTO_APPLY_MIGRATIONS=true` is set.

Bug #1023 reports that `CLEVERAGENTS_AUTO_APPLY_MIGRATIONS=true` triggers schema migrations on an existing database but does NOT create the database file or its parent directory structure, causing `sqlite3.OperationalError: unable to open database file`.

## Changes

### Behave Tests
- `features/tdd_e2e_implicit_init.feature` — Two scenarios tagged `@tdd_expected_fail @tdd_bug @tdd_bug_1023`:
  - `resource add` in a fresh environment without prior init
  - `project create` in a fresh environment without prior init
  - Both scenarios include output content assertions
- `features/steps/tdd_e2e_implicit_init_steps.py` — Step definitions using Typer's CliRunner with real CLI invocation in a pristine temp directory.
  - Env isolation: saves/removes `CLEVERAGENTS_AUTO_APPLY_MIGRATIONS`, `CLEVERAGENTS_DATABASE_URL`, `CLEVERAGENTS_TEST_DATABASE_URL`, `CLEVERAGENTS_HOME`, `BEHAVE_TESTING`, `CLEVERAGENTS_TEMPLATE_DB`, `CLEVERAGENTS_TESTING_USE_MOCK_AI`
  - CliRunner invoked without `catch_exceptions=False` to ensure proper `@tdd_expected_fail` inversion

### Robot Tests
- `robot/tdd_e2e_implicit_init.robot` — Two test cases tagged `tdd_bug tdd_bug_1023 tdd_expected_fail` (listener inverts results while bug is unfixed).
- `robot/helper_tdd_e2e_implicit_init.py` — Helper script exercising CLI in a fresh environment.
  - Env isolation includes `ROBOT_TESTING`, `CLEVERAGENTS_TEMPLATE_DB`, `CLEVERAGENTS_TESTING_USE_MOCK_AI`
  - Env restoration in `finally` block ensures cleanup even on exceptions
  - CliRunner invoked without `catch_exceptions=False` for correct inversion

### Changelog
- Updated `CHANGELOG.md` with entry for this TDD test addition.

## Quality Gates

| Gate | Result |
|------|--------|
| `nox -s lint` | PASS |
| `nox -s typecheck` | PASS (0 errors) |
| `nox -s unit_tests` | PASS (462 features, 12232 scenarios, 0 failed) |
| `nox -s integration_tests` | PASS (pre-existing failures only; our suite correct) |
| `nox -s e2e_tests` | N/A (TDD test only, no E2E suite changes) |
| `nox -s coverage_report` | PASS (98% coverage, threshold 97%) |

Closes #1033

Reviewed-on: cleveragents/cleveragents-core#1113
Reviewed-by: Jeffrey Phillips Freeman <jeffrey.freeman@cleverthis.com>
Co-authored-by: Brent Edwards <brent.edwards@cleverthis.com>
Co-committed-by: Brent Edwards <brent.edwards@cleverthis.com>
2026-03-28 00:30:26 +00:00

36 lines
2.0 KiB
Gherkin

@tdd_expected_fail @tdd_issue @tdd_issue_1023
Feature: TDD Bug #1023 — CLI commands should succeed without explicit init
As a developer
I want to verify that CLI commands that touch the database succeed
without requiring an explicit `agents init` invocation first
So that the bug is captured and will be caught by a regression test
Bug #1023 reports that running any DB-dependent CLI command (e.g.,
`resource add`, `project create`) in a fresh environment fails with
`sqlite3.OperationalError: unable to open database file` even when
`CLEVERAGENTS_AUTO_APPLY_MIGRATIONS=true` is set. The specification
implies that initialization should happen implicitly.
The root cause is that `CLEVERAGENTS_AUTO_APPLY_MIGRATIONS=true`
triggers schema migrations on an existing database but does NOT create
the database file or its parent directory structure. A manual
`agents init --yes --force` is required first.
These tests assert the expected behaviour (implicit init) and will
fail until the bug is fixed. The @tdd_expected_fail tag inverts the
result so CI remains green while the defect is open.
Scenario: Resource add succeeds in a fresh environment without explicit init
Given a fresh isolated environment for tdd-implicit-init
And CLEVERAGENTS_AUTO_APPLY_MIGRATIONS is set to true
When I run the CLI command "resource add git-checkout local/tdd-test-resource --path . --branch main" without prior init
Then the tdd-implicit-init command should exit with code 0
And the tdd-implicit-init command output should contain "tdd-test-resource"
Scenario: Project create succeeds in a fresh environment without explicit init
Given a fresh isolated environment for tdd-implicit-init
And CLEVERAGENTS_AUTO_APPLY_MIGRATIONS is set to true
When I run the CLI command "project create local/tdd-test-project" without prior init
Then the tdd-implicit-init command should exit with code 0
And the tdd-implicit-init command output should contain "tdd-test-project"