Skip to content

Commit 72612b9

Browse files
committed
fix pipeline
1 parent fab1a0f commit 72612b9

3 files changed

Lines changed: 49 additions & 8 deletions

File tree

arazzo/engine_coverage_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,9 +1550,12 @@ func TestEnsureResolvedPathWithinRoots_PathOutsideRoots(t *testing.T) {
15501550
assert.Contains(t, err.Error(), "outside configured roots")
15511551
}
15521552

1553-
func TestEnsureResolvedPathWithinRoots_EvalSymlinksNotExist(t *testing.T) {
1554-
// If the path doesn't exist, EvalSymlinks returns ErrNotExist => return nil
1555-
err := ensureResolvedPathWithinRoots("/nonexistent/path/file.yaml", []string{"/some/root"})
1553+
func TestEnsureResolvedPathWithinRoots_MissingPathInsideRoot(t *testing.T) {
1554+
root := t.TempDir()
1555+
canonicalRoot, err := filepath.EvalSymlinks(root)
1556+
require.NoError(t, err)
1557+
path := filepath.Join(root, "missing", "file.yaml")
1558+
err = ensureResolvedPathWithinRoots(path, []string{canonicalRoot})
15561559
assert.NoError(t, err)
15571560
}
15581561

arazzo/resolve.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,8 @@ func canonicalizeRoots(roots []string) []string {
481481
}
482482

483483
func ensureResolvedPathWithinRoots(path string, roots []string) error {
484-
resolvedPath, err := filepath.EvalSymlinks(path)
484+
resolvedPath, err := resolvePathForContainment(path)
485485
if err != nil {
486-
if errors.Is(err, os.ErrNotExist) {
487-
return nil
488-
}
489486
return err
490487
}
491488
if !isPathWithinRoots(resolvedPath, roots) {
@@ -494,6 +491,44 @@ func ensureResolvedPathWithinRoots(path string, roots []string) error {
494491
return nil
495492
}
496493

494+
// resolvePathForContainment resolves every existing path component, preserving any
495+
// missing tail for the final containment check. filepath.EvalSymlinks returns
496+
// os.ErrNotExist for the whole path when its final component is missing, which would
497+
// otherwise hide a symlinked parent that escapes the configured roots.
498+
func resolvePathForContainment(path string) (string, error) {
499+
candidate := filepath.Clean(path)
500+
var missing []string
501+
502+
for {
503+
resolved, err := filepath.EvalSymlinks(candidate)
504+
if err == nil {
505+
if len(missing) > 0 {
506+
info, statErr := os.Stat(resolved)
507+
if statErr != nil {
508+
return "", statErr
509+
}
510+
if !info.IsDir() {
511+
return "", fmt.Errorf("path component %q is not a directory", candidate)
512+
}
513+
}
514+
for i := len(missing) - 1; i >= 0; i-- {
515+
resolved = filepath.Join(resolved, missing[i])
516+
}
517+
return resolved, nil
518+
}
519+
if !errors.Is(err, os.ErrNotExist) {
520+
return "", err
521+
}
522+
523+
parent := filepath.Dir(candidate)
524+
if parent == candidate {
525+
return "", err
526+
}
527+
missing = append(missing, filepath.Base(candidate))
528+
candidate = parent
529+
}
530+
}
531+
497532
func containsFold(values []string, value string) bool {
498533
for _, v := range values {
499534
if strings.EqualFold(v, value) {

arazzo_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"log/slog"
1111
"os"
1212
"reflect"
13+
"strings"
1314
"sync"
1415
"testing"
1516
"unsafe"
@@ -313,7 +314,9 @@ func TestNewArazzoDocument_Arazzo10GoldenRenderCompatibility(t *testing.T) {
313314
require.NoError(t, err)
314315
rendered, err := document.Render()
315316
require.NoError(t, err)
316-
assert.Equal(t, string(fixture), string(rendered))
317+
// Git may check the fixture out with CRLF on Windows, while yaml.Marshal
318+
// deliberately emits LF. Compare the serialized content, not checkout policy.
319+
assert.Equal(t, strings.ReplaceAll(string(fixture), "\r\n", "\n"), string(rendered))
317320
assert.NotContains(t, string(rendered), "$self")
318321
assert.NotContains(t, string(rendered), "channelPath")
319322
assert.NotContains(t, string(rendered), "targetSelectorType")

0 commit comments

Comments
 (0)