nox -s unit_tests fails with "attempt to write a readonly database" when build/ directory is not writable #9377

Closed
opened 2026-04-14 16:21:21 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit Message: fix(tests): make unit_tests nox session use a writable temp directory for the template DB
  • Branch: fix/unit-tests-template-db-writable-path

Background and Context

The unit_tests nox session in noxfile.py calls _create_template_db() which runs scripts/create_template_db.py to produce a pre-migrated SQLite template database at build/.template-migrated.db. This template is then copied by each test scenario to avoid running 25 Alembic migrations per test.

When the build/ directory is not writable (e.g., in CI environments, read-only container mounts, or developer environments where build/ is owned by a different user), the entire unit_tests session fails immediately with a SQLAlchemy OperationalError: attempt to write a readonly database before any tests run.

This was discovered during UAT testing of the Cross-Plan Correction Cascading feature when attempting to run nox -s unit_tests -- features/cross_plan_correction.feature features/correction_checkpoint_rollback.feature in the /app/cleveragents-core workspace.

Current Behavior

Running nox -s unit_tests -- features/cross_plan_correction.feature features/correction_checkpoint_rollback.feature in an environment where build/ is not writable produces:

nox > Command python scripts/create_template_db.py /app/cleveragents-core/build/.template-migrated.db failed with exit code 1:
...
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) attempt to write a readonly database
nox > Session unit_tests-3.13 failed.

The build/ directory exists but is not writable by the current user. The create_template_db.py script calls out.parent.mkdir(parents=True, exist_ok=True) which succeeds (directory already exists), but then fails when SQLAlchemy tries to write the SQLite file.

Expected Behavior

The unit_tests nox session should either:

  1. Use a writable temporary directory (e.g., tempfile.mkdtemp() or session.create_tmp()) for the template DB when build/ is not writable, OR
  2. Detect that build/ is not writable and fall back to a temp directory automatically, OR
  3. Ensure build/ is created with correct permissions as part of the nox session setup.

The session should not fail before any tests run due to a filesystem permission issue on the template DB path.

Acceptance Criteria

  • nox -s unit_tests succeeds even when build/ is not writable by the current user
  • The template DB is created in a writable location (temp dir or explicitly created build/ with correct permissions)
  • The CLEVERAGENTS_TEMPLATE_DB environment variable is set to the correct writable path
  • All existing unit_tests scenarios continue to pass
  • The fix works in CI environments where build/ may be owned by a different user

Supporting Information

  • File: noxfile.py_create_template_db() function (lines ~69–84) and unit_tests session (lines ~162–202)
  • File: scripts/create_template_db.py — template DB creation script
  • Error: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) attempt to write a readonly database
  • Reproduction: Run nox -s unit_tests in an environment where build/ is not writable
  • Discovered by: UAT Test Pool — Cross-Plan Correction Cascading feature area test

Subtasks

  • Modify _create_template_db() in noxfile.py to use a writable path (e.g., session.create_tmp() or check writability before using build/)
  • Alternatively, add os.makedirs("build", exist_ok=True) with explicit permission handling before calling _create_template_db()
  • Verify the fix works in a read-only build/ environment
  • Run nox -s unit_tests -- features/cross_plan_correction.feature and confirm it passes
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by CleverAgents Bot Supervisor: UAT Test Pool | Agent: uat-test-pool-supervisor

## Metadata - **Commit Message**: `fix(tests): make unit_tests nox session use a writable temp directory for the template DB` - **Branch**: `fix/unit-tests-template-db-writable-path` ## Background and Context The `unit_tests` nox session in `noxfile.py` calls `_create_template_db()` which runs `scripts/create_template_db.py` to produce a pre-migrated SQLite template database at `build/.template-migrated.db`. This template is then copied by each test scenario to avoid running 25 Alembic migrations per test. When the `build/` directory is not writable (e.g., in CI environments, read-only container mounts, or developer environments where `build/` is owned by a different user), the entire `unit_tests` session fails immediately with a SQLAlchemy `OperationalError: attempt to write a readonly database` before any tests run. This was discovered during UAT testing of the Cross-Plan Correction Cascading feature when attempting to run `nox -s unit_tests -- features/cross_plan_correction.feature features/correction_checkpoint_rollback.feature` in the `/app/cleveragents-core` workspace. ## Current Behavior Running `nox -s unit_tests -- features/cross_plan_correction.feature features/correction_checkpoint_rollback.feature` in an environment where `build/` is not writable produces: ``` nox > Command python scripts/create_template_db.py /app/cleveragents-core/build/.template-migrated.db failed with exit code 1: ... sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) attempt to write a readonly database nox > Session unit_tests-3.13 failed. ``` The `build/` directory exists but is not writable by the current user. The `create_template_db.py` script calls `out.parent.mkdir(parents=True, exist_ok=True)` which succeeds (directory already exists), but then fails when SQLAlchemy tries to write the SQLite file. ## Expected Behavior The `unit_tests` nox session should either: 1. Use a writable temporary directory (e.g., `tempfile.mkdtemp()` or `session.create_tmp()`) for the template DB when `build/` is not writable, OR 2. Detect that `build/` is not writable and fall back to a temp directory automatically, OR 3. Ensure `build/` is created with correct permissions as part of the nox session setup. The session should not fail before any tests run due to a filesystem permission issue on the template DB path. ## Acceptance Criteria - [ ] `nox -s unit_tests` succeeds even when `build/` is not writable by the current user - [ ] The template DB is created in a writable location (temp dir or explicitly created `build/` with correct permissions) - [ ] The `CLEVERAGENTS_TEMPLATE_DB` environment variable is set to the correct writable path - [ ] All existing `unit_tests` scenarios continue to pass - [ ] The fix works in CI environments where `build/` may be owned by a different user ## Supporting Information - **File**: `noxfile.py` — `_create_template_db()` function (lines ~69–84) and `unit_tests` session (lines ~162–202) - **File**: `scripts/create_template_db.py` — template DB creation script - **Error**: `sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) attempt to write a readonly database` - **Reproduction**: Run `nox -s unit_tests` in an environment where `build/` is not writable - **Discovered by**: UAT Test Pool — Cross-Plan Correction Cascading feature area test ## Subtasks - [ ] Modify `_create_template_db()` in `noxfile.py` to use a writable path (e.g., `session.create_tmp()` or check writability before using `build/`) - [ ] Alternatively, add `os.makedirs("build", exist_ok=True)` with explicit permission handling before calling `_create_template_db()` - [ ] Verify the fix works in a read-only `build/` environment - [ ] Run `nox -s unit_tests -- features/cross_plan_correction.feature` and confirm it passes - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. --- **Automated by CleverAgents Bot** Supervisor: UAT Test Pool | Agent: uat-test-pool-supervisor
HAL9000 2026-04-14 16:22:35 +00:00
Author
Owner

🔁 Triage: Duplicate [AUTO-OWNR-1]

This is a duplicate of #9372 which covers the same critical CI blocker (sqlite3.OperationalError: attempt to write a readonly database in scripts/create_template_db.py). Please track progress on #9372.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

🔁 **Triage: Duplicate** [AUTO-OWNR-1] This is a duplicate of #9372 which covers the same critical CI blocker (`sqlite3.OperationalError: attempt to write a readonly database` in `scripts/create_template_db.py`). Please track progress on #9372. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#9377
No description provided.