Skip to content

bug(cli): gemini.test.tsx fails with FatalUntrustedWorkspaceError when running in non-TTY/headless environments #29634

Description

@supunyasanthaofficial

What happened?

In packages/cli/src/gemini.test.tsx, the test 'should NOT load project hooks when workspace is not trusted' fails with
FatalUntrustedWorkspaceError whenever tests run in a non-TTY or automated environment (e.g. piped test runners, CI, background processes, or Windows
terminal environments where process.stdin.isTTY is undefined):

FAIL src/gemini.test.tsx > project hooks loading based on trust > should NOT load project hooks when workspace is not trusted
FatalUntrustedWorkspaceError: Gemini CLI is not running in a trusted directory. To proceed, either use --skip-trust, set the
GEMINI_CLI_TRUST_WORKSPACE=true environment variable, or trust this directory in interactive mode. For more details, see https://geminicli.
com/docs/cli/trusted-folders/#headless-and-automated-environments
❯ Object.check src/utils/userStartupWarnings.ts:98:13
❯ getUserStartupWarnings src/utils/userStartupWarnings.ts:122:20
❯ Module.main src/gemini.tsx:890:17
❯ src/gemini.test.tsx:1596:5

Root cause:
The test configures an untrusted workspace (isTrusted: false) expecting main() to load without project hooks. However, getUserStartupWarnings()
calls isHeadlessMode(). In non-TTY environments, isHeadlessMode() returns true, which immediately throws FatalUntrustedWorkspaceError and aborts
main() before reaching loadCliConfig.

Because packages/cli/src/gemini.test.tsx mocks @google/gemini-cli-core without mocking isHeadlessMode, it falls back to the unmocked
implementation and evaluates process.stdin.isTTY.

What did you expect to happen?

The unit test should mock isHeadlessMode: vi.fn(() => false) inside vi.mock('@google/gemini-cli-core') in gemini.test.tsx.
This ensures that the test simulates the interactive CLI startup path as intended and passes deterministically across all environments regardless of
TTY status.

Client information

Client Information

Run gemini to enter the interactive CLI, then run the /about command.

> /about
# paste output here

Login information

No response

Anything else we need to know?

I have a verified, 1-line fix ready: adding isHeadlessMode: vi.fn(() => false) to vi.mock('@google/gemini-cli-core') in packages/cli/src/gemini. test.tsx. All 44 tests in gemini.test.tsx pass cleanly with 0 typecheck and 0 lint errors.

Could a maintainer please add the help wanted label so I can self-assign (/assign) and open a pull request?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/platformIssues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmtstatus/need-triageIssues that need to be triaged by the triage automation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions