refactor: clean up git env handling as not to be part of miro anymore

This commit is contained in:
2026-03-19 18:49:59 +00:00
parent c3823ee9b0
commit ec1d7ec23a
4 changed files with 4 additions and 51 deletions
-4
View File
@@ -11,10 +11,6 @@ import (
"miro/internal/output" "miro/internal/output"
) )
const (
recordGitDate = "2024-01-01T00:00:00Z"
)
type recordIO struct { type recordIO struct {
in io.Reader in io.Reader
out io.Writer out io.Writer
+4 -18
View File
@@ -1,7 +1,6 @@
package miro package miro
import ( import (
"bytes"
"embed" "embed"
"errors" "errors"
"fmt" "fmt"
@@ -9,7 +8,6 @@ import (
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
"text/template"
) )
const recordShellName = "shell.sh" const recordShellName = "shell.sh"
@@ -17,10 +15,6 @@ const recordShellName = "shell.sh"
//go:embed record_shell.sh.tmpl //go:embed record_shell.sh.tmpl
var recordShellTemplateFS embed.FS 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 { func recordShellPath(testDir string) string {
return filepath.Join(testDir, recordShellName) return filepath.Join(testDir, recordShellName)
} }
@@ -69,16 +63,12 @@ func resolveRecordShell(testDir string) (string, error) {
} }
func buildRecordShellScript() string { func buildRecordShellScript() string {
var body bytes.Buffer body, err := recordShellTemplateFS.ReadFile("record_shell.sh.tmpl")
if err := recordShellTemplate.Execute(&body, struct { if err != nil {
GitDate string panic(fmt.Sprintf("read record shell template: %v", err))
}{
GitDate: shQuote(recordGitDate),
}); err != nil {
panic(fmt.Sprintf("render record shell template: %v", err))
} }
return body.String() return string(body)
} }
func recordSessionEnv(sandbox recordSandbox, sandboxConfig map[string]string) []string { func recordSessionEnv(sandbox recordSandbox, sandboxConfig map[string]string) []string {
@@ -107,7 +97,3 @@ func sortedSandboxKeys(sandboxConfig map[string]string) []string {
sort.Strings(keys) sort.Strings(keys)
return keys return keys
} }
func shQuote(value string) string {
return "'" + strings.ReplaceAll(value, "'", `'"'"'`) + "'"
}
-11
View File
@@ -9,13 +9,6 @@ host_tmp=${MIRO_HOST_TMP:?}
path_env=${MIRO_PATH_ENV:?} path_env=${MIRO_PATH_ENV:?}
visible_home=${MIRO_VISIBLE_HOME:?} 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 -- \ set -- \
--ro-bind / / \ --ro-bind / / \
--tmpfs /home \ --tmpfs /home \
@@ -25,10 +18,6 @@ set -- \
--proc /proc \ --proc /proc \
--unshare-pid \ --unshare-pid \
--die-with-parent \ --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 HISTFILE '/dev/null' \
--setenv HOME "$visible_home" \ --setenv HOME "$visible_home" \
--setenv LANG 'C' \ --setenv LANG 'C' \
-18
View File
@@ -171,7 +171,6 @@ func TestBuildRecordShellScriptUsesExpectedCommands(t *testing.T) {
"host_tmp=${MIRO_HOST_TMP:?}", "host_tmp=${MIRO_HOST_TMP:?}",
"path_env=${MIRO_PATH_ENV:?}", "path_env=${MIRO_PATH_ENV:?}",
"visible_home=${MIRO_VISIBLE_HOME:?}", "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_home\" \"$visible_home\"",
"--bind \"$host_tmp\" '/tmp'", "--bind \"$host_tmp\" '/tmp'",
"--setenv HOME \"$visible_home\"", "--setenv HOME \"$visible_home\"",
@@ -186,17 +185,6 @@ func TestBuildRecordShellScriptUsesExpectedCommands(t *testing.T) {
t.Fatalf("wrapper = %q, want substring %q", body, want) 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) { func TestRecordSessionEnvIncludesConfiguredSandboxEnv(t *testing.T) {
@@ -220,9 +208,6 @@ func TestRecordSessionEnvIncludesConfiguredSandboxEnv(t *testing.T) {
t.Fatalf("env = %#v, want entry %q", env, want) 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) { func TestRunRecordSessionUsesSandboxedScriptCommand(t *testing.T) {
@@ -280,9 +265,6 @@ func TestRunRecordSessionUsesSandboxedScriptCommand(t *testing.T) {
t.Fatalf("wrapper = %q, want substring %q", body, want) 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) { func TestRecordScenarioUsesDeterministicSandbox(t *testing.T) {