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

Aperta Adatta ai principianti
#30,384 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
cli, testing

Direzione di ricerca

Leggi packages/core/src/services/shellExecutionService.test.ts, in particolare i test “Orphan PTY slave FD cleanup” intorno alla riga 1559, e verifica come closeOrphanSlaveFd usa i mock del file system. Esegui npx vitest run src/services/shellExecutionService.test.ts -t "Orphan PTY slave FD cleanup" da packages/core. Il lavoro è completato quando i casi con percorsi reali corrispondenti e non corrispondenti sono mockati intenzionalmente e il test passa indipendentemente dai dispositivi presenti sulla macchina.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
109k
Fork
15k
Merge medio
1g 1h
PR unite (30g)
121

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google-gemini/gemini-cli

Tutte le issue di google-gemini/gemini-cli

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.