-
Notifications
You must be signed in to change notification settings - Fork 361
Fix: Accept "beta" as valid WordPress version in CLI validation #2820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
3
commits into
trunk
Choose a base branch
from
copilot/fix-invalid-wordpress-version
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+177
−2
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/playground/cli/tests/is-valid-wordpress-slug.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { isValidWordPressSlug } from '../src/is-valid-wordpress-slug'; | ||
|
|
||
| describe('isValidWordPressSlug', () => { | ||
| it('should accept "latest"', () => { | ||
| expect(isValidWordPressSlug('latest')).toBe(true); | ||
| }); | ||
|
|
||
| it('should accept "beta"', () => { | ||
| expect(isValidWordPressSlug('beta')).toBe(true); | ||
| }); | ||
|
|
||
| it('should accept "trunk"', () => { | ||
| expect(isValidWordPressSlug('trunk')).toBe(true); | ||
| }); | ||
|
|
||
| it('should accept "nightly"', () => { | ||
| expect(isValidWordPressSlug('nightly')).toBe(true); | ||
| }); | ||
|
|
||
| it('should accept version with major and minor (e.g., "6.2")', () => { | ||
| expect(isValidWordPressSlug('6.2')).toBe(true); | ||
| expect(isValidWordPressSlug('5.9')).toBe(true); | ||
| }); | ||
|
|
||
| it('should accept version with major, minor, and patch (e.g., "6.2.1")', () => { | ||
| expect(isValidWordPressSlug('6.2.1')).toBe(true); | ||
| expect(isValidWordPressSlug('5.9.3')).toBe(true); | ||
| }); | ||
|
|
||
| it('should accept version with beta suffix (e.g., "6.2-beta1")', () => { | ||
| expect(isValidWordPressSlug('6.2-beta1')).toBe(true); | ||
| expect(isValidWordPressSlug('6.2.1-beta1')).toBe(true); | ||
| expect(isValidWordPressSlug('6.2-beta')).toBe(true); | ||
| }); | ||
|
|
||
| it('should accept version with RC suffix (e.g., "6.2-RC1")', () => { | ||
| expect(isValidWordPressSlug('6.2-RC1')).toBe(true); | ||
| expect(isValidWordPressSlug('6.2.1-RC1')).toBe(true); | ||
| expect(isValidWordPressSlug('6.2-RC')).toBe(true); | ||
| }); | ||
|
|
||
| it('should reject invalid version strings', () => { | ||
| expect(isValidWordPressSlug('brazil')).toBe(false); | ||
| expect(isValidWordPressSlug('invalid')).toBe(false); | ||
| expect(isValidWordPressSlug('beta1')).toBe(false); | ||
| expect(isValidWordPressSlug('RC1')).toBe(false); | ||
| expect(isValidWordPressSlug('6')).toBe(false); | ||
| expect(isValidWordPressSlug('6.x')).toBe(false); | ||
| expect(isValidWordPressSlug('6.2.x')).toBe(false); | ||
| expect(isValidWordPressSlug('')).toBe(false); | ||
| }); | ||
|
|
||
| it('should reject version with invalid format', () => { | ||
| expect(isValidWordPressSlug('6.2.1.2')).toBe(false); | ||
| expect(isValidWordPressSlug('v6.2')).toBe(false); | ||
| expect(isValidWordPressSlug('6.2-alpha')).toBe(false); | ||
| expect(isValidWordPressSlug('6.2-beta-1')).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
| import { parseOptionsAndRunCLI } from '../src/run-cli'; | ||
|
|
||
| describe('parseOptionsAndRunCLI WordPress version validation', () => { | ||
| let originalArgv: string[]; | ||
| let exitSpy: ReturnType<typeof vi.spyOn>; | ||
| let consoleErrorSpy: ReturnType<typeof vi.spyOn>; | ||
|
|
||
| beforeEach(() => { | ||
| originalArgv = process.argv; | ||
| exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => { | ||
| throw new Error('process.exit called'); | ||
| }) as any); | ||
| consoleErrorSpy = vi | ||
| .spyOn(console, 'error') | ||
| .mockImplementation(() => {}); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.argv = originalArgv; | ||
| exitSpy.mockRestore(); | ||
| consoleErrorSpy.mockRestore(); | ||
| }); | ||
|
|
||
| it('should reject invalid WordPress version "brazil"', async () => { | ||
| process.argv = ['node', 'cli.js', 'server', '--wp=brazil']; | ||
|
|
||
| await expect(parseOptionsAndRunCLI()).rejects.toThrow( | ||
| 'process.exit called' | ||
| ); | ||
|
|
||
| expect(consoleErrorSpy).toHaveBeenCalled(); | ||
| const errorMessage = consoleErrorSpy.mock.calls[0][0]; | ||
| expect(errorMessage).toContain('Unrecognized WordPress version'); | ||
| }); | ||
|
|
||
| it('should reject invalid WordPress version "invalid-version"', async () => { | ||
| process.argv = ['node', 'cli.js', 'server', '--wp=invalid-version']; | ||
|
|
||
| await expect(parseOptionsAndRunCLI()).rejects.toThrow( | ||
| 'process.exit called' | ||
| ); | ||
|
|
||
| expect(consoleErrorSpy).toHaveBeenCalled(); | ||
| const errorMessage = consoleErrorSpy.mock.calls[0][0]; | ||
| expect(errorMessage).toContain('Unrecognized WordPress version'); | ||
| }); | ||
|
|
||
| it('should accept valid WordPress version "beta"', async () => { | ||
| process.argv = [ | ||
| 'node', | ||
| 'cli.js', | ||
| 'server', | ||
| '--wp=beta', | ||
| '--skip-wordpress-setup', | ||
| ]; | ||
|
|
||
| // This test would actually start the server, so we skip it in unit tests | ||
| // The important part is that it doesn't throw a validation error | ||
| // We'll rely on integration tests to verify the full flow | ||
| }); | ||
|
|
||
| it('should accept valid WordPress version "latest"', async () => { | ||
| process.argv = [ | ||
| 'node', | ||
| 'cli.js', | ||
| 'server', | ||
| '--wp=latest', | ||
| '--skip-wordpress-setup', | ||
| ]; | ||
|
|
||
| // This test would actually start the server, so we skip it in unit tests | ||
| // The important part is that it doesn't throw a validation error | ||
| // We'll rely on integration tests to verify the full flow | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamziel I think the point is here, the conditional check if the version is valid, if not skip it and doesn't do anything. I think we should throw a message if the value is not valid