-
Notifications
You must be signed in to change notification settings - Fork 36
feat: support multiple tuple files #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support multiple tuple files #506
Conversation
@aaguiarz Let me know if you could review this as I want to use this feature as well for organising my tuple files |
@SoulPancake yeah, this makes sense. Please make sure you add tests to make sure the new format and old format work, and update docs |
@aaguiarz |
My proposal would be
|
this is linked to the changes proposed and introduced in openfga/cli#506
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. |
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 |
In that case we can just remove the map entirely and just load up all the tuples from all the files |
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the """ WalkthroughThe 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
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)
Suggested labels
Suggested reviewers
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@aaguiarz I have removed dedupe logic and updated this like we discussed, Can you please review this? |
There was a problem hiding this 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 toolsThe 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 bothtuple_file
andtuple_files
are presentThe 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 appendedto 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 theuser: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
📒 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 newlineNo issues spotted.
README.md (1)
552-559
: Great addition – docs now covertuple_files
optionThe explanatory block is concise and matches the implementation.
internal/storetest/storedata.go (1)
187-195
: Collect errors but proceed – good patternNice 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>
There was a problem hiding this 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 beforeloadTestTuples
, so a config that supplies tuples only viaTests[i].TupleFile
is incorrectly rejected.
Move the check afterloadTestTuples
, or includelen(storeData.Tests) > 0
in the condition.
🧹 Nitpick comments (3)
internal/storetest/storedata.go (1)
161-232
: File failsgofmt
The linter reports formatting issues (e.g., mixed tabs/spaces at line 227).
Rungo 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 rungofmt
on the test file
The formatter reports offences at lines 84 and 85.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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
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 |
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 |
NP, Sure I'll rebase it on Sunday. Thanks @rhamzeh |
@rhamzeh I have updated the branch for this PR, can you take a look? |
@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? |
|
There was a problem hiding this 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!
A review from someone not me is required now that I've modified it. Will ask around :) |
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
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
main
Summary by CodeRabbit
Documentation
New Features
Bug Fixes
Tests
Chores