Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions internal/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,26 +314,10 @@ func runAgent(agentName, fullsendDir, outputBase, targetRepo, fullsendBinary str
// 8. Make project code available (copy repo root into a named subdirectory).
copyStart := time.Now()
printer.StepStart("Copying project code into sandbox")
mkRepoCmd := fmt.Sprintf("mkdir -p %s", repoDir)
if _, _, _, err := sandbox.Exec(sandboxName, mkRepoCmd, 10*time.Second); err != nil {
return fmt.Errorf("creating repo dir in sandbox: %w", err)
}
if err := sandbox.Upload(sandboxName, repoSrc+"/.", repoDir+"/"); err != nil {
if err := sandbox.UploadDir(sandboxName, repoSrc, repoDir); err != nil {
printer.StepFail("Failed to copy project code")
return fmt.Errorf("copying project code: %w", err)
}

// openshell upload applies .gitignore filtering by default via
// git ls-files, which never lists .git/. Upload it separately so the
// agent has full git history, refs, and branch state. Uploading .git/
// directly bypasses the filter because .git/ itself is not a working
// tree, causing openshell to fall back to an unfiltered tar upload.
gitDir := filepath.Join(repoSrc, ".git")
if fi, statErr := os.Stat(gitDir); statErr == nil && fi.IsDir() {
if err := sandbox.Upload(sandboxName, gitDir, filepath.Join(repoDir, ".git")); err != nil {
printer.StepWarn("Could not upload .git directory: " + err.Error())
}
}
printer.StepDone(fmt.Sprintf("Project code copied to %s/ (%.1fs)", repoName, time.Since(copyStart).Seconds()))

// 8a. Inject org-level AGENTS.md if the target repo does not have one.
Expand Down
33 changes: 33 additions & 0 deletions internal/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,39 @@ func Upload(sandboxName, localPath, remotePath string) error {
return nil
}

// UploadDir uploads a local directory into a sandbox, preserving symlinks.
// openshell sandbox upload dereferences symlinks; this builds a local tarball
// with --no-dereference, uploads it, and extracts it in the sandbox.
func UploadDir(sandboxName, localPath, remotePath string) error {
tmp, err := os.CreateTemp("", "openshell-upload-*.tar.gz")
if err != nil {
return fmt.Errorf("creating temp tarball: %w", err)
}
tmpPath := tmp.Name()
tmp.Close()
defer os.Remove(tmpPath)

tarCmd := exec.Command("tar", "-czf", tmpPath, "-C", localPath, ".")
if out, tarErr := tarCmd.CombinedOutput(); tarErr != nil {
return fmt.Errorf("creating tarball of %q: %s: %w", localPath, string(out), tarErr)
}

remoteTar := fmt.Sprintf("/tmp/fs-upload-%s.tar.gz", sandboxName)
if err := Upload(sandboxName, tmpPath, remoteTar); err != nil {
return err
}

extractCmd := fmt.Sprintf("mkdir -p %s && tar -xzf %s -C %s && rm %s", remotePath, remoteTar, remotePath, remoteTar)
_, stderr, exitCode, err := Exec(sandboxName, extractCmd, transferTimeout)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[info] style

extractCmd is built with fmt.Sprintf without shell-escaping remotePath or remoteTar. Safe in practice since values are internally constructed, consistent with all other Exec() call sites.

if err != nil {
return fmt.Errorf("extracting tarball in sandbox %q: %w", sandboxName, err)
}
if exitCode != 0 {
return fmt.Errorf("extracting tarball in sandbox %q: exit %d: %s", sandboxName, exitCode, stderr)
}
return nil
}

// Download copies a file or directory from a sandbox to the local machine.
// The localPath is always treated as a directory by openshell — for single-file
// downloads use DownloadFile instead.
Expand Down
8 changes: 8 additions & 0 deletions internal/sandbox/sandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,11 @@ func TestSanitizeDownload_EmptyDir(t *testing.T) {
err := sanitizeDownload(dir)
assert.NoError(t, err)
}

func TestUploadDir_OpenshellNotInPath(t *testing.T) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] test-adequacy

TestUploadDir_OpenshellNotInPath only exercises the error path. The happy path (tarball creation with symlink preservation) is not unit-tested. Manual live-sandbox verification was performed per the PR description.

Suggested fix: Add a unit test that creates a directory with a symlink, runs the tar step in isolation, and inspects the archive to confirm symlinks are preserved.

dir := t.TempDir()
t.Setenv("PATH", "")

err := UploadDir("test-sandbox", dir, "/tmp/workspace/repo")
assert.Error(t, err)
}
Loading