mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 14:10:37 -07:00
Release Promotion Clean up (#8597)
This commit is contained in:
@@ -7,120 +7,117 @@
|
||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||
import { getVersion } from '../get-release-version.js';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
vi.mock('node:child_process');
|
||||
vi.mock('node:fs');
|
||||
|
||||
describe('getReleaseVersion', () => {
|
||||
describe('getVersion', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
// Mock date to be consistent
|
||||
vi.setSystemTime(new Date('2025-09-11T00:00:00.000Z'));
|
||||
vi.setSystemTime(new Date('2025-09-17T00:00:00.000Z'));
|
||||
});
|
||||
|
||||
describe('Nightly Workflow Logic', () => {
|
||||
it('should calculate the next nightly version based on package.json', () => {
|
||||
vi.mocked(readFileSync).mockReturnValue('{"version": "0.5.0"}');
|
||||
vi.mocked(execSync).mockImplementation((command) => {
|
||||
if (command.includes('rev-parse')) return 'a1b2c3d';
|
||||
if (command.includes('release list'))
|
||||
return 'v0.5.0-nightly.20250910.abcdef';
|
||||
return '';
|
||||
});
|
||||
const mockExecSync = (command) => {
|
||||
// NPM Mocks
|
||||
if (command.includes('npm view') && command.includes('--tag=latest'))
|
||||
return '0.4.1';
|
||||
if (command.includes('npm view') && command.includes('--tag=preview'))
|
||||
return '0.5.0-preview-2';
|
||||
if (command.includes('npm view') && command.includes('--tag=nightly'))
|
||||
return '0.6.0-nightly.20250910.a31830a3';
|
||||
|
||||
const result = getVersion({ type: 'nightly' });
|
||||
// Git Tag Mocks
|
||||
if (command.includes("git tag --sort=-creatordate -l 'v[0-9].[0-9].[0-9]'"))
|
||||
return 'v0.4.1';
|
||||
if (command.includes("git tag --sort=-creatordate -l 'v*-preview*'"))
|
||||
return 'v0.5.0-preview-2';
|
||||
if (command.includes("git tag --sort=-creatordate -l 'v*-nightly*'"))
|
||||
return 'v0.6.0-nightly.20250910.a31830a3';
|
||||
|
||||
expect(result.releaseVersion).toBe('0.6.0-nightly.20250911.a1b2c3d');
|
||||
expect(result.npmTag).toBe('nightly');
|
||||
expect(result.previousReleaseTag).toBe('v0.5.0-nightly.20250910.abcdef');
|
||||
});
|
||||
// GitHub Release Mocks
|
||||
if (command.includes('gh release view "v0.4.1"')) return 'v0.4.1';
|
||||
if (command.includes('gh release view "v0.5.0-preview-2"'))
|
||||
return 'v0.5.0-preview-2';
|
||||
if (command.includes('gh release view "v0.6.0-nightly.20250910.a31830a3"'))
|
||||
return 'v0.6.0-nightly.20250910.a31830a3';
|
||||
|
||||
it('should default minor to 0 if missing in package.json version', () => {
|
||||
vi.mocked(readFileSync).mockReturnValue('{"version": "0"}');
|
||||
vi.mocked(execSync).mockImplementation((command) => {
|
||||
if (command.includes('rev-parse')) return 'a1b2c3d';
|
||||
if (command.includes('release list'))
|
||||
return 'v0.0.0-nightly.20250910.abcdef';
|
||||
return '';
|
||||
});
|
||||
// Git Hash Mock
|
||||
if (command.includes('git rev-parse --short HEAD')) return 'd3bf8a3d';
|
||||
|
||||
const result = getVersion({ type: 'nightly' });
|
||||
|
||||
expect(result.releaseVersion).toBe('0.1.0-nightly.20250911.a1b2c3d');
|
||||
expect(result.npmTag).toBe('nightly');
|
||||
expect(result.previousReleaseTag).toBe('v0.0.0-nightly.20250910.abcdef');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Promote Workflow Logic', () => {
|
||||
it('should calculate stable version from the latest preview tag', () => {
|
||||
const latestPreview = 'v0.5.0-preview';
|
||||
const latestStable = 'v0.4.0';
|
||||
|
||||
vi.mocked(execSync).mockImplementation((command) => {
|
||||
if (command.includes('not')) return latestStable;
|
||||
if (command.includes('contains("preview")')) return latestPreview;
|
||||
return '';
|
||||
});
|
||||
return '';
|
||||
};
|
||||
|
||||
describe('Happy Path - Version Calculation', () => {
|
||||
it('should calculate the next stable version from the latest preview', () => {
|
||||
vi.mocked(execSync).mockImplementation(mockExecSync);
|
||||
const result = getVersion({ type: 'stable' });
|
||||
|
||||
expect(result.releaseVersion).toBe('0.5.0');
|
||||
expect(result.npmTag).toBe('latest');
|
||||
expect(result.previousReleaseTag).toBe(latestStable);
|
||||
expect(result.previousReleaseTag).toBe('v0.5.0-preview-2');
|
||||
});
|
||||
|
||||
it('should calculate preview version from the latest nightly tag', () => {
|
||||
const latestNightly = 'v0.6.0-nightly.20250910.abcdef';
|
||||
const latestPreview = 'v0.5.0-preview';
|
||||
|
||||
vi.mocked(execSync).mockImplementation((command) => {
|
||||
if (command.includes('nightly')) return latestNightly;
|
||||
if (command.includes('preview')) return latestPreview;
|
||||
return '';
|
||||
});
|
||||
|
||||
it('should calculate the next preview version from the latest nightly', () => {
|
||||
vi.mocked(execSync).mockImplementation(mockExecSync);
|
||||
const result = getVersion({ type: 'preview' });
|
||||
|
||||
expect(result.releaseVersion).toBe('0.6.0-preview');
|
||||
expect(result.npmTag).toBe('preview');
|
||||
expect(result.previousReleaseTag).toBe(latestPreview);
|
||||
expect(result.previousReleaseTag).toBe(
|
||||
'v0.6.0-nightly.20250910.a31830a3',
|
||||
);
|
||||
});
|
||||
|
||||
it('should calculate the next nightly version from the latest nightly', () => {
|
||||
vi.mocked(execSync).mockImplementation(mockExecSync);
|
||||
const result = getVersion({ type: 'nightly' });
|
||||
expect(result.releaseVersion).toBe('0.7.0-nightly.20250917.d3bf8a3d');
|
||||
expect(result.npmTag).toBe('nightly');
|
||||
expect(result.previousReleaseTag).toBe(
|
||||
'v0.6.0-nightly.20250910.a31830a3',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Patch Workflow Logic', () => {
|
||||
it('should calculate the next patch version for a stable release', () => {
|
||||
const latestStable = 'v0.5.1';
|
||||
vi.mocked(execSync).mockReturnValue(latestStable);
|
||||
|
||||
const result = getVersion({ type: 'patch', patchFrom: 'stable' });
|
||||
|
||||
expect(result.releaseVersion).toBe('0.5.2');
|
||||
vi.mocked(execSync).mockImplementation(mockExecSync);
|
||||
const result = getVersion({ type: 'patch', 'patch-from': 'stable' });
|
||||
expect(result.releaseVersion).toBe('0.4.2');
|
||||
expect(result.npmTag).toBe('latest');
|
||||
expect(result.previousReleaseTag).toBe(latestStable);
|
||||
expect(result.previousReleaseTag).toBe('v0.4.1');
|
||||
});
|
||||
|
||||
it('should calculate the next patch version for a preview release', () => {
|
||||
const latestPreview = 'v0.6.0-preview';
|
||||
vi.mocked(execSync).mockReturnValue(latestPreview);
|
||||
|
||||
const result = getVersion({ type: 'patch', patchFrom: 'preview' });
|
||||
|
||||
expect(result.releaseVersion).toBe('0.6.1-preview');
|
||||
vi.mocked(execSync).mockImplementation(mockExecSync);
|
||||
const result = getVersion({ type: 'patch', 'patch-from': 'preview' });
|
||||
expect(result.releaseVersion).toBe('0.5.1-preview-2');
|
||||
expect(result.npmTag).toBe('preview');
|
||||
expect(result.previousReleaseTag).toBe(latestPreview);
|
||||
expect(result.previousReleaseTag).toBe('v0.5.0-preview-2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Failure Path - Discrepancy Checks', () => {
|
||||
it('should throw an error if the git tag does not match npm', () => {
|
||||
const mockWithMismatchGitTag = (command) => {
|
||||
if (command.includes("git tag --sort=-creatordate -l 'v*-preview*'"))
|
||||
return 'v0.4.0-preview-99'; // Mismatch
|
||||
return mockExecSync(command);
|
||||
};
|
||||
vi.mocked(execSync).mockImplementation(mockWithMismatchGitTag);
|
||||
|
||||
expect(() => getVersion({ type: 'stable' })).toThrow(
|
||||
'Discrepancy found! NPM preview tag (0.5.0-preview-2) does not match latest git preview tag (v0.4.0-preview-99).',
|
||||
);
|
||||
});
|
||||
|
||||
it('should default patch to 0 if missing in stable release', () => {
|
||||
const latestStable = 'v0.5';
|
||||
vi.mocked(execSync).mockReturnValue(latestStable);
|
||||
it('should throw an error if the GitHub release is missing', () => {
|
||||
const mockWithMissingRelease = (command) => {
|
||||
if (command.includes('gh release view "v0.5.0-preview-2"')) {
|
||||
throw new Error('gh command failed'); // Simulate gh failure
|
||||
}
|
||||
return mockExecSync(command);
|
||||
};
|
||||
vi.mocked(execSync).mockImplementation(mockWithMissingRelease);
|
||||
|
||||
const result = getVersion({ type: 'patch', patchFrom: 'stable' });
|
||||
|
||||
expect(result.releaseVersion).toBe('0.5.1');
|
||||
expect(result.npmTag).toBe('latest');
|
||||
expect(result.previousReleaseTag).toBe(latestStable);
|
||||
expect(() => getVersion({ type: 'stable' })).toThrow(
|
||||
'Discrepancy found! Failed to verify GitHub release for v0.5.0-preview-2.',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user