Repository navigation
fix: validate plugin input early before git operations [ED-25747] - #61
Conversation
Address code review comment from PR #60: validate the plugin input ('core' or 'pro') in the 'Handle version input' step before any git branch operations occur. This ensures invalid plugin values like 'koko' fail fast with a clear error message, preventing wasted work and avoiding branch checkout mutations. Changes: - Import and call resolvePluginConfig() at the start of main.ts run() - Add INPUT_PLUGIN env var to 'Handle version input' step in action.yml - Add getPlugin() helper to read INPUT_PLUGIN (defaults to 'core') - Add unit tests for plugin validation behavior - Extend plugin-config.test.ts to explicitly test 'koko' case Ref: #60 Co-authored-by: Davids Seveloff <davseve@users.noreply.github.com>
| } | ||
|
|
||
| export function getPlugin(): string { | ||
| return (process.env['INPUT_PLUGIN'] ?? 'core').trim(); |
There was a problem hiding this comment.
Low: getPlugin() trims, but update-version-files.ts reads INPUT_PLUGIN via getEnv() without trimming. A value like " pro " passes this early check and then fails in 'Update version files' (after the release-branch checkout), which is the late failure this PR is meant to prevent. Either drop .trim() here so both steps reject it at step 2, or trim in update-version-files.ts as well.
| @@ -0,0 +1,36 @@ | |||
| import { describe, expect, it } from 'vitest'; | |||
|
|
|||
| import { resolvePluginConfig } from './plugin-config.ts'; | |||
There was a problem hiding this comment.
Low: this file never imports main.ts; it only re-tests resolvePluginConfig, which plugin-config.test.ts already covers (koko is now in both). getPlugin()'s default/trim and the 'plugin is validated before git ls-remote' order in run() are untested. Because main.ts ends with a bare run();, consider the same split as #60 (run-main.ts entrypoint), then test run() with INPUT_PLUGIN=koko and assert process.exit(1) and that spawnSync was never called.
Summary
Addresses @Ntnelbaba's code review comment on PR #60: "And if the value is 'koko'?"
This PR makes invalid
plugininput values (like"koko") fail fast with a clear error message before any git branch operations occur, preventing wasted work and avoiding branch checkout mutations.Background
PR #60 added a new
plugininput (coreorpro) to therelease-tag-creationcomposite action. The validation logicresolvePluginConfig(plugin)inplugin-config.tsalready throwsplugin must be "core" or "pro", got "<x>"for invalid values, but that validation only ran inside the "Update version files" step (step 5), which is AFTER:git checkout) ← branch mutatedSo an invalid plugin value like
"koko"would waste work and mutate the working tree before failing.What Changed
main.tsnow imports and callsresolvePluginConfig(plugin)at the very start of therun()function, before any version format checks or git operations.getPlugin()to readINPUT_PLUGINenv var (defaults to"core").INPUT_PLUGIN: ${{ inputs.plugin }}to the "Handle version input" step so the plugin value is available.main.test.tswith unit tests for the plugin validation behavior.plugin-config.test.tsto explicitly include the"koko"test case mentioned in the review.How It Works
The "Handle version input" step now:
resolvePluginConfig(plugin))Only after all input validations pass does the workflow proceed to
git checkoutof the release branch.Testing
vitestpasses (49 tests including new plugin validation tests)tsctype-checking passeseslintpassesRelated