core tests: orphan PTY slave fd test fails on Macs where /dev/ttys001 exists

Open Beginner friendly
#30,384 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
cli, testing

Research direction

Read packages/core/src/services/shellExecutionService.test.ts, especially the “Orphan PTY slave FD cleanup” tests around line 1559, and inspect how closeOrphanSlaveFd uses filesystem mocks. Run npx vitest run src/services/shellExecutionService.test.ts -t "Orphan PTY slave FD cleanup" from packages/core. Done means the matching and nonmatching real path cases are mocked deliberately and the test passes independently of devices present on the machine.

Written by the indexing model from the issue text.

Description

status/need-triage
What happened?

ShellExecutionService > Orphan PTY slave FD cleanup > synchronously closes the matching slave fd when platform is darwin in packages/core/src/services/shellExecutionService.test.ts fails on a Mac that has a second terminal tab open:

AssertionError: expected undefined to be 12
 ❯ src/services/shellExecutionService.test.ts:1559:22
    const result = closeOrphanSlaveFd(10, '/dev/ttys001');
    expect(result).toBe(12);

The test mocks fs.statSync and fs.fstatSync, but not fs.realpathSync. closeOrphanSlaveFd calls the real fs.realpathSync('/dev/ttys001'):

  • On CI (Linux), or a Mac with only one terminal, /dev/ttys001 doesn't exist. The call throws, targetRealPath stays undefined, and the function matches on the mocked rdev alone, so the test passes.
  • On a Mac with more than one terminal open, /dev/ttys001 is a real device. targetRealPath gets set, and the function then compares it with the real realpathSync('/dev/fd/12'). fd 12 in the test process isn't that terminal, so the candidate is skipped and the function returns undefined.

So the result depends on which terminals happen to be open on the machine running the tests.

To reproduce, on macOS with at least two terminal windows or tabs open:

ls -l /dev/ttys001        # exists
cd packages/core
npx vitest run src/services/shellExecutionService.test.ts -t "Orphan PTY slave FD cleanup"
# × synchronously closes the matching slave fd when platform is darwin

Changing only the path in that test to one that doesn't exist (/dev/ttys999) makes it pass, which confirms it's the real realpathSync call.

What did you expect to happen?

The test should give the same result on every machine. Mocking realpathSync alongside statSync / fstatSync (or using a device name that can't exist) would make it deterministic. Mocking it also lets the test cover the path-verification branch on purpose instead of by accident: one case where the candidate's /dev/fd/N path matches, and one where it doesn't.

I have a small test-only fix ready and can open a PR if this is OK to be marked help wanted.

Client information

Running the unit tests from source, not the installed CLI, so there's no /about output.

  • main at d4cb1713f
  • macOS 27.3, arm64
  • Node.js 20.19.0 (the version CONTRIBUTING.md asks for). Same result on Node 24.5.0.
Login information

Not applicable; unit tests only.

Anything else we need to know?

The slave-FD cleanup and this test came in with #29340. The function itself looks fine; it's only the test that reaches the real filesystem.

Dominant language
TypeScript
Stars
109k
Forks
15k
Avg merge
1d 1h
Merged PRs (30d)
121

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google-gemini/gemini-cli

All issues in google-gemini/gemini-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.