( args: readonly string[], dataDir: string, approveEmail: string, )
| 168 | // Run `executor login` as a subprocess, approving the device for `approveEmail` |
| 169 | // the moment the verification URL is printed (raw stdout, no PTY). |
| 170 | const runCliLogin = ( |
| 171 | args: readonly string[], |
| 172 | dataDir: string, |
| 173 | approveEmail: string, |
| 174 | ): Promise<{ code: number | null; stdout: string }> => |
| 175 | new Promise((res, rej) => { |
| 176 | const env = { ...process.env, EXECUTOR_DATA_DIR: dataDir }; |
| 177 | for (const k of ["EXECUTOR_API_KEY", "EXECUTOR_AUTH_TOKEN", "EXECUTOR_AUTH_PASSWORD"]) { |
| 178 | delete (env as Record<string, string | undefined>)[k]; |
| 179 | } |
| 180 | const child = spawn("bun", ["run", CLI_ENTRY, ...args], { cwd: REPO_ROOT, env }); |
| 181 | let stdout = ""; |
| 182 | let approved = false; |
| 183 | child.stdout.on("data", (chunk: Buffer) => { |
| 184 | stdout += chunk.toString(); |
| 185 | if (approved) return; |
| 186 | const match = stdout.match(/(https?:\/\/\S*user_code=\S+)/); |
| 187 | if (!match) return; |
| 188 | approved = true; |
| 189 | const url = new URL(match[1]); |
| 190 | url.searchParams.set("login_hint", approveEmail); |
| 191 | void fetch(url, { redirect: "manual" }); |
| 192 | }); |
| 193 | child.stderr.on("data", () => {}); |
| 194 | child.on("error", rej); |
| 195 | child.on("close", (code) => res({ code, stdout })); |
| 196 | }); |
| 197 | |
| 198 | scenario( |
| 199 | "CLI · two accounts on the same host get separate profiles", |
no test coverage detected