From f8119e8bde4f33d779c15917e68935466923d783 Mon Sep 17 00:00:00 2001 From: ruinivist Date: Thu, 19 Mar 2026 15:30:13 +0000 Subject: [PATCH] refactor: delete code for ro bind of repo --- internal/miro/record_session.go | 25 ++++++++----------------- internal/miro/record_shell.go | 3 --- internal/miro/record_shell.sh.tmpl | 5 +++-- internal/miro/record_test.go | 24 +++++++++++++----------- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/internal/miro/record_session.go b/internal/miro/record_session.go index 8c450ea..0605b8f 100644 --- a/internal/miro/record_session.go +++ b/internal/miro/record_session.go @@ -13,7 +13,6 @@ import ( const ( recordVisibleHome = "/home/test" - recordVisibleRepo = "/home/test/repo" recordVisibleTmp = "/tmp" recordGitDate = "2024-01-01T00:00:00Z" ) @@ -88,22 +87,16 @@ func newRecordFiles() (string, string, func(), error) { } type recordSandbox struct { - hostHome string - hostTmp string - projectRoot string - pathEnv string + hostHome string + hostTmp string + pathEnv string } func newRecordSandbox() (recordSandbox, func(), error) { - cwd, err := os.Getwd() - if err != nil { - return recordSandbox{}, nil, err - } - - return newRecordSandboxForProjectRoot(projectRoot(cwd), os.Getenv("PATH")) + return newRecordSandboxForPathEnv(os.Getenv("PATH")) } -func newRecordSandboxForProjectRoot(root, pathEnv string) (recordSandbox, func(), error) { +func newRecordSandboxForPathEnv(pathEnv string) (recordSandbox, func(), error) { dir, err := os.MkdirTemp("", "miro-record-sandbox-") if err != nil { return recordSandbox{}, nil, err @@ -114,15 +107,13 @@ func newRecordSandboxForProjectRoot(root, pathEnv string) (recordSandbox, func() } sandbox := recordSandbox{ - hostHome: filepath.Join(dir, "home"), - hostTmp: filepath.Join(dir, "tmp"), - projectRoot: root, - pathEnv: pathEnv, + hostHome: filepath.Join(dir, "home"), + hostTmp: filepath.Join(dir, "tmp"), + pathEnv: pathEnv, } for _, path := range []string{ sandbox.hostHome, - filepath.Join(sandbox.hostHome, "repo"), sandbox.hostTmp, } { if err := os.MkdirAll(path, 0o755); err != nil { diff --git a/internal/miro/record_shell.go b/internal/miro/record_shell.go index a01f827..d0b21b4 100644 --- a/internal/miro/record_shell.go +++ b/internal/miro/record_shell.go @@ -60,12 +60,10 @@ func buildRecordShellScript() string { var body bytes.Buffer if err := recordShellTemplate.Execute(&body, struct { VisibleHome string - VisibleRepo string VisibleTmp string GitDate string }{ VisibleHome: shQuote(recordVisibleHome), - VisibleRepo: shQuote(recordVisibleRepo), VisibleTmp: shQuote(recordVisibleTmp), GitDate: shQuote(recordGitDate), }); err != nil { @@ -80,7 +78,6 @@ func recordSessionEnv(sandbox recordSandbox) []string { env = append(env, "MIRO_RECORD_HOST_HOME="+sandbox.hostHome, "MIRO_RECORD_HOST_TMP="+sandbox.hostTmp, - "MIRO_RECORD_PROJECT_ROOT="+sandbox.projectRoot, "MIRO_RECORD_PATH_ENV="+sandbox.pathEnv, ) diff --git a/internal/miro/record_shell.sh.tmpl b/internal/miro/record_shell.sh.tmpl index ebc7574..e2cf0ab 100644 --- a/internal/miro/record_shell.sh.tmpl +++ b/internal/miro/record_shell.sh.tmpl @@ -1,9 +1,11 @@ #!/bin/sh set -eu +# Host directory mounted as the sandboxed HOME. host_home=${MIRO_RECORD_HOST_HOME:?} +# Host temp directory mounted read-write inside the sandbox. host_tmp=${MIRO_RECORD_HOST_TMP:?} -project_root=${MIRO_RECORD_PROJECT_ROOT:?} +# PATH value forwarded into the sandbox so required tools stay available. path_env=${MIRO_RECORD_PATH_ENV:?} if command -v git >/dev/null 2>&1; then @@ -17,7 +19,6 @@ exec bwrap \ --ro-bind / / \ --tmpfs /home \ --bind "$host_home" {{ .VisibleHome }} \ - --ro-bind "$project_root" {{ .VisibleRepo }} \ --bind "$host_tmp" {{ .VisibleTmp }} \ --dev /dev \ --proc /proc \ diff --git a/internal/miro/record_test.go b/internal/miro/record_test.go index c6280b7..408173b 100644 --- a/internal/miro/record_test.go +++ b/internal/miro/record_test.go @@ -169,11 +169,9 @@ func TestBuildRecordShellScriptUsesExpectedCommands(t *testing.T) { for _, want := range []string{ "host_home=${MIRO_RECORD_HOST_HOME:?}", "host_tmp=${MIRO_RECORD_HOST_TMP:?}", - "project_root=${MIRO_RECORD_PROJECT_ROOT:?}", "path_env=${MIRO_RECORD_PATH_ENV:?}", "HOME=\"$host_home\" GIT_CONFIG_NOSYSTEM=1 git config --global user.name 'Miro Test'", "--bind \"$host_home\" " + shQuote(recordVisibleHome), - "--ro-bind \"$project_root\" " + shQuote(recordVisibleRepo), "--bind \"$host_tmp\" " + shQuote(recordVisibleTmp), "--setenv HOME " + shQuote(recordVisibleHome), "--setenv PATH \"$path_env\"", @@ -190,8 +188,7 @@ func TestBuildRecordShellScriptUsesExpectedCommands(t *testing.T) { } func TestRunRecordSessionUsesSandboxedScriptCommand(t *testing.T) { - root := t.TempDir() - testDir := filepath.Join(root, "e2e") + testDir := filepath.Join(t.TempDir(), "e2e") mustWriteRecordShell(t, testDir) addFakeRecordDependencies(t, "script") @@ -200,15 +197,15 @@ func TestRunRecordSessionUsesSandboxedScriptCommand(t *testing.T) { t.Setenv("FAKE_SCRIPT_ARGS_FILE", argsPath) t.Setenv("FAKE_SCRIPT_COMMAND_BODY_FILE", commandBodyPath) - sandbox, cleanup, err := newRecordSandboxForProjectRoot(root, os.Getenv("PATH")) + sandbox, cleanup, err := newRecordSandboxForPathEnv(os.Getenv("PATH")) if err != nil { - t.Fatalf("newRecordSandboxForProjectRoot() error = %v", err) + t.Fatalf("newRecordSandboxForPathEnv() error = %v", err) } defer cleanup() shellPath := recordShellPath(testDir) err = withRecordStreams(t, "", func(rio recordIO) error { - return runRecordSession(root, filepath.Join(t.TempDir(), "raw.in"), filepath.Join(t.TempDir(), "raw.out"), shellPath, sandbox, rio) + return runRecordSession(t.TempDir(), filepath.Join(t.TempDir(), "raw.in"), filepath.Join(t.TempDir(), "raw.out"), shellPath, sandbox, rio) }) if err != nil { t.Fatalf("runRecordSession() error = %v", err) @@ -236,7 +233,6 @@ func TestRunRecordSessionUsesSandboxedScriptCommand(t *testing.T) { "host_home=${MIRO_RECORD_HOST_HOME:?}", "--ro-bind / /", "--tmpfs /home", - "--ro-bind \"$project_root\" " + shQuote(recordVisibleRepo), "--setenv HOME " + shQuote(recordVisibleHome), "--setenv TMPDIR " + shQuote(recordVisibleTmp), "bash --noprofile --norc -i", @@ -271,7 +267,7 @@ func TestRecordScenarioUsesDeterministicSandbox(t *testing.T) { defer close(writeDone) defer writer.Close() - if _, err := writer.Write([]byte("pwd\necho \"$HOME\"\ncd repo\npwd\nexit\n")); err != nil { + if _, err := writer.Write([]byte("pwd\necho \"$HOME\"\nif [ -e /home/test/repo ]; then echo FOUND; else echo MISSING; fi\npwd\nexit\n")); err != nil { writeDone <- err return } @@ -304,7 +300,7 @@ func TestRecordScenarioUsesDeterministicSandbox(t *testing.T) { if strings.Contains(recordedIn, "Script started on ") { t.Fatalf("saved in = %q, want stripped script wrapper", recordedIn) } - for _, want := range []string{"pwd\n", "echo \"$HOME\"\n", "cd repo\n", "exit\n"} { + for _, want := range []string{"pwd\n", "echo \"$HOME\"\n", "if [ -e /home/test/repo ]; then echo FOUND; else echo MISSING; fi\n", "exit\n"} { if !strings.Contains(recordedIn, want) { t.Fatalf("saved in = %q, want substring %q", recordedIn, want) } @@ -314,11 +310,17 @@ func TestRecordScenarioUsesDeterministicSandbox(t *testing.T) { if strings.Contains(recordedOut, "Script started on ") { t.Fatalf("saved out = %q, want stripped script wrapper", recordedOut) } - for _, want := range []string{recordVisibleHome, recordVisibleRepo} { + for _, want := range []string{recordVisibleHome} { if !strings.Contains(recordedOut, want) { t.Fatalf("saved out = %q, want substring %q", recordedOut, want) } } + if !strings.Contains(recordedOut, "MISSING") { + t.Fatalf("saved out = %q, want missing repo confirmation", recordedOut) + } + if strings.Contains(recordedOut, "\r\nFOUND\r\n") { + t.Fatalf("saved out = %q, want repo to stay unavailable", recordedOut) + } } func TestRecordFailsWhenRecorderShellMissing(t *testing.T) {