diff --git a/explorer/mquery.go b/explorer/mquery.go index 57f31505fa..20af780d43 100644 --- a/explorer/mquery.go +++ b/explorer/mquery.go @@ -288,12 +288,16 @@ func (m *Mquery) RefreshAsFilter(mrn string, schema llx.Schema) (*llx.CodeBundle return nil, errors.New("filters require MQL snippets (no compiled code generated)") } + checksumInvalidated := false if mrn != "" { m.Mrn = mrn + "/filter/" + m.CodeId + checksumInvalidated = true } - if m.Title == "" { - m.Title = m.Query + if checksumInvalidated { + if err := m.RefreshChecksum(context.Background(), schema, nil); err != nil { + return nil, err + } } return bundle, nil diff --git a/explorer/mquery_test.go b/explorer/mquery_test.go index a95336baff..6abd696145 100644 --- a/explorer/mquery_test.go +++ b/explorer/mquery_test.go @@ -13,6 +13,24 @@ import ( "go.mondoo.com/cnquery/v9/providers-sdk/v1/testutils" ) +func TestMquery_RefreshAsAssetFilterStableChecksum(t *testing.T) { + m := &Mquery{ + Mql: "true", + Uid: "my-id0", + } + + x := testutils.LinuxMock() + + _, err := m.RefreshAsFilter("//owner/me", x.Schema()) + require.NoError(t, err) + assert.Equal(t, "//owner/me/filter/"+m.CodeId, m.Mrn) + + cs := m.Checksum + _, err = m.RefreshAsFilter("//owner/me", x.Schema()) + require.NoError(t, err) + assert.Equal(t, cs, m.Checksum) +} + func TestMquery_Refresh(t *testing.T) { a := &Mquery{ Mql: "mondoo.version != props.world",