Skip to content

Conversation

@tstirrat15
Copy link
Contributor

@tstirrat15 tstirrat15 commented Dec 19, 2025

Reverts #1515
Fixes #338
Continues #1511

Description

The reason we reverted #1511 is that we'd break schemas where folks were using self as an actual relation name. We now have a mechanism to work around that, which is use directives. This updates the code from #1511 to introduce a use self directive which enables this feature at the schema level, disallows the use of self as a normal relation name, and then compiles accordingly.

TODO

Changes

Will annotate. See commits after the first one for the changes required for the use directive.

Testing

Review. See that tests pass.

@github-actions github-actions bot added area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Dec 19, 2025
@tstirrat15 tstirrat15 force-pushed the reopen-self-relation-implementation branch from 68afbcc to 88b7ebc Compare December 19, 2025 22:43
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

❌ Patch coverage is 1.85185% with 159 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.56%. Comparing base (5243b57) to head (1307604).

Files with missing lines Patch % Lines
pkg/query/self.go 0.00% 41 Missing ⚠️
internal/graph/expand.go 0.00% 19 Missing ⚠️
internal/graph/check.go 0.00% 15 Missing ⚠️
internal/graph/lookupresources2.go 0.00% 15 Missing ⚠️
internal/graph/lookupsubjects.go 0.00% 15 Missing ⚠️
pkg/schemadsl/parser/parser.go 0.00% 9 Missing ⚠️
pkg/schema/reachabilitygraphbuilder.go 11.12% 8 Missing ⚠️
pkg/schema/reachabilitygraph.go 0.00% 6 Missing ⚠️
pkg/schema/v2/operations.go 0.00% 5 Missing ⚠️
pkg/schemadsl/lexer/flags.go 0.00% 5 Missing ⚠️
... and 8 more

❌ Your project check has failed because the head coverage (39.56%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (5243b57) and HEAD (1307604). Click for more details.

HEAD has 27 uploads less than BASE
Flag BASE (5243b57) HEAD (1307604)
50 23
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2785       +/-   ##
===========================================
- Coverage   78.50%   39.56%   -38.94%     
===========================================
  Files         458      414       -44     
  Lines       44253    40864     -3389     
===========================================
- Hits        34736    16163    -18573     
- Misses       6698    22828    +16130     
+ Partials     2819     1873      -946     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tstirrat15 tstirrat15 force-pushed the reopen-self-relation-implementation branch from 88b7ebc to 9885a51 Compare December 20, 2025 00:01
@github-actions github-actions bot added the area/dispatch Affects dispatching of requests label Dec 20, 2025
@miparnisari miparnisari force-pushed the reopen-self-relation-implementation branch 6 times, most recently from 4fdb542 to 1230ce6 Compare December 31, 2025 06:02
Copy link
Contributor Author

@tstirrat15 tstirrat15 left a comment

Choose a reason for hiding this comment

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

See comments

Comment on lines +157 to +158
case core.ReachabilityEntrypoint_SELF_ENTRYPOINT:
containingRelation := entrypoint.ContainingRelationOrPermission()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't completely understand this part of the implementation. Where is the self logic here? Or is it actually implemented elsewhere?

}
definition resource {
relation viewer: user#me_or_related | user
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we refactor this to use an arrow, or is there something important about this being a userset?

Comment on lines +1304 to +1305
withTenantPrefix,
`definition expressioned {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why don't these need the use flags?


// Look for `use somefeature`
if nextToken.Kind == TokenTypeIdentifier {
if nextToken.Kind == TokenTypeIdentifier || nextToken.Kind == TokenTypeKeyword {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why was this necessary? Is it because we've already reserved self?

We'll probably refactor this when we go and collapse composableschemadsl and schemadsl.


return lexeme, false
},
// TODO add typechecking flag?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

context?

Comment on lines +713 to +714
if !p.isKeyword("self") {
return nil, false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems like it's not necessary based on how this function is invoked. Is it worth keeping just so that the caller doesn't have to know that?


node := p.startNode(dslshape.NodeTypeSelfExpression)
p.consumeKeyword("self")
defer p.mustFinishNode()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nit, move up

Comment on lines 175 to 176
case *schema.SelfReference:
return NewEmptyFixedIterator(), nil // TODO is this ok?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to update this - we're not actually checking the self relation because we're not asserting that a user is me_or_related to themselves.

@tstirrat15 tstirrat15 marked this pull request as ready for review January 7, 2026 20:38
@tstirrat15 tstirrat15 requested a review from a team as a code owner January 7, 2026 20:38
@tstirrat15 tstirrat15 force-pushed the reopen-self-relation-implementation branch from 4fcd516 to 1307604 Compare January 7, 2026 20:38
}
}
// Return the empty set if none of the resources matches
return func(yield func(Path, error) bool) {}, nil
Copy link
Contributor

@barakmich barakmich Jan 7, 2026

Choose a reason for hiding this comment

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

There's a helper for this (EmptyPathSeq()) but I went to find it and found more copies of this; so this is fine and I'll do a chore on it.

Copy link
Contributor

@barakmich barakmich left a comment

Choose a reason for hiding this comment

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

Looks good from my end -- I checked pkg/query and pkg/schema/v2 thoroughly, and gave the parser a glance from my recollection of it

@tstirrat15
Copy link
Contributor Author

For anyone following along:

The integration tests are broken because the expected relations portion of the integration test harness makes an assumption that it can calculate all accessibility information based on the test relations defined in the validation file. That no longer holds for self-defined permissions, because they're fully synthetic and aren't represented by a relation.

Barak and I talked about how we might fix it both in the short term and the long term; I'd like to revisit that conversation on Monday and figure out whether we want to just get this PR through or come up with a better way of structuring the integration tests.

@tstirrat15 tstirrat15 marked this pull request as draft January 8, 2026 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dispatch Affects dispatching of requests area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for this to allow checks on resources with themselves as the subject

4 participants