@@ -196,6 +196,69 @@ func TestCreateVersion_Draft(t *testing.T) {
196196 assert .Equal (t , utils .StatusDraft , versionContent .Status )
197197}
198198
199+ func TestCreateVersion_SkipUnassigned (t * testing.T ) {
200+ appKey := utils .GenerateUniqueKey ("app-version-skip-unassigned" )
201+ utils .CreateBasicApplication (t , appKey )
202+ defer utils .DeleteApplication (t , appKey )
203+
204+ testPackage := utils .GetTestPackage (t )
205+
206+ t .Run ("passes eligibility when source repo is mapped to first stage" , func (t * testing.T ) {
207+ version := utils .GenerateUniqueKey ("skip-ua-ok" )
208+
209+ packageFlag := fmt .Sprintf ("--source-type-packages=type=%s, name=%s, version=%s, repo-key=%s" ,
210+ testPackage .PackageType , testPackage .PackageName , testPackage .PackageVersion , testPackage .RepoKey )
211+ output := utils .AppTrustCli .RunCliCmdWithOutput (t , "version-create" , appKey , version , packageFlag , "--skip-unassigned" )
212+ defer utils .DeleteApplicationVersion (t , appKey , version )
213+
214+ require .NotEmpty (t , output )
215+
216+ var response struct {
217+ ApplicationKey string `json:"application_key"`
218+ Version string `json:"version"`
219+ Status string `json:"status"`
220+ CurrentStage string `json:"current_stage"`
221+ Message string `json:"message"`
222+ }
223+ err := json .Unmarshal ([]byte (output ), & response )
224+ require .NoError (t , err , "failed to parse CLI output as JSON: %s" , output )
225+ assert .Equal (t , appKey , response .ApplicationKey )
226+ assert .Equal (t , version , response .Version )
227+
228+ versionContent , statusCode , err := utils .GetApplicationVersion (appKey , version )
229+ require .NoError (t , err )
230+ assert .Equal (t , http .StatusOK , statusCode )
231+ require .NotNil (t , versionContent )
232+ assert .Equal (t , utils .StatusCompleted , versionContent .Status )
233+ assert .Equal (t , "DEV" , versionContent .CurrentStage , "Version should be auto-promoted to DEV stage" )
234+ })
235+
236+ t .Run ("stays unassigned with message when artifacts mismatch first stage" , func (t * testing.T ) {
237+ version := utils .GenerateUniqueKey ("skip-ua-fail" )
238+
239+ artifactPath := utils .GetTestArtifactInProdOnlyRepo (t )
240+ artifactFlag := fmt .Sprintf ("--source-type-artifacts=path=%s" , artifactPath )
241+ output := utils .AppTrustCli .RunCliCmdWithOutput (t , "version-create" , appKey , version , artifactFlag , "--skip-unassigned" )
242+ defer utils .DeleteApplicationVersion (t , appKey , version )
243+
244+ require .NotEmpty (t , output )
245+
246+ var response struct {
247+ ApplicationKey string `json:"application_key"`
248+ Version string `json:"version"`
249+ Status string `json:"status"`
250+ CurrentStage string `json:"current_stage"`
251+ Message string `json:"message"`
252+ }
253+ err := json .Unmarshal ([]byte (output ), & response )
254+ require .NoError (t , err , "failed to parse CLI output as JSON: %s" , output )
255+ assert .Equal (t , appKey , response .ApplicationKey )
256+ assert .Equal (t , version , response .Version )
257+ assert .Empty (t , response .CurrentStage , "Version should NOT be promoted when artifacts are in PROD-only repo" )
258+ assert .NotEmpty (t , response .Message , "A message should explain why auto-promotion did not occur" )
259+ })
260+ }
261+
199262func TestCreateVersion_Async (t * testing.T ) {
200263 appKey := utils .GenerateUniqueKey ("app-version-create-async" )
201264 utils .CreateBasicApplication (t , appKey )
0 commit comments