-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Misc: Add script for patching the query history #20654
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
Conversation
Adds `patch_query_history.py` in the `misc/scripts` directory. Its function is to extend the existing VSCode query history with a new entry whose JSON evaluator log summary points at a log that was created outside of VSCode. This enables the use of e.g. the Performance Comparison View on runs that were not initiated from within VSCode.
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.
Pull Request Overview
This PR adds a Python script to enable patching VSCode's CodeQL query history with external evaluator logs, allowing performance comparison views on runs not initiated from within VSCode.
- Adds
patch_query_history.pyscript that duplicates the latest query history entry and updates it to point to an external evaluator log - Implements cross-platform VSCode user data directory discovery (Windows, macOS, Linux, and remote variants)
- Provides atomic file writing to safely modify the workspace query history JSON
| return candidates | ||
|
|
||
| def _generate_new_id() -> str: | ||
| """Return a new random id (24 chars from allowed set, prefixed with 'evaluator-log-' for stability).""" |
Copilot
AI
Oct 16, 2025
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.
The docstring states '24 chars from allowed set' but the code generates 23 characters plus the 'evaluator-log-' prefix. The docstring should clarify that it's 23 random characters plus the prefix, or the total length including prefix.
| """Return a new random id (24 chars from allowed set, prefixed with 'evaluator-log-' for stability).""" | |
| """Return a new random id (23 chars from allowed set, prefixed with 'evaluator-log-' for stability).""" |
| payload["initialInfo"] = initial | ||
| new_id = _generate_new_id() | ||
| initial["id"] = new_id | ||
| initial["start"] = datetime.now(timezone.utc).isoformat(timespec="milliseconds").replace("+00:00", "Z") |
Copilot
AI
Oct 16, 2025
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.
The string replacement to convert '+00:00' to 'Z' is fragile and could fail if the timezone format changes. Consider using a more explicit format string or timezone-aware formatting method.
| initial["start"] = datetime.now(timezone.utc).isoformat(timespec="milliseconds").replace("+00:00", "Z") | |
| now = datetime.now(timezone.utc) | |
| # Format with milliseconds and 'Z' suffix | |
| initial["start"] = now.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z" |
| initial["start"] = datetime.now(timezone.utc).isoformat(timespec="milliseconds").replace("+00:00", "Z") | ||
| payload["jsonEvalLogSummaryLocation"] = str(summary_path) | ||
| parts = list(summary_path.parts) | ||
| last_two = "/".join(parts[-2:]) if len(parts) >= 2 else parts[-1] |
Copilot
AI
Oct 16, 2025
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.
Hardcoded forward slash separator may not be appropriate for all platforms. Consider using os.path.join() or Path.joinpath() for cross-platform compatibility, or use the path's native separator.
| last_two = "/".join(parts[-2:]) if len(parts) >= 2 else parts[-1] | |
| last_two = os.path.join(*parts[-2:]) if len(parts) >= 2 else parts[-1] |
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.
Works for me!
Adds
patch_query_history.pyin themisc/scriptsdirectory. Its function is to extend the existing VSCode query history with a new entry whose JSON evaluator log summary points at a log that was created outside of VSCode.This enables the use of e.g. the Performance Comparison View on runs that were not initiated from within VSCode.
Unfortunately, the VSCode CodeQL extension does not automatically pick up on changes to the
workspace-query-history.jsonfile, and so it's a bit fiddly to force a refresh of the query history. The best way I have found so far is to execute theDeveloper: Reload Windowaction.I have verified that this works on Codespaces, and it seems to work on macOS as well, but I give no guarantees for other systems.
Caveat emptor: This script simply duplicates the latest entry in the query history and patches the evaluator log location, query run ID, and label, and nothing else. In particular, all the other logs (if present) will point to the same place as the item that was duplicated.