Handle relative system temporary directories

This commit is contained in:
2026-10-06 01:10:25 +00:00
parent ce3a85e3e6
commit f4d9cf20ec
3 changed files with 61 additions and 1 deletions

View File

@@ -255,7 +255,9 @@ candidate output still leaves the worktree clean.
**Resolution:** Candidate and CLI delivery builds use shared system temporary
storage allocated by `internal/tempdir`, with worktree containment checks and
caller-owned cleanup. Regressions execute both operations with read-only
repository parents and confirm clean worktrees. Affected suites pass.
repository parents and confirm clean worktrees. Additional helper regressions
cover relative system temporary paths and cleanup after rejecting in-worktree
storage. Affected suites pass.
### R7 — Medium: Attachment origin restrictions exceed credential isolation

View File

@@ -14,6 +14,12 @@ func Outside(repositoryDir, pattern string) (string, error) {
if err != nil {
return "", err
}
absolute, err := filepath.Abs(directory)
if err != nil {
os.RemoveAll(directory)
return "", err
}
directory = absolute
repository, err := filepath.Abs(repositoryDir)
if err == nil && !strings.EqualFold(filepath.VolumeName(repository), filepath.VolumeName(directory)) {
return directory, nil

View File

@@ -0,0 +1,52 @@
package tempdir
import (
"os"
"path/filepath"
"runtime"
"testing"
)
func TestOutsideHonorsRelativeTemporaryDirectory(t *testing.T) {
parent := t.TempDir()
repository := t.TempDir()
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
relative, err := filepath.Rel(cwd, parent)
if err != nil {
t.Skip("temporary directory is on another volume")
}
setTemporaryDirectory(t, relative)
directory, err := Outside(repository, "fixture-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(directory)
if !filepath.IsAbs(directory) || filepath.Dir(directory) != parent {
t.Fatalf("temporary storage=%q want parent %q", directory, parent)
}
}
func TestOutsideRejectsAndCleansStorageInsideWorktree(t *testing.T) {
repository := t.TempDir()
setTemporaryDirectory(t, repository)
if directory, err := Outside(repository, "fixture-"); err == nil {
os.RemoveAll(directory)
t.Fatal("storage created inside worktree")
}
remaining, err := os.ReadDir(repository)
if err != nil || len(remaining) != 0 {
t.Fatalf("temporary storage left behind: %v %v", remaining, err)
}
}
func setTemporaryDirectory(t *testing.T, directory string) {
t.Helper()
variable := "TMPDIR"
if runtime.GOOS == "windows" {
variable = "TMP"
}
t.Setenv(variable, directory)
}