def classify_test_select()

in scripts/commit_classifier.py [0:0]


    def classify_test_select(self, commits, runnable_jobs_path):
        testfailure_probs = self.testfailure_model.classify(
            commits[-1], probabilities=True
        )

        logger.info("Test failure risk: %f", testfailure_probs[0][1])

        if not runnable_jobs_path:
            runnable_jobs = {}
        elif runnable_jobs_path.startswith("http"):
            r = requests.get(runnable_jobs_path)
            r.raise_for_status()
            runnable_jobs = r.json()
        else:
            with open(runnable_jobs_path, "r") as f:
                runnable_jobs = json.load(f)

        # XXX: Remove tasks which are not in runnable jobs right away, so we avoid classifying them.
        # XXX: Consider using mozilla-central built-in rules to filter some of the tasks out, e.g. SCHEDULES.

        selected_tasks = list(
            self.model.select_tests(
                commits, float(get_secret("TEST_SELECTION_CONFIDENCE_THRESHOLD"))
            ).keys()
        )

        # XXX: For now, only restrict to linux64 test tasks (as for runnable jobs above, we could remove these right away).
        selected_tasks = [
            t for t in selected_tasks if t.startswith("test-linux1804-64/")
        ]

        with open("failure_risk", "w") as f:
            f.write(
                "1"
                if testfailure_probs[0][1]
                > float(get_secret("TEST_FAILURE_CONFIDENCE_THRESHOLD"))
                else "0"
            )

        # This should be kept in sync with the test scheduling history retriever script.
        cleaned_selected_tasks = []
        if len(runnable_jobs) > 0:
            for selected_task in selected_tasks:
                if (
                    selected_task.startswith("test-linux64")
                    and selected_task not in runnable_jobs
                ):
                    selected_task = selected_task.replace(
                        "test-linux64-", "test-linux1804-64-"
                    )

                if (
                    selected_task.startswith("test-linux1804-64-")
                    and selected_task not in runnable_jobs
                ):
                    selected_task = selected_task.replace(
                        "test-linux1804-64-", "test-linux64-"
                    )

                if selected_task in runnable_jobs:
                    cleaned_selected_tasks.append(selected_task)

        # It isn't worth running the build associated to the tests, if we only run three test tasks.
        if len(cleaned_selected_tasks) < 3:
            cleaned_selected_tasks = []

        with open("selected_tasks", "w") as f:
            f.writelines(
                f"{selected_task}\n" for selected_task in cleaned_selected_tasks
            )