2121of both invocations is the same, the test passes (with us being alerted to this situtation via a special pipeline that
2222does not block PRs). If not, it fails, preventing PRs from introducing new vulnerable dependencies.
2323"""
24- import os
2524import statistics
2625from pathlib import Path
2726from tempfile import TemporaryDirectory
3130
3231from framework import utils
3332from framework .defs import FC_WORKSPACE_DIR
34- from framework .microvm import Microvm
33+ from framework .properties import global_props
3534from framework .utils import CommandReturn
3635from framework .with_filelock import with_filelock
37- from host_tools .cargo_build import DEFAULT_TARGET_DIR , get_firecracker_binaries
36+ from host_tools .cargo_build import DEFAULT_TARGET_DIR
3837
3938# Locally, this will always compare against main, even if we try to merge into, say, a feature branch.
4039# We might want to do a more sophisticated way to determine a "parent" branch here.
41- DEFAULT_A_REVISION = os . environ . get ( "BUILDKITE_PULL_REQUEST_BASE_BRANCH" ) or "main"
40+ DEFAULT_A_REVISION = global_props . buildkite_revision_a or "main"
4241
4342
4443T = TypeVar ("T" )
@@ -120,11 +119,6 @@ def binary_ab_test(
120119 return result_a , result_b , comparator (result_a , result_b )
121120
122121
123- def is_pr () -> bool :
124- """Returns `True` iff we are executing in the context of a build kite run on a pull request"""
125- return os .environ .get ("BUILDKITE_PULL_REQUEST" , "false" ) != "false"
126-
127-
128122def git_ab_test_host_command_if_pr (
129123 command : str ,
130124 * ,
@@ -134,7 +128,7 @@ def git_ab_test_host_command_if_pr(
134128 """Runs the given bash command as an A/B-Test if we're in a pull request context (asserting that its stdout and
135129 stderr did not change across the PR). Otherwise runs the command, asserting it returns a zero exit code
136130 """
137- if is_pr () :
131+ if global_props . buildkite_pr :
138132 git_ab_test_host_command (command , comparator = comparator )
139133 return None
140134
@@ -176,56 +170,6 @@ def set_did_not_grow_comparator(
176170 )
177171
178172
179- def precompiled_ab_test_guest_command (
180- microvm_factory : Callable [[Path , Path ], Microvm ],
181- command : str ,
182- * ,
183- comparator : Callable [[CommandReturn , CommandReturn ], bool ] = default_comparator ,
184- a_revision : str = DEFAULT_A_REVISION ,
185- b_revision : Optional [str ] = None ,
186- ):
187- """The same as git_ab_test_command, but via SSH. The closure argument should setup a microvm using the passed
188- paths to firecracker and jailer binaries."""
189- b_directory = (
190- DEFAULT_B_DIRECTORY
191- if b_revision is None
192- else FC_WORKSPACE_DIR / "build" / b_revision
193- )
194-
195- def test_runner (bin_dir , _is_a : bool ):
196- microvm = microvm_factory (bin_dir / "firecracker" , bin_dir / "jailer" )
197- return microvm .ssh .run (command )
198-
199- (_ , old_out , old_err ), (_ , new_out , new_err ), the_same = binary_ab_test (
200- test_runner ,
201- comparator ,
202- a_directory = FC_WORKSPACE_DIR / "build" / a_revision ,
203- b_directory = b_directory ,
204- )
205-
206- assert (
207- the_same
208- ), f"The output of running command `{ command } ` changed:\n Old:\n stdout:\n { old_out } \n stderr\n { old_err } \n \n New:\n stdout:\n { new_out } \n stderr:\n { new_err } "
209-
210-
211- def precompiled_ab_test_guest_command_if_pr (
212- microvm_factory : Callable [[Path , Path ], Microvm ],
213- command : str ,
214- * ,
215- comparator = default_comparator ,
216- check_in_nonpr = True ,
217- ):
218- """The same as git_ab_test_command_if_pr, but via SSH"""
219- if is_pr ():
220- precompiled_ab_test_guest_command (
221- microvm_factory , command , comparator = comparator
222- )
223- return None
224-
225- microvm = microvm_factory (* get_firecracker_binaries ())
226- return microvm .ssh .run (command , check = check_in_nonpr )
227-
228-
229173def check_regression (
230174 a_samples : List [float ], b_samples : List [float ], * , n_resamples : int = 9999
231175):
0 commit comments