Allow omitting def in profile rule definitions#6137
Conversation
Co-authored-by: evankanderson <7959095+evankanderson@users.noreply.github.com>
def in profile rule definitions
|
This is going to need some manual testing. (And coveralls.io is down). |
|
I tested this on a staging instance; charmingly, the validation about invalid values actually happens on the client side, so you need a new |
evankanderson
left a comment
There was a problem hiding this comment.
Tested this manually; the validation happens both client and server side, so a new client is needed. Will probably merge on Monday.
evankanderson
left a comment
There was a problem hiding this comment.
This also needs to test that Eval in pkg/engine/v1/rtengine can properly handle if ruleDef is null rather than an empty map.
Co-authored-by: evankanderson <7959095+evankanderson@users.noreply.github.com>
Added a |
evankanderson
left a comment
There was a problem hiding this comment.
Verified that this works with schema validation using the following ruletype and profile:
test-rule-schema.yaml
version: v1
type: rule-type
name: test-rule-schema
display_name: Test rules with required schema fields
context:
provider: github
description: required
guidance: required
def:
in_entity: repository
rule_schema:
type: object
properties:
required_field:
type: string
# No default set
required: ["required_field"]
ingest:
type: rest
rest:
endpoint: "/repos/{{.Entity.Owner}}/{{.Entity.Name}}"
parse: json
eval:
type: jq
jq:
- ingested:
def: '.delete_branch_on_merge'
constant: truepolicy.yaml
version: v1
type: profile
name: test-schema
context:
provider: github
repository:
- type: test-rule-schema|
@JAORMX, it looks like I need your approval again. Sorry for the go-round, but I wanted to verify that this didn't have negative effects, and the extra test case along with manual testing makes me more confident. |
Profile rules with no configurable options required
def: {}as a no-op placeholder. A rule with nodefshould be valid and treated as an empty object.Changes:
validators.go: Removed the nil check invalidateRule()that rejected rules with a missingdef(the TODO comment there already acknowledged this intent)util_test.go: Updated the "invalid with no definition" test case to expect success, confirming that omittingdefproduces a rule with a nilDeffield (equivalent to{})pkg/engine/v1/rtengine/engine_test.go: Added a"nil ruleDef treated as empty map"test case to confirm thatEvalhandles anilruleDefcorrectly end-to-endUsers can now write:
instead of requiring:
(*structpb.Struct).AsMap()safely returns an empty map on a nil receiver, so all downstream schema validation continues to work correctly. TheRuleTypeEngine.Evalalready guards schema validation withif ruleDef != nil, and the rego evaluator handles nil input gracefully.Testing
TestParseYAMLto assert a profile with nodefparses successfully and produces a nilDeffield on the ruleTestGitProvider/nil_ruleDef_treated_as_empty_mapinpkg/engine/v1/rtengine/engine_test.goto verifyEvalworks correctly whenruleDefisnilgo test ./pkg/profiles/... ./pkg/api/protobuf/go/minder/v1/... ./pkg/engine/v1/rtengine/...— all tests passOriginal prompt
nildefin profile definition #4817💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.