From 7cc5edab1d2091e3e98bece842eea174a4fe84ca Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Wed, 25 Nov 2026 16:27:03 -0800 Subject: [PATCH] Add type signature conformance tests for type Adds environment conformance tests for type-of-type signatures (`type` and bare `type` alias normalizing to `type`) in `type_signatures.textproto`, covering primitive, `dyn`, nested collection, wrapper alias, and message parameters, deduced type and evaluation checks, and error cases for empty or excess type parameters. PiperOrigin-RevId: 1030261520 --- common/signature.cc | 8 +++++++- common/signature_test.cc | 22 ++++++++++++++++++++++ env/env_yaml.cc | 2 ++ env/type_info.cc | 2 ++ env/type_info_test.cc | 12 ++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/common/signature.cc b/common/signature.cc index 3f4ea8d29..7d89129d0 100644 --- a/common/signature.cc +++ b/common/signature.cc @@ -283,7 +283,9 @@ std::string StripUnescapedWhitespace(std::string_view str) { } absl::optional ParseBuiltinOrWrapper(std::string_view name_str) { - if (name_str == "null") return TypeSpec(NullTypeSpec()); + if (name_str == "null" || name_str == "null_type" || + name_str == "google.protobuf.NullValue") + return TypeSpec(NullTypeSpec()); if (name_str == "bool") return TypeSpec(PrimitiveType::kBool); if (name_str == "int") return TypeSpec(PrimitiveType::kInt64); if (name_str == "uint") return TypeSpec(PrimitiveType::kUint64); @@ -490,6 +492,10 @@ absl::StatusOr ParseTypeSignature(std::string_view signature) { name_str = Unescape(signature.substr(0, less_idx)); std::string_view params_str = signature.substr(less_idx + 1, signature.size() - less_idx - 2); + if (params_str.empty()) { + return absl::InvalidArgumentError( + "Invalid type signature: empty type parameter list"); + } CEL_ASSIGN_OR_RETURN(auto param_list, SplitTypeList(params_str)); for (std::string_view param_str : param_list) { CEL_ASSIGN_OR_RETURN(auto param, ParseTypeSignature(param_str)); diff --git a/common/signature_test.cc b/common/signature_test.cc index e157d5be0..9f0d45ba5 100644 --- a/common/signature_test.cc +++ b/common/signature_test.cc @@ -528,6 +528,15 @@ TEST(ParseSignatureTest, ProtoParsing) { *GetTestingDescriptorPool())); EXPECT_TRUE(gp_any.IsAny()); + ASSERT_OK_AND_ASSIGN(auto null_alias, ParseType("null_type", GetTestArena(), + *GetTestingDescriptorPool())); + EXPECT_TRUE(null_alias.IsNull()); + + ASSERT_OK_AND_ASSIGN(auto gp_null_value, + ParseType("google.protobuf.NullValue", GetTestArena(), + *GetTestingDescriptorPool())); + EXPECT_TRUE(gp_null_value.IsNull()); + ASSERT_OK_AND_ASSIGN(auto gp_timestamp, ParseType("google.protobuf.Timestamp", GetTestArena(), *GetTestingDescriptorPool())); @@ -764,6 +773,19 @@ TEST(ParseSignatureTest, EmptyOrWhitespaceErrors) { *GetTestingDescriptorPool()), StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("Empty type signature"))); + EXPECT_THAT(ParseType("list<>", GetTestArena(), *GetTestingDescriptorPool()), + StatusIs(absl::StatusCode::kInvalidArgument, + HasSubstr("empty type parameter list"))); + EXPECT_THAT(ParseType("map<>", GetTestArena(), *GetTestingDescriptorPool()), + StatusIs(absl::StatusCode::kInvalidArgument, + HasSubstr("empty type parameter list"))); + EXPECT_THAT(ParseType("map< >", GetTestArena(), *GetTestingDescriptorPool()), + StatusIs(absl::StatusCode::kInvalidArgument, + HasSubstr("empty type parameter list"))); + EXPECT_THAT( + ParseType("list>", GetTestArena(), *GetTestingDescriptorPool()), + StatusIs(absl::StatusCode::kInvalidArgument, + HasSubstr("empty type parameter list"))); } TEST(OverloadSignatureTest, ArgumentTypeVector) { diff --git a/env/env_yaml.cc b/env/env_yaml.cc index b214fe2f7..af5b3e55b 100644 --- a/env/env_yaml.cc +++ b/env/env_yaml.cc @@ -649,6 +649,8 @@ ConstantKindCase GetConstantKindCase(absl::string_view type_name) { static const auto kTypeNameToConstantKindCase = absl::NoDestructor>({ {"null", ConstantKindCase::kNull}, + {"null_type", ConstantKindCase::kNull}, + {"google.protobuf.NullValue", ConstantKindCase::kNull}, {"bool", ConstantKindCase::kBool}, {"int", ConstantKindCase::kInt}, {"uint", ConstantKindCase::kUint}, diff --git a/env/type_info.cc b/env/type_info.cc index f49fab9f4..c1ac65cb2 100644 --- a/env/type_info.cc +++ b/env/type_info.cc @@ -47,6 +47,8 @@ std::optional TypeNameToTypeKind(absl::string_view type_name) { absl::flat_hash_map> kTypeNameToTypeKind({ {"null", TypeKind::kNull}, + {NullType::kName, TypeKind::kNull}, + {"google.protobuf.NullValue", TypeKind::kNull}, {"bool", TypeKind::kBool}, {"int", TypeKind::kInt}, {"uint", TypeKind::kUint}, diff --git a/env/type_info_test.cc b/env/type_info_test.cc index f9d46f9a9..2f25ff6ca 100644 --- a/env/type_info_test.cc +++ b/env/type_info_test.cc @@ -84,6 +84,18 @@ TEST_P(TypeInfoTest, TypeInfo) { std::vector GetTestCases() { return { + TestCase{ + .type_info = {.name = "null"}, + .expected_type_pb = "null: NULL_VALUE", + }, + TestCase{ + .type_info = {.name = "null_type"}, + .expected_type_pb = "null: NULL_VALUE", + }, + TestCase{ + .type_info = {.name = "google.protobuf.NullValue"}, + .expected_type_pb = "null: NULL_VALUE", + }, TestCase{ .type_info = {.name = "int"}, .expected_type_pb = "primitive: INT64",