mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-26 15:40:18 +00:00
fix: CLI commands ignore runtime DATABASE_BACKEND when both features compiled (#740)
* fix: CLI commands ignore runtime DATABASE_BACKEND when both features compiled
`tool auth` and `mcp` CLI subcommands used compile-time `#[cfg]` gates
to select the database backend for secrets storage. When the binary is
compiled with both `postgres` and `libsql` features, the `#[cfg(feature
= "postgres")]` block always wins regardless of the runtime
`DATABASE_BACKEND` setting. This causes `tool auth` and `mcp auth` to
fail with a connection error for users running the libsql backend.
Switch both functions to `match config.database.backend { ... }` with
inner `#[cfg]` guards on each arm, matching the pattern already used in
`main.rs` and `app.rs`.
Also adds a top-level `auth` section to the Telegram channel
capabilities file so `ironclaw tool auth telegram` works for channels
(previously only tools had this section).
Co-Authored-By: Claude Opus 4.6 <[email protected]>
* fix: extract create_secrets_store factory into src/db, bump telegram version
- Move duplicated DB backend selection logic from cli/tool.rs and
cli/mcp.rs into a shared db::create_secrets_store() factory, following
the existing db::connect_from_config() pattern.
- Bump telegram channel version 0.2.0 → 0.2.1 to fix CI Version Bump Check.
- Add regression test for create_secrets_store with libsql backend.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
* fix: address review feedback — wizard.rs pattern, formatting, version bump
- Convert setup/wizard.rs secrets store creation from tri-branch #[cfg]
to runtime match on selected_backend (same pattern as CLI fix).
- Fix formatting (assert! line wrapping caught by CI).
- Bump telegram version to 0.2.2 (main already has 0.2.1).
- Merge latest main.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
* chore: fix regression test doc comment formatting
Co-Authored-By: Claude Opus 4.6 <[email protected]>
[skip-regression-check]
* fix: address Copilot review — wizard default backend, error chain preservation
- Fix wizard.rs: default selected_backend to "libsql" in libsql-only
builds so create_libsql_secrets_store is not skipped.
- Preserve error chain: replace .map_err(|e| anyhow!("{}", e)) with ?
in cli/tool.rs and cli/mcp.rs since DatabaseError implements
std::error::Error.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
---------
Co-authored-by: Tiny Tim <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: firat.sertgoz <[email protected]>
This commit is contained in:
co-authored by
Tiny Tim
Claude Opus 4.6
firat.sertgoz
parent
652f30a826
commit
d8dcc34319
+26
-24
@@ -1612,48 +1612,50 @@ impl SetupWizard {
|
||||
};
|
||||
|
||||
// Create backend-appropriate secrets store.
|
||||
// Respect the user's selected backend when both features are compiled,
|
||||
// so we don't accidentally use a postgres pool from DATABASE_URL when
|
||||
// libsql was chosen (or vice versa).
|
||||
// Use runtime dispatch based on the user's selected backend.
|
||||
// Default to whichever backend is compiled in. When only libsql is
|
||||
// available, we must not default to "postgres" or we'd skip store creation.
|
||||
let default_backend = {
|
||||
#[cfg(feature = "postgres")]
|
||||
{
|
||||
"postgres"
|
||||
}
|
||||
#[cfg(not(feature = "postgres"))]
|
||||
{
|
||||
"libsql"
|
||||
}
|
||||
};
|
||||
let selected_backend = self
|
||||
.settings
|
||||
.database_backend
|
||||
.as_deref()
|
||||
.unwrap_or("postgres");
|
||||
.unwrap_or(default_backend);
|
||||
|
||||
#[cfg(all(feature = "libsql", feature = "postgres"))]
|
||||
{
|
||||
if selected_backend == "libsql" {
|
||||
match selected_backend {
|
||||
#[cfg(feature = "libsql")]
|
||||
"libsql" | "turso" | "sqlite" => {
|
||||
if let Some(store) = self.create_libsql_secrets_store(&crypto)? {
|
||||
return Ok(SecretsContext::from_store(store, "default"));
|
||||
}
|
||||
// Fallback to postgres if libsql store creation returned None
|
||||
#[cfg(feature = "postgres")]
|
||||
if let Some(store) = self.create_postgres_secrets_store(&crypto).await? {
|
||||
return Ok(SecretsContext::from_store(store, "default"));
|
||||
}
|
||||
} else {
|
||||
}
|
||||
#[cfg(feature = "postgres")]
|
||||
_ => {
|
||||
if let Some(store) = self.create_postgres_secrets_store(&crypto).await? {
|
||||
return Ok(SecretsContext::from_store(store, "default"));
|
||||
}
|
||||
// Fallback to libsql if postgres store creation returned None
|
||||
#[cfg(feature = "libsql")]
|
||||
if let Some(store) = self.create_libsql_secrets_store(&crypto)? {
|
||||
return Ok(SecretsContext::from_store(store, "default"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "postgres", not(feature = "libsql")))]
|
||||
{
|
||||
let _ = selected_backend;
|
||||
if let Some(store) = self.create_postgres_secrets_store(&crypto).await? {
|
||||
return Ok(SecretsContext::from_store(store, "default"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "libsql", not(feature = "postgres")))]
|
||||
{
|
||||
let _ = selected_backend;
|
||||
if let Some(store) = self.create_libsql_secrets_store(&crypto)? {
|
||||
return Ok(SecretsContext::from_store(store, "default"));
|
||||
}
|
||||
#[cfg(not(feature = "postgres"))]
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Err(SetupError::Config(
|
||||
|
||||
Reference in New Issue
Block a user