(binary: str, cwd: str, timeout_s: float)
| 111 | |
| 112 | |
| 113 | def profile_single_spawn(binary: str, cwd: str, timeout_s: float) -> dict: |
| 114 | root = Path(tempfile.mkdtemp(prefix="jcode-single-profile-")) |
| 115 | home = root / "home" |
| 116 | runtime_dir = root / "run" |
| 117 | socket_path = runtime_dir / "jcode.sock" |
| 118 | debug_socket_path = runtime_dir / "jcode-debug.sock" |
| 119 | home.mkdir(parents=True, exist_ok=True) |
| 120 | runtime_dir.mkdir(parents=True, exist_ok=True) |
| 121 | env = os.environ.copy() |
| 122 | env.update( |
| 123 | { |
| 124 | "JCODE_HOME": str(home), |
| 125 | "JCODE_RUNTIME_DIR": str(runtime_dir), |
| 126 | "JCODE_SOCKET": str(socket_path), |
| 127 | "JCODE_DEBUG_SOCKET": str(debug_socket_path), |
| 128 | "JCODE_SWARM_ENABLED": "0", |
| 129 | "JCODE_NO_TELEMETRY": "1", |
| 130 | "JCODE_TRACE": "1", |
| 131 | "JCODE_TEMP_SERVER": "1", |
| 132 | "JCODE_SERVER_OWNER_PID": str(os.getpid()), |
| 133 | } |
| 134 | ) |
| 135 | |
| 136 | server_proc = subprocess.Popen( |
| 137 | [binary, "--no-update", "--no-selfdev", "serve", "--socket", str(socket_path)], |
| 138 | env=env, |
| 139 | stdout=subprocess.DEVNULL, |
| 140 | stderr=subprocess.DEVNULL, |
| 141 | preexec_fn=os.setsid, |
| 142 | ) |
| 143 | try: |
| 144 | wait_for_socket(socket_path, timeout_s=min(timeout_s, 10.0)) |
| 145 | wait_for_socket(debug_socket_path, timeout_s=min(timeout_s, 10.0)) |
| 146 | session_id = create_session(debug_socket_path, cwd) |
| 147 | |
| 148 | master_fd, slave_fd = pty.openpty() |
| 149 | client_start = time.perf_counter() |
| 150 | client_proc = subprocess.Popen( |
| 151 | [ |
| 152 | binary, |
| 153 | "--no-update", |
| 154 | "--no-selfdev", |
| 155 | "--socket", |
| 156 | str(socket_path), |
| 157 | "--fresh-spawn", |
| 158 | "--resume", |
| 159 | session_id, |
| 160 | ], |
| 161 | stdin=slave_fd, |
| 162 | stdout=slave_fd, |
| 163 | stderr=slave_fd, |
| 164 | env=env, |
| 165 | preexec_fn=os.setsid, |
| 166 | ) |
| 167 | os.close(slave_fd) |
| 168 | os.set_blocking(master_fd, False) |
| 169 | |
| 170 | buffer = b"" |
no test coverage detected