-
Notifications
You must be signed in to change notification settings - Fork 202
Move variant analysis tests out of cli-integration directory #1628
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
The CI failure is not related to this PR and fails on main as well:
|
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.
Thanks for adding more documentation and cleaning the tests up! ❤️
@@ -10,7 +10,7 @@ import * as path from 'path'; | |||
import { VariantAnalysisResultsManager } from '../../../remote-queries/variant-analysis-results-manager'; | |||
import { createMockVariantAnalysisRepoTask } from '../../factories/remote-queries/gh-api/variant-analysis-repo-task'; | |||
import { CodeQLCliServer } from '../../../cli'; | |||
import { storagePath } from '../global.helper'; | |||
import { storagePath } from '../../cli-integration/global.helper'; |
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.
Should we still be relying on this file from the cli-integration
directory, or should that file be moved to be somewhere more generic? Although I'm also aware we don't want to bloat the PR unless necessary.
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.
There are still three files in the cli-integration folder that depend on that helper:
extensions/ql-vscode/src/vscode-tests/cli-integration/databases.test.ts
extensions/ql-vscode/src/vscode-tests/cli-integration/new-query.test.ts
extensions/ql-vscode/src/vscode-tests/cli-integration/queries.test.ts
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.
I don't think the storagePath
is set outside of the cli-integration
tests (it's set in a helper that is only loaded by the cli-integration
tests), so this would be undefined
in these tests. Where are the results actually stored when running these tests now?
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.
e683ec6
to
ef64dbe
Compare
Taking a look at this, but running the Running the tests via the terminal works fine. I'm less convinced we should be telling people in the |
We've added some tests to the cli-integration folder which don't require the CLI to be run successfully. Let's move them in the no-workspace folder. The three files are: - cli-integration/remote-queries/variant-analysis-manager.test.ts - cli-integration/remote-queries/variant-analysis-monitor.test.ts - cli-integration/remote-queries/variant-analysis-results-manager.test We're also moving the variant-analysis-process.test.ts file into tests/pure-tests/remote-queries as the processor contains helper methods rather than being a core class.
ef64dbe
to
37cc927
Compare
Have rebased to account for #1631 |
9665d46
to
7bbfea6
Compare
This is proving a bit more complicated so I've pulled out the README change into a small PR: #1635 |
5a0399b
to
11ecb3e
Compare
We're no longer able to stub the extension and its context in the same way we did for our CLI integration tests. We do however have helper methods for creating smaller dummy versions in the `no-workspace` folder. We've had to extract the `createMockCliServer` method into a separate file so we can re-use it. We've also had to redefine `storagePath` since it can no longer be loaded from `global.helper.ts`. The `global.helper.ts` file only has methods that execute when we run the CLI integration tests, but not the `no-workspace` tests.
Since we no longer use a fully formed extension object for our tests, it will not have access to the real commands we've defined on it. This means we'll have to stub the `commands.executeCommand` call. The side-effect is that we're no longer able to test that our `autoDownloadVariantAnalysisResult` is really calling the API the way we expect it to do so we'll have to throw away that test.
11ecb3e
to
37bd51c
Compare
Thanks for the reviews @koesie10 and @robertbrignull. I've had to change the way we mock some things in these tests now that they're in the More details in the commit message here: ca3bf04 This is now ready for review again. |
...ions/ql-vscode/src/vscode-tests/no-workspace/remote-queries/variant-analysis-manager.test.ts
Outdated
Show resolved
Hide resolved
...ions/ql-vscode/src/vscode-tests/no-workspace/remote-queries/variant-analysis-monitor.test.ts
Outdated
Show resolved
Hide resolved
...vscode/src/vscode-tests/no-workspace/remote-queries/variant-analysis-results-manager.test.ts
Outdated
Show resolved
Hide resolved
cli = extension.cliServer; | ||
variantAnalysisManager = new VariantAnalysisManager(extension.ctx, cli, storagePath, logger); | ||
const ctx = createMockExtensionContext(); | ||
cli = createMockCliServer({ |
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.
Sorry if this is a silly question, but if we're having to provide a mock CLI server, does that indicate that these tests should be staying in the CLI-integration test suite?
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.
I don't think so, but @elenatanasoiu please correct me if I'm wrong. The cli-integration
tests will also actually call the cli, but in these specific tests we're not actually calling the cli. The only place where the cli would be called from these tests is if we're decoding BQRS results, but that isn't something we're testing from these tests.
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.
Yeah, as @koesie10 said, we don't actually need the CLI for our tests. However, both the variantAnalysisManager
and variantAnalysisResultsManager
tests require some sort of CLI instance when they're first initialised so we need a dummy version of it without actually using it.
And add add a default value for it in the server setup. This means we can now pass only the `sandbox` param in order to have a working CLI server.
Since we've had to stub the `extension.commands` call in order to move these tests to a different folder, we're no longer calling anything on the variant analysis manager. This would normally happen by triggering an extension command. Let's assert that we call the command insteaed of the manager in our monitor tests and get rid of the manager setup.
…folder This was missed when we first moved the test files.
Since we actually have data here that we use in the tests, we might as well point the storagePath at the same directory.
Just a note I'll leave the remaining review of this up to @koesie10. But do let me know if you'd like me to actively review. |
sandbox: sinon.SinonSandbox, | ||
mockOperations: Record<string, any[]> = {} | ||
): CodeQLCliServer { | ||
if (mockOperations == {}) { |
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.
I don't think this will work since objects are reference types, so even {} == {}
will be false
. Instead, you can add the defaults as part of the function arguments or make the default undefined
(although then you will also need to change the argument type).
However, I don't think we are even using these operations. So, would it also work to simply have an empty default (i.e. no operations are mocked)?
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.
Thanks for the review @koesie10! @charisk and I paired a bit on writing some integration tests and decided we're going to go in a different direction: #1628 (comment).
I think the fact that we keep needing to adapt the mocking methods (and deleting tests) is an indicator that the no-workspace
folder isn't the right place for these tests.
variantAnalysisManager = new VariantAnalysisManager(extension.ctx, cli, storagePath, logger); | ||
const ctx = createMockExtensionContext(); | ||
cli = createMockCliServer(sandbox); | ||
const storagePath = path.join(__dirname); |
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.
Do we need this storage path to be set to an existing path or can we just use an empty string instead? I don't think we're actually storing any results in these tests
It looks like no-workspace means mocking out the extension, which from my chat with @elenatanasoiu is not exactly what we want for these tests, so moving to minimal-workspace might make more sense. |
Thanks @charisk. While pairing together, we realized that in order to be able to write some more tests for the monitor and add more integration tests to the query history, we are going to need to be able to listen to API calls. Unfortunately, moving the tests to the We decided that moving these tests into the I'm going to close this PR and open a new one. |
We've added some tests to the cli-integration folder which don't require
the CLI to be run successfully. Let's move them in the no-workspace
folder.
The three files are:
cli-integration/remote-queries/variant-analysis-manager.test.ts
cli-integration/remote-queries/variant-analysis-monitor.test.ts
cli-integration/remote-queries/variant-analysis-results-manager.test
We're also moving the
variant-analysis-processor.test.ts
file intotests/pure-tests/remote-queries
as the processor contains helper methodsand doesn't depend on the CLI.
While we're here, we're also documenting what the cli-integration tests are for
since the name is confusing.
Checklist
ready-for-doc-review
label there.