From 76008e98deb5a189d0b53576ceda1106b8e75ddd Mon Sep 17 00:00:00 2001 From: "detail-app[bot]" <180357370+detail-app[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:42:28 +0000 Subject: [PATCH 1/3] fix: surface Unknown for deep partial-eval patterns with missing ancestors --- src/main/java/dev/trufflecel/EvalContext.java | 10 + src/main/java/dev/trufflecel/ExprNode.java | 60 +++++- .../java/dev/trufflecel/PartialState.java | 32 +++ src/test/java/dev/trufflecel/BUILD.bazel | 11 + .../dev/trufflecel/DeepPatternReproTest.java | 191 ++++++++++++++++++ 5 files changed, 297 insertions(+), 7 deletions(-) create mode 100644 src/test/java/dev/trufflecel/DeepPatternReproTest.java diff --git a/src/main/java/dev/trufflecel/EvalContext.java b/src/main/java/dev/trufflecel/EvalContext.java index 1f82032e..1c463edf 100644 --- a/src/main/java/dev/trufflecel/EvalContext.java +++ b/src/main/java/dev/trufflecel/EvalContext.java @@ -178,6 +178,16 @@ Object attributeRead(Attribute path, boolean presence) { : evaluation.partial.override(path, presence); } + /** + * Overlap-based unknown fallback for SELECT/INDEX hops; see {@link + * PartialState#unknownIntersect}. + */ + Object attributeIntersect(Attribute path) { + return evaluation == null || evaluation.partial == null + ? PartialState.NONE + : evaluation.partial.unknownIntersect(path); + } + @com.oracle.truffle.api.CompilerDirectives.TruffleBoundary static Attribute qualify(Attribute parent, Object qualifier) { if (parent == null) return null; diff --git a/src/main/java/dev/trufflecel/ExprNode.java b/src/main/java/dev/trufflecel/ExprNode.java index ac208fbc..a3578224 100644 --- a/src/main/java/dev/trufflecel/ExprNode.java +++ b/src/main/java/dev/trufflecel/ExprNode.java @@ -690,7 +690,18 @@ Object doExecute(VirtualFrame frame, EvalContext ctx) { && (Boolean.TRUE.equals(value) || a instanceof OptionalValue) ? OptionalValue.of(override) : override; - if (a == PartialState.MISSING) throw missingAttribute(parent); + if (a == PartialState.MISSING) { + // Mirror the SELECT hop: a deep unknown pattern intersecting this read path produces an + // Unknown instead of a hard UNDECLARED error so resolve-and-retry can make progress. + Object intersect = ctx.attributeIntersect(path); + if (intersect != PartialState.NONE) + yield !(intersect instanceof Unknown) + && (Boolean.TRUE.equals(value) || a instanceof OptionalValue) + ? OptionalValue.of(intersect) + : intersect; + if (b instanceof Unknown u) yield u; + throw missingAttribute(parent); + } if (a instanceof Unknown u) yield b instanceof Unknown v ? u.merge(v) : u; if (b instanceof Unknown u) yield u; if (error != null) throw error; @@ -706,6 +717,15 @@ Object doExecute(VirtualFrame frame, EvalContext ctx) { if (optional && (e.code() == CelException.Code.NO_SUCH_KEY || e.code() == CelException.Code.INDEX)) yield OptionalValue.none(); + if (!optional + && (e.code() == CelException.Code.NO_SUCH_KEY + || e.code() == CelException.Code.INDEX)) { + // Container present but the key/index is missing: a deep unknown pattern intersecting + // this read path turns the hard error into an Unknown for resolve-and-retry; a + // resolution that supplies (or has supplied) an ancestor still raises the error. + Object intersect = ctx.attributeIntersect(path); + if (intersect != PartialState.NONE) yield intersect; + } throw e; } } @@ -749,7 +769,8 @@ Object executePresence(VirtualFrame frame, EvalContext ctx) { private Object select(VirtualFrame frame, EvalContext ctx, boolean presence) { Object operand = children[0].execute(frame, ctx); Attribute parent = ctx.attribute(); - Object override = ctx.attributeRead(ctx.qualify(parent, name), presence); + Attribute path = ctx.qualify(parent, name); + Object override = ctx.attributeRead(path, presence); if (presence) ctx.attribute(null); if (override != PartialState.NONE) return !presence @@ -757,10 +778,24 @@ private Object select(VirtualFrame frame, EvalContext ctx, boolean presence) { && (Boolean.TRUE.equals(value) || operand instanceof OptionalValue) ? OptionalValue.of(override) : override; - if (operand == PartialState.MISSING) throw missingAttribute(parent); + if (operand == PartialState.MISSING) { + // A deep unknown pattern (deeper than this hop) was invisible to `override` because + // AttributePattern.matches is one-directional; fall back to overlap semantics so that a + // missing receiver at this hop yields an Unknown instead of a hard UNDECLARED error, + // mirroring cel-go / cel-java. A resolution that has supplied an ancestor is left to + // surface the existing error. + Object intersect = ctx.attributeIntersect(path); + if (intersect != PartialState.NONE) + return !presence + && !(intersect instanceof Unknown) + && (Boolean.TRUE.equals(value) || operand instanceof OptionalValue) + ? OptionalValue.of(intersect) + : intersect; + throw missingAttribute(parent); + } if (fieldRead != null && fieldRead.accepts(operand)) return presence ? fieldRead.has(operand) : fieldRead.read(operand); - return selectValue(ctx, presence, operand); + return selectValue(ctx, presence, operand, path); } @com.oracle.truffle.api.CompilerDirectives.TruffleBoundary @@ -769,7 +804,7 @@ private static CelException missingAttribute(Attribute attribute) { } @com.oracle.truffle.api.CompilerDirectives.TruffleBoundary - private Object selectValue(EvalContext ctx, boolean presence, Object operand) { + private Object selectValue(EvalContext ctx, boolean presence, Object operand, Attribute path) { if (operand instanceof Unknown) return operand; if (extensionSelect) { for (ObjectType type : ctx.environment.runtimeObjectTypes) @@ -790,13 +825,24 @@ private Object selectValue(EvalContext ctx, boolean presence, Object operand) { boolean present = map.containsKey(name); if (presence) return present; if (lifted) return present ? OptionalValue.of(map.get(name)) : OptionalValue.none(); - if (!present) throw Values.error(CelException.Code.NO_SUCH_KEY, "no such key: " + name); + if (!present) { + // The container is present but the key is missing: a deep unknown pattern intersecting + // this read path means the missing key is part of the unknown attribute subtree, so + // surface an Unknown for resolve-and-retry instead of a hard NO_SUCH_KEY; a resolution + // that supplies (or has supplied) an ancestor steers the existing error path. + Object intersect = ctx.attributeIntersect(path); + if (intersect != PartialState.NONE) return intersect; + throw Values.error(CelException.Code.NO_SUCH_KEY, "no such key: " + name); + } return map.get(name); } for (ObjectType type : ctx.environment.runtimeObjectTypes) if (type.accepts(operand)) { - if (!type.fields().containsKey(name)) + if (!type.fields().containsKey(name)) { + Object intersect = ctx.attributeIntersect(path); + if (intersect != PartialState.NONE) return intersect; throw Values.error(CelException.Code.NO_SUCH_FIELD, "no such field: " + name); + } if (presence) return type.has(operand, name); if (lifted) return type.has(operand, name) diff --git a/src/main/java/dev/trufflecel/PartialState.java b/src/main/java/dev/trufflecel/PartialState.java index 950379d6..7fb0cc7e 100644 --- a/src/main/java/dev/trufflecel/PartialState.java +++ b/src/main/java/dev/trufflecel/PartialState.java @@ -42,6 +42,38 @@ Object override(Attribute path, boolean presence) { return unknown == null ? NONE : unknown; } + /** + * Overlap-based fallback used at SELECT/INDEX hops when {@link #override} did not match a + * shallower-or-equal pattern. Returns an {@link Unknown} rooted at the longest common prefix of + * the hop path and each intersecting pattern (i.e. at the hop path when the pattern is deeper, + * and at the pattern granularity when the pattern is shallower-or-equal, mirroring {@code + * override}), so that deep unknown patterns with missing ancestors surface an {@code Unknown} for + * the documented resolve-and-retry loop instead of a hard {@code UNDECLARED} / {@code + * NO_SUCH_KEY} / {@code NO_SUCH_FIELD} error. A resolution that supplies (or has supplied) the + * receiver is left to steer the normal selector read; the caller falls back to its existing error + * path. This matches the bidirectional overlap semantics already used by {@link #consume} and + * {@link #containsUnknown}, and mirrors cel-go / cel-java where the pattern check runs against + * the resolved attribute path before the activation is consulted. + */ + @TruffleBoundary + Object unknownIntersect(Attribute path) { + if (path == null) return NONE; + // A resolution that is an ancestor of (or equal to) the path has already supplied the + // receiver to its selector; surface NO_SUCH_KEY / NO_SUCH_FIELD rather than masking the + // missing descendant with an Unknown. + for (Attribute candidate : activation.resolutions.keySet()) + if (candidate.prefixOf(path)) return NONE; + Unknown unknown = null; + for (AttributePattern pattern : activation.patterns) + if (pattern.intersects(path)) { + int common = Math.min(pattern.qualifiers().size(), path.qualifiers().size()); + var root = new Attribute(path.variable(), path.qualifiers().subList(0, common)); + Unknown next = Unknown.of(root.toString()); + unknown = unknown == null ? next : unknown.merge(next); + } + return unknown == null ? NONE : unknown; + } + @TruffleBoundary Object consume(Object value) { Attribute path = attribute; diff --git a/src/test/java/dev/trufflecel/BUILD.bazel b/src/test/java/dev/trufflecel/BUILD.bazel index 464e4d09..260b637d 100644 --- a/src/test/java/dev/trufflecel/BUILD.bazel +++ b/src/test/java/dev/trufflecel/BUILD.bazel @@ -685,3 +685,14 @@ java_test( "@maven//:junit_junit", ], ) + +java_test( + name = "deepPatternRepro", + srcs = ["DeepPatternReproTest.java"], + test_class = "dev.trufflecel.DeepPatternReproTest", + deps = [ + ":test_support", + "//:trufflecel", + "@maven//:junit_junit", + ], +) diff --git a/src/test/java/dev/trufflecel/DeepPatternReproTest.java b/src/test/java/dev/trufflecel/DeepPatternReproTest.java new file mode 100644 index 00000000..7ea2ac4e --- /dev/null +++ b/src/test/java/dev/trufflecel/DeepPatternReproTest.java @@ -0,0 +1,191 @@ +package dev.trufflecel; + +import static org.junit.Assert.*; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.junit.Test; + +/** + * Regression test for the deep unknown-pattern dead-end in field-level partial evaluation. + * + *
When a declared unknown {@link AttributePattern} is deeper than the receiver chain evaluated + * at some attribute hop, {@code PartialState.override()} previously only consulted patterns where + * {@link AttributePattern#matches} returned true (pattern shallower-or-equal to the hop), so a + * {@code PartialState#MISSING} receiver fell through to a hard {@code UNDECLARED} / {@code + * NO_SUCH_KEY} / {@code NO_SUCH_FIELD} error instead of an {@link Unknown}. That dead-ended the + * documented resolve-and-retry loop: {@link PartialResult#isComplete()} was {@code false} while + * {@link PartialResult#unknownAttributes()} returned an empty set, and the caller had no attribute + * to resolve. + * + *
The fix adds an overlap-based fallback at the SELECT and INDEX hops (mirroring {@code + * PartialState.consume} / {@code PartialState.containsUnknown}) so any pattern that intersects the + * hop path returns an {@link Unknown} rooted at the longest common prefix, matching cel-go / + * cel-java, where the pattern check runs against the resolved attribute path before the activation + * is consulted. + */ +public class DeepPatternReproTest { + + private static final AttributePattern SECRET_DEEP = + AttributePattern.of("data").qualify("secret").qualify("deep"); + + /** + * A deep unknown pattern with no bindings yields an {@link Unknown} on every read shape that + * intersects the pattern, instead of a hard {@code UNDECLARED} error. + */ + @Test + public void deepPatternWithMissingAncestorsYieldsUnknownInsteadOfUndeclared() { + var activation = PartialActivation.of(Map.of(), SECRET_DEEP); + for (String expr : + List.of("data.secret", "data['secret']", "data.secret.deep", "has(data.secret)")) { + var partial = Cel.compile(expr).partialEvaluate(activation); + assertNull(expr + " should not produce a hard error", partial.error()); + assertTrue(expr + " should yield an Unknown", partial.value() instanceof Unknown); + assertFalse(expr + " should be incomplete", partial.isComplete()); + assertFalse( + expr + " should report resolvable unknown attributes", + partial.unknownAttributes().isEmpty()); + } + } + + /** A deep pattern with a present container with a missing intermediate key still Unknowns. */ + @Test + public void deepPatternWithPresentContainerMissingKeyYieldsUnknownInsteadOfNoSuchKey() { + var activation = PartialActivation.of(Map.of("data", Map.of("other", 1L)), SECRET_DEEP); + for (String expr : List.of("data.secret", "data['secret']", "data.secret.deep")) { + var partial = Cel.compile(expr).partialEvaluate(activation); + assertNull(expr + " should not produce a hard error", partial.error()); + assertTrue(expr + " should yield an Unknown", partial.value() instanceof Unknown); + assertFalse( + expr + " should report resolvable unknown attributes", + partial.unknownAttributes().isEmpty()); + } + } + + /** Resolving the exact patterned leaf and retrying completes the evaluation. */ + @Test + public void resolvingExactLeafAfterDeepPatternCompletes() { + var activation = PartialActivation.of(Map.of(), SECRET_DEEP); + var partial = Cel.compile("data.secret.deep").partialEvaluate(activation); + assertTrue(partial.value() instanceof Unknown); + var advanced = + partial.advanceEvaluation( + Map.of(Attribute.of("data").qualify("secret").qualify("deep"), 4L)); + assertTrue("after resolving the deep leaf, evaluation should complete", advanced.isComplete()); + assertEquals(4L, advanced.value()); + assertEquals(Set.of(), advanced.unknownAttributes()); + } + + /** Resolving an ancestor of the deep pattern also completes the evaluation. */ + @Test + public void resolvingAncestorAfterDeepPatternCompletes() { + var activation = PartialActivation.of(Map.of(), SECRET_DEEP); + var partial = Cel.compile("data.secret.deep").partialEvaluate(activation); + assertTrue(partial.value() instanceof Unknown); + var advanced = + partial.advanceEvaluation( + Map.of(Attribute.of("data"), Map.of("secret", Map.of("deep", 7L)))); + assertTrue("after resolving an ancestor, evaluation should complete", advanced.isComplete()); + assertEquals(7L, advanced.value()); + } + + /** Wildcard-deep patterns behave the same as concrete-deep patterns. */ + @Test + public void wildcardDeepPatternYieldsUnknownInsteadOfUndeclared() { + var activation = + PartialActivation.of(Map.of(), AttributePattern.of("data").wildcard().wildcard()); + var partial = Cel.compile("data.secret.deep").partialEvaluate(activation); + assertNull("wildcard-deep pattern should not produce a hard error", partial.error()); + assertTrue(partial.value() instanceof Unknown); + assertFalse(partial.isComplete()); + assertFalse(partial.unknownAttributes().isEmpty()); + } + + /** Reverse-depth reads still produce an Unknown rooted at the pattern (existing behavior). */ + @Test + public void shallowPatternWithDeeperReadStillUnknownsAtPatternGranularity() { + var activation = PartialActivation.of(Map.of(), AttributePattern.of("data").qualify("secret")); + assertEquals( + Unknown.of("data.secret"), + Cel.compile("data.secret.deep").partialEvaluate(activation).value()); + } + + /** A non-intersecting sibling still raises the existing hard {@code UNDECLARED} error. */ + @Test + public void nonIntersectingSiblingStillRaisesUndeclared() { + var activation = PartialActivation.of(Map.of(), SECRET_DEEP); + var partial = Cel.compile("data.known").partialEvaluate(activation); + assertNotNull("non-intersecting sibling should still raise UNDECLARED", partial.error()); + assertEquals(CelException.Code.UNDECLARED, partial.error().code()); + assertEquals(Set.of(), partial.unknownAttributes()); + } + + /** + * A resolved ancestor that supplies (or has supplied) the receiver still surfaces the existing + * {@code NO_SUCH_KEY} error for non-intersecting descendants. + */ + @Test + public void resolvedAncestorStillRaisesNoSuchKeyForMissing() { + var activation = + PartialActivation.of(Map.of(), AttributePattern.of("data").qualify("secret")) + .resolve(Map.of(Attribute.of("data"), Map.of())); + var partial = Cel.compile("data.secret").partialEvaluate(activation); + assertNotNull( + "resolved ancestor with missing key should still raise NO_SUCH_KEY", partial.error()); + assertEquals(CelException.Code.NO_SUCH_KEY, partial.error().code()); + assertEquals(Set.of(), partial.unknownAttributes()); + } + + /** + * A deep unknown pattern inside a comprehension produces a merged {@link Unknown} across + * iterations instead of a hard {@code NO_SUCH_KEY} inside the loop body. + */ + @Test + public void deepPatternInComprehensionMergesUnknownsAcrossIterations() { + var activation = + PartialActivation.of( + Map.of("rows", List.of(Map.of("known", 1L), Map.of("known", 2L))), + AttributePattern.of("rows").wildcard().qualify("leaf").qualify("deep")); + var partial = Cel.compile("rows.map(r, r.leaf.deep)").partialEvaluate(activation); + assertNull("comprehension with deep pattern should not raise a hard error", partial.error()); + assertTrue(partial.value() instanceof Unknown); + var unknowns = partial.unknownAttributes(); + assertEquals(Set.of("rows[0].leaf.deep", "rows[1].leaf.deep"), unknowns); + assertFalse(partial.isComplete()); + var advanced = + partial.advanceEvaluation( + Map.of( + Attribute.of("rows").qualify(0).qualify("leaf").qualify("deep"), 11L, + Attribute.of("rows").qualify(1).qualify("leaf").qualify("deep"), 22L)); + assertTrue(advanced.isComplete()); + assertEquals(List.of(11L, 22L), advanced.value()); + } + + /** A deep unknown pattern via INDEX also yields an {@link Unknown} instead of a hard error. */ + @Test + public void deepPatternViaIndexYieldsUnknownInsteadOfNoSuchKey() { + var activation = PartialActivation.of(Map.of(), SECRET_DEEP); + var partial = Cel.compile("data['secret']['deep']").partialEvaluate(activation); + assertNull("INDEX path with deep pattern should not raise a hard error", partial.error()); + assertTrue(partial.value() instanceof Unknown); + assertFalse(partial.unknownAttributes().isEmpty()); + assertFalse(partial.isComplete()); + } + + /** + * The optional null-coalescing path is unchanged when an ancestor resolution supplies the + * receiver: a missing optional key still yields {@link OptionalValue#none()} rather than an + * {@link Unknown}. The deep-pattern fallback consults the resolved-ancestor check first and + * declines to surface an Unknown. + */ + @Test + public void optionalAccessPreservesNullCoalescingForResolvedAncestor() { + var activation = + PartialActivation.of(Map.of(), SECRET_DEEP).resolve(Map.of(Attribute.of("data"), Map.of())); + var partial = Cel.compile("data[?'secret']").partialEvaluate(activation); + assertNull(partial.error()); + assertEquals(OptionalValue.none(), partial.value()); + assertTrue(partial.isComplete()); + assertEquals(Set.of(), partial.unknownAttributes()); + } +} From dfdbd5fcd561ff4626ed0cd56f1b4b86fabbcc9a Mon Sep 17 00:00:00 2001 From: "detail-app[bot]" <180357370+detail-app[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:36:37 +0000 Subject: [PATCH 2/3] fix: drop dead optional-lift branches and cover remaining intersect paths attributeIntersect/unknownIntersect only ever returns NONE or an Unknown, so the optional-lifting ternaries added to the SELECT/INDEX missing-receiver blocks were unreachable. Removing them restores the 99.8% coverage floor (the dead branches were never exercised) and shrinks the inlined Graal graph for SELECT/INDEX nodes, bringing the representative smoke benchmark back under the 10000-node compilation limit. Add regression tests for the two remaining intersect paths: a missing receiver with an unknown index key, and a deep pattern on a runtime object's missing field reached via dyn(). --- src/main/java/dev/trufflecel/ExprNode.java | 18 +++----- .../dev/trufflecel/DeepPatternReproTest.java | 43 +++++++++++++++++++ 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/main/java/dev/trufflecel/ExprNode.java b/src/main/java/dev/trufflecel/ExprNode.java index a3578224..84a7c06d 100644 --- a/src/main/java/dev/trufflecel/ExprNode.java +++ b/src/main/java/dev/trufflecel/ExprNode.java @@ -693,12 +693,10 @@ Object doExecute(VirtualFrame frame, EvalContext ctx) { if (a == PartialState.MISSING) { // Mirror the SELECT hop: a deep unknown pattern intersecting this read path produces an // Unknown instead of a hard UNDECLARED error so resolve-and-retry can make progress. + // `attributeIntersect` only ever returns NONE or an Unknown, so the optional-lifting form + // used for `override` above is not needed here. Object intersect = ctx.attributeIntersect(path); - if (intersect != PartialState.NONE) - yield !(intersect instanceof Unknown) - && (Boolean.TRUE.equals(value) || a instanceof OptionalValue) - ? OptionalValue.of(intersect) - : intersect; + if (intersect != PartialState.NONE) yield intersect; if (b instanceof Unknown u) yield u; throw missingAttribute(parent); } @@ -783,14 +781,10 @@ private Object select(VirtualFrame frame, EvalContext ctx, boolean presence) { // AttributePattern.matches is one-directional; fall back to overlap semantics so that a // missing receiver at this hop yields an Unknown instead of a hard UNDECLARED error, // mirroring cel-go / cel-java. A resolution that has supplied an ancestor is left to - // surface the existing error. + // surface the existing error. `attributeIntersect` only ever returns NONE or an Unknown, + // so the optional-lifting form used for `override` above is not needed here. Object intersect = ctx.attributeIntersect(path); - if (intersect != PartialState.NONE) - return !presence - && !(intersect instanceof Unknown) - && (Boolean.TRUE.equals(value) || operand instanceof OptionalValue) - ? OptionalValue.of(intersect) - : intersect; + if (intersect != PartialState.NONE) return intersect; throw missingAttribute(parent); } if (fieldRead != null && fieldRead.accepts(operand)) diff --git a/src/test/java/dev/trufflecel/DeepPatternReproTest.java b/src/test/java/dev/trufflecel/DeepPatternReproTest.java index 7ea2ac4e..23eb23fa 100644 --- a/src/test/java/dev/trufflecel/DeepPatternReproTest.java +++ b/src/test/java/dev/trufflecel/DeepPatternReproTest.java @@ -188,4 +188,47 @@ public void optionalAccessPreservesNullCoalescingForResolvedAncestor() { assertTrue(partial.isComplete()); assertEquals(Set.of(), partial.unknownAttributes()); } + + /** + * When the receiver is missing (undeclared) and the index key is itself an {@link Unknown}, the + * unknown key propagates instead of a hard {@code UNDECLARED} error, so resolve-and-retry can + * supply the key's attribute. No pattern intersects the read path (the key is the unknown), so + * the overlap fallback declines and the {@code b instanceof Unknown} arm fires. + */ + @Test + public void missingReceiverWithUnknownIndexKeyYieldsUnknownKey() { + var activation = + PartialActivation.of( + Map.of(), AttributePattern.of("data").qualify("secret"), AttributePattern.of("k")); + var partial = Cel.compile("data[k]").partialEvaluate(activation); + assertNull("missing receiver with unknown key should not raise a hard error", partial.error()); + assertTrue(partial.value() instanceof Unknown); + assertFalse(partial.isComplete()); + } + + /** + * A deep unknown pattern intersecting a missing field on a runtime {@link ObjectType} surfaces an + * {@link Unknown} instead of a hard {@code NO_SUCH_FIELD}; the field is reached via {@code dyn} + * so the static type checker does not reject it. + */ + @Test + public void deepPatternOnRuntimeObjectMissingFieldYieldsUnknownInsteadOfNoSuchField() { + var schema = + new ProtoSchema( + Map.of( + "Msg", Map.of("count", new ProtoSchema.Field(1, 5, "", false, false, false, 0L)))); + var builder = Cel.newBuilder(); + schema.register(builder); + var env = builder.variable("m", CelType.of("Msg")).build(); + var activation = + PartialActivation.of( + Map.of("m", schema.construct("Msg", Map.of("count", 1L))), + AttributePattern.of("m").qualify("missing").qualify("deep")); + var partial = env.compile("dyn(m).missing").partialEvaluate(activation); + assertNull( + "missing field on runtime object with deep pattern should not raise a hard error", + partial.error()); + assertTrue(partial.value() instanceof Unknown); + assertFalse(partial.isComplete()); + } } From f7300ad535d70ddc52b769805d71c26783ff2fd5 Mon Sep 17 00:00:00 2001 From: "detail-app[bot]" <180357370+detail-app[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:16:45 +0000 Subject: [PATCH 3/3] test: cover remaining intersect branches for 99.8% coverage floor Add two regression tests for paths the PR introduced but CI's coverage gate flagged as uncovered: multiple deeper-than-the-hop patterns intersecting the same SELECT path (exercises the multi-pattern merge in PartialState.unknownIntersect), and a non-partial read of a missing map key via the options-bearing evaluate entry (exercises the evaluation.partial == null arm of EvalContext.attributeIntersect, which confirms the new error-path call is a no-op outside partial evaluation). --- .../dev/trufflecel/DeepPatternReproTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/test/java/dev/trufflecel/DeepPatternReproTest.java b/src/test/java/dev/trufflecel/DeepPatternReproTest.java index 23eb23fa..665b9de9 100644 --- a/src/test/java/dev/trufflecel/DeepPatternReproTest.java +++ b/src/test/java/dev/trufflecel/DeepPatternReproTest.java @@ -231,4 +231,43 @@ public void deepPatternOnRuntimeObjectMissingFieldYieldsUnknownInsteadOfNoSuchFi assertTrue(partial.value() instanceof Unknown); assertFalse(partial.isComplete()); } + + /** + * Two deeper-than-the-hop patterns intersecting the same SELECT path merge their {@link Unknown} + * roots via {@link PartialState#unknownIntersect}, exercising the multi-pattern merge arm. + */ + @Test + public void multipleDeepPatternsIntersectingSameHopMergeUnknowns() { + var activation = + PartialActivation.of( + Map.of(), + AttributePattern.of("data").qualify("secret").qualify("deep"), + AttributePattern.of("data").qualify("secret").qualify("deeper")); + var partial = Cel.compile("data.secret").partialEvaluate(activation); + assertNull("merged deep patterns should not produce a hard error", partial.error()); + assertTrue(partial.value() instanceof Unknown); + assertFalse(partial.isComplete()); + assertFalse(partial.unknownAttributes().isEmpty()); + } + + /** + * The intersect fallback is a no-op outside partial evaluation: a non-partial read of a missing + * map key still raises {@code NO_SUCH_KEY}. This exercises the {@code evaluation.partial == null} + * arm of {@link EvalContext#attributeIntersect} so the PR's new error-path call is covered. The + * {@code evaluate(Map, EvaluationOptions)} entry is used (not the bare {@code evaluate(Map)}) + * because only the options-bearing path configures an {@link EvaluationState} with a non-null + * {@code evaluation} and a null {@code partial}. + */ + @Test + public void nonPartialMissingKeyStillThrowsNoSuchKey() { + var env = Cel.newBuilder().variable("m", CelType.map(CelType.STRING, CelType.INT)).build(); + var thrown = + assertThrows( + CelException.class, + () -> + env.compile("m.missing") + .evaluate( + Map.of("m", Map.of("other", 1L)), EvaluationOptions.newBuilder().build())); + assertEquals(CelException.Code.NO_SUCH_KEY, thrown.code()); + } }