@@ -15,7 +15,6 @@ import (
1515 "github.com/spf13/cobra"
1616
1717 "github.com/authzed/spicedb/pkg/development"
18- core "github.com/authzed/spicedb/pkg/proto/core/v1"
1918 devinterface "github.com/authzed/spicedb/pkg/proto/developer/v1"
2019
2120 "github.com/authzed/zed/internal/commands"
@@ -161,34 +160,30 @@ func validateCmdFunc(cmd *cobra.Command, filenames []string) (string, bool, erro
161160
162161 filesystem := os .DirFS (parsed .RootSchemaDir )
163162
164- // This logic will use the zero value of the struct, so we don't need
165- // to do it conditionally.
166- tuples := make ([]* core.RelationTuple , 0 )
167163 totalAssertions := 0
168164 totalRelationsValidated := 0
169165
170- for _ , rel := range parsed .Relationships .Relationships {
171- tuples = append (tuples , rel .ToCoreTuple ())
172- }
173-
174- // Create the development context for each run
166+ // Create the development context for each run. If a schemaFile was used,
167+ // the schema has already been inlined by ResolveSchemaFileIfPresent; clear
168+ // SchemaFile on the copy so the new API uses the inlined schema directly
169+ // rather than trying to re-read it via fs.FS (which doesn't support ../paths).
175170 ctx := cmd .Context ()
176- devCtx , devErrs , err := development .NewDevContext (ctx , & devinterface.RequestContext {
177- Schema : parsed .Schema ,
178- Relationships : tuples ,
179- }, development .WithSourceFS (filesystem ), development .WithRootFileName (parsed .SchemaFileName ))
171+ vfForDev := * parsed .ValidationFile
172+ if vfForDev .SchemaFile != "" {
173+ vfForDev .SchemaFile = ""
174+ }
175+ yctx , devErrs , err := development .NewDevContextForValidationFile (ctx , & vfForDev ,
176+ development .WithSourceFS (filesystem ),
177+ development .WithRootFileName (parsed .SchemaFileName ))
180178 if err != nil {
181179 return "" , false , err
182180 }
183181 if devErrs != nil {
184- schemaOffset := parsed .SchemaOffset .LineNumber
185-
186- // Output errors
187- outputDeveloperErrorsWithLineOffset (toPrint , parsed .DisplayContents , devErrs .InputErrors , schemaOffset , filesystem )
182+ outputDeveloperErrors (toPrint , parsed .DisplayContents , devErrs .InputErrors , filesystem )
188183 return toPrint .String (), true , nil
189184 }
190185 // Run assertions
191- adevErrs , aerr := development .RunAllAssertions (devCtx , & parsed .Assertions )
186+ adevErrs , aerr := development .RunAllAssertions (yctx . DevContext , & yctx .Assertions )
192187 if aerr != nil {
193188 return "" , false , aerr
194189 }
@@ -199,7 +194,7 @@ func validateCmdFunc(cmd *cobra.Command, filenames []string) (string, bool, erro
199194 successfullyValidatedFiles ++
200195
201196 // Run expected relations for file
202- _ , erDevErrs , rerr := development .RunValidation (devCtx , & parsed .ExpectedRelations )
197+ _ , erDevErrs , rerr := development .RunValidation (yctx . DevContext , & yctx .ExpectedRelations )
203198 if rerr != nil {
204199 return "" , false , rerr
205200 }
@@ -208,7 +203,7 @@ func validateCmdFunc(cmd *cobra.Command, filenames []string) (string, bool, erro
208203 return toPrint .String (), true , nil
209204 }
210205 // Print out any warnings for file
211- warnings , err := development .GetWarnings (ctx , devCtx )
206+ warnings , err := development .GetWarnings (ctx , yctx . DevContext )
212207 if err != nil {
213208 return "" , false , err
214209 }
@@ -227,11 +222,11 @@ func validateCmdFunc(cmd *cobra.Command, filenames []string) (string, bool, erro
227222 } else {
228223 toPrint .WriteString (success ())
229224 }
230- totalAssertions += len (parsed .Assertions .AssertTrue ) + len (parsed .Assertions .AssertFalse )
231- totalRelationsValidated += len (parsed .ExpectedRelations .ValidationMap )
225+ totalAssertions += len (yctx .Assertions .AssertTrue ) + len (yctx .Assertions .AssertFalse )
226+ totalRelationsValidated += len (yctx .ExpectedRelations .ValidationMap )
232227
233228 fmt .Fprintf (toPrint , " - %d relationships loaded, %d assertions run, %d expected relations validated\n " ,
234- len (tuples ),
229+ len (vfForDev . Relationships . Relationships ),
235230 totalAssertions ,
236231 totalRelationsValidated )
237232 }
@@ -266,31 +261,28 @@ func outputForLine(sb *strings.Builder, validateContents []byte, oneIndexedLineN
266261}
267262
268263func outputDeveloperErrors (sb * strings.Builder , validateContents []byte , devErrors []* devinterface.DeveloperError , sourceFS fs.FS ) {
269- outputDeveloperErrorsWithLineOffset (sb , validateContents , devErrors , 0 , sourceFS )
270- }
271-
272- func outputDeveloperErrorsWithLineOffset (sb * strings.Builder , validateContents []byte , devErrors []* devinterface.DeveloperError , lineOffset int , sourceFS fs.FS ) {
273264 for _ , devErr := range devErrors {
274- // If the error has a Path, read the contents from that file instead.
265+ contents := validateContents
275266 if len (devErr .Path ) > 0 {
276267 fileContents , err := fs .ReadFile (sourceFS , devErr .Path [0 ])
277268 if err == nil {
278- validateContents = fileContents
269+ contents = fileContents
279270 }
280271 }
281- lines := strings .Split (string (validateContents ), "\n " )
282- outputDeveloperError (sb , devErr , lines , lineOffset )
272+
273+ lines := strings .Split (string (contents ), "\n " )
274+ outputDeveloperError (sb , devErr , lines )
283275 }
284276}
285277
286- func outputDeveloperError (sb * strings.Builder , devError * devinterface.DeveloperError , lines []string , lineOffset int ) {
278+ func outputDeveloperError (sb * strings.Builder , devError * devinterface.DeveloperError , lines []string ) {
287279 errorSource := devError .Context
288280 if len (devError .Path ) > 0 && devError .Path [0 ] != "" {
289281 errorSource = devError .Path [0 ]
290282 }
291283 lineContext := fmt .Sprintf ("parse error in `%s`, line %d, column %d:" , errorSource , devError .Line , devError .Column )
292284 fmt .Fprintf (sb , "%s%s %s\n " , errorPrefix (), lineContext , errorMessageStyle ().Render (devError .Message ))
293- errorLineNumber := int (devError .Line ) - 1 + lineOffset // devError.Line is 1-indexed
285+ errorLineNumber := int (devError .Line ) - 1 // devError.Line is 1-indexed
294286 for i := errorLineNumber - 3 ; i < errorLineNumber + 3 ; i ++ {
295287 if i == errorLineNumber {
296288 renderLine (sb , lines , i , devError .Context , errorLineNumber , - 1 )
0 commit comments