summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/commands/setupGithubCommand.test.ts
diff options
context:
space:
mode:
authorSeth Vargo <[email protected]>2025-08-06 16:56:06 -0400
committerGitHub <[email protected]>2025-08-06 20:56:06 +0000
commit5cd63a6abc0531ec5e6781b2fa065cd22a64eede (patch)
tree3cf02f469f8604fb6e00cd3dc272ab1a6f410e8f /packages/cli/src/ui/commands/setupGithubCommand.test.ts
parentb55467c1dd3515b35607a2abfbdefaa79bf6a48f (diff)
feat(cli): get the run-gemini-cli version from the GitHub API (#5708)
Diffstat (limited to 'packages/cli/src/ui/commands/setupGithubCommand.test.ts')
-rw-r--r--packages/cli/src/ui/commands/setupGithubCommand.test.ts59
1 files changed, 27 insertions, 32 deletions
diff --git a/packages/cli/src/ui/commands/setupGithubCommand.test.ts b/packages/cli/src/ui/commands/setupGithubCommand.test.ts
index ae6378c7..6417c60a 100644
--- a/packages/cli/src/ui/commands/setupGithubCommand.test.ts
+++ b/packages/cli/src/ui/commands/setupGithubCommand.test.ts
@@ -5,13 +5,22 @@
*/
import { vi, describe, expect, it, afterEach, beforeEach } from 'vitest';
-import * as child_process from 'child_process';
+import * as gitUtils from '../../utils/gitUtils.js';
import { setupGithubCommand } from './setupGithubCommand.js';
import { CommandContext, ToolActionReturn } from './types.js';
vi.mock('child_process');
-describe('setupGithubCommand', () => {
+// Mock fetch globally
+global.fetch = vi.fn();
+
+vi.mock('../../utils/gitUtils.js', () => ({
+ isGitHubRepository: vi.fn(),
+ getGitRepoRoot: vi.fn(),
+ getLatestGitHubRelease: vi.fn(),
+}));
+
+describe('setupGithubCommand', async () => {
beforeEach(() => {
vi.resetAllMocks();
});
@@ -20,49 +29,35 @@ describe('setupGithubCommand', () => {
vi.restoreAllMocks();
});
- it('returns a tool action to download github workflows and handles paths', () => {
+ it('returns a tool action to download github workflows and handles paths', async () => {
const fakeRepoRoot = '/github.com/fake/repo/root';
- vi.mocked(child_process.execSync).mockReturnValue(fakeRepoRoot);
+ const fakeReleaseVersion = 'v1.2.3';
- const result = setupGithubCommand.action?.(
+ vi.mocked(gitUtils.isGitHubRepository).mockReturnValueOnce(true);
+ vi.mocked(gitUtils.getGitRepoRoot).mockReturnValueOnce(fakeRepoRoot);
+ vi.mocked(gitUtils.getLatestGitHubRelease).mockResolvedValueOnce(
+ fakeReleaseVersion,
+ );
+
+ const result = (await 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',
- });
+ )) as ToolActionReturn;
const { command } = result.toolArgs;
const expectedSubstrings = [
+ `set -eEuo pipefail`,
`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/tags/v0/examples/workflows/',
+ `curl --fail --location --output "/github.com/fake/repo/root/.github/workflows/gemini-cli.yml" --show-error --silent`,
+ `curl --fail --location --output "/github.com/fake/repo/root/.github/workflows/gemini-issue-automated-triage.yml" --show-error --silent`,
+ `curl --fail --location --output "/github.com/fake/repo/root/.github/workflows/gemini-issue-scheduled-triage.yml" --show-error --silent`,
+ `curl --fail --location --output "/github.com/fake/repo/root/.github/workflows/gemini-pr-review.yml" --show-error --silent`,
+ `https://raw.githubusercontent.com/google-github-actions/run-gemini-cli/refs/tags/`,
];
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 GitHub repository. /setup-github must be run from a git repository.',
- );
- });
});