diff --git a/internal/miro/record.go b/internal/miro/record.go index 4a0c4be..60df42a 100644 --- a/internal/miro/record.go +++ b/internal/miro/record.go @@ -37,11 +37,16 @@ func Record(path string) (string, error) { return "", err } + setupScripts, err := discoverSetupScripts(testDir, target) + if err != nil { + return "", err + } + if err := recordScenario(target, shellPath, recordIO{ in: os.Stdin, out: os.Stdout, err: os.Stderr, - }, cfg.Sandbox); err != nil { + }, cfg.Sandbox, setupScripts); err != nil { return "", err } diff --git a/internal/miro/record_session.go b/internal/miro/record_session.go index ef2b274..dab90f6 100644 --- a/internal/miro/record_session.go +++ b/internal/miro/record_session.go @@ -17,7 +17,7 @@ type recordIO struct { err io.Writer } -func recordScenario(target, shellPath string, rio recordIO, sandboxConfig map[string]string) error { +func recordScenario(target, shellPath string, rio recordIO, sandboxConfig map[string]string, setupScripts []string) error { rawIn, rawOut, cleanup, err := newRecordFiles() if err != nil { return err @@ -40,7 +40,7 @@ func recordScenario(target, shellPath string, rio recordIO, sandboxConfig map[st output.Fprintln(rio.err, "Run commands in the recorder shell, then type exit to finish.") - if err := runRecordSession(target, rawIn, rawOut, shellPath, sandbox, rio, sandboxConfig); err != nil { + if err := runRecordSession(target, rawIn, rawOut, shellPath, sandbox, rio, sandboxConfig, setupScripts); err != nil { return err } @@ -119,10 +119,10 @@ func newRecordSandboxForPathEnv(pathEnv string) (recordSandbox, func(), error) { return sandbox, cleanup, nil } -func runRecordSession(dir, rawIn, rawOut, shellPath string, sandbox recordSandbox, rio recordIO, sandboxConfig map[string]string) error { +func runRecordSession(dir, rawIn, rawOut, shellPath string, sandbox recordSandbox, rio recordIO, sandboxConfig map[string]string, setupScripts []string) error { cmd := exec.Command("script", "-q", "-E", "always", "-I", rawIn, "-O", rawOut, "-c", shellPath) cmd.Dir = dir - cmd.Env = recordSessionEnv(sandbox, sandboxConfig) + cmd.Env = recordSessionEnv(sandbox, sandboxConfig, setupScripts) cmd.Stdin = rio.in cmd.Stdout = rio.out cmd.Stderr = rio.err diff --git a/internal/miro/record_shell.go b/internal/miro/record_shell.go index 0017572..b0fdf19 100644 --- a/internal/miro/record_shell.go +++ b/internal/miro/record_shell.go @@ -79,16 +79,17 @@ func buildRecordShellScript() string { return string(body) } -func recordSessionEnv(sandbox recordSandbox, sandboxConfig map[string]string) []string { - return recordSessionEnvWithExtra(sandbox, sandboxConfig, nil) +func recordSessionEnv(sandbox recordSandbox, sandboxConfig map[string]string, setupScripts []string) []string { + return recordSessionEnvWithExtra(sandbox, sandboxConfig, setupScripts, nil) } -func recordSessionEnvWithExtra(sandbox recordSandbox, sandboxConfig, extraEnv map[string]string) []string { +func recordSessionEnvWithExtra(sandbox recordSandbox, sandboxConfig map[string]string, setupScripts []string, extraEnv map[string]string) []string { env := append([]string{}, os.Environ()...) env = append(env, "MIRO_HOST_HOME="+sandbox.hostHome, "MIRO_HOST_TMP="+sandbox.hostTmp, "MIRO_PATH_ENV="+sandbox.pathEnv, + setupScriptsEnvName+"="+strings.Join(setupScripts, "\n"), ) for _, key := range sortedKeys(sandboxConfig) { env = append(env, sandboxEnvName(key)+"="+sandboxConfig[key]) diff --git a/internal/miro/record_shell.sh b/internal/miro/record_shell.sh index ee8b994..8a0c3b8 100644 --- a/internal/miro/record_shell.sh +++ b/internal/miro/record_shell.sh @@ -6,6 +6,20 @@ host_home=${MIRO_HOST_HOME:?} host_tmp=${MIRO_HOST_TMP:?} path_env=${MIRO_PATH_ENV:?} visible_home=${MIRO_VISIBLE_HOME:?} +bootstrap_rc="$host_home/.miro-shell-rc" +visible_bootstrap_rc="$visible_home/.miro-shell-rc" +setup_scripts_dir='/tmp/miro-setup-scripts' + +cat >"$bootstrap_rc" <<'EOF' +cd "${HOME:?}" + +for path in /tmp/miro-setup-scripts/*.sh; do + [ -e "$path" ] || continue + cd "${HOME:?}" + source "$path" + cd "${HOME:?}" +done +EOF if [ "${MIRO_COMPARE_MARKER:-0}" = "1" ]; then printf '__MIRO_E2E_BEGIN__\n' @@ -32,4 +46,16 @@ set -- \ --setenv TZ 'UTC' \ --chdir "$visible_home" -exec bwrap "$@" bash --noprofile --norc -i +if [ -n "${MIRO_SETUP_SCRIPTS:-}" ]; then + i=1 + while IFS= read -r host_path || [ -n "$host_path" ]; do + [ -n "$host_path" ] || continue + visible_path=$(printf '%s/%03d.sh' "$setup_scripts_dir" "$i") + set -- "$@" --ro-bind "$host_path" "$visible_path" + i=$((i + 1)) + done <