Repository navigation
fix: validate plugin input early before git operations [ED-25747] #61
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { resolvePluginConfig } from './plugin-config.ts'; | ||
|
|
||
| describe('plugin validation in main.ts context', () => { | ||
| it('resolvePluginConfig is imported and used for early validation', () => { | ||
| expect(resolvePluginConfig('core')).toEqual({ | ||
| pluginFile: 'elementor.php', | ||
| versionConstant: 'ELEMENTOR_VERSION', | ||
| updateReadme: true, | ||
| updateElementorTestedUpTo: false, | ||
| }); | ||
|
|
||
| expect(resolvePluginConfig('pro')).toEqual({ | ||
| pluginFile: 'elementor-pro.php', | ||
| versionConstant: 'ELEMENTOR_PRO_VERSION', | ||
| updateReadme: false, | ||
| updateElementorTestedUpTo: true, | ||
| }); | ||
| }); | ||
|
|
||
| it('resolvePluginConfig throws on invalid plugin value "koko"', () => { | ||
| expect(() => resolvePluginConfig('koko')).toThrow( | ||
| 'plugin must be "core" or "pro", got "koko"', | ||
| ); | ||
| }); | ||
|
|
||
| it.each(['', 'Core', 'PRO', 'elementor', 'invalid'])( | ||
| 'resolvePluginConfig throws on invalid plugin value "%s"', | ||
| (invalidPlugin) => { | ||
| expect(() => resolvePluginConfig(invalidPlugin)).toThrow( | ||
| 'plugin must be "core" or "pro"', | ||
| ); | ||
| }, | ||
| ); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { | |
| checkVersionIsNext, | ||
| fetchCompanionTag, | ||
| } from './current-version-validation.ts'; | ||
| import { resolvePluginConfig } from './plugin-config.ts'; | ||
|
|
||
| // ─── I/O helpers ────────────────────────────────────────────────────────────── | ||
|
|
||
|
|
@@ -21,6 +22,10 @@ export function getVersion(): string { | |
| return version; | ||
| } | ||
|
|
||
| export function getPlugin(): string { | ||
| return (process.env['INPUT_PLUGIN'] ?? 'core').trim(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Low: |
||
| } | ||
|
|
||
| export function setOutput(name: string, value: string): void { | ||
| const outputFile = process.env['GITHUB_OUTPUT']; | ||
|
|
||
|
|
@@ -101,6 +106,10 @@ export function deriveBranch(channel: 'stable' | 'beta'): string { | |
| export function run(): void { | ||
| try { | ||
| const version = getVersion(); | ||
| const plugin = getPlugin(); | ||
|
|
||
| resolvePluginConfig(plugin); | ||
| console.log(`✅ Plugin input is valid: ${plugin}`); | ||
|
|
||
| validateFormat(version); | ||
| checkCurrentTagDoesNotExist(version); | ||
|
|
||
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.
Low: this file never imports
main.ts; it only re-testsresolvePluginConfig, whichplugin-config.test.tsalready covers (kokois now in both).getPlugin()'s default/trim and the 'plugin is validated beforegit ls-remote' order inrun()are untested. Becausemain.tsends with a barerun();, consider the same split as #60 (run-main.tsentrypoint), then testrun()withINPUT_PLUGIN=kokoand assertprocess.exit(1)and thatspawnSyncwas never called.