fix: hide cmhub curl download window

This commit is contained in:
chengma
2026-07-08 17:49:54 +08:00
parent 6171b7cd92
commit e25d695ce7
3 changed files with 36 additions and 2 deletions
+15 -1
View File
@@ -725,12 +725,15 @@ class AITests(TempDirMixin, unittest.TestCase):
self.assertIn("--noproxy", args)
self.assertEqual("*", args[args.index("--noproxy") + 1])
self.assertFalse(kwargs["shell"])
self.assertEqual(0x08000000, kwargs["creationflags"])
output_path = args[args.index("--output") + 1]
with open(output_path, "wb") as fh:
fh.write(generated_png)
return SimpleNamespace(returncode=0, stdout=b"", stderr=b"")
with mock.patch("app.ai._find_system_curl", return_value=r"C:\Windows\System32\curl.exe"), \
with mock.patch("app.ai.os.name", "nt"), \
mock.patch("app.ai.subprocess.CREATE_NO_WINDOW", 0x08000000, create=True), \
mock.patch("app.ai._find_system_curl", return_value=r"C:\Windows\System32\curl.exe"), \
mock.patch("app.ai.subprocess.run", side_effect=fake_run), \
mock.patch("app.ai.socket.getaddrinfo", return_value=public_dns):
image_bytes = ai._download_cmhub_image(
@@ -744,6 +747,17 @@ class AITests(TempDirMixin, unittest.TestCase):
self.assertEqual(generated_png, image_bytes)
self.assertEqual(1, len(calls))
def test_cmhub_curl_hidden_window_kwargs_are_windows_only(self):
with mock.patch("app.ai.os.name", "nt"), \
mock.patch("app.ai.subprocess.CREATE_NO_WINDOW", 0x08000000, create=True):
self.assertEqual(
{"creationflags": 0x08000000},
ai._subprocess_hidden_window_kwargs(),
)
with mock.patch("app.ai.os.name", "posix"):
self.assertEqual({}, ai._subprocess_hidden_window_kwargs())
def test_cmhub_image_download_skips_curl_for_private_url(self):
with mock.patch("app.ai._find_system_curl", return_value=r"C:\Windows\System32\curl.exe"), \
mock.patch("app.ai.subprocess.run") as run: