Expand ${VAR} in step env: blocks across all step types (follow-up to #12)#75
Open
hishamMounir wants to merge 1 commit into
Open
Expand ${VAR} in step env: blocks across all step types (follow-up to #12)#75hishamMounir wants to merge 1 commit into
hishamMounir wants to merge 1 commit into
Conversation
3ec0d7b to
d57f734
Compare
…evicelab-dev#12) devicelab-dev#12 fixed the missing ExpandVariables call for `appId`, and the v1.0.7 follow-up extended it to flow Config.Env, withEnvVars (used by runFlow), and LaunchAppStep.Environment. The same class of bug remained for every step type that has a YAML `env:` block but didn't route through one of those expansion sites: - runScript: ExecuteRunScript called SetVariable(k, v) directly. - runBrowserScript / runWebViewScript: the driver layer JSON-encoded step.Env into window.__env without expansion. - runFlow / retry: Env was expanded by withEnvVars at execute time but the canonical pre-execution mutator (ExpandStep) had only one of the two paths covered, so step.Env values stayed unexpanded for any downstream code that read them off the step struct. Repro from the runScript path: - runScript: file: seed.js env: BASE_URL: ${BASE_URL} with `-e BASE_URL=https://api.example.com` left the script variable as the literal string "${BASE_URL}", surfacing as a fmt-mangled error from Go's url package when the JS later constructed a URL and called http.post: Post "$%!B(MISSING)BASE_URL%!D(MISSING)/api/...": unsupported protocol scheme "" Fix --- Centralize env-map expansion in pkg/executor/scripting.go: expandEnvMap(env) — single helper that walks a map[string]string and applies ExpandVariables to every value in place. No-op for values without ${...}, so plain literals pass through untouched. ExpandStep is now the canonical place that expansion happens for every step type with an Env field: - LaunchAppStep.Environment — replaced inline loop with helper. - RunFlowStep.Env — replaced inline loop with helper. - RunScriptStep.Env — new case. - RunBrowserScriptStep.Env — new case. - RunWebViewScriptStep.Env — new case. - RetryStep.Env — new case (defensive; withEnvVars also expands at execute time, which is now idempotent against pre-expansion). - DefineVariablesStep.Env — new case (same idempotency rationale). flow_runner.go now calls fr.script.ExpandStep(step) before ExecuteRunScript / ExecuteDefineVariables, mirroring the pattern already used for LaunchAppStep, RunFlowStep, RunBrowserScriptStep, and RunWebViewScriptStep. ExecuteRunScript's inline ExpandVariables call is kept as a safety net for callers that bypass the dispatcher (tests, future internal APIs); it's a no-op once values are pre-expanded. Tests ----- - TestScriptEngine_RunScript_EnvExpandsVariableRefs — covers the direct RunScript path (the original repro from this report). - TestScriptEngine_ExpandStep_RunScriptStep_Env — covers the dispatch path including a literal value to confirm non-${} keys are untouched. - TestScriptEngine_ExpandStep_RunBrowserScriptStep_Env - TestScriptEngine_ExpandStep_RunWebViewScriptStep_Env All pkg/executor tests pass (go test ./pkg/executor/ -count=1).
d57f734 to
cb517d4
Compare
Contributor
|
@hishamMounir Nice fix — the NotesThe matching // Expand variables in step before execution
fr.script.ExpandStep(step)
// Execute step - route to appropriate handler
var result *core.CommandResult
switch s := step.(type) {
case *flow.DefineVariablesStep:
fr.script.ExpandStep(step) // redundant, ExpandStep ran 7 lines up
result = fr.script.ExecuteDefineVariables(s)
case *flow.RunScriptStep:
fr.script.ExpandStep(step) // redundant, same reason
result = fr.script.ExecuteRunScript(s)Idempotent so harmless — can be cleaned up in a follow-up, or left as-is. The additions in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#12 fixed the missing
ExpandVariablescall forappId. The v1.0.7 follow-up extended it to flowConfig.Env,withEnvVars(used byrunFlow), andLaunchAppStep.Environment. The same class of bug remained for every step type that has a YAMLenv:block but didn't route through one of those expansion sites:runScript—ExecuteRunScriptcalledSetVariable(k, v)directly.runBrowserScript/runWebViewScript— the driver layer JSON-encodedstep.Envintowindow.__envwithout expansion.runFlow/retry—Envwas expanded bywithEnvVarsat execute time but the canonical pre-execution mutator (ExpandStep) had only one of the two paths covered, sostep.Envvalues stayed unexpanded for any downstream code that read them off the step struct.Repro from the
runScriptpath:with
-e BASE_URL=https://api.example.comleft the script variable as the literal string${BASE_URL}. Insideseed.jsthe script then constructed a URL from the unexpanded placeholder and passed it tohttp.post, surfacing as a fmt-mangled error from Go's url package:Fix
Centralize env-map expansion in
pkg/executor/scripting.go:ExpandStepis now the canonical place expansion happens for every step type with anEnvfield:LaunchAppStepfor k, v := rangeexpandEnvMap(refactor)RunFlowStepfor k, v := rangeexpandEnvMap(refactor)RunScriptStepexpandEnvMapRunBrowserScriptStepexpandEnvMapRunWebViewScriptStepexpandEnvMapRetryStepexpandEnvMap(defensive)DefineVariablesStepexpandEnvMap(defensive)flow_runner.gonow callsfr.script.ExpandStep(step)beforeExecuteRunScript/ExecuteDefineVariables, mirroring the pattern already used forLaunchAppStep,RunFlowStep,RunBrowserScriptStep, andRunWebViewScriptStep.ExecuteRunScript's inlineExpandVariablescall is kept as a safety net for callers that bypass the dispatcher (tests, future internal APIs); it's a no-op once values are pre-expanded.Tests
TestScriptEngine_RunScript_EnvExpandsVariableRefs— directRunScriptpath (original repro).TestScriptEngine_ExpandStep_RunScriptStep_Env— dispatch path; includes a literal value to confirm non-${}keys are untouched.TestScriptEngine_ExpandStep_RunBrowserScriptStep_EnvTestScriptEngine_ExpandStep_RunWebViewScriptStep_EnvTest plan
go test ./pkg/executor/ -count=1— passesgo build ./...— cleanrunScriptenv block uses${BASE_URL}and the script now receives the substituted value (previously: literal${BASE_URL}reachinghttp.post).🤖 Generated with Claude Code