Skip to content

Use sarif parser for reopened results#1457

Merged
angelapwen merged 31 commits intogithub:mainfrom
angelapwen:handle-sarif-reopen
Oct 24, 2022
Merged

Use sarif parser for reopened results#1457
angelapwen merged 31 commits intogithub:mainfrom
angelapwen:handle-sarif-reopen

Conversation

@angelapwen
Copy link
Copy Markdown
Contributor

@angelapwen angelapwen commented Aug 9, 2022

When we attempt to re-open query results, instead of using the streaming SARIF parser written in #1004, we used JSON.parse(). This couldn't handle large SARIF files and we ran into an error.

This change uses the streaming SARIF parser instead. Note that this is a draft pull request as it is untested locally. cc @aschackmull (sorry, wrong Anders tagged at first!)

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.

@angelapwen
Copy link
Copy Markdown
Contributor Author

Looks like there are some genuine unit test errors on the method I changed so this will need more 🕵️ work

@angelapwen angelapwen force-pushed the handle-sarif-reopen branch from acb95db to c37c5bf Compare August 15, 2022 17:10
let res;
if (await fs.pathExists(interpretedResultsPath)) {
return { ...JSON.parse(await fs.readFile(interpretedResultsPath, 'utf8')), t: 'SarifInterpretationData' };
res = await sarifParser(interpretedResultsPath);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a thought....if this function throws an error because the file is not parseable, should we delete the file and re-run cli.interpretBqrsSarif?

Possibly, we can do this as a followup.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, that's a good point 👍 I'll leave this comment up for now, while we work out the last invalid SARIF test issue..

@angelapwen angelapwen marked this pull request as ready for review October 19, 2022 22:50
@angelapwen angelapwen requested a review from a team as a code owner October 19, 2022 22:50
expect(results3).to.deep.eq({ a: 6, t: 'SarifInterpretationData' });
afterEach(async () => {
sandbox.restore();
await safeDel(interpretedResultsPath);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm actually seeing sometimes that safeDel isn't so safe. It might be causing some hangs in the cli-integration tests. Can you use the del function instead?

Suggested change
await safeDel(interpretedResultsPath);
await del(interpretedResultsPath);

And add this import to the imports at the top of the file:

import * as del from 'del';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually the test was failing in CI (not locally) when I used del — it said that the file wasn't found when it tried to delete it. See https://github.com/github/vscode-codeql/actions/runs/3285438706/jobs/5412531729

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

1) query-results
       interpretResultsSarif
         "after each" hook for "should use sarifParser on a valid small SARIF file":
     Error: Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.
      at safeCheck (node_modules/del/index.js:37:9)
      at mapper (node_modules/del/index.js:73:4)
      at /home/runner/work/vscode-codeql/vscode-codeql/extensions/ql-vscode/node_modules/p-map/index.js:57:28
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm going to remove the del call entirely and see if it works, given that I am over-writing the existing file when the WriteStream is created.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removing del altogether worked on ubuntu. There is still a failure in this same test in Windows

[main 2022-10-20T17:11:53.979Z] Extension host with pid 6888 exited with code: 134, signal: null.

Test runner caught exception (Failed)
Exit code:   134
Done
Tried running suite 3 time(s), still failed, giving up.

Error: Process completed with exit code 1.

that isn't very descriptive. Exit code 134 seems to be a SIGABRT. I seem to remember there being some intricacies around Windows and file I/O — maybe I'm hitting one of them here?


it('should interpretResultsSarif', async function() {
// up to 2 minutes per test
this.timeout(2 * 60 * 1000);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you move this (and the other) timeout to the describe block above? You only need to set the timeout once up there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I get an Object is possibly undefined error when I move it to the describe block or the beforeEach block — is there a way to get around that error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Figured out how move this to the beforeEach hook and pushed up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nevermind, that didn't work... had to revert

@aeisenberg
Copy link
Copy Markdown
Contributor

I can't tell why the windows tests are failing. It seems to be failing consistently. If you have access to a windows box, maybe try running the tests there.

@angelapwen
Copy link
Copy Markdown
Contributor Author

I can't tell why the windows tests are failing. It seems to be failing consistently. If you have access to a windows box, maybe try running the tests there.

I don't have one, but will 🍐 with Dave tomorrow on this!

@angelapwen angelapwen requested a review from a team as a code owner October 21, 2022 00:16
@aeisenberg
Copy link
Copy Markdown
Contributor

Now, looks like the tests are failing because interpreted.json is trying to be deleted, but a lock on it is being held by another process or something. It has to do with the safeDel method. For some reason, it is not able to be deleted and it looks like the tests can't even read it.

Not a pleasing solution, but perhaps, you can use a different name for interpreted results file for each test. This way, you won't need to delete it in afterEach and you can be sure you can read it in each test.

@angelapwen
Copy link
Copy Markdown
Contributor Author

Now, looks like the tests are failing because interpreted.json is trying to be deleted, but a lock on it is being held by another process or something. It has to do with the safeDel method. For some reason, it is not able to be deleted and it looks like the tests can't even read it.

Not a pleasing solution, but perhaps, you can use a different name for interpreted results file for each test. This way, you won't need to delete it in afterEach and you can be sure you can read it in each test.

Dave and I just came up with something like this in pairing too. It looked like there was a separate issue with Windows Defender that needed a sleep after the file was written (because it couldn't be opened while Windows Defender was scanning it), so we added 10s sleep as well. After that we discovered the problem in the final test where it wasn't able to be deleted/read.

I've renamed the file for just the last test to see if it passes for now (can't reproduce locally without a Windows machine). I can also rename the others for consistency.

@aeisenberg
Copy link
Copy Markdown
Contributor

Not sure if you've tried this already, but you can launch the test version of vscode with --verbose and --log trace` to get some more info while you are running. Augment the CLI options in getLaunchArgs.

@angelapwen angelapwen requested a review from aeisenberg October 24, 2022 17:33
@angelapwen
Copy link
Copy Markdown
Contributor Author

Phew, renaming the path worked 😸 so this PR is finally ready for re-review

Copy link
Copy Markdown
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

Great job sticking with this and working through all these frustrating details. It seemed like a simple task, but there was a lot of subtlety with it.

@angelapwen angelapwen merged commit 63a5021 into github:main Oct 24, 2022
@angelapwen angelapwen deleted the handle-sarif-reopen branch October 24, 2022 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants