Skip to content

[PROD-13446] Solution.sdkVersion is now retrieved from the docker image #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class ControllerTestUtils {
parameters: MutableList<RunTemplateParameter> = mutableListOf(),
parameterGroups: MutableList<RunTemplateParameterGroup> = mutableListOf(),
runTemplates: MutableList<RunTemplate> = mutableListOf(),
sdkVersion: String = "",
url: String = "",
security: SolutionSecurity? = null
): SolutionCreateRequest {
Expand All @@ -101,7 +100,6 @@ class ControllerTestUtils {
parameters = parameters,
parameterGroups = parameterGroups,
runTemplates = runTemplates,
sdkVersion = sdkVersion,
url = url,
security = security,
)
Expand All @@ -117,7 +115,6 @@ class ControllerTestUtils {
description: String = "",
alwaysPull: Boolean? = null,
tags: MutableList<String> = mutableListOf(),
sdkVersion: String = "",
url: String = "",
): SolutionUpdateRequest {
return SolutionUpdateRequest(
Expand All @@ -129,7 +126,6 @@ class ControllerTestUtils {
description = description,
alwaysPull = alwaysPull,
tags = tags,
sdkVersion = sdkVersion,
url = url)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object SolutionConstants {
const val SOLUTION_KEY = "my_solution_key"
const val SOLUTION_REPOSITORY = "solution_repository"
const val SOLUTION_VERSION = "1.0.0"
const val SOLUTION_SDK_VERSION = "11.3.0-45678.abcdef12"
const val SOLUTION_SIMULATOR = "my_simulator_name"
const val NEW_USER_ID = "[email protected]"
const val NEW_USER_ROLE = "editor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.
package com.cosmotech.api.home.solution

import com.cosmotech.api.containerregistry.ContainerRegistryService
import com.cosmotech.api.home.Constants.PLATFORM_ADMIN_EMAIL
import com.cosmotech.api.home.ControllerTestBase
import com.cosmotech.api.home.ControllerTestUtils.OrganizationUtils.constructOrganizationCreateRequest
Expand All @@ -15,21 +16,27 @@ import com.cosmotech.api.home.organization.OrganizationConstants.NEW_USER_ROLE
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_KEY
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_NAME
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_REPOSITORY
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_SDK_VERSION
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_SIMULATOR
import com.cosmotech.api.home.solution.SolutionConstants.SOLUTION_VERSION
import com.cosmotech.api.rbac.ROLE_ADMIN
import com.cosmotech.api.rbac.ROLE_NONE
import com.cosmotech.api.rbac.ROLE_VIEWER
import com.cosmotech.solution.api.SolutionApiService
import com.cosmotech.solution.domain.*
import io.mockk.every
import io.mockk.mockk
import org.json.JSONArray
import org.json.JSONObject
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.http.MediaType
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.util.ReflectionTestUtils
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
Expand All @@ -39,10 +46,18 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class SolutionControllerTests : ControllerTestBase() {

@Autowired lateinit var solutionApiService: SolutionApiService
private lateinit var organizationId: String

private var containerRegistryService: ContainerRegistryService = mockk(relaxed = true)

@BeforeEach
fun beforeEach() {
ReflectionTestUtils.setField(
solutionApiService, "containerRegistryService", containerRegistryService)
every { containerRegistryService.getImageLabel(any(), any(), any()) } returns
SOLUTION_SDK_VERSION

organizationId = createOrganizationAndReturnId(mvc, constructOrganizationCreateRequest())
}

Expand Down Expand Up @@ -78,6 +93,7 @@ class SolutionControllerTests : ControllerTestBase() {
.andExpect(jsonPath("$[0].name").value(firstSolutionName))
.andExpect(jsonPath("$[0].ownerId").value(PLATFORM_ADMIN_EMAIL))
.andExpect(jsonPath("$[0].organizationId").value(organizationId))
.andExpect(jsonPath("$[0].sdkVersion").value(SOLUTION_SDK_VERSION))
.andExpect(jsonPath("$[0].security.default").value(ROLE_NONE))
.andExpect(jsonPath("$[0].security.accessControlList[0].role").value(ROLE_ADMIN))
.andExpect(jsonPath("$[0].security.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL))
Expand All @@ -86,6 +102,7 @@ class SolutionControllerTests : ControllerTestBase() {
.andExpect(jsonPath("$[1].name").value(secondSolutionName))
.andExpect(jsonPath("$[1].ownerId").value(PLATFORM_ADMIN_EMAIL))
.andExpect(jsonPath("$[1].organizationId").value(organizationId))
.andExpect(jsonPath("$[1].sdkVersion").value(SOLUTION_SDK_VERSION))
.andExpect(jsonPath("$[1].security.default").value(ROLE_NONE))
.andExpect(jsonPath("$[1].security.accessControlList[0].role").value(ROLE_ADMIN))
.andExpect(jsonPath("$[1].security.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL))
Expand Down Expand Up @@ -152,7 +169,6 @@ class SolutionControllerTests : ControllerTestBase() {
mutableListOf(parameterGroupId),
10))

val sdkVersion = "this_is_the_sdk_version"
val url = "this_is_the_solution_url"
val security =
SolutionSecurity(
Expand All @@ -174,7 +190,6 @@ class SolutionControllerTests : ControllerTestBase() {
parameters,
parameterGroups,
runTemplates,
sdkVersion,
url,
security)

Expand Down Expand Up @@ -218,6 +233,7 @@ class SolutionControllerTests : ControllerTestBase() {
.andExpect(jsonPath("$.url").value(url))
.andExpect(jsonPath("$.tags").value(tags))
.andExpect(jsonPath("$.organizationId").value(organizationId))
.andExpect(jsonPath("$.sdkVersion").value(SOLUTION_SDK_VERSION))
.andExpect(jsonPath("$.security.default").value(ROLE_NONE))
.andExpect(jsonPath("$.security.accessControlList[0].role").value(ROLE_ADMIN))
.andExpect(jsonPath("$.security.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL))
Expand Down Expand Up @@ -286,7 +302,6 @@ class SolutionControllerTests : ControllerTestBase() {
mutableListOf(parameterGroupId),
10))

val sdkVersion = "this_is_the_sdk_version"
val url = "this_is_the_solution_url"
val security =
SolutionSecurity(
Expand All @@ -308,7 +323,6 @@ class SolutionControllerTests : ControllerTestBase() {
parameters,
parameterGroups,
runTemplates,
sdkVersion,
url,
security)

Expand Down Expand Up @@ -361,6 +375,7 @@ class SolutionControllerTests : ControllerTestBase() {
.andExpect(jsonPath("$.url").value(url))
.andExpect(jsonPath("$.tags").value(tags))
.andExpect(jsonPath("$.organizationId").value(organizationId))
.andExpect(jsonPath("$.sdkVersion").value(SOLUTION_SDK_VERSION))
.andExpect(jsonPath("$.security.default").value(ROLE_NONE))
.andExpect(jsonPath("$.security.accessControlList[0].role").value(ROLE_ADMIN))
.andExpect(jsonPath("$.security.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL))
Expand Down Expand Up @@ -394,7 +409,6 @@ class SolutionControllerTests : ControllerTestBase() {

val description = "this_is_a_description"
val tags = mutableListOf("tag1", "tag2")
val sdkVersion = "this_is_the_sdk_version"
val url = "this_is_the_solution_url"

val solutionUpdateRequest =
Expand All @@ -407,7 +421,6 @@ class SolutionControllerTests : ControllerTestBase() {
description,
true,
tags,
sdkVersion,
url)

mvc.perform(
Expand All @@ -426,6 +439,7 @@ class SolutionControllerTests : ControllerTestBase() {
.andExpect(jsonPath("$.url").value(url))
.andExpect(jsonPath("$.tags").value(tags))
.andExpect(jsonPath("$.organizationId").value(organizationId))
.andExpect(jsonPath("$.sdkVersion").value(SOLUTION_SDK_VERSION))
.andExpect(jsonPath("$.security.default").value(ROLE_NONE))
.andExpect(jsonPath("$.security.accessControlList[0].role").value(ROLE_ADMIN))
.andExpect(jsonPath("$.security.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.cosmotech.dataset.service

import com.cosmotech.api.config.CsmPlatformProperties
import com.cosmotech.api.containerregistry.ContainerRegistryService
import com.cosmotech.api.events.CsmEventPublisher
import com.cosmotech.api.events.TwingraphImportEvent
import com.cosmotech.api.exceptions.CsmAccessForbiddenException
Expand Down Expand Up @@ -118,6 +119,7 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
@Autowired lateinit var workspaceApiService: WorkspaceApiServiceInterface
@SpykBean @Autowired lateinit var csmPlatformProperties: CsmPlatformProperties
@MockK(relaxUnitFun = true) lateinit var eventPublisher: CsmEventPublisher
private var containerRegistryService: ContainerRegistryService = mockk(relaxed = true)

lateinit var connectorSaved: Connector
lateinit var dataset: Dataset
Expand All @@ -144,6 +146,9 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
unifiedJedis = UnifiedJedis(HostAndPort(containerIp, Protocol.DEFAULT_PORT))
ReflectionTestUtils.setField(datasetApiService, "unifiedJedis", unifiedJedis)
ReflectionTestUtils.setField(datasetApiService, "eventPublisher", eventPublisher)
ReflectionTestUtils.setField(
solutionApiService, "containerRegistryService", containerRegistryService)
every { containerRegistryService.getImageLabel(any(), any(), any()) } returns null
}

@BeforeEach
Expand Down
2 changes: 1 addition & 1 deletion doc/Models/Solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| **csmSimulator** | **String** | The main Cosmo Tech simulator name used in standard Run Template | [default to null] |
| **version** | **String** | The Solution version MAJOR.MINOR.PATCH. Must be aligned with an existing repository tag | [default to null] |
| **ownerId** | **String** | The User id which owns this Solution | [default to null] |
| **sdkVersion** | **String** | The MAJOR.MINOR version used to build this solution | [optional] [default to null] |
| **sdkVersion** | **String** | The full SDK version used to build this solution, if available | [optional] [default to null] |
| **url** | **String** | An optional URL link to solution page | [optional] [default to null] |
| **tags** | **List** | The list of tags | [optional] [default to null] |
| **parameters** | [**List**](RunTemplateParameter.md) | The list of Run Template Parameters | [default to null] |
Expand Down
1 change: 0 additions & 1 deletion doc/Models/SolutionCreateRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
| **parameters** | [**List**](RunTemplateParameter.md) | The list of Run Template Parameters | [optional] [default to []] |
| **parameterGroups** | [**List**](RunTemplateParameterGroup.md) | The list of parameters groups for the Run Templates | [optional] [default to []] |
| **runTemplates** | [**List**](RunTemplate.md) | List of Run Templates | [optional] [default to []] |
| **sdkVersion** | **String** | The MAJOR.MINOR version used to build this solution | [optional] [default to null] |
| **url** | **String** | An optional URL link to solution page | [optional] [default to null] |
| **security** | [**SolutionSecurity**](SolutionSecurity.md) | | [optional] [default to null] |

Expand Down
1 change: 0 additions & 1 deletion doc/Models/SolutionUpdateRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
| **alwaysPull** | **Boolean** | Set to true if the runtemplate wants to always pull the image | [optional] [default to false] |
| **csmSimulator** | **String** | The main Cosmo Tech simulator name used in standard Run Template | [optional] [default to null] |
| **version** | **String** | The Solution version MAJOR.MINOR.PATCH. Must be aligned with an existing repository tag | [optional] [default to null] |
| **sdkVersion** | **String** | The MAJOR.MINOR version used to build this solution | [optional] [default to null] |
| **url** | **String** | An optional URL link to solution page | [optional] [default to null] |
| **tags** | **List** | The list of tags | [optional] [default to null] |

Expand Down
2 changes: 0 additions & 2 deletions openapi/plantuml/schemas.plantuml
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ entity SolutionCreateRequest {
parameters: List<RunTemplateParameter>
parameterGroups: List<RunTemplateParameterGroup>
runTemplates: List<RunTemplate>
sdkVersion: String
url: String
security: SolutionSecurity
}
Expand All @@ -492,7 +491,6 @@ entity SolutionUpdateRequest {
alwaysPull: Boolean
csmSimulator: String
version: String
sdkVersion: String
url: String
tags: List<String>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.cosmotech.runner.service

import com.cosmotech.api.config.CsmPlatformProperties
import com.cosmotech.api.containerregistry.ContainerRegistryService
import com.cosmotech.api.events.CsmEventPublisher
import com.cosmotech.api.events.HasRunningRuns
import com.cosmotech.api.events.RunStart
Expand Down Expand Up @@ -53,6 +54,7 @@ import com.redis.om.spring.RediSearchIndexer
import com.redis.testcontainers.RedisStackContainer
import io.mockk.every
import io.mockk.junit5.MockKExtension
import io.mockk.mockk
import io.mockk.mockkStatic
import java.time.Instant
import java.util.*
Expand Down Expand Up @@ -105,6 +107,8 @@ class RunnerServiceIntegrationTest : CsmRedisTestBase() {
@Autowired lateinit var runnerApiService: RunnerApiServiceInterface
@Autowired lateinit var csmPlatformProperties: CsmPlatformProperties

private var containerRegistryService: ContainerRegistryService = mockk(relaxed = true)

lateinit var connector: Connector
lateinit var dataset: Dataset
lateinit var solution: SolutionCreateRequest
Expand Down Expand Up @@ -142,6 +146,9 @@ class RunnerServiceIntegrationTest : CsmRedisTestBase() {
jedis = UnifiedJedis(HostAndPort(containerIp, Protocol.DEFAULT_PORT))

ReflectionTestUtils.setField(datasetApiService, "unifiedJedis", jedis)
ReflectionTestUtils.setField(
solutionApiService, "containerRegistryService", containerRegistryService)
every { containerRegistryService.getImageLabel(any(), any(), any()) } returns null
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.cosmotech.runner.service

import com.cosmotech.api.config.CsmPlatformProperties
import com.cosmotech.api.containerregistry.ContainerRegistryService
import com.cosmotech.api.exceptions.CsmAccessForbiddenException
import com.cosmotech.api.rbac.PERMISSION_CREATE_CHILDREN
import com.cosmotech.api.rbac.PERMISSION_DELETE
Expand Down Expand Up @@ -108,6 +109,8 @@ class RunnerServiceRBACTest : CsmRedisTestBase() {
@Autowired lateinit var runnerApiService: RunnerApiService
@Autowired lateinit var csmPlatformProperties: CsmPlatformProperties

private var containerRegistryService: ContainerRegistryService = mockk(relaxed = true)

lateinit var jedis: UnifiedJedis

@BeforeEach
Expand All @@ -128,6 +131,9 @@ class RunnerServiceRBACTest : CsmRedisTestBase() {
(context.server as RedisStackContainer).containerInfo.networkSettings.ipAddress
jedis = UnifiedJedis(HostAndPort(containerIp, Protocol.DEFAULT_PORT))
ReflectionTestUtils.setField(datasetApiService, "unifiedJedis", jedis)
ReflectionTestUtils.setField(
solutionApiService, "containerRegistryService", containerRegistryService)
every { containerRegistryService.getImageLabel(any(), any(), any()) } returns null
}

@TestFactory
Expand Down
Loading
Loading