Skip to content

Conversation

@tausbn
Copy link
Contributor

@tausbn tausbn commented Oct 16, 2025

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.

Unfortunately, the VSCode CodeQL extension does not automatically pick up on changes to the workspace-query-history.json file, 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 the Developer: Reload Window action.

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.

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.
@tausbn tausbn requested a review from asgerf October 16, 2025 15:03
@tausbn tausbn added the no-change-note-required This PR does not need a change note label Oct 16, 2025
@tausbn tausbn marked this pull request as ready for review October 16, 2025 15:10
@tausbn tausbn requested a review from a team as a code owner October 16, 2025 15:10
Copilot AI review requested due to automatic review settings October 16, 2025 15:10
Copy link
Contributor

Copilot AI left a 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.py script 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)."""
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
"""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)."""

Copilot uses AI. Check for mistakes.
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")
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
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"

Copilot uses AI. Check for mistakes.
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]
Copy link

Copilot AI Oct 16, 2025

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.

Suggested change
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]

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@asgerf asgerf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me!

@tausbn tausbn merged commit 9efa20d into main Oct 20, 2025
8 checks passed
@tausbn tausbn deleted the tausbn/add-query-history-patcher branch October 20, 2025 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants