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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/)
and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]
Fixed:
- Fix relative path resolution in `model test` to resolve paths relative to test file location instead of CWD ([#516](https://github.com/openfga/cli/pull/516)) - fixes #349


## [0.7.5] - 2025-10-09

Expand Down
2 changes: 1 addition & 1 deletion cmd/store/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ var importCmd = &cobra.Command{
return fmt.Errorf("failed to get file name: %w", err)
}

format, storeData, err := storetest.ReadFromFile(fileName, path.Dir(fileName))
format, storeData, err := storetest.ReadFromFile(fileName, "")
if err != nil {
return fmt.Errorf("failed to read from file: %w", err)
}
Expand Down
23 changes: 19 additions & 4 deletions internal/storetest/read-from-input.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package storetest
import (
"fmt"
"os"
"path/filepath"

"github.com/openfga/cli/internal/authorizationmodel"

Expand All @@ -31,10 +32,21 @@ func ReadFromFile(fileName string, basePath string) (authorizationmodel.ModelFor

var storeData StoreData

testFile, err := os.Open(fileName)
absFileName := fileName

// Only join with basePath if fileName is not absolute and basePath is provided
if !filepath.IsAbs(fileName) && basePath != "" {
absFileName = filepath.Join(basePath, fileName)
}

testFile, err := os.Open(absFileName)
if err != nil {
return format, nil, fmt.Errorf("failed to read file %s due to %w", fileName, err)
return format, nil, fmt.Errorf(
"failed to read file %q (resolved path: %q): %w",
fileName, absFileName, err,
)
}
defer testFile.Close()

decoder := yaml.NewDecoder(testFile)
decoder.KnownFields(true)
Expand All @@ -44,12 +56,15 @@ func ReadFromFile(fileName string, basePath string) (authorizationmodel.ModelFor
return format, nil, fmt.Errorf("failed to unmarshal file %s due to %w", fileName, err)
}

format, err = storeData.LoadModel(basePath)
// Use the directory of the resolved file path for nested file references
resolvedBasePath := filepath.Dir(absFileName)

format, err = storeData.LoadModel(resolvedBasePath)
if err != nil {
return format, nil, err
}

err = storeData.LoadTuples(basePath)
err = storeData.LoadTuples(resolvedBasePath)
if err != nil {
return format, nil, err
}
Expand Down
Loading