From ffa1337512a61ad2d49af07944496814c1733bfc Mon Sep 17 00:00:00 2001 From: hugocasa Date: Mon, 31 Aug 2026 13:23:41 +0200 Subject: [PATCH] test: keep the webhook doc comment with the test it describes --- backend/tests/instance_config.rs | 100 +++++++++++++++---------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/backend/tests/instance_config.rs b/backend/tests/instance_config.rs index 36f0c9b1c6..8e5c0f31f5 100644 --- a/backend/tests/instance_config.rs +++ b/backend/tests/instance_config.rs @@ -1436,6 +1436,56 @@ async fn test_no_alert_in_config_table_after_migration(db: Pool) { /// validating `github_app_webhook_base_url` itself. A rejected value must not be /// half-applied: nothing at all may be written, or an unreachable receiver would be /// persisted and only surface much later as a repository falling back to polling. +#[sqlx::test(fixtures("base"))] +async fn declarative_sync_rejects_an_unusable_webhook_base_url(db: Pool) { + clear_settings_and_configs(&db).await; + let before = count_global_settings(&db).await; + + let mut desired = BTreeMap::new(); + desired.insert("base_url".to_string(), serde_json::json!("https://wm.example.com")); + desired.insert( + "github_app_webhook_base_url".to_string(), + serde_json::json!("httpss://hooks.example.com"), + ); + + let err = windmill_common::instance_config::sync_global_settings_declarative( + &db, + &BTreeMap::new(), + &desired, + ) + .await + .expect_err("an invalid webhook base url must fail the sync"); + assert!( + err.to_string().contains("github_app_webhook_base_url"), + "the error should name the offending setting, got: {err}" + ); + + // A non-string shape must be rejected too, not silently treated as "absent" and + // then persisted by the diff. + let mut wrong_type = BTreeMap::new(); + wrong_type.insert( + "github_app_webhook_base_url".to_string(), + serde_json::json!(true), + ); + windmill_common::instance_config::sync_global_settings_declarative( + &db, + &BTreeMap::new(), + &wrong_type, + ) + .await + .expect_err("a non-string webhook base url must fail the sync"); + + assert_eq!( + count_global_settings(&db).await, + before, + "validation must run before anything is applied" + ); + assert!( + get_global_setting(&db, "base_url").await.is_none(), + "the other settings in the same apply must not have been written either" + ); +} + #[sqlx::test(fixtures("base"))] async fn declarative_sync_rejects_an_unusable_default_allowed_origins(db: Pool) { // The declarative writers (the sync-config CLI, the operator's ConfigMap @@ -1489,53 +1539,3 @@ async fn declarative_sync_rejects_an_unusable_default_allowed_origins(db: Pool

) { - clear_settings_and_configs(&db).await; - let before = count_global_settings(&db).await; - - let mut desired = BTreeMap::new(); - desired.insert("base_url".to_string(), serde_json::json!("https://wm.example.com")); - desired.insert( - "github_app_webhook_base_url".to_string(), - serde_json::json!("httpss://hooks.example.com"), - ); - - let err = windmill_common::instance_config::sync_global_settings_declarative( - &db, - &BTreeMap::new(), - &desired, - ) - .await - .expect_err("an invalid webhook base url must fail the sync"); - assert!( - err.to_string().contains("github_app_webhook_base_url"), - "the error should name the offending setting, got: {err}" - ); - - // A non-string shape must be rejected too, not silently treated as "absent" and - // then persisted by the diff. - let mut wrong_type = BTreeMap::new(); - wrong_type.insert( - "github_app_webhook_base_url".to_string(), - serde_json::json!(true), - ); - windmill_common::instance_config::sync_global_settings_declarative( - &db, - &BTreeMap::new(), - &wrong_type, - ) - .await - .expect_err("a non-string webhook base url must fail the sync"); - - assert_eq!( - count_global_settings(&db).await, - before, - "validation must run before anything is applied" - ); - assert!( - get_global_setting(&db, "base_url").await.is_none(), - "the other settings in the same apply must not have been written either" - ); -}