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,278 +0,0 @@
1
- /*
2
- tsp36
3
- Testilo score proc 36
4
-
5
- Computes target score data and adds them to a ts36 report.
6
- */
7
-
8
- // IMPORTS
9
-
10
- const {issues} = require('./tic36');
11
-
12
- // CONSTANTS
13
-
14
- // ID of this proc.
15
- const scoreProcID = 'tsp36';
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
- };
@@ -1,292 +0,0 @@
1
- /*
2
- tsp37
3
- Testilo score proc 37
4
-
5
- Computes target score data and adds them to a ts37 report.
6
- */
7
-
8
- // IMPORTS
9
-
10
- const {issues} = require('./tic37');
11
-
12
- // CONSTANTS
13
-
14
- // ID of this proc.
15
- const scoreProcID = 'tsp37';
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
- weights: {
71
- severities: severityWeights,
72
- tool: toolWeight,
73
- log: logWeights,
74
- latency: latencyWeight,
75
- prevention: preventionWeight
76
- },
77
- normalLatency,
78
- summary: {
79
- total: 0,
80
- issue: 0,
81
- solo: 0,
82
- tool: 0,
83
- prevention: 0,
84
- log: 0,
85
- latency: 0
86
- },
87
- details: {
88
- severity: {
89
- total: [0, 0, 0, 0],
90
- byTool: {}
91
- },
92
- prevention: {},
93
- issue: {},
94
- solo: {},
95
- tool: {}
96
- }
97
- };
98
- const {summary, details} = score;
99
- // For each test act:
100
- testActs.forEach(act => {
101
- // If the page prevented the tool from operating:
102
- const {which, standardResult} = act;
103
- if (! standardResult || standardResult.prevented) {
104
- // Add this to the score.
105
- details.prevention[which] = preventionWeight;
106
- }
107
- // Otherwise, if a valid standard result exists:
108
- else if (
109
- standardResult
110
- && standardResult.totals
111
- && standardResult.totals.length === 4
112
- && standardResult.instances
113
- ) {
114
- // Add the severity totals of the tool to the score.
115
- const {totals} = standardResult;
116
- details.severity.byTool[which] = totals;
117
- // Add the severity-weighted tool totals to the score.
118
- details.tool[which] = totals.reduce(
119
- (sum, current, index) => sum + severityWeights[index] * current, 0
120
- );
121
- // For each instance of the tool:
122
- standardResult.instances.forEach(instance => {
123
- // Get the rule ID.
124
- const {ruleID, ordinalSeverity, count} = instance;
125
- // If it is not in the table of tool rules:
126
- let canonicalRuleID = ruleID;
127
- if (! issueIndex[which][ruleID]) {
128
- // Convert it to the variably named tool rule that it matches, if any.
129
- canonicalRuleID = issueMatcher.find(pattern => {
130
- const patternRE = new RegExp(pattern);
131
- return patternRE.test(instance.ruleID);
132
- });
133
- }
134
- // If the rule ID belongs to an issue:
135
- if (canonicalRuleID) {
136
- // Get the issue.
137
- const issueName = issueIndex[which][canonicalRuleID];
138
- // Add the instance to the issue details of the score data.
139
- if (! details.issue[issueName]) {
140
- details.issue[issueName] = {
141
- summary: issues[issueName].summary,
142
- score: 0,
143
- maxCount: 0,
144
- weight: issues[issueName].weight,
145
- tools: {}
146
- };
147
- }
148
- if (! details.issue[issueName].tools[which]) {
149
- details.issue[issueName].tools[which] = {};
150
- }
151
- if (! details.issue[issueName].tools[which][canonicalRuleID]) {
152
- const ruleData = issues[issueName].tools[which][canonicalRuleID];
153
- details.issue[issueName].tools[which][canonicalRuleID] = {
154
- quality: ruleData.quality,
155
- what: ruleData.what,
156
- complaints: {
157
- countTotal: 0,
158
- texts: []
159
- }
160
- };
161
- }
162
- details
163
- .issue[issueName]
164
- .tools[which][canonicalRuleID]
165
- .complaints
166
- .countTotal += instance.count || 1;
167
- if (
168
- ! details
169
- .issue[issueName]
170
- .tools[which][canonicalRuleID]
171
- .complaints
172
- .texts
173
- .includes(instance.what)
174
- ) {
175
- details
176
- .issue[issueName]
177
- .tools[which][canonicalRuleID]
178
- .complaints
179
- .texts
180
- .push(instance.what);
181
- }
182
- }
183
- // Otherwise, i.e. if the rule ID belongs to no issue:
184
- else {
185
- // Add the instance to the solo details of the score data.
186
- if (! details.solo[which]) {
187
- details.solo[which] = {};
188
- }
189
- if (! details.solo[which][ruleID]) {
190
- details.solo[which][ruleID] = 0;
191
- }
192
- details.solo[which][ruleID] += (count || 1) * (ordinalSeverity + 1);
193
- // Report this.
194
- console.log(`ERROR: ${instance.ruleID} of ${which} not found in issues`);
195
- }
196
- });
197
- }
198
- // Otherwise, i.e. if a failed standard result exists:
199
- else {
200
- // Add an inferred prevention to the score.
201
- details.prevention[which] = preventionWeight;
202
- }
203
- });
204
- // For each issue with any complaints:
205
- Object.keys(details.issue).forEach(issueName => {
206
- const issueData = details.issue[issueName];
207
- // For each tool with any complaints for the issue:
208
- Object.keys(issueData.tools).forEach(toolID => {
209
- // Get the sum of the weighted counts of its issue rules.
210
- let weightedCount = 0;
211
- Object.values(issueData.tools[toolID]).forEach(ruleData => {
212
- weightedCount += ruleData.quality * ruleData.complaints.countTotal;
213
- });
214
- // If the sum exceeds the existing maximum weighted count for the issue:
215
- if (weightedCount > issueData.maxCount) {
216
- // Change the maximum count for the issue to the sum.
217
- issueData.maxCount = weightedCount;
218
- }
219
- });
220
- // Get the score for the issue.
221
- issueData.score = Math.round(issueData.weight * issueData.maxCount);
222
- });
223
- // Add the severity detail totals to the score.
224
- details.severity.total = Object.keys(details.severity.byTool).reduce((severityTotals, toolID) => {
225
- details.severity.byTool[toolID].forEach((severityScore, index) => {
226
- severityTotals[index] += severityScore;
227
- });
228
- return severityTotals;
229
- }, details.severity.total);
230
- // Add the summary issue total to the score.
231
- summary.issue = Object
232
- .values(details.issue)
233
- .reduce((total, current) => total + current.score, 0);
234
- // Add the summary solo total to the score.
235
- Object.keys(details.solo).forEach(tool => {
236
- summary.solo += Object
237
- .values(details.solo[tool])
238
- .reduce((total, current) => total + current);
239
- });
240
- // Add the summary tool total to the score.
241
- summary.tool = toolWeight * details.severity.total.reduce(
242
- (total, current, index) => total + severityWeights[index] * current, 0
243
- );
244
- // Add the summary prevention total to the score.
245
- summary.prevention = Object.values(details.prevention).reduce(
246
- (total, current) => total + current, 0
247
- );
248
- // Add the summary log score to the score.
249
- const {jobData} = report;
250
- if (jobData) {
251
- summary.log = Math.max(0, Math.round(
252
- logWeights.logCount * jobData.logCount
253
- + logWeights.logSize * jobData.logSize +
254
- + logWeights.errorLogCount * jobData.errorLogCount
255
- + logWeights.errorLogSize * jobData.errorLogSize
256
- + logWeights.prohibitedCount * jobData.prohibitedCount +
257
- + logWeights.visitRejectionCount * jobData.visitRejectionCount
258
- ));
259
- // Add the summary latency score to the score.
260
- summary.latency = Math.round(
261
- latencyWeight * (Math.max(0, jobData.visitLatency - normalLatency))
262
- );
263
- }
264
- // Round the unrounded scores.
265
- Object.keys(summary).forEach(summaryTypeName => {
266
- summary[summaryTypeName] = Math.round(summary[summaryTypeName]);
267
- });
268
- details.severity.total.forEach((severityTotal, index) => {
269
- details.severity.total[index] = Math.round(severityTotal);
270
- });
271
- // Add the summary total score to the score.
272
- summary.total = summary.issue
273
- + summary.solo
274
- + summary.tool
275
- + summary.prevention
276
- + summary.log
277
- + summary.latency;
278
- // Add the score to the report.
279
- report.score = score;
280
- }
281
- // Otherwise, i.e. if none of them is a test act:
282
- else {
283
- // Report this.
284
- console.log('ERROR: No test acts');
285
- }
286
- }
287
- // Otherwise, i.e. if there are no acts in the report:
288
- else {
289
- // Report this.
290
- console.log('ERROR: No acts');
291
- }
292
- };
File without changes