Skip to content

Commit befd804

Browse files
committed
Extend diagnostics export integration test to capture location bug
1 parent a21bb7f commit befd804

File tree

2 files changed

+97
-17
lines changed

2 files changed

+97
-17
lines changed

.github/workflows/__diagnostics-export.yml

Lines changed: 48 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pr-checks/checks/diagnostics-export.yml

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "Diagnostic export"
2-
description: "Tests that a manually added diagnostic is exported to SARIF."
2+
description: "Tests that manually added diagnostics are correctly exported to SARIF."
33
versions: ["latest", "nightly-latest"]
44
env:
55
CODEQL_ACTION_EXPORT_DIAGNOSTICS: true
@@ -10,12 +10,22 @@ steps:
1010
languages: javascript
1111
queries: security-extended
1212
tools: ${{ steps.prepare-test.outputs.tools-url }}
13-
- name: Manually add a diagnostic
13+
- name: Add test diagnostics
1414
shell: bash
1515
env:
1616
CODEQL_PATH: ${{ steps.init.outputs.codeql-path }}
1717
run: |
18-
"$CODEQL_PATH" database add-diagnostic "$RUNNER_TEMP/codeql_databases/javascript" --plaintext-message="Plaintext message" --source-id="lang/diagnostics/example" --source-name="Diagnostic name"
18+
for i in {1..2}; do
19+
# Use the same location twice to test the workaround for the bug in CodeQL CLI 2.12.5 that
20+
# produces an invalid diagnostic with multiple identical location objects.
21+
"$CODEQL_PATH" database add-diagnostic \
22+
"$RUNNER_TEMP/codeql_databases/javascript" \
23+
--file-path /path/to/file \
24+
--plaintext-message "Plaintext message $i" \
25+
--source-id "lang/diagnostics/example" \
26+
--source-name "Diagnostic name" \
27+
--ready-for-status-page
28+
done
1929
- uses: ./../action/analyze
2030
with:
2131
output: "${{ runner.temp }}/results"
@@ -34,19 +44,49 @@ steps:
3444
script: |
3545
const fs = require('fs');
3646
47+
function checkStatusPageNotification(n) {
48+
const expectedMessage = 'Plaintext message 1\n\nCodeQL also found 1 other diagnostic like this. See the workflow log for details.';
49+
if (n.message.text !== expectedMessage) {
50+
core.setFailed(`Expected the status page diagnostic to have the message '${expectedMessage}', but found '${n.message.text}'.`);
51+
}
52+
if (n.locations.length !== 1) {
53+
core.setFailed(`Expected the status page diagnostic to have exactly 1 location, but found ${n.locations.length}.`);
54+
}
55+
const actualUri = n.locations[0].physicalLocation?.artifactLocation?.uri
56+
if (actualUri !== '/path/to/file') {
57+
core.setFailed(`Expected the status page diagnostic to have a location with the URI '/path/to/file', but found '${actualUri}'.`);
58+
}
59+
}
60+
3761
const sarif = JSON.parse(fs.readFileSync(process.env['SARIF_PATH'], 'utf8'));
3862
const run = sarif.runs[0];
3963
4064
const toolExecutionNotifications = run.invocations[0].toolExecutionNotifications;
41-
const diagnosticToolExecutionNotification = toolExecutionNotifications.filter(n => n.descriptor.id === 'lang/diagnostics/example' && n.message.text === 'Plaintext message');
42-
if (diagnosticToolExecutionNotification.length !== 1) {
43-
core.setFailed(`Expected exactly 1 entry for this diagnostic in the 'runs[].invocations[].toolExecutionNotifications[]' SARIF property, found ${diagnosticToolExecutionNotification.length}`);
65+
const statusPageNotifications = toolExecutionNotifications.filter(n =>
66+
n.descriptor.id === 'lang/diagnostics/example' && n.properties?.visibility?.statusPage
67+
);
68+
if (statusPageNotifications.length !== 1) {
69+
core.setFailed(
70+
'Expected exactly one status page reporting descriptor for this diagnostic in the ' +
71+
`'runs[].invocations[].toolExecutionNotifications[]' SARIF property, but found ` +
72+
`${statusPageNotifications.length}. All notification reporting descriptors: ` +
73+
`${JSON.stringify(toolExecutionNotifications)}.`
74+
);
4475
}
76+
checkStatusPageNotification(statusPageNotifications[0]);
4577
4678
const notifications = run.tool.driver.notifications;
47-
const diagnosticNotification = notifications.filter(n => n.id === 'lang/diagnostics/example' && n.name === 'lang/diagnostics/example' && n.fullDescription.text && 'Diagnostic name');
79+
const diagnosticNotification = notifications.filter(n =>
80+
n.id === 'lang/diagnostics/example' && n.name === 'lang/diagnostics/example' &&
81+
n.fullDescription.text === 'Diagnostic name'
82+
);
4883
if (diagnosticNotification.length !== 1) {
49-
core.setFailed(`Expected exactly 1 entry for this diagnostic in the 'runs[].tool.driver.notifications[]' SARIF property, found ${diagnosticNotification.length}`);
84+
core.setFailed(
85+
'Expected exactly one notification for this diagnostic in the ' +
86+
`'runs[].tool.driver.notifications[]' SARIF property, but found ` +
87+
`${diagnosticNotification.length}. All notifications: ` +
88+
`${JSON.stringify(notifications)}.`
89+
);
5090
}
5191
52-
core.info('Finished diagnostic export test');
92+
core.info('Finished diagnostic export test');

0 commit comments

Comments
 (0)