@@ -196,6 +196,70 @@ 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+ prodRepo := utils .CreateLocalRepo (t , "prod-only-local" , []string {"PROD" })
240+ artifactPath := utils .UploadTestArtifact (t , prodRepo , "mismatch-artifact.txt" )
241+ artifactFlag := fmt .Sprintf ("--source-type-artifacts=path=%s" , artifactPath )
242+ output := utils .AppTrustCli .RunCliCmdWithOutput (t , "version-create" , appKey , version , artifactFlag , "--skip-unassigned" )
243+ defer utils .DeleteApplicationVersion (t , appKey , version )
244+
245+ require .NotEmpty (t , output )
246+
247+ var response struct {
248+ ApplicationKey string `json:"application_key"`
249+ Version string `json:"version"`
250+ Status string `json:"status"`
251+ CurrentStage string `json:"current_stage"`
252+ Message string `json:"message"`
253+ }
254+ err := json .Unmarshal ([]byte (output ), & response )
255+ require .NoError (t , err , "failed to parse CLI output as JSON: %s" , output )
256+ assert .Equal (t , appKey , response .ApplicationKey )
257+ assert .Equal (t , version , response .Version )
258+ assert .Empty (t , response .CurrentStage , "Version should NOT be promoted when artifacts are in PROD-only repo" )
259+ assert .NotEmpty (t , response .Message , "A message should explain why auto-promotion did not occur" )
260+ })
261+ }
262+
199263func TestCreateVersion_Async (t * testing.T ) {
200264 appKey := utils .GenerateUniqueKey ("app-version-create-async" )
201265 utils .CreateBasicApplication (t , appKey )
0 commit comments