refactor: clean up git env handling as not to be part of miro anymore
This commit is contained in:
@@ -11,10 +11,6 @@ import (
|
||||
"miro/internal/output"
|
||||
)
|
||||
|
||||
const (
|
||||
recordGitDate = "2024-01-01T00:00:00Z"
|
||||
)
|
||||
|
||||
type recordIO struct {
|
||||
in io.Reader
|
||||
out io.Writer
|
||||
|
||||
@@ -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, "'", `'"'"'`) + "'"
|
||||
}
|
||||
|
||||
@@ -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' \
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user