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