mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-15 08:31:14 -07:00
Copy commands as part of setup-github (#13464)
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
setupGithubCommand,
|
||||
updateGitignore,
|
||||
GITHUB_WORKFLOW_PATHS,
|
||||
GITHUB_COMMANDS_PATHS,
|
||||
} from './setupGithubCommand.js';
|
||||
import type { CommandContext, ToolActionReturn } from './types.js';
|
||||
import * as commandUtils from '../utils/commandUtils.js';
|
||||
@@ -56,11 +57,16 @@ describe('setupGithubCommand', async () => {
|
||||
const fakeReleaseVersion = 'v1.2.3';
|
||||
|
||||
const workflows = GITHUB_WORKFLOW_PATHS.map((p) => path.basename(p));
|
||||
for (const workflow of workflows) {
|
||||
vi.mocked(global.fetch).mockReturnValueOnce(
|
||||
Promise.resolve(new Response(workflow)),
|
||||
);
|
||||
}
|
||||
const commands = GITHUB_COMMANDS_PATHS.map((p) => path.basename(p));
|
||||
|
||||
vi.mocked(global.fetch).mockImplementation(async (url) => {
|
||||
const filename = path.basename(url.toString());
|
||||
return new Response(filename, {
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
});
|
||||
});
|
||||
|
||||
vi.mocked(gitUtils.isGitHubRepository).mockReturnValueOnce(true);
|
||||
vi.mocked(gitUtils.getGitRepoRoot).mockReturnValueOnce(fakeRepoRoot);
|
||||
@@ -102,6 +108,12 @@ describe('setupGithubCommand', async () => {
|
||||
expect(contents).toContain(workflow);
|
||||
}
|
||||
|
||||
for (const command of commands) {
|
||||
const commandFile = path.join(scratchDir, '.github', 'commands', command);
|
||||
const contents = await fs.readFile(commandFile, 'utf8');
|
||||
expect(contents).toContain(command);
|
||||
}
|
||||
|
||||
// Verify that .gitignore was created with the expected entries
|
||||
const gitignorePath = path.join(scratchDir, '.gitignore');
|
||||
const gitignoreExists = await fs
|
||||
@@ -116,6 +128,32 @@ describe('setupGithubCommand', async () => {
|
||||
expect(gitignoreContent).toContain('gha-creds-*.json');
|
||||
}
|
||||
});
|
||||
|
||||
it('throws an error when download fails', async () => {
|
||||
const fakeRepoRoot = scratchDir;
|
||||
const fakeReleaseVersion = 'v1.2.3';
|
||||
|
||||
vi.mocked(global.fetch).mockResolvedValue(
|
||||
new Response('Not Found', {
|
||||
status: 404,
|
||||
statusText: 'Not Found',
|
||||
}),
|
||||
);
|
||||
|
||||
vi.mocked(gitUtils.isGitHubRepository).mockReturnValueOnce(true);
|
||||
vi.mocked(gitUtils.getGitRepoRoot).mockReturnValueOnce(fakeRepoRoot);
|
||||
vi.mocked(gitUtils.getLatestGitHubRelease).mockResolvedValueOnce(
|
||||
fakeReleaseVersion,
|
||||
);
|
||||
vi.mocked(gitUtils.getGitHubRepoInfo).mockReturnValue({
|
||||
owner: 'fake',
|
||||
repo: 'repo',
|
||||
});
|
||||
|
||||
await expect(
|
||||
setupGithubCommand.action?.({} as CommandContext, ''),
|
||||
).rejects.toThrow(/Invalid response code downloading.*404 - Not Found/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateGitignore', () => {
|
||||
|
||||
Reference in New Issue
Block a user