Files
cleveragents-core/robot/cli_init_fresh_environment.robot
T
CoreRasurae 0c5b140d29
CI / push-validation (pull_request) Successful in 18s
CI / lint (pull_request) Successful in 26s
CI / helm (pull_request) Successful in 38s
CI / build (pull_request) Successful in 48s
CI / quality (pull_request) Successful in 54s
CI / security (pull_request) Successful in 55s
CI / typecheck (pull_request) Successful in 57s
CI / e2e_tests (pull_request) Successful in 4m48s
CI / unit_tests (pull_request) Successful in 8m5s
CI / integration_tests (pull_request) Successful in 9m23s
CI / docker (pull_request) Successful in 1m23s
CI / coverage (pull_request) Successful in 12m29s
CI / benchmark-regression (push) Failing after 0s
CI / benchmark-publish (push) Failing after 0s
CI / status-check (pull_request) Successful in 1s
CI / push-validation (push) Successful in 12s
CI / helm (push) Successful in 29s
CI / build (push) Successful in 3m23s
CI / lint (push) Successful in 3m38s
CI / quality (push) Successful in 3m40s
CI / security (push) Successful in 4m3s
CI / typecheck (push) Successful in 4m5s
CI / e2e_tests (push) Successful in 6m42s
CI / unit_tests (push) Successful in 10m7s
CI / integration_tests (push) Successful in 10m13s
CI / docker (push) Successful in 1m46s
CI / coverage (push) Successful in 10m58s
CI / status-check (push) Successful in 2s
fix(database): include alembic files in package distribution
Move alembic configuration and migration files from repository root into the
Python package structure to ensure they are included in the wheel distribution.

This fix resolves the FileNotFoundError when running `agents init` in Docker
containers or any environment using the built wheel distribution.

Changes:
- Move alembic/ directory from repo root to
  src/cleveragents/infrastructure/database/migrations/
- Move alembic.ini to the same new location and update script_location setting
- Update MigrationRunner._find_alembic_ini() to search from the new canonical
  location within the package
- Update create_template_db.py to point to the new alembic.ini location
- Update documentation references to reflect new migration file locations
- Create __init__.py for migrations package

- The env.py file is imported when running tests that verify all modules can be
  imported without errors. However, context.config is only available when alembic
  is actually running migrations, not during normal module imports. This caused
  an AttributeError when the test tried to import the migrations.env module.

- Fix by using getattr() with a default value to safely access context.config,
  and guard all code that uses config with None checks. This allows the module
  to be safely imported while still functioning correctly during migrations.

Testing:
- Verified MigrationRunner can locate alembic.ini in new location
- Tested agents init succeeds in creating project with database
- Template database creation works correctly
- All migration tests should pass without changes

Alembic files now follow standard Python packaging conventions, making them
automatically included in wheel distributions without special configuration.

ISSUES CLOSED: #4180
2026-04-17 17:40:00 +00:00

79 lines
4.5 KiB
Plaintext

*** Settings ***
Documentation Integration test for agents init in fresh environment (issue #4180).
... Verifies that agents init properly initializes the database and
... creates all required directories in a clean, containerized context.
Resource ${CURDIR}/common.resource
Library Process
Library OperatingSystem
Library String
Suite Setup Setup Test Environment
Suite Teardown Cleanup Test Environment
*** Test Cases ***
Init In Fresh Environment Exits Successfully
[Documentation] agents init should complete with exit code 0 in a fresh environment
[Tags] issue_4180 fresh_environment
${tmpdir}= Evaluate __import__('tempfile').mkdtemp(prefix='init_fresh_')
${result}= Run Process ${PYTHON} -m cleveragents init --yes
... timeout=120s on_timeout=kill cwd=${tmpdir}
Should Be Equal As Integers ${result.rc} 0
... msg=Expected exit code 0 in fresh environment, got ${result.rc}. stderr: ${result.stderr}
[Teardown] Remove Directory ${tmpdir} recursive=True
Init In Fresh Environment Initializes Database
[Documentation] agents init should properly initialize the database in fresh environment
[Tags] issue_4180 fresh_environment
${tmpdir}= Evaluate __import__('tempfile').mkdtemp(prefix='init_fresh_db_')
${result}= Run Process ${PYTHON} -m cleveragents init --yes
... timeout=120s on_timeout=kill cwd=${tmpdir}
Should Be Equal As Integers ${result.rc} 0
... msg=Init should succeed in fresh environment
Should Contain ${result.stdout} Database:
... msg=Output should indicate database was initialized
[Teardown] Remove Directory ${tmpdir} recursive=True
Init In Fresh Environment Creates Required Directories
[Documentation] agents init should create all required directories for packaged/containerized context
[Tags] issue_4180 fresh_environment
${tmpdir}= Evaluate __import__('tempfile').mkdtemp(prefix='init_fresh_dirs_')
${result}= Run Process ${PYTHON} -m cleveragents init --yes
... timeout=120s on_timeout=kill cwd=${tmpdir}
Should Be Equal As Integers ${result.rc} 0
Should Contain ${result.stdout} Directories:
... msg=Output should indicate directories were created
# Verify required directories exist
${config_dir}= Evaluate __import__('os').path.join('${tmpdir}', '.cleveragents')
Directory Should Exist ${config_dir}
... msg=.cleveragents config directory should exist
[Teardown] Remove Directory ${tmpdir} recursive=True
Init In Fresh Environment Reports All Init Output Fields
[Documentation] agents init should produce all spec-required output fields for fresh environment
[Tags] issue_4180 fresh_environment
${tmpdir}= Evaluate __import__('tempfile').mkdtemp(prefix='init_fresh_out_')
${result}= Run Process ${PYTHON} -m cleveragents init --yes
... timeout=120s on_timeout=kill cwd=${tmpdir}
Should Be Equal As Integers ${result.rc} 0
# All spec-required output fields must be present
Should Contain ${result.stdout} Data Dir:
... msg=Output should contain Data Dir field per spec
Should Contain ${result.stdout} Config:
... msg=Output should contain Config field per spec
Should Contain ${result.stdout} Database:
... msg=Output should contain Database field per spec
Should Contain ${result.stdout} Directories:
... msg=Output should contain Directories field per spec
[Teardown] Remove Directory ${tmpdir} recursive=True
Init Handles Packaged Alembic Files Correctly
[Documentation] agents init should find and use alembic files from packaged location in fresh environment
[Tags] issue_4180 fresh_environment alembic_packaging
${tmpdir}= Evaluate __import__('tempfile').mkdtemp(prefix='init_fresh_alembic_')
${result}= Run Process ${PYTHON} -m cleveragents init --yes
... timeout=120s on_timeout=kill cwd=${tmpdir}
Should Be Equal As Integers ${result.rc} 0
... msg=Init should succeed with packaged alembic files. stderr: ${result.stderr}
Should Contain ${result.stdout} Database:
... msg=Database should be initialized from packaged alembic files
[Teardown] Remove Directory ${tmpdir} recursive=True