Skip to content

Commit

Permalink
🧹 enable bool assertions by default (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaym authored Oct 18, 2022
1 parent d3a8a41 commit 78ec8dc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
2 changes: 0 additions & 2 deletions policy/executor/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func ExecuteResolvedPolicy(schema *resources.Schema, runtime *resources.Runtime,
builder := builderFromResolvedPolicy(resolvedPolicy)
builder.AddDatapointCollector(collector)
builder.AddScoreCollector(collector)
builder.WithFeatureBoolAssertions(features.IsActive(cnquery.BoolAssertions))
if progressFn != nil {
builder.WithProgressReporter(progressFn)
}
Expand Down Expand Up @@ -95,7 +94,6 @@ func ExecuteFilterQueries(schema *resources.Schema, runtime *resources.Runtime,

func ExecuteQuery(schema *resources.Schema, runtime *resources.Runtime, codeBundle *llx.CodeBundle, props map[string]*llx.Primitive, features cnquery.Features) (*policy.Score, map[string]*llx.RawResult, error) {
builder := internal.NewBuilder()
builder.WithFeatureBoolAssertions(features.IsActive(cnquery.BoolAssertions))

builder.AddQuery(codeBundle, nil, props)
for _, checksum := range internal.CodepointChecksums(codeBundle) {
Expand Down
15 changes: 4 additions & 11 deletions policy/executor/internal/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ type GraphBuilder struct {
// queryTimeout is the amount of time to wait for the underlying lumi
// runtime to send all the expected datapoints.
queryTimeout time.Duration

featureBoolAssertions bool
}

func NewBuilder() *GraphBuilder {
Expand Down Expand Up @@ -133,10 +131,6 @@ func (b *GraphBuilder) WithQueryTimeout(timeout time.Duration) {
b.queryTimeout = timeout
}

func (b *GraphBuilder) WithFeatureBoolAssertions(featureBoolAssertions bool) {
b.featureBoolAssertions = featureBoolAssertions
}

func (b *GraphBuilder) Build(schema *resources.Schema, runtime *resources.Runtime, assetMrn string) (*GraphExecutor, error) {
resultChan := make(chan *llx.RawResult, 128)

Expand Down Expand Up @@ -192,7 +186,7 @@ func (b *GraphBuilder) Build(schema *resources.Schema, runtime *resources.Runtim
} else {
unrunnableQueries = append(unrunnableQueries, q)
}
ge.addReportingQueryNode(queryID, q, b.featureBoolAssertions)
ge.addReportingQueryNode(queryID, q)
}

scoresToCollect := make([]string, len(b.collectScoreQrIDs))
Expand Down Expand Up @@ -350,16 +344,15 @@ func (ge *GraphExecutor) addExecutionQueryNode(queryID string, q query, resolved
ge.nodes[n.id] = n
}

func (ge *GraphExecutor) addReportingQueryNode(queryID string, q query, featureBoolAssertions bool) {
func (ge *GraphExecutor) addReportingQueryNode(queryID string, q query) {
n, ok := ge.nodes[NodeID(queryID)]
if ok {
return
}

nodeData := &ReportingQueryNodeData{
results: map[string]*DataResult{},
queryID: queryID,
featureBoolAssertions: featureBoolAssertions,
results: map[string]*DataResult{},
queryID: queryID,
}

n = &Node{
Expand Down
20 changes: 6 additions & 14 deletions policy/executor/internal/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ func (nodeData *DatapointNodeData) recalculate() *envelope {

// ReportingQueryNodeData is the data for queries of type ReportingQueryNodeType.
type ReportingQueryNodeData struct {
featureBoolAssertions bool
queryID string
queryID string

results map[string]*DataResult
invalidated bool
Expand Down Expand Up @@ -338,19 +337,12 @@ func (nodeData *ReportingQueryNodeData) score() *policy.Score {
continue
}

if nodeData.featureBoolAssertions {
success, valid := cur.Data.IsSuccess()
if !success && valid {
allTrue = false
}
if valid {
allSkipped = false
}
} else {
success, valid := cur.Data.IsSuccess()
if !success && valid {
allTrue = false
}
if valid {
allSkipped = false
if truthy, _ := cur.Data.IsTruthy(); !truthy {
allTrue = false
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions policy/executor/internal/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,10 @@ func TestReportingQueryNode(t *testing.T) {
})
}

func TestReportingQueryNode_FeatureBoolAssertions(t *testing.T) {
func TestReportingQueryNode_BoolAssertion(t *testing.T) {
newNodeData := func() *ReportingQueryNodeData {
data := &ReportingQueryNodeData{
queryID: "testqueryid",
featureBoolAssertions: true,
queryID: "testqueryid",
}
return data
}
Expand Down

0 comments on commit 78ec8dc

Please sign in to comment.