Repository: kurtosis-tech/kurtosis
Pull request #1253 (2023-09-07 08:43:30)

refactor: Refactor Starlark Value serde to avoid import cycles
## Description:
<!-- Describe this change, how it works, and the motivation behind it. -->

## Is this change user facing?
NO
<!-- If yes, please add the "user facing" label to the PR -->
<!-- If yes, don't forget to include docs changes where relevant -->

## References (if applicable):
<!-- Add relevant Github Issues, Discord threads, or other helpful information. -->



Patch:
diff --git a/core/server/api_container/main.go b/core/server/api_container/main.go
index da5560488..fc26f6ad5 100644
--- a/core/server/api_container/main.go
+++ b/core/server/api_container/main.go
@@ -20,11 +20,13 @@ import (
 	"github.com/kurtosis-tech/kurtosis/core/server/api_container/server"
 	"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/service_network"
 	"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine"
+	"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_types"
 	"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/runtime_value_store"
 	"github.com/kurtosis-tech/kurtosis/core/server/commons/enclave_data_directory"
 	minimal_grpc_server "github.com/kurtosis-tech/minimal-grpc-server/golang/server"
 	"github.com/kurtosis-tech/stacktrace"
 	"github.com/sirupsen/logrus"
+	"go.starlark.net/starlark"
 	"google.golang.org/grpc"
 	"net"
 	"os"
@@ -162,7 +164,8 @@ func runMain() error {
 		return stacktrace.Propagate(err, "An error occurred creating the service network")
 	}
 
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	starlarkValueSerde := createStarlarkValueSerde()
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(starlarkValueSerde, enclaveDb)
 	if err != nil {
 		return stacktrace.Propagate(err, "An error occurred creating the runtime value store")
 	}
@@ -233,6 +236,22 @@ func createServiceNetwork(
 	return serviceNetwork, nil
 }
 
+func createStarlarkValueSerde() *kurtosis_types.StarlarkValueSerde {
+	starlarkThread := &starlark.Thread{
+		Name:       "starlark-serde-thread",
+		Print:      nil,
+		Load:       nil,
+		OnMaxSteps: nil,
+		Steps:      0,
+	}
+	starlarkEnv := startosis_engine.Predeclared()
+	builtins := startosis_engine.KurtosisTypeConstructors()
+	for _, builtin := range builtins {
+		starlarkEnv[builtin.Name()] = builtin
+	}
+	return kurtosis_types.NewStarlarkValueSerde(starlarkThread, starlarkEnv)
+}
+
 func formatFilenameFunctionForLogs(filename string, functionName string) string {
 	var output strings.Builder
 	output.WriteString("[")
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_types/starlark_value_serde.go b/core/server/api_container/server/startosis_engine/kurtosis_types/starlark_value_serde.go
new file mode 100644
index 000000000..400b1a263
--- /dev/null
+++ b/core/server/api_container/server/startosis_engine/kurtosis_types/starlark_value_serde.go
@@ -0,0 +1,30 @@
+package kurtosis_types
+
+import (
+	"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_errors"
+	"go.starlark.net/starlark"
+)
+
+type StarlarkValueSerde struct {
+	thread      *starlark.Thread
+	starlarkEnv starlark.StringDict
+}
+
+func NewStarlarkValueSerde(thread *starlark.Thread, starlarkEnv starlark.StringDict) *StarlarkValueSerde {
+	return &StarlarkValueSerde{
+		thread:      thread,
+		starlarkEnv: starlarkEnv,
+	}
+}
+
+func (serde *StarlarkValueSerde) Serialize(val starlark.Value) string {
+	return val.String()
+}
+
+func (serde *StarlarkValueSerde) Deserialize(serializedStarlarkValue string) (starlark.Value, *startosis_errors.InterpretationError) {
+	val, err := starlark.Eval(serde.thread, "", serializedStarlarkValue, serde.starlarkEnv)
+	if err != nil {
+		return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to deserialize starlark value '%s'", serializedStarlarkValue)
+	}
+	return val, nil
+}
diff --git a/core/server/api_container/server/startosis_engine/runtime_value_store/runtime_value_store.go b/core/server/api_container/server/startosis_engine/runtime_value_store/runtime_value_store.go
index 63de7ca0b..ab4139ce9 100644
--- a/core/server/api_container/server/startosis_engine/runtime_value_store/runtime_value_store.go
+++ b/core/server/api_container/server/startosis_engine/runtime_value_store/runtime_value_store.go
@@ -4,16 +4,18 @@ import (
 	"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service"
 	"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/database_accessors/enclave_db"
 	"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/uuid_generator"
+	"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_types"
 	"github.com/kurtosis-tech/stacktrace"
 	"go.starlark.net/starlark"
 )
 
 type RuntimeValueStore struct {
+	starlarkValueSerde                *kurtosis_types.StarlarkValueSerde
 	recipeResultRepository            *recipeResultRepository
 	serviceAssociatedValuesRepository *serviceAssociatedValuesRepository
 }
 
-func CreateRuntimeValueStore(enclaveDb *enclave_db.EnclaveDB) (*RuntimeValueStore, error) {
+func CreateRuntimeValueStore(starlarkValueSerde *kurtosis_types.StarlarkValueSerde, enclaveDb *enclave_db.EnclaveDB) (*RuntimeValueStore, error) {
 	associatedValuesRepository, err := getOrCreateNewServiceAssociatedValuesRepository(enclaveDb)
 	if err != nil {
 		return nil, stacktrace.Propagate(err, "An error occurred getting or creating the service associated values repository")
@@ -25,6 +27,7 @@ func CreateRuntimeValueStore(enclaveDb *enclave_db.EnclaveDB) (*RuntimeValueStor
 	}
 
 	runtimeValueStore := &RuntimeValueStore{
+		starlarkValueSerde:                starlarkValueSerde,
 		recipeResultRepository:            recipeResultRepositoryObj,
 		serviceAssociatedValuesRepository: associatedValuesRepository,
 	}
diff --git a/core/server/api_container/server/startosis_engine/starlark_value_serde.go b/core/server/api_container/server/startosis_engine/starlark_value_serde.go
deleted file mode 100644
index 0d40c79c9..000000000
--- a/core/server/api_container/server/startosis_engine/starlark_value_serde.go
+++ /dev/null
@@ -1,45 +0,0 @@
-package startosis_engine
-
-import (
-	"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_errors"
-	"go.starlark.net/starlark"
-)
-
-const (
-	starlarkThreadName = "starlark-deserializer-thread"
-)
-
-var (
-	cachedStarlarkThread *starlark.Thread
-
-	cachedStarlarkEnv starlark.StringDict
-)
-
-func SerializeStarlarkValue(val starlark.Value) string {
-	return val.String()
-}
-
-func DeserializeStarlarkValue(serializedStarlarkValue string) (starlark.Value, *startosis_errors.InterpretationError) {
-	if cachedStarlarkThread == nil {
-		cachedStarlarkThread = &starlark.Thread{
-			Name:       starlarkThreadName,
-			Print:      nil,
-			Load:       nil,
-			OnMaxSteps: nil,
-			Steps:      0,
-		}
-	}
-	if cachedStarlarkEnv == nil {
-		cachedStarlarkEnv = Predeclared()
-		builtins := KurtosisTypeConstructors()
-		for _, builtin := range builtins {
-			cachedStarlarkEnv[builtin.Name()] = builtin
-		}
-	}
-
-	val, err := starlark.Eval(cachedStarlarkThread, "", serializedStarlarkValue, cachedStarlarkEnv)
-	if err != nil {
-		return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to deserialize starlark value '%s'", serializedStarlarkValue)
-	}
-	return val, nil
-}


Test patch:
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared_test.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared_test.go
index db696d12b..6ba79c145 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/add_service/add_service_shared_test.go
@@ -19,7 +19,7 @@ const (
 
 func TestAddServiceShared_EntryPointArgsRuntimeValueAreReplaced(t *testing.T) {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	stringValueUuid, err := runtimeValueStore.CreateValue()
@@ -56,7 +56,7 @@ func TestAddServiceShared_EntryPointArgsRuntimeValueAreReplaced(t *testing.T) {
 
 func TestAddServiceShared_CmdArgsRuntimeValueAreReplaced(t *testing.T) {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 	stringValueUuid, err := runtimeValueStore.CreateValue()
 	require.Nil(t, err, "error creating a runtime value UUID")
@@ -92,7 +92,7 @@ func TestAddServiceShared_CmdArgsRuntimeValueAreReplaced(t *testing.T) {
 
 func TestAddServiceShared_EnvVarsWithRuntimeValueAreReplaced(t *testing.T) {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 	stringValueUuid, err := runtimeValueStore.CreateValue()
 	require.Nil(t, err, "error creating a runtime value UUID")
@@ -133,7 +133,7 @@ func TestAddServiceShared_EnvVarsWithRuntimeValueAreReplaced(t *testing.T) {
 
 func TestAddServiceShared_ServiceNameWithRuntimeValuesAreReplaced(t *testing.T) {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 	stringValueUuid, err := runtimeValueStore.CreateValue()
 	require.Nil(t, err, "error creating a runtime value UUID")
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/shared_helpers/magic_string_helper/magic_string_helper_test.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/shared_helpers/magic_string_helper/magic_string_helper_test.go
index 9f075c093..d0cba38af 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/shared_helpers/magic_string_helper/magic_string_helper_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/shared_helpers/magic_string_helper/magic_string_helper_test.go
@@ -21,7 +21,7 @@ var testIntRuntimeValue = starlark.MakeInt(0)
 
 func TestGetOrReplaceRuntimeValueFromString_BasicFetch(t *testing.T) {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 	stringValueUuid, err := runtimeValueStore.CreateValue()
 	require.Nil(t, err)
@@ -41,7 +41,7 @@ func TestGetOrReplaceRuntimeValueFromString_BasicFetch(t *testing.T) {
 
 func TestGetOrReplaceRuntimeValueFromString_Interpolated(t *testing.T) {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 	stringValueUuid, err := runtimeValueStore.CreateValue()
 	require.Nil(t, err)
@@ -61,7 +61,7 @@ func TestGetOrReplaceRuntimeValueFromString_Interpolated(t *testing.T) {
 
 func TestReplaceRuntimeValueFromString(t *testing.T) {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 	stringValueUuid, err := runtimeValueStore.CreateValue()
 	require.Nil(t, err)
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go
index 70ec8d98a..2bf2a7f30 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go
@@ -38,7 +38,7 @@ func (t *addServiceTestCase) GetId() string {
 func (t *addServiceTestCase) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork.EXPECT().ExistServiceRegistration(TestServiceName).Times(1).Return(false, nil)
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go
index ab98a87da..b5f833a74 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go
@@ -38,7 +38,7 @@ func (t *addServicesTestCase) GetId() string {
 func (t *addServicesTestCase) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork.EXPECT().ExistServiceRegistration(TestServiceName).Times(1).Return(false, nil)
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/assert_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/assert_framework_test.go
index 819550a2e..ddbe4592e 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/assert_framework_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/assert_framework_test.go
@@ -36,7 +36,7 @@ func (t assertTestCase) GetId() string {
 
 func (t assertTestCase) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 	err = runtimeValueStore.SetValue(t.runtimeValueUuid, map[string]starlark.Comparable{
 		"value": starlark.String(runtimeValueValue),
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_framework_test_case_1_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_framework_test_case_1_test.go
index 0a70df0cb..ed5d4676b 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_framework_test_case_1_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_framework_test_case_1_test.go
@@ -35,7 +35,7 @@ func (t execTestCase1) GetId() string {
 func (t execTestCase1) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork.EXPECT().RunExec(
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_framework_test_case_2_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_framework_test_case_2_test.go
index fd04bb2df..d32124f77 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_framework_test_case_2_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_framework_test_case_2_test.go
@@ -31,7 +31,7 @@ func (t execTestCase2) GetId() string {
 func (t execTestCase2) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork.EXPECT().RunExec(
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_recipe_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_recipe_framework_test.go
index 195a2035f..20eec9d30 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_recipe_framework_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_recipe_framework_test.go
@@ -22,7 +22,7 @@ type execRecipeTestCase struct {
 
 func newExecRecipeTestCase(t *testing.T) *execRecipeTestCase {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
 	serviceNetwork.EXPECT().RunExec(
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_no_extractor_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_no_extractor_test.go
index ff8948545..f14b88b26 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_no_extractor_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_no_extractor_test.go
@@ -23,7 +23,7 @@ type getHttpRequestRecipeNoExtractorTestCase struct {
 
 func newGetHttpRequestRecipeNoExtractorTestCase(t *testing.T) *getHttpRequestRecipeNoExtractorTestCase {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_test.go
index cba9784a0..d161d5e92 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_test.go
@@ -27,7 +27,7 @@ type getHttpRequestRecipeTestCase struct {
 
 func newGetHttpRequestRecipeTestCase(t *testing.T) *getHttpRequestRecipeTestCase {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/kurtosis_print_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/kurtosis_print_framework_test.go
index 49107afcd..6f3b83be2 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/kurtosis_print_framework_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/kurtosis_print_framework_test.go
@@ -32,7 +32,7 @@ func (t *printTestCase) GetId() string {
 func (t *printTestCase) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	return kurtosis_print.NewPrint(serviceNetwork, runtimeValueStore)
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_minimal_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_minimal_test.go
index e856d3558..d8083bb95 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_minimal_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_minimal_test.go
@@ -23,7 +23,7 @@ type postHttpRequestRecipeMinimalTestCase struct {
 
 func newPostHttpRequestRecipeMinimalTestCase(t *testing.T) *postHttpRequestRecipeMinimalTestCase {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_test.go
index 47d5c6fa1..cacb8290f 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_test.go
@@ -27,7 +27,7 @@ type postHttpRequestRecipeTestCase struct {
 
 func newPostHttpRequestRecipeTestCase(t *testing.T) *postHttpRequestRecipeTestCase {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_multiple_templates_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_multiple_templates_framework_test.go
index e0e8665e3..ee21543eb 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_multiple_templates_framework_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_multiple_templates_framework_test.go
@@ -62,7 +62,7 @@ func (t renderMultipleTemplatesTestCase) GetId() string {
 
 func (t renderMultipleTemplatesTestCase) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	return render_templates.NewRenderTemplatesInstruction(t.serviceNetwork, runtimeValueStore)
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_single_templates_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_single_templates_framework_test.go
index e3f5ebcb5..0303e0f94 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_single_templates_framework_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_single_templates_framework_test.go
@@ -47,7 +47,7 @@ func (t renderSingleTemplateTestCase) GetId() string {
 
 func (t renderSingleTemplateTestCase) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 	return render_templates.NewRenderTemplatesInstruction(t.serviceNetwork, runtimeValueStore)
 }
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/request_framework_test_case_1_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/request_framework_test_case_1_test.go
index f8344e78d..8ad3f7266 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/request_framework_test_case_1_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/request_framework_test_case_1_test.go
@@ -44,7 +44,7 @@ func (t *requestTestCase1) GetId() string {
 func (t *requestTestCase1) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork.EXPECT().HttpRequestService(
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/request_framework_test_case_2_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/request_framework_test_case_2_test.go
index a66ddf713..adf9d831f 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/request_framework_test_case_2_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/request_framework_test_case_2_test.go
@@ -33,7 +33,7 @@ func (t *requestTestCase2) GetId() string {
 func (t *requestTestCase2) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork.EXPECT().HttpRequestService(
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/wait_framework_test_case_1_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/wait_framework_test_case_1_test.go
index 1e288fb98..6104973a6 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/wait_framework_test_case_1_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/wait_framework_test_case_1_test.go
@@ -50,7 +50,7 @@ func (t *waitTestCase1) GetId() string {
 func (t *waitTestCase1) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork.EXPECT().HttpRequestService(
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/wait_framework_test_case_2_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/wait_framework_test_case_2_test.go
index 40aa8b7d0..8b7fb2003 100644
--- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/wait_framework_test_case_2_test.go
+++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/wait_framework_test_case_2_test.go
@@ -34,7 +34,7 @@ func (t *waitTestCase2) GetId() string {
 func (t *waitTestCase2) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction {
 	serviceNetwork := service_network.NewMockServiceNetwork(t)
 	enclaveDb := getEnclaveDBForTest(t.T)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	serviceNetwork.EXPECT().HttpRequestService(
diff --git a/core/server/api_container/server/startosis_engine/kurtosis_types/starlark_value_serde_test.go b/core/server/api_container/server/startosis_engine/kurtosis_types/starlark_value_serde_test.go
new file mode 100644
index 000000000..076aa0514
--- /dev/null
+++ b/core/server/api_container/server/startosis_engine/kurtosis_types/starlark_value_serde_test.go
@@ -0,0 +1,104 @@
+package kurtosis_types
+
+import (
+	port_spec_core "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec"
+	"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_types/port_spec"
+	"github.com/stretchr/testify/require"
+	"github.com/stretchr/testify/suite"
+	"go.starlark.net/starlark"
+	"go.starlark.net/starlarkstruct"
+	"testing"
+)
+
+type StarlarkValueSerdeSuite struct {
+	suite.Suite
+
+	serde *StarlarkValueSerde
+}
+
+func TestRunStarlarkValueSerdeSuite(t *testing.T) {
+	suite.Run(t, new(StarlarkValueSerdeSuite))
+}
+
+func (suite *StarlarkValueSerdeSuite) SetupTest() {
+	thread := &starlark.Thread{
+		Name:       "test-serde-thread",
+		Print:      nil,
+		Load:       nil,
+		OnMaxSteps: nil,
+		Steps:      0,
+	}
+	starlarkEnv := starlark.StringDict{
+		starlarkstruct.Default.GoString(): starlark.NewBuiltin(starlarkstruct.Default.GoString(), starlarkstruct.Make),
+
+		ServiceTypeName:            starlark.NewBuiltin(ServiceTypeName, NewServiceType().CreateBuiltin()),
+		port_spec.PortSpecTypeName: starlark.NewBuiltin(port_spec.PortSpecTypeName, port_spec.NewPortSpecType().CreateBuiltin()),
+	}
+	suite.serde = NewStarlarkValueSerde(thread, starlarkEnv)
+}
+
+func (suite *StarlarkValueSerdeSuite) TestStarlarkValueSerde_Integer() {
+	val := starlark.MakeInt(42)
+
+	serializedStarlarkValue := suite.serde.Serialize(val)
+	require.Equal(suite.T(), "42", serializedStarlarkValue)
+
+	deserializedStarlarkValue, interpretationErr := suite.serde.Deserialize(serializedStarlarkValue)
+	require.Nil(suite.T(), interpretationErr)
+	require.Equal(suite.T(), val, deserializedStarlarkValue)
+}
+
+func (suite *StarlarkValueSerdeSuite) TestStarlarkValueSerde_String() {
+	val := starlark.String("Hello world")
+
+	serializedStarlarkValue := suite.serde.Serialize(val)
+	require.Equal(suite.T(), `"Hello world"`, serializedStarlarkValue)
+
+	deserializedStarlarkValue, interpretationErr := suite.serde.Deserialize(serializedStarlarkValue)
+	require.Nil(suite.T(), interpretationErr)
+	require.Equal(suite.T(), val, deserializedStarlarkValue)
+}
+
+func (suite *StarlarkValueSerdeSuite) TestStarlarkValueSerde_Dict() {
+	val := starlark.NewDict(3)
+	require.NoError(suite.T(), val.SetKey(starlark.String("hello"), starlark.String("world")))
+	require.NoError(suite.T(), val.SetKey(starlark.String("answer"), starlark.MakeInt(42)))
+	require.NoError(suite.T(), val.SetKey(starlark.String("nested"), starlarkstruct.FromStringDict(starlarkstruct.Default, starlark.StringDict{
+		"blah": starlark.String("blah"),
+	})))
+
+	serializedStarlarkValue := suite.serde.Serialize(val)
+	require.Equal(suite.T(), `{"hello": "world", "answer": 42, "nested": struct(blah = "blah")}`, serializedStarlarkValue)
+
+	deserializedStarlarkValue, interpretationErr := suite.serde.Deserialize(serializedStarlarkValue)
+	require.Nil(suite.T(), interpretationErr)
+	require.Equal(suite.T(), val, deserializedStarlarkValue)
+}
+
+func (suite *StarlarkValueSerdeSuite) TestStarlarkValueSerde_Service() {
+	port, interpretationErr := port_spec.CreatePortSpec(
+		uint16(443),
+		port_spec_core.TransportProtocol_TCP,
+		nil,
+		"10s",
+	)
+	require.Nil(suite.T(), interpretationErr)
+	ports := starlark.NewDict(1)
+	require.NoError(suite.T(), ports.SetKey(starlark.String("http"), port))
+
+	serviceObj, interpretationErr := CreateService(
+		"test-service",
+		"test-service-hostname",
+		"192.168.0.22",
+		ports,
+	)
+	require.Nil(suite.T(), interpretationErr)
+
+	serializedStarlarkValue := suite.serde.Serialize(serviceObj)
+	expectedSerializedServiceObj := `Service(name="test-service", hostname="test-service-hostname", ip_address="192.168.0.22", ports={"http": PortSpec(number=443, transport_protocol="TCP", wait="10s")})`
+	require.Equal(suite.T(), expectedSerializedServiceObj, serializedStarlarkValue)
+
+	deserializedStarlarkValue, interpretationErr := suite.serde.Deserialize(serializedStarlarkValue)
+	require.Nil(suite.T(), interpretationErr)
+	require.Equal(suite.T(), serviceObj.String(), deserializedStarlarkValue.String())
+}
diff --git a/core/server/api_container/server/startosis_engine/starlark_value_serde_test.go b/core/server/api_container/server/startosis_engine/starlark_value_serde_test.go
deleted file mode 100644
index f02d1121a..000000000
--- a/core/server/api_container/server/startosis_engine/starlark_value_serde_test.go
+++ /dev/null
@@ -1,77 +0,0 @@
-package startosis_engine
-
-import (
-	"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/port_spec"
-	"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_types"
-	port_spec2 "github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_types/port_spec"
-	"github.com/stretchr/testify/require"
-	"go.starlark.net/starlark"
-	"go.starlark.net/starlarkstruct"
-	"testing"
-)
-
-func TestStarlarkValueSerde_Integer(t *testing.T) {
-	val := starlark.MakeInt(42)
-
-	serializedStarlarkValue := SerializeStarlarkValue(val)
-	require.Equal(t, "42", serializedStarlarkValue)
-
-	deserializedStarlarkValue, interpretationErr := DeserializeStarlarkValue(serializedStarlarkValue)
-	require.Nil(t, interpretationErr)
-	require.Equal(t, val, deserializedStarlarkValue)
-}
-
-func TestStarlarkValueSerde_String(t *testing.T) {
-	val := starlark.String("Hello world")
-
-	serializedStarlarkValue := SerializeStarlarkValue(val)
-	require.Equal(t, `"Hello world"`, serializedStarlarkValue)
-
-	deserializedStarlarkValue, interpretationErr := DeserializeStarlarkValue(serializedStarlarkValue)
-	require.Nil(t, interpretationErr)
-	require.Equal(t, val, deserializedStarlarkValue)
-}
-
-func TestStarlarkValueSerde_Dict(t *testing.T) {
-	val := starlark.NewDict(3)
-	require.NoError(t, val.SetKey(starlark.String("hello"), starlark.String("world")))
-	require.NoError(t, val.SetKey(starlark.String("answer"), starlark.MakeInt(42)))
-	require.NoError(t, val.SetKey(starlark.String("nested"), starlarkstruct.FromStringDict(starlarkstruct.Default, starlark.StringDict{
-		"blah": starlark.String("blah"),
-	})))
-
-	serializedStarlarkValue := SerializeStarlarkValue(val)
-	require.Equal(t, `{"hello": "world", "answer": 42, "nested": struct(blah = "blah")}`, serializedStarlarkValue)
-
-	deserializedStarlarkValue, interpretationErr := DeserializeStarlarkValue(serializedStarlarkValue)
-	require.Nil(t, interpretationErr)
-	require.Equal(t, val, deserializedStarlarkValue)
-}
-
-func TestStarlarkValueSerde_Service(t *testing.T) {
-	port, interpretationErr := port_spec2.CreatePortSpec(
-		uint16(443),
-		port_spec.TransportProtocol_TCP,
-		nil,
-		"10s",
-	)
-	require.Nil(t, interpretationErr)
-	ports := starlark.NewDict(1)
-	require.NoError(t, ports.SetKey(starlark.String("http"), port))
-
-	serviceObj, interpretationErr := kurtosis_types.CreateService(
-		"test-service",
-		"test-service-hostname",
-		"192.168.0.22",
-		ports,
-	)
-	require.Nil(t, interpretationErr)
-
-	serializedStarlarkValue := SerializeStarlarkValue(serviceObj)
-	expectedSerializedServiceObj := `Service(name="test-service", hostname="test-service-hostname", ip_address="192.168.0.22", ports={"http": PortSpec(number=443, transport_protocol="TCP", wait="10s")})`
-	require.Equal(t, expectedSerializedServiceObj, serializedStarlarkValue)
-
-	deserializedStarlarkValue, interpretationErr := DeserializeStarlarkValue(serializedStarlarkValue)
-	require.Nil(t, interpretationErr)
-	require.Equal(t, serviceObj.String(), deserializedStarlarkValue.String())
-}
diff --git a/core/server/api_container/server/startosis_engine/startosis_executor_test.go b/core/server/api_container/server/startosis_engine/startosis_executor_test.go
index db67631ff..af0e0bcc0 100644
--- a/core/server/api_container/server/startosis_engine/startosis_executor_test.go
+++ b/core/server/api_container/server/startosis_engine/startosis_executor_test.go
@@ -38,7 +38,7 @@ var (
 
 func TestExecuteKurtosisInstructions_ExecuteForReal_Success(t *testing.T) {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, createRuntimeValueStoreErr := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, createRuntimeValueStoreErr := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, createRuntimeValueStoreErr)
 
 	executor := NewStartosisExecutor(runtimeValueStore)
@@ -79,7 +79,7 @@ func TestExecuteKurtosisInstructions_ExecuteForReal_Success(t *testing.T) {
 
 func TestExecuteKurtosisInstructions_ExecuteForReal_FailureHalfWay(t *testing.T) {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, err)
 
 	executor := NewStartosisExecutor(runtimeValueStore)
@@ -121,7 +121,7 @@ instruction2()
 
 func TestExecuteKurtosisInstructions_DoDryRun(t *testing.T) {
 	enclaveDb := getEnclaveDBForTest(t)
-	runtimeValueStore, createRuntimeValueStoreErr := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, createRuntimeValueStoreErr := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(t, createRuntimeValueStoreErr)
 
 	executor := NewStartosisExecutor(runtimeValueStore)
diff --git a/core/server/api_container/server/startosis_engine/startosis_interpreter_idempotent_test.go b/core/server/api_container/server/startosis_engine/startosis_interpreter_idempotent_test.go
index a148dd24a..b2d235dc2 100644
--- a/core/server/api_container/server/startosis_engine/startosis_interpreter_idempotent_test.go
+++ b/core/server/api_container/server/startosis_engine/startosis_interpreter_idempotent_test.go
@@ -30,7 +30,7 @@ type StartosisInterpreterIdempotentTestSuite struct {
 func (suite *StartosisInterpreterIdempotentTestSuite) SetupTest() {
 	suite.packageContentProvider = mock_package_content_provider.NewMockPackageContentProvider()
 	enclaveDb := getEnclaveDBForTest(suite.T())
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(suite.T(), err)
 
 	serviceNetwork := service_network.NewMockServiceNetwork(suite.T())
diff --git a/core/server/api_container/server/startosis_engine/startosis_interpreter_test.go b/core/server/api_container/server/startosis_engine/startosis_interpreter_test.go
index 8e8ab3ff6..1e2f84645 100644
--- a/core/server/api_container/server/startosis_engine/startosis_interpreter_test.go
+++ b/core/server/api_container/server/startosis_engine/startosis_interpreter_test.go
@@ -62,7 +62,7 @@ type StartosisInterpreterTestSuite struct {
 func (suite *StartosisInterpreterTestSuite) SetupTest() {
 	suite.packageContentProvider = mock_package_content_provider.NewMockPackageContentProvider()
 	enclaveDb := getEnclaveDBForTest(suite.T())
-	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(enclaveDb)
+	runtimeValueStore, err := runtime_value_store.CreateRuntimeValueStore(nil, enclaveDb)
 	require.NoError(suite.T(), err)
 	suite.runtimeValueStore = runtimeValueStore
 	suite.serviceNetwork = service_network.NewMockServiceNetwork(suite.T())