Repository navigation
fix: resolve container-qualified bindings for unchecked parsed eval #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
detail-app
wants to merge
6
commits into
main
Choose a base branch
from
detail/bug-fix/fix-resolve-container-qualified-bindings-for-unche-0835f6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
94b3a3b
fix: resolve container-qualified bindings for unchecked parsed eval
detail-app[bot] edc1165
fix: keep rootBinding on compiled path; mark new test NullMarked
detail-app[bot] 4f668ba
fix: drop redundant jspecify dep flagged by gazelle
detail-app[bot] 0a257a0
fix: revert @NullMarked on ContainerResolutionTest
detail-app[bot] 4f639e7
fix: keep container walk off compiled fast path when container is empty
detail-app[bot] d3955b4
test: cover no-match container-walk branches in rootBinding
detail-app[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/test/java/dev/trufflecel/ContainerResolutionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package dev.trufflecel; | ||
|
|
||
| import static dev.trufflecel.CanonicalAst.*; | ||
| import static org.junit.Assert.*; | ||
|
|
||
| import com.google.protobuf.*; | ||
| import java.util.*; | ||
| import org.junit.Test; | ||
|
|
||
| /** Runtime container-qualified binding resolution for unchecked/parsed evaluation. */ | ||
| public final class ContainerResolutionTest { | ||
| private static Program parsedProgram(String source, String container) { | ||
| Environment environment = Cel.newBuilder().container(container).inferVariables(true).build(); | ||
| Message parsed = CanonicalAst.parse(environment, source); | ||
| return CanonicalAst.program(environment, parsed); | ||
| } | ||
|
|
||
| @Test | ||
| public void containerQualifiedBindingWinsOverBareForParsedIdent() { | ||
| Program program = parsedProgram("y", "x"); | ||
| assertEquals(Boolean.TRUE, program.evaluateInternal(Map.of("x.y", true, "y", "false"))); | ||
| assertEquals(Boolean.TRUE, program.evaluate(Map.of("x.y", true, "y", "false"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void containerQualifiedBindingAloneResolvesForParsedIdent() { | ||
| Program program = parsedProgram("y", "x"); | ||
| assertEquals(Boolean.TRUE, program.evaluateInternal(Map.of("x.y", true))); | ||
| } | ||
|
|
||
| @Test | ||
| public void bareBindingStillResolvesWhenNoContainerQualifiedKeyExists() { | ||
| Program program = parsedProgram("y", "x"); | ||
| assertEquals("false", program.evaluateInternal(Map.of("y", "false"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void genuinelyMissingIdentifierStillErrorsAfterContainerWalk() { | ||
| Program program = parsedProgram("y", "x"); | ||
| assertEquals( | ||
| CelException.Code.UNDECLARED, | ||
| assertThrows(CelException.class, () -> program.evaluateInternal(Map.of("z", 1))).code()); | ||
| } | ||
|
|
||
| @Test | ||
| public void nestedContainerWalksInnermostFirst() { | ||
| Program program = parsedProgram("y", "a.b"); | ||
| assertEquals(1L, program.evaluateInternal(Map.of("a.b.y", 1L, "a.y", 2L, "y", 3L))); | ||
| assertEquals(2L, program.evaluateInternal(Map.of("a.y", 2L, "y", 3L))); | ||
| assertEquals(3L, program.evaluateInternal(Map.of("y", 3L))); | ||
| assertEquals(1L, program.evaluateInternal(Map.of("a.b.y", 1L, "y", 3L))); | ||
| } | ||
|
|
||
| @Test | ||
| public void multipleRootsEachResolveThroughContainer() { | ||
| Program program = parsedProgram("y + z", "x"); | ||
| assertEquals(3L, program.evaluateInternal(Map.of("x.y", 1L, "x.z", 2L, "y", 10L, "z", 20L))); | ||
| } | ||
|
|
||
| @Test | ||
| public void absoluteReferenceSkipsContainerWalk() { | ||
| Program program = parsedProgram(".y", "x"); | ||
| assertEquals(2L, program.evaluateInternal(Map.of("x.y", 1L, "y", 2L))); | ||
| } | ||
|
|
||
| @Test | ||
| public void checkedPathRemainsUnchangedByContainerResolution() { | ||
| Environment env = | ||
| Cel.newBuilder() | ||
| .container("x") | ||
| .variable("x.y", CelType.BOOL) | ||
| .variable("y", CelType.STRING) | ||
| .build(); | ||
| Message parsed = CanonicalAst.parse(env, "y"); | ||
| Message checked = CanonicalAst.check(env, parsed); | ||
| Program program = CanonicalAst.program(env, checked); | ||
| assertEquals(Boolean.TRUE, program.evaluateInternal(Map.of("x.y", true, "y", "false"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void emptyContainerFallsBackToBareNameOnly() { | ||
| Program program = parsedProgram("y", ""); | ||
| assertEquals("false", program.evaluateInternal(Map.of("y", "false"))); | ||
| assertEquals( | ||
| CelException.Code.UNDECLARED, | ||
| assertThrows(CelException.class, () -> program.evaluateInternal(Map.of("x.y", true))) | ||
| .code()); | ||
| } | ||
|
|
||
| @Test | ||
| public void singleEntryActivationResolvesContainerQualifiedKey() { | ||
| Program program = parsedProgram("y", "x"); | ||
| assertEquals(Boolean.TRUE, program.evaluate(Activation.snapshot(Map.of("x.y", true)))); | ||
| assertEquals("false", program.evaluate(Activation.snapshot(Map.of("y", "false")))); | ||
| } | ||
|
|
||
| @Test | ||
| public void singleEntryActivationMissingIdentifierErrorsAfterContainerWalk() { | ||
| Program program = parsedProgram("y", "x"); | ||
| // Object[] fast path: a single String binding that matches neither the container-qualified | ||
| // name nor the bare name must fall through to UNDECLARED after the container walk. | ||
| assertEquals( | ||
| CelException.Code.UNDECLARED, | ||
| assertThrows( | ||
| CelException.class, () -> program.evaluate(Activation.snapshot(Map.of("z", 1)))) | ||
| .code()); | ||
| // Scoped single-name path (options-driven evaluation): same container walk, no match. | ||
| assertEquals( | ||
| CelException.Code.UNDECLARED, | ||
| assertThrows( | ||
| CelException.class, | ||
| () -> | ||
| program.evaluate( | ||
| Activation.snapshot(Map.of("z", 1)), | ||
| EvaluationOptions.newBuilder().build())) | ||
| .code()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in edc1165: dropped the added @TruffleBoundary from rootBinding so the compiled root-resolution fast path matches the pre-PR allocation profile (restores the benchmarks:compiled budget); the new container-walk helpers stay @TruffleBoundary. Also added NullMarked to ContainerResolutionTest (+ @maven//:org_jspecify_jspecify dep) to satisfy RequireExplicitNullMarking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up in 0a257a0: reverted the NullMarked addition. It can't land cleanly here — strict deps requires a direct @maven//:org_jspecify_jspecify dep, but Gazelle auto-removes that dep as transitively-satisfied, so the two checks conflict. The RequireExplicitNullMarking finding is WARN-level (code-scanning), not a CI failure (trufflecheck passed without the annotation), so a human can decide later whether to adopt NullMarked package-wide.