You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test: add coverage for mixed operators metadata helpers and warning lint
Add TestMixedOperatorsMetadata to pkg/namespace/metadata_test.go covering
all code paths in HasMixedOperatorsWithoutParens, GetMixedOperatorsPosition,
and SetMixedOperatorsWithoutParens (nil metadata, empty metadata, non-permission
relation, permission with/without flag, set/clear operations, creation of new
metadata entries).
Add additional warning test cases to pkg/development/warnings_test.go for
mixed intersection+exclusion, intersection+union operator combinations,
same-operators-repeated (no warning), and relation-referencing-parent for
a non-permission relation.
name: "mixed intersection and exclusion without parentheses",
317
+
schema: `definition user {}
318
+
319
+
definition document {
320
+
relation viewer: user
321
+
relation editor: user
322
+
relation admin: user
323
+
permission view = viewer & editor - admin
324
+
}
325
+
`,
326
+
expectedWarning: &developerv1.DeveloperWarning{
327
+
Message: "Permission \"view\" mixes operators (union, intersection, exclusion) at the same level without explicit parentheses; consider adding parentheses to clarify precedence (mixed-operators-without-parentheses)",
328
+
Line: 7,
329
+
Column: 23,
330
+
SourceCode: "view",
331
+
},
332
+
},
333
+
{
334
+
name: "mixed intersection and union without parentheses",
335
+
schema: `definition user {}
336
+
337
+
definition document {
338
+
relation viewer: user
339
+
relation editor: user
340
+
relation admin: user
341
+
permission view = viewer & editor + admin
342
+
}
343
+
`,
344
+
expectedWarning: &developerv1.DeveloperWarning{
345
+
Message: "Permission \"view\" mixes operators (union, intersection, exclusion) at the same level without explicit parentheses; consider adding parentheses to clarify precedence (mixed-operators-without-parentheses)",
346
+
Line: 7,
347
+
Column: 32,
348
+
SourceCode: "view",
349
+
},
350
+
},
351
+
{
352
+
name: "same operators repeated does not warn",
353
+
schema: `definition user {}
354
+
355
+
definition document {
356
+
relation viewer: user
357
+
relation editor: user
358
+
relation admin: user
359
+
permission view = viewer + editor + admin
360
+
}
361
+
`,
362
+
expectedWarning: nil,
363
+
},
364
+
{
365
+
name: "relation name referencing parent is a relation not permission",
366
+
schema: `definition user {}
367
+
368
+
definition document {
369
+
relation viewer_document: user
370
+
permission view = viewer_document
371
+
}`,
372
+
expectedWarning: &developerv1.DeveloperWarning{
373
+
Message: "Relation \"viewer_document\" references parent type \"document\" in its name; it is recommended to drop the suffix (relation-name-references-parent)",
0 commit comments