@piwitests/reporter 0.67.0 → 0.68.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/dist/cli/index.js +448 -295
- package/dist/global-setup-module.js +297 -72
- package/dist/index.d.ts +33 -2
- package/dist/index.js +4715 -2376
- package/dist/internal/capture/attachments.d.ts +1 -0
- package/dist/internal/capture/attachments.js +2 -1
- package/dist/internal/capture/capture-fixtures.d.ts +100 -11
- package/dist/internal/capture/capture-fixtures.js +3295 -2303
- package/package.json +1 -1
|
@@ -41,7 +41,7 @@ function errorMessage(error) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// src/internal/config/env.ts
|
|
44
|
-
var
|
|
44
|
+
var path3 = __toESM(require("path"));
|
|
45
45
|
|
|
46
46
|
// src/internal/config/desktop.ts
|
|
47
47
|
var fs = __toESM(require("fs"));
|
|
@@ -59,14 +59,23 @@ function processAlive(pid) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
function readDesktopConfig(filePath) {
|
|
62
|
+
const file = readDesktopFile(filePath);
|
|
63
|
+
if (!file) return null;
|
|
64
|
+
if (file.pid !== null && !processAlive(file.pid)) return null;
|
|
65
|
+
return { url: file.url, token: file.token };
|
|
66
|
+
}
|
|
67
|
+
function readDesktopToken(filePath) {
|
|
68
|
+
return readDesktopFile(filePath)?.token ?? null;
|
|
69
|
+
}
|
|
70
|
+
function readDesktopFile(filePath) {
|
|
62
71
|
try {
|
|
63
72
|
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
64
73
|
const url = parsed?.url;
|
|
65
74
|
const token = parsed?.token;
|
|
66
75
|
if (typeof url !== "string" || !url) return null;
|
|
67
76
|
if (typeof token !== "string" || !token) return null;
|
|
68
|
-
|
|
69
|
-
return { url, token };
|
|
77
|
+
const pid = Number.isInteger(parsed?.pid) && parsed.pid > 0 ? parsed.pid : null;
|
|
78
|
+
return { url, token, pid };
|
|
70
79
|
} catch {
|
|
71
80
|
return null;
|
|
72
81
|
}
|
|
@@ -134,6 +143,118 @@ function resolveRunLabel(configured, sharded) {
|
|
|
134
143
|
return !sharded && ci.job ? `${ci.run}|${ci.job}` : ci.run;
|
|
135
144
|
}
|
|
136
145
|
|
|
146
|
+
// ../core/src/run-request.ts
|
|
147
|
+
var RUN_REQUEST_LIMITS = {
|
|
148
|
+
tests: { min: 1, max: 200 },
|
|
149
|
+
repeatEach: { min: 1, max: 10 },
|
|
150
|
+
workers: { min: 1, max: 4 },
|
|
151
|
+
/** How long a request waits for a target to claim it, in milliseconds. */
|
|
152
|
+
lifetimeMs: 2 * 60 * 1e3,
|
|
153
|
+
/**
|
|
154
|
+
* How often a target that holds a request calls the instance at least, in milliseconds: it hears its stops from the
|
|
155
|
+
* list of requests. Past this silence the instance ends the request as an error.
|
|
156
|
+
*/
|
|
157
|
+
silentTargetMs: 5 * 60 * 1e3,
|
|
158
|
+
/** How long a stop waits for the target to end a run, in milliseconds, before a second stop ends the request. */
|
|
159
|
+
stopGraceMs: 60 * 1e3
|
|
160
|
+
};
|
|
161
|
+
var REQUEST_TOKEN_PREFIX = "pdq_";
|
|
162
|
+
var REQUEST_TOKEN = /^pdq_[0-9a-f]{64}$/;
|
|
163
|
+
var REQUEST_RUN_ENV = {
|
|
164
|
+
tokenFile: "PIWI_REQUEST_TOKEN_FILE",
|
|
165
|
+
instance: "PIWI_REQUEST_INSTANCE"
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/internal/support/private-file.ts
|
|
169
|
+
var crypto2 = __toESM(require("crypto"));
|
|
170
|
+
var fs3 = __toESM(require("fs"));
|
|
171
|
+
var os2 = __toESM(require("os"));
|
|
172
|
+
var path2 = __toESM(require("path"));
|
|
173
|
+
function privateTempDir() {
|
|
174
|
+
if (process.platform !== "win32") return os2.tmpdir();
|
|
175
|
+
const dir = path2.join(process.env.LOCALAPPDATA || path2.join(os2.homedir(), "AppData", "Local"), "piwi", "tmp");
|
|
176
|
+
try {
|
|
177
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
return dir;
|
|
181
|
+
}
|
|
182
|
+
var NO_FOLLOW = fs3.constants.O_NOFOLLOW ?? 0;
|
|
183
|
+
var NO_WAIT = fs3.constants.O_NONBLOCK ?? 0;
|
|
184
|
+
function untrustedReason(stat) {
|
|
185
|
+
if (stat.isSymbolicLink()) return "it is a symbolic link";
|
|
186
|
+
if (!stat.isFile()) return "it is not a regular file";
|
|
187
|
+
if (typeof process.getuid === "function") {
|
|
188
|
+
if (stat.uid !== process.getuid()) return "another user owns it";
|
|
189
|
+
if (stat.mode & 18) return "other users may write to it";
|
|
190
|
+
if (stat.nlink > 1) return "it has another name";
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
function writePrivateFile(file, text) {
|
|
195
|
+
const temp = `${file}.${process.pid}.${crypto2.randomBytes(6).toString("hex")}.tmp`;
|
|
196
|
+
try {
|
|
197
|
+
fs3.writeFileSync(temp, text, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
198
|
+
fs3.renameSync(temp, file);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
fs3.rmSync(temp, { force: true });
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function readPrivateFile(file) {
|
|
205
|
+
const found = fs3.lstatSync(file, { throwIfNoEntry: false });
|
|
206
|
+
if (!found) return null;
|
|
207
|
+
const reason = untrustedReason(found);
|
|
208
|
+
if (reason) return { untrusted: reason };
|
|
209
|
+
const fd = fs3.openSync(file, fs3.constants.O_RDONLY | NO_FOLLOW | NO_WAIT);
|
|
210
|
+
try {
|
|
211
|
+
const stat = fs3.fstatSync(fd);
|
|
212
|
+
const opened = untrustedReason(stat);
|
|
213
|
+
if (opened) return { untrusted: opened };
|
|
214
|
+
return { text: fs3.readFileSync(fd, "utf8"), mode: stat.mode };
|
|
215
|
+
} finally {
|
|
216
|
+
fs3.closeSync(fd);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/internal/config/requested-run.ts
|
|
221
|
+
function readRequestedRun(env) {
|
|
222
|
+
const file = env[REQUEST_RUN_ENV.tokenFile];
|
|
223
|
+
const instance = env[REQUEST_RUN_ENV.instance];
|
|
224
|
+
if (!file && !instance) return null;
|
|
225
|
+
if (!file || !instance) {
|
|
226
|
+
return { problem: `${REQUEST_RUN_ENV.tokenFile} and ${REQUEST_RUN_ENV.instance} are set together, or not at all.` };
|
|
227
|
+
}
|
|
228
|
+
let url;
|
|
229
|
+
try {
|
|
230
|
+
url = new URL(instance);
|
|
231
|
+
} catch {
|
|
232
|
+
return { problem: `${REQUEST_RUN_ENV.instance} is not a URL.` };
|
|
233
|
+
}
|
|
234
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
235
|
+
return { problem: `${REQUEST_RUN_ENV.instance} is not an http or https URL.` };
|
|
236
|
+
}
|
|
237
|
+
let read;
|
|
238
|
+
try {
|
|
239
|
+
read = readPrivateFile(file);
|
|
240
|
+
} catch {
|
|
241
|
+
read = null;
|
|
242
|
+
}
|
|
243
|
+
if (!read) return { problem: `The request token file in ${REQUEST_RUN_ENV.tokenFile} cannot be read.` };
|
|
244
|
+
if ("untrusted" in read || readableByOthers(read.mode)) {
|
|
245
|
+
return { problem: `The request token file in ${REQUEST_RUN_ENV.tokenFile} is not this user's alone.` };
|
|
246
|
+
}
|
|
247
|
+
const token = read.text.trim();
|
|
248
|
+
if (!REQUEST_TOKEN.test(token)) {
|
|
249
|
+
return { problem: `The file in ${REQUEST_RUN_ENV.tokenFile} holds no request token.` };
|
|
250
|
+
}
|
|
251
|
+
return { instance: `${url.origin}${url.pathname.replace(/\/+$/, "")}`, token };
|
|
252
|
+
}
|
|
253
|
+
function readableByOthers(mode) {
|
|
254
|
+
if (typeof process.getuid !== "function") return false;
|
|
255
|
+
return (mode & 36) !== 0;
|
|
256
|
+
}
|
|
257
|
+
|
|
137
258
|
// src/internal/config/env.ts
|
|
138
259
|
var DEFAULTS = {
|
|
139
260
|
projectName: "default-project",
|
|
@@ -142,6 +263,7 @@ var DEFAULTS = {
|
|
|
142
263
|
liveFileUploads: true,
|
|
143
264
|
collectScmInfo: true,
|
|
144
265
|
collectCiInfo: true,
|
|
266
|
+
collectEnvironmentInfo: true,
|
|
145
267
|
collectPerformanceMetrics: true,
|
|
146
268
|
captureLocators: true,
|
|
147
269
|
capturePageState: true,
|
|
@@ -171,6 +293,7 @@ var DEFAULTS = {
|
|
|
171
293
|
var PIWI_ENV_KEYS = {
|
|
172
294
|
serverUrl: "PIWI_DASHBOARD_URL",
|
|
173
295
|
desktopApp: "PIWI_DESKTOP_APP",
|
|
296
|
+
desktopKey: "PIWI_DESKTOP_KEY",
|
|
174
297
|
projectName: "PIWI_PROJECT_NAME",
|
|
175
298
|
verbose: "PIWI_VERBOSE",
|
|
176
299
|
apiKey: "PIWI_API_KEY",
|
|
@@ -189,6 +312,7 @@ var PIWI_ENV_KEYS = {
|
|
|
189
312
|
failOnFlakyTests: "PIWI_FAIL_ON_FLAKY_TESTS",
|
|
190
313
|
uploadTraces: "PIWI_UPLOAD_TRACES",
|
|
191
314
|
uploadReport: "PIWI_UPLOAD_REPORT",
|
|
315
|
+
collectEnvironmentInfo: "PIWI_COLLECT_ENVIRONMENT_INFO",
|
|
192
316
|
captureLocators: "PIWI_CAPTURE_LOCATORS",
|
|
193
317
|
capturePageState: "PIWI_CAPTURE_PAGE_STATE",
|
|
194
318
|
capturePageInventory: "PIWI_CAPTURE_PAGE_INVENTORY",
|
|
@@ -249,6 +373,7 @@ var ENV_FALLBACK_SPECS = [
|
|
|
249
373
|
{ option: "failOnFlakyTests", env: PIWI_ENV_KEYS.failOnFlakyTests, kind: "bool" },
|
|
250
374
|
{ option: "uploadTraces", env: PIWI_ENV_KEYS.uploadTraces, kind: "bool" },
|
|
251
375
|
{ option: "uploadReport", env: PIWI_ENV_KEYS.uploadReport, kind: "bool" },
|
|
376
|
+
{ option: "collectEnvironmentInfo", env: PIWI_ENV_KEYS.collectEnvironmentInfo, kind: "bool" },
|
|
252
377
|
{ option: "captureLocators", env: PIWI_ENV_KEYS.captureLocators, kind: "bool" },
|
|
253
378
|
{ option: "capturePageState", env: PIWI_ENV_KEYS.capturePageState, kind: "bool" },
|
|
254
379
|
{ option: "capturePageInventory", env: PIWI_ENV_KEYS.capturePageInventory, kind: "bool" },
|
|
@@ -273,9 +398,15 @@ function desktopAppMode(option, envValue) {
|
|
|
273
398
|
return "fallback";
|
|
274
399
|
}
|
|
275
400
|
var desktopDiscovered = false;
|
|
401
|
+
var desktopTokenHeld = false;
|
|
402
|
+
var requestedRunInstance = null;
|
|
403
|
+
var requestedRunError = null;
|
|
276
404
|
var desktopReplacedServerUrl = null;
|
|
277
405
|
var dotEnvUse = null;
|
|
278
406
|
var ignoredEnv = [];
|
|
407
|
+
function usedDesktopToken() {
|
|
408
|
+
return desktopTokenHeld;
|
|
409
|
+
}
|
|
279
410
|
function resolveOptions(raw, configDir) {
|
|
280
411
|
const env = process.env;
|
|
281
412
|
const mergedRaw = { ...raw };
|
|
@@ -295,7 +426,7 @@ function resolveOptions(raw, configDir) {
|
|
|
295
426
|
}
|
|
296
427
|
dotEnvUse = null;
|
|
297
428
|
if (configDir) {
|
|
298
|
-
const file =
|
|
429
|
+
const file = path3.join(configDir, ".env");
|
|
299
430
|
const dotEnv = readDotEnv(file);
|
|
300
431
|
const keys = [];
|
|
301
432
|
for (const option of DOTENV_OPTIONS) {
|
|
@@ -307,8 +438,12 @@ function resolveOptions(raw, configDir) {
|
|
|
307
438
|
if (keys.length > 0) dotEnvUse = { file, keys };
|
|
308
439
|
}
|
|
309
440
|
desktopDiscovered = false;
|
|
441
|
+
desktopTokenHeld = false;
|
|
310
442
|
desktopReplacedServerUrl = null;
|
|
311
|
-
const
|
|
443
|
+
const requested = readRequestedRun(env);
|
|
444
|
+
requestedRunInstance = requested && "instance" in requested ? requested.instance : null;
|
|
445
|
+
requestedRunError = requested && "problem" in requested ? requested.problem : null;
|
|
446
|
+
const mode = requested ? "off" : desktopAppMode(mergedRaw.desktopApp, env[PIWI_ENV_KEYS.desktopApp]);
|
|
312
447
|
mergedRaw.desktopApp = mode;
|
|
313
448
|
const serverUrlUnset = mergedRaw.serverUrl === void 0;
|
|
314
449
|
const apiKeyUnset = mergedRaw.apiKey === void 0 || mergedRaw.apiKey === null;
|
|
@@ -325,6 +460,7 @@ function resolveOptions(raw, configDir) {
|
|
|
325
460
|
desktopDiscovered = true;
|
|
326
461
|
}
|
|
327
462
|
}
|
|
463
|
+
desktopTokenHeld = desktopDiscovered || env[PIWI_ENV_KEYS.desktopKey] === "1" && !!env[PIWI_ENV_KEYS.apiKey] && mergedRaw.apiKey === env[PIWI_ENV_KEYS.apiKey] || typeof mergedRaw.apiKey === "string" && mergedRaw.apiKey !== "" && readDesktopToken(env[PIWI_DESKTOP_CONFIG_ENV] || defaultDesktopConfigPath()) === mergedRaw.apiKey;
|
|
328
464
|
const coverage = { ...mergedRaw.coverage };
|
|
329
465
|
const coverageBrowser = env[PIWI_ENV_KEYS.coverageBrowser];
|
|
330
466
|
const coverageServer = env[PIWI_ENV_KEYS.coverageServer];
|
|
@@ -343,6 +479,24 @@ function resolveOptions(raw, configDir) {
|
|
|
343
479
|
if (externalId.onDuplicate === void 0 && externalIdOnDuplicate)
|
|
344
480
|
externalId.onDuplicate = externalIdOnDuplicate;
|
|
345
481
|
if (Object.keys(externalId).length > 0) mergedRaw.externalId = externalId;
|
|
482
|
+
if (requested && "instance" in requested) {
|
|
483
|
+
desktopTokenHeld = false;
|
|
484
|
+
mergedRaw.serverUrl = requested.instance;
|
|
485
|
+
mergedRaw.apiKey = requested.token;
|
|
486
|
+
mergedRaw.username = null;
|
|
487
|
+
mergedRaw.password = null;
|
|
488
|
+
mergedRaw.enabled = true;
|
|
489
|
+
mergedRaw.streaming = true;
|
|
490
|
+
mergedRaw.keep = false;
|
|
491
|
+
mergedRaw.sampleAriaOnPass = false;
|
|
492
|
+
mergedRaw.uploadManifest = false;
|
|
493
|
+
mergedRaw.captureCodeReach = false;
|
|
494
|
+
mergedRaw.collectEnvironmentInfo = false;
|
|
495
|
+
delete mergedRaw.coverage;
|
|
496
|
+
mergedRaw.ai = { ...mergedRaw.ai, mode: "replay" };
|
|
497
|
+
} else if (requested) {
|
|
498
|
+
mergedRaw.enabled = false;
|
|
499
|
+
}
|
|
346
500
|
const opts = { ...DEFAULTS, ...mergedRaw };
|
|
347
501
|
if (env[PIWI_ENV_KEYS.verbose] !== void 0) opts.verbose = readBool(env[PIWI_ENV_KEYS.verbose]);
|
|
348
502
|
return opts;
|
|
@@ -354,6 +508,77 @@ var http = __toESM(require("http"));
|
|
|
354
508
|
var import_node_url = require("url");
|
|
355
509
|
var import_form_data = __toESM(require("form-data"));
|
|
356
510
|
|
|
511
|
+
// ../core/src/hmac.ts
|
|
512
|
+
async function hmacSha256Hex(key, message) {
|
|
513
|
+
const encoder = new TextEncoder();
|
|
514
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
515
|
+
"raw",
|
|
516
|
+
encoder.encode(key),
|
|
517
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
518
|
+
false,
|
|
519
|
+
["sign"]
|
|
520
|
+
);
|
|
521
|
+
return hex(new Uint8Array(await crypto.subtle.sign("HMAC", cryptoKey, encoder.encode(message))));
|
|
522
|
+
}
|
|
523
|
+
function randomHex(byteCount) {
|
|
524
|
+
return hex(crypto.getRandomValues(new Uint8Array(byteCount)));
|
|
525
|
+
}
|
|
526
|
+
function hex(bytes) {
|
|
527
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// ../core/src/desktop-proof.ts
|
|
531
|
+
var DESKTOP_CHALLENGE_HEADER = "x-piwi-desktop-challenge";
|
|
532
|
+
var DESKTOP_PROOF_HEADER = "x-piwi-desktop-proof";
|
|
533
|
+
function newDesktopChallenge() {
|
|
534
|
+
return randomHex(32);
|
|
535
|
+
}
|
|
536
|
+
function desktopTokenProof(token, port, challenge) {
|
|
537
|
+
return hmacSha256Hex(token, `piwi-desktop-proof:${port}:${challenge}`);
|
|
538
|
+
}
|
|
539
|
+
var PROOF_TIMEOUT_MS = 5e3;
|
|
540
|
+
function sameHex(a, b) {
|
|
541
|
+
if (a.length !== b.length) return false;
|
|
542
|
+
let diff = 0;
|
|
543
|
+
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
544
|
+
return diff === 0;
|
|
545
|
+
}
|
|
546
|
+
async function proveDesktopServer(baseUrl, token, options = {}) {
|
|
547
|
+
let url;
|
|
548
|
+
try {
|
|
549
|
+
url = new URL(baseUrl);
|
|
550
|
+
} catch {
|
|
551
|
+
return "unreachable";
|
|
552
|
+
}
|
|
553
|
+
const request3 = options.request ?? ((target, init) => fetch(target, { ...init, redirect: "error" }));
|
|
554
|
+
const challenge = newDesktopChallenge();
|
|
555
|
+
let res;
|
|
556
|
+
try {
|
|
557
|
+
res = await request3(new URL("/api/health", url).href, {
|
|
558
|
+
headers: { [DESKTOP_CHALLENGE_HEADER]: challenge },
|
|
559
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? PROOF_TIMEOUT_MS)
|
|
560
|
+
});
|
|
561
|
+
} catch {
|
|
562
|
+
return "unreachable";
|
|
563
|
+
}
|
|
564
|
+
const proof = res.headers.get(DESKTOP_PROOF_HEADER);
|
|
565
|
+
if (!proof) return res.status === 200 ? "unproven" : "unreachable";
|
|
566
|
+
const port = Number(url.port || (url.protocol === "https:" ? 443 : 80));
|
|
567
|
+
return sameHex(proof, await desktopTokenProof(token, port, challenge)) ? "proven" : "unproven";
|
|
568
|
+
}
|
|
569
|
+
function shareInFlight() {
|
|
570
|
+
const running = /* @__PURE__ */ new Map();
|
|
571
|
+
return (key, check) => {
|
|
572
|
+
const existing = running.get(key);
|
|
573
|
+
if (existing) return existing;
|
|
574
|
+
const started = check().finally(() => {
|
|
575
|
+
if (running.get(key) === started) running.delete(key);
|
|
576
|
+
});
|
|
577
|
+
running.set(key, started);
|
|
578
|
+
return started;
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
357
582
|
// src/internal/support/logger.ts
|
|
358
583
|
var Logger = class {
|
|
359
584
|
constructor(verbose = false) {
|
|
@@ -385,6 +610,15 @@ var HttpError = class extends Error {
|
|
|
385
610
|
this.name = "HttpError";
|
|
386
611
|
}
|
|
387
612
|
};
|
|
613
|
+
var DesktopNotProvenError = class extends Error {
|
|
614
|
+
constructor(serverUrl, proof) {
|
|
615
|
+
super(
|
|
616
|
+
proof === "unreachable" ? `The desktop app at ${serverUrl} did not answer, so its token is not sent and nothing is uploaded.` : `The desktop app's token is not sent to ${serverUrl}: the server there did not prove it holds the token, so nothing is uploaded. Restart or update the desktop app, or name another instance with a server URL and an API key.`
|
|
617
|
+
);
|
|
618
|
+
this.name = "DesktopNotProvenError";
|
|
619
|
+
if (proof === "unreachable") this.code = "ECONNREFUSED";
|
|
620
|
+
}
|
|
621
|
+
};
|
|
388
622
|
var FAILURE_DETAIL_MAX = 500;
|
|
389
623
|
function failureDetail(res) {
|
|
390
624
|
let text = null;
|
|
@@ -437,17 +671,21 @@ var HttpClient = class {
|
|
|
437
671
|
* @param uploadTimeout Socket inactivity timeout of a multipart upload, or of
|
|
438
672
|
* a run's results sent as JSON, in ms (default 10 min): the
|
|
439
673
|
* dashboard answers one only once it has stored all of it.
|
|
674
|
+
* @param desktopToken The desktop app's token when `serverUrl` is the app's: a request that carries it waits for
|
|
675
|
+
* the server to prove it holds it, and without the proof nothing is sent.
|
|
440
676
|
*/
|
|
441
|
-
constructor(serverUrl, logger2 = new Logger(), timeout = 3e4, uploadTimeout = 10 * 60 * 1e3) {
|
|
677
|
+
constructor(serverUrl, logger2 = new Logger(), timeout = 3e4, uploadTimeout = 10 * 60 * 1e3, desktopToken = null) {
|
|
442
678
|
this.serverUrl = serverUrl;
|
|
443
679
|
this.logger = logger2;
|
|
444
680
|
this.timeout = timeout;
|
|
445
681
|
this.uploadTimeout = uploadTimeout;
|
|
682
|
+
this.desktopToken = desktopToken;
|
|
446
683
|
/** Requests in flight, so `close` can abort them. */
|
|
447
684
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
448
685
|
/** Set by `close`: every later request fails with this reason. */
|
|
449
686
|
this.closedReason = null;
|
|
450
687
|
this.loginAnnounced = false;
|
|
688
|
+
this.proofsInFlight = shareInFlight();
|
|
451
689
|
this.warnIfInsecureTransport();
|
|
452
690
|
}
|
|
453
691
|
/**
|
|
@@ -607,7 +845,21 @@ var HttpClient = class {
|
|
|
607
845
|
* Unified request core: transport, headers, auth, response accumulation, timeout. Nothing is sent to a `serverUrl`
|
|
608
846
|
* that is not an `http://` or `https://` URL.
|
|
609
847
|
*/
|
|
610
|
-
request(method, pathname, opts) {
|
|
848
|
+
async request(method, pathname, opts) {
|
|
849
|
+
if (!this.desktopToken || opts.auth !== this.desktopToken) return this.send(method, pathname, opts);
|
|
850
|
+
await this.requireDesktopProof();
|
|
851
|
+
return this.send(method, pathname, opts);
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Resolves once the server proved it holds the desktop token. Each request that carries the token asks for its own
|
|
855
|
+
* proof; requests that arrive while a proof is being asked share it, and a proof that has arrived is never used for
|
|
856
|
+
* a later request.
|
|
857
|
+
*/
|
|
858
|
+
async requireDesktopProof() {
|
|
859
|
+
const proof = await this.proofsInFlight("proof", () => proveDesktopServer(this.serverUrl, this.desktopToken));
|
|
860
|
+
if (proof !== "proven") throw new DesktopNotProvenError(this.serverUrl, proof);
|
|
861
|
+
}
|
|
862
|
+
send(method, pathname, opts) {
|
|
611
863
|
return new Promise((resolve4, reject) => {
|
|
612
864
|
if (this.closedReason !== null) {
|
|
613
865
|
reject(new Error(this.closedReason));
|
|
@@ -680,7 +932,7 @@ var HttpClient = class {
|
|
|
680
932
|
}
|
|
681
933
|
applyAuth(headers, auth) {
|
|
682
934
|
if (!auth) return;
|
|
683
|
-
if (auth.startsWith("pd_")) {
|
|
935
|
+
if (auth.startsWith("pd_") || auth.startsWith(REQUEST_TOKEN_PREFIX)) {
|
|
684
936
|
headers["Authorization"] = `Bearer ${auth}`;
|
|
685
937
|
} else {
|
|
686
938
|
headers["Cookie"] = auth;
|
|
@@ -689,14 +941,14 @@ var HttpClient = class {
|
|
|
689
941
|
};
|
|
690
942
|
|
|
691
943
|
// src/internal/support/instance-id.ts
|
|
692
|
-
var
|
|
693
|
-
var
|
|
944
|
+
var crypto3 = __toESM(require("crypto"));
|
|
945
|
+
var os3 = __toESM(require("os"));
|
|
694
946
|
function hashForProject(projectName) {
|
|
695
|
-
return
|
|
947
|
+
return crypto3.createHash("sha1").update(projectName).digest("hex").slice(0, 16);
|
|
696
948
|
}
|
|
697
949
|
function computeInstanceId(projectName, runLabel) {
|
|
698
|
-
const seed = runLabel ? `${projectName}|${runLabel}` : `${
|
|
699
|
-
return
|
|
950
|
+
const seed = runLabel ? `${projectName}|${runLabel}` : `${os3.hostname()}|${projectName}`;
|
|
951
|
+
return crypto3.createHash("sha256").update(seed).digest("hex").slice(0, 16);
|
|
700
952
|
}
|
|
701
953
|
|
|
702
954
|
// src/internal/support/shard-info.ts
|
|
@@ -743,9 +995,9 @@ var MAX_REGION_SNAPSHOT = 1024 * 1024;
|
|
|
743
995
|
var MAX_AGENT_SNAPSHOT = 1024 * 1024;
|
|
744
996
|
|
|
745
997
|
// src/internal/support/test-paths.ts
|
|
746
|
-
var
|
|
998
|
+
var path4 = __toESM(require("path"));
|
|
747
999
|
function configDirFromConfig(config) {
|
|
748
|
-
if (config?.configFile) return
|
|
1000
|
+
if (config?.configFile) return path4.dirname(config.configFile);
|
|
749
1001
|
if (config?.rootDir) return config.rootDir;
|
|
750
1002
|
return process.cwd();
|
|
751
1003
|
}
|
|
@@ -868,59 +1120,6 @@ function isLiveViewKey(value) {
|
|
|
868
1120
|
// src/internal/support/setup-file.ts
|
|
869
1121
|
var path5 = __toESM(require("path"));
|
|
870
1122
|
var fs4 = __toESM(require("fs"));
|
|
871
|
-
|
|
872
|
-
// src/internal/support/private-file.ts
|
|
873
|
-
var crypto2 = __toESM(require("crypto"));
|
|
874
|
-
var fs3 = __toESM(require("fs"));
|
|
875
|
-
var os3 = __toESM(require("os"));
|
|
876
|
-
var path4 = __toESM(require("path"));
|
|
877
|
-
function privateTempDir() {
|
|
878
|
-
if (process.platform !== "win32") return os3.tmpdir();
|
|
879
|
-
const dir = path4.join(process.env.LOCALAPPDATA || path4.join(os3.homedir(), "AppData", "Local"), "piwi", "tmp");
|
|
880
|
-
try {
|
|
881
|
-
fs3.mkdirSync(dir, { recursive: true });
|
|
882
|
-
} catch {
|
|
883
|
-
}
|
|
884
|
-
return dir;
|
|
885
|
-
}
|
|
886
|
-
var NO_FOLLOW = fs3.constants.O_NOFOLLOW ?? 0;
|
|
887
|
-
var NO_WAIT = fs3.constants.O_NONBLOCK ?? 0;
|
|
888
|
-
function untrustedReason(stat) {
|
|
889
|
-
if (stat.isSymbolicLink()) return "it is a symbolic link";
|
|
890
|
-
if (!stat.isFile()) return "it is not a regular file";
|
|
891
|
-
if (typeof process.getuid === "function") {
|
|
892
|
-
if (stat.uid !== process.getuid()) return "another user owns it";
|
|
893
|
-
if (stat.mode & 18) return "other users may write to it";
|
|
894
|
-
if (stat.nlink > 1) return "it has another name";
|
|
895
|
-
}
|
|
896
|
-
return null;
|
|
897
|
-
}
|
|
898
|
-
function writePrivateFile(file, text) {
|
|
899
|
-
const temp = `${file}.${process.pid}.${crypto2.randomBytes(6).toString("hex")}.tmp`;
|
|
900
|
-
try {
|
|
901
|
-
fs3.writeFileSync(temp, text, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
902
|
-
fs3.renameSync(temp, file);
|
|
903
|
-
} catch (error) {
|
|
904
|
-
fs3.rmSync(temp, { force: true });
|
|
905
|
-
throw error;
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
function readPrivateFile(file) {
|
|
909
|
-
const found = fs3.lstatSync(file, { throwIfNoEntry: false });
|
|
910
|
-
if (!found) return null;
|
|
911
|
-
const reason = untrustedReason(found);
|
|
912
|
-
if (reason) return { untrusted: reason };
|
|
913
|
-
const fd = fs3.openSync(file, fs3.constants.O_RDONLY | NO_FOLLOW | NO_WAIT);
|
|
914
|
-
try {
|
|
915
|
-
const opened = untrustedReason(fs3.fstatSync(fd));
|
|
916
|
-
if (opened) return { untrusted: opened };
|
|
917
|
-
return { text: fs3.readFileSync(fd, "utf8") };
|
|
918
|
-
} finally {
|
|
919
|
-
fs3.closeSync(fd);
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
// src/internal/support/setup-file.ts
|
|
924
1123
|
var logger = new Logger();
|
|
925
1124
|
function getSetupFilePath(projectName, pid = process.pid) {
|
|
926
1125
|
return path5.join(privateTempDir(), `piwi-dashboard-setup-${hashForProject(projectName)}-${pid}.json`);
|
|
@@ -936,6 +1135,23 @@ function writeSetupFailure(projectName, failed) {
|
|
|
936
1135
|
}
|
|
937
1136
|
}
|
|
938
1137
|
|
|
1138
|
+
// src/internal/support/run-url.ts
|
|
1139
|
+
function runUrl(serverUrl, runId) {
|
|
1140
|
+
return `${serverUrl.replace(/\/+$/, "")}/test-runs/${runId}`;
|
|
1141
|
+
}
|
|
1142
|
+
function answeredRunUrl(answer, serverUrl, runId) {
|
|
1143
|
+
const named = answer?.runUrl;
|
|
1144
|
+
if (typeof named === "string" && named.length <= 2048 && !/[\s()<>"'`\\]/.test(named)) {
|
|
1145
|
+
if (/^\/[^/]/.test(named)) return `${serverUrl.replace(/\/+$/, "")}${named}`;
|
|
1146
|
+
try {
|
|
1147
|
+
const url = new URL(named);
|
|
1148
|
+
if (url.protocol === "http:" || url.protocol === "https:") return url.href;
|
|
1149
|
+
} catch {
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
return runUrl(serverUrl, runId);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
939
1155
|
// src/internal/support/aria-sampling.ts
|
|
940
1156
|
var path6 = __toESM(require("path"));
|
|
941
1157
|
var fs5 = __toESM(require("fs"));
|
|
@@ -1218,6 +1434,7 @@ async function fetchManifestAt(manifestUrl, fetchImpl) {
|
|
|
1218
1434
|
const res = await fetchImpl(manifestUrl, { signal: AbortSignal.timeout(INSTRUMENTATION_FETCH_TIMEOUT_MS) });
|
|
1219
1435
|
return res.ok ? parseManifestJson(await res.text()) : null;
|
|
1220
1436
|
}
|
|
1437
|
+
var MAX_ENVIRONMENT_BYTES = 64 * 1024;
|
|
1221
1438
|
|
|
1222
1439
|
// src/internal/manifest/run-manifests.ts
|
|
1223
1440
|
async function lookupProjectId(httpClient, auth, projectName) {
|
|
@@ -1231,7 +1448,7 @@ async function uploadManifest(httpClient, auth, projectId, upload, logger2) {
|
|
|
1231
1448
|
}
|
|
1232
1449
|
|
|
1233
1450
|
// src/internal/collect/source-checksums.ts
|
|
1234
|
-
var
|
|
1451
|
+
var crypto4 = __toESM(require("crypto"));
|
|
1235
1452
|
var fs7 = __toESM(require("fs"));
|
|
1236
1453
|
var path8 = __toESM(require("path"));
|
|
1237
1454
|
|
|
@@ -1374,7 +1591,13 @@ function createGlobalSetup(options, userSetup) {
|
|
|
1374
1591
|
if (userSetup) return userSetup(config);
|
|
1375
1592
|
return;
|
|
1376
1593
|
}
|
|
1377
|
-
const httpClient = new HttpClient(
|
|
1594
|
+
const httpClient = new HttpClient(
|
|
1595
|
+
opts.serverUrl,
|
|
1596
|
+
logger2,
|
|
1597
|
+
void 0,
|
|
1598
|
+
void 0,
|
|
1599
|
+
usedDesktopToken() ? opts.apiKey ?? null : null
|
|
1600
|
+
);
|
|
1378
1601
|
const registers = opts.streaming !== false;
|
|
1379
1602
|
let registered = false;
|
|
1380
1603
|
try {
|
|
@@ -1453,14 +1676,16 @@ async function registerRun(httpClient, auth, opts, config, logger2) {
|
|
|
1453
1676
|
throw new Error("the answer to /api/test-runs/setup names no run");
|
|
1454
1677
|
}
|
|
1455
1678
|
const liveViewKey = response.liveView?.key;
|
|
1679
|
+
const runUrl2 = answeredRunUrl(response, httpClient.baseUrl, response.runId);
|
|
1456
1680
|
writeSetupInfo({
|
|
1457
1681
|
runId: response.runId,
|
|
1458
1682
|
setupToken: response.setupToken,
|
|
1459
1683
|
projectName: opts.projectName,
|
|
1460
1684
|
...isLiveViewKey(liveViewKey) ? { liveViewKey } : {},
|
|
1461
|
-
...response.liveView?.refused === "local" ? { liveViewLocal: true } : {}
|
|
1685
|
+
...response.liveView?.refused === "local" ? { liveViewLocal: true } : {},
|
|
1686
|
+
runUrl: runUrl2
|
|
1462
1687
|
});
|
|
1463
|
-
logger2.
|
|
1688
|
+
logger2.info(`View live progress: ${runUrl2}`);
|
|
1464
1689
|
if (isLiveViewKey(liveViewKey) && detectCi(process.env) && !relaying) {
|
|
1465
1690
|
try {
|
|
1466
1691
|
const stopRelay = relayRunLog((line) => logger2.info(line));
|
package/dist/index.d.ts
CHANGED
|
@@ -61,6 +61,13 @@ interface PiwiDashboardOptions {
|
|
|
61
61
|
collectScmInfo?: boolean;
|
|
62
62
|
/** Auto-collect CI environment info. Defaults to `true`. */
|
|
63
63
|
collectCiInfo?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Record where the run executed: the runner's time zone, locale, OS, Node.js version and CI image, each browser as
|
|
66
|
+
* its page reports itself (with the capture fixtures), and each instrumented server under test. The dashboard
|
|
67
|
+
* shows when they change between runs or shards. Defaults to `true`. Can also be forced off with
|
|
68
|
+
* `PIWI_COLLECT_ENVIRONMENT_INFO=false`.
|
|
69
|
+
*/
|
|
70
|
+
collectEnvironmentInfo?: boolean;
|
|
64
71
|
/** Collect step timings, network requests and web vitals. Defaults to `true`. */
|
|
65
72
|
collectPerformanceMetrics?: boolean;
|
|
66
73
|
/**
|
|
@@ -540,8 +547,14 @@ declare class PiwiDashboardReporter {
|
|
|
540
547
|
private uncapturedSpecs;
|
|
541
548
|
/** Whether the run is a CI run whose workers stream to the instance's live view, set in `onBegin`. */
|
|
542
549
|
private liveViewOn;
|
|
550
|
+
/** The run's own connection to the hub its workers reach, from `onBegin` to `onEnd`; null for a run without one. */
|
|
551
|
+
private hubLink;
|
|
543
552
|
/** The live steps begun and not ended, by step, sent again when someone opens the run (`onWatched`). */
|
|
544
553
|
private openSteps;
|
|
554
|
+
/** The attempts running now, by test id, for the stops their workers note (`heardStop`). */
|
|
555
|
+
private runningTests;
|
|
556
|
+
/** Reads the stops the workers note (`readStopNotes`). */
|
|
557
|
+
private stopNotes;
|
|
545
558
|
/**
|
|
546
559
|
* The failed attempts with retries left, by `test.id`: each is its test's last failure when no later attempt has a
|
|
547
560
|
* say in its outcome (`decidesOutcome`), the run stopping before the retry or the retry not running.
|
|
@@ -572,6 +585,8 @@ declare class PiwiDashboardReporter {
|
|
|
572
585
|
private readonly mergingReports;
|
|
573
586
|
/** True when the server URL and API key came from the desktop app, not from config. */
|
|
574
587
|
private viaDesktopApp;
|
|
588
|
+
/** The team instance a requested run uploads to, or why it uploads nowhere. */
|
|
589
|
+
private requestedRun;
|
|
575
590
|
/** The configured server `desktopApp: 'prefer'` set aside for the desktop app, if any. */
|
|
576
591
|
private readonly desktopReplaced;
|
|
577
592
|
/** The config folder's `.env` file and the connection variables taken from it, if any. */
|
|
@@ -588,6 +603,8 @@ declare class PiwiDashboardReporter {
|
|
|
588
603
|
private resourceCensuses;
|
|
589
604
|
/** Lifecycle steps of the tests that ran without the fixtures. */
|
|
590
605
|
private lifecycleTallies;
|
|
606
|
+
/** The spec and helper files those steps point at, read once each. */
|
|
607
|
+
private readonly sourceLines;
|
|
591
608
|
/** The user fixtures set up by the tests that left a page unused, by test id. */
|
|
592
609
|
private fixturesByTest;
|
|
593
610
|
/** The file workers append their shutdown census to, set in `onBegin`. */
|
|
@@ -608,6 +625,8 @@ declare class PiwiDashboardReporter {
|
|
|
608
625
|
private lastTestWatch;
|
|
609
626
|
/** The manifests of the instrumented origins the run reaches beyond its base URLs. */
|
|
610
627
|
private manifests;
|
|
628
|
+
/** Where the run executes: the runner, each project's browser and each server under test; null when off. */
|
|
629
|
+
private environments;
|
|
611
630
|
/** Result events that stream once their test's server coverage is in. */
|
|
612
631
|
private coverageSends;
|
|
613
632
|
/** The errors Playwright reported outside any test (`onError`), the first `MAX_RUN_ERRORS` of them. */
|
|
@@ -649,8 +668,18 @@ declare class PiwiDashboardReporter {
|
|
|
649
668
|
* the run so the dashboard lists them too.
|
|
650
669
|
*/
|
|
651
670
|
private planExternalIds;
|
|
671
|
+
/**
|
|
672
|
+
* Name the planned tests whose tags are cut at the limit, once, and record them on the run so the dashboard shows
|
|
673
|
+
* them too. A planned test whose properties cannot be read is left out.
|
|
674
|
+
*/
|
|
675
|
+
private noteTagsTruncated;
|
|
652
676
|
/** The external ID fields of a test's payload: `null` tells the dashboard the test has none to match on. */
|
|
653
677
|
private externalIdFields;
|
|
678
|
+
/**
|
|
679
|
+
* A stop a worker noted (`stop-notes.ts`), of an attempt running now: a `test-stopped` event as it shows and a
|
|
680
|
+
* `test-resumed` as it ends, named as its `begin` named the attempt, sent whoever watches.
|
|
681
|
+
*/
|
|
682
|
+
private heardStop;
|
|
654
683
|
/** Playwright reporter hook: called when an individual test begins */
|
|
655
684
|
onTestBegin(test: TestCase, result: TestResult): void;
|
|
656
685
|
/**
|
|
@@ -702,8 +731,8 @@ declare class PiwiDashboardReporter {
|
|
|
702
731
|
onTestEnd(test: TestCase, result: TestResult): void;
|
|
703
732
|
/**
|
|
704
733
|
* Add up the files a test attached, and keep its resource census; for a test
|
|
705
|
-
* that ran without the capture fixtures, tally the browsers
|
|
706
|
-
* steps opened and closed.
|
|
734
|
+
* that ran without the capture fixtures, tally the browsers, contexts and
|
|
735
|
+
* pages its steps opened and closed.
|
|
707
736
|
*/
|
|
708
737
|
private collectResources;
|
|
709
738
|
/**
|
|
@@ -738,6 +767,8 @@ declare class PiwiDashboardReporter {
|
|
|
738
767
|
onEnd(result: FullResult): Promise<{
|
|
739
768
|
status?: FullResult['status'];
|
|
740
769
|
} | void>;
|
|
770
|
+
/** Every environment snapshot of the run; none when collection is off or reading them failed. */
|
|
771
|
+
private readEnvironments;
|
|
741
772
|
private finishRun;
|
|
742
773
|
}
|
|
743
774
|
|