Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions MODULE.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,18 +16,23 @@ module(
name = "cel_java",
)

bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_jvm_external", version = "6.9")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "rules_jvm_external", version = "6.10")
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33.bcr.1", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "googleapis", version = "0.0.0-20260223-edfe7983", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.2.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_java", version = "9.3.0")
bazel_dep(name = "rules_android", version = "0.7.1")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "googleapis-java", version = "1.0.0")
bazel_dep(name = "cel-spec", version = "0.24.0", repo_name = "cel_spec")
bazel_dep(name = "cel-spec", version = "0.25.1", repo_name = "cel_spec")
bazel_dep(name = "rules_go", version = "0.50.1")

# Required by cel-spec to satisfy gazelle transitive dependency
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)
Expand Down
4 changes: 4 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelEnvironment.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -672,6 +672,10 @@ public CelType toCelType(CelTypeProvider celTypeProvider) {
return TypeParamType.create(name());
}

if (name().equals("dyn")) {
return SimpleType.DYN;
}

CelType simpleType = SimpleType.findByName(name()).orElse(null);
if (simpleType != null) {
return simpleType;
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/dev/cel/common/types/SimpleType.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,6 @@ public abstract class SimpleType extends CelType {

public static final ImmutableMap<String, CelType> TYPE_MAP =
ImmutableMap.of(
DYN.name(), DYN,
BOOL.name(), BOOL,
BYTES.name(), BYTES,
DOUBLE.name(), DOUBLE,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All@@ -27,6 +29,7 @@
import com.google.protobuf.BytesValue;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.google.protobuf.FloatValue;
import com.google.protobuf.Int32Value;
import com.google.protobuf.Int64Value;
Expand All@@ -41,6 +44,8 @@
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.ProtoTimeUtils;
import dev.cel.common.internal.WellKnownProto;
import java.util.ArrayList;
import java.util.List;

/**
* {@code BaseProtoCelValueConverter} contains the common logic for converting between native Java
Expand DownExpand Up@@ -98,6 +103,17 @@ protected Object fromWellKnownProto(MessageLiteOrBuilder message, WellKnownProto
return UnsignedLong.valueOf(((UInt32Value) message).getValue());
case UINT64_VALUE:
return UnsignedLong.fromLongBits(((UInt64Value) message).getValue());
case FIELD_MASK:
FieldMask fieldMask = (FieldMask) message;
List<String> paths = new ArrayList<>(fieldMask.getPathsCount());
for (String path : fieldMask.getPathsList()) {
if (!path.isEmpty()) {
paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
}
}
return normalizePrimitive(Joiner.on(",").join(paths));
case EMPTY:
return ImmutableMap.of();
default:
throw new UnsupportedOperationException(
"Unsupported well known proto conversion - " + wellKnownProto);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,10 @@ public Object unwrap(CelValue celValue) {
return Optional.of(optionalValue.value());
}

if (celValue instanceof ErrorValue) {
return celValue;
}

return celValue.value();
}

Expand Down
80 changes: 70 additions & 10 deletions conformance/src/test/java/dev/cel/conformance/BUILD.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ java_library(
"//parser:parser_builder",
"//parser:parser_factory",
"//runtime",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -57,6 +58,8 @@ java_library(
deps = MAVEN_JAR_DEPS + [
"//:java_truth",
"//compiler:compiler_builder",
"//parser:parser_factory",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -100,14 +103,8 @@ _ALL_TESTS = [
"@cel_spec//tests/simple:testdata/wrappers.textproto",
]

_TESTS_TO_SKIP = [
# Tests which require spec changes.
# TODO: Deprecate Duration.get_milliseconds
"timestamps/duration_converters/get_milliseconds",

_TESTS_TO_SKIP_LEGACY = [
# Broken test cases which should be supported.
# TODO: Invalid bytes to string conversion should error.
"conversions/string/bytes_invalid",
# TODO: Support setting / getting enum values out of the defined enum value range.
"enums/legacy_proto2/select_big,select_neg",
"enums/legacy_proto2/assign_standalone_int_big,assign_standalone_int_neg",
Expand All@@ -116,7 +113,6 @@ _TESTS_TO_SKIP = [
# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
# TODO: Duration and timestamp operations should error on overflow.
"timestamps/duration_range/from_string_under,from_string_over",
"timestamps/timestamp_range/sub_time_duration_over,sub_time_duration_under",
# TODO: Ensure adding negative duration values is appropriately supported.
"timestamps/timestamp_arithmetic/add_time_to_duration_nanos_negative",
Expand DownExpand Up@@ -159,21 +155,85 @@ _TESTS_TO_SKIP = [
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",
]

_TESTS_TO_SKIP_PLANNER = [
# TODO: Add strings.format and strings.quote.
"string_ext/quote",
"string_ext/format",
"string_ext/format_errors",

# TODO: Check behavior for go/cpp
"basic/functions/unbound",
"basic/functions/unbound_is_runtime_error",

# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
"enums/legacy_proto3/assign_standalone_int_too_big",
"enums/legacy_proto3/assign_standalone_int_too_neg",

# TODO: Duration and timestamp operations should error on overflow.
"timestamps/timestamp_range/sub_time_duration_over",
"timestamps/timestamp_range/sub_time_duration_under",

# Skip until fixed.
"fields/qualified_identifier_resolution/map_key_float",
"fields/qualified_identifier_resolution/map_key_null",
"fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",
"optionals/optionals/map_null_entry_no_such_key",
"optionals/optionals/map_present_key_invalid_field",
"parse/receiver_function_names",
"proto2/extensions_get/package_scoped_test_all_types_ext",
"proto2/extensions_get/package_scoped_repeated_test_all_types",
"proto2/extensions_get/message_scoped_nested_ext",
"proto2/extensions_get/message_scoped_repeated_test_all_types",
"proto2_ext/get_ext/package_scoped_repeated_test_all_types",
"proto2_ext/get_ext/message_scoped_repeated_test_all_types",

# TODO: Fix null assignment to a field
"proto2/set_null/single_message",
"proto2/set_null/single_duration",
"proto2/set_null/single_timestamp",
"proto3/set_null/single_message",
"proto3/set_null/single_duration",
"proto3/set_null/single_timestamp",

# Type inference edgecases around null(able) assignability.
# These type check, but resolve to a different type.
# list(int), want list(wrapper(int))
"type_deductions/wrappers/wrapper_promotion",
# list(null), want list(Message)
"type_deductions/legacy_nullable_types/null_assignable_to_message_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_abstract_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_duration_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",

# Future features for CEL 1.0
# TODO: Strong typing support for enums, specified but not implemented.
"enums/strong_proto2",
"enums/strong_proto3",
]

conformance_test(
name = "conformance",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_maven",
data = _ALL_TESTS,
mode = MODE.MAVEN_TEST,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_dashboard",
data = _ALL_TESTS,
mode = MODE.DASHBOARD,
)

conformance_test(
name = "conformance_planner",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP_PLANNER,
use_planner = True,
)
46 changes: 34 additions & 12 deletions conformance/src/test/java/dev/cel/conformance/ConformanceTest.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,9 @@
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelRuntime.Program;
import dev.cel.runtime.CelRuntimeBuilder;
import dev.cel.runtime.CelRuntimeFactory;
import dev.cel.runtime.CelRuntimeImpl;
import dev.cel.runtime.CelRuntimeLibrary;
import java.util.Map;
import org.junit.runners.model.Statement;
Expand DownExpand Up@@ -118,15 +120,25 @@ private static CelChecker getChecker(SimpleTest test) throws Exception {
.build();
}

private static final CelRuntime RUNTIME =
CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor())
.build();
private static CelRuntime getRuntime(SimpleTest test, boolean usePlanner) {
CelRuntimeBuilder builder =
usePlanner ? CelRuntimeImpl.newBuilder() : CelRuntimeFactory.standardCelRuntimeBuilder();

builder
// CEL-Internal-2
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor());

if (usePlanner) {
builder.setContainer(CelContainer.ofName(test.getContainer()));
}

return builder.build();
}

private static ImmutableMap<String, Object> getBindings(SimpleTest test) throws Exception {
ImmutableMap.Builder<String, Object> bindings =
Expand DownExpand Up@@ -157,13 +169,15 @@ private static SimpleTest defaultTestMatcherToTrueIfUnset(SimpleTest test) {
private final String name;
private final SimpleTest test;
private final boolean skip;
private final boolean usePlanner;

public ConformanceTest(String name, SimpleTest test, boolean skip) {
public ConformanceTest(String name, SimpleTest test, boolean skip, boolean usePlanner) {
this.name = Preconditions.checkNotNull(name);
this.test =
Preconditions.checkNotNull(
defaultTestMatcherToTrueIfUnset(Preconditions.checkNotNull(test)));
this.skip = skip;
this.usePlanner = usePlanner;
}

public String getName() {
Expand All@@ -178,7 +192,9 @@ public boolean shouldSkip() {
public void evaluate() throws Throwable {
CelValidationResult response = getParser(test).parse(test.getExpr(), test.getName());
assertThat(response.hasError()).isFalse();
response = getChecker(test).check(response.getAst());
if (!test.getDisableCheck()) {
response = getChecker(test).check(response.getAst());
}
assertThat(response.hasError()).isFalse();
Type resultType = CelProtoTypes.celTypeToType(response.getAst().getResultType());

Expand All@@ -188,7 +204,13 @@ public void evaluate() throws Throwable {
return;
}

Program program = RUNTIME.createProgram(response.getAst());
if (!usePlanner && test.getDisableCheck()) {
// Only planner supports parsed-only evaluation
return;
}

CelRuntime runtime = getRuntime(test, usePlanner);
Program program = runtime.createProgram(response.getAst());
ExprValue result = null;
CelEvaluationException error = null;
try {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ public final class ConformanceTestRunner extends ParentRunner<ConformanceTest> {

private final ImmutableSortedMap<String, SimpleTestFile> testFiles;
private final ImmutableList<String> testsToSkip;
private final boolean usePlanner;

private static ImmutableSortedMap<String, SimpleTestFile> loadTestFiles() {
List<String> testPaths =
Expand DownExpand Up@@ -75,6 +76,9 @@ public ConformanceTestRunner(Class<?> clazz) throws InitializationError {
ImmutableList.copyOf(
SPLITTER.splitToList(
System.getProperty("dev.cel.conformance.ConformanceTests.skip_tests")));
usePlanner =
Boolean.parseBoolean(
System.getProperty("dev.cel.conformance.ConformanceTests.use_planner", "false"));
}

private boolean shouldSkipTest(String name) {
Expand All@@ -97,8 +101,7 @@ protected List<ConformanceTest> getChildren() {
for (SimpleTest test : testSection.getTestList()) {
String name =
String.format("%s/%s/%s", testFile.getName(), testSection.getName(), test.getName());
tests.add(
new ConformanceTest(name, test, test.getDisableCheck() || shouldSkipTest(name)));
tests.add(new ConformanceTest(name, test, shouldSkipTest(name), usePlanner));
}
}
}
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions MODULE.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,18 +16,23 @@ module(
name = "cel_java",
)

bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_jvm_external", version = "6.9")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "rules_jvm_external", version = "6.10")
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33.bcr.1", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "googleapis", version = "0.0.0-20260223-edfe7983", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.2.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_java", version = "9.3.0")
bazel_dep(name = "rules_android", version = "0.7.1")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "googleapis-java", version = "1.0.0")
bazel_dep(name = "cel-spec", version = "0.24.0", repo_name = "cel_spec")
bazel_dep(name = "cel-spec", version = "0.25.1", repo_name = "cel_spec")
bazel_dep(name = "rules_go", version = "0.50.1")

# Required by cel-spec to satisfy gazelle transitive dependency
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)
Expand Down
4 changes: 4 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelEnvironment.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -672,6 +672,10 @@ public CelType toCelType(CelTypeProvider celTypeProvider) {
return TypeParamType.create(name());
}

if (name().equals("dyn")) {
return SimpleType.DYN;
}

CelType simpleType = SimpleType.findByName(name()).orElse(null);
if (simpleType != null) {
return simpleType;
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/dev/cel/common/types/SimpleType.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,6 @@ public abstract class SimpleType extends CelType {

public static final ImmutableMap<String, CelType> TYPE_MAP =
ImmutableMap.of(
DYN.name(), DYN,
BOOL.name(), BOOL,
BYTES.name(), BYTES,
DOUBLE.name(), DOUBLE,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All@@ -27,6 +29,7 @@
import com.google.protobuf.BytesValue;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.google.protobuf.FloatValue;
import com.google.protobuf.Int32Value;
import com.google.protobuf.Int64Value;
Expand All@@ -41,6 +44,8 @@
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.ProtoTimeUtils;
import dev.cel.common.internal.WellKnownProto;
import java.util.ArrayList;
import java.util.List;

/**
* {@code BaseProtoCelValueConverter} contains the common logic for converting between native Java
Expand DownExpand Up@@ -98,6 +103,17 @@ protected Object fromWellKnownProto(MessageLiteOrBuilder message, WellKnownProto
return UnsignedLong.valueOf(((UInt32Value) message).getValue());
case UINT64_VALUE:
return UnsignedLong.fromLongBits(((UInt64Value) message).getValue());
case FIELD_MASK:
FieldMask fieldMask = (FieldMask) message;
List<String> paths = new ArrayList<>(fieldMask.getPathsCount());
for (String path : fieldMask.getPathsList()) {
if (!path.isEmpty()) {
paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
}
}
return normalizePrimitive(Joiner.on(",").join(paths));
case EMPTY:
return ImmutableMap.of();
default:
throw new UnsupportedOperationException(
"Unsupported well known proto conversion - " + wellKnownProto);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,10 @@ public Object unwrap(CelValue celValue) {
return Optional.of(optionalValue.value());
}

if (celValue instanceof ErrorValue) {
return celValue;
}

return celValue.value();
}

Expand Down
80 changes: 70 additions & 10 deletions conformance/src/test/java/dev/cel/conformance/BUILD.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ java_library(
"//parser:parser_builder",
"//parser:parser_factory",
"//runtime",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -57,6 +58,8 @@ java_library(
deps = MAVEN_JAR_DEPS + [
"//:java_truth",
"//compiler:compiler_builder",
"//parser:parser_factory",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -100,14 +103,8 @@ _ALL_TESTS = [
"@cel_spec//tests/simple:testdata/wrappers.textproto",
]

_TESTS_TO_SKIP = [
# Tests which require spec changes.
# TODO: Deprecate Duration.get_milliseconds
"timestamps/duration_converters/get_milliseconds",

_TESTS_TO_SKIP_LEGACY = [
# Broken test cases which should be supported.
# TODO: Invalid bytes to string conversion should error.
"conversions/string/bytes_invalid",
# TODO: Support setting / getting enum values out of the defined enum value range.
"enums/legacy_proto2/select_big,select_neg",
"enums/legacy_proto2/assign_standalone_int_big,assign_standalone_int_neg",
Expand All@@ -116,7 +113,6 @@ _TESTS_TO_SKIP = [
# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
# TODO: Duration and timestamp operations should error on overflow.
"timestamps/duration_range/from_string_under,from_string_over",
"timestamps/timestamp_range/sub_time_duration_over,sub_time_duration_under",
# TODO: Ensure adding negative duration values is appropriately supported.
"timestamps/timestamp_arithmetic/add_time_to_duration_nanos_negative",
Expand DownExpand Up@@ -159,21 +155,85 @@ _TESTS_TO_SKIP = [
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",
]

_TESTS_TO_SKIP_PLANNER = [
# TODO: Add strings.format and strings.quote.
"string_ext/quote",
"string_ext/format",
"string_ext/format_errors",

# TODO: Check behavior for go/cpp
"basic/functions/unbound",
"basic/functions/unbound_is_runtime_error",

# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
"enums/legacy_proto3/assign_standalone_int_too_big",
"enums/legacy_proto3/assign_standalone_int_too_neg",

# TODO: Duration and timestamp operations should error on overflow.
"timestamps/timestamp_range/sub_time_duration_over",
"timestamps/timestamp_range/sub_time_duration_under",

# Skip until fixed.
"fields/qualified_identifier_resolution/map_key_float",
"fields/qualified_identifier_resolution/map_key_null",
"fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",
"optionals/optionals/map_null_entry_no_such_key",
"optionals/optionals/map_present_key_invalid_field",
"parse/receiver_function_names",
"proto2/extensions_get/package_scoped_test_all_types_ext",
"proto2/extensions_get/package_scoped_repeated_test_all_types",
"proto2/extensions_get/message_scoped_nested_ext",
"proto2/extensions_get/message_scoped_repeated_test_all_types",
"proto2_ext/get_ext/package_scoped_repeated_test_all_types",
"proto2_ext/get_ext/message_scoped_repeated_test_all_types",

# TODO: Fix null assignment to a field
"proto2/set_null/single_message",
"proto2/set_null/single_duration",
"proto2/set_null/single_timestamp",
"proto3/set_null/single_message",
"proto3/set_null/single_duration",
"proto3/set_null/single_timestamp",

# Type inference edgecases around null(able) assignability.
# These type check, but resolve to a different type.
# list(int), want list(wrapper(int))
"type_deductions/wrappers/wrapper_promotion",
# list(null), want list(Message)
"type_deductions/legacy_nullable_types/null_assignable_to_message_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_abstract_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_duration_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",

# Future features for CEL 1.0
# TODO: Strong typing support for enums, specified but not implemented.
"enums/strong_proto2",
"enums/strong_proto3",
]

conformance_test(
name = "conformance",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_maven",
data = _ALL_TESTS,
mode = MODE.MAVEN_TEST,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_dashboard",
data = _ALL_TESTS,
mode = MODE.DASHBOARD,
)

conformance_test(
name = "conformance_planner",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP_PLANNER,
use_planner = True,
)
46 changes: 34 additions & 12 deletions conformance/src/test/java/dev/cel/conformance/ConformanceTest.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,9 @@
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelRuntime.Program;
import dev.cel.runtime.CelRuntimeBuilder;
import dev.cel.runtime.CelRuntimeFactory;
import dev.cel.runtime.CelRuntimeImpl;
import dev.cel.runtime.CelRuntimeLibrary;
import java.util.Map;
import org.junit.runners.model.Statement;
Expand DownExpand Up@@ -118,15 +120,25 @@ private static CelChecker getChecker(SimpleTest test) throws Exception {
.build();
}

private static final CelRuntime RUNTIME =
CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor())
.build();
private static CelRuntime getRuntime(SimpleTest test, boolean usePlanner) {
CelRuntimeBuilder builder =
usePlanner ? CelRuntimeImpl.newBuilder() : CelRuntimeFactory.standardCelRuntimeBuilder();

builder
// CEL-Internal-2
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor());

if (usePlanner) {
builder.setContainer(CelContainer.ofName(test.getContainer()));
}

return builder.build();
}

private static ImmutableMap<String, Object> getBindings(SimpleTest test) throws Exception {
ImmutableMap.Builder<String, Object> bindings =
Expand DownExpand Up@@ -157,13 +169,15 @@ private static SimpleTest defaultTestMatcherToTrueIfUnset(SimpleTest test) {
private final String name;
private final SimpleTest test;
private final boolean skip;
private final boolean usePlanner;

public ConformanceTest(String name, SimpleTest test, boolean skip) {
public ConformanceTest(String name, SimpleTest test, boolean skip, boolean usePlanner) {
this.name = Preconditions.checkNotNull(name);
this.test =
Preconditions.checkNotNull(
defaultTestMatcherToTrueIfUnset(Preconditions.checkNotNull(test)));
this.skip = skip;
this.usePlanner = usePlanner;
}

public String getName() {
Expand All@@ -178,7 +192,9 @@ public boolean shouldSkip() {
public void evaluate() throws Throwable {
CelValidationResult response = getParser(test).parse(test.getExpr(), test.getName());
assertThat(response.hasError()).isFalse();
response = getChecker(test).check(response.getAst());
if (!test.getDisableCheck()) {
response = getChecker(test).check(response.getAst());
}
assertThat(response.hasError()).isFalse();
Type resultType = CelProtoTypes.celTypeToType(response.getAst().getResultType());

Expand All@@ -188,7 +204,13 @@ public void evaluate() throws Throwable {
return;
}

Program program = RUNTIME.createProgram(response.getAst());
if (!usePlanner && test.getDisableCheck()) {
// Only planner supports parsed-only evaluation
return;
}

CelRuntime runtime = getRuntime(test, usePlanner);
Program program = runtime.createProgram(response.getAst());
ExprValue result = null;
CelEvaluationException error = null;
try {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ public final class ConformanceTestRunner extends ParentRunner<ConformanceTest> {

private final ImmutableSortedMap<String, SimpleTestFile> testFiles;
private final ImmutableList<String> testsToSkip;
private final boolean usePlanner;

private static ImmutableSortedMap<String, SimpleTestFile> loadTestFiles() {
List<String> testPaths =
Expand DownExpand Up@@ -75,6 +76,9 @@ public ConformanceTestRunner(Class<?> clazz) throws InitializationError {
ImmutableList.copyOf(
SPLITTER.splitToList(
System.getProperty("dev.cel.conformance.ConformanceTests.skip_tests")));
usePlanner =
Boolean.parseBoolean(
System.getProperty("dev.cel.conformance.ConformanceTests.use_planner", "false"));
}

private boolean shouldSkipTest(String name) {
Expand All@@ -97,8 +101,7 @@ protected List<ConformanceTest> getChildren() {
for (SimpleTest test : testSection.getTestList()) {
String name =
String.format("%s/%s/%s", testFile.getName(), testSection.getName(), test.getName());
tests.add(
new ConformanceTest(name, test, test.getDisableCheck() || shouldSkipTest(name)));
tests.add(new ConformanceTest(name, test, shouldSkipTest(name), usePlanner));
}
}
}
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions MODULE.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,18 +16,23 @@ module(
name = "cel_java",
)

bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_jvm_external", version = "6.9")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "rules_jvm_external", version = "6.10")
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33.bcr.1", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "googleapis", version = "0.0.0-20260223-edfe7983", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.2.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_java", version = "9.3.0")
bazel_dep(name = "rules_android", version = "0.7.1")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "googleapis-java", version = "1.0.0")
bazel_dep(name = "cel-spec", version = "0.24.0", repo_name = "cel_spec")
bazel_dep(name = "cel-spec", version = "0.25.1", repo_name = "cel_spec")
bazel_dep(name = "rules_go", version = "0.50.1")

# Required by cel-spec to satisfy gazelle transitive dependency
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)
Expand Down
4 changes: 4 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelEnvironment.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -672,6 +672,10 @@ public CelType toCelType(CelTypeProvider celTypeProvider) {
return TypeParamType.create(name());
}

if (name().equals("dyn")) {
return SimpleType.DYN;
}

CelType simpleType = SimpleType.findByName(name()).orElse(null);
if (simpleType != null) {
return simpleType;
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/dev/cel/common/types/SimpleType.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,6 @@ public abstract class SimpleType extends CelType {

public static final ImmutableMap<String, CelType> TYPE_MAP =
ImmutableMap.of(
DYN.name(), DYN,
BOOL.name(), BOOL,
BYTES.name(), BYTES,
DOUBLE.name(), DOUBLE,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All@@ -27,6 +29,7 @@
import com.google.protobuf.BytesValue;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.google.protobuf.FloatValue;
import com.google.protobuf.Int32Value;
import com.google.protobuf.Int64Value;
Expand All@@ -41,6 +44,8 @@
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.ProtoTimeUtils;
import dev.cel.common.internal.WellKnownProto;
import java.util.ArrayList;
import java.util.List;

/**
* {@code BaseProtoCelValueConverter} contains the common logic for converting between native Java
Expand DownExpand Up@@ -98,6 +103,17 @@ protected Object fromWellKnownProto(MessageLiteOrBuilder message, WellKnownProto
return UnsignedLong.valueOf(((UInt32Value) message).getValue());
case UINT64_VALUE:
return UnsignedLong.fromLongBits(((UInt64Value) message).getValue());
case FIELD_MASK:
FieldMask fieldMask = (FieldMask) message;
List<String> paths = new ArrayList<>(fieldMask.getPathsCount());
for (String path : fieldMask.getPathsList()) {
if (!path.isEmpty()) {
paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
}
}
return normalizePrimitive(Joiner.on(",").join(paths));
case EMPTY:
return ImmutableMap.of();
default:
throw new UnsupportedOperationException(
"Unsupported well known proto conversion - " + wellKnownProto);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,10 @@ public Object unwrap(CelValue celValue) {
return Optional.of(optionalValue.value());
}

if (celValue instanceof ErrorValue) {
return celValue;
}

return celValue.value();
}

Expand Down
80 changes: 70 additions & 10 deletions conformance/src/test/java/dev/cel/conformance/BUILD.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ java_library(
"//parser:parser_builder",
"//parser:parser_factory",
"//runtime",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -57,6 +58,8 @@ java_library(
deps = MAVEN_JAR_DEPS + [
"//:java_truth",
"//compiler:compiler_builder",
"//parser:parser_factory",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -100,14 +103,8 @@ _ALL_TESTS = [
"@cel_spec//tests/simple:testdata/wrappers.textproto",
]

_TESTS_TO_SKIP = [
# Tests which require spec changes.
# TODO: Deprecate Duration.get_milliseconds
"timestamps/duration_converters/get_milliseconds",

_TESTS_TO_SKIP_LEGACY = [
# Broken test cases which should be supported.
# TODO: Invalid bytes to string conversion should error.
"conversions/string/bytes_invalid",
# TODO: Support setting / getting enum values out of the defined enum value range.
"enums/legacy_proto2/select_big,select_neg",
"enums/legacy_proto2/assign_standalone_int_big,assign_standalone_int_neg",
Expand All@@ -116,7 +113,6 @@ _TESTS_TO_SKIP = [
# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
# TODO: Duration and timestamp operations should error on overflow.
"timestamps/duration_range/from_string_under,from_string_over",
"timestamps/timestamp_range/sub_time_duration_over,sub_time_duration_under",
# TODO: Ensure adding negative duration values is appropriately supported.
"timestamps/timestamp_arithmetic/add_time_to_duration_nanos_negative",
Expand DownExpand Up@@ -159,21 +155,85 @@ _TESTS_TO_SKIP = [
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",
]

_TESTS_TO_SKIP_PLANNER = [
# TODO: Add strings.format and strings.quote.
"string_ext/quote",
"string_ext/format",
"string_ext/format_errors",

# TODO: Check behavior for go/cpp
"basic/functions/unbound",
"basic/functions/unbound_is_runtime_error",

# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
"enums/legacy_proto3/assign_standalone_int_too_big",
"enums/legacy_proto3/assign_standalone_int_too_neg",

# TODO: Duration and timestamp operations should error on overflow.
"timestamps/timestamp_range/sub_time_duration_over",
"timestamps/timestamp_range/sub_time_duration_under",

# Skip until fixed.
"fields/qualified_identifier_resolution/map_key_float",
"fields/qualified_identifier_resolution/map_key_null",
"fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",
"optionals/optionals/map_null_entry_no_such_key",
"optionals/optionals/map_present_key_invalid_field",
"parse/receiver_function_names",
"proto2/extensions_get/package_scoped_test_all_types_ext",
"proto2/extensions_get/package_scoped_repeated_test_all_types",
"proto2/extensions_get/message_scoped_nested_ext",
"proto2/extensions_get/message_scoped_repeated_test_all_types",
"proto2_ext/get_ext/package_scoped_repeated_test_all_types",
"proto2_ext/get_ext/message_scoped_repeated_test_all_types",

# TODO: Fix null assignment to a field
"proto2/set_null/single_message",
"proto2/set_null/single_duration",
"proto2/set_null/single_timestamp",
"proto3/set_null/single_message",
"proto3/set_null/single_duration",
"proto3/set_null/single_timestamp",

# Type inference edgecases around null(able) assignability.
# These type check, but resolve to a different type.
# list(int), want list(wrapper(int))
"type_deductions/wrappers/wrapper_promotion",
# list(null), want list(Message)
"type_deductions/legacy_nullable_types/null_assignable_to_message_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_abstract_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_duration_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",

# Future features for CEL 1.0
# TODO: Strong typing support for enums, specified but not implemented.
"enums/strong_proto2",
"enums/strong_proto3",
]

conformance_test(
name = "conformance",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_maven",
data = _ALL_TESTS,
mode = MODE.MAVEN_TEST,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_dashboard",
data = _ALL_TESTS,
mode = MODE.DASHBOARD,
)

conformance_test(
name = "conformance_planner",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP_PLANNER,
use_planner = True,
)
46 changes: 34 additions & 12 deletions conformance/src/test/java/dev/cel/conformance/ConformanceTest.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,9 @@
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelRuntime.Program;
import dev.cel.runtime.CelRuntimeBuilder;
import dev.cel.runtime.CelRuntimeFactory;
import dev.cel.runtime.CelRuntimeImpl;
import dev.cel.runtime.CelRuntimeLibrary;
import java.util.Map;
import org.junit.runners.model.Statement;
Expand DownExpand Up@@ -118,15 +120,25 @@ private static CelChecker getChecker(SimpleTest test) throws Exception {
.build();
}

private static final CelRuntime RUNTIME =
CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor())
.build();
private static CelRuntime getRuntime(SimpleTest test, boolean usePlanner) {
CelRuntimeBuilder builder =
usePlanner ? CelRuntimeImpl.newBuilder() : CelRuntimeFactory.standardCelRuntimeBuilder();

builder
// CEL-Internal-2
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor());

if (usePlanner) {
builder.setContainer(CelContainer.ofName(test.getContainer()));
}

return builder.build();
}

private static ImmutableMap<String, Object> getBindings(SimpleTest test) throws Exception {
ImmutableMap.Builder<String, Object> bindings =
Expand DownExpand Up@@ -157,13 +169,15 @@ private static SimpleTest defaultTestMatcherToTrueIfUnset(SimpleTest test) {
private final String name;
private final SimpleTest test;
private final boolean skip;
private final boolean usePlanner;

public ConformanceTest(String name, SimpleTest test, boolean skip) {
public ConformanceTest(String name, SimpleTest test, boolean skip, boolean usePlanner) {
this.name = Preconditions.checkNotNull(name);
this.test =
Preconditions.checkNotNull(
defaultTestMatcherToTrueIfUnset(Preconditions.checkNotNull(test)));
this.skip = skip;
this.usePlanner = usePlanner;
}

public String getName() {
Expand All@@ -178,7 +192,9 @@ public boolean shouldSkip() {
public void evaluate() throws Throwable {
CelValidationResult response = getParser(test).parse(test.getExpr(), test.getName());
assertThat(response.hasError()).isFalse();
response = getChecker(test).check(response.getAst());
if (!test.getDisableCheck()) {
response = getChecker(test).check(response.getAst());
}
assertThat(response.hasError()).isFalse();
Type resultType = CelProtoTypes.celTypeToType(response.getAst().getResultType());

Expand All@@ -188,7 +204,13 @@ public void evaluate() throws Throwable {
return;
}

Program program = RUNTIME.createProgram(response.getAst());
if (!usePlanner && test.getDisableCheck()) {
// Only planner supports parsed-only evaluation
return;
}

CelRuntime runtime = getRuntime(test, usePlanner);
Program program = runtime.createProgram(response.getAst());
ExprValue result = null;
CelEvaluationException error = null;
try {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ public final class ConformanceTestRunner extends ParentRunner<ConformanceTest> {

private final ImmutableSortedMap<String, SimpleTestFile> testFiles;
private final ImmutableList<String> testsToSkip;
private final boolean usePlanner;

private static ImmutableSortedMap<String, SimpleTestFile> loadTestFiles() {
List<String> testPaths =
Expand DownExpand Up@@ -75,6 +76,9 @@ public ConformanceTestRunner(Class<?> clazz) throws InitializationError {
ImmutableList.copyOf(
SPLITTER.splitToList(
System.getProperty("dev.cel.conformance.ConformanceTests.skip_tests")));
usePlanner =
Boolean.parseBoolean(
System.getProperty("dev.cel.conformance.ConformanceTests.use_planner", "false"));
}

private boolean shouldSkipTest(String name) {
Expand All@@ -97,8 +101,7 @@ protected List<ConformanceTest> getChildren() {
for (SimpleTest test : testSection.getTestList()) {
String name =
String.format("%s/%s/%s", testFile.getName(), testSection.getName(), test.getName());
tests.add(
new ConformanceTest(name, test, test.getDisableCheck() || shouldSkipTest(name)));
tests.add(new ConformanceTest(name, test, shouldSkipTest(name), usePlanner));
}
}
}
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions MODULE.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,18 +16,23 @@ module(
name = "cel_java",
)

bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_jvm_external", version = "6.9")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "rules_jvm_external", version = "6.10")
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33.bcr.1", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "googleapis", version = "0.0.0-20260223-edfe7983", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.2.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_java", version = "9.3.0")
bazel_dep(name = "rules_android", version = "0.7.1")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "googleapis-java", version = "1.0.0")
bazel_dep(name = "cel-spec", version = "0.24.0", repo_name = "cel_spec")
bazel_dep(name = "cel-spec", version = "0.25.1", repo_name = "cel_spec")
bazel_dep(name = "rules_go", version = "0.50.1")

# Required by cel-spec to satisfy gazelle transitive dependency
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)
Expand Down
4 changes: 4 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelEnvironment.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -672,6 +672,10 @@ public CelType toCelType(CelTypeProvider celTypeProvider) {
return TypeParamType.create(name());
}

if (name().equals("dyn")) {
return SimpleType.DYN;
}

CelType simpleType = SimpleType.findByName(name()).orElse(null);
if (simpleType != null) {
return simpleType;
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/dev/cel/common/types/SimpleType.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,6 @@ public abstract class SimpleType extends CelType {

public static final ImmutableMap<String, CelType> TYPE_MAP =
ImmutableMap.of(
DYN.name(), DYN,
BOOL.name(), BOOL,
BYTES.name(), BYTES,
DOUBLE.name(), DOUBLE,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All@@ -27,6 +29,7 @@
import com.google.protobuf.BytesValue;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.google.protobuf.FloatValue;
import com.google.protobuf.Int32Value;
import com.google.protobuf.Int64Value;
Expand All@@ -41,6 +44,8 @@
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.ProtoTimeUtils;
import dev.cel.common.internal.WellKnownProto;
import java.util.ArrayList;
import java.util.List;

/**
* {@code BaseProtoCelValueConverter} contains the common logic for converting between native Java
Expand DownExpand Up@@ -98,6 +103,17 @@ protected Object fromWellKnownProto(MessageLiteOrBuilder message, WellKnownProto
return UnsignedLong.valueOf(((UInt32Value) message).getValue());
case UINT64_VALUE:
return UnsignedLong.fromLongBits(((UInt64Value) message).getValue());
case FIELD_MASK:
FieldMask fieldMask = (FieldMask) message;
List<String> paths = new ArrayList<>(fieldMask.getPathsCount());
for (String path : fieldMask.getPathsList()) {
if (!path.isEmpty()) {
paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
}
}
return normalizePrimitive(Joiner.on(",").join(paths));
case EMPTY:
return ImmutableMap.of();
default:
throw new UnsupportedOperationException(
"Unsupported well known proto conversion - " + wellKnownProto);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,10 @@ public Object unwrap(CelValue celValue) {
return Optional.of(optionalValue.value());
}

if (celValue instanceof ErrorValue) {
return celValue;
}

return celValue.value();
}

Expand Down
80 changes: 70 additions & 10 deletions conformance/src/test/java/dev/cel/conformance/BUILD.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ java_library(
"//parser:parser_builder",
"//parser:parser_factory",
"//runtime",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -57,6 +58,8 @@ java_library(
deps = MAVEN_JAR_DEPS + [
"//:java_truth",
"//compiler:compiler_builder",
"//parser:parser_factory",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -100,14 +103,8 @@ _ALL_TESTS = [
"@cel_spec//tests/simple:testdata/wrappers.textproto",
]

_TESTS_TO_SKIP = [
# Tests which require spec changes.
# TODO: Deprecate Duration.get_milliseconds
"timestamps/duration_converters/get_milliseconds",

_TESTS_TO_SKIP_LEGACY = [
# Broken test cases which should be supported.
# TODO: Invalid bytes to string conversion should error.
"conversions/string/bytes_invalid",
# TODO: Support setting / getting enum values out of the defined enum value range.
"enums/legacy_proto2/select_big,select_neg",
"enums/legacy_proto2/assign_standalone_int_big,assign_standalone_int_neg",
Expand All@@ -116,7 +113,6 @@ _TESTS_TO_SKIP = [
# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
# TODO: Duration and timestamp operations should error on overflow.
"timestamps/duration_range/from_string_under,from_string_over",
"timestamps/timestamp_range/sub_time_duration_over,sub_time_duration_under",
# TODO: Ensure adding negative duration values is appropriately supported.
"timestamps/timestamp_arithmetic/add_time_to_duration_nanos_negative",
Expand DownExpand Up@@ -159,21 +155,85 @@ _TESTS_TO_SKIP = [
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",
]

_TESTS_TO_SKIP_PLANNER = [
# TODO: Add strings.format and strings.quote.
"string_ext/quote",
"string_ext/format",
"string_ext/format_errors",

# TODO: Check behavior for go/cpp
"basic/functions/unbound",
"basic/functions/unbound_is_runtime_error",

# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
"enums/legacy_proto3/assign_standalone_int_too_big",
"enums/legacy_proto3/assign_standalone_int_too_neg",

# TODO: Duration and timestamp operations should error on overflow.
"timestamps/timestamp_range/sub_time_duration_over",
"timestamps/timestamp_range/sub_time_duration_under",

# Skip until fixed.
"fields/qualified_identifier_resolution/map_key_float",
"fields/qualified_identifier_resolution/map_key_null",
"fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",
"optionals/optionals/map_null_entry_no_such_key",
"optionals/optionals/map_present_key_invalid_field",
"parse/receiver_function_names",
"proto2/extensions_get/package_scoped_test_all_types_ext",
"proto2/extensions_get/package_scoped_repeated_test_all_types",
"proto2/extensions_get/message_scoped_nested_ext",
"proto2/extensions_get/message_scoped_repeated_test_all_types",
"proto2_ext/get_ext/package_scoped_repeated_test_all_types",
"proto2_ext/get_ext/message_scoped_repeated_test_all_types",

# TODO: Fix null assignment to a field
"proto2/set_null/single_message",
"proto2/set_null/single_duration",
"proto2/set_null/single_timestamp",
"proto3/set_null/single_message",
"proto3/set_null/single_duration",
"proto3/set_null/single_timestamp",

# Type inference edgecases around null(able) assignability.
# These type check, but resolve to a different type.
# list(int), want list(wrapper(int))
"type_deductions/wrappers/wrapper_promotion",
# list(null), want list(Message)
"type_deductions/legacy_nullable_types/null_assignable_to_message_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_abstract_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_duration_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",

# Future features for CEL 1.0
# TODO: Strong typing support for enums, specified but not implemented.
"enums/strong_proto2",
"enums/strong_proto3",
]

conformance_test(
name = "conformance",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_maven",
data = _ALL_TESTS,
mode = MODE.MAVEN_TEST,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_dashboard",
data = _ALL_TESTS,
mode = MODE.DASHBOARD,
)

conformance_test(
name = "conformance_planner",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP_PLANNER,
use_planner = True,
)
46 changes: 34 additions & 12 deletions conformance/src/test/java/dev/cel/conformance/ConformanceTest.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,9 @@
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelRuntime.Program;
import dev.cel.runtime.CelRuntimeBuilder;
import dev.cel.runtime.CelRuntimeFactory;
import dev.cel.runtime.CelRuntimeImpl;
import dev.cel.runtime.CelRuntimeLibrary;
import java.util.Map;
import org.junit.runners.model.Statement;
Expand DownExpand Up@@ -118,15 +120,25 @@ private static CelChecker getChecker(SimpleTest test) throws Exception {
.build();
}

private static final CelRuntime RUNTIME =
CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor())
.build();
private static CelRuntime getRuntime(SimpleTest test, boolean usePlanner) {
CelRuntimeBuilder builder =
usePlanner ? CelRuntimeImpl.newBuilder() : CelRuntimeFactory.standardCelRuntimeBuilder();

builder
// CEL-Internal-2
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor());

if (usePlanner) {
builder.setContainer(CelContainer.ofName(test.getContainer()));
}

return builder.build();
}

private static ImmutableMap<String, Object> getBindings(SimpleTest test) throws Exception {
ImmutableMap.Builder<String, Object> bindings =
Expand DownExpand Up@@ -157,13 +169,15 @@ private static SimpleTest defaultTestMatcherToTrueIfUnset(SimpleTest test) {
private final String name;
private final SimpleTest test;
private final boolean skip;
private final boolean usePlanner;

public ConformanceTest(String name, SimpleTest test, boolean skip) {
public ConformanceTest(String name, SimpleTest test, boolean skip, boolean usePlanner) {
this.name = Preconditions.checkNotNull(name);
this.test =
Preconditions.checkNotNull(
defaultTestMatcherToTrueIfUnset(Preconditions.checkNotNull(test)));
this.skip = skip;
this.usePlanner = usePlanner;
}

public String getName() {
Expand All@@ -178,7 +192,9 @@ public boolean shouldSkip() {
public void evaluate() throws Throwable {
CelValidationResult response = getParser(test).parse(test.getExpr(), test.getName());
assertThat(response.hasError()).isFalse();
response = getChecker(test).check(response.getAst());
if (!test.getDisableCheck()) {
response = getChecker(test).check(response.getAst());
}
assertThat(response.hasError()).isFalse();
Type resultType = CelProtoTypes.celTypeToType(response.getAst().getResultType());

Expand All@@ -188,7 +204,13 @@ public void evaluate() throws Throwable {
return;
}

Program program = RUNTIME.createProgram(response.getAst());
if (!usePlanner && test.getDisableCheck()) {
// Only planner supports parsed-only evaluation
return;
}

CelRuntime runtime = getRuntime(test, usePlanner);
Program program = runtime.createProgram(response.getAst());
ExprValue result = null;
CelEvaluationException error = null;
try {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ public final class ConformanceTestRunner extends ParentRunner<ConformanceTest> {

private final ImmutableSortedMap<String, SimpleTestFile> testFiles;
private final ImmutableList<String> testsToSkip;
private final boolean usePlanner;

private static ImmutableSortedMap<String, SimpleTestFile> loadTestFiles() {
List<String> testPaths =
Expand DownExpand Up@@ -75,6 +76,9 @@ public ConformanceTestRunner(Class<?> clazz) throws InitializationError {
ImmutableList.copyOf(
SPLITTER.splitToList(
System.getProperty("dev.cel.conformance.ConformanceTests.skip_tests")));
usePlanner =
Boolean.parseBoolean(
System.getProperty("dev.cel.conformance.ConformanceTests.use_planner", "false"));
}

private boolean shouldSkipTest(String name) {
Expand All@@ -97,8 +101,7 @@ protected List<ConformanceTest> getChildren() {
for (SimpleTest test : testSection.getTestList()) {
String name =
String.format("%s/%s/%s", testFile.getName(), testSection.getName(), test.getName());
tests.add(
new ConformanceTest(name, test, test.getDisableCheck() || shouldSkipTest(name)));
tests.add(new ConformanceTest(name, test, shouldSkipTest(name), usePlanner));
}
}
}
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions MODULE.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,18 +16,23 @@ module(
name = "cel_java",
)

bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_jvm_external", version = "6.9")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "rules_jvm_external", version = "6.10")
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33.bcr.1", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "googleapis", version = "0.0.0-20260223-edfe7983", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.2.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_java", version = "9.3.0")
bazel_dep(name = "rules_android", version = "0.7.1")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "googleapis-java", version = "1.0.0")
bazel_dep(name = "cel-spec", version = "0.24.0", repo_name = "cel_spec")
bazel_dep(name = "cel-spec", version = "0.25.1", repo_name = "cel_spec")
bazel_dep(name = "rules_go", version = "0.50.1")

# Required by cel-spec to satisfy gazelle transitive dependency
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)
Expand Down
4 changes: 4 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelEnvironment.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -672,6 +672,10 @@ public CelType toCelType(CelTypeProvider celTypeProvider) {
return TypeParamType.create(name());
}

if (name().equals("dyn")) {
return SimpleType.DYN;
}

CelType simpleType = SimpleType.findByName(name()).orElse(null);
if (simpleType != null) {
return simpleType;
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/dev/cel/common/types/SimpleType.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,6 @@ public abstract class SimpleType extends CelType {

public static final ImmutableMap<String, CelType> TYPE_MAP =
ImmutableMap.of(
DYN.name(), DYN,
BOOL.name(), BOOL,
BYTES.name(), BYTES,
DOUBLE.name(), DOUBLE,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All@@ -27,6 +29,7 @@
import com.google.protobuf.BytesValue;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.google.protobuf.FloatValue;
import com.google.protobuf.Int32Value;
import com.google.protobuf.Int64Value;
Expand All@@ -41,6 +44,8 @@
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.ProtoTimeUtils;
import dev.cel.common.internal.WellKnownProto;
import java.util.ArrayList;
import java.util.List;

/**
* {@code BaseProtoCelValueConverter} contains the common logic for converting between native Java
Expand DownExpand Up@@ -98,6 +103,17 @@ protected Object fromWellKnownProto(MessageLiteOrBuilder message, WellKnownProto
return UnsignedLong.valueOf(((UInt32Value) message).getValue());
case UINT64_VALUE:
return UnsignedLong.fromLongBits(((UInt64Value) message).getValue());
case FIELD_MASK:
FieldMask fieldMask = (FieldMask) message;
List<String> paths = new ArrayList<>(fieldMask.getPathsCount());
for (String path : fieldMask.getPathsList()) {
if (!path.isEmpty()) {
paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
}
}
return normalizePrimitive(Joiner.on(",").join(paths));
case EMPTY:
return ImmutableMap.of();
default:
throw new UnsupportedOperationException(
"Unsupported well known proto conversion - " + wellKnownProto);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,10 @@ public Object unwrap(CelValue celValue) {
return Optional.of(optionalValue.value());
}

if (celValue instanceof ErrorValue) {
return celValue;
}

return celValue.value();
}

Expand Down
80 changes: 70 additions & 10 deletions conformance/src/test/java/dev/cel/conformance/BUILD.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ java_library(
"//parser:parser_builder",
"//parser:parser_factory",
"//runtime",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -57,6 +58,8 @@ java_library(
deps = MAVEN_JAR_DEPS + [
"//:java_truth",
"//compiler:compiler_builder",
"//parser:parser_factory",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -100,14 +103,8 @@ _ALL_TESTS = [
"@cel_spec//tests/simple:testdata/wrappers.textproto",
]

_TESTS_TO_SKIP = [
# Tests which require spec changes.
# TODO: Deprecate Duration.get_milliseconds
"timestamps/duration_converters/get_milliseconds",

_TESTS_TO_SKIP_LEGACY = [
# Broken test cases which should be supported.
# TODO: Invalid bytes to string conversion should error.
"conversions/string/bytes_invalid",
# TODO: Support setting / getting enum values out of the defined enum value range.
"enums/legacy_proto2/select_big,select_neg",
"enums/legacy_proto2/assign_standalone_int_big,assign_standalone_int_neg",
Expand All@@ -116,7 +113,6 @@ _TESTS_TO_SKIP = [
# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
# TODO: Duration and timestamp operations should error on overflow.
"timestamps/duration_range/from_string_under,from_string_over",
"timestamps/timestamp_range/sub_time_duration_over,sub_time_duration_under",
# TODO: Ensure adding negative duration values is appropriately supported.
"timestamps/timestamp_arithmetic/add_time_to_duration_nanos_negative",
Expand DownExpand Up@@ -159,21 +155,85 @@ _TESTS_TO_SKIP = [
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",
]

_TESTS_TO_SKIP_PLANNER = [
# TODO: Add strings.format and strings.quote.
"string_ext/quote",
"string_ext/format",
"string_ext/format_errors",

# TODO: Check behavior for go/cpp
"basic/functions/unbound",
"basic/functions/unbound_is_runtime_error",

# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
"enums/legacy_proto3/assign_standalone_int_too_big",
"enums/legacy_proto3/assign_standalone_int_too_neg",

# TODO: Duration and timestamp operations should error on overflow.
"timestamps/timestamp_range/sub_time_duration_over",
"timestamps/timestamp_range/sub_time_duration_under",

# Skip until fixed.
"fields/qualified_identifier_resolution/map_key_float",
"fields/qualified_identifier_resolution/map_key_null",
"fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",
"optionals/optionals/map_null_entry_no_such_key",
"optionals/optionals/map_present_key_invalid_field",
"parse/receiver_function_names",
"proto2/extensions_get/package_scoped_test_all_types_ext",
"proto2/extensions_get/package_scoped_repeated_test_all_types",
"proto2/extensions_get/message_scoped_nested_ext",
"proto2/extensions_get/message_scoped_repeated_test_all_types",
"proto2_ext/get_ext/package_scoped_repeated_test_all_types",
"proto2_ext/get_ext/message_scoped_repeated_test_all_types",

# TODO: Fix null assignment to a field
"proto2/set_null/single_message",
"proto2/set_null/single_duration",
"proto2/set_null/single_timestamp",
"proto3/set_null/single_message",
"proto3/set_null/single_duration",
"proto3/set_null/single_timestamp",

# Type inference edgecases around null(able) assignability.
# These type check, but resolve to a different type.
# list(int), want list(wrapper(int))
"type_deductions/wrappers/wrapper_promotion",
# list(null), want list(Message)
"type_deductions/legacy_nullable_types/null_assignable_to_message_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_abstract_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_duration_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",

# Future features for CEL 1.0
# TODO: Strong typing support for enums, specified but not implemented.
"enums/strong_proto2",
"enums/strong_proto3",
]

conformance_test(
name = "conformance",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_maven",
data = _ALL_TESTS,
mode = MODE.MAVEN_TEST,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_dashboard",
data = _ALL_TESTS,
mode = MODE.DASHBOARD,
)

conformance_test(
name = "conformance_planner",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP_PLANNER,
use_planner = True,
)
46 changes: 34 additions & 12 deletions conformance/src/test/java/dev/cel/conformance/ConformanceTest.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,9 @@
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelRuntime.Program;
import dev.cel.runtime.CelRuntimeBuilder;
import dev.cel.runtime.CelRuntimeFactory;
import dev.cel.runtime.CelRuntimeImpl;
import dev.cel.runtime.CelRuntimeLibrary;
import java.util.Map;
import org.junit.runners.model.Statement;
Expand DownExpand Up@@ -118,15 +120,25 @@ private static CelChecker getChecker(SimpleTest test) throws Exception {
.build();
}

private static final CelRuntime RUNTIME =
CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor())
.build();
private static CelRuntime getRuntime(SimpleTest test, boolean usePlanner) {
CelRuntimeBuilder builder =
usePlanner ? CelRuntimeImpl.newBuilder() : CelRuntimeFactory.standardCelRuntimeBuilder();

builder
// CEL-Internal-2
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor());

if (usePlanner) {
builder.setContainer(CelContainer.ofName(test.getContainer()));
}

return builder.build();
}

private static ImmutableMap<String, Object> getBindings(SimpleTest test) throws Exception {
ImmutableMap.Builder<String, Object> bindings =
Expand DownExpand Up@@ -157,13 +169,15 @@ private static SimpleTest defaultTestMatcherToTrueIfUnset(SimpleTest test) {
private final String name;
private final SimpleTest test;
private final boolean skip;
private final boolean usePlanner;

public ConformanceTest(String name, SimpleTest test, boolean skip) {
public ConformanceTest(String name, SimpleTest test, boolean skip, boolean usePlanner) {
this.name = Preconditions.checkNotNull(name);
this.test =
Preconditions.checkNotNull(
defaultTestMatcherToTrueIfUnset(Preconditions.checkNotNull(test)));
this.skip = skip;
this.usePlanner = usePlanner;
}

public String getName() {
Expand All@@ -178,7 +192,9 @@ public boolean shouldSkip() {
public void evaluate() throws Throwable {
CelValidationResult response = getParser(test).parse(test.getExpr(), test.getName());
assertThat(response.hasError()).isFalse();
response = getChecker(test).check(response.getAst());
if (!test.getDisableCheck()) {
response = getChecker(test).check(response.getAst());
}
assertThat(response.hasError()).isFalse();
Type resultType = CelProtoTypes.celTypeToType(response.getAst().getResultType());

Expand All@@ -188,7 +204,13 @@ public void evaluate() throws Throwable {
return;
}

Program program = RUNTIME.createProgram(response.getAst());
if (!usePlanner && test.getDisableCheck()) {
// Only planner supports parsed-only evaluation
return;
}

CelRuntime runtime = getRuntime(test, usePlanner);
Program program = runtime.createProgram(response.getAst());
ExprValue result = null;
CelEvaluationException error = null;
try {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ public final class ConformanceTestRunner extends ParentRunner<ConformanceTest> {

private final ImmutableSortedMap<String, SimpleTestFile> testFiles;
private final ImmutableList<String> testsToSkip;
private final boolean usePlanner;

private static ImmutableSortedMap<String, SimpleTestFile> loadTestFiles() {
List<String> testPaths =
Expand DownExpand Up@@ -75,6 +76,9 @@ public ConformanceTestRunner(Class<?> clazz) throws InitializationError {
ImmutableList.copyOf(
SPLITTER.splitToList(
System.getProperty("dev.cel.conformance.ConformanceTests.skip_tests")));
usePlanner =
Boolean.parseBoolean(
System.getProperty("dev.cel.conformance.ConformanceTests.use_planner", "false"));
}

private boolean shouldSkipTest(String name) {
Expand All@@ -97,8 +101,7 @@ protected List<ConformanceTest> getChildren() {
for (SimpleTest test : testSection.getTestList()) {
String name =
String.format("%s/%s/%s", testFile.getName(), testSection.getName(), test.getName());
tests.add(
new ConformanceTest(name, test, test.getDisableCheck() || shouldSkipTest(name)));
tests.add(new ConformanceTest(name, test, shouldSkipTest(name), usePlanner));
}
}
}
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions MODULE.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,18 +16,23 @@ module(
name = "cel_java",
)

bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_jvm_external", version = "6.9")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "rules_jvm_external", version = "6.10")
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33.bcr.1", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "googleapis", version = "0.0.0-20260223-edfe7983", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.2.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_java", version = "9.3.0")
bazel_dep(name = "rules_android", version = "0.7.1")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "googleapis-java", version = "1.0.0")
bazel_dep(name = "cel-spec", version = "0.24.0", repo_name = "cel_spec")
bazel_dep(name = "cel-spec", version = "0.25.1", repo_name = "cel_spec")
bazel_dep(name = "rules_go", version = "0.50.1")

# Required by cel-spec to satisfy gazelle transitive dependency
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)
Expand Down
4 changes: 4 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelEnvironment.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -672,6 +672,10 @@ public CelType toCelType(CelTypeProvider celTypeProvider) {
return TypeParamType.create(name());
}

if (name().equals("dyn")) {
return SimpleType.DYN;
}

CelType simpleType = SimpleType.findByName(name()).orElse(null);
if (simpleType != null) {
return simpleType;
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/dev/cel/common/types/SimpleType.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,6 @@ public abstract class SimpleType extends CelType {

public static final ImmutableMap<String, CelType> TYPE_MAP =
ImmutableMap.of(
DYN.name(), DYN,
BOOL.name(), BOOL,
BYTES.name(), BYTES,
DOUBLE.name(), DOUBLE,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All@@ -27,6 +29,7 @@
import com.google.protobuf.BytesValue;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.google.protobuf.FloatValue;
import com.google.protobuf.Int32Value;
import com.google.protobuf.Int64Value;
Expand All@@ -41,6 +44,8 @@
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.ProtoTimeUtils;
import dev.cel.common.internal.WellKnownProto;
import java.util.ArrayList;
import java.util.List;

/**
* {@code BaseProtoCelValueConverter} contains the common logic for converting between native Java
Expand DownExpand Up@@ -98,6 +103,17 @@ protected Object fromWellKnownProto(MessageLiteOrBuilder message, WellKnownProto
return UnsignedLong.valueOf(((UInt32Value) message).getValue());
case UINT64_VALUE:
return UnsignedLong.fromLongBits(((UInt64Value) message).getValue());
case FIELD_MASK:
FieldMask fieldMask = (FieldMask) message;
List<String> paths = new ArrayList<>(fieldMask.getPathsCount());
for (String path : fieldMask.getPathsList()) {
if (!path.isEmpty()) {
paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
}
}
return normalizePrimitive(Joiner.on(",").join(paths));
case EMPTY:
return ImmutableMap.of();
default:
throw new UnsupportedOperationException(
"Unsupported well known proto conversion - " + wellKnownProto);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,10 @@ public Object unwrap(CelValue celValue) {
return Optional.of(optionalValue.value());
}

if (celValue instanceof ErrorValue) {
return celValue;
}

return celValue.value();
}

Expand Down
80 changes: 70 additions & 10 deletions conformance/src/test/java/dev/cel/conformance/BUILD.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ java_library(
"//parser:parser_builder",
"//parser:parser_factory",
"//runtime",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -57,6 +58,8 @@ java_library(
deps = MAVEN_JAR_DEPS + [
"//:java_truth",
"//compiler:compiler_builder",
"//parser:parser_factory",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -100,14 +103,8 @@ _ALL_TESTS = [
"@cel_spec//tests/simple:testdata/wrappers.textproto",
]

_TESTS_TO_SKIP = [
# Tests which require spec changes.
# TODO: Deprecate Duration.get_milliseconds
"timestamps/duration_converters/get_milliseconds",

_TESTS_TO_SKIP_LEGACY = [
# Broken test cases which should be supported.
# TODO: Invalid bytes to string conversion should error.
"conversions/string/bytes_invalid",
# TODO: Support setting / getting enum values out of the defined enum value range.
"enums/legacy_proto2/select_big,select_neg",
"enums/legacy_proto2/assign_standalone_int_big,assign_standalone_int_neg",
Expand All@@ -116,7 +113,6 @@ _TESTS_TO_SKIP = [
# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
# TODO: Duration and timestamp operations should error on overflow.
"timestamps/duration_range/from_string_under,from_string_over",
"timestamps/timestamp_range/sub_time_duration_over,sub_time_duration_under",
# TODO: Ensure adding negative duration values is appropriately supported.
"timestamps/timestamp_arithmetic/add_time_to_duration_nanos_negative",
Expand DownExpand Up@@ -159,21 +155,85 @@ _TESTS_TO_SKIP = [
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",
]

_TESTS_TO_SKIP_PLANNER = [
# TODO: Add strings.format and strings.quote.
"string_ext/quote",
"string_ext/format",
"string_ext/format_errors",

# TODO: Check behavior for go/cpp
"basic/functions/unbound",
"basic/functions/unbound_is_runtime_error",

# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
"enums/legacy_proto3/assign_standalone_int_too_big",
"enums/legacy_proto3/assign_standalone_int_too_neg",

# TODO: Duration and timestamp operations should error on overflow.
"timestamps/timestamp_range/sub_time_duration_over",
"timestamps/timestamp_range/sub_time_duration_under",

# Skip until fixed.
"fields/qualified_identifier_resolution/map_key_float",
"fields/qualified_identifier_resolution/map_key_null",
"fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",
"optionals/optionals/map_null_entry_no_such_key",
"optionals/optionals/map_present_key_invalid_field",
"parse/receiver_function_names",
"proto2/extensions_get/package_scoped_test_all_types_ext",
"proto2/extensions_get/package_scoped_repeated_test_all_types",
"proto2/extensions_get/message_scoped_nested_ext",
"proto2/extensions_get/message_scoped_repeated_test_all_types",
"proto2_ext/get_ext/package_scoped_repeated_test_all_types",
"proto2_ext/get_ext/message_scoped_repeated_test_all_types",

# TODO: Fix null assignment to a field
"proto2/set_null/single_message",
"proto2/set_null/single_duration",
"proto2/set_null/single_timestamp",
"proto3/set_null/single_message",
"proto3/set_null/single_duration",
"proto3/set_null/single_timestamp",

# Type inference edgecases around null(able) assignability.
# These type check, but resolve to a different type.
# list(int), want list(wrapper(int))
"type_deductions/wrappers/wrapper_promotion",
# list(null), want list(Message)
"type_deductions/legacy_nullable_types/null_assignable_to_message_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_abstract_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_duration_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",

# Future features for CEL 1.0
# TODO: Strong typing support for enums, specified but not implemented.
"enums/strong_proto2",
"enums/strong_proto3",
]

conformance_test(
name = "conformance",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_maven",
data = _ALL_TESTS,
mode = MODE.MAVEN_TEST,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_dashboard",
data = _ALL_TESTS,
mode = MODE.DASHBOARD,
)

conformance_test(
name = "conformance_planner",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP_PLANNER,
use_planner = True,
)
46 changes: 34 additions & 12 deletions conformance/src/test/java/dev/cel/conformance/ConformanceTest.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,9 @@
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelRuntime.Program;
import dev.cel.runtime.CelRuntimeBuilder;
import dev.cel.runtime.CelRuntimeFactory;
import dev.cel.runtime.CelRuntimeImpl;
import dev.cel.runtime.CelRuntimeLibrary;
import java.util.Map;
import org.junit.runners.model.Statement;
Expand DownExpand Up@@ -118,15 +120,25 @@ private static CelChecker getChecker(SimpleTest test) throws Exception {
.build();
}

private static final CelRuntime RUNTIME =
CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor())
.build();
private static CelRuntime getRuntime(SimpleTest test, boolean usePlanner) {
CelRuntimeBuilder builder =
usePlanner ? CelRuntimeImpl.newBuilder() : CelRuntimeFactory.standardCelRuntimeBuilder();

builder
// CEL-Internal-2
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor());

if (usePlanner) {
builder.setContainer(CelContainer.ofName(test.getContainer()));
}

return builder.build();
}

private static ImmutableMap<String, Object> getBindings(SimpleTest test) throws Exception {
ImmutableMap.Builder<String, Object> bindings =
Expand DownExpand Up@@ -157,13 +169,15 @@ private static SimpleTest defaultTestMatcherToTrueIfUnset(SimpleTest test) {
private final String name;
private final SimpleTest test;
private final boolean skip;
private final boolean usePlanner;

public ConformanceTest(String name, SimpleTest test, boolean skip) {
public ConformanceTest(String name, SimpleTest test, boolean skip, boolean usePlanner) {
this.name = Preconditions.checkNotNull(name);
this.test =
Preconditions.checkNotNull(
defaultTestMatcherToTrueIfUnset(Preconditions.checkNotNull(test)));
this.skip = skip;
this.usePlanner = usePlanner;
}

public String getName() {
Expand All@@ -178,7 +192,9 @@ public boolean shouldSkip() {
public void evaluate() throws Throwable {
CelValidationResult response = getParser(test).parse(test.getExpr(), test.getName());
assertThat(response.hasError()).isFalse();
response = getChecker(test).check(response.getAst());
if (!test.getDisableCheck()) {
response = getChecker(test).check(response.getAst());
}
assertThat(response.hasError()).isFalse();
Type resultType = CelProtoTypes.celTypeToType(response.getAst().getResultType());

Expand All@@ -188,7 +204,13 @@ public void evaluate() throws Throwable {
return;
}

Program program = RUNTIME.createProgram(response.getAst());
if (!usePlanner && test.getDisableCheck()) {
// Only planner supports parsed-only evaluation
return;
}

CelRuntime runtime = getRuntime(test, usePlanner);
Program program = runtime.createProgram(response.getAst());
ExprValue result = null;
CelEvaluationException error = null;
try {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ public final class ConformanceTestRunner extends ParentRunner<ConformanceTest> {

private final ImmutableSortedMap<String, SimpleTestFile> testFiles;
private final ImmutableList<String> testsToSkip;
private final boolean usePlanner;

private static ImmutableSortedMap<String, SimpleTestFile> loadTestFiles() {
List<String> testPaths =
Expand DownExpand Up@@ -75,6 +76,9 @@ public ConformanceTestRunner(Class<?> clazz) throws InitializationError {
ImmutableList.copyOf(
SPLITTER.splitToList(
System.getProperty("dev.cel.conformance.ConformanceTests.skip_tests")));
usePlanner =
Boolean.parseBoolean(
System.getProperty("dev.cel.conformance.ConformanceTests.use_planner", "false"));
}

private boolean shouldSkipTest(String name) {
Expand All@@ -97,8 +101,7 @@ protected List<ConformanceTest> getChildren() {
for (SimpleTest test : testSection.getTestList()) {
String name =
String.format("%s/%s/%s", testFile.getName(), testSection.getName(), test.getName());
tests.add(
new ConformanceTest(name, test, test.getDisableCheck() || shouldSkipTest(name)));
tests.add(new ConformanceTest(name, test, shouldSkipTest(name), usePlanner));
}
}
}
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions MODULE.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,18 +16,23 @@ module(
name = "cel_java",
)

bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_jvm_external", version = "6.9")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "rules_jvm_external", version = "6.10")
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33.bcr.1", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "googleapis", version = "0.0.0-20260223-edfe7983", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.2.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_java", version = "9.3.0")
bazel_dep(name = "rules_android", version = "0.7.1")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "googleapis-java", version = "1.0.0")
bazel_dep(name = "cel-spec", version = "0.24.0", repo_name = "cel_spec")
bazel_dep(name = "cel-spec", version = "0.25.1", repo_name = "cel_spec")
bazel_dep(name = "rules_go", version = "0.50.1")

# Required by cel-spec to satisfy gazelle transitive dependency
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)
Expand Down
4 changes: 4 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelEnvironment.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -672,6 +672,10 @@ public CelType toCelType(CelTypeProvider celTypeProvider) {
return TypeParamType.create(name());
}

if (name().equals("dyn")) {
return SimpleType.DYN;
}

CelType simpleType = SimpleType.findByName(name()).orElse(null);
if (simpleType != null) {
return simpleType;
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/dev/cel/common/types/SimpleType.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,6 @@ public abstract class SimpleType extends CelType {

public static final ImmutableMap<String, CelType> TYPE_MAP =
ImmutableMap.of(
DYN.name(), DYN,
BOOL.name(), BOOL,
BYTES.name(), BYTES,
DOUBLE.name(), DOUBLE,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All@@ -27,6 +29,7 @@
import com.google.protobuf.BytesValue;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.google.protobuf.FloatValue;
import com.google.protobuf.Int32Value;
import com.google.protobuf.Int64Value;
Expand All@@ -41,6 +44,8 @@
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.ProtoTimeUtils;
import dev.cel.common.internal.WellKnownProto;
import java.util.ArrayList;
import java.util.List;

/**
* {@code BaseProtoCelValueConverter} contains the common logic for converting between native Java
Expand DownExpand Up@@ -98,6 +103,17 @@ protected Object fromWellKnownProto(MessageLiteOrBuilder message, WellKnownProto
return UnsignedLong.valueOf(((UInt32Value) message).getValue());
case UINT64_VALUE:
return UnsignedLong.fromLongBits(((UInt64Value) message).getValue());
case FIELD_MASK:
FieldMask fieldMask = (FieldMask) message;
List<String> paths = new ArrayList<>(fieldMask.getPathsCount());
for (String path : fieldMask.getPathsList()) {
if (!path.isEmpty()) {
paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
}
}
return normalizePrimitive(Joiner.on(",").join(paths));
case EMPTY:
return ImmutableMap.of();
default:
throw new UnsupportedOperationException(
"Unsupported well known proto conversion - " + wellKnownProto);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,10 @@ public Object unwrap(CelValue celValue) {
return Optional.of(optionalValue.value());
}

if (celValue instanceof ErrorValue) {
return celValue;
}

return celValue.value();
}

Expand Down
80 changes: 70 additions & 10 deletions conformance/src/test/java/dev/cel/conformance/BUILD.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ java_library(
"//parser:parser_builder",
"//parser:parser_factory",
"//runtime",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -57,6 +58,8 @@ java_library(
deps = MAVEN_JAR_DEPS + [
"//:java_truth",
"//compiler:compiler_builder",
"//parser:parser_factory",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -100,14 +103,8 @@ _ALL_TESTS = [
"@cel_spec//tests/simple:testdata/wrappers.textproto",
]

_TESTS_TO_SKIP = [
# Tests which require spec changes.
# TODO: Deprecate Duration.get_milliseconds
"timestamps/duration_converters/get_milliseconds",

_TESTS_TO_SKIP_LEGACY = [
# Broken test cases which should be supported.
# TODO: Invalid bytes to string conversion should error.
"conversions/string/bytes_invalid",
# TODO: Support setting / getting enum values out of the defined enum value range.
"enums/legacy_proto2/select_big,select_neg",
"enums/legacy_proto2/assign_standalone_int_big,assign_standalone_int_neg",
Expand All@@ -116,7 +113,6 @@ _TESTS_TO_SKIP = [
# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
# TODO: Duration and timestamp operations should error on overflow.
"timestamps/duration_range/from_string_under,from_string_over",
"timestamps/timestamp_range/sub_time_duration_over,sub_time_duration_under",
# TODO: Ensure adding negative duration values is appropriately supported.
"timestamps/timestamp_arithmetic/add_time_to_duration_nanos_negative",
Expand DownExpand Up@@ -159,21 +155,85 @@ _TESTS_TO_SKIP = [
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",
]

_TESTS_TO_SKIP_PLANNER = [
# TODO: Add strings.format and strings.quote.
"string_ext/quote",
"string_ext/format",
"string_ext/format_errors",

# TODO: Check behavior for go/cpp
"basic/functions/unbound",
"basic/functions/unbound_is_runtime_error",

# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
"enums/legacy_proto3/assign_standalone_int_too_big",
"enums/legacy_proto3/assign_standalone_int_too_neg",

# TODO: Duration and timestamp operations should error on overflow.
"timestamps/timestamp_range/sub_time_duration_over",
"timestamps/timestamp_range/sub_time_duration_under",

# Skip until fixed.
"fields/qualified_identifier_resolution/map_key_float",
"fields/qualified_identifier_resolution/map_key_null",
"fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",
"optionals/optionals/map_null_entry_no_such_key",
"optionals/optionals/map_present_key_invalid_field",
"parse/receiver_function_names",
"proto2/extensions_get/package_scoped_test_all_types_ext",
"proto2/extensions_get/package_scoped_repeated_test_all_types",
"proto2/extensions_get/message_scoped_nested_ext",
"proto2/extensions_get/message_scoped_repeated_test_all_types",
"proto2_ext/get_ext/package_scoped_repeated_test_all_types",
"proto2_ext/get_ext/message_scoped_repeated_test_all_types",

# TODO: Fix null assignment to a field
"proto2/set_null/single_message",
"proto2/set_null/single_duration",
"proto2/set_null/single_timestamp",
"proto3/set_null/single_message",
"proto3/set_null/single_duration",
"proto3/set_null/single_timestamp",

# Type inference edgecases around null(able) assignability.
# These type check, but resolve to a different type.
# list(int), want list(wrapper(int))
"type_deductions/wrappers/wrapper_promotion",
# list(null), want list(Message)
"type_deductions/legacy_nullable_types/null_assignable_to_message_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_abstract_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_duration_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",

# Future features for CEL 1.0
# TODO: Strong typing support for enums, specified but not implemented.
"enums/strong_proto2",
"enums/strong_proto3",
]

conformance_test(
name = "conformance",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_maven",
data = _ALL_TESTS,
mode = MODE.MAVEN_TEST,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_dashboard",
data = _ALL_TESTS,
mode = MODE.DASHBOARD,
)

conformance_test(
name = "conformance_planner",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP_PLANNER,
use_planner = True,
)
46 changes: 34 additions & 12 deletions conformance/src/test/java/dev/cel/conformance/ConformanceTest.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,9 @@
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelRuntime.Program;
import dev.cel.runtime.CelRuntimeBuilder;
import dev.cel.runtime.CelRuntimeFactory;
import dev.cel.runtime.CelRuntimeImpl;
import dev.cel.runtime.CelRuntimeLibrary;
import java.util.Map;
import org.junit.runners.model.Statement;
Expand DownExpand Up@@ -118,15 +120,25 @@ private static CelChecker getChecker(SimpleTest test) throws Exception {
.build();
}

private static final CelRuntime RUNTIME =
CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor())
.build();
private static CelRuntime getRuntime(SimpleTest test, boolean usePlanner) {
CelRuntimeBuilder builder =
usePlanner ? CelRuntimeImpl.newBuilder() : CelRuntimeFactory.standardCelRuntimeBuilder();

builder
// CEL-Internal-2
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor());

if (usePlanner) {
builder.setContainer(CelContainer.ofName(test.getContainer()));
}

return builder.build();
}

private static ImmutableMap<String, Object> getBindings(SimpleTest test) throws Exception {
ImmutableMap.Builder<String, Object> bindings =
Expand DownExpand Up@@ -157,13 +169,15 @@ private static SimpleTest defaultTestMatcherToTrueIfUnset(SimpleTest test) {
private final String name;
private final SimpleTest test;
private final boolean skip;
private final boolean usePlanner;

public ConformanceTest(String name, SimpleTest test, boolean skip) {
public ConformanceTest(String name, SimpleTest test, boolean skip, boolean usePlanner) {
this.name = Preconditions.checkNotNull(name);
this.test =
Preconditions.checkNotNull(
defaultTestMatcherToTrueIfUnset(Preconditions.checkNotNull(test)));
this.skip = skip;
this.usePlanner = usePlanner;
}

public String getName() {
Expand All@@ -178,7 +192,9 @@ public boolean shouldSkip() {
public void evaluate() throws Throwable {
CelValidationResult response = getParser(test).parse(test.getExpr(), test.getName());
assertThat(response.hasError()).isFalse();
response = getChecker(test).check(response.getAst());
if (!test.getDisableCheck()) {
response = getChecker(test).check(response.getAst());
}
assertThat(response.hasError()).isFalse();
Type resultType = CelProtoTypes.celTypeToType(response.getAst().getResultType());

Expand All@@ -188,7 +204,13 @@ public void evaluate() throws Throwable {
return;
}

Program program = RUNTIME.createProgram(response.getAst());
if (!usePlanner && test.getDisableCheck()) {
// Only planner supports parsed-only evaluation
return;
}

CelRuntime runtime = getRuntime(test, usePlanner);
Program program = runtime.createProgram(response.getAst());
ExprValue result = null;
CelEvaluationException error = null;
try {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ public final class ConformanceTestRunner extends ParentRunner<ConformanceTest> {

private final ImmutableSortedMap<String, SimpleTestFile> testFiles;
private final ImmutableList<String> testsToSkip;
private final boolean usePlanner;

private static ImmutableSortedMap<String, SimpleTestFile> loadTestFiles() {
List<String> testPaths =
Expand DownExpand Up@@ -75,6 +76,9 @@ public ConformanceTestRunner(Class<?> clazz) throws InitializationError {
ImmutableList.copyOf(
SPLITTER.splitToList(
System.getProperty("dev.cel.conformance.ConformanceTests.skip_tests")));
usePlanner =
Boolean.parseBoolean(
System.getProperty("dev.cel.conformance.ConformanceTests.use_planner", "false"));
}

private boolean shouldSkipTest(String name) {
Expand All@@ -97,8 +101,7 @@ protected List<ConformanceTest> getChildren() {
for (SimpleTest test : testSection.getTestList()) {
String name =
String.format("%s/%s/%s", testFile.getName(), testSection.getName(), test.getName());
tests.add(
new ConformanceTest(name, test, test.getDisableCheck() || shouldSkipTest(name)));
tests.add(new ConformanceTest(name, test, shouldSkipTest(name), usePlanner));
}
}
}
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions MODULE.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,18 +16,23 @@ module(
name = "cel_java",
)

bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_jvm_external", version = "6.9")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "rules_jvm_external", version = "6.10")
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33.bcr.1", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "googleapis", version = "0.0.0-20260223-edfe7983", repo_name = "com_google_googleapis")
bazel_dep(name = "rules_pkg", version = "1.2.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_java", version = "9.3.0")
bazel_dep(name = "rules_android", version = "0.7.1")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "googleapis-java", version = "1.0.0")
bazel_dep(name = "cel-spec", version = "0.24.0", repo_name = "cel_spec")
bazel_dep(name = "cel-spec", version = "0.25.1", repo_name = "cel_spec")
bazel_dep(name = "rules_go", version = "0.50.1")

# Required by cel-spec to satisfy gazelle transitive dependency
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)
Expand Down
4 changes: 4 additions & 0 deletions bundle/src/main/java/dev/cel/bundle/CelEnvironment.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -672,6 +672,10 @@ public CelType toCelType(CelTypeProvider celTypeProvider) {
return TypeParamType.create(name());
}

if (name().equals("dyn")) {
return SimpleType.DYN;
}

CelType simpleType = SimpleType.findByName(name()).orElse(null);
if (simpleType != null) {
return simpleType;
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/dev/cel/common/types/SimpleType.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,6 @@ public abstract class SimpleType extends CelType {

public static final ImmutableMap<String, CelType> TYPE_MAP =
ImmutableMap.of(
DYN.name(), DYN,
BOOL.name(), BOOL,
BYTES.name(), BYTES,
DOUBLE.name(), DOUBLE,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All@@ -27,6 +29,7 @@
import com.google.protobuf.BytesValue;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.Duration;
import com.google.protobuf.FieldMask;
import com.google.protobuf.FloatValue;
import com.google.protobuf.Int32Value;
import com.google.protobuf.Int64Value;
Expand All@@ -41,6 +44,8 @@
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.ProtoTimeUtils;
import dev.cel.common.internal.WellKnownProto;
import java.util.ArrayList;
import java.util.List;

/**
* {@code BaseProtoCelValueConverter} contains the common logic for converting between native Java
Expand DownExpand Up@@ -98,6 +103,17 @@ protected Object fromWellKnownProto(MessageLiteOrBuilder message, WellKnownProto
return UnsignedLong.valueOf(((UInt32Value) message).getValue());
case UINT64_VALUE:
return UnsignedLong.fromLongBits(((UInt64Value) message).getValue());
case FIELD_MASK:
FieldMask fieldMask = (FieldMask) message;
List<String> paths = new ArrayList<>(fieldMask.getPathsCount());
for (String path : fieldMask.getPathsList()) {
if (!path.isEmpty()) {
paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
}
}
return normalizePrimitive(Joiner.on(",").join(paths));
case EMPTY:
return ImmutableMap.of();
default:
throw new UnsupportedOperationException(
"Unsupported well known proto conversion - " + wellKnownProto);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,10 @@ public Object unwrap(CelValue celValue) {
return Optional.of(optionalValue.value());
}

if (celValue instanceof ErrorValue) {
return celValue;
}

return celValue.value();
}

Expand Down
80 changes: 70 additions & 10 deletions conformance/src/test/java/dev/cel/conformance/BUILD.bazel
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ java_library(
"//parser:parser_builder",
"//parser:parser_factory",
"//runtime",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -57,6 +58,8 @@ java_library(
deps = MAVEN_JAR_DEPS + [
"//:java_truth",
"//compiler:compiler_builder",
"//parser:parser_factory",
"//runtime:runtime_planner_impl",
"//testing:expr_value_utils",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
Expand DownExpand Up@@ -100,14 +103,8 @@ _ALL_TESTS = [
"@cel_spec//tests/simple:testdata/wrappers.textproto",
]

_TESTS_TO_SKIP = [
# Tests which require spec changes.
# TODO: Deprecate Duration.get_milliseconds
"timestamps/duration_converters/get_milliseconds",

_TESTS_TO_SKIP_LEGACY = [
# Broken test cases which should be supported.
# TODO: Invalid bytes to string conversion should error.
"conversions/string/bytes_invalid",
# TODO: Support setting / getting enum values out of the defined enum value range.
"enums/legacy_proto2/select_big,select_neg",
"enums/legacy_proto2/assign_standalone_int_big,assign_standalone_int_neg",
Expand All@@ -116,7 +113,6 @@ _TESTS_TO_SKIP = [
# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
# TODO: Duration and timestamp operations should error on overflow.
"timestamps/duration_range/from_string_under,from_string_over",
"timestamps/timestamp_range/sub_time_duration_over,sub_time_duration_under",
# TODO: Ensure adding negative duration values is appropriately supported.
"timestamps/timestamp_arithmetic/add_time_to_duration_nanos_negative",
Expand DownExpand Up@@ -159,21 +155,85 @@ _TESTS_TO_SKIP = [
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",
]

_TESTS_TO_SKIP_PLANNER = [
# TODO: Add strings.format and strings.quote.
"string_ext/quote",
"string_ext/format",
"string_ext/format_errors",

# TODO: Check behavior for go/cpp
"basic/functions/unbound",
"basic/functions/unbound_is_runtime_error",

# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
"conversions/int/double_int_min_range",
"enums/legacy_proto3/assign_standalone_int_too_big",
"enums/legacy_proto3/assign_standalone_int_too_neg",

# TODO: Duration and timestamp operations should error on overflow.
"timestamps/timestamp_range/sub_time_duration_over",
"timestamps/timestamp_range/sub_time_duration_under",

# Skip until fixed.
"fields/qualified_identifier_resolution/map_key_float",
"fields/qualified_identifier_resolution/map_key_null",
"fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",
"optionals/optionals/map_null_entry_no_such_key",
"optionals/optionals/map_present_key_invalid_field",
"parse/receiver_function_names",
"proto2/extensions_get/package_scoped_test_all_types_ext",
"proto2/extensions_get/package_scoped_repeated_test_all_types",
"proto2/extensions_get/message_scoped_nested_ext",
"proto2/extensions_get/message_scoped_repeated_test_all_types",
"proto2_ext/get_ext/package_scoped_repeated_test_all_types",
"proto2_ext/get_ext/message_scoped_repeated_test_all_types",

# TODO: Fix null assignment to a field
"proto2/set_null/single_message",
"proto2/set_null/single_duration",
"proto2/set_null/single_timestamp",
"proto3/set_null/single_message",
"proto3/set_null/single_duration",
"proto3/set_null/single_timestamp",

# Type inference edgecases around null(able) assignability.
# These type check, but resolve to a different type.
# list(int), want list(wrapper(int))
"type_deductions/wrappers/wrapper_promotion",
# list(null), want list(Message)
"type_deductions/legacy_nullable_types/null_assignable_to_message_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_abstract_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_duration_parameter_candidate",
"type_deductions/legacy_nullable_types/null_assignable_to_timestamp_parameter_candidate",

# Future features for CEL 1.0
# TODO: Strong typing support for enums, specified but not implemented.
"enums/strong_proto2",
"enums/strong_proto3",
]

conformance_test(
name = "conformance",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_maven",
data = _ALL_TESTS,
mode = MODE.MAVEN_TEST,
skip_tests = _TESTS_TO_SKIP,
skip_tests = _TESTS_TO_SKIP_LEGACY,
)

conformance_test(
name = "conformance_dashboard",
data = _ALL_TESTS,
mode = MODE.DASHBOARD,
)

conformance_test(
name = "conformance_planner",
data = _ALL_TESTS,
skip_tests = _TESTS_TO_SKIP_PLANNER,
use_planner = True,
)
46 changes: 34 additions & 12 deletions conformance/src/test/java/dev/cel/conformance/ConformanceTest.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,9 @@
import dev.cel.runtime.CelEvaluationException;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelRuntime.Program;
import dev.cel.runtime.CelRuntimeBuilder;
import dev.cel.runtime.CelRuntimeFactory;
import dev.cel.runtime.CelRuntimeImpl;
import dev.cel.runtime.CelRuntimeLibrary;
import java.util.Map;
import org.junit.runners.model.Statement;
Expand DownExpand Up@@ -118,15 +120,25 @@ private static CelChecker getChecker(SimpleTest test) throws Exception {
.build();
}

private static final CelRuntime RUNTIME =
CelRuntimeFactory.standardCelRuntimeBuilder()
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor())
.build();
private static CelRuntime getRuntime(SimpleTest test, boolean usePlanner) {
CelRuntimeBuilder builder =
usePlanner ? CelRuntimeImpl.newBuilder() : CelRuntimeFactory.standardCelRuntimeBuilder();

builder
// CEL-Internal-2
.setOptions(OPTIONS)
.addLibraries(CANONICAL_RUNTIME_EXTENSIONS)
.setExtensionRegistry(DEFAULT_EXTENSION_REGISTRY)
.addMessageTypes(dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor())
.addMessageTypes(dev.cel.expr.conformance.proto3.TestAllTypes.getDescriptor())
.addFileTypes(dev.cel.expr.conformance.proto2.TestAllTypesExtensions.getDescriptor());

if (usePlanner) {
builder.setContainer(CelContainer.ofName(test.getContainer()));
}

return builder.build();
}

private static ImmutableMap<String, Object> getBindings(SimpleTest test) throws Exception {
ImmutableMap.Builder<String, Object> bindings =
Expand DownExpand Up@@ -157,13 +169,15 @@ private static SimpleTest defaultTestMatcherToTrueIfUnset(SimpleTest test) {
private final String name;
private final SimpleTest test;
private final boolean skip;
private final boolean usePlanner;

public ConformanceTest(String name, SimpleTest test, boolean skip) {
public ConformanceTest(String name, SimpleTest test, boolean skip, boolean usePlanner) {
this.name = Preconditions.checkNotNull(name);
this.test =
Preconditions.checkNotNull(
defaultTestMatcherToTrueIfUnset(Preconditions.checkNotNull(test)));
this.skip = skip;
this.usePlanner = usePlanner;
}

public String getName() {
Expand All@@ -178,7 +192,9 @@ public boolean shouldSkip() {
public void evaluate() throws Throwable {
CelValidationResult response = getParser(test).parse(test.getExpr(), test.getName());
assertThat(response.hasError()).isFalse();
response = getChecker(test).check(response.getAst());
if (!test.getDisableCheck()) {
response = getChecker(test).check(response.getAst());
}
assertThat(response.hasError()).isFalse();
Type resultType = CelProtoTypes.celTypeToType(response.getAst().getResultType());

Expand All@@ -188,7 +204,13 @@ public void evaluate() throws Throwable {
return;
}

Program program = RUNTIME.createProgram(response.getAst());
if (!usePlanner && test.getDisableCheck()) {
// Only planner supports parsed-only evaluation
return;
}

CelRuntime runtime = getRuntime(test, usePlanner);
Program program = runtime.createProgram(response.getAst());
ExprValue result = null;
CelEvaluationException error = null;
try {
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,6 +43,7 @@ public final class ConformanceTestRunner extends ParentRunner<ConformanceTest> {

private final ImmutableSortedMap<String, SimpleTestFile> testFiles;
private final ImmutableList<String> testsToSkip;
private final boolean usePlanner;

private static ImmutableSortedMap<String, SimpleTestFile> loadTestFiles() {
List<String> testPaths =
Expand DownExpand Up@@ -75,6 +76,9 @@ public ConformanceTestRunner(Class<?> clazz) throws InitializationError {
ImmutableList.copyOf(
SPLITTER.splitToList(
System.getProperty("dev.cel.conformance.ConformanceTests.skip_tests")));
usePlanner =
Boolean.parseBoolean(
System.getProperty("dev.cel.conformance.ConformanceTests.use_planner", "false"));
}

private boolean shouldSkipTest(String name) {
Expand All@@ -97,8 +101,7 @@ protected List<ConformanceTest> getChildren() {
for (SimpleTest test : testSection.getTestList()) {
String name =
String.format("%s/%s/%s", testFile.getName(), testSection.getName(), test.getName());
tests.add(
new ConformanceTest(name, test, test.getDisableCheck() || shouldSkipTest(name)));
tests.add(new ConformanceTest(name, test, shouldSkipTest(name), usePlanner));
}
}
}
Expand Down
Loading
Loading