forked from cleveragents/cleveragents-core
fix(test): add temp directory and DB bootstrap to project list scenario
The 'Test project list command with no projects' scenario was missing a Given step to set up a writable working directory. Without it, the container fell back to CWD/.cleveragents/db.sqlite which could not be opened (directory did not exist), causing sqlite3.OperationalError. - Add 'Given I have a temporary working directory' to the scenario - Bootstrap the SQLite schema in the When step so the ns_projects table exists for the empty-list query
This commit is contained in:
@@ -97,6 +97,7 @@ Feature: Project Commands Coverage
|
||||
|
||||
@phase1
|
||||
Scenario: Test project list command with no projects
|
||||
Given I have a temporary working directory
|
||||
When I run project list command
|
||||
Then the project list output should contain "No projects found"
|
||||
|
||||
|
||||
@@ -274,7 +274,33 @@ def step_execute_project_status_error(context):
|
||||
|
||||
@when("I run project list command")
|
||||
def step_run_project_list(context):
|
||||
"""Run project list command."""
|
||||
"""Run project list command.
|
||||
|
||||
Ensures the default database path is writable by creating the
|
||||
``.cleveragents`` directory and bootstrapping the schema so the
|
||||
``list`` sub-command can query the ``ns_projects`` table even
|
||||
when no projects exist.
|
||||
"""
|
||||
import os
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
from cleveragents.infrastructure.database.models import Base
|
||||
|
||||
# Ensure the fallback database directory exists inside the temp CWD
|
||||
db_dir = Path.cwd() / ".cleveragents"
|
||||
db_dir.mkdir(parents=True, exist_ok=True)
|
||||
db_path = db_dir / "db.sqlite"
|
||||
|
||||
# Point the container at this database so it doesn't fail on open
|
||||
db_url = f"sqlite:///{db_path.absolute()}"
|
||||
os.environ["CLEVERAGENTS_DATABASE_URL"] = db_url
|
||||
|
||||
# Bootstrap the schema so the table exists for the query
|
||||
engine = create_engine(db_url, echo=False)
|
||||
Base.metadata.create_all(engine)
|
||||
engine.dispose()
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(project.app, ["list"])
|
||||
context.result = result
|
||||
|
||||
Reference in New Issue
Block a user