Skip to content

Conversation

SoulPancake
Copy link
Contributor

@SoulPancake SoulPancake commented Jun 5, 2025

Solves #499 #233

I was giving this feature a shot,
I was able to make it work when you provide the source test files like such

name: Test Store
model_file: ./test.fga
#tuple_file: ./singletuple.yaml
tuple_files:
  - ./tuple.yaml
  - ./tuple_2.yaml
tests:
  - name:  Admin checks
    description: To test what   authorisation on all objects
    check:

Although this is still in draft mode so let me know if this is what we expect, I can finish the tests then

Description

References

closes #506
closes #233

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

  • Documentation

    • Clarified usage and added examples for single and multiple global tuple files in test configurations.
  • New Features

    • Enabled support for multiple global tuple files to aggregate tuples from various sources during testing.
  • Bug Fixes

    • Enhanced error handling and reporting for tuple loading from files.
  • Tests

    • Added tests covering tuple loading from different file setups and error conditions.
  • Chores

    • Added example tuple files illustrating hierarchical folder relationships.

@SoulPancake SoulPancake requested a review from a team as a code owner June 5, 2025 06:03
@SoulPancake SoulPancake marked this pull request as draft June 5, 2025 06:04
@SoulPancake
Copy link
Contributor Author

@aaguiarz Let me know if you could review this as I want to use this feature as well for organising my tuple files

@aaguiarz
Copy link
Member

aaguiarz commented Jun 9, 2025

@SoulPancake yeah, this makes sense.

Please make sure you add tests to make sure the new format and old format work, and update docs

@SoulPancake
Copy link
Contributor Author

@aaguiarz
What should the expected behaviour be if the tuple file ( single ) and tuple files array both are provided?

@SoulPancake
Copy link
Contributor Author

@aaguiarz What should the expected behaviour be if the tuple file ( single ) and tuple files array both are provided?

My proposal would be

  1. If a tuple file alone is provided, just load those tuples.
  2. If multiple tuple files are provided, load all of them
  3. If both tuple file and tuple files array is provided, load from all the files but do a duplicate check before loading tuples?

@SoulPancake SoulPancake marked this pull request as ready for review June 11, 2025 12:26
@SoulPancake SoulPancake requested review from a team as code owners June 12, 2025 05:40
SoulPancake added a commit to SoulPancake/openfga.dev that referenced this pull request Jun 12, 2025
this is linked to the changes proposed and introduced in openfga/cli#506
@aaguiarz
Copy link
Member

@aaguiarz What should the expected behaviour be if the tuple file ( single ) and tuple files array both are provided?

My proposal would be

  1. If a tuple file alone is provided, just load those tuples.
  2. If multiple tuple files are provided, load all of them
  3. If both tuple file and tuple files array is provided, load from all the files but do a duplicate check before loading tuples?

This makes sense. I would not do a duplicate check before loading tuples for now, I think it's better to surface that issue to the user than to hide it.

Thanks a lot for your help with this.

@SoulPancake
Copy link
Contributor Author

SoulPancake commented Jun 12, 2025

I think it's better to surface that issue to the user than to hide it.

So programmatically we still keep the map? and error out on duplicate tuples.

@aaguiarz
Copy link
Member

I think it's better to surface that issue to the user than to hide it.

So programmatically we still keep the map? and error out on duplicate tuples.

Yes, the test will fail because they are duplicated tuples, and that's OK

@SoulPancake
Copy link
Contributor Author

SoulPancake commented Jun 13, 2025

@aaguiarz

the test will fail because they are duplicated tuples, and that's OK

In that case we can just remove the map entirely and just load up all the tuples from all the files

Copy link
Contributor

coderabbitai bot commented Jun 17, 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

The changes introduce support for specifying multiple global tuple files in configuration and documentation, update example files to demonstrate this capability, and refactor the tuple loading logic to handle multiple sources and aggregate errors. A comprehensive test suite is added to verify tuple loading behavior under various scenarios.

Changes

File(s) Change Summary
README.md Updated documentation to clarify and exemplify usage of tuples, tuple_file, and new tuple_files options.
example/model.fga.yaml Added tuple_files key to support multiple global tuple files in configuration.
example/model_tuples_2.yaml, example/model_tuples_3.yaml Added new tuple files defining hierarchical parent relationships between folders.
internal/storetest/storedata.go Refactored tuple loading logic; added support for multiple tuple files, error aggregation, and helper functions.
internal/storetest/storedata_test.go Introduced tests covering tuple loading from various file configurations and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant StoreData
    participant FileSystem

    User->>StoreData: Call LoadTuples(basePath)
    StoreData->>FileSystem: Load tuples from Tuples (inline)
    StoreData->>FileSystem: Load tuples from TupleFile (single file)
    StoreData->>FileSystem: Load tuples from TupleFiles (multiple files)
    StoreData->>FileSystem: Load test-specific tuple files
    StoreData->>StoreData: Aggregate all loaded tuples
    StoreData->>User: Return (possibly with aggregated error)
Loading

Suggested labels

codex

Suggested reviewers

  • rhamzeh
    """

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@SoulPancake
Copy link
Contributor Author

@aaguiarz I have removed dedupe logic and updated this like we discussed, Can you please review this?

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: 3

🧹 Nitpick comments (4)
example/model_tuples_3.yaml (1)

1-6: Add trailing newline to satisfy linters and POSIX tools

The file is missing a newline at EOF (flagged by yamllint).
Some editors and tooling rely on this – worth adding to keep a clean CI signal.

   object: folder:marketing-Q1↵
+ 
example/model.fga.yaml (1)

9-12: Clarify precedence when both tuple_file and tuple_files are present

The example shows both keys populated, which is helpful, but users may wonder which one “wins” on duplicate paths or conflicting tuples. Consider an inline comment such as:

tuple_file: ./model_tuples.yaml  # loaded as-is, duplicates NOT filtered
tuple_files:                     # additional files – all tuples are appended

to make the behaviour explicit and avoid support questions.

internal/storetest/storedata_test.go (1)

31-37: Minor: reduce duplication to keep test fixtures minimal

tupleFile2 repeats the user:jon … doc1 tuple already present in
tupleFile. If you ever introduce a duplicate-detection mode the test
will become brittle. Consider unique tuples per file or an explicit
expectDuplicates flag to make intent clearer.

internal/storetest/storedata.go (1)

171-173: Minor wording nit

"global tuple %s file" reads awkwardly. Consider "global tuple file %s" for clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb88057 and 56792d8.

📒 Files selected for processing (6)
  • README.md (1 hunks)
  • example/model.fga.yaml (1 hunks)
  • example/model_tuples_2.yaml (1 hunks)
  • example/model_tuples_3.yaml (1 hunks)
  • internal/storetest/storedata.go (3 hunks)
  • internal/storetest/storedata_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
internal/storetest/storedata.go (1)
internal/tuplefile/read.go (1)
  • ReadTupleFile (15-40)
internal/storetest/storedata_test.go (1)
internal/storetest/storedata.go (2)
  • StoreData (73-81)
  • ModelTest (63-71)
🪛 YAMLlint (1.37.1)
example/model_tuples_3.yaml

[error] 6-6: no new line character at the end of file

(new-line-at-end-of-file)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test Release Process
🔇 Additional comments (3)
example/model_tuples_2.yaml (1)

1-7: Looks good – valid YAML and terminates with a newline

No issues spotted.

README.md (1)

552-559: Great addition – docs now cover tuple_files option

The explanatory block is concise and matches the implementation.

internal/storetest/storedata.go (1)

187-195: Collect errors but proceed – good pattern

Nice use of errors.Join to aggregate per-file failures while still loading the remaining tuple files.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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

♻️ Duplicate comments (1)
internal/storetest/storedata.go (1)

125-131: Missing-tuple guard still fires too early
The guard runs before loadTestTuples, so a config that supplies tuples only via Tests[i].TupleFile is incorrectly rejected.
Move the check after loadTestTuples, or include len(storeData.Tests) > 0 in the condition.

🧹 Nitpick comments (3)
internal/storetest/storedata.go (1)

161-232: File fails gofmt
The linter reports formatting issues (e.g., mixed tabs/spaces at line 227).
Run go fmt ./... to keep CI green.

internal/storetest/storedata_test.go (2)

84-86: Loop-variable copy no longer needed (Go 1.22)
Since Go 1.22, t.Run captures the value, not the pointer, of the loop variable.
tc := tc can be deleted without risking the classic capture bug.


1-107: Please run gofmt on the test file
The formatter reports offences at lines 84 and 85.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56792d8 and 5e6594f.

📒 Files selected for processing (2)
  • internal/storetest/storedata.go (3 hunks)
  • internal/storetest/storedata_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
internal/storetest/storedata.go (1)
internal/tuplefile/read.go (1)
  • ReadTupleFile (15-40)
internal/storetest/storedata_test.go (1)
internal/storetest/storedata.go (2)
  • StoreData (73-81)
  • ModelTest (63-71)
🪛 GitHub Check: Lints
internal/storetest/storedata.go

[failure] 227-227:
File is not properly formatted (gofmt)

internal/storetest/storedata_test.go

[failure] 84-84:
File is not properly formatted (gofmt)


[failure] 85-85:
The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Release Process
  • GitHub Check: Tests

@SoulPancake
Copy link
Contributor Author

Hi @aaguiarz, just wanted to check in—would someone be able to review this sometime soon? Otherwise I'll rebase resolving the conflicts later on

@rhamzeh
Copy link
Member

rhamzeh commented Jun 27, 2025

Hey @SoulPancake - yeah apologies for the delay. I will be taking a look early next week, most likely monday.

I have not looked extensively at the code yet, but make sure we're disallowing things like loading a tuple file multiple times in an array.

Also @aaguiarz maybe we want to deduplicate tuples before writing? As I assume it will become harder and harder for users to audit whether they have duplicates and duplicate files as this gets more expansive

@SoulPancake
Copy link
Contributor Author

NP, Sure I'll rebase it on Sunday. Thanks @rhamzeh

@SoulPancake
Copy link
Contributor Author

@rhamzeh I have updated the branch for this PR, can you take a look?

@rhamzeh rhamzeh mentioned this pull request Jul 7, 2025
4 tasks
@rhamzeh
Copy link
Member

rhamzeh commented Jul 7, 2025

@SoulPancake - fixing the lint issues your having in a separate PR, will merge to this once those are merged. Any chance you can give the team edit access to this?

@SoulPancake
Copy link
Contributor Author

image
@rhamzeh I already have allowed access to edit by the maintainers

Copy link
Member

@rhamzeh rhamzeh left a comment

Choose a reason for hiding this comment

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

@SoulPancake Looks good to me

I do have one thing for consideration - but that could be in a follow up PR - if we decide to do it.

I'm thinking about the duplicate files and duplicate tuples, and how we'll manage them.

  • I do not think we should error on duplicates, as I can imagine how as user's needs get more complex, the files they're managing can grow. If they have to hunt down which file is causing a duplicate issue that can become a mess
  • For performance reasons, it makes sense to dedup the file names instead of loading them everytime
  • Deduping the tuples makes sense as it would prevent the API erroring on duplicates

But we probably need to discuss that in details before doing it - again unrelated to this PR itself.

Thank you for working on it!

@rhamzeh
Copy link
Member

rhamzeh commented Jul 7, 2025

A review from someone not me is required now that I've modified it. Will ask around :)

@rhamzeh rhamzeh requested a review from jimmyjames July 7, 2025 22:03
@rhamzeh rhamzeh added this pull request to the merge queue Jul 7, 2025
Merged via the queue into openfga:main with commit 043d54e Jul 7, 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.

Support multiple tuple files in tests
4 participants