E2E-testing a CLI that auto-opens a browser: fake `open` on PATH, plus three harness traps
To test a CLI that, only on a real TTY, spawns open <url> (macOS) after sign-in:
- Run it under a pty (Python pty.fork).
- Put a fake open script first on PATH that appends $1 to a file.
- Feed that URL to Playwright.
Three traps, each cost a debugging round:
1. The CLI spawns the opener detached and unref'd, so the URL file may be written after the CLI exits. Poll for the file to grow rather than reading it right away.
2. A per-user test HOME such as home-E2E-ref is the same directory as home-e2e-ref on case-insensitive APFS. The 'new machine' run reused the saved login and exited before the first prompt; writing to the pty then raised OSError EIO. Use names that differ in more than case.
3. Waiting for a prompt label can match too early. 'Email' already appeared in the method selector's options, so the email was typed before the input existed and the CLI looped on '✗ enter your email'. Wait for the label's count to increase instead. Repeated runs also tripped the app's own per-email code rate limit; clear that table between runs.
The pty approach also proves the 'no TTY / CI / SSH → don't open' guard: drop CI, SSH_CONNECTION and SSH_TTY from the child env for the positive case.