Bugfix involving nested directory creation
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
This commit is contained in:
@@ -99,7 +99,11 @@ func runLocalPathForCanonical(layout runStageLayout, sessionPaths artifacts.Sess
|
|||||||
if rel == "." || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
|
if rel == "." || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
|
||||||
return "", fmt.Errorf("canonical path %q is outside session root %q", cleanCanonical, sessionPaths.Root)
|
return "", fmt.Errorf("canonical path %q is outside session root %q", cleanCanonical, sessionPaths.Root)
|
||||||
}
|
}
|
||||||
return filepath.Join(layout.OutputsDir, rel), nil
|
localPath := filepath.Join(layout.OutputsDir, rel)
|
||||||
|
if err := os.MkdirAll(filepath.Dir(localPath), 0o755); err != nil {
|
||||||
|
return "", fmt.Errorf("create run-local output parent for %q: %w", localPath, err)
|
||||||
|
}
|
||||||
|
return localPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func promoteRunLocalOutput(
|
func promoteRunLocalOutput(
|
||||||
|
|||||||
35
internal/stage/run_local_test.go
Normal file
35
internal/stage/run_local_test.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package stage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRunLocalPathForCanonicalCreatesParentDirectories(t *testing.T) {
|
||||||
|
root := t.TempDir()
|
||||||
|
sessionRoot := filepath.Join(root, "work", "dilfs", "2026-05-17")
|
||||||
|
layout := runStageLayout{
|
||||||
|
Enabled: true,
|
||||||
|
OutputsDir: filepath.Join(sessionRoot, "runs", "run-1", "merge", "outputs"),
|
||||||
|
}
|
||||||
|
if err := os.MkdirAll(layout.OutputsDir, 0o755); err != nil {
|
||||||
|
t.Fatalf("mkdir outputs dir: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
canonical := filepath.Join(sessionRoot, "transcripts", "merged.json")
|
||||||
|
got, err := runLocalPathForCanonical(layout, artifacts.SessionPaths{Root: sessionRoot}, canonical)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("runLocalPathForCanonical() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
want := filepath.Join(layout.OutputsDir, "transcripts", "merged.json")
|
||||||
|
if got != want {
|
||||||
|
t.Fatalf("runLocalPathForCanonical() = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(filepath.Dir(got)); err != nil {
|
||||||
|
t.Fatalf("expected run-local parent directory to exist: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user