-
Notifications
You must be signed in to change notification settings - Fork 202
Add integration tests with the CLI #645
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
8d76a68 to
5769c14
Compare
|
OK...I'm making progress here. Tests are still failing, but now it is a different failure. Uncovered by fixing the first failure. |
1d88795 to
f53d728
Compare
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.
Added a bunch of comments that help explain things in the commit. Some of the comments are reminders for myself to change things later.
.github/workflows/main.yml
Outdated
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest] | ||
| version: ['v2.3.1', 'v2.3.0'] |
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.
We can choose as many versions as we like. Though, my suggestion is to use the latest as well as one for each supported version of LGTM.
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.
We've had a few recent releases, so let's go with 2.2.6, 2.3.3, 2.4.0, latest.
https://github.com/github/codeql-cli-binaries/releases/latest will always point you to the latest release, so we should deliberately test against that even if we are slow to update the hardcoded list.
| @@ -4,6 +4,7 @@ | |||
| # Generated files | |||
| /dist/ | |||
| out/ | |||
| build/ | |||
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.
Over time, I'd like to move all build artifacts to the build directory. This will make it very clear which pieces we can easily clean up.
| @@ -687,7 +687,8 @@ | |||
| "watch:extension": "tsc --watch", | |||
| "test": "mocha --exit -r ts-node/register test/pure-tests/**/*.ts", | |||
| "preintegration": "rm -rf ./out/vscode-tests && gulp", | |||
| "integration": "node ./out/vscode-tests/run-integration-tests.js", | |||
| "integration": "node ./out/vscode-tests/run-integration-tests.js no-workspace,minimal-workspace", | |||
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.
Note: must pass in the directories to test as part of the argument.
| /** | ||
| * Get the name of the codeql cli installation we prefer to install, based on our current platform. | ||
| */ | ||
| public static getRequiredAssetName(): string { |
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.
Made static so we can use this in our integration tests.
| beforeEach(async () => { | ||
| sandbox = sinon.createSandbox(); |
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.
Use sinon.sandbox where possible. This ensures all stubs and mocks are cleaned up when sandbox.restore() is called. One problem with the integration tests earlier on was that mocks were not being properly restored and we were seeing confusing errors across tests.
| const manager = new (createModule().DistributionManager)(undefined as any, { customCodeQlPath: pathToCmd } as any, undefined as any); | ||
| it('should not warn when deprecated launcher is used, but no new launcher is available', async function() { | ||
| const manager = new (createModule().DistributionManager)( | ||
| { customCodeQlPath: pathToCmd } as any, |
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.
DistributionManager has changed. So, need to update these tests.
| for (const integrationTestSuite of integrationTestSuites) { | ||
| await runTestsWithRetryOnSegfault(integrationTestSuite, 3); | ||
| // Which tests to run. Use a comma-separated list of directories. | ||
| const testDirsString = process.argv[2]; |
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.
See package.json for where this is used.
| @@ -94,3 +104,25 @@ async function main() { | |||
| } | |||
|
|
|||
| main(); | |||
|
|
|||
|
|
|||
| function getLaunchArgs(dir: TestDir) { | |||
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.
This was uglier than I had hoped. '--disable-extensions' needs to be called for minimal and no workspace runs otherwise ambient extensions get in the way of the run. This may not be a problem on the build server, but it is definitely a problem locally.
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.
Annoying but fine for now, since I see you manually install the Test Explorer.
| command.match(/^codeQLDatabases\./) | ||
| || command.match(/^codeQLQueryHistory\./) | ||
| || command.match(/^codeQLAstViewer\./) | ||
| ) { | ||
| scopedCmds.add(command); | ||
| expect(title).not.to.be.undefined; | ||
| commandTitles[command] = title!; | ||
| } | ||
| else { | ||
| } else if ( |
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.
This change is no longer necessary.
f53d728 to
3ceaba9
Compare
4d566a9 to
7cf33a8
Compare
25a608f to
92c70f8
Compare
c345b10 to
ce22b15
Compare
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.
This is great! Didn't go into the details of the test harness execution from Node (if it runs, I trust you) but the refactoring and tests themselves look good.
| @@ -59,16 +59,15 @@ interface QueryHistoryDataProvider extends vscode.TreeDataProvider<CompletedQuer | |||
| /** | |||
| * Tree data provider for the query history view. | |||
| */ | |||
| class HistoryTreeDataProvider implements QueryHistoryDataProvider { | |||
| class HistoryTreeDataProvider extends DisposableObject implements QueryHistoryDataProvider { | |||
| /** | |||
| * XXX: This idiom for how to get a `.fire()`-able event emitter was | |||
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.
Still planning to do this?
|
|
||
| async () => { | ||
| // Set the CLI version here before activation to ensure we don't accidentally try to download a cli | ||
| await workspace.getConfiguration().update('codeQL.cli.executablePath', process.env.CLI_PATH, ConfigurationTarget.Global); |
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.
Good call. Would it make sense to also test picking up a CLI from the PATH? (Perhaps we have that tested elsewhere.)
| import { assertNever } from '../pure/helpers-pure'; | ||
|
|
||
| // For some reason, `TestOptions` is not exported directly from `vscode-test`, | ||
| // but we can be tricky and import directly from the out file. |
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.
crafty
| NoWorskspace = 'no-workspace', | ||
| MinimalWorskspace = 'minimal-workspace', |
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.
minor typos: Workspace
| @@ -94,3 +104,25 @@ async function main() { | |||
| } | |||
|
|
|||
| main(); | |||
|
|
|||
|
|
|||
| function getLaunchArgs(dir: TestDir) { | |||
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.
Annoying but fine for now, since I see you manually install the Test Explorer.
.github/workflows/main.yml
Outdated
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest] | ||
| version: ['v2.3.1', 'v2.3.0'] |
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.
We've had a few recent releases, so let's go with 2.2.6, 2.3.3, 2.4.0, latest.
https://github.com/github/codeql-cli-binaries/releases/latest will always point you to the latest release, so we should deliberately test against that even if we are slow to update the hardcoded list.
|
|
||
| // CLI version to test. Hard code the latest as default. And be sure | ||
| // to update the env if it is not otherwise set. | ||
| const CLI_VERSION = process.env.CLI_VERSION || 'v2.3.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.
I think you can hardcode latest, though you should check the API docs to make sure the asset download URL still works the same.
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.
Unfortunately,
This does not work:
https://github.com/github/codeql-cli-binaries/releases/download/latest/codeql-osx64.zip
But this does:
https://github.com/github/codeql-cli-binaries/releases/download/v2.3.1/codeql-osx64.zip
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.
Also, a downside of using latest locally is that once you download latest once, you will never re-download. We check whether or not to re-download based on the presence of the directory name. The directory name is generated based on the version number. I could probably be more sophisticated about this, but that would add complexity.
This commit adds integration tests that run commands using the CLI. This change introduces a number of enhancements in order to get there. 1. Augments the index-template.ts file so that it downloads an appropriate cli version if requested. 2. Adds the ensureCli.ts that performs the download if a a suitable version is not already installed. See the comments in the file for how this is done. 3. Changes how run-integration-tests is done so that the directories run are specified through a cli argument. 4. Updates the main.yml workflow so that it also runs the cli-integration tests. 5. Takes advantage of the return value of the call to `activate` on the extension. This allows the integration tests to have access to internal variables of the extension like the context, cli, and query server. 6. And of course, adds a handful of simple tests that ensure we have a cli installed of the correct version.
In order to do this, needed to add a few extra pieces: * extracted the simple database download so that it only happens once and is shared across all tests. * needed to update mocha to latest version since that has the new API * But typings isn't updated yet, so submitted a PR into DefinitelyTyped for that. * Added a concept of helper files for test runs. These helper files will contain all the shared global setup. Unfortunately, at this point, we can't run using a language pack since we would also need to download the the ql repository from somewhere.
Also, fix a typo and remove comment.
ce22b15 to
f3d7d07
Compare


Note that even though this PR is labeled as
Complexity: High, it is not particularly dangerous in that most of the complexity is around how the tests run.This commit adds integration tests that run commands using the CLI. This
change introduces a number of enhancements in order to get there.
activateon the extension. This allows the integration tests to have access to internal variables of the extension like the context, cli, and query server.Resolves #642.
Checklist
@github/docs-content-dsphas been cc'd in all issues for UI or other user-facing changes made by this pull request.