@jrpool/kilotest 46.0.4 → 46.0.5
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/api/requestRetest.js +4 -8
- package/index.js +0 -3
- package/package.json +1 -1
- package/test/fixtures/buildFixtures.js +1 -1
- package/util.js +21 -72
- package/util.test.js +2 -4
- package/web/expungeReportsForm/index.js +1 -3
- package/web/hideReportForm/index.js +1 -3
- package/web/pruneReportsForm/index.js +1 -3
- package/web/unhideReportForm/index.js +1 -3
package/api/requestRetest.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// IMPORTS
|
|
7
7
|
|
|
8
8
|
const {getResponseMetadata, getToolsFacts, processTestRequest, thisHost} = require('./util');
|
|
9
|
-
const {getLatestReportExtracts,
|
|
9
|
+
const {getLatestReportExtracts, getReportExtract} = require('../util');
|
|
10
10
|
|
|
11
11
|
// FUNCTIONS
|
|
12
12
|
|
|
@@ -19,15 +19,11 @@ exports.response = async args => {
|
|
|
19
19
|
'disposition of your request': null
|
|
20
20
|
};
|
|
21
21
|
const reasonLength = reason.length;
|
|
22
|
-
// Get data on the available reports.
|
|
23
|
-
const reportsExtract = await getReportsExtract();
|
|
24
22
|
// Get data on the report.
|
|
25
|
-
const reportExtract =
|
|
26
|
-
.
|
|
27
|
-
.find(extract => extract.timeStamp === timeStamp && extract.jobID === jobID);
|
|
28
|
-
const {what, url} = reportExtract || {};
|
|
23
|
+
const reportExtract = await getReportExtract(timeStamp, jobID);
|
|
24
|
+
const {what, url} = reportExtract.error ? {} : reportExtract;
|
|
29
25
|
// If this failed:
|
|
30
|
-
if (
|
|
26
|
+
if (reportExtract.error) {
|
|
31
27
|
// Add this to the response content.
|
|
32
28
|
responseContent['details about your request'] = {
|
|
33
29
|
error: 'request invalid: the specified existing report is not an available report'
|
package/index.js
CHANGED
|
@@ -24,7 +24,6 @@ const {
|
|
|
24
24
|
isTimeStamp,
|
|
25
25
|
isJobID,
|
|
26
26
|
jobsPath,
|
|
27
|
-
makeReportsExtract,
|
|
28
27
|
recsLock,
|
|
29
28
|
reportsPath
|
|
30
29
|
} = require('./util');
|
|
@@ -747,8 +746,6 @@ const requestHandler = async (request, response) => {
|
|
|
747
746
|
report.sources = {...report.sources, worker: workerName};
|
|
748
747
|
// Save the report.
|
|
749
748
|
await fs.writeFile(getReportPath(timeStamp, jobID), getJSON(report));
|
|
750
|
-
// Update the data on the available reports.
|
|
751
|
-
await makeReportsExtract();
|
|
752
749
|
// Annotate the report.
|
|
753
750
|
await annotateReport(timeStamp, jobID);
|
|
754
751
|
console.log(`Testaro report ${id} was annotated, saved, and indexed`);
|
package/package.json
CHANGED
|
@@ -216,7 +216,7 @@ const main = async () => {
|
|
|
216
216
|
preventedReport
|
|
217
217
|
);
|
|
218
218
|
|
|
219
|
-
// Fixture 7: hidden. A report placed in hiddenReports/ instead of reports/, so it must not appear in listReports, listIssues, listViolators, listDiagnoses, or getReport API responses.
|
|
219
|
+
// Fixture 7: hidden. A report placed in hiddenReports/ instead of reports/, so it must not appear in listReports, listIssues, listViolators, listDiagnoses, or getReport API responses.
|
|
220
220
|
const hiddenCatalog = {
|
|
221
221
|
'0': catalogItem('A', 'Secret link', '/html/body/a[1]', '5:10:60:20')
|
|
222
222
|
};
|
package/util.js
CHANGED
|
@@ -24,8 +24,6 @@ const recsPath = exports.recsPath = () => path.join(jobsPath(), 'recs.json');
|
|
|
24
24
|
const reportsPath = exports.reportsPath = () => path.join(dbPath(), 'reports');
|
|
25
25
|
// Path of the hidden-reports directory.
|
|
26
26
|
const hiddenReportsPath = exports.hiddenReportsPath = () => path.join(dbPath(), 'hiddenReports');
|
|
27
|
-
// Path of the reports data file.
|
|
28
|
-
const reportsExtractPath = exports.reportsExtractPath = () => path.join(dbPath(), 'reportsExtract.json');
|
|
29
27
|
// IDs, names, and sponsors of Testaro rule engines.
|
|
30
28
|
const ruleEngines = exports.ruleEngines = {
|
|
31
29
|
alfa: ['Alfa', 'Siteimprove'],
|
|
@@ -662,68 +660,43 @@ exports.isHidden = async (timeStamp, jobID) => {
|
|
|
662
660
|
// Return whether the report is among them.
|
|
663
661
|
return hiddenReportFileNames.includes(`${timeStamp}-${jobID}.json`);
|
|
664
662
|
};
|
|
665
|
-
//
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
// For each of them:
|
|
672
|
-
for (const reportFileName of reportFileNames) {
|
|
673
|
-
// Get its content.
|
|
674
|
-
const reportJSON = await fs.readFile(path.join(reportsPath(), reportFileName), 'utf8');
|
|
675
|
-
// Get the object that it represents.
|
|
663
|
+
// Returns an extract of an available report, or an error object if it cannot be read or parsed.
|
|
664
|
+
const getReportExtract = exports.getReportExtract = async (timeStamp, jobID) => {
|
|
665
|
+
try {
|
|
666
|
+
const reportJSON = await fs.readFile(
|
|
667
|
+
path.join(reportsPath(), `${timeStamp}-${jobID}.json`), 'utf8'
|
|
668
|
+
);
|
|
676
669
|
const report = JSON.parse(reportJSON);
|
|
677
670
|
const {target, jobData} = report;
|
|
678
|
-
const jobName = reportFileName.slice(0, -5);
|
|
679
|
-
const [timeStamp, jobID] = jobName.split('-');
|
|
680
671
|
const {what, url} = target;
|
|
681
|
-
|
|
682
|
-
const reportExtract = {
|
|
672
|
+
return {
|
|
683
673
|
timeStamp,
|
|
684
674
|
jobID,
|
|
685
675
|
what,
|
|
686
676
|
url,
|
|
687
677
|
reportTime: new Date(`20${jobData.endTime}Z`).toISOString()
|
|
688
678
|
};
|
|
689
|
-
// Add the report extract to the reports extract.
|
|
690
|
-
reportsExtract[jobName] = reportExtract;
|
|
691
|
-
}
|
|
692
|
-
// Ensure the data directory exists.
|
|
693
|
-
await fs.mkdir(dbPath(), {recursive: true});
|
|
694
|
-
// Save the extract of the reports.
|
|
695
|
-
await fs.writeFile(reportsExtractPath(), getJSON(reportsExtract));
|
|
696
|
-
// Return it.
|
|
697
|
-
return reportsExtract;
|
|
698
|
-
};
|
|
699
|
-
// Gets an extract of all available reports.
|
|
700
|
-
const getReportsExtract = exports.getReportsExtract = async () => {
|
|
701
|
-
let reportsExtract;
|
|
702
|
-
try {
|
|
703
|
-
// Get the reports extract file.
|
|
704
|
-
const reportsExtractJSON = await fs.readFile(reportsExtractPath(), 'utf8');
|
|
705
|
-
// Get its data.
|
|
706
|
-
reportsExtract = JSON.parse(reportsExtractJSON);
|
|
707
|
-
// If it is empty:
|
|
708
|
-
if (!Object.keys(reportsExtract).length) {
|
|
709
|
-
// Throw an error.
|
|
710
|
-
throw new Error('Reports extract file is empty');
|
|
711
|
-
}
|
|
712
679
|
}
|
|
713
|
-
// If this fails:
|
|
714
680
|
catch {
|
|
715
|
-
|
|
716
|
-
|
|
681
|
+
return {
|
|
682
|
+
error: `No report ${timeStamp}-${jobID} is available`
|
|
683
|
+
};
|
|
717
684
|
}
|
|
718
|
-
// Return the extract.
|
|
719
|
-
return reportsExtract;
|
|
720
685
|
};
|
|
721
686
|
// Returns extracts of all available reports.
|
|
722
687
|
const getReportExtracts = exports.getReportExtracts = async () => {
|
|
723
|
-
const
|
|
724
|
-
|
|
688
|
+
const reportFileNames = await fs.readdir(reportsPath());
|
|
689
|
+
const extracts = [];
|
|
690
|
+
for (const reportFileName of reportFileNames) {
|
|
691
|
+
const [timeStamp, jobID] = reportFileName.slice(0, -5).split('-');
|
|
692
|
+
const extract = await getReportExtract(timeStamp, jobID);
|
|
693
|
+
if (!extract.error) {
|
|
694
|
+
extracts.push(extract);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return extracts;
|
|
725
698
|
};
|
|
726
|
-
// Returns whether a report
|
|
699
|
+
// Returns whether a report with a description or URL is available.
|
|
727
700
|
exports.isReportAvailable = async (what, url) => {
|
|
728
701
|
const reportExtracts = await getReportExtracts();
|
|
729
702
|
const whats = reportExtracts.map(reportExtract => reportExtract.what);
|
|
@@ -732,43 +705,19 @@ exports.isReportAvailable = async (what, url) => {
|
|
|
732
705
|
};
|
|
733
706
|
// Gets extracts of the latest available reports for all page descriptions.
|
|
734
707
|
exports.getLatestReportExtracts = async () => {
|
|
735
|
-
// Get extracts of all available reports.
|
|
736
708
|
const reportExtracts = await getReportExtracts();
|
|
737
|
-
// Sort them primarily by page description and secondarily by completion time.
|
|
738
709
|
objectSort(reportExtracts, 'reportTime', 'alpha');
|
|
739
710
|
objectSort(reportExtracts, 'what', 'alpha');
|
|
740
|
-
// Get the latest ones for all page descriptions.
|
|
741
711
|
const latestReportExtracts = reportExtracts
|
|
742
712
|
.filter((extract, index) => extract.what !== reportExtracts[index + 1]?.what);
|
|
743
|
-
// Return them.
|
|
744
713
|
return latestReportExtracts;
|
|
745
714
|
};
|
|
746
|
-
// Returns an extract of an available report.
|
|
747
|
-
exports.getReportExtract = async (timeStamp, jobID) => {
|
|
748
|
-
// Get the extract of all available reports.
|
|
749
|
-
const reportsExtract = await getReportsExtract();
|
|
750
|
-
// Get the extract of the report from it.
|
|
751
|
-
const reportExtract = reportsExtract[`${timeStamp}-${jobID}`];
|
|
752
|
-
// If it exists:
|
|
753
|
-
if (reportExtract) {
|
|
754
|
-
// Return it.
|
|
755
|
-
return reportExtract;
|
|
756
|
-
}
|
|
757
|
-
// Otherwise, i.e. if it does not exist, return this.
|
|
758
|
-
return {
|
|
759
|
-
error: `No report ${timeStamp}-${jobID} is available`
|
|
760
|
-
};
|
|
761
|
-
};
|
|
762
715
|
// Gets the descriptions of multi-report pages.
|
|
763
716
|
exports.getMultiReportWhats = async () => {
|
|
764
|
-
// Get extracts of all available reports.
|
|
765
717
|
const reportExtracts = await getReportExtracts();
|
|
766
|
-
// Get their sorted page descriptions.
|
|
767
718
|
const sortedWhats = reportExtracts.map(extract => extract.what).sort();
|
|
768
|
-
// Get those that at least 2 reports have.
|
|
769
719
|
const multiReportWhats = sortedWhats.filter(
|
|
770
720
|
(what, index) => what !== sortedWhats[index - 1] && what === sortedWhats[index + 1]
|
|
771
721
|
);
|
|
772
|
-
// Return an array of descriptions of multi-report pages.
|
|
773
722
|
return multiReportWhats;
|
|
774
723
|
};
|
package/util.test.js
CHANGED
|
@@ -13,8 +13,7 @@ const {
|
|
|
13
13
|
jobsPath,
|
|
14
14
|
recsPath,
|
|
15
15
|
reportsPath,
|
|
16
|
-
hiddenReportsPath
|
|
17
|
-
reportsExtractPath
|
|
16
|
+
hiddenReportsPath
|
|
18
17
|
} = require('./util');
|
|
19
18
|
|
|
20
19
|
// TESTS
|
|
@@ -48,7 +47,7 @@ test('dbPath honors DB_DIR when it is set', () => {
|
|
|
48
47
|
}
|
|
49
48
|
});
|
|
50
49
|
|
|
51
|
-
test('jobsPath, recsPath, reportsPath,
|
|
50
|
+
test('jobsPath, recsPath, reportsPath, and hiddenReportsPath derive from DB_DIR', () => {
|
|
52
51
|
const saved = process.env.DB_DIR;
|
|
53
52
|
process.env.DB_DIR = '/tmp/kilotest-fixtures';
|
|
54
53
|
try {
|
|
@@ -56,7 +55,6 @@ test('jobsPath, recsPath, reportsPath, hiddenReportsPath, and reportsExtractPath
|
|
|
56
55
|
assert.equal(recsPath(), path.join('/tmp/kilotest-fixtures', 'jobs', 'recs.json'));
|
|
57
56
|
assert.equal(reportsPath(), path.join('/tmp/kilotest-fixtures', 'reports'));
|
|
58
57
|
assert.equal(hiddenReportsPath(), path.join('/tmp/kilotest-fixtures', 'hiddenReports'));
|
|
59
|
-
assert.equal(reportsExtractPath(), path.join('/tmp/kilotest-fixtures', 'reportsExtract.json'));
|
|
60
58
|
}
|
|
61
59
|
finally {
|
|
62
60
|
if (saved !== undefined) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
// IMPORTS
|
|
7
7
|
|
|
8
|
-
const {getReportData,
|
|
8
|
+
const {getReportData, objectSort, reportsPath} = require('../../util');
|
|
9
9
|
const fs = require('fs/promises');
|
|
10
10
|
const path = require('path');
|
|
11
11
|
|
|
@@ -26,8 +26,6 @@ exports.answer = async (_, search) => {
|
|
|
26
26
|
// Delete it.
|
|
27
27
|
await fs.unlink(path.join(reportsPath(), `${jobName}.json`));
|
|
28
28
|
}
|
|
29
|
-
// Update the extract of the available reports.
|
|
30
|
-
await makeReportsExtract();
|
|
31
29
|
}
|
|
32
30
|
// If this failed:
|
|
33
31
|
catch (error) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
// IMPORTS
|
|
7
7
|
|
|
8
|
-
const {getReportExtracts, hiddenReportsPath,
|
|
8
|
+
const {getReportExtracts, hiddenReportsPath, reportsPath} = require('../../util');
|
|
9
9
|
const fs = require('fs/promises');
|
|
10
10
|
const path = require('path');
|
|
11
11
|
|
|
@@ -24,8 +24,6 @@ exports.answer = async (_, search) => {
|
|
|
24
24
|
try {
|
|
25
25
|
// Move the specified report to the directory of hidden reports.
|
|
26
26
|
await fs.rename(path.join(reportsPath(), fileName), path.join(hiddenReportsPath(), fileName));
|
|
27
|
-
// Update the data on the available reports.
|
|
28
|
-
await makeReportsExtract();
|
|
29
27
|
}
|
|
30
28
|
// If this failed:
|
|
31
29
|
catch (error) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
// IMPORTS
|
|
7
7
|
|
|
8
|
-
const {getReportData,
|
|
8
|
+
const {getReportData, reportsPath} = require('../../util');
|
|
9
9
|
const fs = require('fs/promises');
|
|
10
10
|
const path = require('path');
|
|
11
11
|
|
|
@@ -26,8 +26,6 @@ exports.answer = async (_, search) => {
|
|
|
26
26
|
// Delete it.
|
|
27
27
|
await fs.unlink(path.join(reportsPath(), `${jobName}.json`));
|
|
28
28
|
}
|
|
29
|
-
// Update the extract of the available reports.
|
|
30
|
-
await makeReportsExtract();
|
|
31
29
|
}
|
|
32
30
|
// If this failed:
|
|
33
31
|
catch (error) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
// IMPORTS
|
|
7
7
|
|
|
8
|
-
const {hiddenReportsPath,
|
|
8
|
+
const {hiddenReportsPath, reportsPath} = require('../../util');
|
|
9
9
|
const fs = require('fs/promises');
|
|
10
10
|
const path = require('path');
|
|
11
11
|
|
|
@@ -24,8 +24,6 @@ exports.answer = async (_, search) => {
|
|
|
24
24
|
try {
|
|
25
25
|
// Move the report to the reports directory.
|
|
26
26
|
await fs.rename(path.join(hiddenReportsPath(), fileName), path.join(reportsPath(), fileName));
|
|
27
|
-
// Update the data on the available reports.
|
|
28
|
-
await makeReportsExtract();
|
|
29
27
|
}
|
|
30
28
|
catch (error) {
|
|
31
29
|
// Return why.
|