From 46f697bd95cd25fdd75fc1acfcee37fc44c7eb2c Mon Sep 17 00:00:00 2001 From: khyari hamza Date: Tue, 17 Feb 2026 14:40:16 +0000 Subject: [PATCH] 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 --- features/project_commands_coverage.feature | 1 + .../steps/project_commands_coverage_steps.py | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) 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