summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/commands/setupGithubCommand.test.ts
diff options
context:
space:
mode:
authorJeromeJu <[email protected]>2025-07-31 18:14:22 -0400
committerGitHub <[email protected]>2025-07-31 22:14:22 +0000
commit574015edd91a651b0a4770e595be7ff10d67e5ab (patch)
tree8283bdc1e4f37ae3b034234752b7b51ca62f20f5 /packages/cli/src/ui/commands/setupGithubCommand.test.ts
parentf9a05401c1d2d93d1251d3ebf2c079ee1f4ba8df (diff)
feat: Implement /setup-github command (#5069)
Diffstat (limited to 'packages/cli/src/ui/commands/setupGithubCommand.test.ts')
-rw-r--r--packages/cli/src/ui/commands/setupGithubCommand.test.ts66
1 files changed, 66 insertions, 0 deletions
diff --git a/packages/cli/src/ui/commands/setupGithubCommand.test.ts b/packages/cli/src/ui/commands/setupGithubCommand.test.ts
new file mode 100644
index 00000000..fe68be0c
--- /dev/null
+++ b/packages/cli/src/ui/commands/setupGithubCommand.test.ts
@@ -0,0 +1,66 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { vi, describe, expect, it, afterEach, beforeEach } from 'vitest';
+import * as child_process from 'child_process';
+import { setupGithubCommand } from './setupGithubCommand.js';
+import { CommandContext, ToolActionReturn } from './types.js';
+
+vi.mock('child_process');
+
+describe('setupGithubCommand', () => {
+ beforeEach(() => {
+ vi.resetAllMocks();
+ });
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ it('returns a tool action to download github workflows and handles paths', () => {
+ const fakeRepoRoot = '/github.com/fake/repo/root';
+ vi.mocked(child_process.execSync).mockReturnValue(fakeRepoRoot);
+
+ const result = setupGithubCommand.action?.(
+ {} as CommandContext,
+ '',
+ ) as ToolActionReturn;
+
+ expect(result.type).toBe('tool');
+ expect(result.toolName).toBe('run_shell_command');
+ expect(child_process.execSync).toHaveBeenCalledWith(
+ 'git rev-parse --show-toplevel',
+ {
+ encoding: 'utf-8',
+ },
+ );
+ expect(child_process.execSync).toHaveBeenCalledWith('git remote -v', {
+ encoding: 'utf-8',
+ });
+
+ const { command } = result.toolArgs;
+
+ const expectedSubstrings = [
+ `mkdir -p "${fakeRepoRoot}/.github/workflows"`,
+ `curl -fsSL -o "${fakeRepoRoot}/.github/workflows/gemini-cli.yml"`,
+ `curl -fsSL -o "${fakeRepoRoot}/.github/workflows/gemini-issue-automated-triage.yml"`,
+ `curl -fsSL -o "${fakeRepoRoot}/.github/workflows/gemini-issue-scheduled-triage.yml"`,
+ `curl -fsSL -o "${fakeRepoRoot}/.github/workflows/gemini-pr-review.yml"`,
+ 'https://raw.githubusercontent.com/google-github-actions/run-gemini-cli/refs/heads/main/workflows/',
+ ];
+
+ for (const substring of expectedSubstrings) {
+ expect(command).toContain(substring);
+ }
+ });
+
+ it('throws an error if git root cannot be determined', () => {
+ vi.mocked(child_process.execSync).mockReturnValue('');
+ expect(() => {
+ setupGithubCommand.action?.({} as CommandContext, '');
+ }).toThrow('Unable to determine the Git root directory.');
+ });
+});