Skip to content

Commit 8cde8b0

Browse files
l46kokcopybara-github
authored andcommitted
Add isolated artifact tests for dev.cel:compiler and dev.cel:runtime
Includes some CI optimizations for preventing protoc recompilation for Bazel and proper workflow caching PiperOrigin-RevId: 872058140
1 parent 81a8692 commit 8cde8b0

8 files changed

Lines changed: 598 additions & 9 deletions

File tree

.bazelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
common --enable_bzlmod
2+
# Use built-in protoc
3+
common --incompatible_enable_proto_toolchain_resolution --@com_google_protobuf//bazel/toolchains:prefer_prebuilt_protoc
4+
25
build --java_runtime_version=remotejdk_11
36
build --java_language_version=11
47

8+
59
# Hide Java 8 deprecation warnings.
610
common --javacopt=-Xlint:-options
711

812
# Remove flag once https://github.com/google/cel-spec/issues/508 and rules_jvm_external is fixed.
913
common --incompatible_autoload_externally=proto_library,cc_proto_library,java_proto_library,java_test
14+

.github/workflows/workflow.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
disk-cache: ${{ github.workflow }}
3434
# Share repository cache between workflows.
3535
repository-cache: true
36+
# Never write to the cache, strictly read-only
37+
cache-save: false
3638
- name: Unwanted Dependencies
3739
run: .github/workflows/unwanted_deps.sh
3840
- name: Cross-artifact Duplicate Classes Check
@@ -56,6 +58,8 @@ jobs:
5658
disk-cache: ${{ github.workflow }}
5759
# Share repository cache between workflows.
5860
repository-cache: true
61+
# Prevent PRs from polluting cache
62+
cache-save: ${{ github.event_name != 'pull_request' }}
5963
- name: Bazel Output Version
6064
run: bazelisk --version
6165
- name: Java 8 Build
@@ -91,12 +95,14 @@ jobs:
9195
disk-cache: ${{ github.workflow }}
9296
# Share repository cache between workflows.
9397
repository-cache: true
98+
# Never write to the cache, strictly read-only
99+
cache-save: false
94100
- name: Verify Version Consistency
95101
if: steps.changed_file.outputs.any_changed == 'true'
96102
run: |
97103
CEL_VERSION=$(grep 'CEL_VERSION =' publish/cel_version.bzl | cut -d '"' -f 2)
98104
99-
MODULE_VERSION=$(grep 'dev.cel:cel' MODULE.bazel | cut -d '"' -f 2 | cut -d ':' -f 3)
105+
MODULE_VERSION=$(grep 'CEL_VERSION =' MODULE.bazel | cut -d '"' -f 2)
100106
101107
if [ -z "$CEL_VERSION" ] || [ -z "$MODULE_VERSION" ]; then
102108
echo "❌ Error: Could not extract one or both version strings."

MODULE.bazel

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ module(
1616
name = "cel_java",
1717
)
1818

19-
bazel_dep(name = "bazel_skylib", version = "1.7.1")
19+
bazel_dep(name = "bazel_skylib", version = "1.8.2")
2020
bazel_dep(name = "rules_jvm_external", version = "6.9")
21-
bazel_dep(name = "protobuf", version = "29.3", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
21+
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf") # see https://github.com/bazelbuild/rules_android/issues/373
2222
bazel_dep(name = "googleapis", version = "0.0.0-20241220-5e258e33.bcr.1", repo_name = "com_google_googleapis")
2323
bazel_dep(name = "rules_pkg", version = "1.0.1")
2424
bazel_dep(name = "rules_license", version = "1.0.0")
2525
bazel_dep(name = "rules_proto", version = "7.1.0")
26-
bazel_dep(name = "rules_java", version = "8.12.0")
26+
bazel_dep(name = "rules_java", version = "9.3.0")
2727
bazel_dep(name = "rules_android", version = "0.7.1")
28-
bazel_dep(name = "rules_shell", version = "0.5.1")
28+
bazel_dep(name = "rules_shell", version = "0.6.1")
2929
bazel_dep(name = "googleapis-java", version = "1.0.0")
3030
bazel_dep(name = "cel-spec", version = "0.24.0", repo_name = "cel_spec")
3131

@@ -39,7 +39,9 @@ GUAVA_VERSION = "33.5.0"
3939

4040
TRUTH_VERSION = "1.4.4"
4141

42-
PROTOBUF_JAVA_VERSION = "4.33.4"
42+
PROTOBUF_JAVA_VERSION = "4.33.5"
43+
44+
CEL_VERSION = "0.12.0-SNAPSHOT"
4345

4446
# Compile only artifacts
4547
[
@@ -114,7 +116,11 @@ maven.install(
114116

115117
maven.install(
116118
name = "maven_conformance",
117-
artifacts = ["dev.cel:cel:0.11.1"],
119+
artifacts = [
120+
"dev.cel:cel:" + CEL_VERSION,
121+
"dev.cel:compiler:" + CEL_VERSION,
122+
"dev.cel:runtime:" + CEL_VERSION,
123+
],
118124
repositories = [
119125
"https://maven.google.com",
120126
"https://repo1.maven.org/maven2",

conformance/src/test/java/dev/cel/conformance/BUILD.bazel

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ java_library(
4141
],
4242
)
4343

44-
MAVEN_JAR_DEPS = ["@maven_conformance//:dev_cel_cel"]
44+
MAVEN_JAR_DEPS = [
45+
"@maven_conformance//:dev_cel_compiler",
46+
"@maven_conformance//:dev_cel_common",
47+
"@maven_conformance//:dev_cel_runtime",
48+
"@maven_conformance//:dev_cel_protobuf",
49+
"@maven_conformance//:dev_cel_cel",
50+
]
4551

4652
java_library(
4753
name = "run_maven_jar",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
load("@rules_java//java:defs.bzl", "java_test")
2+
3+
package(default_applicable_licenses = [
4+
"//:license",
5+
])
6+
7+
# keep sorted
8+
MAVEN_COMPILER_JAR_DEPS = [
9+
"@maven_conformance//:dev_cel_common",
10+
"@maven_conformance//:dev_cel_compiler",
11+
]
12+
13+
# keep sorted
14+
MAVEN_RUNTIME_JAR_DEPS = [
15+
"@maven_conformance//:dev_cel_common",
16+
"@maven_conformance//:dev_cel_protobuf",
17+
"@maven_conformance//:dev_cel_runtime",
18+
]
19+
20+
java_test(
21+
name = "compiler_artifact_test",
22+
srcs = ["CompilerArtifactTest.java"],
23+
test_class = "dev.cel.maven.CompilerArtifactTest",
24+
deps =
25+
MAVEN_COMPILER_JAR_DEPS + [
26+
"//:java_truth",
27+
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
28+
"@maven//:com_google_testparameterinjector_test_parameter_injector",
29+
"@maven//:junit_junit",
30+
],
31+
)
32+
33+
java_test(
34+
name = "runtime_artifact_test",
35+
srcs = ["RuntimeArtifactTest.java"],
36+
test_class = "dev.cel.maven.RuntimeArtifactTest",
37+
deps =
38+
MAVEN_RUNTIME_JAR_DEPS + [
39+
"//:java_truth",
40+
"@cel_spec//proto/cel/expr:checked_java_proto",
41+
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
42+
"@maven//:com_google_guava_guava",
43+
"@maven//:com_google_protobuf_protobuf_java",
44+
"@maven//:com_google_testparameterinjector_test_parameter_injector",
45+
"@maven//:junit_junit",
46+
],
47+
)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package dev.cel.maven;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
import static dev.cel.common.CelFunctionDecl.newFunctionDeclaration;
19+
import static dev.cel.common.CelOverloadDecl.newGlobalOverload;
20+
import static org.junit.Assert.assertThrows;
21+
22+
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
23+
import dev.cel.checker.CelChecker;
24+
import dev.cel.common.CelAbstractSyntaxTree;
25+
import dev.cel.common.CelContainer;
26+
import dev.cel.common.CelOptions;
27+
import dev.cel.common.CelValidationException;
28+
import dev.cel.common.CelValidationResult;
29+
import dev.cel.common.ast.CelConstant;
30+
import dev.cel.common.ast.CelExpr;
31+
import dev.cel.common.types.ProtoMessageTypeProvider;
32+
import dev.cel.common.types.SimpleType;
33+
import dev.cel.common.types.StructTypeReference;
34+
import dev.cel.compiler.CelCompiler;
35+
import dev.cel.compiler.CelCompilerFactory;
36+
import dev.cel.expr.conformance.proto3.TestAllTypes;
37+
import dev.cel.parser.CelParser;
38+
import dev.cel.parser.CelParserFactory;
39+
import dev.cel.parser.CelStandardMacro;
40+
import dev.cel.parser.CelUnparser;
41+
import dev.cel.parser.CelUnparserFactory;
42+
import org.junit.Test;
43+
import org.junit.runner.RunWith;
44+
45+
@RunWith(TestParameterInjector.class)
46+
public class CompilerArtifactTest {
47+
48+
@Test
49+
public void parse() throws Exception {
50+
CelParser parser = CelParserFactory.standardCelParserBuilder().build();
51+
CelUnparser unparser = CelUnparserFactory.newUnparser();
52+
53+
CelAbstractSyntaxTree ast = parser.parse("'Hello World'").getAst();
54+
55+
assertThat(ast.getExpr()).isEqualTo(CelExpr.ofConstant(1L, CelConstant.ofValue("Hello World")));
56+
assertThat(unparser.unparse(ast)).isEqualTo("\"Hello World\"");
57+
}
58+
59+
@Test
60+
public void typeCheck() throws Exception {
61+
CelParser parser = CelParserFactory.standardCelParserBuilder().build();
62+
CelChecker checker = CelCompilerFactory.standardCelCheckerBuilder().build();
63+
64+
CelAbstractSyntaxTree ast = checker.check(parser.parse("'Hello World'").getAst()).getAst();
65+
66+
assertThat(ast.getResultType()).isEqualTo(SimpleType.STRING);
67+
}
68+
69+
@Test
70+
public void compile() throws Exception {
71+
CelCompiler compiler =
72+
CelCompilerFactory.standardCelCompilerBuilder()
73+
.addFunctionDeclarations(
74+
newFunctionDeclaration(
75+
"getThree", newGlobalOverload("getThree_overload", SimpleType.INT)))
76+
.setOptions(CelOptions.DEFAULT)
77+
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
78+
.setTypeProvider(
79+
ProtoMessageTypeProvider.newBuilder()
80+
.addFileDescriptors(TestAllTypes.getDescriptor().getFile())
81+
.build())
82+
.setContainer(CelContainer.ofName("cel.expr.conformance.proto3"))
83+
.addVar("msg", StructTypeReference.create(TestAllTypes.getDescriptor().getFullName()))
84+
.build();
85+
CelUnparser unparser = CelUnparserFactory.newUnparser();
86+
87+
CelAbstractSyntaxTree ast =
88+
compiler.compile("msg == TestAllTypes{} && 3 == getThree()").getAst();
89+
90+
assertThat(unparser.unparse(ast))
91+
.isEqualTo("msg == cel.expr.conformance.proto3.TestAllTypes{} && 3 == getThree()");
92+
assertThat(ast.getResultType()).isEqualTo(SimpleType.BOOL);
93+
}
94+
95+
@Test
96+
public void compile_error() {
97+
CelCompiler compiler = CelCompilerFactory.standardCelCompilerBuilder().build();
98+
99+
CelValidationResult result = compiler.compile("'foo' + 1");
100+
101+
assertThat(result.hasError()).isTrue();
102+
assertThat(assertThrows(CelValidationException.class, result::getAst))
103+
.hasMessageThat()
104+
.contains("found no matching overload for '_+_' applied to '(string, int)'");
105+
}
106+
}

0 commit comments

Comments
 (0)