chore: bring in spicedb and update compilation#635
Conversation
610e2cc to
1fb916b
Compare
|
Current TODOs and notes:
|
d353034 to
6dc6f3f
Compare
6dc6f3f to
47ee676
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #635 +/- ##
==========================================
+ Coverage 41.66% 42.13% +0.47%
==========================================
Files 38 38
Lines 6128 6064 -64
==========================================
+ Hits 2553 2555 +2
+ Misses 3319 3252 -67
- Partials 256 257 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
47ee676 to
32e38db
Compare
| From pastebin: | ||
| zed validate https://pastebin.com/8qU45rVK | ||
|
|
||
| From a devtools instance: |
There was a problem hiding this comment.
FYI devtools was deprecated
| ``` | ||
| --fail-on-warn treat warnings as errors during validation | ||
| --force-color force color code output even in non-tty environments | ||
| --schema-type string force validation according to specific schema syntax ("", "composable", "standard") |
There was a problem hiding this comment.
FYI big change: removing the flag
| command: []string{"zed", "validate"}, | ||
| expectFlagErrorCalled: true, | ||
| flagErrorContains: "requires at least 1 arg(s), only received 0", | ||
| expectUsageContains: "zed validate <validation_file_or_schema_file> [flags]", |
There was a problem hiding this comment.
I don't know who would want to validate more than one schema file at once, but 🤷♀️
| Schema: parsed.Schema.Schema, | ||
| Relationships: tuples, | ||
| }) | ||
| }, development.WithSourceFS(filesystem), development.WithRootFileName(filepath.Base(filename))) |
There was a problem hiding this comment.
FYI this is what allows us to validate composable schemas
|
|
||
| func outputDeveloperErrorsWithLineOffset(sb *strings.Builder, validateContents []byte, devErrors []*devinterface.DeveloperError, lineOffset int, sourceFS fs.FS) { | ||
| for _, devErr := range devErrors { | ||
| // If the error has a Path, read the contents from that file instead. |
There was a problem hiding this comment.
FYI this is what lets zed know which file contained error so it can print the contents of the context of the error
There was a problem hiding this comment.
I'm pretty sure we can get this through the DeveloperError as well, but that can be future work.
There was a problem hiding this comment.
🤔 Path is a field of DeveloperError
32e38db to
f1602c1
Compare
f1602c1 to
d6d687e
Compare
internal/cmd/validate.go
Outdated
| if fileTypeArg != "" { | ||
| switch fileTypeArg { | ||
| case "yaml": | ||
| fileType = decode.FileTypeYaml | ||
| case "zed": | ||
| fileType = decode.FileTypeZed | ||
| default: | ||
| return "", true, fmt.Errorf("invalid value \"%s\" for --type. valid options are \"zed\" and \"yaml\"", fileTypeArg) | ||
| } | ||
| } |
There was a problem hiding this comment.
Why remove this?
There was a problem hiding this comment.
we can detect the extension of the file, i don't see the need to pass in the file type by hand
There was a problem hiding this comment.
Right, my thought was just to give folks the option to do so - make the heuristics dumber (and the code simpler and more predictable) and then give folks an escape hatch where they can tell zed how to treat the file.
I'm open to disagreement with that take, though.
| if !filepath.IsLocal(schemaPath) { | ||
| return nil, fmt.Errorf("schema filepath %q must be local to where the command was invoked", schemaPath) | ||
| } | ||
|
|
||
| if d.FS == nil { | ||
| return nil, fmt.Errorf("cannot resolve schemaFile %q: no local filesystem context (remote URL?)", schemaPath) | ||
| } |
There was a problem hiding this comment.
I think we can use os.DirFS here as well - I'd think that you should be able to open one FS from another. Then we don't need to deal with IsLocal questions.
| func importCmdFunc(cmd *cobra.Command, schemaClient v1.SchemaServiceClient, relationshipsClient v1.PermissionsServiceClient, prefix string, u *url.URL) error { | ||
| prefix = strings.TrimRight(prefix, "/") | ||
| contents, err := decode.FetchURL(u) | ||
| d, err := decode.DecoderFromURL(u) |
There was a problem hiding this comment.
Why the change back to a decoder struct? What's the state that's being held in the decoder object?
There was a problem hiding this comment.
the decoder holds the fs
|
|
||
| func outputDeveloperErrorsWithLineOffset(sb *strings.Builder, validateContents []byte, devErrors []*devinterface.DeveloperError, lineOffset int, sourceFS fs.FS) { | ||
| for _, devErr := range devErrors { | ||
| // If the error has a Path, read the contents from that file instead. |
There was a problem hiding this comment.
I'm pretty sure we can get this through the DeveloperError as well, but that can be future work.
| // Only attempt YAML unmarshaling if the input looks like a YAML validation file. | ||
| if !hasYAMLSchemaKey(inputString) && !hasYAMLSchemaFileKey(inputString) && !yamlRelationshipsKeyPattern.MatchString(inputString) { | ||
| return nil, fmt.Errorf("%w: input does not appear to be a YAML validation file", ErrInvalidYamlTryZed) | ||
| } |
There was a problem hiding this comment.
Why necessary?
Does this fix the relation something: schema issue?
My thought was that we can do a relatively naive yaml parse and let the user force it if they want to.
There was a problem hiding this comment.
Why necessary?
this code was already there, no?
Does this fix the
relation something: schemaissue?
that was fixed in an old PR, and the test schema with relation named schema still passes
859759e to
8b680d4
Compare
internal/decode/decoder_test.go
Outdated
| } | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.expectedSchema, vFile.Schema.Schema) | ||
| require.Empty(t, vFile.SchemaFile) |
There was a problem hiding this comment.
I don't think this assertion is necessary so I'd rather not assert it.
| // If the file is just a schema file, we set the LineNumber offset to 0 | ||
| // for the purposes of displaying errors. | ||
| SourcePosition: spiceerrors.SourcePosition{LineNumber: 0, ColumnPosition: 1}, |
There was a problem hiding this comment.
This change means we don't need to post-hoc check whether it's a schema file we're looking at for the purposes of offsets
| data, err := os.ReadFile(filePath) //nolint:gosec // not an issue | ||
| filePath := filepath.Clean(u.Path) | ||
|
|
||
| invocationFS := os.DirFS(".") |
There was a problem hiding this comment.
Using DirFS here ensures that we don't have traversal issues (gosec) and also means that we don't have to validate locality otherwise.
8b680d4 to
665577c
Compare
| validateCmd.Flags().Bool("force-color", false, "force color code output even in non-tty environments") | ||
| validateCmd.Flags().Bool("fail-on-warn", false, "treat warnings as errors during validation") | ||
| validateCmd.Flags().String("schema-type", "", "force validation according to specific schema syntax (\"\", \"composable\", \"standard\")") | ||
| validateCmd.Flags().String("type", "", "the type of the validated file. valid options are \"zed\" and \"yaml\"") |
There was a problem hiding this comment.
| validateCmd.Flags().String("type", "", "the type of the validated file. valid options are \"zed\" and \"yaml\"") | |
| validateCmd.Flags().String("type", "", "the type of the validated file. use this when zed cannot auto-detect the format of the file properly. valid options are \"zed\" and \"yaml\"") |
Description
This PR is part of unifying the composable schema package into the tooling for a better developer experience. The key changes are:
- Import errors in composable schemas
- Nonexistent imports
- Nested composable schemas
- External schemas with escaping/errors
Testing
Unit tests