Skip to content

Commit fe5cdce

Browse files
gagdiezGuillermo Alejandro Gallardo Diezclaude
authored
fix: owner_id was stored as string when recovered from settings on restart (#2561)
* fix: owner_id was stored as string when recovered from settings on restart Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test: add regression test for owner_id type on restart Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: use existing function --------- Co-authored-by: Guillermo Alejandro Gallardo Diez <gagdiez@iR2.local> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2474f65 commit fe5cdce

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

src/channels/wasm/setup.rs

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -262,28 +262,11 @@ async fn register_channel(
262262

263263
// Inject runtime config (tunnel URL, webhook secret, owner_id).
264264
{
265-
let mut config_updates = std::collections::HashMap::new();
266-
267-
if let Some(ref tunnel_url) = config.tunnel.public_url {
268-
config_updates.insert(
269-
"tunnel_url".to_string(),
270-
serde_json::Value::String(tunnel_url.clone()),
271-
);
272-
}
273-
274-
if let Some(ref secret) = webhook_secret {
275-
config_updates.insert(
276-
"webhook_secret".to_string(),
277-
serde_json::Value::String(secret.clone()),
278-
);
279-
}
280-
281-
if let Some(ref resolved_owner_id) = owner_actor_id {
282-
config_updates.insert(
283-
"owner_id".to_string(),
284-
serde_json::Value::String(resolved_owner_id.clone()),
285-
);
286-
}
265+
let mut config_updates = crate::pairing::approval::build_runtime_config_updates(
266+
config.tunnel.public_url.as_deref(),
267+
webhook_secret.as_deref(),
268+
owner_actor_id.as_deref(),
269+
);
287270

288271
if channel_name == TELEGRAM_CHANNEL_NAME
289272
&& let Some(store) = settings_store
@@ -888,7 +871,37 @@ mod tests {
888871
let owner_id = runtime_config
889872
.get("owner_id")
890873
.expect("owner_id should be in config");
891-
assert_eq!(owner_id, &serde_json::json!("12345"));
874+
assert_eq!(owner_id, &serde_json::json!(12345));
875+
}
876+
877+
#[tokio::test]
878+
async fn register_channel_injects_settings_owner_id_as_number() {
879+
let (mut config, _temp_dir) = test_config();
880+
config
881+
.channels
882+
.wasm_channel_owner_ids
883+
.insert("telegram".to_string(), 176326495);
884+
let loaded = test_loaded_channel("telegram", serde_json::json!({ "owner_id": null }));
885+
let wasm_router = Arc::new(WasmChannelRouter::new());
886+
let pairing_store = Arc::new(PairingStore::new_noop());
887+
888+
let (_name, _channel) =
889+
super::register_channel(loaded, &config, &None, None, &pairing_store, &wasm_router)
890+
.await;
891+
892+
let registered = wasm_router
893+
.get_channel_for_path("/webhook/telegram")
894+
.await
895+
.expect("telegram channel should be registered");
896+
let runtime_config = registered.get_config().await;
897+
let owner_id = runtime_config
898+
.get("owner_id")
899+
.expect("owner_id should be in config");
900+
assert_eq!(
901+
owner_id,
902+
&serde_json::json!(176326495),
903+
"owner_id recovered from settings must be a JSON number, not a string"
904+
);
892905
}
893906

894907
#[tokio::test]

0 commit comments

Comments
 (0)