perf(ci): transfer artifacts locally instead of through FRP
Gitea CI / Check code and tests (pull_request) Successful in 6m9s
Gitea CI / Build Android APK (pull_request) Successful in 3m35s
Gitea CI / Build Windows x64 app (pull_request) Successful in 7m45s
Gitea CI / Audit and package Windows x64 (pull_request) Failing after 1m41s
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 2s

This commit is contained in:
lingjhf committed 2026-10-06 14:49:31 +08:00
1 parent e06590dc82
commit 8e523f0e89
6 files changed
+83 -2

No files matched your search

+45
View File
@@ -9,6 +9,51 @@ import release_transport as transfers
class TransferToolsTests(unittest.TestCase):
def setUp(self):
environment = patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': ''})
environment.start()
self.addCleanup(environment.stop)
def test_local_api_transport_preserves_authenticated_request_and_public_identity(self):
class Response(io.BytesIO):
headers = {'Content-Type': 'application/json'}
with patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': 'http://127.0.0.1:3000/',
'GITEA_TOKEN': 'test-token'}), \
patch.object(transfers.urllib.request, 'urlopen', return_value=Response(b'{"id":3}')) as open_url:
result = transfers.request(transfers.SERVER + '/api/v1/releases?name=a%20b',
data=b'package', method='POST', content_type='application/octet-stream')
request = open_url.call_args.args[0]
self.assertEqual(result, {'id': 3})
self.assertEqual(request.full_url, 'http://127.0.0.1:3000/api/v1/releases?name=a%20b')
self.assertEqual(request.get_method(), 'POST')
self.assertEqual(request.get_header('Authorization'), 'token test-token')
self.assertEqual(request.data, b'package')
self.assertEqual(transfers.SERVER, 'https://git.orangraph.com')
def test_local_verification_routes_validated_attachment_without_changing_its_public_url(self):
asset = {'browser_download_url': 'https://git.orangraph.com/attachments/example'}
with patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': 'http://127.0.0.1:3000',
'GITEA_TOKEN': 'test-token'}), \
patch.object(transfers.urllib.request, 'urlopen', return_value=io.BytesIO(b'app')) as open_url:
result = transfers.fingerprint(asset)
self.assertEqual(open_url.call_args.args[0].full_url, 'http://127.0.0.1:3000/attachments/example')
self.assertEqual(result['sha256'], hashlib.sha256(b'app').hexdigest())
self.assertEqual(asset['browser_download_url'], 'https://git.orangraph.com/attachments/example')
def test_local_transport_rejects_unexpected_endpoint_or_origin_before_sending_credentials(self):
for internal, url, message in [
('http://example.com:3000', transfers.SERVER + '/api/v1/releases', 'internal Gitea endpoint'),
('http://127.0.0.1:3000', 'https://example.com/file', 'transport origin'),
('http://127.0.0.1:3000', 'http://git.orangraph.com/file', 'transport origin'),
]:
with self.subTest(internal=internal, url=url), \
patch.dict('os.environ', {'CUTDEX_GITEA_INTERNAL_URL': internal, 'GITEA_TOKEN': 'test-token'}), \
patch.object(transfers.urllib.request, 'urlopen') as open_url:
with self.assertRaisesRegex(ValueError, message):
transfers.request(url)
open_url.assert_not_called()
def test_frp_tunnel_not_found_page_is_retried_as_a_temporary_failure(self):
calls = 0