1
1
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."
3
3
versions : ["latest", "nightly-latest"]
4
4
env :
5
5
CODEQL_ACTION_EXPORT_DIAGNOSTICS : true
@@ -10,12 +10,22 @@ steps:
10
10
languages : javascript
11
11
queries : security-extended
12
12
tools : ${{ steps.prepare-test.outputs.tools-url }}
13
- - name : Manually add a diagnostic
13
+ - name : Add test diagnostics
14
14
shell : bash
15
15
env :
16
16
CODEQL_PATH : ${{ steps.init.outputs.codeql-path }}
17
17
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
19
29
- uses : ./../action/analyze
20
30
with :
21
31
output : " ${{ runner.temp }}/results"
@@ -34,19 +44,49 @@ steps:
34
44
script : |
35
45
const fs = require('fs');
36
46
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
+
37
61
const sarif = JSON.parse(fs.readFileSync(process.env['SARIF_PATH'], 'utf8'));
38
62
const run = sarif.runs[0];
39
63
40
64
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
+ );
44
75
}
76
+ checkStatusPageNotification(statusPageNotifications[0]);
45
77
46
78
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
+ );
48
83
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
+ );
50
90
}
51
91
52
- core.info('Finished diagnostic export test');
92
+ core.info('Finished diagnostic export test');
0 commit comments