diff --git a/features/project_commands_coverage.feature b/features/project_commands_coverage.feature index ba03a419..c4e8c2bb 100644 --- a/features/project_commands_coverage.feature +++ b/features/project_commands_coverage.feature @@ -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" diff --git a/features/steps/project_commands_coverage_steps.py b/features/steps/project_commands_coverage_steps.py index cf4ce6da..7596ecae 100644 --- a/features/steps/project_commands_coverage_steps.py +++ b/features/steps/project_commands_coverage_steps.py @@ -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