Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@SoulPancake
Copy link
Member

@SoulPancake SoulPancake commented Jun 12, 2025

Fixes #349

Description

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • New Features
    • Relative file paths are now resolved against a provided base directory when reading store files, enabling more flexible project layouts and portability.
  • Bug Fixes
    • More reliable file opening in mixed absolute/relative path scenarios; error messages remain consistent for easier troubleshooting.
  • Notes
    • No changes to public interfaces; existing workflows continue to work as before.

@SoulPancake SoulPancake requested a review from a team as a code owner June 12, 2025 06:53
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 27, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Introduces conditional path resolution in internal/storetest/read-from-input.go: when a basePath is provided and fileName is relative, the code computes an absolute path and opens the file using it. Error reporting continues to reference the original fileName. No exported/public signatures changed.

Changes

Cohort / File(s) Summary
Path resolution for store file opening
internal/storetest/read-from-input.go
Add path/filepath import; compute absFileName using basePath when fileName is relative; open using absFileName; retain original fileName in error messages; no exported API changes.

Sequence Diagram(s)

sequenceDiagram
  actor Caller
  participant Func as read-from-input
  participant FS as Filesystem

  Caller->>Func: read(fileName, basePath)
  alt fileName is absolute or no basePath
    Note over Func: absFileName = fileName
  else relative fileName and basePath provided
    Note over Func: absFileName = join(basePath, fileName)
  end
  Func->>FS: open(absFileName)
  alt open fails
    FS-->>Func: error
    Func-->>Caller: error (mentions original fileName)
  else open succeeds
    FS-->>Func: handle
    Func-->>Caller: data/result
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
internal/storetest/read-from-input.go (2)

35-39: Variable name is misleading; also consider cleaning the joined path.

absFileName may still be relative if basePath is relative. Rename to resolvedPath and apply filepath.Clean to normalize.

-	absFileName := fileName
+	resolvedPath := fileName

-	if !filepath.IsAbs(fileName) && basePath != "" {
-		absFileName = filepath.Join(basePath, fileName)
-	}
+	if !filepath.IsAbs(fileName) && basePath != "" {
+		resolvedPath = filepath.Clean(filepath.Join(basePath, fileName))
+	}

49-52: Mirror the improved error message for YAML unmarshal.

Keep the user-supplied name and also report the resolved path.

-		return format, nil, fmt.Errorf("failed to unmarshal file %s due to %w", fileName, err)
+		return format, nil, fmt.Errorf("failed to unmarshal file %q (resolved path: %q): %w", fileName, absFileName, err)

If you adopted the resolvedPath rename, use that identifier instead of absFileName.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bd345de and 03d69e0.

📒 Files selected for processing (1)
  • internal/storetest/read-from-input.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test Release Process
  • GitHub Check: Tests
🔇 Additional comments (1)
internal/storetest/read-from-input.go (1)

22-22: Import addition is appropriate.

Adding path/filepath is necessary for the new path resolution logic.

@Siddhant-K-code
Copy link
Member

@SoulPancake, can you please address the review comments & fix the CI please!

SoulPancake and others added 4 commits September 18, 2025 06:24
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* Fix lint failures and integration test issues

---------

Co-authored-by: SoulPancake <[email protected]>
@SoulPancake
Copy link
Member Author

@Siddhant-K-code Hi
Can you please have a look at it now?

Copy link
Member

@Siddhant-K-code Siddhant-K-code left a comment

Choose a reason for hiding this comment

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

Changes look good and are backward compatible. Thanks @SoulPancake!

Before merging, please add this to CHANGELOG.md under 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

@SoulPancake
Copy link
Member Author

Done, Please have a look @Siddhant-K-code

Copy link
Member

@Siddhant-K-code Siddhant-K-code left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@openfga/dx, can you give a ✅ to unblock the merge queue.

@aaguiarz aaguiarz added this pull request to the merge queue Oct 13, 2025
Merged via the queue into openfga:main with commit 7266fff Oct 13, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Relative Path in model_file in Tests

4 participants