From ec1d7ec23a9d7f93f21b1a196aaa92b415a57a8e Mon Sep 17 00:00:00 2001 From: ruinivist Date: Thu, 19 Mar 2026 18:49:59 +0000 Subject: [PATCH] refactor: clean up git env handling as not to be part of miro anymore --- internal/miro/record_session.go | 4 ---- internal/miro/record_shell.go | 22 ++++------------------ internal/miro/record_shell.sh.tmpl | 11 ----------- internal/miro/record_test.go | 18 ------------------ 4 files changed, 4 insertions(+), 51 deletions(-) diff --git a/internal/miro/record_session.go b/internal/miro/record_session.go index 5f727c5..ef2b274 100644 --- a/internal/miro/record_session.go +++ b/internal/miro/record_session.go @@ -11,10 +11,6 @@ import ( "miro/internal/output" ) -const ( - recordGitDate = "2024-01-01T00:00:00Z" -) - type recordIO struct { in io.Reader out io.Writer diff --git a/internal/miro/record_shell.go b/internal/miro/record_shell.go index 0a61359..865b23b 100644 --- a/internal/miro/record_shell.go +++ b/internal/miro/record_shell.go @@ -1,7 +1,6 @@ package miro import ( - "bytes" "embed" "errors" "fmt" @@ -9,7 +8,6 @@ import ( "path/filepath" "sort" "strings" - "text/template" ) const recordShellName = "shell.sh" @@ -17,10 +15,6 @@ const recordShellName = "shell.sh" //go:embed record_shell.sh.tmpl var recordShellTemplateFS embed.FS -var recordShellTemplate = template.Must( - template.New("record_shell.sh.tmpl").ParseFS(recordShellTemplateFS, "record_shell.sh.tmpl"), -) - func recordShellPath(testDir string) string { return filepath.Join(testDir, recordShellName) } @@ -69,16 +63,12 @@ func resolveRecordShell(testDir string) (string, error) { } func buildRecordShellScript() string { - var body bytes.Buffer - if err := recordShellTemplate.Execute(&body, struct { - GitDate string - }{ - GitDate: shQuote(recordGitDate), - }); err != nil { - panic(fmt.Sprintf("render record shell template: %v", err)) + body, err := recordShellTemplateFS.ReadFile("record_shell.sh.tmpl") + if err != nil { + panic(fmt.Sprintf("read record shell template: %v", err)) } - return body.String() + return string(body) } func recordSessionEnv(sandbox recordSandbox, sandboxConfig map[string]string) []string { @@ -107,7 +97,3 @@ func sortedSandboxKeys(sandboxConfig map[string]string) []string { sort.Strings(keys) return keys } - -func shQuote(value string) string { - return "'" + strings.ReplaceAll(value, "'", `'"'"'`) + "'" -} diff --git a/internal/miro/record_shell.sh.tmpl b/internal/miro/record_shell.sh.tmpl index 3dd23c3..6fc4dd2 100644 --- a/internal/miro/record_shell.sh.tmpl +++ b/internal/miro/record_shell.sh.tmpl @@ -9,13 +9,6 @@ host_tmp=${MIRO_HOST_TMP:?} path_env=${MIRO_PATH_ENV:?} visible_home=${MIRO_VISIBLE_HOME:?} -if command -v git >/dev/null 2>&1; then - HOME="$host_home" GIT_CONFIG_NOSYSTEM=1 git config --global user.name 'Miro Test' >/dev/null 2>&1 || : - HOME="$host_home" GIT_CONFIG_NOSYSTEM=1 git config --global user.email 'miro-test@example.com' >/dev/null 2>&1 || : - HOME="$host_home" GIT_CONFIG_NOSYSTEM=1 git config --global init.defaultBranch main >/dev/null 2>&1 || : - HOME="$host_home" GIT_CONFIG_NOSYSTEM=1 git config --global advice.defaultBranchName false >/dev/null 2>&1 || : -fi - set -- \ --ro-bind / / \ --tmpfs /home \ @@ -25,10 +18,6 @@ set -- \ --proc /proc \ --unshare-pid \ --die-with-parent \ - --setenv GIT_AUTHOR_DATE {{ .GitDate }} \ - --setenv GIT_COMMITTER_DATE {{ .GitDate }} \ - --setenv GIT_CONFIG_NOSYSTEM '1' \ - --setenv GIT_PAGER 'cat' \ --setenv HISTFILE '/dev/null' \ --setenv HOME "$visible_home" \ --setenv LANG 'C' \ diff --git a/internal/miro/record_test.go b/internal/miro/record_test.go index 9efde6c..55ea56c 100644 --- a/internal/miro/record_test.go +++ b/internal/miro/record_test.go @@ -171,7 +171,6 @@ func TestBuildRecordShellScriptUsesExpectedCommands(t *testing.T) { "host_tmp=${MIRO_HOST_TMP:?}", "path_env=${MIRO_PATH_ENV:?}", "visible_home=${MIRO_VISIBLE_HOME:?}", - "HOME=\"$host_home\" GIT_CONFIG_NOSYSTEM=1 git config --global user.name 'Miro Test'", "--bind \"$host_home\" \"$visible_home\"", "--bind \"$host_tmp\" '/tmp'", "--setenv HOME \"$visible_home\"", @@ -186,17 +185,6 @@ func TestBuildRecordShellScriptUsesExpectedCommands(t *testing.T) { t.Fatalf("wrapper = %q, want substring %q", body, want) } } - for _, unwanted := range []string{ - "MIRO_SANDBOX_ENVS", - "set -- \"$@\" --setenv \"$env_name\" \"$env_value\"", - } { - if strings.Contains(body, unwanted) { - t.Fatalf("wrapper = %q, want no substring %q", body, unwanted) - } - } - if strings.Contains(body, "/home/test") { - t.Fatalf("wrapper = %q, want no hardcoded visible home", body) - } } func TestRecordSessionEnvIncludesConfiguredSandboxEnv(t *testing.T) { @@ -220,9 +208,6 @@ func TestRecordSessionEnvIncludesConfiguredSandboxEnv(t *testing.T) { t.Fatalf("env = %#v, want entry %q", env, want) } } - if containsEnvEntry(env, "MIRO_SANDBOX_ENVS=MIRO_KEY_WORD:MIRO_VISIBLE_HOME") { - t.Fatalf("env = %#v, want MIRO_SANDBOX_ENVS to be absent", env) - } } func TestRunRecordSessionUsesSandboxedScriptCommand(t *testing.T) { @@ -280,9 +265,6 @@ func TestRunRecordSessionUsesSandboxedScriptCommand(t *testing.T) { t.Fatalf("wrapper = %q, want substring %q", body, want) } } - if strings.Contains(body, "MIRO_SANDBOX_ENVS") { - t.Fatalf("wrapper = %q, want no MIRO_SANDBOX_ENVS reference", body) - } } func TestRecordScenarioUsesDeterministicSandbox(t *testing.T) {