Repository: servo/servo
File: python/servo/testing_commands.py (Python)

Code before:
        with open(logger, "w") as file:
            file.write(filedata)
        # copy
        delete(path.join(tdir, "webgpu"))
        shutil.copytree(path.join(clone_dir, "out-wpt"), path.join(tdir, "webgpu"))
        # update commit
        commit = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=clone_dir).decode()
        with open(path.join(tdir, "checkout_commit.txt"), "w") as file:
            file.write(commit)
        # clean up
        delete(clone_dir)
        print("Updating manifest.")
        return self.context.commands.dispatch("update-manifest", self.context)

    @Command(
        "smoketest", description="Load a simple page in Servo and ensure that it closes properly", category="testing"
    )
    @CommandArgument("params", nargs="...", help="Command-line arguments to be passed through to Servo")
    @CommandBase.common_command_arguments(binary_selection=True)
    def smoketest(self, servo_binary: str, params: list[str], **kwargs: Any) -> int | None:
        # We pass `-f` here so that any thread panic will cause Servo to exit,
        # preventing a panic from hanging execution. This means that these kind
        # of panics won't cause timeouts on CI.
        return PostBuildCommands(self.context)._run(
            servo_binary, params + ["-f", "tests/html/close-on-load.html", "-M"]
        )

    @Command("try", description="Runs try jobs by force pushing to try branch", category="testing")
    @CommandArgument("--remote", "-r", default="origin", help="A git remote to run the try job on")
    @CommandArgument(
        "try_strings", default=["full"], nargs="...", help="A list of try strings specifying what kind of job to run."
    )
    def try_command(self, remote: str, try_strings: list[str]) -> int:
        if subprocess.check_output(["git", "diff", "--cached", "--name-only"]).strip():
            print("Cannot run `try` with staged and uncommited changes. ")
            print("Please either commit or stash them before running `try`.")
            return 1

        remote_url = subprocess.check_output(["git", "config", "--get", f"remote.{remote}.url"]).decode().strip()
        if "github.com" not in remote_url:
            print(f"The remote provided ({remote_url}) isn't a GitHub remote.")
            return 1

        try_string = " ".join(try_strings)
        try:
            config = servo.try_parser.Config(try_string)
        except ValueError as err:
            print(f"Failed to parse `try` config because of {err}")
            return 1
        print(f"Trying on {remote} ({remote_url}) with following configuration:")
        print()

Review comment (suggestion):
I think we should not hardcode` -M` here and should instead pass it as argument into smoketest invocation.

Code after:
        with open(logger, "w") as file:
            file.write(filedata)
        # copy
        delete(path.join(tdir, "webgpu"))
        shutil.copytree(path.join(clone_dir, "out-wpt"), path.join(tdir, "webgpu"))
        # update commit
        commit = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=clone_dir).decode()
        with open(path.join(tdir, "checkout_commit.txt"), "w") as file:
            file.write(commit)
        # clean up
        delete(clone_dir)
        print("Updating manifest.")
        return self.context.commands.dispatch("update-manifest", self.context)

    @Command(
        "smoketest", description="Load a simple page in Servo and ensure that it closes properly", category="testing"
    )
    @CommandArgument("params", nargs="...", help="Command-line arguments to be passed through to Servo")
    @CommandArgument("--multiprocess", "-M", default=False, action="store_true", help="Run in multiprocess mode")
    @CommandBase.common_command_arguments(binary_selection=True)
    def smoketest(self, servo_binary: str, multiprocess: bool, params: list[str], **kwargs: Any) -> int | None:
        # We pass `-f` here so that any thread panic will cause Servo to exit,
        # preventing a panic from hanging execution. This means that these kind
        # of panics won't cause timeouts on CI.
        args = ["-f", "tests/html/close-on-load.html"]
        if multiprocess:
            args.append("-M")
        return PostBuildCommands(self.context)._run(servo_binary, params + args)

    @Command("try", description="Runs try jobs by force pushing to try branch", category="testing")
    @CommandArgument("--remote", "-r", default="origin", help="A git remote to run the try job on")
    @CommandArgument(
        "try_strings", default=["full"], nargs="...", help="A list of try strings specifying what kind of job to run."
    )
    def try_command(self, remote: str, try_strings: list[str]) -> int:
        if subprocess.check_output(["git", "diff", "--cached", "--name-only"]).strip():
            print("Cannot run `try` with staged and uncommited changes. ")
            print("Please either commit or stash them before running `try`.")
            return 1

        remote_url = subprocess.check_output(["git", "config", "--get", f"remote.{remote}.url"]).decode().strip()
        if "github.com" not in remote_url:
            print(f"The remote provided ({remote_url}) isn't a GitHub remote.")
            return 1

        try_string = " ".join(try_strings)
        try:
            config = servo.try_parser.Config(try_string)
        except ValueError as err:
            print(f"Failed to parse `try` config because of {err}")
            return 1