Files
cleveragents-core/robot/project_create_persist.robot
brent.edwards 26de6bb7de fix(project): persist project to database during creation (#591)
## Summary

Fix `agents project create` not persisting projects to the database. `NamespacedProjectRepository.create()` called `session.flush()` but never `session.commit()`, so projects were invisible to subsequent `agents project list` invocations that open a separate session.

## Changes

**Production fix** (`src/cleveragents/infrastructure/database/repositories.py`):
- Replace `session.flush()` with `session.commit()` in `NamespacedProjectRepository.create()`
- Add `finally: session.close()` guard for proper session lifecycle

**Tests & benchmarks**:
- 4 Behave BDD regression scenarios (`features/project_create_persist.feature`)
- Robot Framework integration smoke tests (`robot/project_create_persist.robot`)
- ASV benchmarks for create-then-list round-trip (`benchmarks/project_create_persist_bench.py`)

## Review feedback addressed

- **H3**: Added `finally: session.close()` to `create()` method
- **M1**: Removed redundant `session.flush()` before `session.commit()`
- **M2**: Updated stale TDD "expected to fail" comments — this PR includes the fix
- **M4**: Rewrote CHANGELOG entry to describe the fix, not just tests
- **F1**: Updated Robot documentation (Suite Setup/Teardown kept — needed for `${PYTHON}`)
- **F2**: Fixed bare assertion `"my-app"` to `"local/my-app"` in namespace scenario
- **F3**: Removed redundant `Base.metadata.create_all()` from `_make_fresh_repo()`

## Process

- Single squashed commit, rebased onto `master` (no merge commits)
- Prescribed commit message from issue #589 metadata

ISSUES CLOSED: #589

Reviewed-on: cleveragents/cleveragents-core#591
Reviewed-by: Rui Hu <rui.hu@cleverthis.com>
Co-authored-by: Brent E. Edwards <brent.edwards@cleverthis.com>
Co-committed-by: Brent E. Edwards <brent.edwards@cleverthis.com>
2026-03-09 06:59:15 +00:00

56 lines
3.4 KiB
Plaintext

*** Settings ***
Documentation Integration smoke test for project create persistence (bug #589).
... Verifies that ``agents project create`` commits to the database
... so that ``agents project list`` shows previously created projects.
Resource ${CURDIR}/common.resource
Library Process
Library OperatingSystem
Library String
Suite Setup Setup Test Environment
Suite Teardown Cleanup Test Environment
*** Test Cases ***
Project Create Then List Shows Created Project
[Documentation] After creating a project, listing projects should include it.
${tmpdir}= Evaluate __import__('tempfile').mkdtemp(prefix='persist_589_')
${init}= Run Process ${PYTHON} -m cleveragents init persist-test
... timeout=60s cwd=${tmpdir}
Should Be Equal As Integers ${init.rc} 0
... msg=agents init should exit 0 but got ${init.rc}. stderr: ${init.stderr}
${create}= Run Process ${PYTHON} -m cleveragents project create local/smoke-proj
... timeout=60s cwd=${tmpdir}
Should Be Equal As Integers ${create.rc} 0
... msg=project create should exit 0 but got ${create.rc}. stderr: ${create.stderr}
${list}= Run Process ${PYTHON} -m cleveragents project list
... timeout=60s cwd=${tmpdir}
Should Be Equal As Integers ${list.rc} 0
... msg=project list should exit 0 but got ${list.rc}. stderr: ${list.stderr}
Should Contain ${list.stdout} local/smoke-proj
... msg=project list output should contain 'local/smoke-proj' but got: ${list.stdout}
[Teardown] Remove Directory ${tmpdir} recursive=True
Multiple Created Projects Appear In List
[Documentation] Creating two projects should result in both appearing in list.
${tmpdir}= Evaluate __import__('tempfile').mkdtemp(prefix='persist_589_multi_')
${init}= Run Process ${PYTHON} -m cleveragents init persist-multi
... timeout=60s cwd=${tmpdir}
Should Be Equal As Integers ${init.rc} 0
... msg=agents init should exit 0 but got ${init.rc}. stderr: ${init.stderr}
${create_first}= Run Process ${PYTHON} -m cleveragents project create local/first
... timeout=60s cwd=${tmpdir}
Should Be Equal As Integers ${create_first.rc} 0
... msg=project create local/first should exit 0 but got ${create_first.rc}. stderr: ${create_first.stderr}
${create_second}= Run Process ${PYTHON} -m cleveragents project create local/second
... timeout=60s cwd=${tmpdir}
Should Be Equal As Integers ${create_second.rc} 0
... msg=project create local/second should exit 0 but got ${create_second.rc}. stderr: ${create_second.stderr}
${list}= Run Process ${PYTHON} -m cleveragents project list
... timeout=60s cwd=${tmpdir}
Should Be Equal As Integers ${list.rc} 0
... msg=project list should exit 0 but got ${list.rc}. stderr: ${list.stderr}
Should Contain ${list.stdout} local/first
... msg=project list should contain 'local/first' but got: ${list.stdout}
Should Contain ${list.stdout} local/second
... msg=project list should contain 'local/second' but got: ${list.stdout}
[Teardown] Remove Directory ${tmpdir} recursive=True