testilo 44.4.1 → 45.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/procs/classify/classify.js +121 -0
package/package.json
CHANGED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/*
|
|
2
|
+
© 2025 Jonathan Robert Pool. All rights reserved.
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
classify
|
|
25
|
+
Standard instance issue classification proc
|
|
26
|
+
|
|
27
|
+
Adds an issue ID to each standard instance in a Testaro report.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
// IMPORTS
|
|
31
|
+
|
|
32
|
+
const {issues} = require('../score/tic');
|
|
33
|
+
|
|
34
|
+
// FUNCTIONS
|
|
35
|
+
|
|
36
|
+
// Returns a directory of issue-classified tool rules, including an array of variable rule IDs.
|
|
37
|
+
const getIssueDirectory = exports.getIssueDirectory = () => {
|
|
38
|
+
// Initialize the directory.
|
|
39
|
+
const issueIndex = {};
|
|
40
|
+
// Initialize an array of variable rule IDs.
|
|
41
|
+
const variableRuleIDs = [];
|
|
42
|
+
// For each classified issue:
|
|
43
|
+
Object.keys(issues).forEach(issueID => {
|
|
44
|
+
// For each tool with rules belonging to that issue:
|
|
45
|
+
Object.keys(issues[issueID].tools).forEach(toolID => {
|
|
46
|
+
// For each of those rules:
|
|
47
|
+
Object.keys(issues[issueID].tools[toolID]).forEach(ruleID => {
|
|
48
|
+
issueIndex[toolID] ??= {};
|
|
49
|
+
// Add its ID to the directory.
|
|
50
|
+
issueIndex[toolID][ruleID] = issueID;
|
|
51
|
+
// If it has a variable ID:
|
|
52
|
+
if (issues[issueID].tools[toolID][ruleID].variable) {
|
|
53
|
+
// Add its ID to the array of variable rule IDs.
|
|
54
|
+
variableRuleIDs.push(ruleID);
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
issueIndex,
|
|
61
|
+
variableRuleIDs
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
// Returns the issue ID of a standard instance.
|
|
65
|
+
const getIssueID = (toolID, instance, issueDirectory) => {
|
|
66
|
+
const {issueIndex, variableRuleIDs} = issueDirectory;
|
|
67
|
+
const {ruleID} = instance;
|
|
68
|
+
let canonicalRuleID = ruleID;
|
|
69
|
+
// If the rule is not in the issue index:
|
|
70
|
+
if (! issueIndex[toolID][ruleID]) {
|
|
71
|
+
// Convert its ID to the variable rule ID that it matches, if any.
|
|
72
|
+
canonicalRuleID = variableRuleIDs.find(pattern => {
|
|
73
|
+
const patternRE = new RegExp(pattern);
|
|
74
|
+
return patternRE.test(ruleID);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
// If the rule or a variable match is in the issue index:
|
|
78
|
+
if (canonicalRuleID) {
|
|
79
|
+
// Return the issue ID of the rule.
|
|
80
|
+
return issueIndex[toolID][canonicalRuleID];
|
|
81
|
+
}
|
|
82
|
+
// Otherwise, i.e. if neither the rule nor a variable match is in the issue index, report this.
|
|
83
|
+
console.log(`ERROR: Unclassified rule of ${toolID}: ${ruleID}`);
|
|
84
|
+
};
|
|
85
|
+
// Adds an issue ID to each standard instance in a report.
|
|
86
|
+
exports.issueAnnotate = report => {
|
|
87
|
+
const {acts} = report;
|
|
88
|
+
// If there are any acts in the report:
|
|
89
|
+
if (Array.isArray(acts) && acts.length) {
|
|
90
|
+
// Get those that are test acts.
|
|
91
|
+
const testActs = acts.filter(act => act.type === 'test');
|
|
92
|
+
// If there are any:
|
|
93
|
+
if (testActs.length) {
|
|
94
|
+
// Get an issue index and an array of variable rule IDs.
|
|
95
|
+
const issueDirectory = getIssueDirectory();
|
|
96
|
+
// For each test act:
|
|
97
|
+
testActs.forEach(act => {
|
|
98
|
+
const {which, standardResult} = act;
|
|
99
|
+
// If a valid non-empty standard result exists:
|
|
100
|
+
if (
|
|
101
|
+
standardResult
|
|
102
|
+
&& standardResult.totals
|
|
103
|
+
&& standardResult.totals.length === 4
|
|
104
|
+
&& standardResult.instances
|
|
105
|
+
&& standardResult.instances.length
|
|
106
|
+
) {
|
|
107
|
+
// For each instance of the tool:
|
|
108
|
+
standardResult.instances.forEach(instance => {
|
|
109
|
+
// Get the issue ID, if any, of the rule.
|
|
110
|
+
const issueID = getIssueID(which, instance, issueDirectory);
|
|
111
|
+
// If the issue ID exists:
|
|
112
|
+
if (issueID) {
|
|
113
|
+
// Add the issue ID to the instance.
|
|
114
|
+
instance.issueID = issueID;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|