Skip to content

Commit 2bba1bc

Browse files
authored
fix: enclave manager passing in deprecated args object (#2342)
## Description The enclave builder would fail to render packages that used `def run(plan, args)` where starlark in the package depended on values in `args` being set. This was because the enclave manager was passing args to interpretation using via an `args`. The use of `args` dict as sole input is deprecated. While it's deprecated we still support it for backwards compatibility but everything in `args` is dropped - which caused the failure. This PR fixes it by unpacking the values in `args` so enclave builder passes them as unpacked `kwargs` to interpretation, as opposed to using the sole deprecated `args` dict. I've also added a test to highlight this behavior. ``` def run(plan, args): all_arg_values = args["arg1"] + ":" + args["arg2"] return all_arg_values ``` will error when passing input with only `args` `{"args": {"arg1": "arg1-value", "arg2": "arg2-value"}}` ## Is this change user facing? NO
1 parent 0dca278 commit 2bba1bc

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

core/server/api_container/server/startosis_engine/startosis_interpreter_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,31 @@ def my_func(my_arg1, my_arg2, args):
160160
require.Equal(suite.T(), expectedResult, result)
161161
}
162162

163+
func (suite *StartosisInterpreterTestSuite) TestStartosisInterpreter_MainFunctionAndParamsErrWhenOnlyDeprecatedArgsObjectProvided() {
164+
script := `
165+
def run(plan, args):
166+
all_arg_values = args["arg1"] + ":" + args["arg2"]
167+
return all_arg_values
168+
`
169+
mainFunctionName := "run"
170+
// passing in only "args" dictionary is deprecated
171+
inputArgs := `{"args": {"arg1": "arg1-value", "arg2": "arg2-value"}}`
172+
173+
_, _, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, mainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, inputArgs, defaultNonBlockingMode, emptyEnclaveComponents, emptyInstructionsPlanMask, defaultImageDownloadMode)
174+
require.NotNil(suite.T(), interpretationError)
175+
require.Equal(suite.T(), "Evaluation error: key \"arg1\" not in dict\n\tat [3:23]: run", interpretationError.GetErrorMessage())
176+
177+
scriptWithKwarg := `
178+
def run(plan, arg0, args):
179+
all_arg_values = arg0 + args["arg1"] + ":" + args["arg2"]
180+
return all_arg_values
181+
`
182+
// however passing in kwargs, with args at the end is still fine
183+
inputArgsWithKwarg := `{"arg0": "foo", "args": {"arg1": "arg1-value", "arg2": "arg2-value"}}`
184+
_, _, interpretationError = suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, mainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, scriptWithKwarg, inputArgsWithKwarg, defaultNonBlockingMode, emptyEnclaveComponents, emptyInstructionsPlanMask, defaultImageDownloadMode)
185+
require.Nil(suite.T(), interpretationError)
186+
}
187+
163188
func (suite *StartosisInterpreterTestSuite) TestStartosisInterpreter_Test() {
164189
script := `
165190
def run(plan):

enclave-manager/web/packages/app/src/emui/enclaves/components/enclaveBuilder/nodes/KurtosisPackageNode.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const KurtosisPackageNode = memo(
2626

2727
useEffect(() => {
2828
const packageId = nodeData?.packageId;
29-
const args = nodeData?.args;
29+
let args = nodeData?.args;
3030
if (isDefined(packageId) && isDefined(args) && packageId !== "") {
3131
let cancelled = false;
3232
(async () => {
@@ -40,6 +40,14 @@ export const KurtosisPackageNode = memo(
4040
setMode({ type: "error", error: "APIC info missing from temporary enclave" });
4141
return;
4242
}
43+
44+
// If args only has one record, and its value is args, ASSUME user is passing args via a JSON or YAML into the args object of def run(plan, args)
45+
// via Json or Yaml editor
46+
// If only an `args` object is provided, kurtosis will not interpret the value in the args object as passing args via the args dictionary is (technically) deprecated even though it's still allowed
47+
if (Object.keys(args).length === 1 && args.hasOwnProperty("args")) {
48+
args = args["args"] as Record<string, string>; // TODO(tedi): ideally we'd validate and handle this in transform args utils
49+
}
50+
4351
const plan = await kurtosisClient.getStarlarkPackagePlanYaml(
4452
enclave.value.enclaveInfo.apiContainerInfo,
4553
packageId,

0 commit comments

Comments
 (0)