Pass Node path to frontend services

This commit is contained in:
王鹏
2026-10-09 13:23:12 +08:00
parent e5e584eb73
commit c2d124cc09
3 changed files with 56 additions and 1 deletions

View File

@@ -326,6 +326,44 @@ class DeployerTests(unittest.TestCase):
self.assertEqual(exit_code, 7)
restart_backend.assert_called_once()
def test_frontend_early_exit_reports_log_tail(self):
logs = []
popen_options = {}
npm = Path.cwd() / "fake-node" / "npm.cmd"
class ExitedProcess:
pid = 22996
def poll(self):
return 1
def fake_popen(*args, **kwargs):
popen_options.update(kwargs)
kwargs["stdout"].write("ERROR Failed to compile.\nModule not found: missing-package\n")
kwargs["stdout"].flush()
return ExitedProcess()
with TemporaryDirectory() as temp:
root = Path(temp)
exit_code = deployer_module._restart_frontend(
[str(npm), "run", "serve"],
root,
logs.append,
port=8081,
service_name="管理端",
log_path=root / "frontend-admin.log",
replace_listeners=lambda port, on_output: True,
popen=fake_popen,
)
self.assertEqual(exit_code, 1)
self.assertTrue(any("管理端日志末尾" in line for line in logs))
self.assertTrue(any("Module not found: missing-package" in line for line in logs))
self.assertEqual(
Path(popen_options["env"]["PATH"].split(os.pathsep)[0]),
npm.parent,
)
def test_backend_restart_separates_each_run_in_backend_log(self):
restart_backend = getattr(deployer_module, "_restart_backend", lambda *args, **kwargs: 0)