|
| 1 | +open Base |
| 2 | +open Bot_components |
| 3 | +open Config |
| 4 | +open Config_resolver |
| 5 | +open Repo_config |
| 6 | +open Alcotest |
| 7 | +open Test_helpers |
| 8 | + |
| 9 | +(** Integration tests that verify end-to-end workflows and catch regressions. |
| 10 | + These tests verify that components work together correctly, not just in isolation. |
| 11 | + |
| 12 | + NOTE: These tests focus on UNIQUE integration scenarios not covered by unit tests. |
| 13 | + For config resolution, backport, multi-repo, cache, etc., see: |
| 14 | + - config_resolver_test.ml |
| 15 | + - refactored_code_backport_test.ml |
| 16 | + - repo_config_integration_test.ml |
| 17 | + - cache_test.ml |
| 18 | + - refactored_code_generic_test.ml |
| 19 | + *) |
| 20 | + |
| 21 | +(** Test 1: Minimizer URL Configuration Integration |
| 22 | + Verifies that minimizer_url from TOML, env var, or None works correctly end-to-end. |
| 23 | + This is a regression test for making minimizer_url generic. |
| 24 | + |
| 25 | + Tests all configuration scenarios: |
| 26 | + 1. TOML config only (explicit takes priority) |
| 27 | + 2. Environment variable only (used when TOML is None) |
| 28 | + 3. Both TOML and env var (TOML takes priority) |
| 29 | + 4. Neither configured (returns None) |
| 30 | + *) |
| 31 | +let test_minimizer_url_integration () = |
| 32 | + let bot_info = create_mock_bot_info () in |
| 33 | + (* Test case 1: TOML config only - explicit config takes priority *) |
| 34 | + let config_with_toml_minimizer = |
| 35 | + { github_owner= "test-org" |
| 36 | + ; github_repo= "test-repo" |
| 37 | + ; gitlab_domain= None |
| 38 | + ; gitlab_owner= None |
| 39 | + ; gitlab_repo= None |
| 40 | + ; github_installation_id= None |
| 41 | + ; github_project_number= None |
| 42 | + ; org_name= None |
| 43 | + ; team_name= None |
| 44 | + ; minimizer_url= Some "https://toml-minimizer.com" |
| 45 | + ; ci_config= None |
| 46 | + ; labels= None |
| 47 | + ; jobs= None |
| 48 | + ; documentation= None } |
| 49 | + in |
| 50 | + let resolved_toml = |
| 51 | + Lwt_main.run |
| 52 | + (resolve_repo_config ~bot_info ~explicit_config:config_with_toml_minimizer) |
| 53 | + in |
| 54 | + check (option string) "TOML minimizer_url preserved" |
| 55 | + resolved_toml.minimizer_url (Some "https://toml-minimizer.com") ; |
| 56 | + (* Test case 2: Environment variable only - used when TOML is None *) |
| 57 | + (* Save original env var value if it exists *) |
| 58 | + (* Sys.getenv in Base returns string option directly, no exception *) |
| 59 | + let original_env_var = Sys.getenv "BOT_MINIMIZER_URL" in |
| 60 | + (* Set env var for this test *) |
| 61 | + Unix.putenv "BOT_MINIMIZER_URL" "https://env-minimizer.com" ; |
| 62 | + let config_without_minimizer = |
| 63 | + { github_owner= "test-org" |
| 64 | + ; github_repo= "test-repo" |
| 65 | + ; gitlab_domain= None |
| 66 | + ; gitlab_owner= None |
| 67 | + ; gitlab_repo= None |
| 68 | + ; github_installation_id= None |
| 69 | + ; github_project_number= None |
| 70 | + ; org_name= None |
| 71 | + ; team_name= None |
| 72 | + ; minimizer_url= None |
| 73 | + ; ci_config= None |
| 74 | + ; labels= None |
| 75 | + ; jobs= None |
| 76 | + ; documentation= None } |
| 77 | + in |
| 78 | + let resolved_with_env = |
| 79 | + Lwt_main.run |
| 80 | + (resolve_repo_config ~bot_info ~explicit_config:config_without_minimizer) |
| 81 | + in |
| 82 | + (* Should use env var when TOML is None *) |
| 83 | + check (option string) "minimizer_url from env var when TOML is None" |
| 84 | + resolved_with_env.minimizer_url (Some "https://env-minimizer.com") ; |
| 85 | + (* Test case 2b: None when neither TOML nor env var is configured *) |
| 86 | + (* Clear env var by setting it to empty string (which gets treated as None) *) |
| 87 | + Unix.putenv "BOT_MINIMIZER_URL" "" ; |
| 88 | + let config_without_minimizer = |
| 89 | + { github_owner= "test-org" |
| 90 | + ; github_repo= "test-repo" |
| 91 | + ; gitlab_domain= None |
| 92 | + ; gitlab_owner= None |
| 93 | + ; gitlab_repo= None |
| 94 | + ; github_installation_id= None |
| 95 | + ; github_project_number= None |
| 96 | + ; org_name= None |
| 97 | + ; team_name= None |
| 98 | + ; minimizer_url= None |
| 99 | + ; ci_config= None |
| 100 | + ; labels= None |
| 101 | + ; jobs= None |
| 102 | + ; documentation= None } |
| 103 | + in |
| 104 | + let resolved_no_minimizer = |
| 105 | + Lwt_main.run |
| 106 | + (resolve_repo_config ~bot_info ~explicit_config:config_without_minimizer) |
| 107 | + in |
| 108 | + (* Should be None when neither configured (empty string is treated as None) *) |
| 109 | + check (option string) "minimizer_url is None when not configured" |
| 110 | + resolved_no_minimizer.minimizer_url None ; |
| 111 | + (* Test case 3: Both TOML and env var - TOML takes priority *) |
| 112 | + (* Set env var to verify TOML takes priority *) |
| 113 | + Unix.putenv "BOT_MINIMIZER_URL" "https://env-should-be-ignored.com" ; |
| 114 | + (* This verifies the priority: Explicit > Auto-detected > Defaults *) |
| 115 | + (* Since TOML is explicit config, it should override env var (which is in defaults) *) |
| 116 | + let config_with_both = |
| 117 | + { github_owner= "test-org" |
| 118 | + ; github_repo= "test-repo" |
| 119 | + ; gitlab_domain= None |
| 120 | + ; gitlab_owner= None |
| 121 | + ; gitlab_repo= None |
| 122 | + ; github_installation_id= None |
| 123 | + ; github_project_number= None |
| 124 | + ; org_name= None |
| 125 | + ; team_name= None |
| 126 | + ; minimizer_url= Some "https://toml-priority.com" |
| 127 | + ; ci_config= None |
| 128 | + ; labels= None |
| 129 | + ; jobs= None |
| 130 | + ; documentation= None } |
| 131 | + in |
| 132 | + (* Even if env var was set, TOML should win *) |
| 133 | + let resolved_both = |
| 134 | + Lwt_main.run |
| 135 | + (resolve_repo_config ~bot_info ~explicit_config:config_with_both) |
| 136 | + in |
| 137 | + check (option string) "TOML minimizer_url takes priority over env var" |
| 138 | + resolved_both.minimizer_url (Some "https://toml-priority.com") ; |
| 139 | + (* Restore original env var at the end of all tests *) |
| 140 | + match original_env_var with |
| 141 | + | Some value -> |
| 142 | + Unix.putenv "BOT_MINIMIZER_URL" value |
| 143 | + | None -> |
| 144 | + (* Clear env var by setting to empty string *) |
| 145 | + Unix.putenv "BOT_MINIMIZER_URL" "" |
| 146 | + |
| 147 | +(** Test 2: Feature Flag Integration |
| 148 | + Verifies that feature flags (backport, minimization, custom job status) work together *) |
| 149 | +let test_feature_flags_integration () = |
| 150 | + let toml_str = |
| 151 | + {| |
| 152 | +[repositories.full-featured] |
| 153 | +github = "org/repo" |
| 154 | +github_project_number = "10" |
| 155 | +minimizer_url = "https://minimizer.com" |
| 156 | + |
| 157 | +[repositories.full-featured.jobs] |
| 158 | +custom_job_status = true |
| 159 | +bench = "bench" |
| 160 | +|} |
| 161 | + in |
| 162 | + let toml_data = Utils.toml_of_string toml_str in |
| 163 | + let table = repo_config_table toml_data in |
| 164 | + let config = |
| 165 | + Option.value_exn (get_repo_config_opt ~owner:"org" ~repo:"repo" table) |
| 166 | + in |
| 167 | + (* Verify all feature flags are set *) |
| 168 | + check bool "backport enabled (project_number)" |
| 169 | + (Option.is_some config.github_project_number) |
| 170 | + true ; |
| 171 | + check bool "minimization enabled (minimizer_url)" |
| 172 | + (Option.is_some config.minimizer_url) |
| 173 | + true ; |
| 174 | + match config.jobs with |
| 175 | + | Some jobs -> |
| 176 | + (* Check that custom_job_status is explicitly enabled (Some true) *) |
| 177 | + check (option bool) "custom job status enabled" jobs.custom_job_status |
| 178 | + (Some true) ; |
| 179 | + check (option string) "bench job configured" jobs.bench (Some "bench") |
| 180 | + | None -> |
| 181 | + Alcotest.fail "Expected jobs config" |
| 182 | + |
| 183 | +let () = |
| 184 | + run "Integration" |
| 185 | + [ ( "minimizer_url" |
| 186 | + , [ test_case "minimizer_url configuration integration" `Quick |
| 187 | + test_minimizer_url_integration ] ) |
| 188 | + ; ( "feature_flags" |
| 189 | + , [ test_case "feature flags integration" `Quick |
| 190 | + test_feature_flags_integration ] ) ] |
0 commit comments