
brizental pushed to branch tor-browser-140.2.0esr-15.0-1 at The Tor Project / Applications / Tor Browser Commits: 35347c26 by Beatriz Rizental at 2025-09-04T14:28:01+02:00 fixup! BB 43564: Modify ./mach bootstrap for Base Browser - - - - - f17c4e08 by Beatriz Rizental at 2025-09-04T14:28:30+02:00 fixup! BB 43564: Modify ./mach bootstrap for Tor Browser - - - - - c8b4882e by Beatriz Rizental at 2025-09-04T14:51:58+02:00 fixup! Add CI for Base Browser Run all of our python tests everytime. This is a quick workaround for tests to pass, before I address it properly in tor-browser#44149 - - - - - 5 changed files: - .gitlab/ci/jobs/test/python-test.yml - build/moz.configure/bootstrap.configure - python/mozbuild/mozbuild/tbbutils.py - python/mozbuild/mozbuild/test/python.toml - + python/mozbuild/mozbuild/test/test_tbbutils.py Changes: ===================================== .gitlab/ci/jobs/test/python-test.yml ===================================== @@ -17,7 +17,7 @@ python-test: - firefox script: - ./mach configure --with-base-browser-version=0.0.0 - - .gitlab/ci/jobs/helpers.py --get-changed-files | xargs -0 --no-run-if-empty ./mach python-test -v + - ./mach python-test --subsuite base-browser rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' || ($CI_COMMIT_BRANCH && $CI_COMMIT_REF_PROTECTED == 'true' && $CI_PIPELINE_SOURCE == 'push') changes: ===================================== build/moz.configure/bootstrap.configure ===================================== @@ -205,9 +205,7 @@ def bootstrap_path(path, **kwargs): if not target.tor_browser_build_alias: return False - artifact = mozbuild.tbbutils.get_artifact_name( - path_parts[0], target, tasks.prefix - ) + artifact = mozbuild.tbbutils.get_artifact_name(path_parts[0], tasks.prefix) if not artifact: log.info("%s is not mapped to a tbb artifact", path_parts[0]) return False ===================================== python/mozbuild/mozbuild/tbbutils.py ===================================== @@ -45,7 +45,7 @@ ARTIFACT_NAME_MAP = { } -def get_artifact_name(original_artifact_name, target, host): +def get_artifact_name(original_artifact_name, host): # These are not build artifacts, they are pre-built artifacts to be added to the final build, # therefore this check can come before the host check. if original_artifact_name in TOR_BROWSER_BUILD_ARTIFACTS: @@ -76,7 +76,7 @@ def get_artifact_path(url, artifact, target, prefix=""): def filter_files(files, keyword): return [file for file in files if keyword in file] - artifact_files = filter_files(files, artifact) + artifact_files = [file for file in files if file.startswith(artifact)] if len(artifact_files) == 1: return f"{url}/{path}/{artifact_files[0]}" @@ -84,8 +84,13 @@ def get_artifact_path(url, artifact, target, prefix=""): files_per_os = filter_files(artifact_files, target.tor_browser_build_alias) # If there are files in the folder, but they don't have the OS in the name - # it means we can get any of them because they can be used to build for any OS. - # So let's just get the first one. + # it probably means we can get any of them because they can be used to build + # for any OS. So let's just get the first one. + # + # Note: It could be the case that the artifact _is_ OS dependant, but there + # just are no files for the OS we are looking for. In that case, this will + # return an incorrect artifact. This should not happen often though and is + # something we cannot address until artifact names are standardized on tbb. if len(files_per_os) == 0: return f"{url}/{artifact}/{artifact_files[0]}" ===================================== python/mozbuild/mozbuild/test/python.toml ===================================== @@ -111,6 +111,9 @@ subsuite = "mozbuild" ["test_rewrite_mozbuild.py"] +["test_tbbutils.py"] +subsuite = "base-browser" + ["test_telemetry.py"] ["test_telemetry_settings.py"] ===================================== python/mozbuild/mozbuild/test/test_tbbutils.py ===================================== @@ -0,0 +1,151 @@ +import unittest +from types import SimpleNamespace +from unittest.mock import MagicMock, patch + +import mozunit + +from mozbuild.tbbutils import get_artifact_path, list_files_http + + +class TestGetArtifactName(unittest.TestCase): + def setUp(self): + self.artifact = "artifact" + self.host = "linux64" + + @patch("mozbuild.tbbutils.TOR_BROWSER_BUILD_ARTIFACTS", new=["artifact"]) + def test_artifact_in_tbb_artifacts(self): + from mozbuild.tbbutils import get_artifact_name + + result = get_artifact_name(self.artifact, self.host) + self.assertEqual(result, self.artifact) + + @patch("mozbuild.tbbutils.ARTIFACT_NAME_MAP", new={"artifact": "tcafitra"}) + def test_host_is_not_linux64(self): + from mozbuild.tbbutils import get_artifact_name + + result = get_artifact_name(self.artifact, "linux64-aarch64") + self.assertIsNone(result) + + @patch("mozbuild.tbbutils.ARTIFACT_NAME_MAP", new={"artifact": "tcafitra"}) + def test_mapped_artifact(self): + from mozbuild.tbbutils import get_artifact_name + + result = get_artifact_name(self.artifact, self.host) + self.assertEqual(result, self.artifact[::-1]) + + +class TestGetArtifactPath(unittest.TestCase): + def setUp(self): + self.url = "http://example.com" + self.artifact = "artifact" + # This is just an example target which is valid. But it doesn't make + # any difference and could be anything for these tests. + self.target = SimpleNamespace(tor_browser_build_alias="linux", cpu="x86_64") + + @patch("mozbuild.tbbutils.list_files_http") + def test_no_files_returns_none(self, mock_list_files): + mock_list_files.return_value = [] + result = get_artifact_path(self.url, self.artifact, self.target) + self.assertIsNone(result) + + @patch("mozbuild.tbbutils.list_files_http") + def test_single_artifact_match(self, mock_list_files): + mock_list_files.return_value = ["artifact-1.zip"] + result = get_artifact_path(self.url, self.artifact, self.target) + self.assertEqual(result, f"{self.url}/{self.artifact}/artifact-1.zip") + + @patch("mozbuild.tbbutils.list_files_http") + def test_artifact_without_os_returns_first(self, mock_list_files): + mock_list_files.return_value = ["artifact-1.zip", "artifact-2.zip"] + result = get_artifact_path(self.url, self.artifact, self.target) + self.assertTrue(result.startswith(f"{self.url}/{self.artifact}/")) + self.assertIn("artifact-", result) + + @patch("mozbuild.tbbutils.list_files_http") + def test_artifact_with_os_match(self, mock_list_files): + mock_list_files.return_value = [ + "artifact-windows.zip", + "artifact-linux.zip", + ] + result = get_artifact_path(self.url, self.artifact, self.target) + self.assertEqual(result, f"{self.url}/{self.artifact}/artifact-linux.zip") + + @patch("mozbuild.tbbutils.list_files_http") + def test_artifact_with_cpu_match(self, mock_list_files): + mock_list_files.return_value = [ + "artifact-linux-arm.zip", + "artifact-linux-x86_64.zip", + ] + result = get_artifact_path(self.url, self.artifact, self.target) + self.assertEqual( + result, f"{self.url}/{self.artifact}/artifact-linux-x86_64.zip" + ) + + @patch("mozbuild.tbbutils.list_files_http") + def test_artifact_with_prefix(self, mock_list_files): + mock_list_files.return_value = ["artifact-1.zip"] + + prefix = "prefix" + result = get_artifact_path(self.url, self.artifact, self.target, prefix=prefix) + self.assertEqual(result, f"{self.url}/{prefix}/artifact-1.zip") + mock_list_files.assert_called_with(f"{self.url}/{prefix}?C=M;O=D") + + +class TestListFilesHttp(unittest.TestCase): + def setUp(self): + self.url = "http://example.com" + + @patch("mozbuild.tbbutils.urlopen") + def test_non_200_status_returns_empty(self, mock_urlopen): + mock_resp = MagicMock() + mock_resp.status = 404 + mock_resp.read.return_value = b"" + mock_urlopen.return_value.__enter__.return_value = mock_resp + + result = list_files_http(self.url) + self.assertEqual(result, []) + + @patch("mozbuild.tbbutils.urlopen") + def test_exception_returns_empty(self, mock_urlopen): + mock_urlopen.side_effect = Exception("network error") + result = list_files_http(self.url) + self.assertEqual(result, []) + + @patch("mozbuild.tbbutils.urlopen") + def test_regular_links(self, mock_urlopen): + html = b""" + <html><body> + <a href="../">Parent</a> + <a href="file1.zip">file1</a> + <a href="file2.zip">file2</a> + </body></html> + """ + mock_resp = MagicMock() + mock_resp.status = 200 + mock_resp.read.return_value = html + mock_urlopen.return_value.__enter__.return_value = mock_resp + + result = list_files_http(self.url) + self.assertEqual(result, ["file1.zip", "file2.zip"]) + + @patch("mozbuild.tbbutils.urlopen") + def test_tor_expert_bundle_rewrites(self, mock_urlopen): + html = """ + <a href="tor-expert-bundle">bundle</a> + """ + mock_resp = MagicMock() + mock_resp.status = 200 + mock_resp.read.return_value = html.encode() + mock_urlopen.return_value.__enter__.return_value = mock_resp + + result = list_files_http(self.url) + self.assertEqual( + result, + [ + "tor-expert-bundle/tor-expert-bundle.tar.gz", + ], + ) + + +if __name__ == "__main__": + mozunit.main() View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/8a7c971... -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/8a7c971... You're receiving this email because of your account on gitlab.torproject.org.
participants (1)
-
brizental (@brizental)