google-gemini / google-gemini/gemini-cli

bug(ci): SDK tests not run in PR CI; nightly broken by incorrect mock in session.test.ts

Open
#24,999 4 comments 0 reactions 0 assignees View on GitHub
🔒 maintainer only area/non-interactive effort/medium kind/bug priority/p2 status/bot-triaged type/bug
Dominant language
TypeScript
Stars
107k
Forks
14.6k
Avg merge
2d 3h
Merged PRs (30d)
45

Description

### What happened?

The nightly release workflow ([run #24165914961](https://github.com/google-gemini/gemini-cli/actions/runs/24165914961)) fails with 6 test failures in `packages/sdk/src/session.test.ts`. All 6 failures are in the `GeminiCliSession sendStream()` describe block with:

```
TypeError: Cannot read properties of undefined (reading 'sendMessageStream')
❯ GeminiCliSession.sendStream src/session.ts:206:29
```

**Root cause has two parts:**

**1. Incorrect mock in `session.test.ts` (PR #21897)**

The test file (added in #21897, commit `1023c5b7a`) mocks `Config` with `getGeminiClient()` as a method:

```ts
getGeminiClient: vi.fn().mockReturnValue(mockClient),
```

But `session.ts` accesses the client via the `AgentLoopContext` property getter (migrated in #22115):

```ts
const loopContext2: AgentLoopContext = this.config;
this.client = loopContext2.geminiClient; // property, not method
```

Since the mock has no `geminiClient` property, `this.client` remains `undefined`, crashing all `sendStream()` tests.

**2. `@google/gemini-cli-sdk` is missing from PR CI test matrix**

The CI workflow (`.github/workflows/ci.yml`) explicitly lists workspaces per shard:

- **`cli` shard:** `@google/gemini-cli`
- **`others` shard:** `@google/gemini-cli-core`, `@google/gemini-cli-a2a-server`, `gemini-cli-vscode-ide-companion`, `@google/gemini-cli-test-utils`

`@google/gemini-cli-sdk` is **not included in either shard**, so its tests never run during PR checks. The nightly release uses `npm run test:ci --workspaces --if-present` (all workspaces), which is why it caught the failure.

### What did you expect to happen?

1. The SDK test mock should correctly match the `AgentLoopContext` interface (using `geminiClient` property instead of `getGeminiClient()` method).
2. `@google/gemini-cli-sdk` should be included in the `others` shard of `ci.yml` so SDK tests are run during PR checks.

### Client information

Client Information

N/A — this is a CI infrastructure issue, not a runtime bug.

### Anything else we need to know?

**Failed tests (all in `packages/sdk/src/session.test.ts`):**
- `GeminiCliSession sendStream() > auto-initializes if not yet initialized`
- `GeminiCliSession sendStream() > completes cleanly when model returns no tool calls`
- `GeminiCliSession sendStream() > accepts an AbortSignal without throwing`
- `GeminiCliSession sendStream() > executes tool call loop and sends function response back to model`
- `GeminiCliSession sendStream() > calls setUserMemory and updateSystemInstruction when instructions is a function`
- `GeminiCliSession sendStream() > does not call setUserMemory when instructions is a string`

**Suggested fix:**
1. In `session.test.ts`, change the mock to use `geminiClient: mockClient` (property) and similarly fix `toolRegistry`, `messageBus` to match `AgentLoopContext`.
2. In `.github/workflows/ci.yml`, add `--workspace "@google/gemini-cli-sdk"` to the `others` shard (lines 181, 269, 436).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.