From d8eae0ec0356ac5b43c70a231b19e79b7c3c9c78 Mon Sep 17 00:00:00 2001 From: itvi-1234 Date: Sat, 14 Nov 2026 19:58:34 +0530 Subject: [PATCH] Check operations written as strings against the extension vocabulary The profile validator skipped every operation that was not an object, so a string operation such as the smtp interface's send was never checked against the interface.operations[] values the extension declares. It now checks it, as the Go profiler's validator does. --- .../profile/validator.py | 8 +++++ tests/test_extension_identity.py | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/runtimeconditions_profiler/profile/validator.py b/runtimeconditions_profiler/profile/validator.py index 3c5edc6..860d182 100644 --- a/runtimeconditions_profiler/profile/validator.py +++ b/runtimeconditions_profiler/profile/validator.py @@ -101,6 +101,14 @@ def validate_condition( add, ) for op_index, operation in enumerate(operations): + if isinstance(operation, str): + # An operation named with a plain string, such as the smtp interface's "send". + expect_profile_count( + vocabulary.field_value_count("interface.operations[]", kind, interface_type, operation), + f"{prefix}.interface.operations[{op_index}] {operation} for {kind}/{interface_type}", + add, + ) + continue if not isinstance(operation, dict): continue for field, value in operation.items(): diff --git a/tests/test_extension_identity.py b/tests/test_extension_identity.py index de94f60..c185cde 100644 --- a/tests/test_extension_identity.py +++ b/tests/test_extension_identity.py @@ -105,3 +105,34 @@ def test_string_dependencies_resolve_to_their_definitions() -> None: closure: set[tuple[str, str]] = set() add_extension_closure((TOP, "v1"), {key: value.dependencies for key, value in definitions.items()}, closure) assert closure == {(BASE, "v1"), (TOP, "v1")} + + +MAIL = "https://example.test/rc/mail/v1/runtimeconditions.extension.yaml" + + +def test_validator_checks_operations_written_as_strings() -> None: + from types import SimpleNamespace + + from runtimeconditions_profiler.extension.definition import parse_extension_definition + from runtimeconditions_profiler.profile.validator import ProfileValidator + + spec = { + "kinds": [{"name": "api"}], + "interfaceTypes": [{"name": "smtp", "targetKind": "api"}], + "interfaceFields": [{"name": "operations", "targetKind": "api", "targetType": "smtp"}], + "fieldValues": [{"field": "interface.operations[]", "targetKind": "api", "targetType": "smtp", "values": ["send"]}], + } + definition = parse_extension_definition({"metadata": {"id": MAIL, "version": "v1"}, "spec": spec}, MAIL, MAIL) + discovery = SimpleNamespace(validated_artifacts=[], sdk_extensions=[SimpleNamespace(id=MAIL, version="v1", definition=definition)]) + + def messages(operations: list[str]) -> list[str]: + profile = { + "apiVersion": "runtimeconditions.io/v1alpha1", + "kind": "RuntimeConditionsProfile", + "extensions": ["https://example.test/rc/mail:v1"], + "conditions": [{"kind": "api", "interface": {"type": "smtp", "operations": operations}}], + } + return [item.message for item in ProfileValidator().validate(profile, discovery)] + + assert not [m for m in messages(["send"]) if "operations" in m] + assert any("interface.operations[0] receive for api/smtp" in m for m in messages(["receive"]))