From d8fec54e817e74f2de533e511cfd31ae93f58963 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Mon, 11 Aug 2025 21:32:23 -0400 Subject: feat(/setup-github): Use node to download the files (#5863) --- .../cli/src/ui/commands/setupGithubCommand.test.ts | 54 ++++++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'packages/cli/src/ui/commands/setupGithubCommand.test.ts') diff --git a/packages/cli/src/ui/commands/setupGithubCommand.test.ts b/packages/cli/src/ui/commands/setupGithubCommand.test.ts index be0a657f..38589e58 100644 --- a/packages/cli/src/ui/commands/setupGithubCommand.test.ts +++ b/packages/cli/src/ui/commands/setupGithubCommand.test.ts @@ -4,10 +4,15 @@ * SPDX-License-Identifier: Apache-2.0 */ +import os from 'node:os'; +import path from 'node:path'; +import fs from 'node:fs/promises'; + import { vi, describe, expect, it, afterEach, beforeEach } from 'vitest'; import * as gitUtils from '../../utils/gitUtils.js'; import { setupGithubCommand } from './setupGithubCommand.js'; import { CommandContext, ToolActionReturn } from './types.js'; +import * as commandUtils from '../utils/commandUtils.js'; vi.mock('child_process'); @@ -21,21 +26,43 @@ vi.mock('../../utils/gitUtils.js', () => ({ getGitHubRepoInfo: vi.fn(), })); +vi.mock('../utils/commandUtils.js', () => ({ + getUrlOpenCommand: vi.fn(), +})); + describe('setupGithubCommand', async () => { - beforeEach(() => { + let scratchDir = ''; + + beforeEach(async () => { vi.resetAllMocks(); + scratchDir = await fs.mkdtemp( + path.join(os.tmpdir(), 'setup-github-command-'), + ); }); - afterEach(() => { + afterEach(async () => { vi.restoreAllMocks(); + if (scratchDir) await fs.rm(scratchDir, { recursive: true }); }); it('returns a tool action to download github workflows and handles paths', async () => { const fakeRepoOwner = 'fake'; const fakeRepoName = 'repo'; - const fakeRepoRoot = `/github.com/${fakeRepoOwner}/${fakeRepoName}/root`; + const fakeRepoRoot = scratchDir; const fakeReleaseVersion = 'v1.2.3'; + const workflows = [ + 'gemini-cli.yml', + 'gemini-issue-automated-triage.yml', + 'gemini-issue-scheduled-triage.yml', + 'gemini-pr-review.yml', + ]; + for (const workflow of workflows) { + vi.mocked(global.fetch).mockReturnValueOnce( + Promise.resolve(new Response(workflow)), + ); + } + vi.mocked(gitUtils.isGitHubRepository).mockReturnValueOnce(true); vi.mocked(gitUtils.getGitRepoRoot).mockReturnValueOnce(fakeRepoRoot); vi.mocked(gitUtils.getLatestGitHubRelease).mockResolvedValueOnce( @@ -45,6 +72,9 @@ describe('setupGithubCommand', async () => { owner: fakeRepoOwner, repo: fakeRepoName, }); + vi.mocked(commandUtils.getUrlOpenCommand).mockReturnValueOnce( + 'fakeOpenCommand', + ); const result = (await setupGithubCommand.action?.( {} as CommandContext, @@ -55,16 +85,22 @@ describe('setupGithubCommand', async () => { const expectedSubstrings = [ `set -eEuo pipefail`, - `mkdir -p "${fakeRepoRoot}/.github/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/`, + `fakeOpenCommand "https://github.com/google-github-actions/run-gemini-cli`, ]; for (const substring of expectedSubstrings) { expect(command).toContain(substring); } + + for (const workflow of workflows) { + const workflowFile = path.join( + scratchDir, + '.github', + 'workflows', + workflow, + ); + const contents = await fs.readFile(workflowFile, 'utf8'); + expect(contents).toContain(workflow); + } }); }); -- cgit v1.2.3