diff --git a/catfish/project/__init__.py b/catfish/project/__init__.py index dee90a0..46ff790 100644 --- a/catfish/project/__init__.py +++ b/catfish/project/__init__.py @@ -53,6 +53,9 @@ class Project: except StopIteration: return None + def get_extra_path(self): + return [self.root.joinpath("node_modules/.bin"), self.root.joinpath("env/bin")] + @dataclass class Process: diff --git a/catfish/worker/server.py b/catfish/worker/server.py index 3a2b013..d0c3ef7 100644 --- a/catfish/worker/server.py +++ b/catfish/worker/server.py @@ -68,7 +68,14 @@ async def run_process_command(project: Project, process: Process): *command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - env={**os.environ, "PYTHONUNBUFFERED": "1"}, + env={ + **os.environ, + "PYTHONUNBUFFERED": "1", + "CATFISH_IDENT": process.ident, + "PATH": "{}:{}".format( + ":".join(map(str, project.get_extra_path())), os.environ["PATH"] + ), + }, cwd=project.root ) asyncio.ensure_future(publish_stdout_for(proc, process)) diff --git a/tests/test_worker/test_server.py b/tests/test_worker/test_server.py index ef10fb1..91fe445 100644 --- a/tests/test_worker/test_server.py +++ b/tests/test_worker/test_server.py @@ -1,3 +1,5 @@ +import psutil + from catfish.project import Project from catfish.utils.processes import is_process_running from catfish.worker import BASE_SOCKET_DIR @@ -6,20 +8,37 @@ from tests import BaseWorkerTestCase class WorkerServerTestCase(BaseWorkerTestCase): - def test_server_creates_process(self): - project = Project(self.EXAMPLE_DIR) - process = project.get_process("bg") - response = send_to_server( - PayloadType.PROCESS, - {"path": str(project.root), "process": str(process.name)}, - ) - self.assertTrue(is_process_running(response["pid"])) - def test_ping(self): response = send_to_server(PayloadType.PING, {}) self.assertEqual(response, {"ping": "pong"}) +class ProcessWorkerTestCase(BaseWorkerTestCase): + def setUp(self): + super().setUp() + self.project = Project(self.EXAMPLE_DIR) + self.process = self.project.get_process("bg") + + def test_server_creates_process(self): + response = send_to_server( + PayloadType.PROCESS, + {"path": str(self.project.root), "process": str(self.process.name)}, + ) + self.assertTrue(is_process_running(response["pid"])) + + def test_additional_environment(self): + response = send_to_server( + PayloadType.PROCESS, + {"path": str(self.project.root), "process": str(self.process.name)}, + ) + env = psutil.Process(response["pid"]).environ() + self.assertEqual(env["PYTHONUNBUFFERED"], "1") + self.assertEqual(env["CATFISH_IDENT"], self.process.ident) + path_dirs = env["PATH"].split(":") + for path in self.project.get_extra_path(): + self.assertIn(str(path), path_dirs) + + class ProcessLogsTestCase(BaseWorkerTestCase): def setUp(self): super().setUp()