-
Notifications
You must be signed in to change notification settings - Fork 234
Fix flaky query history reveal test via stable TreeItem ids #4468
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
cklin
wants to merge
1
commit into
main
Choose a base branch
from
cklin/fix-query-history-reveal-flaky
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ import { env, EventEmitter, ThemeColor, ThemeIcon, TreeItem } from "vscode"; | |
| import { DisposableObject } from "../common/disposable-object"; | ||
| import { assertNever } from "../common/helpers-pure"; | ||
| import type { QueryHistoryInfo } from "./query-history-info"; | ||
| import { getLanguage } from "./query-history-info"; | ||
| import { getLanguage, getQueryId } from "./query-history-info"; | ||
| import { QueryStatus } from "./query-status"; | ||
| import type { HistoryItemLabelProvider } from "./history-item-label-provider"; | ||
| import type { LanguageContextStore } from "../language-context-store"; | ||
|
|
@@ -17,6 +17,25 @@ export enum SortOrder { | |
| CountDesc = "CountDesc", | ||
| } | ||
|
|
||
| /** | ||
| * Computes a stable, unique id for a query history item, suitable for use as a | ||
| * `TreeItem.id`. `getQueryId` alone is not unique because a multi-query run | ||
| * produces several local-query items that share the same `initialInfo.id`; for | ||
| * those we also include the (per-result) output base name. | ||
| */ | ||
| function getTreeItemId(element: QueryHistoryInfo): string { | ||
| switch (element.t) { | ||
| case "local": | ||
| return `local:${element.initialInfo.id}:${ | ||
| element.completedQuery?.query.outputBaseName ?? "" | ||
| }`; | ||
|
Comment on lines
+29
to
+31
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mainly a test flakiness fix, and I don't think the behavior nuance is important enough to justify having its own tests. |
||
| case "variant-analysis": | ||
| return `variant-analysis:${getQueryId(element)}`; | ||
| default: | ||
| assertNever(element); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Tree data provider for the query history view. | ||
| */ | ||
|
|
@@ -54,6 +73,22 @@ export class HistoryTreeDataProvider | |
| async getTreeItem(element: QueryHistoryInfo): Promise<TreeItem> { | ||
| const treeItem = new TreeItem(this.labelProvider.getLabel(element)); | ||
|
|
||
| // Give the tree item a stable, unique id. Without this, VS Code identifies | ||
| // tree nodes by their label plus their position in the list. When multiple | ||
| // history items share the same label, that positional identity is ambiguous | ||
| // and makes `treeView.reveal` resolve to the wrong item (or fail outright) | ||
| // when the list is re-sorted or refreshed. The default label format includes | ||
| // the start time, so labels are effectively unique in practice and users are | ||
| // unlikely to hit this; it mainly affects tests (and any user who customises | ||
| // the label format to something non-unique). | ||
| // | ||
| // `getQueryId` is not guaranteed to be unique: a multi-query run produces | ||
| // several local-query items that share the same `initialInfo.id`. Those | ||
| // items differ by their output base name, so we include it to keep the id | ||
| // unique (VS Code de-duplicates nodes that share an id, which would break | ||
| // reveal/selection for all but one of them). | ||
| treeItem.id = getTreeItemId(element); | ||
|
|
||
| treeItem.command = { | ||
| title: "Query History Item", | ||
| command: "codeQLQueryHistory.itemClicked", | ||
|
|
||
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.
My understanding is that
outputBaseNamewas introduced the same time as multi-query support, so there cannot be any legacy multi-query entry withoutoutputBaseName.