fix(setup): run migrations during onboard when DATABASE_URL preset (#846) - #2309
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
ilblackdragon
left a comment
There was a problem hiding this comment.
Blocking feedback, posted as a comment because GitHub does not allow requesting changes on your own PR.
The fix itself is directionally right, but the regression coverage does not test the branch that changed.
The bug was in the PostgreSQL early-return path in auto_setup_database() when DATABASE_URL was already set. The added test only exercises the libSQL branch, so it would not catch a future regression in the Postgres wiring. That violates the repo rule to test through the real caller rather than only proving a similar helper/path.
I want a caller-level regression test that drives auto_setup_database() with DATABASE_URL preset and proves the wizard ends up with a live DB handle and successful persistence on the PostgreSQL path.
…abase path Addresses PR #2309 review feedback: prior test only covered the libSQL branch while the original bug was in the PostgreSQL early-return path. Drives auto_setup_database() with a preset DATABASE_URL against a real pgvector-enabled Postgres container (testcontainers), asserts the wizard ends up with a live db_pool, proves migrations ran by invoking persist_settings(), and does a round-trip read-back via Store::get_setting to confirm actual persistence — not just an in-memory Ok. Skips gracefully when Docker is unavailable, matching the workspace_integration pattern. Gated behind the integration feature. [skip-regression-check] Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Addressed in ebe8a80: added caller-level integration test driving |
…eSQL config (#846) When DATABASE_URL was already set before running `ironclaw onboard`, auto_setup_database() skipped both connection testing and migrations, leaving self.db_pool as None. This caused save_and_summarize() to fail with "Failed to save settings to database" because persist_settings() had no DB handle to write to. Now both postgres early-return paths call test_database_connection_postgres() and run_migrations_postgres() before returning, matching the existing libsql behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…abase path Addresses PR #2309 review feedback: prior test only covered the libSQL branch while the original bug was in the PostgreSQL early-return path. Drives auto_setup_database() with a preset DATABASE_URL against a real pgvector-enabled Postgres container (testcontainers), asserts the wizard ends up with a live db_pool, proves migrations ran by invoking persist_settings(), and does a round-trip read-back via Store::get_setting to confirm actual persistence — not just an in-memory Ok. Skips gracefully when Docker is unavailable, matching the workspace_integration pattern. Gated behind the integration feature. [skip-regression-check] Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ebe8a80 to
e70f5de
Compare
When DATABASE_URL is preset and the user accepts "Use this database?" in the interactive wizard, route through finish_postgres_auto_setup so connection-test + migrations both run instead of returning Ok(()) without running migrations. Same bug shape as PR nearai#2309 / issue nearai#846 fixed in auto_setup_database; the interactive existing-URL branch was the remaining sibling site. Host: ironclaw-dev Model: claude-opus-4-7 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…earai#846) (nearai#2309) * fix(setup): run migrations in auto_setup_database for existing PostgreSQL config (nearai#846) When DATABASE_URL was already set before running `ironclaw onboard`, auto_setup_database() skipped both connection testing and migrations, leaving self.db_pool as None. This caused save_and_summarize() to fail with "Failed to save settings to database" because persist_settings() had no DB handle to write to. Now both postgres early-return paths call test_database_connection_postgres() and run_migrations_postgres() before returning, matching the existing libsql behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test(setup): caller-level regression test for Postgres auto_setup_database path Addresses PR nearai#2309 review feedback: prior test only covered the libSQL branch while the original bug was in the PostgreSQL early-return path. Drives auto_setup_database() with a preset DATABASE_URL against a real pgvector-enabled Postgres container (testcontainers), asserts the wizard ends up with a live db_pool, proves migrations ran by invoking persist_settings(), and does a round-trip read-back via Store::get_setting to confirm actual persistence — not just an in-memory Ok. Skips gracefully when Docker is unavailable, matching the workspace_integration pattern. Gated behind the integration feature. [skip-regression-check] Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(setup): case-insensitive backend comparison + migration coupling assert Addresses PR nearai#2309 review: DATABASE_BACKEND comparison is now case-insensitive, debug_assert guards the db_pool coupling between connection test and migration, and a new test covers the DATABASE_BACKEND=postgres early-return path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * refactor(setup): typed DatabaseBackend parsing, extract finish_postgres_auto_setup Address review feedback on nearai#846: - Parse DATABASE_BACKEND via DatabaseBackend::FromStr instead of stringly comparing "postgres"/"postgresql". Aligns with .claude/rules/types.md and gains the "pg" alias for free. - Extract the duplicated body of both postgres early-return branches (connection test + debug_assert + migration + settings record) into a shared finish_postgres_auto_setup helper so the two call sites cannot drift. - Move the "Using existing PostgreSQL configuration" banner to after the connection test succeeds, so a failing connection no longer prints a misleading success-toned message first. - Factor postgres-container setup and round-trip assertions out of the two integration tests into start_pg_container and assert_auto_setup_postgres_persisted helpers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(setup): make run_migrations_postgres error on missing pool Address PR nearai#2309 review comments from serrrfirat and Copilot: - run_migrations_postgres() previously returned Ok(()) silently when db_pool was None. That made the correctness of the onboarding path depend on a side-effect-only ordering contract with test_database_connection_postgres(), flagged as fragile in the review. Convert the silent no-op into an explicit SetupError so a future regression cannot re-introduce the original nearai#846 failure mode in release builds (debug_assert only fires in debug). - Drop the now-redundant debug_assert in finish_postgres_auto_setup — the runtime check in the callee supersedes it. - Replace the misleading tests/workspace_integration.rs reference in start_pg_container's docstring (that file uses env-PG skip, not testcontainers) with a self-contained description. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Fixes #846. The
auto_setup_database()PostgreSQL early-return paths skippedtest_database_connection_postgres()andrun_migrations_postgres()whenDATABASE_URLwas already set, leavingself.db_pool = Noneand causing "Failed to save settings to database" at the final onboard step.test_auto_setup_database_runs_migrations_with_existing_envregression test (libsql variant)Test plan
cargo fmt,cargo clippy --all-featureszero warningscargo test --lib -- setup bootstrap(125 tests pass)ironclaw onboard, verify it completes🤖 Generated with Claude Code