@piwitests/reporter 0.67.0 → 0.69.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 +1903 -640
- package/dist/global-setup-module.js +458 -135
- package/dist/index.d.ts +39 -4
- package/dist/index.js +10174 -4441
- 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 +176 -21
- package/dist/internal/capture/capture-fixtures.js +6932 -2926
- package/package.json +1 -1
- package/templates/skills/fix-a-reported-bug/SKILL.md +3 -1
- package/templates/skills/investigate-failure/SKILL.md +1 -1
|
@@ -41,12 +41,33 @@ 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"));
|
|
48
48
|
var os = __toESM(require("os"));
|
|
49
49
|
var path = __toESM(require("path"));
|
|
50
|
+
|
|
51
|
+
// ../core/src/hmac.ts
|
|
52
|
+
async function hmacSha256Hex(key, message) {
|
|
53
|
+
const encoder = new TextEncoder();
|
|
54
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
55
|
+
"raw",
|
|
56
|
+
encoder.encode(key),
|
|
57
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
58
|
+
false,
|
|
59
|
+
["sign"]
|
|
60
|
+
);
|
|
61
|
+
return hex(new Uint8Array(await crypto.subtle.sign("HMAC", cryptoKey, encoder.encode(message))));
|
|
62
|
+
}
|
|
63
|
+
function randomHex(byteCount) {
|
|
64
|
+
return hex(crypto.getRandomValues(new Uint8Array(byteCount)));
|
|
65
|
+
}
|
|
66
|
+
function hex(bytes) {
|
|
67
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/internal/config/desktop.ts
|
|
50
71
|
function defaultDesktopConfigPath() {
|
|
51
72
|
return path.join(os.homedir(), ".piwi", "desktop.json");
|
|
52
73
|
}
|
|
@@ -59,18 +80,30 @@ function processAlive(pid) {
|
|
|
59
80
|
}
|
|
60
81
|
}
|
|
61
82
|
function readDesktopConfig(filePath) {
|
|
83
|
+
const file = readDesktopFile(filePath);
|
|
84
|
+
if (!file) return null;
|
|
85
|
+
if (file.pid !== null && !processAlive(file.pid)) return null;
|
|
86
|
+
return { url: file.url, token: file.token };
|
|
87
|
+
}
|
|
88
|
+
function readDesktopToken(filePath) {
|
|
89
|
+
return readDesktopFile(filePath)?.token ?? null;
|
|
90
|
+
}
|
|
91
|
+
function readDesktopFile(filePath) {
|
|
62
92
|
try {
|
|
63
|
-
|
|
64
|
-
const url = parsed?.url;
|
|
65
|
-
const token = parsed?.token;
|
|
66
|
-
if (typeof url !== "string" || !url) return null;
|
|
67
|
-
if (typeof token !== "string" || !token) return null;
|
|
68
|
-
if (Number.isInteger(parsed?.pid) && parsed.pid > 0 && !processAlive(parsed.pid)) return null;
|
|
69
|
-
return { url, token };
|
|
93
|
+
return desktopFields(JSON.parse(fs.readFileSync(filePath, "utf8")));
|
|
70
94
|
} catch {
|
|
71
95
|
return null;
|
|
72
96
|
}
|
|
73
97
|
}
|
|
98
|
+
function desktopFields(parsed) {
|
|
99
|
+
const file = parsed;
|
|
100
|
+
const url = file?.url;
|
|
101
|
+
const token = file?.token;
|
|
102
|
+
if (typeof url !== "string" || !url) return null;
|
|
103
|
+
if (typeof token !== "string" || !token) return null;
|
|
104
|
+
const pid = Number.isInteger(file?.pid) && file.pid > 0 ? file.pid : null;
|
|
105
|
+
return { url, token, pid };
|
|
106
|
+
}
|
|
74
107
|
|
|
75
108
|
// src/internal/config/dotenv.ts
|
|
76
109
|
var fs2 = __toESM(require("fs"));
|
|
@@ -134,6 +167,146 @@ function resolveRunLabel(configured, sharded) {
|
|
|
134
167
|
return !sharded && ci.job ? `${ci.run}|${ci.job}` : ci.run;
|
|
135
168
|
}
|
|
136
169
|
|
|
170
|
+
// ../core/src/run-request.ts
|
|
171
|
+
var RUN_REQUEST_LIMITS = {
|
|
172
|
+
tests: { min: 1, max: 200 },
|
|
173
|
+
repeatEach: { min: 1, max: 10 },
|
|
174
|
+
workers: { min: 1, max: 4 },
|
|
175
|
+
/** How long a request waits for a target to claim it, in milliseconds. */
|
|
176
|
+
lifetimeMs: 2 * 60 * 1e3,
|
|
177
|
+
/**
|
|
178
|
+
* How often a target that holds a request calls the instance at least, in milliseconds: it hears its stops from the
|
|
179
|
+
* list of requests. Past this silence the instance ends the request as an error.
|
|
180
|
+
*/
|
|
181
|
+
silentTargetMs: 5 * 60 * 1e3,
|
|
182
|
+
/** How long a stop waits for the target to end a run, in milliseconds, before a second stop ends the request. */
|
|
183
|
+
stopGraceMs: 60 * 1e3
|
|
184
|
+
};
|
|
185
|
+
var REQUEST_TOKEN_PREFIX = "pdq_";
|
|
186
|
+
var REQUEST_TOKEN = /^pdq_[0-9a-f]{64}$/;
|
|
187
|
+
var REQUEST_RUN_ENV = {
|
|
188
|
+
tokenFile: "PIWI_REQUEST_TOKEN_FILE",
|
|
189
|
+
instance: "PIWI_REQUEST_INSTANCE"
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/internal/support/private-file.ts
|
|
193
|
+
var crypto2 = __toESM(require("crypto"));
|
|
194
|
+
var fs3 = __toESM(require("fs"));
|
|
195
|
+
var os2 = __toESM(require("os"));
|
|
196
|
+
var path2 = __toESM(require("path"));
|
|
197
|
+
function privateTempDir() {
|
|
198
|
+
if (process.platform !== "win32") return os2.tmpdir();
|
|
199
|
+
const dir = path2.join(process.env.LOCALAPPDATA || path2.join(os2.homedir(), "AppData", "Local"), "piwi", "tmp");
|
|
200
|
+
try {
|
|
201
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
202
|
+
} catch {
|
|
203
|
+
}
|
|
204
|
+
return dir;
|
|
205
|
+
}
|
|
206
|
+
var STALE_PRIVATE_FILE_MS = 24 * 60 * 60 * 1e3;
|
|
207
|
+
function sweepStalePrivateFiles(prefix, { dir = privateTempDir(), now = Date.now() } = {}) {
|
|
208
|
+
let names;
|
|
209
|
+
try {
|
|
210
|
+
names = fs3.readdirSync(dir);
|
|
211
|
+
} catch {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
for (const name of names) {
|
|
215
|
+
if (!name.startsWith(prefix)) continue;
|
|
216
|
+
const file = path2.join(dir, name);
|
|
217
|
+
try {
|
|
218
|
+
const stat = fs3.lstatSync(file);
|
|
219
|
+
if (!stat.isFile()) continue;
|
|
220
|
+
if (typeof process.getuid === "function" && stat.uid !== process.getuid()) continue;
|
|
221
|
+
if (now - stat.mtimeMs < STALE_PRIVATE_FILE_MS) continue;
|
|
222
|
+
fs3.rmSync(file, { force: true });
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function keepPrivateFileLive(file) {
|
|
228
|
+
try {
|
|
229
|
+
const now = /* @__PURE__ */ new Date();
|
|
230
|
+
fs3.lutimesSync(file, now, now);
|
|
231
|
+
} catch {
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
var NO_FOLLOW = fs3.constants.O_NOFOLLOW ?? 0;
|
|
235
|
+
var NO_WAIT = fs3.constants.O_NONBLOCK ?? 0;
|
|
236
|
+
function untrustedReason(stat) {
|
|
237
|
+
if (stat.isSymbolicLink()) return "it is a symbolic link";
|
|
238
|
+
if (!stat.isFile()) return "it is not a regular file";
|
|
239
|
+
if (typeof process.getuid === "function") {
|
|
240
|
+
if (stat.uid !== process.getuid()) return "another user owns it";
|
|
241
|
+
if (stat.mode & 18) return "other users may write to it";
|
|
242
|
+
if (stat.nlink > 1) return "it has another name";
|
|
243
|
+
}
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
function writePrivateFile(file, text) {
|
|
247
|
+
const temp = `${file}.${process.pid}.${crypto2.randomBytes(6).toString("hex")}.tmp`;
|
|
248
|
+
try {
|
|
249
|
+
fs3.writeFileSync(temp, text, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
250
|
+
fs3.renameSync(temp, file);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
fs3.rmSync(temp, { force: true });
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function readPrivateFile(file) {
|
|
257
|
+
const found = fs3.lstatSync(file, { throwIfNoEntry: false });
|
|
258
|
+
if (!found) return null;
|
|
259
|
+
const reason = untrustedReason(found);
|
|
260
|
+
if (reason) return { untrusted: reason };
|
|
261
|
+
const fd = fs3.openSync(file, fs3.constants.O_RDONLY | NO_FOLLOW | NO_WAIT);
|
|
262
|
+
try {
|
|
263
|
+
const stat = fs3.fstatSync(fd);
|
|
264
|
+
const opened = untrustedReason(stat);
|
|
265
|
+
if (opened) return { untrusted: opened };
|
|
266
|
+
return { text: fs3.readFileSync(fd, "utf8"), mode: stat.mode };
|
|
267
|
+
} finally {
|
|
268
|
+
fs3.closeSync(fd);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/internal/config/requested-run.ts
|
|
273
|
+
function readRequestedRun(env) {
|
|
274
|
+
const file = env[REQUEST_RUN_ENV.tokenFile];
|
|
275
|
+
const instance = env[REQUEST_RUN_ENV.instance];
|
|
276
|
+
if (!file && !instance) return null;
|
|
277
|
+
if (!file || !instance) {
|
|
278
|
+
return { problem: `${REQUEST_RUN_ENV.tokenFile} and ${REQUEST_RUN_ENV.instance} are set together, or not at all.` };
|
|
279
|
+
}
|
|
280
|
+
let url;
|
|
281
|
+
try {
|
|
282
|
+
url = new URL(instance);
|
|
283
|
+
} catch {
|
|
284
|
+
return { problem: `${REQUEST_RUN_ENV.instance} is not a URL.` };
|
|
285
|
+
}
|
|
286
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
287
|
+
return { problem: `${REQUEST_RUN_ENV.instance} is not an http or https URL.` };
|
|
288
|
+
}
|
|
289
|
+
let read;
|
|
290
|
+
try {
|
|
291
|
+
read = readPrivateFile(file);
|
|
292
|
+
} catch {
|
|
293
|
+
read = null;
|
|
294
|
+
}
|
|
295
|
+
if (!read) return { problem: `The request token file in ${REQUEST_RUN_ENV.tokenFile} cannot be read.` };
|
|
296
|
+
if ("untrusted" in read || readableByOthers(read.mode)) {
|
|
297
|
+
return { problem: `The request token file in ${REQUEST_RUN_ENV.tokenFile} is not this user's alone.` };
|
|
298
|
+
}
|
|
299
|
+
const token = read.text.trim();
|
|
300
|
+
if (!REQUEST_TOKEN.test(token)) {
|
|
301
|
+
return { problem: `The file in ${REQUEST_RUN_ENV.tokenFile} holds no request token.` };
|
|
302
|
+
}
|
|
303
|
+
return { instance: `${url.origin}${url.pathname.replace(/\/+$/, "")}`, token };
|
|
304
|
+
}
|
|
305
|
+
function readableByOthers(mode) {
|
|
306
|
+
if (typeof process.getuid !== "function") return false;
|
|
307
|
+
return (mode & 36) !== 0;
|
|
308
|
+
}
|
|
309
|
+
|
|
137
310
|
// src/internal/config/env.ts
|
|
138
311
|
var DEFAULTS = {
|
|
139
312
|
projectName: "default-project",
|
|
@@ -142,6 +315,7 @@ var DEFAULTS = {
|
|
|
142
315
|
liveFileUploads: true,
|
|
143
316
|
collectScmInfo: true,
|
|
144
317
|
collectCiInfo: true,
|
|
318
|
+
collectEnvironmentInfo: true,
|
|
145
319
|
collectPerformanceMetrics: true,
|
|
146
320
|
captureLocators: true,
|
|
147
321
|
capturePageState: true,
|
|
@@ -171,6 +345,7 @@ var DEFAULTS = {
|
|
|
171
345
|
var PIWI_ENV_KEYS = {
|
|
172
346
|
serverUrl: "PIWI_DASHBOARD_URL",
|
|
173
347
|
desktopApp: "PIWI_DESKTOP_APP",
|
|
348
|
+
desktopKey: "PIWI_DESKTOP_KEY",
|
|
174
349
|
projectName: "PIWI_PROJECT_NAME",
|
|
175
350
|
verbose: "PIWI_VERBOSE",
|
|
176
351
|
apiKey: "PIWI_API_KEY",
|
|
@@ -189,6 +364,7 @@ var PIWI_ENV_KEYS = {
|
|
|
189
364
|
failOnFlakyTests: "PIWI_FAIL_ON_FLAKY_TESTS",
|
|
190
365
|
uploadTraces: "PIWI_UPLOAD_TRACES",
|
|
191
366
|
uploadReport: "PIWI_UPLOAD_REPORT",
|
|
367
|
+
collectEnvironmentInfo: "PIWI_COLLECT_ENVIRONMENT_INFO",
|
|
192
368
|
captureLocators: "PIWI_CAPTURE_LOCATORS",
|
|
193
369
|
capturePageState: "PIWI_CAPTURE_PAGE_STATE",
|
|
194
370
|
capturePageInventory: "PIWI_CAPTURE_PAGE_INVENTORY",
|
|
@@ -221,6 +397,7 @@ var PIWI_ENV_KEYS = {
|
|
|
221
397
|
var PIWI_DESKTOP_CONFIG_ENV = "PIWI_DESKTOP_CONFIG";
|
|
222
398
|
var PIWI_SHARD_ENV = "PIWI_SHARD";
|
|
223
399
|
var PIWI_RUN_LOG_ENV = "PIWI_RUN_LOG";
|
|
400
|
+
var PIWI_TERMINAL_PROGRESS_ENV = "PIWI_TERMINAL_PROGRESS";
|
|
224
401
|
function readBool(val) {
|
|
225
402
|
if (val === void 0) return void 0;
|
|
226
403
|
return ["true", "1", "yes", "on"].includes(val.trim().toLowerCase());
|
|
@@ -249,6 +426,7 @@ var ENV_FALLBACK_SPECS = [
|
|
|
249
426
|
{ option: "failOnFlakyTests", env: PIWI_ENV_KEYS.failOnFlakyTests, kind: "bool" },
|
|
250
427
|
{ option: "uploadTraces", env: PIWI_ENV_KEYS.uploadTraces, kind: "bool" },
|
|
251
428
|
{ option: "uploadReport", env: PIWI_ENV_KEYS.uploadReport, kind: "bool" },
|
|
429
|
+
{ option: "collectEnvironmentInfo", env: PIWI_ENV_KEYS.collectEnvironmentInfo, kind: "bool" },
|
|
252
430
|
{ option: "captureLocators", env: PIWI_ENV_KEYS.captureLocators, kind: "bool" },
|
|
253
431
|
{ option: "capturePageState", env: PIWI_ENV_KEYS.capturePageState, kind: "bool" },
|
|
254
432
|
{ option: "capturePageInventory", env: PIWI_ENV_KEYS.capturePageInventory, kind: "bool" },
|
|
@@ -273,9 +451,15 @@ function desktopAppMode(option, envValue) {
|
|
|
273
451
|
return "fallback";
|
|
274
452
|
}
|
|
275
453
|
var desktopDiscovered = false;
|
|
454
|
+
var desktopTokenHeld = false;
|
|
455
|
+
var requestedRunInstance = null;
|
|
456
|
+
var requestedRunError = null;
|
|
276
457
|
var desktopReplacedServerUrl = null;
|
|
277
458
|
var dotEnvUse = null;
|
|
278
459
|
var ignoredEnv = [];
|
|
460
|
+
function usedDesktopToken() {
|
|
461
|
+
return desktopTokenHeld;
|
|
462
|
+
}
|
|
279
463
|
function resolveOptions(raw, configDir) {
|
|
280
464
|
const env = process.env;
|
|
281
465
|
const mergedRaw = { ...raw };
|
|
@@ -295,7 +479,7 @@ function resolveOptions(raw, configDir) {
|
|
|
295
479
|
}
|
|
296
480
|
dotEnvUse = null;
|
|
297
481
|
if (configDir) {
|
|
298
|
-
const file =
|
|
482
|
+
const file = path3.join(configDir, ".env");
|
|
299
483
|
const dotEnv = readDotEnv(file);
|
|
300
484
|
const keys = [];
|
|
301
485
|
for (const option of DOTENV_OPTIONS) {
|
|
@@ -307,8 +491,12 @@ function resolveOptions(raw, configDir) {
|
|
|
307
491
|
if (keys.length > 0) dotEnvUse = { file, keys };
|
|
308
492
|
}
|
|
309
493
|
desktopDiscovered = false;
|
|
494
|
+
desktopTokenHeld = false;
|
|
310
495
|
desktopReplacedServerUrl = null;
|
|
311
|
-
const
|
|
496
|
+
const requested = readRequestedRun(env);
|
|
497
|
+
requestedRunInstance = requested && "instance" in requested ? requested.instance : null;
|
|
498
|
+
requestedRunError = requested && "problem" in requested ? requested.problem : null;
|
|
499
|
+
const mode = requested ? "off" : desktopAppMode(mergedRaw.desktopApp, env[PIWI_ENV_KEYS.desktopApp]);
|
|
312
500
|
mergedRaw.desktopApp = mode;
|
|
313
501
|
const serverUrlUnset = mergedRaw.serverUrl === void 0;
|
|
314
502
|
const apiKeyUnset = mergedRaw.apiKey === void 0 || mergedRaw.apiKey === null;
|
|
@@ -325,6 +513,7 @@ function resolveOptions(raw, configDir) {
|
|
|
325
513
|
desktopDiscovered = true;
|
|
326
514
|
}
|
|
327
515
|
}
|
|
516
|
+
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
517
|
const coverage = { ...mergedRaw.coverage };
|
|
329
518
|
const coverageBrowser = env[PIWI_ENV_KEYS.coverageBrowser];
|
|
330
519
|
const coverageServer = env[PIWI_ENV_KEYS.coverageServer];
|
|
@@ -343,6 +532,24 @@ function resolveOptions(raw, configDir) {
|
|
|
343
532
|
if (externalId.onDuplicate === void 0 && externalIdOnDuplicate)
|
|
344
533
|
externalId.onDuplicate = externalIdOnDuplicate;
|
|
345
534
|
if (Object.keys(externalId).length > 0) mergedRaw.externalId = externalId;
|
|
535
|
+
if (requested && "instance" in requested) {
|
|
536
|
+
desktopTokenHeld = false;
|
|
537
|
+
mergedRaw.serverUrl = requested.instance;
|
|
538
|
+
mergedRaw.apiKey = requested.token;
|
|
539
|
+
mergedRaw.username = null;
|
|
540
|
+
mergedRaw.password = null;
|
|
541
|
+
mergedRaw.enabled = true;
|
|
542
|
+
mergedRaw.streaming = true;
|
|
543
|
+
mergedRaw.keep = false;
|
|
544
|
+
mergedRaw.sampleAriaOnPass = false;
|
|
545
|
+
mergedRaw.uploadManifest = false;
|
|
546
|
+
mergedRaw.captureCodeReach = false;
|
|
547
|
+
mergedRaw.collectEnvironmentInfo = false;
|
|
548
|
+
delete mergedRaw.coverage;
|
|
549
|
+
mergedRaw.ai = { ...mergedRaw.ai, mode: "replay" };
|
|
550
|
+
} else if (requested) {
|
|
551
|
+
mergedRaw.enabled = false;
|
|
552
|
+
}
|
|
346
553
|
const opts = { ...DEFAULTS, ...mergedRaw };
|
|
347
554
|
if (env[PIWI_ENV_KEYS.verbose] !== void 0) opts.verbose = readBool(env[PIWI_ENV_KEYS.verbose]);
|
|
348
555
|
return opts;
|
|
@@ -354,6 +561,58 @@ var http = __toESM(require("http"));
|
|
|
354
561
|
var import_node_url = require("url");
|
|
355
562
|
var import_form_data = __toESM(require("form-data"));
|
|
356
563
|
|
|
564
|
+
// ../core/src/desktop-proof.ts
|
|
565
|
+
var DESKTOP_CHALLENGE_HEADER = "x-piwi-desktop-challenge";
|
|
566
|
+
var DESKTOP_PROOF_HEADER = "x-piwi-desktop-proof";
|
|
567
|
+
function newDesktopChallenge() {
|
|
568
|
+
return randomHex(32);
|
|
569
|
+
}
|
|
570
|
+
function desktopTokenProof(token, port, challenge) {
|
|
571
|
+
return hmacSha256Hex(token, `piwi-desktop-proof:${port}:${challenge}`);
|
|
572
|
+
}
|
|
573
|
+
var PROOF_TIMEOUT_MS = 5e3;
|
|
574
|
+
function sameHex(a, b) {
|
|
575
|
+
if (a.length !== b.length) return false;
|
|
576
|
+
let diff = 0;
|
|
577
|
+
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
578
|
+
return diff === 0;
|
|
579
|
+
}
|
|
580
|
+
async function proveDesktopServer(baseUrl, token, options = {}) {
|
|
581
|
+
let url;
|
|
582
|
+
try {
|
|
583
|
+
url = new URL(baseUrl);
|
|
584
|
+
} catch {
|
|
585
|
+
return "unreachable";
|
|
586
|
+
}
|
|
587
|
+
const request3 = options.request ?? ((target, init) => fetch(target, { ...init, redirect: "error" }));
|
|
588
|
+
const challenge = newDesktopChallenge();
|
|
589
|
+
let res;
|
|
590
|
+
try {
|
|
591
|
+
res = await request3(new URL("/api/health", url).href, {
|
|
592
|
+
headers: { [DESKTOP_CHALLENGE_HEADER]: challenge },
|
|
593
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? PROOF_TIMEOUT_MS)
|
|
594
|
+
});
|
|
595
|
+
} catch {
|
|
596
|
+
return "unreachable";
|
|
597
|
+
}
|
|
598
|
+
const proof = res.headers.get(DESKTOP_PROOF_HEADER);
|
|
599
|
+
if (!proof) return res.status === 200 ? "unproven" : "unreachable";
|
|
600
|
+
const port = Number(url.port || (url.protocol === "https:" ? 443 : 80));
|
|
601
|
+
return sameHex(proof, await desktopTokenProof(token, port, challenge)) ? "proven" : "unproven";
|
|
602
|
+
}
|
|
603
|
+
function shareInFlight() {
|
|
604
|
+
const running = /* @__PURE__ */ new Map();
|
|
605
|
+
return (key, check) => {
|
|
606
|
+
const existing = running.get(key);
|
|
607
|
+
if (existing) return existing;
|
|
608
|
+
const started = check().finally(() => {
|
|
609
|
+
if (running.get(key) === started) running.delete(key);
|
|
610
|
+
});
|
|
611
|
+
running.set(key, started);
|
|
612
|
+
return started;
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
357
616
|
// src/internal/support/logger.ts
|
|
358
617
|
var Logger = class {
|
|
359
618
|
constructor(verbose = false) {
|
|
@@ -385,6 +644,15 @@ var HttpError = class extends Error {
|
|
|
385
644
|
this.name = "HttpError";
|
|
386
645
|
}
|
|
387
646
|
};
|
|
647
|
+
var DesktopNotProvenError = class extends Error {
|
|
648
|
+
constructor(serverUrl, proof) {
|
|
649
|
+
super(
|
|
650
|
+
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.`
|
|
651
|
+
);
|
|
652
|
+
this.name = "DesktopNotProvenError";
|
|
653
|
+
if (proof === "unreachable") this.code = "ECONNREFUSED";
|
|
654
|
+
}
|
|
655
|
+
};
|
|
388
656
|
var FAILURE_DETAIL_MAX = 500;
|
|
389
657
|
function failureDetail(res) {
|
|
390
658
|
let text = null;
|
|
@@ -437,17 +705,21 @@ var HttpClient = class {
|
|
|
437
705
|
* @param uploadTimeout Socket inactivity timeout of a multipart upload, or of
|
|
438
706
|
* a run's results sent as JSON, in ms (default 10 min): the
|
|
439
707
|
* dashboard answers one only once it has stored all of it.
|
|
708
|
+
* @param desktopToken The desktop app's token when `serverUrl` is the app's: a request that carries it waits for
|
|
709
|
+
* the server to prove it holds it, and without the proof nothing is sent.
|
|
440
710
|
*/
|
|
441
|
-
constructor(serverUrl, logger2 = new Logger(), timeout = 3e4, uploadTimeout = 10 * 60 * 1e3) {
|
|
711
|
+
constructor(serverUrl, logger2 = new Logger(), timeout = 3e4, uploadTimeout = 10 * 60 * 1e3, desktopToken = null) {
|
|
442
712
|
this.serverUrl = serverUrl;
|
|
443
713
|
this.logger = logger2;
|
|
444
714
|
this.timeout = timeout;
|
|
445
715
|
this.uploadTimeout = uploadTimeout;
|
|
716
|
+
this.desktopToken = desktopToken;
|
|
446
717
|
/** Requests in flight, so `close` can abort them. */
|
|
447
718
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
448
719
|
/** Set by `close`: every later request fails with this reason. */
|
|
449
720
|
this.closedReason = null;
|
|
450
721
|
this.loginAnnounced = false;
|
|
722
|
+
this.proofsInFlight = shareInFlight();
|
|
451
723
|
this.warnIfInsecureTransport();
|
|
452
724
|
}
|
|
453
725
|
/**
|
|
@@ -607,7 +879,21 @@ var HttpClient = class {
|
|
|
607
879
|
* Unified request core: transport, headers, auth, response accumulation, timeout. Nothing is sent to a `serverUrl`
|
|
608
880
|
* that is not an `http://` or `https://` URL.
|
|
609
881
|
*/
|
|
610
|
-
request(method, pathname, opts) {
|
|
882
|
+
async request(method, pathname, opts) {
|
|
883
|
+
if (!this.desktopToken || opts.auth !== this.desktopToken) return this.send(method, pathname, opts);
|
|
884
|
+
await this.requireDesktopProof();
|
|
885
|
+
return this.send(method, pathname, opts);
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Resolves once the server proved it holds the desktop token. Each request that carries the token asks for its own
|
|
889
|
+
* proof; requests that arrive while a proof is being asked share it, and a proof that has arrived is never used for
|
|
890
|
+
* a later request.
|
|
891
|
+
*/
|
|
892
|
+
async requireDesktopProof() {
|
|
893
|
+
const proof = await this.proofsInFlight("proof", () => proveDesktopServer(this.serverUrl, this.desktopToken));
|
|
894
|
+
if (proof !== "proven") throw new DesktopNotProvenError(this.serverUrl, proof);
|
|
895
|
+
}
|
|
896
|
+
send(method, pathname, opts) {
|
|
611
897
|
return new Promise((resolve4, reject) => {
|
|
612
898
|
if (this.closedReason !== null) {
|
|
613
899
|
reject(new Error(this.closedReason));
|
|
@@ -680,7 +966,7 @@ var HttpClient = class {
|
|
|
680
966
|
}
|
|
681
967
|
applyAuth(headers, auth) {
|
|
682
968
|
if (!auth) return;
|
|
683
|
-
if (auth.startsWith("pd_")) {
|
|
969
|
+
if (auth.startsWith("pd_") || auth.startsWith(REQUEST_TOKEN_PREFIX)) {
|
|
684
970
|
headers["Authorization"] = `Bearer ${auth}`;
|
|
685
971
|
} else {
|
|
686
972
|
headers["Cookie"] = auth;
|
|
@@ -689,14 +975,14 @@ var HttpClient = class {
|
|
|
689
975
|
};
|
|
690
976
|
|
|
691
977
|
// src/internal/support/instance-id.ts
|
|
692
|
-
var
|
|
693
|
-
var
|
|
978
|
+
var crypto3 = __toESM(require("crypto"));
|
|
979
|
+
var os3 = __toESM(require("os"));
|
|
694
980
|
function hashForProject(projectName) {
|
|
695
|
-
return
|
|
981
|
+
return crypto3.createHash("sha1").update(projectName).digest("hex").slice(0, 16);
|
|
696
982
|
}
|
|
697
983
|
function computeInstanceId(projectName, runLabel) {
|
|
698
|
-
const seed = runLabel ? `${projectName}|${runLabel}` : `${
|
|
699
|
-
return
|
|
984
|
+
const seed = runLabel ? `${projectName}|${runLabel}` : `${os3.hostname()}|${projectName}`;
|
|
985
|
+
return crypto3.createHash("sha256").update(seed).digest("hex").slice(0, 16);
|
|
700
986
|
}
|
|
701
987
|
|
|
702
988
|
// src/internal/support/shard-info.ts
|
|
@@ -717,67 +1003,8 @@ function resolveShardInfo(config, env = process.env) {
|
|
|
717
1003
|
var import_node_child_process = require("child_process");
|
|
718
1004
|
var import_node_util = require("util");
|
|
719
1005
|
|
|
720
|
-
// ../core/src/
|
|
721
|
-
var
|
|
722
|
-
var MAX_VIEW_FRAME_BASE64 = 4 * Math.ceil(MAX_VIEW_FRAME / 3);
|
|
723
|
-
|
|
724
|
-
// ../core/src/run-channel.ts
|
|
725
|
-
var RUN_INTENTS = ["pick", "record", "assert", "assert-region"];
|
|
726
|
-
var RUN_TAKES = [
|
|
727
|
-
...RUN_INTENTS,
|
|
728
|
-
"requests",
|
|
729
|
-
"mock",
|
|
730
|
-
"locator",
|
|
731
|
-
"view",
|
|
732
|
-
"input",
|
|
733
|
-
"input-clicks",
|
|
734
|
-
"pick-at",
|
|
735
|
-
"agent",
|
|
736
|
-
"events",
|
|
737
|
-
"bind",
|
|
738
|
-
"end",
|
|
739
|
-
"share"
|
|
740
|
-
];
|
|
741
|
-
var MAX_KEPT_BODY = 256 * 1024;
|
|
742
|
-
var MAX_REGION_SNAPSHOT = 1024 * 1024;
|
|
743
|
-
var MAX_AGENT_SNAPSHOT = 1024 * 1024;
|
|
744
|
-
|
|
745
|
-
// src/internal/support/test-paths.ts
|
|
746
|
-
var path3 = __toESM(require("path"));
|
|
747
|
-
function configDirFromConfig(config) {
|
|
748
|
-
if (config?.configFile) return path3.dirname(config.configFile);
|
|
749
|
-
if (config?.rootDir) return config.rootDir;
|
|
750
|
-
return process.cwd();
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
// src/internal/collect/metadata-collector.ts
|
|
754
|
-
var DETACHED_HEAD = "HEAD";
|
|
755
|
-
function resolveScmBranch(env, gitBranch) {
|
|
756
|
-
const pick = (...names) => {
|
|
757
|
-
for (const name of names) {
|
|
758
|
-
const value = env[name]?.trim();
|
|
759
|
-
if (value) return value;
|
|
760
|
-
}
|
|
761
|
-
return void 0;
|
|
762
|
-
};
|
|
763
|
-
const override = env.PIWI_BRANCH?.trim();
|
|
764
|
-
if (override) return override;
|
|
765
|
-
let provider;
|
|
766
|
-
if (env.JENKINS_URL) provider = pick("CHANGE_BRANCH", "BRANCH_NAME");
|
|
767
|
-
else if (env.GITHUB_ACTIONS) provider = pick("GITHUB_HEAD_REF", "GITHUB_REF_NAME");
|
|
768
|
-
else if (env.GITLAB_CI) provider = pick("CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", "CI_COMMIT_REF_NAME");
|
|
769
|
-
else if (env.CIRCLECI) provider = pick("CIRCLE_BRANCH");
|
|
770
|
-
else if (env.TRAVIS) provider = pick("TRAVIS_PULL_REQUEST_BRANCH", "TRAVIS_BRANCH");
|
|
771
|
-
else if (env.TF_BUILD) provider = pick("SYSTEM_PULLREQUEST_SOURCEBRANCH", "BUILD_SOURCEBRANCHNAME");
|
|
772
|
-
else if (env.BITBUCKET_BUILD_NUMBER) provider = pick("BITBUCKET_BRANCH");
|
|
773
|
-
if (provider) return normalizeRef(provider);
|
|
774
|
-
const trimmed = gitBranch?.trim();
|
|
775
|
-
if (trimmed && trimmed !== DETACHED_HEAD) return trimmed;
|
|
776
|
-
return void 0;
|
|
777
|
-
}
|
|
778
|
-
function normalizeRef(ref) {
|
|
779
|
-
return ref.replace(/^refs\/heads\//, "");
|
|
780
|
-
}
|
|
1006
|
+
// ../core/src/live-layer-bounds.ts
|
|
1007
|
+
var MAX_LANE_TEXT = 96 * 1024;
|
|
781
1008
|
|
|
782
1009
|
// ../core/src/locator-chain.ts
|
|
783
1010
|
var LOCATING_METHODS = /* @__PURE__ */ new Set([
|
|
@@ -855,6 +1082,20 @@ var WHOLE_SHAPES = SECRET_SHAPES.map(
|
|
|
855
1082
|
(re) => new RegExp(`^(?:${re.source})$`, re.flags.replace("g", ""))
|
|
856
1083
|
);
|
|
857
1084
|
|
|
1085
|
+
// ../core/src/live-layers.ts
|
|
1086
|
+
var MAX_EVENT_MS = 7 * 24 * 36e5;
|
|
1087
|
+
var MAX_LANE_TEXT_BYTES = 192 * 1024;
|
|
1088
|
+
var MAX_LANE_THUMB = 128 * 1024;
|
|
1089
|
+
var MAX_LANE_THUMB_BASE64 = 4 * Math.ceil(MAX_LANE_THUMB / 3);
|
|
1090
|
+
var MAX_FILMSTRIP_BYTES = 1024 * 1024;
|
|
1091
|
+
|
|
1092
|
+
// ../core/src/live-inspect.ts
|
|
1093
|
+
var MAX_SNAPSHOT_BYTES = 4 * 1024 * 1024;
|
|
1094
|
+
var MAX_RESOURCE_BYTES = 2 * 1024 * 1024;
|
|
1095
|
+
var MAX_SNAPSHOT_BACKLOG = 16 * 1024 * 1024;
|
|
1096
|
+
var KEPT_DATA = /data:(?:image\/[a-z0-9.+-]+|font\/[a-z0-9.+-]+|application\/(?:font-|x-font-)[a-z0-9.+-]+|application\/vnd\.ms-fontobject)(?:;[a-z0-9.+=-]+)*;base64,[A-Za-z0-9+/=]+/gi;
|
|
1097
|
+
var KEPT_DATA_URL = new RegExp(`^${KEPT_DATA.source}$`, "i");
|
|
1098
|
+
|
|
858
1099
|
// ../core/src/live-view.ts
|
|
859
1100
|
var LIVE_FRAME_BYTE_RATE = 256 * 1024;
|
|
860
1101
|
var MAX_LIVE_FRAME = 192 * 1024;
|
|
@@ -864,63 +1105,77 @@ var KEY = /^pdl_[A-Za-z0-9_-]{43}$/;
|
|
|
864
1105
|
function isLiveViewKey(value) {
|
|
865
1106
|
return typeof value === "string" && KEY.test(value);
|
|
866
1107
|
}
|
|
1108
|
+
var MAX_LIVE_HEADER = 64 * 1024;
|
|
1109
|
+
var MAX_LIVE_FRAME_MESSAGE = 8 + MAX_LIVE_HEADER + MAX_LIVE_FRAME;
|
|
1110
|
+
var MAX_LIVE_INSPECT_MESSAGE = 8 + MAX_LIVE_HEADER + MAX_SNAPSHOT_BYTES;
|
|
1111
|
+
var LIVE_HEARTBEAT = new Uint8Array(8);
|
|
1112
|
+
var ASK_TO_WATCH_MS = 5 * 6e4;
|
|
867
1113
|
|
|
868
|
-
// src/
|
|
869
|
-
var
|
|
870
|
-
var
|
|
1114
|
+
// ../core/src/run-view.ts
|
|
1115
|
+
var MAX_VIEW_FRAME = 384 * 1024;
|
|
1116
|
+
var MAX_VIEW_FRAME_BASE64 = 4 * Math.ceil(MAX_VIEW_FRAME / 3);
|
|
871
1117
|
|
|
872
|
-
// src/
|
|
873
|
-
var
|
|
874
|
-
var
|
|
875
|
-
|
|
1118
|
+
// ../core/src/run-channel.ts
|
|
1119
|
+
var RUN_INTENTS = ["pick", "record", "assert", "assert-region"];
|
|
1120
|
+
var RUN_TAKES = [
|
|
1121
|
+
...RUN_INTENTS,
|
|
1122
|
+
"requests",
|
|
1123
|
+
"mock",
|
|
1124
|
+
"locator",
|
|
1125
|
+
"view",
|
|
1126
|
+
"input",
|
|
1127
|
+
"input-clicks",
|
|
1128
|
+
"pick-at",
|
|
1129
|
+
"agent",
|
|
1130
|
+
"events",
|
|
1131
|
+
"bind",
|
|
1132
|
+
"end",
|
|
1133
|
+
"share"
|
|
1134
|
+
];
|
|
1135
|
+
var MAX_KEPT_BODY = 256 * 1024;
|
|
1136
|
+
var MAX_REGION_SNAPSHOT = 1024 * 1024;
|
|
1137
|
+
var MAX_AGENT_SNAPSHOT = 1024 * 1024;
|
|
1138
|
+
|
|
1139
|
+
// src/internal/support/test-paths.ts
|
|
876
1140
|
var path4 = __toESM(require("path"));
|
|
877
|
-
function
|
|
878
|
-
if (
|
|
879
|
-
|
|
880
|
-
|
|
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;
|
|
1141
|
+
function configDirFromConfig(config) {
|
|
1142
|
+
if (config?.configFile) return path4.dirname(config.configFile);
|
|
1143
|
+
if (config?.rootDir) return config.rootDir;
|
|
1144
|
+
return process.cwd();
|
|
897
1145
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1146
|
+
|
|
1147
|
+
// src/internal/collect/metadata-collector.ts
|
|
1148
|
+
var DETACHED_HEAD = "HEAD";
|
|
1149
|
+
function resolveScmBranch(env, gitBranch) {
|
|
1150
|
+
const pick = (...names) => {
|
|
1151
|
+
for (const name of names) {
|
|
1152
|
+
const value = env[name]?.trim();
|
|
1153
|
+
if (value) return value;
|
|
1154
|
+
}
|
|
1155
|
+
return void 0;
|
|
1156
|
+
};
|
|
1157
|
+
const override = env.PIWI_BRANCH?.trim();
|
|
1158
|
+
if (override) return override;
|
|
1159
|
+
let provider;
|
|
1160
|
+
if (env.JENKINS_URL) provider = pick("CHANGE_BRANCH", "BRANCH_NAME");
|
|
1161
|
+
else if (env.GITHUB_ACTIONS) provider = pick("GITHUB_HEAD_REF", "GITHUB_REF_NAME");
|
|
1162
|
+
else if (env.GITLAB_CI) provider = pick("CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", "CI_COMMIT_REF_NAME");
|
|
1163
|
+
else if (env.CIRCLECI) provider = pick("CIRCLE_BRANCH");
|
|
1164
|
+
else if (env.TRAVIS) provider = pick("TRAVIS_PULL_REQUEST_BRANCH", "TRAVIS_BRANCH");
|
|
1165
|
+
else if (env.TF_BUILD) provider = pick("SYSTEM_PULLREQUEST_SOURCEBRANCH", "BUILD_SOURCEBRANCHNAME");
|
|
1166
|
+
else if (env.BITBUCKET_BUILD_NUMBER) provider = pick("BITBUCKET_BRANCH");
|
|
1167
|
+
if (provider) return normalizeRef(provider);
|
|
1168
|
+
const trimmed = gitBranch?.trim();
|
|
1169
|
+
if (trimmed && trimmed !== DETACHED_HEAD) return trimmed;
|
|
1170
|
+
return void 0;
|
|
907
1171
|
}
|
|
908
|
-
function
|
|
909
|
-
|
|
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
|
-
}
|
|
1172
|
+
function normalizeRef(ref) {
|
|
1173
|
+
return ref.replace(/^refs\/heads\//, "");
|
|
921
1174
|
}
|
|
922
1175
|
|
|
923
1176
|
// src/internal/support/setup-file.ts
|
|
1177
|
+
var path5 = __toESM(require("path"));
|
|
1178
|
+
var fs4 = __toESM(require("fs"));
|
|
924
1179
|
var logger = new Logger();
|
|
925
1180
|
function getSetupFilePath(projectName, pid = process.pid) {
|
|
926
1181
|
return path5.join(privateTempDir(), `piwi-dashboard-setup-${hashForProject(projectName)}-${pid}.json`);
|
|
@@ -936,6 +1191,24 @@ function writeSetupFailure(projectName, failed) {
|
|
|
936
1191
|
}
|
|
937
1192
|
}
|
|
938
1193
|
|
|
1194
|
+
// src/internal/support/run-url.ts
|
|
1195
|
+
function runUrl(serverUrl, runId) {
|
|
1196
|
+
return `${serverUrl.replace(/\/+$/, "")}/test-runs/${runId}`;
|
|
1197
|
+
}
|
|
1198
|
+
var UNREADABLE = /[\s()<>"'`\\\u0000-\u001f\u007f-\u009f]/;
|
|
1199
|
+
function answeredRunUrl(answer, serverUrl, runId) {
|
|
1200
|
+
const named = answer?.runUrl;
|
|
1201
|
+
if (typeof named === "string" && named.length <= 2048 && !UNREADABLE.test(named)) {
|
|
1202
|
+
if (/^\/[^/]/.test(named)) return `${serverUrl.replace(/\/+$/, "")}${named}`;
|
|
1203
|
+
try {
|
|
1204
|
+
const url = new URL(named);
|
|
1205
|
+
if (url.protocol === "http:" || url.protocol === "https:") return url.href;
|
|
1206
|
+
} catch {
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
return runUrl(serverUrl, runId);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
939
1212
|
// src/internal/support/aria-sampling.ts
|
|
940
1213
|
var path6 = __toESM(require("path"));
|
|
941
1214
|
var fs5 = __toESM(require("fs"));
|
|
@@ -1198,8 +1471,8 @@ var MAX_MANIFEST_BYTES = 4 * 1024 * 1024;
|
|
|
1198
1471
|
function instrumentationManifestUrls(baseUrl) {
|
|
1199
1472
|
const base = new URL(baseUrl);
|
|
1200
1473
|
const root = new URL(INSTRUMENTATION_MANIFEST_PATH, base).toString();
|
|
1201
|
-
const
|
|
1202
|
-
return
|
|
1474
|
+
const path13 = base.pathname.replace(/\/+$/, "");
|
|
1475
|
+
return path13 ? [new URL(`${path13}${INSTRUMENTATION_MANIFEST_PATH}`, base).toString(), root] : [root];
|
|
1203
1476
|
}
|
|
1204
1477
|
async function fetchInstrumentationManifest(baseUrl, fetchImpl = fetch) {
|
|
1205
1478
|
try {
|
|
@@ -1218,6 +1491,7 @@ async function fetchManifestAt(manifestUrl, fetchImpl) {
|
|
|
1218
1491
|
const res = await fetchImpl(manifestUrl, { signal: AbortSignal.timeout(INSTRUMENTATION_FETCH_TIMEOUT_MS) });
|
|
1219
1492
|
return res.ok ? parseManifestJson(await res.text()) : null;
|
|
1220
1493
|
}
|
|
1494
|
+
var MAX_ENVIRONMENT_BYTES = 64 * 1024;
|
|
1221
1495
|
|
|
1222
1496
|
// src/internal/manifest/run-manifests.ts
|
|
1223
1497
|
async function lookupProjectId(httpClient, auth, projectName) {
|
|
@@ -1231,7 +1505,7 @@ async function uploadManifest(httpClient, auth, projectId, upload, logger2) {
|
|
|
1231
1505
|
}
|
|
1232
1506
|
|
|
1233
1507
|
// src/internal/collect/source-checksums.ts
|
|
1234
|
-
var
|
|
1508
|
+
var crypto4 = __toESM(require("crypto"));
|
|
1235
1509
|
var fs7 = __toESM(require("fs"));
|
|
1236
1510
|
var path8 = __toESM(require("path"));
|
|
1237
1511
|
|
|
@@ -1299,9 +1573,11 @@ function getReporterVersion() {
|
|
|
1299
1573
|
var import_node_crypto = require("crypto");
|
|
1300
1574
|
var fs9 = __toESM(require("fs"));
|
|
1301
1575
|
var path11 = __toESM(require("path"));
|
|
1576
|
+
var RUN_LOG_PREFIX = "piwi-run-log-";
|
|
1302
1577
|
var READ_MS = 1e3;
|
|
1303
1578
|
function relayRunLog(print, env = process.env) {
|
|
1304
|
-
|
|
1579
|
+
sweepStalePrivateFiles(RUN_LOG_PREFIX);
|
|
1580
|
+
const file = path11.join(privateTempDir(), `${RUN_LOG_PREFIX}${(0, import_node_crypto.randomBytes)(12).toString("hex")}.txt`);
|
|
1305
1581
|
writePrivateFile(file, "");
|
|
1306
1582
|
env[PIWI_RUN_LOG_ENV] = file;
|
|
1307
1583
|
let printed = 0;
|
|
@@ -1311,6 +1587,7 @@ function relayRunLog(print, env = process.env) {
|
|
|
1311
1587
|
const found = readPrivateFile(file);
|
|
1312
1588
|
if (!found || !("text" in found)) return;
|
|
1313
1589
|
text = found.text;
|
|
1590
|
+
keepPrivateFileLive(file);
|
|
1314
1591
|
} catch {
|
|
1315
1592
|
return;
|
|
1316
1593
|
}
|
|
@@ -1329,6 +1606,44 @@ function relayRunLog(print, env = process.env) {
|
|
|
1329
1606
|
};
|
|
1330
1607
|
}
|
|
1331
1608
|
|
|
1609
|
+
// src/internal/support/ci-output.ts
|
|
1610
|
+
var fs10 = __toESM(require("fs"));
|
|
1611
|
+
var path12 = __toESM(require("path"));
|
|
1612
|
+
|
|
1613
|
+
// src/internal/support/terminal.ts
|
|
1614
|
+
function readsProgress(env) {
|
|
1615
|
+
return !!env.WT_SESSION || env.ConEmuANSI === "ON" || env.TERM_PROGRAM === "ghostty";
|
|
1616
|
+
}
|
|
1617
|
+
function terminalFeatures(env, isTerminal) {
|
|
1618
|
+
const setting = env[PIWI_TERMINAL_PROGRESS_ENV]?.trim().toLowerCase();
|
|
1619
|
+
if (!isTerminal || detectCi(env) || env.TERM === "dumb" || ["off", "false", "0", "no"].includes(setting ?? "")) {
|
|
1620
|
+
return { links: false, progress: false };
|
|
1621
|
+
}
|
|
1622
|
+
return { links: true, progress: ["on", "true", "1", "yes"].includes(setting ?? "") || readsProgress(env) };
|
|
1623
|
+
}
|
|
1624
|
+
var OSC = "\x1B]";
|
|
1625
|
+
var ST = "\x1B\\";
|
|
1626
|
+
var TERMINAL_PROGRESS_CLEAR = `${OSC}9;4;0;0${ST}`;
|
|
1627
|
+
var CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
|
|
1628
|
+
function terminalLink(url, text = url) {
|
|
1629
|
+
const plain = text.replace(/[\u0000-\u001f\u007f-\u009f]/g, "");
|
|
1630
|
+
if (CONTROL.test(url) || plain !== text) return plain;
|
|
1631
|
+
return `${OSC}8;;${url}${ST}${text}${OSC}8;;${ST}`;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
// src/internal/support/ci-output.ts
|
|
1635
|
+
function announceLiveRun(runUrl2, logger2, env = process.env) {
|
|
1636
|
+
logger2.info(`View live progress: ${shownUrl(runUrl2, env)}`);
|
|
1637
|
+
if (env.GITHUB_ACTIONS) process.stdout.write(`::notice title=Piwi live run::${workflowCommandValue(runUrl2)}
|
|
1638
|
+
`);
|
|
1639
|
+
}
|
|
1640
|
+
function shownUrl(url, env) {
|
|
1641
|
+
return terminalFeatures(env, !!process.stdout.isTTY).links ? terminalLink(url) : url;
|
|
1642
|
+
}
|
|
1643
|
+
function workflowCommandValue(value) {
|
|
1644
|
+
return value.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1332
1647
|
// src/public/global-setup.ts
|
|
1333
1648
|
var relaying = false;
|
|
1334
1649
|
function createGlobalSetup(options, userSetup) {
|
|
@@ -1374,7 +1689,13 @@ function createGlobalSetup(options, userSetup) {
|
|
|
1374
1689
|
if (userSetup) return userSetup(config);
|
|
1375
1690
|
return;
|
|
1376
1691
|
}
|
|
1377
|
-
const httpClient = new HttpClient(
|
|
1692
|
+
const httpClient = new HttpClient(
|
|
1693
|
+
opts.serverUrl,
|
|
1694
|
+
logger2,
|
|
1695
|
+
void 0,
|
|
1696
|
+
void 0,
|
|
1697
|
+
usedDesktopToken() ? opts.apiKey ?? null : null
|
|
1698
|
+
);
|
|
1378
1699
|
const registers = opts.streaming !== false;
|
|
1379
1700
|
let registered = false;
|
|
1380
1701
|
try {
|
|
@@ -1453,14 +1774,16 @@ async function registerRun(httpClient, auth, opts, config, logger2) {
|
|
|
1453
1774
|
throw new Error("the answer to /api/test-runs/setup names no run");
|
|
1454
1775
|
}
|
|
1455
1776
|
const liveViewKey = response.liveView?.key;
|
|
1777
|
+
const runUrl2 = answeredRunUrl(response, httpClient.baseUrl, response.runId);
|
|
1456
1778
|
writeSetupInfo({
|
|
1457
1779
|
runId: response.runId,
|
|
1458
1780
|
setupToken: response.setupToken,
|
|
1459
1781
|
projectName: opts.projectName,
|
|
1460
1782
|
...isLiveViewKey(liveViewKey) ? { liveViewKey } : {},
|
|
1461
|
-
...response.liveView?.refused === "local" ? { liveViewLocal: true } : {}
|
|
1783
|
+
...response.liveView?.refused === "local" ? { liveViewLocal: true } : {},
|
|
1784
|
+
runUrl: runUrl2
|
|
1462
1785
|
});
|
|
1463
|
-
|
|
1786
|
+
announceLiveRun(runUrl2, logger2);
|
|
1464
1787
|
if (isLiveViewKey(liveViewKey) && detectCi(process.env) && !relaying) {
|
|
1465
1788
|
try {
|
|
1466
1789
|
const stopRelay = relayRunLog((line) => logger2.info(line));
|