Ruby: Address testFailures in inline expectations tests (part 2)#22081
Open
geoffw0 wants to merge 6 commits into
Open
Ruby: Address testFailures in inline expectations tests (part 2)#22081geoffw0 wants to merge 6 commits into
geoffw0 wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes remaining failures in Ruby inline-expectations-based tests by (1) updating test annotations to match intended outcomes and (2) extending the Ruby inline expectations implementation so expectation markers can be written in .erb template comments.
Changes:
- Mark the
improper_memoization.rbm14result as a known false positive (SPURIOUS) to eliminate an “Unexpected result” test failure. - Add support for parsing inline expectation markers from ERB comments (
<%# ... %>) in the Ruby inline expectations test implementation. - Update the Sinatra ERB view test to annotate the expected taint flow on the relevant line, clearing the
.expectedfiletestFailuressection.
Show a summary per file
| File | Description |
|---|---|
| ruby/ql/test/query-tests/experimental/improper-memoization/ImproperMemoization.expected | Removes a testFailures entry now that the test source is annotated appropriately. |
| ruby/ql/test/query-tests/experimental/improper-memoization/improper_memoization.rb | Adds an inline SPURIOUS annotation for m14 on the end line. |
| ruby/ql/test/library-tests/frameworks/sinatra/views/index.erb | Adds an ERB comment inline expectation for hasTaintFlow on the sink line. |
| ruby/ql/test/library-tests/frameworks/sinatra/Flow.expected | Removes the testFailures entry for the ERB taint flow result. |
| ruby/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll | Extends Ruby inline expectations comment handling to include ERB comment tokens. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
hvitved
reviewed
Jun 29, 2026
| RubyComment(Ruby::Comment comment) or | ||
| ErbComment(R::ErbComment comment) | ||
|
|
||
| private class AnyComment extends TAnyComment { |
Contributor
There was a problem hiding this comment.
Why not just inline this into ExpectationComment?
Contributor
Author
There was a problem hiding this comment.
Done. I've also cleaned up the CodeQL slightly using any.
hvitved
requested changes
Jun 29, 2026
hvitved
left a comment
Contributor
There was a problem hiding this comment.
One more small suggestion.
Comment on lines
+15
to
+31
| string toString() { | ||
| result = any(Ruby::Comment c | this = RubyComment(c)).toString() | ||
| or | ||
| result = any(R::ErbComment c | this = ErbComment(c)).toString() | ||
| } | ||
|
|
||
| Location getLocation() { | ||
| result = any(Ruby::Comment c | this = RubyComment(c)).getLocation() | ||
| or | ||
| result = any(R::ErbComment c | this = ErbComment(c)).getLocation() | ||
| } | ||
|
|
||
| string getContents() { | ||
| result = any(Ruby::Comment c | this = RubyComment(c)).getValue().suffix(1) | ||
| or | ||
| result = any(R::ErbComment c | this = ErbComment(c)).getValue().suffix(1) | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| string toString() { | |
| result = any(Ruby::Comment c | this = RubyComment(c)).toString() | |
| or | |
| result = any(R::ErbComment c | this = ErbComment(c)).toString() | |
| } | |
| Location getLocation() { | |
| result = any(Ruby::Comment c | this = RubyComment(c)).getLocation() | |
| or | |
| result = any(R::ErbComment c | this = ErbComment(c)).getLocation() | |
| } | |
| string getContents() { | |
| result = any(Ruby::Comment c | this = RubyComment(c)).getValue().suffix(1) | |
| or | |
| result = any(R::ErbComment c | this = ErbComment(c)).getValue().suffix(1) | |
| } | |
| Ruby::Comment asRubyComment() { this = RubyComment(result) } | |
| R::ErbComment asErbComment() { this = ErbComment(result) } | |
| string toString() { | |
| result = this.asRubyComment().toString() | |
| or | |
| result = this.asErbComment().toString() | |
| } | |
| Location getLocation() { | |
| result = this.asRubyComment().getLocation() | |
| or | |
| result = this.asErbComment().getLocation() | |
| } | |
| string getContents() { | |
| result = this.asRubyComment().getValue().suffix(1) | |
| or | |
| result = this.asErbComment().getValue().suffix(1) | |
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Address further testFailures in inline expectations tests. Annotations should always be updated so that the
testFailuressection of the.expectedfile is empty.The
improper_memoization.rbchange is trivial. The other one is in a.erbfile, so I had to add support for inline expectations comments in.erbfiles in order to make thetestFailuresresult go away. I'm fairly happy with that aspect of the PR.I'd appreciate confirmation that the taint flow result in the
.erbis a valid result, and shouldn't be marked asSPURIOUS:. It looks like that's the intent, but I wasn't 100% confident what was going on.