Files
temp/features/steps/tdd_session_create_persist_steps.py
brent.edwards b59100cc6c test: add TDD bug-capture test for #1141 — session create persistence (#1144)
## Summary

Adds TDD bug-capture coverage for bug #1141 (`session create` -> `session list` lifecycle) on metadata branch `tdd/m3-session-create-persist`.

### What changed

- Added Behave bug-capture feature: `features/tdd_session_create_persist.feature`
  - Required tags: `@tdd_bug @tdd_bug_1141 @tdd_expected_fail`
  - Scenario path: `init --force --yes` -> `session list --format json` -> `session create` -> `session list --format json`
- Added Behave step definitions: `features/steps/tdd_session_create_persist_steps.py`
  - Uses root CLI app (`cleveragents.cli.main:app`) for realistic command routing
  - Asserts expected list totals; underlying assertion intentionally fails while bug is present
- Added Robot E2E bug-capture test: `robot/e2e/e2e_session_create_persist.robot`
  - Required tags: `E2E`, `tdd_expected_fail`, `tdd_bug`, `tdd_bug_1141`
  - Includes explicit in-file note to remove `tdd_expected_fail` when #1141 is fixed
- Updated changelog (`CHANGELOG.md`, Unreleased)

### Notes

- The issue subtask referenced `robot/e2e/e2e_session_lifecycle.robot`, which is not present on current `master`; equivalent E2E coverage is implemented in `robot/e2e/e2e_session_create_persist.robot`.
- The branch was force-updated to remove stale merge-based history and keep an atomic, rebase-clean commit for this issue.

## Quality gates

| Gate | Result |
|---|---|
| `nox -s lint` |  pass |
| `nox -s typecheck` |  pass |
| `nox -s unit_tests -- features/tdd_session_create_persist.feature` |  pass (TDD inversion active; underlying assert fails) |
| `nox -s integration_tests -- robot/e2e/e2e_session_create_persist.robot` |  pass |
| `nox -s e2e_tests` |  pass |
| `nox -s coverage_report` |  pass (97.66173849218832%) |
| `nox` (full default suite) |  pass |

## Related issue

Closes #1142

Reviewed-on: cleveragents/cleveragents-core#1144
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 04:34:47 +00:00

91 lines
3.1 KiB
Python

"""Step definitions for TDD Bug #1141 — session create does not persist.
Steps exercise the create-then-list round-trip through the real DI path.
All step names use the ``tdd1141`` prefix to avoid ``AmbiguousStep``
collisions with existing session create/list steps.
The shared ``Given a CLI runner using the real session DI path`` step
(from ``tdd_session_shared_steps.py``) handles setup and cleanup:
temp database, DI reset, structlog suppression, and cleanup registration.
"""
from __future__ import annotations
import json
from behave import then, when
from behave.runner import Context
from cleveragents.cli.main import app as main_app
@when("I tdd1141 invoke init with force yes")
def step_tdd1141_invoke_init(context: Context) -> None:
"""Invoke ``init --force --yes`` via the root CLI app."""
context.tdd1141_init_result = context.runner.invoke(
main_app, ["init", "--force", "--yes"]
)
@then("the tdd1141 init should exit successfully")
def step_tdd1141_init_exits_ok(context: Context) -> None:
"""Assert init exits with code 0."""
result = context.tdd1141_init_result
assert result.exit_code == 0, (
f"Expected init exit code 0, got {result.exit_code}.\nOutput:\n{result.output}"
)
@when("I tdd1141 invoke session create")
def step_tdd1141_invoke_create(context: Context) -> None:
"""Invoke ``session create`` through the root CLI app."""
context.tdd1141_create_result = context.runner.invoke(
main_app, ["session", "create"]
)
@then("the tdd1141 session create should exit successfully")
def step_tdd1141_create_exits_ok(context: Context) -> None:
"""Assert session create exits with code 0."""
result = context.tdd1141_create_result
assert result.exit_code == 0, (
f"Expected session create exit code 0, got {result.exit_code}.\n"
f"Output:\n{result.output}"
)
@when("I tdd1141 invoke session list with format json")
def step_tdd1141_invoke_list_json(context: Context) -> None:
"""Invoke ``session list --format json`` through the root CLI app."""
context.tdd1141_list_result = context.runner.invoke(
main_app, ["session", "list", "--format", "json"]
)
@then("the tdd1141 session list should exit successfully")
def step_tdd1141_list_exits_ok(context: Context) -> None:
"""Assert session list exits with code 0."""
result = context.tdd1141_list_result
assert result.exit_code == 0, (
f"Expected session list exit code 0, got {result.exit_code}.\n"
f"Output:\n{result.output}"
)
@then("the tdd1141 session list output should report total {count:d}")
def step_tdd1141_list_contains_count(context: Context, count: int) -> None:
"""Assert the JSON output reports the expected total session count."""
output = context.tdd1141_list_result.output
try:
data = json.loads(output)
except json.JSONDecodeError as exc:
raise AssertionError(
f"Session list output is not valid JSON:\n{output}"
) from exc
actual = data.get("total")
assert actual == count, (
f"Expected 'total': {count} in session list output, got {actual!r}.\n"
f"Full output:\n{output}"
)