Skip to content

test: add unit tests for Gemini CLI adapter#1317

Open
jpleva91 wants to merge 1 commit intomainfrom
agent/copilot-test-writer-oss-20260329-053003
Open

test: add unit tests for Gemini CLI adapter#1317
jpleva91 wants to merge 1 commit intomainfrom
agent/copilot-test-writer-oss-20260329-053003

Conversation

@jpleva91
Copy link
Copy Markdown
Collaborator

What

Unit tests for packages/adapters/src/gemini-cli.ts — previously untested at the adapter level. CLI-level tests existed (cli-gemini-hook.test.ts) but didn't cover the core normalization and response-formatting logic.

Coverage

  • resolveGeminiAgentIdentity: no-session fallback, empty/whitespace, hash format and consistency, uniqueness across sessions
  • normalizeGeminiCliAction: all 7 tool mappings (WriteFile→Write, EditFile→Edit, ReadFile→Read, Shell→Bash, ListFiles→Glob, SearchCode→Grep, WebSearch→WebFetch), unknown tool passthrough, missing tool_input, source: gemini-cli metadata invariant
  • Session ID propagation: payload sessionId, GEMINI_SESSION_ID env var fallback, metadata threading across all tool types
  • geminiToActionContext: KE-2 adapter contract — file.write/file.read/git.push/shell.exec action classes, destructive flag, persona pass-through, full ActionContext shape
  • formatGeminiHookResponse: empty string for allow (Gemini-specific contract), deny JSON with decision field (not permissionDecision), guide mode with suggestion + retry exhaustion, educate mode
  • Integration: real kernel in dryRun mode — allow benign reads, deny destructive shell, policy-based git.push deny, hashed agent identity in decision record
  • geminiCliToEnvelope: KE-3 source tagging, policyVersion and decisionCodes propagation

Notes

  • Gemini uses tool_input as an object (not a JSON string like Copilot/Codex) — no parse step needed
  • Gemini's allow response is an empty string (not { decision: 'allow' }) per Gemini CLI contract
  • Bootstrap deadlock encountered: worktree had stale node_modules (no turbo), blocking Write hook. Resolved via pnpm install --force which bypasses the interactive reinstall prompt.

Created by copilot-test-writer-oss — AgentGuard Copilot swarm

Tests for packages/adapters/src/gemini-cli.ts — previously untested.

Covers:
- resolveGeminiAgentIdentity: no session, empty/whitespace, hash format, consistency
- normalizeGeminiCliAction: all 7 tool mappings (WriteFile, EditFile, ReadFile,
  Shell, ListFiles, SearchCode, WebSearch), unknown passthrough, missing tool_input
- Session ID propagation: payload, GEMINI_SESSION_ID env var, metadata
- geminiToActionContext: KE-2 mapping, file/git/shell actions, persona, shape
- formatGeminiHookResponse: allow (empty string), deny JSON, guide mode with
  suggestion and retry exhaustion, educate mode; Gemini-specific 'decision' field
- Integration: kernel allow/deny/policy flows with real kernel in dryRun mode
- geminiCliToEnvelope: KE-3 source tagging, policyVersion, decisionCodes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jpleva91 added a commit that referenced this pull request Mar 29, 2026
- Health: yellow — PR #1303 (sprint #955/#957) CONFLICTING after PR #1300 merged
- PR #1300 MERGED: complete Go kernel (145x faster, 2ms vs 290ms) — major milestone
- PR #1295 MERGED: bootstrap catch-22 fix (#995)
- PR #1296 MERGED: site-only PR CI skip fix (#1267)
- PR #969 MERGED: fix claude-init binary path (closes #964)
- PR #1303: sprint work CONFLICTING — senior must assess rebase vs close
- No P0/P1 issues open
- PR #1317 (Gemini tests, 4/4 CI green, copilot squad): ready for human review
- Dogfood #1323 filed: pnpm install --frozen-lockfile bootstrap hang in non-TTY

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant