-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathbrowser-specific-failures.js
More file actions
181 lines (162 loc) · 6.27 KB
/
browser-specific-failures.js
File metadata and controls
181 lines (162 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
'use strict';
/**
* Implements a view of how many browser specific failures each engine has over
* time.
*/
const fs = require('fs');
const flags = require('flags');
const Git = require('nodegit');
const lib = require('./lib');
const moment = require('moment');
flags.defineString('from', '2018-07-01', 'Starting date (inclusive)');
flags.defineString('to', moment().format('YYYY-MM-DD'),
'Ending date (exclusive)');
flags.defineStringList('products', ['chrome', 'firefox', 'safari'],
'Browsers to compare. Must match the products used on wpt.fyi');
flags.defineString('output', null,
'Output CSV file to write to. Defaults to ' +
'{stable, experimental}-browser-specific-failures.csv');
flags.defineBoolean('experimental', false,
'Calculate metrics for experimental runs.');
flags.parse();
// WPT result paths to exclude from browser-specific-failure scoring.
// /third_party/test262/ introduces Temporal tests as individual tests
// instead of using the subtest WPT convention. These test failtures
// misrepresent the overal interoperability of the web by causing the
// single browser failure graph to be completely dominated by a feature
// not yet shipped by all browsers.
const EXCLUDED_PATHS = ['/third_party/test262'];
// Returns a copy of |tree| with any subtrees whose path appears in
// |excludedPaths| removed. Subtrees not on a path to an excluded entry are
// shared by reference (no deep copy), so the operation is cheap.
function pruneExcludedPaths(tree, excludedPaths, currentPath = '') {
const relevant = excludedPaths.filter(p =>
p.startsWith(currentPath + '/'));
if (relevant.length === 0) {
return tree;
}
const newTrees = {};
for (const [name, child] of Object.entries(tree.trees)) {
const childPath = `${currentPath}/${name}`;
if (relevant.includes(childPath)) {
continue;
}
newTrees[name] = relevant.some(p => p.startsWith(childPath + '/')) ?
pruneExcludedPaths(child, relevant, childPath) :
child;
}
return {...tree, trees: newTrees};
}
async function main() {
// Sort the products so that output files are consistent.
const products = flags.get('products');
if (products.length < 2) {
throw new Error('At least 2 products must be specified for this analysis');
}
products.sort();
const repo = await Git.Repository.open('results-analysis-cache.git');
// First, grab aligned runs from the server for the dates that we are
// interested in.
const from = moment(flags.get('from'));
const to = moment(flags.get('to'));
const experimental = flags.get('experimental');
const alignedRuns = await lib.runs.fetchAlignedRunsFromServer(
products, from, to, experimental);
// Verify that we have data for the fetched runs in the results-analysis-cache
// repo.
console.log('Getting local set of run ids from repo');
let before = Date.now();
const localRunIds = await lib.results.getLocalRunIds(repo);
let after = Date.now();
console.log(`Found ${localRunIds.size} ids (took ${after - before} ms)`);
let hadErrors = false;
for (const [date, runs] of alignedRuns.entries()) {
for (const run of runs) {
if (!localRunIds.has(run.id)) {
// If you see this, you probably need to run git-write.js or just update
// your results-analysis-cache.git repo; see the README.md.
console.error(`Run ${run.id} missing from local git repo (${date})`);
hadErrors = true;
}
}
}
if (hadErrors) {
throw new Error('Missing data for some runs (see errors logged above). ' +
'Try running "git fetch --all --tags" in results-analysis-cache/');
}
// Load the test result trees into memory; creates a list of recursive tree
// structures: tree = { trees: [...], tests: [...] }. Each 'tree' represents a
// directory, each 'test' is the results from a given test file.
console.log('Iterating over all runs, loading test results');
before = Date.now();
for (const runs of alignedRuns.values()) {
for (const run of runs) {
// Just in case someone ever adds a 'tree' field to the JSON.
if (run.tree) {
throw new Error('Run JSON contains "tree" field; code needs changed.');
}
run.tree = await lib.results.getGitTree(repo, run);
run.tree = pruneExcludedPaths(run.tree, EXCLUDED_PATHS);
}
}
after = Date.now();
console.log(`Loading ${alignedRuns.size} sets of runs took ` +
`${after - before} ms`);
// We're ready to score the runs now!
console.log('Calculating browser-specific failures for the runs');
before = Date.now();
const dateToScores = new Map();
for (const [date, runs] of alignedRuns.entries()) {
// The SHA should be the same for all runs, so just grab the first.
const sha = runs[0].full_revision_hash;
const versions = runs.map(run => run.browser_version);
try {
const scores = lib.browserSpecific.scoreBrowserSpecificFailures(
runs, new Set(products));
dateToScores.set(date, {sha, versions, scores});
} catch (e) {
e.message += `\n\tRuns: ${runs.map(r => r.id)}`;
throw e;
}
}
after = Date.now();
console.log(`Done scoring (took ${after - before} ms)`);
// Finally, time to dump stuff.
let outputFilename = flags.get('output');
if (!outputFilename) {
outputFilename = experimental ?
'experimental-browser-specific-failures.csv' :
'stable-browser-specific-failures.csv';
}
console.log(`Writing data to ${outputFilename}`);
let data = 'sha,date';
for (const product of products) {
data += `,${product}-version,${product}`;
}
data += '\n';
// ES6 maps iterate in insertion order, and we initially inserted in date
// order, so we can just iterate |dateToScores|.
for (const [date, shaAndScores] of dateToScores) {
const sha = shaAndScores.sha;
const scores = shaAndScores.scores;
const versions = shaAndScores.versions;
if (!scores) {
console.log(`ERROR: ${date} had no scores`);
continue;
}
const csvRecord = [
sha,
date.substr(0, 10),
];
for (let i = 0; i < products.length; i++) {
csvRecord.push(versions[i]);
csvRecord.push(scores.get(products[i]));
}
data += csvRecord.join(',') + '\n';
}
await fs.promises.writeFile(outputFilename, data, 'utf-8');
}
main().catch(reason => {
console.error(reason);
process.exit(1);
});