Skip to content

Make query history tests work with remote queries & variant analyses#1688

Merged
elenatanasoiu merged 17 commits intomainfrom
elena/query-history-testing-with-different-items
Nov 2, 2022
Merged

Make query history tests work with remote queries & variant analyses#1688
elenatanasoiu merged 17 commits intomainfrom
elena/query-history-testing-with-different-items

Conversation

@elenatanasoiu
Copy link
Copy Markdown
Contributor

@elenatanasoiu elenatanasoiu commented Oct 31, 2022

🚨 Please review this PR commit-by-commit.

This PR holds part of the clean-up work to allow us to write more tests for the QueryHistoryManager and HistoryTreeDataProvider by re-organising tests to make it clear what they're checking and removing
some duplication in the process. This unfortunately results in a lot of noisy diffs as I shuffle things into
describe blocks.

We're also changing part of these tests to work with RemoteQueryHistoryItems and
VariantAnalysisHistoryItems, instead of just testing local query history items.

The query history now has increased test coverage in terms of how items of different types interact
together, specifically:

  • handling an item being clicked / double clicked
  • removing and selecting an item this has been reverted, see 5a40159 for details
  • showing query results for different item types
  • handling single / multi selection

In a future PR we'll also look at:

  • sorting results of different types and
  • removing & re-selecting an item

Disclaimer: I don't think these tests are perfect and there's definitely still some duplication between the
tests in query-history.test.ts and the individual history item test files, but they're a step in the right
direction as they untangle some things that are annoying to deal with in terms of writing/changing
query history tests.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

@elenatanasoiu elenatanasoiu force-pushed the elena/query-history-testing-with-different-items branch from 98a08fb to ab8f59b Compare October 31, 2022 19:52
At the moment our query history tests are set up to only check
local queries.

Let's prepare the ground to introduce remote query history items
and variant analysis history items.

This will allow us to expand test coverage for these other types
of items.
There's a lot of clean-up in these tests so I'm making one change per commit.

Let's move out the utility methods so we can focus on just our tests.
There are a couple of tests that check whether we can correctly
compare two local queries.

These shouldn't be applied to remote queries [1] so let's just
make that a bit clearer by moving them into a local queries describe
block and using the `localHistory` array to choose items to compare
instead of the `allHistory` array.

[1]: https://github.com/github/vscode-codeql/blob/bf1e3c10dbf23480d0e0121fe1990e8d07b707c1/extensions/ql-vscode/src/query-history.ts#L1311-L1314
We're adding both remote query history items and variant analysis history
items to the query history.

We've introduced a little method to shuffle the query history list
before we run our tests so that we don't accidentally write tests that
depend on a fixed order.

The query history now has increased test coverage for:
- handling an item being clicked
- removing and selecting the next item in query history
- handling single / multi selection
- showing the item results

While we're here we're also:
1. Adding a factory to generate variant analysis history items
2. Providing all fields for remote query history items and ordering them
according to their type definition order. At least one field (`queryId`)
was missing from our factory, which we will need to make the tests work
with remote queries.
I don't know why there are two.
And rename original `getChildren` describe block to `sorting` since
that's what the tests are checking.
@elenatanasoiu elenatanasoiu force-pushed the elena/query-history-testing-with-different-items branch 3 times, most recently from 855f6b5 to 5ee5a6d Compare November 1, 2022 11:34
We've introduced a new `local-query-history-item.ts` factory method [1]
which includes a cancellation token. The factory will need to import the
CancellationTokenSource from `vscode`.

We already had a factory method but it didn't quite map with the setup
we needed. For example we need to call `.completeQuery` rather than
providing a dummy `completedQuery` object.

The previous factory method was used in the tests for
`query-history-info.test.ts`. Because that factory omitted the
cancellation token, we could get away with having these tests in the
`tests/pure-tests` folder.

With the addition of the second factory method, the tests for
`query-history-info` blow up because they can't find `vscode`.

Now that we need to add more fields to local query history items, it's
becoming clearer that these `query-history-info` tests should live next
to the `query-history` tests in `vscode-tests/no-workspace`.

Granted, in an ideal situation we'd only have one factory method to
generate a local query history item, but combining these two methods
is actually quite painful. So for now let's at least have the query
history tests next to each other and appease Typescript.
In [1] we changed our factory methods to actually use QueryStatus when
creating remote query & variant analysis history items.

Previously we were just setting the value to `in progress`...

... which made the tests for history-item-label-provider.test.ts pass...

... but that value did not reflect reality ...

What we actually need to do is introduce a method to map different
query statuses to human readable strings, e.g.

QueryStatus.InProgress becomes 'in progress'

[1]: 4b9db6a#diff-217b085c45cd008d938c3da4714b5782db6ad31438b27b07e969254feec8298aL28
We were expecting all three types to behave the same when clicked /
double clicked.

In fact local & remote queries only allow you to open the results view
when they're complete, while variant analyses always allow you to open
the results view no matter what their status.

Let's break down these tests per history item type and test the
expected behaviour more granularly.

NB: I tried moving some of the setup in beforeEach blocks, but alas
queryHistoryManager can be undefined so rather than adding `?` to
every method call, I'm just gonna leave the setup inside the tests.

In an ideal world, we'd stop declaring `queryHistoryManager` as
`undefined`:

```
let queryHistoryManager: QueryHistoryManager | undefined;
```

Baby steps!
@elenatanasoiu elenatanasoiu force-pushed the elena/query-history-testing-with-different-items branch from 5ee5a6d to a1daa91 Compare November 1, 2022 11:40
Paired with @robertbrignull on debugging why having all types of
query history items isn't playing nicely when we try to remove an item.

We've tracked down the issue it the handleRemoveHistoryItem method
not correctly setting the `current` item after a deletion.

However, it's unclear whether the test setup is to blame or this is a
real bug.

I'm going to leave the tests for `handleRemoveHistoryItem` to test just
local queries for now (as they were originally) and will come back to
this in a different PR.
@elenatanasoiu elenatanasoiu force-pushed the elena/query-history-testing-with-different-items branch from 0cc631d to 5a40159 Compare November 1, 2022 17:35
@elenatanasoiu elenatanasoiu changed the title Make query history tests work with remote &variant analysis history items Make query history tests work with remote query & variant analysis history items Nov 1, 2022
@elenatanasoiu elenatanasoiu changed the title Make query history tests work with remote query & variant analysis history items Make query history tests work with remote queries & variant analyses Nov 1, 2022
@elenatanasoiu elenatanasoiu marked this pull request as ready for review November 1, 2022 17:50
@elenatanasoiu elenatanasoiu requested review from a team as code owners November 1, 2022 17:50
To produce valid history items and have them blow up when we need to
add new fields.
@elenatanasoiu elenatanasoiu force-pushed the elena/query-history-testing-with-different-items branch from da61b9e to 841c66c Compare November 2, 2022 10:37
@elenatanasoiu elenatanasoiu merged commit 0965448 into main Nov 2, 2022
@elenatanasoiu elenatanasoiu deleted the elena/query-history-testing-with-different-items branch November 2, 2022 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants