@@ -15,10 +15,17 @@ const actionExecutionMocks = vi.hoisted(() => ({
1515 executeAction : vi . fn ( ) ,
1616} ) ) ;
1717
18+ const configMocks = vi . hoisted ( ( ) => ( {
19+ validateTrack : vi . fn ( ( value : string ) => value ) ,
20+ } ) ) ;
21+
1822vi . mock ( '@actions/core' , ( ) => coreMocks ) ;
1923vi . mock ( '../src/action-execution' , ( ) => ( {
2024 executeAction : actionExecutionMocks . executeAction ,
2125} ) ) ;
26+ vi . mock ( '../src/config' , ( ) => ( {
27+ validateTrack : configMocks . validateTrack ,
28+ } ) ) ;
2229
2330const mockGetInput = coreMocks . getInput ;
2431const mockGetMultilineInput = coreMocks . getMultilineInput ;
@@ -29,6 +36,7 @@ const mockSetOutput = coreMocks.setOutput;
2936const mockSetFailed = coreMocks . setFailed ;
3037const mockWarning = coreMocks . warning ;
3138const mockExecuteAction = actionExecutionMocks . executeAction as ReturnType < typeof vi . fn > ;
39+ const mockValidateTrack = configMocks . validateTrack as ReturnType < typeof vi . fn > ;
3240
3341import { run } from '../src/index' ;
3442
@@ -46,6 +54,7 @@ describe('run', () => {
4654 filesChanged : [ 'Dockerfile' ] ,
4755 dryRun : true ,
4856 } ) ;
57+ mockValidateTrack . mockImplementation ( ( value : string ) => value ) ;
4958 } ) ;
5059
5160 it ( 'uses default configuration when inputs are empty' , async ( ) => {
@@ -134,4 +143,21 @@ describe('run', () => {
134143
135144 expect ( mockSetFailed ) . toHaveBeenCalledWith ( 'run failure' ) ;
136145 } ) ;
146+
147+ it ( 'fails fast when track input is invalid' , async ( ) => {
148+ mockGetInput . mockImplementation ( ( name : string ) => {
149+ if ( name === 'track' ) return 'invalid' ;
150+ return '' ;
151+ } ) ;
152+ mockValidateTrack . mockImplementation ( ( ) => {
153+ throw new Error ( 'Input "track" must match X.Y (e.g. 3.13). Received "invalid".' ) ;
154+ } ) ;
155+
156+ await run ( ) ;
157+
158+ expect ( mockExecuteAction ) . not . toHaveBeenCalled ( ) ;
159+ expect ( mockSetFailed ) . toHaveBeenCalledWith (
160+ 'Input "track" must match X.Y (e.g. 3.13). Received "invalid".' ,
161+ ) ;
162+ } ) ;
137163} ) ;
0 commit comments