From b704344688b8d55af19b08010d206696090a00d2 Mon Sep 17 00:00:00 2001 From: Ben Kalmus Date: Tue, 9 Sep 2025 03:31:48 +0100 Subject: [PATCH 1/3] update metadata and external injection tests --- .../composition-full/putComposition.json | 151 +++++++++++++ .../composition-full/putCompositionRule.json | 198 ++++++++++++++++++ .../CTS/requests/composition-full/search.json | 14 +- 3 files changed, 361 insertions(+), 2 deletions(-) diff --git a/tests/CTS/requests/composition-full/putComposition.json b/tests/CTS/requests/composition-full/putComposition.json index af1874b2118..f0434ecc91b 100644 --- a/tests/CTS/requests/composition-full/putComposition.json +++ b/tests/CTS/requests/composition-full/putComposition.json @@ -62,6 +62,7 @@ } } }, + { "parameters": { "compositionID": "my-external-injection-compo", @@ -132,5 +133,155 @@ } } } + }, + + { + "parameters": { + "compositionID": "my-metadata-compo", + "composition": { + "objectID": "my-metadata-compo", + "name": "my composition", + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "foo", + "params": { "filters": "brand:adidas" } + } + } + }, + "injectedItems": [ + { + "key": "injectedItem1", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:adidas" + } + } + }, + "position": 2, + "length": 1, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + }, + { + "key": "externalItem", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:puma" + } + } + }, + "position": 5, + "length": 5, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + } + ] + } + } + } + }, + "request": { + "path": "/1/compositions/my-metadata-compo", + "method": "PUT", + "body": { + "objectID": "my-metadata-compo", + "name": "my composition", + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "foo", + "params": { "filters": "brand:adidas" } + } + } + }, + "injectedItems": [ + { + "key": "injectedItem1", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:adidas" + } + } + }, + "position": 2, + "length": 1, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + }, + { + "key": "externalItem", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:puma" + } + } + }, + "position": 5, + "length": 5, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + } + ] + } + } + } + } } ] diff --git a/tests/CTS/requests/composition-full/putCompositionRule.json b/tests/CTS/requests/composition-full/putCompositionRule.json index ddb6ffaed4b..f4149485943 100644 --- a/tests/CTS/requests/composition-full/putCompositionRule.json +++ b/tests/CTS/requests/composition-full/putCompositionRule.json @@ -76,5 +76,203 @@ } } } + }, + + { + "parameters": { + "compositionID": "compositionID", + "objectID": "ruleID", + "compositionRule": { + "objectID": "ruleID", + "conditions": [ + { + "anchoring": "is", + "pattern": "test" + } + ], + "consequence": { + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "foo" + } + } + }, + "injectedItems": [ + { + "key": "injectedItem1", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:adidas" + } + } + }, + "position": 2, + "length": 1, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + } + ] + } + } + } + } + }, + "request": { + "path": "/1/compositions/compositionID/rules/ruleID", + "method": "PUT", + "body": { + "objectID": "ruleID", + "conditions": [ + { + "anchoring": "is", + "pattern": "test" + } + ], + "consequence": { + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "foo" + } + } + }, + "injectedItems": [ + { + "key": "injectedItem1", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:adidas" + } + } + }, + "position": 2, + "length": 1, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + } + ] + } + } + } + } + } + }, + + { + "parameters": { + "compositionID": "compositionID", + "objectID": "ruleID", + "compositionRule": { + "objectID": "ruleID", + "description": "my description", + "tags": ["tag1", "tag2"], + "enabled": true, + "validity": [{ "from": 1704063600, "until": 1704083600 }], + "conditions": [ + { "anchoring": "contains", "pattern": "harry" }, + { "anchoring": "contains", "pattern": "potter" } + ], + "consequence": { + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "my-index", + "params": { "filters": "brand:adidas" } + } + } + }, + "injectedItems": [ + { + "key": "injectedItem", + "source": { + "search": { + "index": "my-index", + "params": { "filters": "brand:adidas" } + } + }, + "position": 0, + "length": 3 + } + ] + } + } + } + } + }, + "request": { + "path": "/1/compositions/compositionID/rules/ruleID", + "method": "PUT", + "body": { + "objectID": "ruleID", + "description": "my description", + "tags": ["tag1", "tag2"], + "enabled": true, + "validity": [{ "from": 1704063600, "until": 1704083600 }], + "conditions": [ + { "anchoring": "contains", "pattern": "harry" }, + { "anchoring": "contains", "pattern": "potter" } + ], + "consequence": { + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "my-index", + "params": { "filters": "brand:adidas" } + } + } + }, + "injectedItems": [ + { + "key": "injectedItem", + "source": { + "search": { + "index": "my-index", + "params": { "filters": "brand:adidas" } + } + }, + "position": 0, + "length": 3 + } + ] + } + } + } + } + } } ] diff --git a/tests/CTS/requests/composition-full/search.json b/tests/CTS/requests/composition-full/search.json index 367fd9378ac..6ca8776a0c7 100644 --- a/tests/CTS/requests/composition-full/search.json +++ b/tests/CTS/requests/composition-full/search.json @@ -29,7 +29,12 @@ { "objectID": "my-object-2", "metadata": { - "my-key": "my-value" + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} } } ] @@ -53,7 +58,12 @@ { "objectID": "my-object-2", "metadata": { - "my-key": "my-value" + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} } } ] From 08563ef97011e1f68c865cc9fe979ea0b841edcc Mon Sep 17 00:00:00 2001 From: Ben Kalmus Date: Tue, 9 Sep 2025 09:29:50 +0100 Subject: [PATCH 2/3] add additional tests --- .../composition-full/multipleBatch.json | 244 ++++++++++++++++++ .../composition-full/putCompositionRule.json | 36 +-- .../requests/composition-full/saveRules.json | 226 ++++++++++++++++ 3 files changed, 489 insertions(+), 17 deletions(-) diff --git a/tests/CTS/requests/composition-full/multipleBatch.json b/tests/CTS/requests/composition-full/multipleBatch.json index 52bcd79e03a..413b022be9f 100644 --- a/tests/CTS/requests/composition-full/multipleBatch.json +++ b/tests/CTS/requests/composition-full/multipleBatch.json @@ -62,5 +62,249 @@ ] } } + }, + + { + "parameters": { + "requests": [ + { + "action": "upsert", + "body": { + "objectID": "my-external-injection-compo", + "name": "my first composition", + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "foo" + } + } + }, + "injectedItems": [ + { + "key": "injectedItem1", + "source": { + "external": { + "index": "foo", + "ordering": "userDefined", + "params": { + "filters": "brand:adidas" + } + } + }, + "position": 2, + "length": 1 + } + ] + } + } + } + } + ] + }, + "request": { + "path": "/1/compositions/*/batch", + "method": "POST", + "body": { + "requests": [ + { + "action": "upsert", + "body": { + "objectID": "my-external-injection-compo", + "name": "my first composition", + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "foo" + } + } + }, + "injectedItems": [ + { + "key": "injectedItem1", + "source": { + "external": { + "index": "foo", + "ordering": "userDefined", + "params": { + "filters": "brand:adidas" + } + } + }, + "position": 2, + "length": 1 + } + ] + } + } + } + } + ] + } + } + }, + + { + "parameters": { + "requests": [ + { + "action": "upsert", + "body": { + "objectID": "my-metadata-compo", + "name": "my composition", + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "foo", + "params": { "filters": "brand:adidas" } + } + } + }, + "injectedItems": [ + { + "key": "injectedItem1", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:adidas" + } + } + }, + "position": 2, + "length": 1, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + }, + { + "key": "externalItem", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:puma" + } + } + }, + "position": 5, + "length": 5, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + } + ] + } + } + } + } + ] + }, + "request": { + "path": "/1/compositions/*/batch", + "method": "POST", + "body": { + "requests": [ + { + "action": "upsert", + "body": { + "objectID": "my-metadata-compo", + "name": "my composition", + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "foo", + "params": { "filters": "brand:adidas" } + } + } + }, + "injectedItems": [ + { + "key": "injectedItem1", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:adidas" + } + } + }, + "position": 2, + "length": 1, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + }, + { + "key": "externalItem", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:puma" + } + } + }, + "position": 5, + "length": 5, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + } + ] + } + } + } + } + ] + } + } } ] diff --git a/tests/CTS/requests/composition-full/putCompositionRule.json b/tests/CTS/requests/composition-full/putCompositionRule.json index f4149485943..30b692e9370 100644 --- a/tests/CTS/requests/composition-full/putCompositionRule.json +++ b/tests/CTS/requests/composition-full/putCompositionRule.json @@ -1,10 +1,10 @@ [ { "parameters": { - "compositionID": "1234", - "objectID": "5678", + "compositionID": "compositionID", + "objectID": "ruleID", "compositionRule": { - "objectID": "5678", + "objectID": "ruleID", "conditions": [ { "anchoring": "is", @@ -39,10 +39,10 @@ } }, "request": { - "path": "/1/compositions/1234/rules/5678", + "path": "/1/compositions/compositionID/rules/ruleID", "method": "PUT", "body": { - "objectID": "5678", + "objectID": "ruleID", "conditions": [ { "anchoring": "is", @@ -81,9 +81,9 @@ { "parameters": { "compositionID": "compositionID", - "objectID": "ruleID", + "objectID": "rule-with-metadata", "compositionRule": { - "objectID": "ruleID", + "objectID": "rule-with-metadata", "conditions": [ { "anchoring": "is", @@ -134,10 +134,10 @@ } }, "request": { - "path": "/1/compositions/compositionID/rules/ruleID", + "path": "/1/compositions/compositionID/rules/rule-with-metadata", "method": "PUT", "body": { - "objectID": "ruleID", + "objectID": "rule-with-metadata", "conditions": [ { "anchoring": "is", @@ -192,9 +192,9 @@ { "parameters": { "compositionID": "compositionID", - "objectID": "ruleID", + "objectID": "rule-with-exernal-source", "compositionRule": { - "objectID": "ruleID", + "objectID": "rule-with-exernal-source", "description": "my description", "tags": ["tag1", "tag2"], "enabled": true, @@ -218,9 +218,10 @@ { "key": "injectedItem", "source": { - "search": { + "external": { "index": "my-index", - "params": { "filters": "brand:adidas" } + "params": { "filters": "brand:adidas" }, + "ordering": "userDefined" } }, "position": 0, @@ -233,10 +234,10 @@ } }, "request": { - "path": "/1/compositions/compositionID/rules/ruleID", + "path": "/1/compositions/compositionID/rules/rule-with-exernal-source", "method": "PUT", "body": { - "objectID": "ruleID", + "objectID": "rule-with-exernal-source", "description": "my description", "tags": ["tag1", "tag2"], "enabled": true, @@ -260,9 +261,10 @@ { "key": "injectedItem", "source": { - "search": { + "external": { "index": "my-index", - "params": { "filters": "brand:adidas" } + "params": { "filters": "brand:adidas" }, + "ordering": "userDefined" } }, "position": 0, diff --git a/tests/CTS/requests/composition-full/saveRules.json b/tests/CTS/requests/composition-full/saveRules.json index 1cafbabd0e8..beee5baecc8 100644 --- a/tests/CTS/requests/composition-full/saveRules.json +++ b/tests/CTS/requests/composition-full/saveRules.json @@ -63,5 +63,231 @@ ] } } + }, + + { + "parameters": { + "compositionID": "rule-with-metadata", + "rules": { + "requests": [ + { + "action": "upsert", + "body": { + "objectID": "rule-with-metadata", + "conditions": [ + { + "anchoring": "is", + "pattern": "test" + } + ], + "consequence": { + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "foo" + } + } + }, + "injectedItems": [ + { + "key": "injectedItem1", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:adidas" + } + } + }, + "position": 2, + "length": 1, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + } + ] + } + } + } + } + } + ] + } + }, + "request": { + "path": "/1/compositions/rule-with-metadata/rules/batch", + "method": "POST", + "body": { + "requests": [ + { + "action": "upsert", + "body": { + "objectID": "rule-with-metadata", + "conditions": [ + { + "anchoring": "is", + "pattern": "test" + } + ], + "consequence": { + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "foo" + } + } + }, + "injectedItems": [ + { + "key": "injectedItem1", + "source": { + "search": { + "index": "foo", + "params": { + "filters": "brand:adidas" + } + } + }, + "position": 2, + "length": 1, + "metadata": { + "hits": { + "addItemKey": true, + "extra": { + "my-string": "string", + "my-bool": true, + "my-number": 42, + "my-object": { "sub-key": "sub-value" }, + "my-array": [1, 2, 3], + "my-empty-object": {} + } + } + } + } + ] + } + } + } + } + } + ] + } + } + }, + + { + "parameters": { + "compositionID": "rule-with-exernal-source", + "rules": { + "requests": [ + { + "action": "upsert", + "body": { + "objectID": "rule-with-exernal-source", + "description": "my description", + "tags": ["tag1", "tag2"], + "enabled": true, + "validity": [{ "from": 1704063600, "until": 1704083600 }], + "conditions": [ + { "anchoring": "contains", "pattern": "harry" }, + { "anchoring": "contains", "pattern": "potter" } + ], + "consequence": { + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "my-index", + "params": { "filters": "brand:adidas" } + } + } + }, + "injectedItems": [ + { + "key": "injectedItem", + "source": { + "external": { + "index": "my-index", + "params": { "filters": "brand:adidas" }, + "ordering": "userDefined" + } + }, + "position": 0, + "length": 3 + } + ] + } + } + } + } + } + ] + } + }, + "request": { + "path": "/1/compositions/rule-with-exernal-source/rules/batch", + "method": "POST", + "body": { + "requests": [ + { + "action": "upsert", + "body": { + "objectID": "rule-with-exernal-source", + "description": "my description", + "tags": ["tag1", "tag2"], + "enabled": true, + "validity": [{ "from": 1704063600, "until": 1704083600 }], + "conditions": [ + { "anchoring": "contains", "pattern": "harry" }, + { "anchoring": "contains", "pattern": "potter" } + ], + "consequence": { + "behavior": { + "injection": { + "main": { + "source": { + "search": { + "index": "my-index", + "params": { "filters": "brand:adidas" } + } + } + }, + "injectedItems": [ + { + "key": "injectedItem", + "source": { + "external": { + "index": "my-index", + "params": { "filters": "brand:adidas" }, + "ordering": "userDefined" + } + }, + "position": 0, + "length": 3 + } + ] + } + } + } + } + } + ] + } + } } ] From be1ca1f470a92ef34c56dddbb896bb2988641e45 Mon Sep 17 00:00:00 2001 From: Ben Kalmus Date: Tue, 9 Sep 2025 10:05:21 +0100 Subject: [PATCH 3/3] ADD: rule tags definition --- .../common/schemas/components/CompositionRule.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/specs/composition-full/common/schemas/components/CompositionRule.yml b/specs/composition-full/common/schemas/components/CompositionRule.yml index 2bf9f3939b8..f696e687598 100644 --- a/specs/composition-full/common/schemas/components/CompositionRule.yml +++ b/specs/composition-full/common/schemas/components/CompositionRule.yml @@ -34,6 +34,12 @@ compositionRule: description: Time periods when the rule is active. items: $ref: '../../../../common/schemas/Rule.yml#/timeRange' + tags: + type: array + description: A list of tags. + items: + type: string + example: ['conditional'] required: - objectID - conditions @@ -76,4 +82,4 @@ anchoring: - `contains`. The pattern must match anywhere in the query. Empty queries are only allowed as patterns with `anchoring: is`. - enum: [is, startsWith, endsWith, contains] \ No newline at end of file + enum: [is, startsWith, endsWith, contains]