fix: escape file paths in GraphQL queries and add batch-size limits#300
Open
travellingsoldier85 wants to merge 6 commits intoentrius:testfrom
Open
Conversation
Co-authored-by: Ander <61125407+anderdc@users.noreply.github.com>
Co-authored-by: Ander <61125407+anderdc@users.noreply.github.com>
Fix two issues in the file content fetching functions used for
token-based PR scoring:
1. **GraphQL injection from unescaped file paths**: File paths containing
double quotes or backslashes are interpolated directly into GraphQL
query strings, breaking query syntax and causing the entire file
content fetch to fail silently. This means PRs touching files with
special characters in their paths get scored as 0.
- Add _escape_graphql_expression() helper that escapes \ and "
- Apply escaping in both fetch_file_contents_batch and
fetch_file_contents_with_base
2. **No batch-size limit for large PRs**: PRs with many files generate
a single GraphQL query with one object lookup per file. GitHub's
GraphQL API has query complexity limits, so large PRs can trigger
502 errors and lose all file contents for scoring.
- Add _MAX_FILES_PER_GRAPHQL_BATCH = 50 constant
- Split both fetch functions into batched requests
- Extract _fetch_file_contents_with_base_batch() as internal helper
Tests added for escaping correctness, batch splitting behavior,
special character handling, and edge cases (empty input, added/removed
files, failed batches).
Author
34f0be2 to
d4815ff
Compare
Collaborator
|
Have we ever actually seen a PR where we need to escape characters? do you have one where gittensor miners needed this? what happens when that issue occurs? do we fail the entire PR or just grading that file? also I do like the graphql query limits though, not sure if I like the file path escape portion |
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.
Rebased version of #275 — conflicts resolved.
Changes
Previous PR was closed due to merge conflicts. This is a clean rebase on latest
testbranch.