Conversation
938d746 to
b6a32f2
Compare
| var relationNotFoundError sharederrors.UnknownRelationError | ||
|
|
||
| var compilerError compiler.BaseCompilerError | ||
| var sourceError *spiceerrors.WithSourceError |
There was a problem hiding this comment.
I'm pretty sure this was wrong?
There was a problem hiding this comment.
Nvm it was right. I'm pretty confused as to why it is the way it is.
| // Compile compilers the input schema into a set of namespace definition protos. | ||
| func Compile(schema InputSchema, prefix ObjectPrefixOption, opts ...Option) (*CompiledSchema, error) { | ||
| cfg := &config{ | ||
| allowedFlags: mapz.NewSet[string](expirationFlag, selfFlag), |
There was a problem hiding this comment.
My LSP marked this as unnecessary
| opts := strings.Join(slices.Sorted(maps.Keys(lexer.Flags)), ", ") | ||
| p.emitErrorf("Unknown use flag: `%s`. Options are: %s", useFlag, opts) |
There was a problem hiding this comment.
Porting this over from composableschemadsl - should give us a stable output order.
| }, | ||
| }, | ||
| { | ||
| "duplicate use of expiration pragmas", |
There was a problem hiding this comment.
uses should be declared per-file, and should be treated as file-local, so the compiler shouldn't take issue with having multiple of them in the same file.
| present, err := validateImportPresence(cfg.allowedFlags.Has(importFlag), root) | ||
| if err != nil { | ||
| // This condition should basically always be satisfied (we trigger errors off of the node), | ||
| // but we're defensive here in case the implementation changes. | ||
| var withNodeError withNodeError | ||
| if errors.As(err, &withNodeError) { | ||
| return nil, toContextError(withNodeError.Error(), withNodeError.errorSourceCode, withNodeError.node, mapper) | ||
| } | ||
| } |
There was a problem hiding this comment.
This is net-new - this is how we ensure that import compilation isn't attempted if it's disallowed.
| } | ||
| } | ||
|
|
||
| if present { |
There was a problem hiding this comment.
And then because we have information about whether imports are present, we can either run this or not - it's a small optimization but why not
5619cfd to
47395a4
Compare
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (74.49%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2919 +/- ##
===========================================
+ Coverage 49.06% 74.49% +25.44%
===========================================
Files 420 488 +68
Lines 54148 60397 +6249
===========================================
+ Hits 26560 44989 +18429
+ Misses 24871 12258 -12613
- Partials 2717 3150 +433 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
47395a4 to
1bb8a7d
Compare
| @@ -0,0 +1,2 @@ | |||
| // caveat | |||
There was a problem hiding this comment.
if i import a file that has one caveat, does it work? or is imports only for definitions 🤔
There was a problem hiding this comment.
Imports is for anything - caveats, definitions, partials
There was a problem hiding this comment.
oh ok; i don't think i've seen a test where the imports is for caveats
| @@ -0,0 +1,8 @@ | |||
| use import | |||
|
|
|||
| import "definitions/user/user.zed" | |||
There was a problem hiding this comment.
do we have a test somewhere for a root with two imports, and both have the same definition sometype with different relations? it should error out
There was a problem hiding this comment.
No, but I can add that
cdfea10 to
6bc1e5e
Compare
| }, compiler.AllowUnprefixedObjectType(), | ||
| compiler.SourceFolder(sourceFolder)) | ||
|
|
||
| require.ErrorContains(t, err, "AAAAA") |
86fa9b4 to
4a8d83c
Compare
barakmich
left a comment
There was a problem hiding this comment.
LGTM with a few thoughts, mostly just positive comments
| func TestSchemaWriteImportsDisallowed(t *testing.T) { | ||
| conn, cleanup, _, _ := testserver.NewTestServer(require.New(t), 0, memdb.DisableGC, true, tf.EmptyDatastore) | ||
| t.Cleanup(cleanup) | ||
| client := v1.NewSchemaServiceClient(conn) | ||
|
|
||
| _, err := client.WriteSchema(t.Context(), &v1.WriteSchemaRequest{ | ||
| Schema: ` | ||
| use import |
There was a problem hiding this comment.
This is correct, in the context of the WriteSchema API -- however, I think that part of the overarching problem is that we don't have a WriteCompiledSchema API or similar
|
|
||
| Every folder should have a `root.zed`. This is the target for compilation. | ||
|
|
||
| Every folder will have an `expected.zed`, which is the output of the compilation process. |
There was a problem hiding this comment.
The corollary to a WriteCompiledSchema API is that every folder would have a generated expected.proto. Again, farther in the future...
|
|
||
| // In an import context, this is the FS containing | ||
| // the importing schema (as opposed to imported schemas) | ||
| sourceFS fs.FS |
There was a problem hiding this comment.
I think I ended up here accidentally 😅
| importerTests := []importerTest{ | ||
| {"simple local import", "simple-local"}, | ||
| {"simple local import with transitive hop", "simple-local-with-hop"}, | ||
| {"nested local import", "nested-local"}, | ||
| {"nested local import with transitive hop", "nested-local-with-hop"}, | ||
| {"nested local two layers deep import", "nested-two-layer-local"}, | ||
| {"diamond-shaped imports are fine", "diamond-shaped"}, | ||
| {"multiple use directives are fine", "multiple-use-directives"}, | ||
| {"many imports are correctly resolved", "many-imports"}, | ||
| } |
There was a problem hiding this comment.
If you're feeling saucy, this could be collected by walking the directory (and omitting the name field), but I don't feel strongly to do so either way.
It does match pkg/schemadsl/parser/parser_test.go though so there's that too
There was a problem hiding this comment.
Yeah, and the other part is that I'd then need a convention for negative tests (of which there are two or three). I found that it was easier to be explicit.
Co-authored-by: Maria Ines Parnisari <maria.ines.parnisari@authzed.com>
4a8d83c to
e433ebd
Compare
Description
Part of the puzzle of folding
composableschemadslintoschemadsl. This implementsimportlogic behind auseflag.Changes
composableschemadslusebehavior (expiration-usageor whatever it's called)importstatements are disallowed in a schema written toWriteSchemaTesting
Review. See that tests pass.