testilo 20.0.2 → 21.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.
@@ -1,241 +0,0 @@
1
- /*
2
- tsp31
3
- Testilo score proc 31
4
-
5
- Computes target score data and adds them to a ts31 report.
6
- */
7
-
8
- // IMPORTS
9
-
10
- const {issues} = require('./tic31');
11
-
12
- // CONSTANTS
13
-
14
- // ID of this proc.
15
- const scoreProcID = 'tsp31';
16
- // Configuration disclosures.
17
- const severityWeights = [1, 2, 3, 4];
18
- const toolWeight = 0.1;
19
- const logWeights = {
20
- logCount: 0.1,
21
- logSize: 0.002,
22
- errorLogCount: 0.2,
23
- errorLogSize: 0.004,
24
- prohibitedCount: 3,
25
- visitRejectionCount: 2
26
- };
27
- // How much each second of excess latency adds to the score.
28
- const latencyWeight = 1;
29
- // Normal latency (1.5 second per visit).
30
- const normalLatency = 9;
31
- // How much each prevention adds to the score.
32
- const preventionWeight = 300;
33
- // Indexes of issues.
34
- const issueIndex = {};
35
- const issueMatcher = [];
36
- Object.keys(issues).forEach(issueName => {
37
- Object.keys(issues[issueName].tools).forEach(toolName => {
38
- Object.keys(issues[issueName].tools[toolName]).forEach(issueID => {
39
- if (! issueIndex[toolName]) {
40
- issueIndex[toolName] = {};
41
- }
42
- issueIndex[toolName][issueID] = issueName;
43
- if (issues[issueName].tools[toolName][issueID].variable) {
44
- issueMatcher.push(issueID);
45
- }
46
- })
47
- });
48
- });
49
-
50
- // FUNCTIONS
51
-
52
- // Scores a report.
53
- exports.scorer = report => {
54
- console.log(`Scoring report ${report.id}`);
55
- // If there are any acts in the report:
56
- const {acts} = report;
57
- if (Array.isArray(acts) && acts.length) {
58
- // If any of them are test acts:
59
- const testActs = acts.filter(act => act.type === 'test');
60
- if (testActs.length) {
61
- // Initialize the score data.
62
- const score = {
63
- scoreProcID,
64
- summary: {
65
- total: 0,
66
- issue: 0,
67
- tool: 0,
68
- prevention: 0,
69
- log: 0,
70
- latency: 0
71
- },
72
- details: {
73
- severity: {
74
- total: [0, 0, 0, 0],
75
- byTool: {}
76
- },
77
- prevention: {},
78
- issue: {}
79
- }
80
- };
81
- const {summary, details} = score;
82
- // For each test act:
83
- testActs.forEach(act => {
84
- // If the page prevented the tool from operating:
85
- const {which, standardResult} = act;
86
- if (! standardResult || standardResult.prevented) {
87
- // Add this to the score.
88
- details.prevention[which] = preventionWeight;
89
- }
90
- // Otherwise, if a successful standard result exists:
91
- else if (
92
- standardResult
93
- && standardResult.totals
94
- && standardResult.totals.length === 4
95
- && standardResult.instances
96
- ) {
97
- // Add the severity totals of the tool to the score.
98
- const {totals} = standardResult;
99
- details.severity.byTool[which] = totals;
100
- // Add the instance data of the tool to the score.
101
- standardResult.instances.forEach(instance => {
102
- let {ruleID} = instance;
103
- if (! issueIndex[which][ruleID]) {
104
- ruleID = issueMatcher.find(pattern => {
105
- const patternRE = new RegExp(pattern);
106
- return patternRE.test(instance.ruleID);
107
- });
108
- }
109
- if (ruleID) {
110
- const issueID = issueIndex[which][ruleID];
111
- if (! details.issue[issueID]) {
112
- details.issue[issueID] = {
113
- score: 0,
114
- maxCount: 0,
115
- weight: issues[issueID].weight,
116
- tools: {}
117
- };
118
- }
119
- if (! details.issue[issueID].tools[which]) {
120
- details.issue[issueID].tools[which] = {};
121
- }
122
- if (! details.issue[issueID].tools[which][ruleID]) {
123
- const ruleData = issues[issueID].tools[which][ruleID];
124
- details.issue[issueID].tools[which][ruleID] = {
125
- quality: ruleData.quality,
126
- what: ruleData.what,
127
- complaints: {
128
- countTotal: 0,
129
- texts: []
130
- }
131
- };
132
- }
133
- details
134
- .issue[issueID]
135
- .tools[which][ruleID]
136
- .complaints
137
- .countTotal += instance.count || 1;
138
- if (
139
- ! details
140
- .issue[issueID]
141
- .tools[which][ruleID]
142
- .complaints
143
- .texts
144
- .includes(instance.what)
145
- ) {
146
- details.issue[issueID].tools[which][ruleID].complaints.texts.push(instance.what);
147
- }
148
- }
149
- else {
150
- console.log(`ERROR: ${instance.ruleID} of ${which} not found in issues`);
151
- }
152
- });
153
- }
154
- // Otherwise, i.e. if a failed standard result exists:
155
- else {
156
- // Add an inferred prevention to the score.
157
- details.prevention[which] = preventionWeight;
158
- }
159
- });
160
- // For each issue with any complaints:
161
- Object.keys(details.issue).forEach(issueID => {
162
- const issueData = details.issue[issueID];
163
- // For each tool with any complaints for the issue:
164
- Object.keys(issueData.tools).forEach(toolID => {
165
- // Get the sum of the weighted counts of its issue rules.
166
- let weightedCount = 0;
167
- Object.values(issueData.tools[toolID]).forEach(ruleData => {
168
- weightedCount += ruleData.quality * ruleData.complaints.countTotal;
169
- });
170
- // If the sum exceeds the existing maximum weighted count for the issue:
171
- if (weightedCount > issueData.maxCount) {
172
- // Change the maximum count for the issue to the sum.
173
- issueData.maxCount = weightedCount;
174
- }
175
- });
176
- // Get the score for the issue.
177
- issueData.score = Math.round(issueData.weight * issueData.maxCount);
178
- });
179
- // Add the severity detail totals to the score.
180
- details.severity.total = Object.keys(details.severity.byTool).reduce((severityTotals, toolID) => {
181
- details.severity.byTool[toolID].forEach((severityScore, index) => {
182
- severityTotals[index] += severityScore;
183
- });
184
- return severityTotals;
185
- }, details.severity.total);
186
- // Add the summary issue total to the score.
187
- summary.issue = Object
188
- .values(details.issue)
189
- .reduce((total, current) => total + current.score, 0);
190
- // Add the summary tool total to the score.
191
- summary.tool = toolWeight * details.severity.total.reduce(
192
- (total, current, index) => total + severityWeights[index] * current, 0
193
- );
194
- // Add the summary prevention total to the score.
195
- summary.prevention = Object.values(details.prevention).reduce(
196
- (total, current) => total + current, 0
197
- );
198
- // Add the summary log score to the score.
199
- const {jobData} = report;
200
- if (jobData) {
201
- summary.log = Math.max(0, Math.round(
202
- logWeights.logCount * jobData.logCount
203
- + logWeights.logSize * jobData.logSize +
204
- + logWeights.errorLogCount * jobData.errorLogCount
205
- + logWeights.errorLogSize * jobData.errorLogSize
206
- + logWeights.prohibitedCount * jobData.prohibitedCount +
207
- + logWeights.visitRejectionCount * jobData.visitRejectionCount
208
- ));
209
- // Add the summary latency score to the score.
210
- summary.latency = Math.round(
211
- latencyWeight * (Math.max(0, jobData.visitLatency - normalLatency))
212
- );
213
- }
214
- // Round the unrounded scores.
215
- Object.keys(summary).forEach(summaryTypeName => {
216
- summary[summaryTypeName] = Math.round(summary[summaryTypeName]);
217
- });
218
- details.severity.total.forEach((severityTotal, index) => {
219
- details.severity.total[index] = Math.round(severityTotal);
220
- });
221
- // Add the summary total score to the score.
222
- summary.total = summary.issue
223
- + summary.tool
224
- + summary.prevention
225
- + summary.log
226
- + summary.latency;
227
- // Add the score to the report.
228
- report.score = score;
229
- }
230
- // Otherwise, i.e. if none of them is a test act:
231
- else {
232
- // Report this.
233
- console.log('ERROR: No test acts');
234
- }
235
- }
236
- // Otherwise, i.e. if there are no acts in the report:
237
- else {
238
- // Report this.
239
- console.log('ERROR: No acts');
240
- }
241
- };
@@ -1,278 +0,0 @@
1
- /*
2
- tsp33
3
- Testilo score proc 33
4
-
5
- Computes target score data and adds them to a ts33 report.
6
- */
7
-
8
- // IMPORTS
9
-
10
- const {issues} = require('./tic33');
11
-
12
- // CONSTANTS
13
-
14
- // ID of this proc.
15
- const scoreProcID = 'tsp33';
16
- // Configuration disclosures.
17
- const severityWeights = [1, 2, 3, 4];
18
- const toolWeight = 0.1;
19
- const logWeights = {
20
- logCount: 0.1,
21
- logSize: 0.002,
22
- errorLogCount: 0.2,
23
- errorLogSize: 0.004,
24
- prohibitedCount: 3,
25
- visitRejectionCount: 2
26
- };
27
- // How much each second of excess latency adds to the score.
28
- const latencyWeight = 1;
29
- // Normal latency (1.5 second per visit).
30
- const normalLatency = 9;
31
- // How much each prevention adds to the score.
32
- const preventionWeight = 300;
33
- // Initialize a table of tool rules.
34
- const issueIndex = {};
35
- // Initialize an array of variably named tool rules.
36
- const issueMatcher = [];
37
- // For each issue:
38
- Object.keys(issues).forEach(issueName => {
39
- // For each tool with rules belonging to that issue:
40
- Object.keys(issues[issueName].tools).forEach(toolName => {
41
- // For each of those rules:
42
- Object.keys(issues[issueName].tools[toolName]).forEach(ruleID => {
43
- // Add it to the table of tool rules.
44
- if (! issueIndex[toolName]) {
45
- issueIndex[toolName] = {};
46
- }
47
- issueIndex[toolName][ruleID] = issueName;
48
- // If it is variably named:
49
- if (issues[issueName].tools[toolName][ruleID].variable) {
50
- // Add it to the array of variably named tool rules.
51
- issueMatcher.push(ruleID);
52
- }
53
- })
54
- });
55
- });
56
-
57
- // FUNCTIONS
58
-
59
- // Scores a report.
60
- exports.scorer = report => {
61
- // If there are any acts in the report:
62
- const {acts} = report;
63
- if (Array.isArray(acts) && acts.length) {
64
- // If any of them are test acts:
65
- const testActs = acts.filter(act => act.type === 'test');
66
- if (testActs.length) {
67
- // Initialize the score data.
68
- const score = {
69
- scoreProcID,
70
- summary: {
71
- total: 0,
72
- issue: 0,
73
- solo: 0,
74
- tool: 0,
75
- prevention: 0,
76
- log: 0,
77
- latency: 0
78
- },
79
- details: {
80
- severity: {
81
- total: [0, 0, 0, 0],
82
- byTool: {}
83
- },
84
- prevention: {},
85
- issue: {},
86
- solo: {}
87
- }
88
- };
89
- const {summary, details} = score;
90
- // For each test act:
91
- testActs.forEach(act => {
92
- // If the page prevented the tool from operating:
93
- const {which, standardResult} = act;
94
- if (! standardResult || standardResult.prevented) {
95
- // Add this to the score.
96
- details.prevention[which] = preventionWeight;
97
- }
98
- // Otherwise, if a successful standard result exists:
99
- else if (
100
- standardResult
101
- && standardResult.totals
102
- && standardResult.totals.length === 4
103
- && standardResult.instances
104
- ) {
105
- // Add the severity totals of the tool to the score.
106
- const {totals} = standardResult;
107
- details.severity.byTool[which] = totals;
108
- // For each instance of the tool:
109
- standardResult.instances.forEach(instance => {
110
- // Get the rule ID.
111
- const {ruleID, ordinalSeverity, count} = instance;
112
- // If it is not in the table of tool rules:
113
- let canonicalRuleID = ruleID;
114
- if (! issueIndex[which][ruleID]) {
115
- // Convert it to the variably named tool rule that it matches, if any.
116
- canonicalRuleID = issueMatcher.find(pattern => {
117
- const patternRE = new RegExp(pattern);
118
- return patternRE.test(instance.ruleID);
119
- });
120
- }
121
- // If the rule ID belongs to an issue:
122
- if (canonicalRuleID) {
123
- // Get the issue.
124
- const issueName = issueIndex[which][canonicalRuleID];
125
- // Add the instance to the issue details of the score data.
126
- if (! details.issue[issueName]) {
127
- details.issue[issueName] = {
128
- score: 0,
129
- maxCount: 0,
130
- weight: issues[issueName].weight,
131
- tools: {}
132
- };
133
- }
134
- if (! details.issue[issueName].tools[which]) {
135
- details.issue[issueName].tools[which] = {};
136
- }
137
- if (! details.issue[issueName].tools[which][canonicalRuleID]) {
138
- const ruleData = issues[issueName].tools[which][canonicalRuleID];
139
- details.issue[issueName].tools[which][canonicalRuleID] = {
140
- quality: ruleData.quality,
141
- what: ruleData.what,
142
- complaints: {
143
- countTotal: 0,
144
- texts: []
145
- }
146
- };
147
- }
148
- details
149
- .issue[issueName]
150
- .tools[which][canonicalRuleID]
151
- .complaints
152
- .countTotal += instance.count || 1;
153
- if (
154
- ! details
155
- .issue[issueName]
156
- .tools[which][canonicalRuleID]
157
- .complaints
158
- .texts
159
- .includes(instance.what)
160
- ) {
161
- details
162
- .issue[issueName]
163
- .tools[which][canonicalRuleID]
164
- .complaints
165
- .texts
166
- .push(instance.what);
167
- }
168
- }
169
- // Otherwise, i.e. if the rule ID belongs to no issue:
170
- else {
171
- // Add the instance to the solo details of the score data.
172
- if (! details.solo[which]) {
173
- details.solo[which] = {};
174
- }
175
- if (! details.solo[which][ruleID]) {
176
- details.solo[which][ruleID] = 0;
177
- }
178
- details.solo[which][ruleID] += (count || 1) * (ordinalSeverity + 1);
179
- // Report this.
180
- console.log(`ERROR: ${instance.ruleID} of ${which} not found in issues`);
181
- }
182
- });
183
- }
184
- // Otherwise, i.e. if a failed standard result exists:
185
- else {
186
- // Add an inferred prevention to the score.
187
- details.prevention[which] = preventionWeight;
188
- }
189
- });
190
- // For each issue with any complaints:
191
- Object.keys(details.issue).forEach(issueName => {
192
- const issueData = details.issue[issueName];
193
- // For each tool with any complaints for the issue:
194
- Object.keys(issueData.tools).forEach(toolID => {
195
- // Get the sum of the weighted counts of its issue rules.
196
- let weightedCount = 0;
197
- Object.values(issueData.tools[toolID]).forEach(ruleData => {
198
- weightedCount += ruleData.quality * ruleData.complaints.countTotal;
199
- });
200
- // If the sum exceeds the existing maximum weighted count for the issue:
201
- if (weightedCount > issueData.maxCount) {
202
- // Change the maximum count for the issue to the sum.
203
- issueData.maxCount = weightedCount;
204
- }
205
- });
206
- // Get the score for the issue.
207
- issueData.score = Math.round(issueData.weight * issueData.maxCount);
208
- });
209
- // Add the severity detail totals to the score.
210
- details.severity.total = Object.keys(details.severity.byTool).reduce((severityTotals, toolID) => {
211
- details.severity.byTool[toolID].forEach((severityScore, index) => {
212
- severityTotals[index] += severityScore;
213
- });
214
- return severityTotals;
215
- }, details.severity.total);
216
- // Add the summary issue total to the score.
217
- summary.issue = Object
218
- .values(details.issue)
219
- .reduce((total, current) => total + current.score, 0);
220
- // Add the summary solo total to the score.
221
- Object.keys(details.solo).forEach(tool => {
222
- summary.solo += Object
223
- .values(details.solo[tool])
224
- .reduce((total, current) => total + current);
225
- });
226
- // Add the summary tool total to the score.
227
- summary.tool = toolWeight * details.severity.total.reduce(
228
- (total, current, index) => total + severityWeights[index] * current, 0
229
- );
230
- // Add the summary prevention total to the score.
231
- summary.prevention = Object.values(details.prevention).reduce(
232
- (total, current) => total + current, 0
233
- );
234
- // Add the summary log score to the score.
235
- const {jobData} = report;
236
- if (jobData) {
237
- summary.log = Math.max(0, Math.round(
238
- logWeights.logCount * jobData.logCount
239
- + logWeights.logSize * jobData.logSize +
240
- + logWeights.errorLogCount * jobData.errorLogCount
241
- + logWeights.errorLogSize * jobData.errorLogSize
242
- + logWeights.prohibitedCount * jobData.prohibitedCount +
243
- + logWeights.visitRejectionCount * jobData.visitRejectionCount
244
- ));
245
- // Add the summary latency score to the score.
246
- summary.latency = Math.round(
247
- latencyWeight * (Math.max(0, jobData.visitLatency - normalLatency))
248
- );
249
- }
250
- // Round the unrounded scores.
251
- Object.keys(summary).forEach(summaryTypeName => {
252
- summary[summaryTypeName] = Math.round(summary[summaryTypeName]);
253
- });
254
- details.severity.total.forEach((severityTotal, index) => {
255
- details.severity.total[index] = Math.round(severityTotal);
256
- });
257
- // Add the summary total score to the score.
258
- summary.total = summary.issue
259
- + summary.solo
260
- + summary.tool
261
- + summary.prevention
262
- + summary.log
263
- + summary.latency;
264
- // Add the score to the report.
265
- report.score = score;
266
- }
267
- // Otherwise, i.e. if none of them is a test act:
268
- else {
269
- // Report this.
270
- console.log('ERROR: No test acts');
271
- }
272
- }
273
- // Otherwise, i.e. if there are no acts in the report:
274
- else {
275
- // Report this.
276
- console.log('ERROR: No acts');
277
- }
278
- };