@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
package/dist/cli/index.js
CHANGED
|
@@ -220,10 +220,10 @@ var Parser = class {
|
|
|
220
220
|
this.i += 2;
|
|
221
221
|
continue;
|
|
222
222
|
}
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
225
|
-
out += String.fromCodePoint(parseInt(
|
|
226
|
-
this.i += 1 +
|
|
223
|
+
const hex2 = next === "u" && this.src[this.i + 2] === "{" ? /^u\{([0-9a-fA-F]{1,6})\}/.exec(this.src.slice(this.i + 1)) : next === "u" ? /^u([0-9a-fA-F]{4})/.exec(this.src.slice(this.i + 1)) : next === "x" ? /^x([0-9a-fA-F]{2})/.exec(this.src.slice(this.i + 1)) : null;
|
|
224
|
+
if (hex2) {
|
|
225
|
+
out += String.fromCodePoint(parseInt(hex2[1], 16));
|
|
226
|
+
this.i += 1 + hex2[0].length;
|
|
227
227
|
continue;
|
|
228
228
|
}
|
|
229
229
|
if (next === "u" || next === "x") this.fail("malformed escape");
|
|
@@ -487,7 +487,7 @@ function parseEntry(text) {
|
|
|
487
487
|
}
|
|
488
488
|
|
|
489
489
|
// src/internal/ai/keys.ts
|
|
490
|
-
var
|
|
490
|
+
var crypto2 = __toESM(require("crypto"));
|
|
491
491
|
var path3 = __toESM(require("path"));
|
|
492
492
|
var DEFAULT_AI_DIR = "__piwi__";
|
|
493
493
|
function normalizeTemplate(template) {
|
|
@@ -798,11 +798,11 @@ async function runAi(argv, env = process.env) {
|
|
|
798
798
|
}
|
|
799
799
|
|
|
800
800
|
// src/cli/bug.ts
|
|
801
|
-
var
|
|
802
|
-
var
|
|
801
|
+
var fs8 = __toESM(require("fs"));
|
|
802
|
+
var path11 = __toESM(require("path"));
|
|
803
803
|
|
|
804
804
|
// src/internal/config/env.ts
|
|
805
|
-
var
|
|
805
|
+
var path9 = __toESM(require("path"));
|
|
806
806
|
|
|
807
807
|
// src/internal/config/desktop.ts
|
|
808
808
|
var fs4 = __toESM(require("fs"));
|
|
@@ -820,14 +820,23 @@ function processAlive(pid) {
|
|
|
820
820
|
}
|
|
821
821
|
}
|
|
822
822
|
function readDesktopConfig(filePath2) {
|
|
823
|
+
const file = readDesktopFile(filePath2);
|
|
824
|
+
if (!file) return null;
|
|
825
|
+
if (file.pid !== null && !processAlive(file.pid)) return null;
|
|
826
|
+
return { url: file.url, token: file.token };
|
|
827
|
+
}
|
|
828
|
+
function readDesktopToken(filePath2) {
|
|
829
|
+
return readDesktopFile(filePath2)?.token ?? null;
|
|
830
|
+
}
|
|
831
|
+
function readDesktopFile(filePath2) {
|
|
823
832
|
try {
|
|
824
833
|
const parsed = JSON.parse(fs4.readFileSync(filePath2, "utf8"));
|
|
825
834
|
const url = parsed?.url;
|
|
826
835
|
const token = parsed?.token;
|
|
827
836
|
if (typeof url !== "string" || !url) return null;
|
|
828
837
|
if (typeof token !== "string" || !token) return null;
|
|
829
|
-
|
|
830
|
-
return { url, token };
|
|
838
|
+
const pid = Number.isInteger(parsed?.pid) && parsed.pid > 0 ? parsed.pid : null;
|
|
839
|
+
return { url, token, pid };
|
|
831
840
|
} catch {
|
|
832
841
|
return null;
|
|
833
842
|
}
|
|
@@ -854,6 +863,7 @@ function parseDotEnv(text) {
|
|
|
854
863
|
}
|
|
855
864
|
return out;
|
|
856
865
|
}
|
|
866
|
+
var DESKTOP_KEY_ENV = "PIWI_DESKTOP_KEY";
|
|
857
867
|
function resolvePiwiConnection(sources) {
|
|
858
868
|
const own = {
|
|
859
869
|
serverUrl: sources.flags?.serverUrl || sources.env?.PIWI_DASHBOARD_URL,
|
|
@@ -867,7 +877,12 @@ function resolvePiwiConnection(sources) {
|
|
|
867
877
|
const serverUrl = layer ? trim(layer.serverUrl) : desktop ? trim(desktop.url) : "";
|
|
868
878
|
if (!serverUrl) return null;
|
|
869
879
|
const desktopKey = desktop && trim(desktop.url) === serverUrl ? desktop.token : null;
|
|
870
|
-
|
|
880
|
+
const apiKey = layer?.apiKey || desktopKey || null;
|
|
881
|
+
const fromFile = apiKey !== null && apiKey === desktopKey && !layer?.apiKey;
|
|
882
|
+
const fromRun = apiKey !== null && layer === own && !sources.flags?.apiKey && apiKey === sources.env?.PIWI_API_KEY && sources.env?.[DESKTOP_KEY_ENV] === "1";
|
|
883
|
+
const knownToken = desktop?.token ?? sources.desktopToken ?? null;
|
|
884
|
+
const byValue = apiKey !== null && knownToken !== null && apiKey === knownToken;
|
|
885
|
+
return { serverUrl, apiKey, project, ...(fromFile || fromRun || byValue) && { desktop: true } };
|
|
871
886
|
}
|
|
872
887
|
|
|
873
888
|
// src/internal/config/dotenv.ts
|
|
@@ -886,6 +901,30 @@ function detectCi(env) {
|
|
|
886
901
|
);
|
|
887
902
|
}
|
|
888
903
|
|
|
904
|
+
// ../core/src/run-request.ts
|
|
905
|
+
var RUN_REQUEST_LIMITS = {
|
|
906
|
+
tests: { min: 1, max: 200 },
|
|
907
|
+
repeatEach: { min: 1, max: 10 },
|
|
908
|
+
workers: { min: 1, max: 4 },
|
|
909
|
+
/** How long a request waits for a target to claim it, in milliseconds. */
|
|
910
|
+
lifetimeMs: 2 * 60 * 1e3,
|
|
911
|
+
/**
|
|
912
|
+
* How often a target that holds a request calls the instance at least, in milliseconds: it hears its stops from the
|
|
913
|
+
* list of requests. Past this silence the instance ends the request as an error.
|
|
914
|
+
*/
|
|
915
|
+
silentTargetMs: 5 * 60 * 1e3,
|
|
916
|
+
/** How long a stop waits for the target to end a run, in milliseconds, before a second stop ends the request. */
|
|
917
|
+
stopGraceMs: 60 * 1e3
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
// src/internal/support/private-file.ts
|
|
921
|
+
var crypto3 = __toESM(require("crypto"));
|
|
922
|
+
var fs6 = __toESM(require("fs"));
|
|
923
|
+
var os3 = __toESM(require("os"));
|
|
924
|
+
var path8 = __toESM(require("path"));
|
|
925
|
+
var NO_FOLLOW = fs6.constants.O_NOFOLLOW ?? 0;
|
|
926
|
+
var NO_WAIT = fs6.constants.O_NONBLOCK ?? 0;
|
|
927
|
+
|
|
889
928
|
// ../core/src/rerun-args.ts
|
|
890
929
|
var RERUN_ARGS_ENV = "PIWI_RERUN_ARGS";
|
|
891
930
|
var WHITESPACE = /[ \t\r\n]/;
|
|
@@ -923,6 +962,7 @@ var DEFAULTS = {
|
|
|
923
962
|
liveFileUploads: true,
|
|
924
963
|
collectScmInfo: true,
|
|
925
964
|
collectCiInfo: true,
|
|
965
|
+
collectEnvironmentInfo: true,
|
|
926
966
|
collectPerformanceMetrics: true,
|
|
927
967
|
captureLocators: true,
|
|
928
968
|
capturePageState: true,
|
|
@@ -952,6 +992,7 @@ var DEFAULTS = {
|
|
|
952
992
|
var PIWI_ENV_KEYS = {
|
|
953
993
|
serverUrl: "PIWI_DASHBOARD_URL",
|
|
954
994
|
desktopApp: "PIWI_DESKTOP_APP",
|
|
995
|
+
desktopKey: "PIWI_DESKTOP_KEY",
|
|
955
996
|
projectName: "PIWI_PROJECT_NAME",
|
|
956
997
|
verbose: "PIWI_VERBOSE",
|
|
957
998
|
apiKey: "PIWI_API_KEY",
|
|
@@ -970,6 +1011,7 @@ var PIWI_ENV_KEYS = {
|
|
|
970
1011
|
failOnFlakyTests: "PIWI_FAIL_ON_FLAKY_TESTS",
|
|
971
1012
|
uploadTraces: "PIWI_UPLOAD_TRACES",
|
|
972
1013
|
uploadReport: "PIWI_UPLOAD_REPORT",
|
|
1014
|
+
collectEnvironmentInfo: "PIWI_COLLECT_ENVIRONMENT_INFO",
|
|
973
1015
|
captureLocators: "PIWI_CAPTURE_LOCATORS",
|
|
974
1016
|
capturePageState: "PIWI_CAPTURE_PAGE_STATE",
|
|
975
1017
|
capturePageInventory: "PIWI_CAPTURE_PAGE_INVENTORY",
|
|
@@ -1037,6 +1079,7 @@ var ENV_FALLBACK_SPECS = [
|
|
|
1037
1079
|
{ option: "failOnFlakyTests", env: PIWI_ENV_KEYS.failOnFlakyTests, kind: "bool" },
|
|
1038
1080
|
{ option: "uploadTraces", env: PIWI_ENV_KEYS.uploadTraces, kind: "bool" },
|
|
1039
1081
|
{ option: "uploadReport", env: PIWI_ENV_KEYS.uploadReport, kind: "bool" },
|
|
1082
|
+
{ option: "collectEnvironmentInfo", env: PIWI_ENV_KEYS.collectEnvironmentInfo, kind: "bool" },
|
|
1040
1083
|
{ option: "captureLocators", env: PIWI_ENV_KEYS.captureLocators, kind: "bool" },
|
|
1041
1084
|
{ option: "capturePageState", env: PIWI_ENV_KEYS.capturePageState, kind: "bool" },
|
|
1042
1085
|
{ option: "capturePageInventory", env: PIWI_ENV_KEYS.capturePageInventory, kind: "bool" },
|
|
@@ -1065,6 +1108,88 @@ var https = __toESM(require("https"));
|
|
|
1065
1108
|
var http = __toESM(require("http"));
|
|
1066
1109
|
var import_node_url2 = require("url");
|
|
1067
1110
|
var import_form_data = __toESM(require("form-data"));
|
|
1111
|
+
|
|
1112
|
+
// ../core/src/hmac.ts
|
|
1113
|
+
async function hmacSha256Hex(key, message) {
|
|
1114
|
+
const encoder = new TextEncoder();
|
|
1115
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
1116
|
+
"raw",
|
|
1117
|
+
encoder.encode(key),
|
|
1118
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
1119
|
+
false,
|
|
1120
|
+
["sign"]
|
|
1121
|
+
);
|
|
1122
|
+
return hex(new Uint8Array(await crypto.subtle.sign("HMAC", cryptoKey, encoder.encode(message))));
|
|
1123
|
+
}
|
|
1124
|
+
function randomHex(byteCount) {
|
|
1125
|
+
return hex(crypto.getRandomValues(new Uint8Array(byteCount)));
|
|
1126
|
+
}
|
|
1127
|
+
function hex(bytes) {
|
|
1128
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
// ../core/src/desktop-proof.ts
|
|
1132
|
+
var DESKTOP_CHALLENGE_HEADER = "x-piwi-desktop-challenge";
|
|
1133
|
+
var DESKTOP_PROOF_HEADER = "x-piwi-desktop-proof";
|
|
1134
|
+
function newDesktopChallenge() {
|
|
1135
|
+
return randomHex(32);
|
|
1136
|
+
}
|
|
1137
|
+
function desktopTokenProof(token, port, challenge) {
|
|
1138
|
+
return hmacSha256Hex(token, `piwi-desktop-proof:${port}:${challenge}`);
|
|
1139
|
+
}
|
|
1140
|
+
var PROOF_TIMEOUT_MS = 5e3;
|
|
1141
|
+
function sameHex(a, b) {
|
|
1142
|
+
if (a.length !== b.length) return false;
|
|
1143
|
+
let diff = 0;
|
|
1144
|
+
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
1145
|
+
return diff === 0;
|
|
1146
|
+
}
|
|
1147
|
+
async function proveDesktopServer(baseUrl, token, options = {}) {
|
|
1148
|
+
let url;
|
|
1149
|
+
try {
|
|
1150
|
+
url = new URL(baseUrl);
|
|
1151
|
+
} catch {
|
|
1152
|
+
return "unreachable";
|
|
1153
|
+
}
|
|
1154
|
+
const request = options.request ?? ((target, init) => fetch(target, { ...init, redirect: "error" }));
|
|
1155
|
+
const challenge = newDesktopChallenge();
|
|
1156
|
+
let res;
|
|
1157
|
+
try {
|
|
1158
|
+
res = await request(new URL("/api/health", url).href, {
|
|
1159
|
+
headers: { [DESKTOP_CHALLENGE_HEADER]: challenge },
|
|
1160
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? PROOF_TIMEOUT_MS)
|
|
1161
|
+
});
|
|
1162
|
+
} catch {
|
|
1163
|
+
return "unreachable";
|
|
1164
|
+
}
|
|
1165
|
+
const proof = res.headers.get(DESKTOP_PROOF_HEADER);
|
|
1166
|
+
if (!proof) return res.status === 200 ? "unproven" : "unreachable";
|
|
1167
|
+
const port = Number(url.port || (url.protocol === "https:" ? 443 : 80));
|
|
1168
|
+
return sameHex(proof, await desktopTokenProof(token, port, challenge)) ? "proven" : "unproven";
|
|
1169
|
+
}
|
|
1170
|
+
function shareInFlight() {
|
|
1171
|
+
const running = /* @__PURE__ */ new Map();
|
|
1172
|
+
return (key, check) => {
|
|
1173
|
+
const existing = running.get(key);
|
|
1174
|
+
if (existing) return existing;
|
|
1175
|
+
const started = check().finally(() => {
|
|
1176
|
+
if (running.get(key) === started) running.delete(key);
|
|
1177
|
+
});
|
|
1178
|
+
running.set(key, started);
|
|
1179
|
+
return started;
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
// src/internal/transport/http-client.ts
|
|
1184
|
+
var DesktopNotProvenError = class extends Error {
|
|
1185
|
+
constructor(serverUrl, proof) {
|
|
1186
|
+
super(
|
|
1187
|
+
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.`
|
|
1188
|
+
);
|
|
1189
|
+
this.name = "DesktopNotProvenError";
|
|
1190
|
+
if (proof === "unreachable") this.code = "ECONNREFUSED";
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1068
1193
|
var FAILURE_DETAIL_MAX = 500;
|
|
1069
1194
|
function failureDetail(res) {
|
|
1070
1195
|
let text = null;
|
|
@@ -1081,16 +1206,16 @@ function failureDetail(res) {
|
|
|
1081
1206
|
}
|
|
1082
1207
|
|
|
1083
1208
|
// src/internal/support/connection.ts
|
|
1084
|
-
var
|
|
1085
|
-
var
|
|
1209
|
+
var fs7 = __toESM(require("fs"));
|
|
1210
|
+
var path10 = __toESM(require("path"));
|
|
1086
1211
|
var import_node_child_process2 = require("child_process");
|
|
1087
1212
|
var CONFIG_NAMES = ["playwright.config.ts", "playwright.config.js", "playwright.config.mjs", "playwright.config.cjs"];
|
|
1088
1213
|
function findPlaywrightRoot(from, root) {
|
|
1089
|
-
const top = root ?
|
|
1090
|
-
let dir =
|
|
1214
|
+
const top = root ? path10.resolve(root) : null;
|
|
1215
|
+
let dir = path10.resolve(from);
|
|
1091
1216
|
for (; ; ) {
|
|
1092
|
-
if (CONFIG_NAMES.some((name) =>
|
|
1093
|
-
const parent =
|
|
1217
|
+
if (CONFIG_NAMES.some((name) => fs7.existsSync(path10.join(dir, name)))) return dir;
|
|
1218
|
+
const parent = path10.dirname(dir);
|
|
1094
1219
|
if (dir === top || parent === dir) return null;
|
|
1095
1220
|
dir = parent;
|
|
1096
1221
|
}
|
|
@@ -1102,7 +1227,7 @@ function gitRoot(cwd) {
|
|
|
1102
1227
|
encoding: "utf-8",
|
|
1103
1228
|
stdio: ["ignore", "pipe", "ignore"]
|
|
1104
1229
|
}).trim();
|
|
1105
|
-
return out ?
|
|
1230
|
+
return out ? path10.resolve(out) : null;
|
|
1106
1231
|
} catch {
|
|
1107
1232
|
return null;
|
|
1108
1233
|
}
|
|
@@ -1110,14 +1235,14 @@ function gitRoot(cwd) {
|
|
|
1110
1235
|
function connectionFolders(cwd) {
|
|
1111
1236
|
const root = gitRoot(cwd);
|
|
1112
1237
|
const dirs = [findPlaywrightRoot(cwd, root) ?? cwd, cwd, root];
|
|
1113
|
-
return [...new Set(dirs.filter((dir) => dir !== null).map((dir) =>
|
|
1238
|
+
return [...new Set(dirs.filter((dir) => dir !== null).map((dir) => path10.resolve(dir)))];
|
|
1114
1239
|
}
|
|
1115
1240
|
function projectOf(source) {
|
|
1116
1241
|
const project = source[PIWI_ENV_KEYS.projectName];
|
|
1117
1242
|
return project ? { [PIWI_ENV_KEYS.projectName]: project } : {};
|
|
1118
1243
|
}
|
|
1119
1244
|
function readDotEnvConnection(dirs) {
|
|
1120
|
-
const files = dirs.map((dir) => readDotEnv(
|
|
1245
|
+
const files = dirs.map((dir) => readDotEnv(path10.join(dir, ".env")));
|
|
1121
1246
|
const withUrl = files.find((file) => file[PIWI_ENV_KEYS.serverUrl]);
|
|
1122
1247
|
const vars = {};
|
|
1123
1248
|
if (withUrl) {
|
|
@@ -1135,10 +1260,12 @@ function resolveCliConnection(flags, env, dirs, command = "piwi") {
|
|
|
1135
1260
|
const urlSet = Boolean(flags.serverUrl || env[PIWI_ENV_KEYS.serverUrl] || dotEnv[PIWI_ENV_KEYS.serverUrl]);
|
|
1136
1261
|
const keySet = Boolean(flags.apiKey || env[PIWI_ENV_KEYS.apiKey] || anyKey);
|
|
1137
1262
|
const readDesktop = mode !== "off" && (preferLocally || urlSet || !keySet);
|
|
1138
|
-
const
|
|
1263
|
+
const discoveryPath = env[PIWI_DESKTOP_CONFIG_ENV] || defaultDesktopConfigPath();
|
|
1264
|
+
const desktop = readDesktop ? readDesktopConfig(discoveryPath) : null;
|
|
1265
|
+
const desktopToken = keySet ? readDesktopToken(discoveryPath) : desktop?.token ?? null;
|
|
1139
1266
|
const preferDesktop = desktop !== null && preferLocally;
|
|
1140
1267
|
const connection = resolvePiwiConnection(
|
|
1141
|
-
preferDesktop ? { flags, env: projectOf(env), dotEnv: projectOf(dotEnv), desktop } : { flags, env, dotEnv, desktop }
|
|
1268
|
+
preferDesktop ? { flags, env: projectOf(env), dotEnv: projectOf(dotEnv), desktop, desktopToken } : { flags, env, dotEnv, desktop, desktopToken }
|
|
1142
1269
|
);
|
|
1143
1270
|
if (connection && flags.apiKey && connection.apiKey !== flags.apiKey) {
|
|
1144
1271
|
const from = !preferDesktop && dotEnv[PIWI_ENV_KEYS.serverUrl] ? "a .env file" : "the desktop app";
|
|
@@ -1146,8 +1273,34 @@ function resolveCliConnection(flags, env, dirs, command = "piwi") {
|
|
|
1146
1273
|
`${command}: --api-key is not sent to ${connection.serverUrl}, which comes from ${from}: a key goes only to the URL given with it. Pass --server-url to name the instance the key is for.`
|
|
1147
1274
|
);
|
|
1148
1275
|
}
|
|
1276
|
+
if (connection?.desktop && connection.apiKey) desktopKeys.add(keyAt(connection.serverUrl, connection.apiKey));
|
|
1149
1277
|
return connection;
|
|
1150
1278
|
}
|
|
1279
|
+
var desktopKeys = /* @__PURE__ */ new Set();
|
|
1280
|
+
var proofsInFlight = shareInFlight();
|
|
1281
|
+
function keyAt(serverUrl, key) {
|
|
1282
|
+
try {
|
|
1283
|
+
return `${new URL(serverUrl).origin}
|
|
1284
|
+
${key}`;
|
|
1285
|
+
} catch {
|
|
1286
|
+
return `${serverUrl}
|
|
1287
|
+
${key}`;
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
async function cliFetch(input, init) {
|
|
1291
|
+
const headers = new Headers(init?.headers);
|
|
1292
|
+
const keys = [headers.get("x-api-key"), /^Bearer\s+(.+)$/i.exec(headers.get("authorization") ?? "")?.[1]];
|
|
1293
|
+
let carriesDesktopKey = false;
|
|
1294
|
+
for (const key of new Set(keys.filter((value) => !!value))) {
|
|
1295
|
+
const target = keyAt(String(input), key);
|
|
1296
|
+
if (!desktopKeys.has(target)) continue;
|
|
1297
|
+
carriesDesktopKey = true;
|
|
1298
|
+
const serverUrl = new URL(input).origin;
|
|
1299
|
+
const proof = await proofsInFlight(target, () => proveDesktopServer(serverUrl, key));
|
|
1300
|
+
if (proof !== "proven") throw new DesktopNotProvenError(serverUrl, proof);
|
|
1301
|
+
}
|
|
1302
|
+
return fetch(input, carriesDesktopKey ? { ...init, redirect: "error" } : init);
|
|
1303
|
+
}
|
|
1151
1304
|
|
|
1152
1305
|
// src/cli/bug.ts
|
|
1153
1306
|
var EXIT_OK2 = 0;
|
|
@@ -1228,7 +1381,7 @@ async function fetchBugSpec(args, specDir) {
|
|
|
1228
1381
|
const url = `${args.serverUrl}/api/bug-reports/${args.id}/spec?mode=${args.mode}${dir}`;
|
|
1229
1382
|
let res;
|
|
1230
1383
|
try {
|
|
1231
|
-
res = await
|
|
1384
|
+
res = await cliFetch(url, {
|
|
1232
1385
|
headers: args.apiKey ? { "X-API-Key": args.apiKey } : {},
|
|
1233
1386
|
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
1234
1387
|
});
|
|
@@ -1250,20 +1403,20 @@ async function fetchBugSpec(args, specDir) {
|
|
|
1250
1403
|
function realFolder(dir) {
|
|
1251
1404
|
const rest = [];
|
|
1252
1405
|
let current = dir;
|
|
1253
|
-
while (!
|
|
1254
|
-
rest.unshift(
|
|
1255
|
-
current =
|
|
1406
|
+
while (!fs8.existsSync(current) && path11.dirname(current) !== current) {
|
|
1407
|
+
rest.unshift(path11.basename(current));
|
|
1408
|
+
current = path11.dirname(current);
|
|
1256
1409
|
}
|
|
1257
|
-
return
|
|
1410
|
+
return path11.join(fs8.realpathSync(current), ...rest);
|
|
1258
1411
|
}
|
|
1259
1412
|
function folderInRepository(root, dir) {
|
|
1260
|
-
const relative9 =
|
|
1261
|
-
if (relative9.startsWith("..") ||
|
|
1262
|
-
return relative9.split(
|
|
1413
|
+
const relative9 = path11.relative(realFolder(root), realFolder(dir));
|
|
1414
|
+
if (relative9.startsWith("..") || path11.isAbsolute(relative9)) return void 0;
|
|
1415
|
+
return relative9.split(path11.sep).join("/");
|
|
1263
1416
|
}
|
|
1264
1417
|
function fileFilter(file) {
|
|
1265
1418
|
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1266
|
-
return `${escape(
|
|
1419
|
+
return `${escape(path11.basename(path11.dirname(file)))}[\\\\/]${escape(path11.basename(file))}$`;
|
|
1267
1420
|
}
|
|
1268
1421
|
function runPlaywright(file, cwd, id, env) {
|
|
1269
1422
|
return spawnPlaywright([fileFilter(file)], { ...env, ...originEnv("bug", id) }, { cwd, command: "piwi bug" });
|
|
@@ -1283,10 +1436,10 @@ ${USAGE2}`);
|
|
|
1283
1436
|
return EXIT_ERROR2;
|
|
1284
1437
|
}
|
|
1285
1438
|
const root = args.write ? gitRoot(cwd) : null;
|
|
1286
|
-
const outFile = args.out !== null ?
|
|
1439
|
+
const outFile = args.out !== null ? path11.resolve(cwd, args.out) : null;
|
|
1287
1440
|
let spec;
|
|
1288
1441
|
try {
|
|
1289
|
-
spec = await fetchBugSpec(args, outFile && root ? folderInRepository(root,
|
|
1442
|
+
spec = await fetchBugSpec(args, outFile && root ? folderInRepository(root, path11.dirname(outFile)) : void 0);
|
|
1290
1443
|
} catch (e) {
|
|
1291
1444
|
console.error(`piwi bug: ${e.message}`);
|
|
1292
1445
|
return EXIT_ERROR2;
|
|
@@ -1301,16 +1454,16 @@ ${USAGE2}`);
|
|
|
1301
1454
|
if (!outFile && !root) {
|
|
1302
1455
|
console.error("piwi bug: not in a git repository \u2014 the bugs folder is read from the working directory");
|
|
1303
1456
|
}
|
|
1304
|
-
const file = outFile ??
|
|
1457
|
+
const file = outFile ?? path11.resolve(root ?? cwd, spec.path);
|
|
1305
1458
|
try {
|
|
1306
|
-
|
|
1307
|
-
|
|
1459
|
+
fs8.mkdirSync(path11.dirname(file), { recursive: true });
|
|
1460
|
+
fs8.writeFileSync(file, spec.code, { flag: args.force ? "w" : "wx" });
|
|
1308
1461
|
} catch (e) {
|
|
1309
1462
|
const exists = e.code === "EEXIST";
|
|
1310
1463
|
console.error(`piwi bug: ${exists ? `${file} exists \u2014 pass --force to replace it` : e.message}`);
|
|
1311
1464
|
return EXIT_ERROR2;
|
|
1312
1465
|
}
|
|
1313
|
-
const shown =
|
|
1466
|
+
const shown = path11.relative(cwd, file) || file;
|
|
1314
1467
|
console.error(`piwi bug: wrote ${shown}`);
|
|
1315
1468
|
if (!args.run) return EXIT_OK2;
|
|
1316
1469
|
const code = await runPlaywright(file, cwd, args.id, env);
|
|
@@ -1329,8 +1482,8 @@ ${USAGE2}`);
|
|
|
1329
1482
|
}
|
|
1330
1483
|
|
|
1331
1484
|
// src/cli/codegen.ts
|
|
1332
|
-
var
|
|
1333
|
-
var
|
|
1485
|
+
var fs9 = __toESM(require("fs"));
|
|
1486
|
+
var path12 = __toESM(require("path"));
|
|
1334
1487
|
|
|
1335
1488
|
// ../core/src/recording.ts
|
|
1336
1489
|
var ASSERTION_MATCHERS = [
|
|
@@ -2649,43 +2802,43 @@ var Checker = class {
|
|
|
2649
2802
|
constructor() {
|
|
2650
2803
|
this.errors = [];
|
|
2651
2804
|
}
|
|
2652
|
-
fail(
|
|
2653
|
-
if (this.errors.length < 20) this.errors.push(`${
|
|
2805
|
+
fail(path26, message) {
|
|
2806
|
+
if (this.errors.length < 20) this.errors.push(`${path26}: ${message}`);
|
|
2654
2807
|
}
|
|
2655
|
-
text(v,
|
|
2808
|
+
text(v, path26, max, nullable) {
|
|
2656
2809
|
if (v == null) {
|
|
2657
|
-
if (!nullable) this.fail(
|
|
2810
|
+
if (!nullable) this.fail(path26, "is required");
|
|
2658
2811
|
return null;
|
|
2659
2812
|
}
|
|
2660
2813
|
if (typeof v !== "string") {
|
|
2661
|
-
this.fail(
|
|
2814
|
+
this.fail(path26, "must be a string");
|
|
2662
2815
|
return null;
|
|
2663
2816
|
}
|
|
2664
|
-
if (v.length > max) this.fail(
|
|
2817
|
+
if (v.length > max) this.fail(path26, `is longer than ${max} characters`);
|
|
2665
2818
|
return v;
|
|
2666
2819
|
}
|
|
2667
|
-
number(v,
|
|
2820
|
+
number(v, path26) {
|
|
2668
2821
|
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
2669
|
-
this.fail(
|
|
2822
|
+
this.fail(path26, "must be a number");
|
|
2670
2823
|
return 0;
|
|
2671
2824
|
}
|
|
2672
2825
|
return v;
|
|
2673
2826
|
}
|
|
2674
2827
|
};
|
|
2675
|
-
function checkTarget(c, v,
|
|
2828
|
+
function checkTarget(c, v, path26) {
|
|
2676
2829
|
if (v == null) return null;
|
|
2677
2830
|
if (!isObject(v)) {
|
|
2678
|
-
c.fail(
|
|
2831
|
+
c.fail(path26, "must be an object");
|
|
2679
2832
|
return null;
|
|
2680
2833
|
}
|
|
2681
2834
|
const alternativesIn = v.alternatives ?? [];
|
|
2682
2835
|
const alternatives = [];
|
|
2683
|
-
if (!Array.isArray(alternativesIn)) c.fail(`${
|
|
2836
|
+
if (!Array.isArray(alternativesIn)) c.fail(`${path26}.alternatives`, "must be a list");
|
|
2684
2837
|
else if (alternativesIn.length > STEPS_LIMITS.alternatives)
|
|
2685
|
-
c.fail(`${
|
|
2838
|
+
c.fail(`${path26}.alternatives`, `holds more than ${STEPS_LIMITS.alternatives}`);
|
|
2686
2839
|
else {
|
|
2687
2840
|
alternativesIn.forEach((alt, i) => {
|
|
2688
|
-
const at = `${
|
|
2841
|
+
const at = `${path26}.alternatives[${i}]`;
|
|
2689
2842
|
if (!isObject(alt)) return c.fail(at, "must be an object");
|
|
2690
2843
|
const locator = c.text(alt.locator, `${at}.locator`, STEPS_LIMITS.textLength, false);
|
|
2691
2844
|
const safe = locator ? safeLocator(locator) : null;
|
|
@@ -2699,48 +2852,48 @@ function checkTarget(c, v, path25) {
|
|
|
2699
2852
|
});
|
|
2700
2853
|
}
|
|
2701
2854
|
return {
|
|
2702
|
-
tagName: c.text(v.tagName, `${
|
|
2703
|
-
role: c.text(v.role, `${
|
|
2704
|
-
accessibleName: c.text(v.accessibleName, `${
|
|
2705
|
-
testId: c.text(v.testId, `${
|
|
2706
|
-
text: c.text(v.text, `${
|
|
2855
|
+
tagName: c.text(v.tagName, `${path26}.tagName`, 64, false) ?? "",
|
|
2856
|
+
role: c.text(v.role, `${path26}.role`, 64, true),
|
|
2857
|
+
accessibleName: c.text(v.accessibleName, `${path26}.accessibleName`, STEPS_LIMITS.textLength, true),
|
|
2858
|
+
testId: c.text(v.testId, `${path26}.testId`, STEPS_LIMITS.textLength, true),
|
|
2859
|
+
text: c.text(v.text, `${path26}.text`, STEPS_LIMITS.textLength, true),
|
|
2707
2860
|
alternatives
|
|
2708
2861
|
};
|
|
2709
2862
|
}
|
|
2710
|
-
function checkAssertion(c, v,
|
|
2863
|
+
function checkAssertion(c, v, path26) {
|
|
2711
2864
|
if (!isObject(v)) {
|
|
2712
|
-
c.fail(
|
|
2865
|
+
c.fail(path26, "is required on an assert step");
|
|
2713
2866
|
return void 0;
|
|
2714
2867
|
}
|
|
2715
2868
|
const matcher = v.matcher;
|
|
2716
2869
|
if (!ASSERTION_MATCHERS.includes(matcher)) {
|
|
2717
|
-
c.fail(`${
|
|
2870
|
+
c.fail(`${path26}.matcher`, `must be one of ${ASSERTION_MATCHERS.join(", ")}`);
|
|
2718
2871
|
return void 0;
|
|
2719
2872
|
}
|
|
2720
|
-
const expected = c.text(v.expected, `${
|
|
2873
|
+
const expected = c.text(v.expected, `${path26}.expected`, STEPS_LIMITS.valueLength, !VALUE_MATCHERS.has(matcher));
|
|
2721
2874
|
if (matcher === "toHaveCount" && expected != null && !/^\d{1,6}$/.test(expected)) {
|
|
2722
|
-
c.fail(`${
|
|
2875
|
+
c.fail(`${path26}.expected`, "must be a whole number of elements on a toHaveCount assertion");
|
|
2723
2876
|
}
|
|
2724
2877
|
return {
|
|
2725
2878
|
matcher,
|
|
2726
2879
|
expected: VALUE_MATCHERS.has(matcher) ? expected : null,
|
|
2727
|
-
actual: c.text(v.actual, `${
|
|
2880
|
+
actual: c.text(v.actual, `${path26}.actual`, STEPS_LIMITS.valueLength, true),
|
|
2728
2881
|
negated: v.negated === true,
|
|
2729
|
-
note: c.text(v.note, `${
|
|
2882
|
+
note: c.text(v.note, `${path26}.note`, STEPS_LIMITS.valueLength, true)
|
|
2730
2883
|
};
|
|
2731
2884
|
}
|
|
2732
|
-
function checkManual(c, v,
|
|
2885
|
+
function checkManual(c, v, path26) {
|
|
2733
2886
|
if (!isObject(v)) {
|
|
2734
|
-
c.fail(
|
|
2887
|
+
c.fail(path26, "is required on a manual step");
|
|
2735
2888
|
return void 0;
|
|
2736
2889
|
}
|
|
2737
|
-
const description = c.text(v.description, `${
|
|
2738
|
-
if (description != null && !description.trim()) c.fail(`${
|
|
2890
|
+
const description = c.text(v.description, `${path26}.description`, STEPS_LIMITS.valueLength, false);
|
|
2891
|
+
if (description != null && !description.trim()) c.fail(`${path26}.description`, "must not be empty");
|
|
2739
2892
|
const instruction = readInstruction(v.instruction);
|
|
2740
2893
|
return {
|
|
2741
2894
|
description: description ?? "",
|
|
2742
|
-
location: c.text(v.location, `${
|
|
2743
|
-
call: c.text(v.call, `${
|
|
2895
|
+
location: c.text(v.location, `${path26}.location`, STEPS_LIMITS.textLength, true),
|
|
2896
|
+
call: c.text(v.call, `${path26}.call`, STEPS_LIMITS.textLength, true),
|
|
2744
2897
|
...instruction ? { instruction } : {}
|
|
2745
2898
|
};
|
|
2746
2899
|
}
|
|
@@ -2839,43 +2992,43 @@ function checkViewports(c, v, stepCount) {
|
|
|
2839
2992
|
});
|
|
2840
2993
|
return out;
|
|
2841
2994
|
}
|
|
2842
|
-
function checkStep(c, v,
|
|
2995
|
+
function checkStep(c, v, path26) {
|
|
2843
2996
|
if (!isObject(v)) {
|
|
2844
|
-
c.fail(
|
|
2997
|
+
c.fail(path26, "must be an object");
|
|
2845
2998
|
return null;
|
|
2846
2999
|
}
|
|
2847
3000
|
const action = v.action;
|
|
2848
3001
|
if (!ACTIONS.has(action)) {
|
|
2849
|
-
c.fail(`${
|
|
3002
|
+
c.fail(`${path26}.action`, "is not a known action");
|
|
2850
3003
|
return null;
|
|
2851
3004
|
}
|
|
2852
3005
|
const step = {
|
|
2853
3006
|
action: action === "assertVisible" ? "assert" : action,
|
|
2854
|
-
target: checkTarget(c, v.target, `${
|
|
2855
|
-
value: c.text(v.value, `${
|
|
3007
|
+
target: checkTarget(c, v.target, `${path26}.target`),
|
|
3008
|
+
value: c.text(v.value, `${path26}.value`, STEPS_LIMITS.valueLength, true),
|
|
2856
3009
|
redacted: v.redacted === true,
|
|
2857
|
-
pageUrl: c.text(v.pageUrl, `${
|
|
2858
|
-
timestamp: v.timestamp == null ? 0 : c.number(v.timestamp, `${
|
|
3010
|
+
pageUrl: c.text(v.pageUrl, `${path26}.pageUrl`, STEPS_LIMITS.valueLength, false) ?? "",
|
|
3011
|
+
timestamp: v.timestamp == null ? 0 : c.number(v.timestamp, `${path26}.timestamp`)
|
|
2859
3012
|
};
|
|
2860
3013
|
if (step.redacted) step.value = null;
|
|
2861
3014
|
if (action === "hover" || action === "dblclick") {
|
|
2862
3015
|
step.value = null;
|
|
2863
|
-
if (!step.target) c.fail(`${
|
|
3016
|
+
if (!step.target) c.fail(`${path26}.target`, `is required on a ${action} step`);
|
|
2864
3017
|
}
|
|
2865
|
-
if (action === "setInputFiles" && !step.target) c.fail(`${
|
|
3018
|
+
if (action === "setInputFiles" && !step.target) c.fail(`${path26}.target`, "is required on a setInputFiles step");
|
|
2866
3019
|
if (action === "dragTo") {
|
|
2867
3020
|
step.value = null;
|
|
2868
|
-
if (!step.target) c.fail(`${
|
|
2869
|
-
step.dropTarget = checkTarget(c, v.dropTarget, `${
|
|
2870
|
-
if (!step.dropTarget) c.fail(`${
|
|
3021
|
+
if (!step.target) c.fail(`${path26}.target`, "is required on a dragTo step");
|
|
3022
|
+
step.dropTarget = checkTarget(c, v.dropTarget, `${path26}.dropTarget`);
|
|
3023
|
+
if (!step.dropTarget) c.fail(`${path26}.dropTarget`, "is required on a dragTo step");
|
|
2871
3024
|
}
|
|
2872
3025
|
if (action === "assertVisible") {
|
|
2873
3026
|
step.assertion = { matcher: "toBeVisible", expected: null, actual: null, negated: false, note: null };
|
|
2874
3027
|
} else if (action === "assert") {
|
|
2875
|
-
step.assertion = checkAssertion(c, v.assertion, `${
|
|
3028
|
+
step.assertion = checkAssertion(c, v.assertion, `${path26}.assertion`);
|
|
2876
3029
|
} else if (action === "manual") {
|
|
2877
3030
|
step.value = null;
|
|
2878
|
-
step.manual = checkManual(c, v.manual, `${
|
|
3031
|
+
step.manual = checkManual(c, v.manual, `${path26}.manual`);
|
|
2879
3032
|
}
|
|
2880
3033
|
return step;
|
|
2881
3034
|
}
|
|
@@ -2934,7 +3087,7 @@ function authHeaders(apiKey) {
|
|
|
2934
3087
|
async function resolveProjectId(options) {
|
|
2935
3088
|
if (!options.project) throw new Error("No project \u2014 pass --project or set PIWI_PROJECT_NAME");
|
|
2936
3089
|
if (/^\d+$/.test(options.project)) return Number(options.project);
|
|
2937
|
-
const res = await
|
|
3090
|
+
const res = await cliFetch(`${options.serverUrl}/api/projects/menu`, { headers: authHeaders(options.apiKey) });
|
|
2938
3091
|
if (!res.ok) throw new Error(`Could not list projects (dashboard returned ${res.status})`);
|
|
2939
3092
|
const body = await res.json();
|
|
2940
3093
|
const match = body.items?.find((p) => p.name.toLowerCase() === options.project.toLowerCase());
|
|
@@ -2948,7 +3101,7 @@ async function fetchResolution(options, projectId) {
|
|
|
2948
3101
|
if (options.shard) params.set("shard", options.shard);
|
|
2949
3102
|
if (options.order) params.set("order", options.order);
|
|
2950
3103
|
const url = `${options.serverUrl}/api/projects/${projectId}/selections/${encodeURIComponent(options.key)}/resolve?${params}`;
|
|
2951
|
-
const res = await
|
|
3104
|
+
const res = await cliFetch(url, { headers: authHeaders(options.apiKey) });
|
|
2952
3105
|
if (!res.ok) {
|
|
2953
3106
|
const body = await res.json().catch(() => ({}));
|
|
2954
3107
|
throw new Error(body.message || `Dashboard returned ${res.status} resolving "${options.key}"`);
|
|
@@ -2957,7 +3110,7 @@ async function fetchResolution(options, projectId) {
|
|
|
2957
3110
|
}
|
|
2958
3111
|
async function fetchImpact(options, projectId, changedFiles, changes = []) {
|
|
2959
3112
|
const url = `${options.serverUrl}/api/projects/${projectId}/selections/impact`;
|
|
2960
|
-
const res = await
|
|
3113
|
+
const res = await cliFetch(url, {
|
|
2961
3114
|
method: "POST",
|
|
2962
3115
|
headers: { "Content-Type": "application/json", ...authHeaders(options.apiKey) },
|
|
2963
3116
|
body: JSON.stringify({
|
|
@@ -2976,7 +3129,7 @@ async function fetchImpact(options, projectId, changedFiles, changes = []) {
|
|
|
2976
3129
|
}
|
|
2977
3130
|
async function fetchLocatorIndex(options, projectId, branch) {
|
|
2978
3131
|
const query = branch ? `?branch=${encodeURIComponent(branch)}` : "";
|
|
2979
|
-
const res = await
|
|
3132
|
+
const res = await cliFetch(`${options.serverUrl}/api/projects/${projectId}/locator-index${query}`, {
|
|
2980
3133
|
headers: authHeaders(options.apiKey)
|
|
2981
3134
|
});
|
|
2982
3135
|
if (!res.ok) {
|
|
@@ -2987,7 +3140,7 @@ async function fetchLocatorIndex(options, projectId, branch) {
|
|
|
2987
3140
|
}
|
|
2988
3141
|
async function fetchCodeIndex(options, projectId, branch) {
|
|
2989
3142
|
const query = branch ? `?branch=${encodeURIComponent(branch)}` : "";
|
|
2990
|
-
const res = await
|
|
3143
|
+
const res = await cliFetch(`${options.serverUrl}/api/projects/${projectId}/code-index${query}`, {
|
|
2991
3144
|
headers: authHeaders(options.apiKey)
|
|
2992
3145
|
});
|
|
2993
3146
|
if (!res.ok) throw new Error(`Dashboard returned ${res.status} fetching the code index`);
|
|
@@ -3123,7 +3276,7 @@ function authHeaders2(apiKey) {
|
|
|
3123
3276
|
return apiKey ? { "X-API-Key": apiKey } : {};
|
|
3124
3277
|
}
|
|
3125
3278
|
async function fetchJson(url, apiKey) {
|
|
3126
|
-
const res = await
|
|
3279
|
+
const res = await cliFetch(url, { headers: authHeaders2(apiKey), signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2) });
|
|
3127
3280
|
if (!res.ok) throw new Error(`${new URL(url).pathname} answered ${res.status}`);
|
|
3128
3281
|
return res.json();
|
|
3129
3282
|
}
|
|
@@ -3186,8 +3339,8 @@ ${USAGE3}`);
|
|
|
3186
3339
|
}
|
|
3187
3340
|
} else {
|
|
3188
3341
|
try {
|
|
3189
|
-
if (
|
|
3190
|
-
text =
|
|
3342
|
+
if (fs9.statSync(args.file).size > MAX_STEPS_FILE_BYTES) throw new Error("is too large to be a steps file");
|
|
3343
|
+
text = fs9.readFileSync(args.file, "utf-8");
|
|
3191
3344
|
} catch (e) {
|
|
3192
3345
|
const reason = e.code === "ENOENT" ? "does not exist" : e.message;
|
|
3193
3346
|
console.error(`piwi codegen: ${args.file} ${reason}`);
|
|
@@ -3219,8 +3372,8 @@ ${USAGE3}`);
|
|
|
3219
3372
|
return EXIT_OK3;
|
|
3220
3373
|
}
|
|
3221
3374
|
try {
|
|
3222
|
-
|
|
3223
|
-
|
|
3375
|
+
fs9.mkdirSync(path12.dirname(args.out), { recursive: true });
|
|
3376
|
+
fs9.writeFileSync(args.out, result.code, { flag: args.force ? "w" : "wx" });
|
|
3224
3377
|
} catch (e) {
|
|
3225
3378
|
const exists = e.code === "EEXIST";
|
|
3226
3379
|
console.error(`piwi codegen: ${exists ? `${args.out} exists \u2014 pass --force to replace it` : e.message}`);
|
|
@@ -3234,7 +3387,7 @@ ${USAGE3}`);
|
|
|
3234
3387
|
}
|
|
3235
3388
|
|
|
3236
3389
|
// src/cli/coverage.ts
|
|
3237
|
-
var
|
|
3390
|
+
var path17 = __toESM(require("path"));
|
|
3238
3391
|
|
|
3239
3392
|
// ../core/src/codeowners.ts
|
|
3240
3393
|
function patternParts(pattern) {
|
|
@@ -3279,9 +3432,9 @@ function pathPatternMatcher(pattern) {
|
|
|
3279
3432
|
const { segments, floating } = patternParts(pattern);
|
|
3280
3433
|
if (floating) {
|
|
3281
3434
|
const only = segments[0];
|
|
3282
|
-
if (only === "**") return (
|
|
3283
|
-
return (
|
|
3284
|
-
const parts =
|
|
3435
|
+
if (only === "**") return (path26) => !LINE_TERMINATOR.test(path26);
|
|
3436
|
+
return (path26) => {
|
|
3437
|
+
const parts = path26.split("/");
|
|
3285
3438
|
const clean = cleanTails(parts);
|
|
3286
3439
|
for (let j = 0; j < parts.length; j++) {
|
|
3287
3440
|
if (segmentMatches(only, parts[j]) && clean[j + 1]) return true;
|
|
@@ -3290,8 +3443,8 @@ function pathPatternMatcher(pattern) {
|
|
|
3290
3443
|
return false;
|
|
3291
3444
|
};
|
|
3292
3445
|
}
|
|
3293
|
-
return (
|
|
3294
|
-
const parts =
|
|
3446
|
+
return (path26) => {
|
|
3447
|
+
const parts = path26.split("/");
|
|
3295
3448
|
const clean = cleanTails(parts);
|
|
3296
3449
|
let at = new Uint8Array(parts.length);
|
|
3297
3450
|
at[0] = 1;
|
|
@@ -3367,8 +3520,8 @@ function parseCoverageScope(raw) {
|
|
|
3367
3520
|
function compileCoverageScope(scope) {
|
|
3368
3521
|
const include = scope.include.map(pathPatternMatcher);
|
|
3369
3522
|
const exclude = scope.exclude.map(pathPatternMatcher);
|
|
3370
|
-
return (
|
|
3371
|
-
const file =
|
|
3523
|
+
return (path26) => {
|
|
3524
|
+
const file = path26.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
3372
3525
|
if (include.length > 0 && !include.some((matches) => matches(file))) return false;
|
|
3373
3526
|
return !exclude.some((matches) => matches(file));
|
|
3374
3527
|
};
|
|
@@ -3410,7 +3563,7 @@ var MAX_REGION_SNAPSHOT = 1024 * 1024;
|
|
|
3410
3563
|
var MAX_AGENT_SNAPSHOT = 1024 * 1024;
|
|
3411
3564
|
|
|
3412
3565
|
// src/internal/support/test-paths.ts
|
|
3413
|
-
var
|
|
3566
|
+
var path13 = __toESM(require("path"));
|
|
3414
3567
|
|
|
3415
3568
|
// src/internal/collect/metadata-collector.ts
|
|
3416
3569
|
var DETACHED_HEAD = "HEAD";
|
|
@@ -3443,14 +3596,14 @@ function normalizeRef(ref) {
|
|
|
3443
3596
|
|
|
3444
3597
|
// src/internal/coverage-upload/git-inventory.ts
|
|
3445
3598
|
var import_node_child_process5 = require("child_process");
|
|
3446
|
-
var
|
|
3447
|
-
var
|
|
3599
|
+
var fs11 = __toESM(require("fs"));
|
|
3600
|
+
var path15 = __toESM(require("path"));
|
|
3448
3601
|
|
|
3449
3602
|
// src/internal/collect/blob-ids.ts
|
|
3450
3603
|
var import_node_child_process4 = require("child_process");
|
|
3451
|
-
var
|
|
3452
|
-
var
|
|
3453
|
-
var
|
|
3604
|
+
var crypto4 = __toESM(require("crypto"));
|
|
3605
|
+
var fs10 = __toESM(require("fs"));
|
|
3606
|
+
var path14 = __toESM(require("path"));
|
|
3454
3607
|
function gitHashObjects(root, paths) {
|
|
3455
3608
|
return new Promise((resolve11) => {
|
|
3456
3609
|
const child = (0, import_node_child_process4.execFile)(
|
|
@@ -3517,7 +3670,7 @@ async function readInventory(root, warn = () => {
|
|
|
3517
3670
|
const changed = [];
|
|
3518
3671
|
for (const file of (await git(root, ["diff", "--name-only", "-z", "HEAD"]).catch(() => "")).split("\0")) {
|
|
3519
3672
|
if (!file || !inventory.has(file)) continue;
|
|
3520
|
-
if (
|
|
3673
|
+
if (fs11.existsSync(path15.join(root, file))) changed.push(file);
|
|
3521
3674
|
else inventory.delete(file);
|
|
3522
3675
|
}
|
|
3523
3676
|
const ids = await hashPaths(root, changed);
|
|
@@ -3536,8 +3689,8 @@ async function readInventory(root, warn = () => {
|
|
|
3536
3689
|
}
|
|
3537
3690
|
|
|
3538
3691
|
// src/internal/coverage-upload/report-files.ts
|
|
3539
|
-
var
|
|
3540
|
-
var
|
|
3692
|
+
var fs12 = __toESM(require("fs"));
|
|
3693
|
+
var path16 = __toESM(require("path"));
|
|
3541
3694
|
|
|
3542
3695
|
// ../core/src/coverage.ts
|
|
3543
3696
|
var MAX_LINE = 1e6;
|
|
@@ -3616,7 +3769,7 @@ var FileLines = class {
|
|
|
3616
3769
|
this.functions.set(key, { start, end: last, ran });
|
|
3617
3770
|
}
|
|
3618
3771
|
}
|
|
3619
|
-
toFile(
|
|
3772
|
+
toFile(path26) {
|
|
3620
3773
|
const executable = [];
|
|
3621
3774
|
const lines = [];
|
|
3622
3775
|
const push = (ranges, line) => {
|
|
@@ -3636,7 +3789,7 @@ var FileLines = class {
|
|
|
3636
3789
|
if (didRun) ran.push([start, end]);
|
|
3637
3790
|
}
|
|
3638
3791
|
return {
|
|
3639
|
-
path:
|
|
3792
|
+
path: path26,
|
|
3640
3793
|
executable,
|
|
3641
3794
|
lines,
|
|
3642
3795
|
functions: normalizeFunctionRanges(ran),
|
|
@@ -3648,16 +3801,16 @@ var ReportFiles = class {
|
|
|
3648
3801
|
constructor() {
|
|
3649
3802
|
this.byPath = /* @__PURE__ */ new Map();
|
|
3650
3803
|
}
|
|
3651
|
-
of(
|
|
3652
|
-
let file = this.byPath.get(
|
|
3804
|
+
of(path26) {
|
|
3805
|
+
let file = this.byPath.get(path26);
|
|
3653
3806
|
if (!file) {
|
|
3654
3807
|
file = new FileLines();
|
|
3655
|
-
this.byPath.set(
|
|
3808
|
+
this.byPath.set(path26, file);
|
|
3656
3809
|
}
|
|
3657
3810
|
return file;
|
|
3658
3811
|
}
|
|
3659
3812
|
toFiles() {
|
|
3660
|
-
return [...this.byPath].map(([
|
|
3813
|
+
return [...this.byPath].map(([path26, file]) => file.toFile(path26));
|
|
3661
3814
|
}
|
|
3662
3815
|
};
|
|
3663
3816
|
var XML_ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
|
|
@@ -3996,23 +4149,23 @@ function normalizeSlashPath(raw) {
|
|
|
3996
4149
|
}
|
|
3997
4150
|
return (drive || (absolute ? "/" : "")) + out.join("/");
|
|
3998
4151
|
}
|
|
3999
|
-
function isAbsolutePath(
|
|
4000
|
-
return
|
|
4152
|
+
function isAbsolutePath(path26) {
|
|
4153
|
+
return path26.startsWith("/") || /^[A-Za-z]:\//.test(path26);
|
|
4001
4154
|
}
|
|
4002
|
-
function relativeTo(
|
|
4155
|
+
function relativeTo(path26, root) {
|
|
4003
4156
|
const drive = /^[A-Za-z]:/.test(root);
|
|
4004
4157
|
const base = root.endsWith("/") ? root : `${root}/`;
|
|
4005
|
-
const head =
|
|
4158
|
+
const head = path26.slice(0, base.length);
|
|
4006
4159
|
const inside = drive ? head.toLowerCase() === base.toLowerCase() : head === base;
|
|
4007
4160
|
if (!inside) return null;
|
|
4008
|
-
const relative9 =
|
|
4161
|
+
const relative9 = path26.slice(base.length);
|
|
4009
4162
|
return relative9 || null;
|
|
4010
4163
|
}
|
|
4011
4164
|
function reportPathCandidates(raw, { repoRoot, bases }) {
|
|
4012
4165
|
const slash = (value) => value.replace(/\\/g, "/");
|
|
4013
4166
|
const root = normalizeSlashPath(slash(repoRoot));
|
|
4014
|
-
const
|
|
4015
|
-
if (!root || !
|
|
4167
|
+
const path26 = slash(raw.trim());
|
|
4168
|
+
if (!root || !path26 || path26.includes("\0")) return [];
|
|
4016
4169
|
const out = [];
|
|
4017
4170
|
const add = (absolute) => {
|
|
4018
4171
|
const normalized = normalizeSlashPath(absolute);
|
|
@@ -4020,12 +4173,12 @@ function reportPathCandidates(raw, { repoRoot, bases }) {
|
|
|
4020
4173
|
const relative9 = normalized.startsWith("/_/") ? normalized.slice(3) : relativeTo(normalized, root);
|
|
4021
4174
|
if (relative9 && !out.includes(relative9)) out.push(relative9);
|
|
4022
4175
|
};
|
|
4023
|
-
if (isAbsolutePath(
|
|
4024
|
-
add(
|
|
4176
|
+
if (isAbsolutePath(path26)) {
|
|
4177
|
+
add(path26);
|
|
4025
4178
|
} else {
|
|
4026
4179
|
for (const base of bases) {
|
|
4027
4180
|
const dir = slash(base);
|
|
4028
|
-
if (isAbsolutePath(dir)) add(`${dir}/${
|
|
4181
|
+
if (isAbsolutePath(dir)) add(`${dir}/${path26}`);
|
|
4029
4182
|
}
|
|
4030
4183
|
}
|
|
4031
4184
|
return out;
|
|
@@ -4049,14 +4202,14 @@ function globSegmentRegExp(segment) {
|
|
|
4049
4202
|
function expandPattern(pattern, cwd) {
|
|
4050
4203
|
const normalized = pattern.replace(/\\/g, "/");
|
|
4051
4204
|
if (!/[*?]/.test(normalized)) {
|
|
4052
|
-
const file =
|
|
4053
|
-
return
|
|
4205
|
+
const file = path16.resolve(cwd, normalized);
|
|
4206
|
+
return fs12.existsSync(file) && fs12.statSync(file).isFile() ? [file] : [];
|
|
4054
4207
|
}
|
|
4055
|
-
const absolute =
|
|
4208
|
+
const absolute = path16.isAbsolute(normalized) || /^[A-Za-z]:\//.test(normalized);
|
|
4056
4209
|
const segments = normalized.split("/");
|
|
4057
4210
|
const firstWild = segments.findIndex((s) => /[*?]/.test(s));
|
|
4058
4211
|
const baseParts = segments.slice(0, firstWild);
|
|
4059
|
-
const base = absolute ? baseParts.join("/") || "/" :
|
|
4212
|
+
const base = absolute ? baseParts.join("/") || "/" : path16.resolve(cwd, ...baseParts);
|
|
4060
4213
|
const rest = segments.slice(firstWild).filter((s) => s !== "");
|
|
4061
4214
|
const out = [];
|
|
4062
4215
|
const walk = (dir, at) => {
|
|
@@ -4064,14 +4217,14 @@ function expandPattern(pattern, cwd) {
|
|
|
4064
4217
|
const segment = rest[at];
|
|
4065
4218
|
let entries;
|
|
4066
4219
|
try {
|
|
4067
|
-
entries =
|
|
4220
|
+
entries = fs12.readdirSync(dir, { withFileTypes: true });
|
|
4068
4221
|
} catch {
|
|
4069
4222
|
return;
|
|
4070
4223
|
}
|
|
4071
4224
|
if (segment === "**") {
|
|
4072
4225
|
walk(dir, at + 1);
|
|
4073
4226
|
for (const entry of entries) {
|
|
4074
|
-
if (entry.isDirectory() && !SKIPPED_DIRS.has(entry.name)) walk(
|
|
4227
|
+
if (entry.isDirectory() && !SKIPPED_DIRS.has(entry.name)) walk(path16.join(dir, entry.name), at);
|
|
4075
4228
|
}
|
|
4076
4229
|
return;
|
|
4077
4230
|
}
|
|
@@ -4079,7 +4232,7 @@ function expandPattern(pattern, cwd) {
|
|
|
4079
4232
|
const last = at === rest.length - 1;
|
|
4080
4233
|
for (const entry of entries) {
|
|
4081
4234
|
if (!match.test(entry.name)) continue;
|
|
4082
|
-
const full =
|
|
4235
|
+
const full = path16.join(dir, entry.name);
|
|
4083
4236
|
if (last && entry.isFile()) out.push(full);
|
|
4084
4237
|
else if (!last && entry.isDirectory() && (!SKIPPED_DIRS.has(entry.name) || segment === entry.name)) {
|
|
4085
4238
|
walk(full, at + 1);
|
|
@@ -4092,7 +4245,7 @@ function expandPattern(pattern, cwd) {
|
|
|
4092
4245
|
async function readReport(file, format) {
|
|
4093
4246
|
let reader = format ? new CoverageReportReader(format) : null;
|
|
4094
4247
|
let head = "";
|
|
4095
|
-
for await (const chunk of
|
|
4248
|
+
for await (const chunk of fs12.createReadStream(file, { encoding: "utf8", highWaterMark: 1024 * 1024 })) {
|
|
4096
4249
|
if (!reader) {
|
|
4097
4250
|
head += chunk;
|
|
4098
4251
|
if (head.length < 4096) continue;
|
|
@@ -4114,18 +4267,18 @@ async function readReport(file, format) {
|
|
|
4114
4267
|
return reader.end();
|
|
4115
4268
|
}
|
|
4116
4269
|
function reportBases(report, reportFile, options) {
|
|
4117
|
-
if (options.root) return [
|
|
4118
|
-
const dir =
|
|
4270
|
+
if (options.root) return [path16.resolve(options.cwd, options.root)];
|
|
4271
|
+
const dir = path16.dirname(path16.resolve(reportFile));
|
|
4119
4272
|
const sources = report.sources.map(
|
|
4120
|
-
(source) =>
|
|
4273
|
+
(source) => path16.isAbsolute(source) || /^[A-Za-z]:[\\/]/.test(source) ? source : path16.resolve(dir, source)
|
|
4121
4274
|
);
|
|
4122
|
-
return [...sources, options.cwd, dir,
|
|
4275
|
+
return [...sources, options.cwd, dir, path16.dirname(dir), options.repoRoot];
|
|
4123
4276
|
}
|
|
4124
4277
|
function resolveReport(report, reportFile, options, into) {
|
|
4125
4278
|
const bases = reportBases(report, reportFile, options);
|
|
4126
4279
|
for (const file of report.files) {
|
|
4127
4280
|
const candidates = reportPathCandidates(file.path, { repoRoot: options.repoRoot, bases });
|
|
4128
|
-
const match = candidates.find((candidate) => options.inventory.has(candidate)) ?? candidates.find((candidate) =>
|
|
4281
|
+
const match = candidates.find((candidate) => options.inventory.has(candidate)) ?? candidates.find((candidate) => fs12.existsSync(path16.join(options.repoRoot, candidate)));
|
|
4129
4282
|
if (!match) {
|
|
4130
4283
|
into.unmatched.push(file.path);
|
|
4131
4284
|
continue;
|
|
@@ -4297,7 +4450,7 @@ function authHeaders3(apiKey) {
|
|
|
4297
4450
|
return apiKey ? { "X-API-Key": apiKey } : {};
|
|
4298
4451
|
}
|
|
4299
4452
|
async function fetchScope(args, projectId) {
|
|
4300
|
-
const res = await
|
|
4453
|
+
const res = await cliFetch(`${args.serverUrl}/api/projects/${projectId}`, { headers: authHeaders3(args.apiKey) });
|
|
4301
4454
|
if (!res.ok) throw new Error(`Could not read the project (dashboard returned ${res.status})`);
|
|
4302
4455
|
const body = await res.json();
|
|
4303
4456
|
const raw = body.coverageScope ?? body.project?.coverageScope;
|
|
@@ -4358,7 +4511,7 @@ async function uploadCoverage(args, env, cwd, warn = warnOnStderr) {
|
|
|
4358
4511
|
commit: checkout.commit,
|
|
4359
4512
|
branch,
|
|
4360
4513
|
suite: args.suite,
|
|
4361
|
-
reports: reports.map((report) =>
|
|
4514
|
+
reports: reports.map((report) => path17.relative(cwd, report) || report),
|
|
4362
4515
|
files: files.length,
|
|
4363
4516
|
unmatched: resolved.unmatched.length,
|
|
4364
4517
|
outOfScope: resolved.outOfScope,
|
|
@@ -4369,7 +4522,7 @@ async function uploadCoverage(args, env, cwd, warn = warnOnStderr) {
|
|
|
4369
4522
|
return { summary, code: reports.length === 0 || files.length === 0 ? EXIT_NOTHING : EXIT_OK4 };
|
|
4370
4523
|
}
|
|
4371
4524
|
for (const part of parts) {
|
|
4372
|
-
const res = await
|
|
4525
|
+
const res = await cliFetch(`${args.serverUrl}/api/projects/${projectId}/coverage-reports`, {
|
|
4373
4526
|
method: "POST",
|
|
4374
4527
|
headers: { "Content-Type": "application/json", ...authHeaders3(args.apiKey) },
|
|
4375
4528
|
body: JSON.stringify(part)
|
|
@@ -4428,9 +4581,9 @@ ${USAGE4}`);
|
|
|
4428
4581
|
|
|
4429
4582
|
// src/cli/flake.ts
|
|
4430
4583
|
var import_node_child_process6 = require("child_process");
|
|
4431
|
-
var
|
|
4432
|
-
var
|
|
4433
|
-
var
|
|
4584
|
+
var fs13 = __toESM(require("fs"));
|
|
4585
|
+
var os4 = __toESM(require("os"));
|
|
4586
|
+
var path18 = __toESM(require("path"));
|
|
4434
4587
|
|
|
4435
4588
|
// ../core/src/error-parse.ts
|
|
4436
4589
|
var ANSI_RE = new RegExp("\\u001B\\[[0-9;]*m", "g");
|
|
@@ -4798,7 +4951,7 @@ function formatP(p) {
|
|
|
4798
4951
|
var FlakeError = class extends Error {
|
|
4799
4952
|
};
|
|
4800
4953
|
async function getJson(http2, url) {
|
|
4801
|
-
const res = await
|
|
4954
|
+
const res = await cliFetch(`${http2.serverUrl}${url}`, { headers: http2.headers });
|
|
4802
4955
|
if (!res.ok) {
|
|
4803
4956
|
const body = await res.json().catch(() => ({}));
|
|
4804
4957
|
throw new FlakeError(body.message || `the dashboard returned ${res.status} for ${url.split("?")[0]}`);
|
|
@@ -4820,9 +4973,9 @@ function playwrightRunner(dir, log) {
|
|
|
4820
4973
|
return {
|
|
4821
4974
|
now: () => Date.now(),
|
|
4822
4975
|
async runBatch(plan, arm, repeat, batch) {
|
|
4823
|
-
const planFile =
|
|
4824
|
-
if (!
|
|
4825
|
-
|
|
4976
|
+
const planFile = path18.join(dir, `${arm.id}.plan.json`);
|
|
4977
|
+
if (!fs13.existsSync(planFile)) {
|
|
4978
|
+
fs13.writeFileSync(
|
|
4826
4979
|
planFile,
|
|
4827
4980
|
JSON.stringify({
|
|
4828
4981
|
version: FLAKE_PLAN_VERSION,
|
|
@@ -4833,15 +4986,15 @@ function playwrightRunner(dir, log) {
|
|
|
4833
4986
|
})
|
|
4834
4987
|
);
|
|
4835
4988
|
}
|
|
4836
|
-
const resultsFile =
|
|
4837
|
-
|
|
4989
|
+
const resultsFile = path18.join(dir, `${arm.id}.${batch}.jsonl`);
|
|
4990
|
+
fs13.writeFileSync(resultsFile, "");
|
|
4838
4991
|
const env = {
|
|
4839
4992
|
...process.env,
|
|
4840
4993
|
[PIWI_FLAKE_ENV.plan]: planFile,
|
|
4841
4994
|
[PIWI_FLAKE_ENV.results]: resultsFile
|
|
4842
4995
|
};
|
|
4843
4996
|
delete env[PIWI_PROBE_ENV.flag];
|
|
4844
|
-
|
|
4997
|
+
fs13.appendFileSync(log, `
|
|
4845
4998
|
\u2500\u2500 ${arm.id} batch ${batch} \u2500\u2500
|
|
4846
4999
|
`);
|
|
4847
5000
|
await spawnPlaywright(playwrightArgs(plan.test, arm, repeat), env, {
|
|
@@ -4854,7 +5007,7 @@ function playwrightRunner(dir, log) {
|
|
|
4854
5007
|
}
|
|
4855
5008
|
function readResults(file) {
|
|
4856
5009
|
const lines = [];
|
|
4857
|
-
for (const line of
|
|
5010
|
+
for (const line of fs13.readFileSync(file, "utf8").split("\n")) {
|
|
4858
5011
|
if (!line.trim()) continue;
|
|
4859
5012
|
try {
|
|
4860
5013
|
lines.push(JSON.parse(line));
|
|
@@ -5009,7 +5162,7 @@ function printHeader(plan, commit, estimate, budgetMs) {
|
|
|
5009
5162
|
out.push("");
|
|
5010
5163
|
const estimateText = estimate != null ? `up to ${formatDuration(estimate)}` : "unknown (no passing run on record)";
|
|
5011
5164
|
out.push(`Estimate: ${estimateText} \xB7 budget ${formatDuration(budgetMs)}`);
|
|
5012
|
-
out.push(`Lab \xB7 ${
|
|
5165
|
+
out.push(`Lab \xB7 ${os4.hostname()} \xB7 HEAD ${short(commit)} \xB7 ${plan.test.project ?? "default project"} \xB7 retries off`);
|
|
5013
5166
|
if (commitsDiffer(commit, plan.failureCommit)) {
|
|
5014
5167
|
out.push(`warning: this checkout is ${short(commit)}; the latest failure ran on ${short(plan.failureCommit)}.`);
|
|
5015
5168
|
}
|
|
@@ -5018,7 +5171,7 @@ function printHeader(plan, commit, estimate, budgetMs) {
|
|
|
5018
5171
|
async function loadPlan(args, commit) {
|
|
5019
5172
|
if (args.planFile) {
|
|
5020
5173
|
try {
|
|
5021
|
-
const raw = JSON.parse(
|
|
5174
|
+
const raw = JSON.parse(fs13.readFileSync(args.planFile, "utf8"));
|
|
5022
5175
|
const plan = "plan" in raw && raw.plan ? raw.plan : raw;
|
|
5023
5176
|
if (plan.version !== 1 || !plan.control || !Array.isArray(plan.arms)) throw new Error("not a flake-lab plan");
|
|
5024
5177
|
if (args.verify !== (plan.kind === "verify")) {
|
|
@@ -5050,7 +5203,7 @@ async function loadPlan(args, commit) {
|
|
|
5050
5203
|
const params = new URLSearchParams({
|
|
5051
5204
|
kind: args.verify ? "verify" : "reproduce",
|
|
5052
5205
|
source: args.source ?? (process.env.CI ? "ci" : "cli"),
|
|
5053
|
-
machine:
|
|
5206
|
+
machine: os4.hostname(),
|
|
5054
5207
|
record: String(args.upload)
|
|
5055
5208
|
});
|
|
5056
5209
|
if (commit) params.set("commit", commit);
|
|
@@ -5113,8 +5266,8 @@ async function runFlake(argv, runner) {
|
|
|
5113
5266
|
if (!args.json) {
|
|
5114
5267
|
printHeader(plan, commit, estimate, args.budgetMs);
|
|
5115
5268
|
}
|
|
5116
|
-
const dir =
|
|
5117
|
-
const log =
|
|
5269
|
+
const dir = fs13.mkdtempSync(path18.join(os4.tmpdir(), "piwi-flake-"));
|
|
5270
|
+
const log = path18.join(dir, "playwright.log");
|
|
5118
5271
|
let session;
|
|
5119
5272
|
try {
|
|
5120
5273
|
session = await runSession(runner ?? playwrightRunner(dir, log), plan, args, (result) => {
|
|
@@ -5122,8 +5275,8 @@ async function runFlake(argv, runner) {
|
|
|
5122
5275
|
});
|
|
5123
5276
|
} catch (error) {
|
|
5124
5277
|
console.error(`piwi flake: ${error.message}`);
|
|
5125
|
-
if (
|
|
5126
|
-
const tail =
|
|
5278
|
+
if (fs13.existsSync(log)) {
|
|
5279
|
+
const tail = fs13.readFileSync(log, "utf8").trimEnd().split("\n").slice(-LOG_TAIL_LINES).join("\n");
|
|
5127
5280
|
console.error(`
|
|
5128
5281
|
Playwright's output (${log}):
|
|
5129
5282
|
${tail}`);
|
|
@@ -5139,7 +5292,7 @@ ${tail}`);
|
|
|
5139
5292
|
let uploaded = false;
|
|
5140
5293
|
if (args.upload && http2 && plan.experimentId) {
|
|
5141
5294
|
try {
|
|
5142
|
-
const res = await
|
|
5295
|
+
const res = await cliFetch(`${http2.serverUrl}/api/projects/${plan.projectId}/flake-lab/results`, {
|
|
5143
5296
|
method: "POST",
|
|
5144
5297
|
headers: { "Content-Type": "application/json", ...http2.headers },
|
|
5145
5298
|
body: JSON.stringify({
|
|
@@ -5196,7 +5349,7 @@ ${tail}`);
|
|
|
5196
5349
|
verifyCommand: plan.kind === "reproduce" && verdict === "reproduced" ? verifyCommand : null,
|
|
5197
5350
|
exitCode: code
|
|
5198
5351
|
};
|
|
5199
|
-
|
|
5352
|
+
fs13.rmSync(dir, { recursive: true, force: true });
|
|
5200
5353
|
if (args.json) {
|
|
5201
5354
|
console.log(JSON.stringify(report, null, 2));
|
|
5202
5355
|
return code;
|
|
@@ -5211,7 +5364,7 @@ ${tail}`);
|
|
|
5211
5364
|
}
|
|
5212
5365
|
|
|
5213
5366
|
// src/cli/gate.ts
|
|
5214
|
-
var
|
|
5367
|
+
var fs14 = __toESM(require("fs"));
|
|
5215
5368
|
|
|
5216
5369
|
// ../core/src/gate.ts
|
|
5217
5370
|
function formatGateResult(result) {
|
|
@@ -5305,9 +5458,9 @@ function readCount(argv, name) {
|
|
|
5305
5458
|
if (!Number.isFinite(n) || n < 0) throw new Error(`${name} expects a non-negative number, got "${raw}"`);
|
|
5306
5459
|
return Math.floor(n);
|
|
5307
5460
|
}
|
|
5308
|
-
function readRunIdFromFile(
|
|
5461
|
+
function readRunIdFromFile(path26) {
|
|
5309
5462
|
try {
|
|
5310
|
-
const parsed = JSON.parse(
|
|
5463
|
+
const parsed = JSON.parse(fs14.readFileSync(path26, "utf-8"));
|
|
5311
5464
|
const runId = Number(parsed.runId);
|
|
5312
5465
|
return Number.isFinite(runId) && runId > 0 ? runId : null;
|
|
5313
5466
|
} catch {
|
|
@@ -5358,7 +5511,7 @@ function parseGateArgs(argv, env, dirs = []) {
|
|
|
5358
5511
|
async function requestGate(args) {
|
|
5359
5512
|
const headers = { "Content-Type": "application/json", "X-Piwi-Client": "cli" };
|
|
5360
5513
|
if (args.apiKey) headers["X-API-Key"] = args.apiKey;
|
|
5361
|
-
const res = await
|
|
5514
|
+
const res = await cliFetch(`${args.serverUrl}/api/test-runs/${args.runId}/gate`, {
|
|
5362
5515
|
method: "POST",
|
|
5363
5516
|
headers,
|
|
5364
5517
|
body: JSON.stringify({
|
|
@@ -5407,8 +5560,8 @@ async function runGate(argv, env = process.env, cwd = process.cwd()) {
|
|
|
5407
5560
|
|
|
5408
5561
|
// src/cli/init.ts
|
|
5409
5562
|
var import_node_child_process7 = require("child_process");
|
|
5410
|
-
var
|
|
5411
|
-
var
|
|
5563
|
+
var fs17 = __toESM(require("fs"));
|
|
5564
|
+
var path21 = __toESM(require("path"));
|
|
5412
5565
|
var readline = __toESM(require("readline"));
|
|
5413
5566
|
var tty = __toESM(require("tty"));
|
|
5414
5567
|
|
|
@@ -5427,8 +5580,8 @@ function formatStep(result) {
|
|
|
5427
5580
|
}
|
|
5428
5581
|
|
|
5429
5582
|
// src/cli/detect.ts
|
|
5430
|
-
var
|
|
5431
|
-
var
|
|
5583
|
+
var fs15 = __toESM(require("fs"));
|
|
5584
|
+
var path19 = __toESM(require("path"));
|
|
5432
5585
|
var CONFIG_NAMES2 = [
|
|
5433
5586
|
"playwright.config.ts",
|
|
5434
5587
|
"playwright.config.mts",
|
|
@@ -5446,9 +5599,9 @@ var LOCKFILES = [
|
|
|
5446
5599
|
];
|
|
5447
5600
|
var REPORTER_PACKAGE = "@piwitests/reporter";
|
|
5448
5601
|
function readPackageJson(root) {
|
|
5449
|
-
const pkgPath =
|
|
5602
|
+
const pkgPath = path19.join(root, "package.json");
|
|
5450
5603
|
try {
|
|
5451
|
-
return { pkg: JSON.parse(
|
|
5604
|
+
return { pkg: JSON.parse(fs15.readFileSync(pkgPath, "utf-8")), pkgPath };
|
|
5452
5605
|
} catch {
|
|
5453
5606
|
return { pkg: null, pkgPath: null };
|
|
5454
5607
|
}
|
|
@@ -5457,7 +5610,7 @@ function declaredPackageManager(dir, pkg) {
|
|
|
5457
5610
|
const declared = pkg?.packageManager?.split("@")[0];
|
|
5458
5611
|
if (declared === "pnpm" || declared === "yarn" || declared === "bun" || declared === "npm") return declared;
|
|
5459
5612
|
for (const [file, manager] of LOCKFILES) {
|
|
5460
|
-
if (
|
|
5613
|
+
if (fs15.existsSync(path19.join(dir, file))) return manager;
|
|
5461
5614
|
}
|
|
5462
5615
|
return null;
|
|
5463
5616
|
}
|
|
@@ -5467,16 +5620,16 @@ function detectPackageManager(root, pkg) {
|
|
|
5467
5620
|
for (; ; ) {
|
|
5468
5621
|
const manager = declaredPackageManager(dir, dirPkg);
|
|
5469
5622
|
if (manager) return manager;
|
|
5470
|
-
const parent =
|
|
5471
|
-
if (parent === dir ||
|
|
5623
|
+
const parent = path19.dirname(dir);
|
|
5624
|
+
if (parent === dir || fs15.existsSync(path19.join(dir, ".git"))) return "npm";
|
|
5472
5625
|
dir = parent;
|
|
5473
5626
|
dirPkg = readPackageJson(dir).pkg;
|
|
5474
5627
|
}
|
|
5475
5628
|
}
|
|
5476
5629
|
function findConfig(root) {
|
|
5477
5630
|
for (const name of CONFIG_NAMES2) {
|
|
5478
|
-
const candidate =
|
|
5479
|
-
if (
|
|
5631
|
+
const candidate = path19.join(root, name);
|
|
5632
|
+
if (fs15.existsSync(candidate)) return candidate;
|
|
5480
5633
|
}
|
|
5481
5634
|
return null;
|
|
5482
5635
|
}
|
|
@@ -5486,7 +5639,7 @@ function langOf(configPath) {
|
|
|
5486
5639
|
}
|
|
5487
5640
|
function suggestProjectName(root, pkg) {
|
|
5488
5641
|
const fromPkg = pkg?.name?.replace(/^@[^/]+\//, "").trim();
|
|
5489
|
-
return fromPkg ||
|
|
5642
|
+
return fromPkg || path19.basename(root) || "default-project";
|
|
5490
5643
|
}
|
|
5491
5644
|
function hasReporter(pkg) {
|
|
5492
5645
|
if (!pkg) return false;
|
|
@@ -5521,21 +5674,21 @@ function workspaceGlobs(root, pkg) {
|
|
|
5521
5674
|
typeof declared === "object" && declared !== null && "packages" in declared ? declared.packages : declared
|
|
5522
5675
|
);
|
|
5523
5676
|
try {
|
|
5524
|
-
globs.push(...pnpmWorkspaceGlobs(
|
|
5677
|
+
globs.push(...pnpmWorkspaceGlobs(fs15.readFileSync(path19.join(root, "pnpm-workspace.yaml"), "utf-8")));
|
|
5525
5678
|
} catch {
|
|
5526
5679
|
}
|
|
5527
5680
|
return globs;
|
|
5528
5681
|
}
|
|
5529
5682
|
function isDirectory(dir) {
|
|
5530
5683
|
try {
|
|
5531
|
-
return
|
|
5684
|
+
return fs15.statSync(dir).isDirectory();
|
|
5532
5685
|
} catch {
|
|
5533
5686
|
return false;
|
|
5534
5687
|
}
|
|
5535
5688
|
}
|
|
5536
5689
|
function subfolders(dir) {
|
|
5537
5690
|
try {
|
|
5538
|
-
return
|
|
5691
|
+
return fs15.readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== "node_modules" && !entry.name.startsWith(".")).map((entry) => path19.join(dir, entry.name));
|
|
5539
5692
|
} catch {
|
|
5540
5693
|
return [];
|
|
5541
5694
|
}
|
|
@@ -5558,27 +5711,27 @@ function expandGlob(root, glob) {
|
|
|
5558
5711
|
for (const child of subfolders(dir)) walk(child, index);
|
|
5559
5712
|
} else if (/[*?]/.test(segment)) {
|
|
5560
5713
|
const pattern = namePattern(segment);
|
|
5561
|
-
for (const child of subfolders(dir)) if (pattern.test(
|
|
5562
|
-
} else if (isDirectory(
|
|
5563
|
-
walk(
|
|
5714
|
+
for (const child of subfolders(dir)) if (pattern.test(path19.basename(child))) walk(child, index + 1);
|
|
5715
|
+
} else if (isDirectory(path19.join(dir, segment))) {
|
|
5716
|
+
walk(path19.join(dir, segment), index + 1);
|
|
5564
5717
|
}
|
|
5565
5718
|
};
|
|
5566
5719
|
walk(root, 0);
|
|
5567
5720
|
return found;
|
|
5568
5721
|
}
|
|
5569
5722
|
function workspacePackagesWithConfig(root) {
|
|
5570
|
-
const absRoot =
|
|
5723
|
+
const absRoot = path19.resolve(root);
|
|
5571
5724
|
const globs = workspaceGlobs(absRoot, readPackageJson(absRoot).pkg);
|
|
5572
5725
|
const excluded = new Set(
|
|
5573
5726
|
globs.filter((glob) => glob.startsWith("!")).flatMap((glob) => expandGlob(absRoot, glob.slice(1)))
|
|
5574
5727
|
);
|
|
5575
5728
|
const packages = new Set(
|
|
5576
|
-
globs.filter((glob) => !glob.startsWith("!")).flatMap((glob) => expandGlob(absRoot, glob)).filter((dir) => dir !== absRoot && !excluded.has(dir) &&
|
|
5729
|
+
globs.filter((glob) => !glob.startsWith("!")).flatMap((glob) => expandGlob(absRoot, glob)).filter((dir) => dir !== absRoot && !excluded.has(dir) && fs15.existsSync(path19.join(dir, "package.json")))
|
|
5577
5730
|
);
|
|
5578
|
-
return [...packages].filter((dir) => findConfig(dir) !== null).map((dir) =>
|
|
5731
|
+
return [...packages].filter((dir) => findConfig(dir) !== null).map((dir) => path19.relative(absRoot, dir).split(path19.sep).join("/")).sort();
|
|
5579
5732
|
}
|
|
5580
5733
|
function detectProject(root) {
|
|
5581
|
-
const absRoot =
|
|
5734
|
+
const absRoot = path19.resolve(root);
|
|
5582
5735
|
const { pkg, pkgPath } = readPackageJson(absRoot);
|
|
5583
5736
|
const configPath = findConfig(absRoot);
|
|
5584
5737
|
return {
|
|
@@ -5744,8 +5897,8 @@ function ensureGitignoreEntry(existing, entry = ".env") {
|
|
|
5744
5897
|
}
|
|
5745
5898
|
|
|
5746
5899
|
// src/cli/skills.ts
|
|
5747
|
-
var
|
|
5748
|
-
var
|
|
5900
|
+
var fs16 = __toESM(require("fs"));
|
|
5901
|
+
var path20 = __toESM(require("path"));
|
|
5749
5902
|
|
|
5750
5903
|
// ../core/src/hash.ts
|
|
5751
5904
|
function fnv1a32(input, seed = 2166136261) {
|
|
@@ -5810,16 +5963,16 @@ var WORKFLOW_SKILLS = [
|
|
|
5810
5963
|
"fix-a-reported-bug"
|
|
5811
5964
|
];
|
|
5812
5965
|
var ALL_SKILLS = [SETUP_SKILL, ...WORKFLOW_SKILLS];
|
|
5813
|
-
var DEFAULT_SKILLS_DIR =
|
|
5966
|
+
var DEFAULT_SKILLS_DIR = path20.join(".claude", "skills");
|
|
5814
5967
|
function findTemplatesDir(fromDir) {
|
|
5815
5968
|
let dir = fromDir;
|
|
5816
5969
|
for (let i = 0; i < 6; i++) {
|
|
5817
|
-
if (
|
|
5818
|
-
const parent =
|
|
5970
|
+
if (fs16.existsSync(path20.join(dir, "templates", "skills"))) return path20.join(dir, "templates");
|
|
5971
|
+
const parent = path20.dirname(dir);
|
|
5819
5972
|
if (parent === dir) break;
|
|
5820
5973
|
dir = parent;
|
|
5821
5974
|
}
|
|
5822
|
-
return
|
|
5975
|
+
return path20.resolve(fromDir, "..", "..", "templates");
|
|
5823
5976
|
}
|
|
5824
5977
|
function readFrontMatter(markdown) {
|
|
5825
5978
|
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(markdown);
|
|
@@ -5833,21 +5986,21 @@ function readFrontMatter(markdown) {
|
|
|
5833
5986
|
}
|
|
5834
5987
|
function readTemplatesVersion(templatesDir) {
|
|
5835
5988
|
try {
|
|
5836
|
-
const pkg = JSON.parse(
|
|
5989
|
+
const pkg = JSON.parse(fs16.readFileSync(path20.join(templatesDir, "..", "package.json"), "utf-8"));
|
|
5837
5990
|
return typeof pkg.version === "string" ? pkg.version : "0.0.0";
|
|
5838
5991
|
} catch {
|
|
5839
5992
|
return "0.0.0";
|
|
5840
5993
|
}
|
|
5841
5994
|
}
|
|
5842
5995
|
function templatePath(templatesDir, slug) {
|
|
5843
|
-
return
|
|
5996
|
+
return path20.join(templatesDir, "skills", slug, "SKILL.md");
|
|
5844
5997
|
}
|
|
5845
5998
|
function listSkills(templatesDir, slugs = ALL_SKILLS) {
|
|
5846
5999
|
const infos = [];
|
|
5847
6000
|
for (const slug of slugs) {
|
|
5848
6001
|
const file = templatePath(templatesDir, slug);
|
|
5849
|
-
if (!
|
|
5850
|
-
const front = readFrontMatter(
|
|
6002
|
+
if (!fs16.existsSync(file)) continue;
|
|
6003
|
+
const front = readFrontMatter(fs16.readFileSync(file, "utf-8"));
|
|
5851
6004
|
infos.push({ slug, name: front.name ?? slug, description: front.description ?? "" });
|
|
5852
6005
|
}
|
|
5853
6006
|
return infos;
|
|
@@ -5857,18 +6010,18 @@ function installSkills(opts) {
|
|
|
5857
6010
|
for (const slug of opts.slugs) {
|
|
5858
6011
|
const step = `skill:${slug}`;
|
|
5859
6012
|
const source = templatePath(opts.templatesDir, slug);
|
|
5860
|
-
const relDest =
|
|
5861
|
-
const dest =
|
|
5862
|
-
if (!
|
|
6013
|
+
const relDest = path20.join(opts.skillsDir, slug, "SKILL.md");
|
|
6014
|
+
const dest = path20.join(opts.root, relDest);
|
|
6015
|
+
if (!fs16.existsSync(source)) {
|
|
5863
6016
|
results.push({ step, status: "error", detail: `no template found for "${slug}"` });
|
|
5864
6017
|
continue;
|
|
5865
6018
|
}
|
|
5866
6019
|
const version = opts.version ?? readTemplatesVersion(opts.templatesDir);
|
|
5867
|
-
const contents = stampSkill(
|
|
5868
|
-
const exists =
|
|
6020
|
+
const contents = stampSkill(fs16.readFileSync(source, "utf-8"), version);
|
|
6021
|
+
const exists = fs16.existsSync(dest);
|
|
5869
6022
|
let detail = "installed skill";
|
|
5870
6023
|
if (exists) {
|
|
5871
|
-
const installed =
|
|
6024
|
+
const installed = fs16.readFileSync(dest, "utf-8");
|
|
5872
6025
|
const state = classifyInstalledSkill(installed, contents);
|
|
5873
6026
|
const from = readSkillStamp(installed).version;
|
|
5874
6027
|
if (state === "current") {
|
|
@@ -5890,8 +6043,8 @@ function installSkills(opts) {
|
|
|
5890
6043
|
}
|
|
5891
6044
|
}
|
|
5892
6045
|
if (!opts.dryRun) {
|
|
5893
|
-
|
|
5894
|
-
|
|
6046
|
+
fs16.mkdirSync(path20.dirname(dest), { recursive: true });
|
|
6047
|
+
fs16.writeFileSync(dest, contents);
|
|
5895
6048
|
}
|
|
5896
6049
|
results.push({ step, file: relDest, status: exists ? "updated" : "created", detail });
|
|
5897
6050
|
}
|
|
@@ -5963,7 +6116,7 @@ function runSkills(argv, templatesDir, cwd = process.cwd()) {
|
|
|
5963
6116
|
}
|
|
5964
6117
|
const results = installSkills({
|
|
5965
6118
|
templatesDir,
|
|
5966
|
-
root:
|
|
6119
|
+
root: path20.resolve(readOption5(rest, "--cwd") ?? cwd),
|
|
5967
6120
|
skillsDir: readOption5(rest, "--dir") ?? DEFAULT_SKILLS_DIR,
|
|
5968
6121
|
slugs: requested.length ? requested : ALL_SKILLS,
|
|
5969
6122
|
force: rest.includes("--force"),
|
|
@@ -6047,7 +6200,7 @@ function resolveSkillSlugs(raw) {
|
|
|
6047
6200
|
return raw.split(",").map((slug) => slug.trim()).filter(Boolean);
|
|
6048
6201
|
}
|
|
6049
6202
|
function parseInitArgs(argv, env, cwd) {
|
|
6050
|
-
const root =
|
|
6203
|
+
const root = path21.resolve(cwd, readOption6(argv, "--cwd") ?? ".");
|
|
6051
6204
|
const detected = detectProject(root);
|
|
6052
6205
|
const noServerUrl = argv.includes("--no-server-url");
|
|
6053
6206
|
const flagKey = readOption6(argv, "--api-key");
|
|
@@ -6071,7 +6224,7 @@ function parseInitArgs(argv, env, cwd) {
|
|
|
6071
6224
|
}
|
|
6072
6225
|
function readFileOr(file, fallback) {
|
|
6073
6226
|
try {
|
|
6074
|
-
return
|
|
6227
|
+
return fs17.readFileSync(file, "utf-8");
|
|
6075
6228
|
} catch {
|
|
6076
6229
|
return fallback;
|
|
6077
6230
|
}
|
|
@@ -6114,7 +6267,7 @@ function stepRecordReporter(project, opts) {
|
|
|
6114
6267
|
const file = "package.json";
|
|
6115
6268
|
const version = readTemplatesVersion(findTemplatesDir(__dirname));
|
|
6116
6269
|
const range = version === "0.0.0" ? "latest" : `^${version}`;
|
|
6117
|
-
const pkgPath = project.packageJsonPath ??
|
|
6270
|
+
const pkgPath = project.packageJsonPath ?? path21.join(project.root, file);
|
|
6118
6271
|
const edit = recordDevDependency(readFileOr(pkgPath, ""), REPORTER_PACKAGE, range);
|
|
6119
6272
|
if (edit.status === "manual")
|
|
6120
6273
|
return {
|
|
@@ -6123,7 +6276,7 @@ function stepRecordReporter(project, opts) {
|
|
|
6123
6276
|
status: "manual",
|
|
6124
6277
|
detail: `Could not read package.json \u2014 run \`${installCommand(project.packageManager)}\``
|
|
6125
6278
|
};
|
|
6126
|
-
if (edit.status === "updated" && !opts.dryRun)
|
|
6279
|
+
if (edit.status === "updated" && !opts.dryRun) fs17.writeFileSync(pkgPath, edit.text);
|
|
6127
6280
|
return {
|
|
6128
6281
|
step,
|
|
6129
6282
|
file,
|
|
@@ -6139,7 +6292,7 @@ function stepConfig(project, opts) {
|
|
|
6139
6292
|
status: "manual",
|
|
6140
6293
|
detail: "No playwright.config found \u2014 create one, then re-run `npx @piwitests/reporter init`"
|
|
6141
6294
|
};
|
|
6142
|
-
const rel =
|
|
6295
|
+
const rel = path21.relative(project.root, project.configPath) || path21.basename(project.configPath);
|
|
6143
6296
|
const source = readFileOr(project.configPath, "");
|
|
6144
6297
|
const desktopApp = opts.desktopApp ?? void 0;
|
|
6145
6298
|
const edit = wrapPlaywrightConfig(source, {
|
|
@@ -6147,7 +6300,7 @@ function stepConfig(project, opts) {
|
|
|
6147
6300
|
projectName: opts.projectName,
|
|
6148
6301
|
desktopApp
|
|
6149
6302
|
});
|
|
6150
|
-
if (edit.status === "updated" && !opts.dryRun)
|
|
6303
|
+
if (edit.status === "updated" && !opts.dryRun) fs17.writeFileSync(project.configPath, edit.text);
|
|
6151
6304
|
if (edit.status === "already" && desktopApp && !new RegExp(`\\bdesktopApp\\s*:\\s*['"\`]${desktopApp}['"\`]`).test(source)) {
|
|
6152
6305
|
return {
|
|
6153
6306
|
step,
|
|
@@ -6160,9 +6313,9 @@ function stepConfig(project, opts) {
|
|
|
6160
6313
|
}
|
|
6161
6314
|
function stepFixtures(project, opts) {
|
|
6162
6315
|
const step = "fixtures";
|
|
6163
|
-
const rel =
|
|
6164
|
-
const dest =
|
|
6165
|
-
if (
|
|
6316
|
+
const rel = path21.join("tests", project.configLang === "js" ? "fixtures.js" : "fixtures.ts");
|
|
6317
|
+
const dest = path21.join(project.root, rel);
|
|
6318
|
+
if (fs17.existsSync(dest)) {
|
|
6166
6319
|
const current = readFileOr(dest, "");
|
|
6167
6320
|
if (/piwiFixtures/.test(current))
|
|
6168
6321
|
return { step, file: rel, status: "already", detail: "capture fixtures already set up" };
|
|
@@ -6174,8 +6327,8 @@ function stepFixtures(project, opts) {
|
|
|
6174
6327
|
};
|
|
6175
6328
|
}
|
|
6176
6329
|
if (!opts.dryRun) {
|
|
6177
|
-
|
|
6178
|
-
|
|
6330
|
+
fs17.mkdirSync(path21.dirname(dest), { recursive: true });
|
|
6331
|
+
fs17.writeFileSync(dest, fixturesContents());
|
|
6179
6332
|
}
|
|
6180
6333
|
return {
|
|
6181
6334
|
step,
|
|
@@ -6195,9 +6348,9 @@ function gitTracking(root, file) {
|
|
|
6195
6348
|
return inRepository(root) ? "unknown" : "untracked";
|
|
6196
6349
|
}
|
|
6197
6350
|
function inRepository(dir) {
|
|
6198
|
-
for (let current =
|
|
6199
|
-
if (
|
|
6200
|
-
if (
|
|
6351
|
+
for (let current = path21.resolve(dir); ; current = path21.dirname(current)) {
|
|
6352
|
+
if (fs17.existsSync(path21.join(current, ".git"))) return true;
|
|
6353
|
+
if (path21.dirname(current) === current) return false;
|
|
6201
6354
|
}
|
|
6202
6355
|
}
|
|
6203
6356
|
var KEY_IN_ENVIRONMENT = "set PIWI_API_KEY in the environment (in CI, as a secret)";
|
|
@@ -6215,7 +6368,7 @@ function envKeyBlock(root) {
|
|
|
6215
6368
|
instead: `${KEY_IN_ENVIRONMENT}, or make \`git ls-files .env\` work here`
|
|
6216
6369
|
};
|
|
6217
6370
|
}
|
|
6218
|
-
const env =
|
|
6371
|
+
const env = fs17.lstatSync(path21.join(root, ".env"), { throwIfNoEntry: false });
|
|
6219
6372
|
if (env && (env.isSymbolicLink() || env.nlink > 1)) {
|
|
6220
6373
|
return { why: ".env is a link", instead: `${KEY_IN_ENVIRONMENT}, or put a file of its own in place of the link` };
|
|
6221
6374
|
}
|
|
@@ -6223,12 +6376,12 @@ function envKeyBlock(root) {
|
|
|
6223
6376
|
}
|
|
6224
6377
|
function stepEnv(project, opts, envBlock) {
|
|
6225
6378
|
const results = [];
|
|
6226
|
-
const examplePath =
|
|
6379
|
+
const examplePath = path21.join(project.root, ".env.example");
|
|
6227
6380
|
const example = upsertEnvKeys(readFileOr(examplePath, ""), [
|
|
6228
6381
|
["PIWI_DASHBOARD_URL", opts.serverUrl],
|
|
6229
6382
|
["PIWI_API_KEY", ""]
|
|
6230
6383
|
]);
|
|
6231
|
-
if (example.added.length && !opts.dryRun)
|
|
6384
|
+
if (example.added.length && !opts.dryRun) fs17.writeFileSync(examplePath, example.text);
|
|
6232
6385
|
results.push({
|
|
6233
6386
|
step: "env",
|
|
6234
6387
|
file: ".env.example",
|
|
@@ -6250,20 +6403,20 @@ function stepEnv(project, opts, envBlock) {
|
|
|
6250
6403
|
detail: `${envBlock.why}, so the API key is not written into it \u2014 ${envBlock.instead} and run init again`
|
|
6251
6404
|
});
|
|
6252
6405
|
} else if (opts.apiKey) {
|
|
6253
|
-
const envPath =
|
|
6406
|
+
const envPath = path21.join(project.root, ".env");
|
|
6254
6407
|
const entries = [["PIWI_API_KEY", opts.apiKey]];
|
|
6255
6408
|
if (opts.serverUrl) entries.unshift(["PIWI_DASHBOARD_URL", opts.serverUrl]);
|
|
6256
6409
|
const env = upsertEnvKeys(readFileOr(envPath, ""), entries);
|
|
6257
|
-
if (env.added.length && !opts.dryRun)
|
|
6410
|
+
if (env.added.length && !opts.dryRun) fs17.writeFileSync(envPath, env.text);
|
|
6258
6411
|
results.push({
|
|
6259
6412
|
step: "env",
|
|
6260
6413
|
file: ".env",
|
|
6261
6414
|
status: env.added.length ? "updated" : "already",
|
|
6262
6415
|
detail: env.added.length ? `Wrote ${env.added.join(", ")} (keep .env out of git)` : "already set"
|
|
6263
6416
|
});
|
|
6264
|
-
const gitignorePath =
|
|
6417
|
+
const gitignorePath = path21.join(project.root, ".gitignore");
|
|
6265
6418
|
const gitignore = ensureGitignoreEntry(readFileOr(gitignorePath, ""));
|
|
6266
|
-
if (gitignore.added && !opts.dryRun)
|
|
6419
|
+
if (gitignore.added && !opts.dryRun) fs17.writeFileSync(gitignorePath, gitignore.text);
|
|
6267
6420
|
results.push({
|
|
6268
6421
|
step: "gitignore",
|
|
6269
6422
|
file: ".gitignore",
|
|
@@ -6343,7 +6496,7 @@ function inPackage(opts, argv, root) {
|
|
|
6343
6496
|
}
|
|
6344
6497
|
function unwiredWorkspace(workspace, cwd) {
|
|
6345
6498
|
const flags = workspace.packages.map(
|
|
6346
|
-
(pkg) => `\`--cwd ${
|
|
6499
|
+
(pkg) => `\`--cwd ${path21.relative(cwd, path21.join(workspace.root, pkg)) || "."}\``
|
|
6347
6500
|
);
|
|
6348
6501
|
return {
|
|
6349
6502
|
step: {
|
|
@@ -6365,7 +6518,7 @@ function printOutcome(opts, project, workspace, steps, guidance) {
|
|
|
6365
6518
|
project: {
|
|
6366
6519
|
root: project.root,
|
|
6367
6520
|
packageManager: project.packageManager,
|
|
6368
|
-
configPath: project.configPath ?
|
|
6521
|
+
configPath: project.configPath ? path21.relative(project.root, project.configPath) : null,
|
|
6369
6522
|
projectName: opts.projectName,
|
|
6370
6523
|
serverUrl: opts.serverUrl,
|
|
6371
6524
|
desktopApp: opts.desktopApp
|
|
@@ -6413,7 +6566,7 @@ async function runInit(argv, env = process.env, cwd = process.cwd(), ask = termi
|
|
|
6413
6566
|
return 0;
|
|
6414
6567
|
}
|
|
6415
6568
|
if (workspace?.wired) {
|
|
6416
|
-
opts = inPackage(opts, argv,
|
|
6569
|
+
opts = inPackage(opts, argv, path21.join(workspace.root, workspace.wired));
|
|
6417
6570
|
project = detectProject(opts.root);
|
|
6418
6571
|
}
|
|
6419
6572
|
const steps = [];
|
|
@@ -6441,8 +6594,8 @@ async function runInit(argv, env = process.env, cwd = process.cwd(), ask = termi
|
|
|
6441
6594
|
}
|
|
6442
6595
|
|
|
6443
6596
|
// src/cli/select.ts
|
|
6444
|
-
var
|
|
6445
|
-
var
|
|
6597
|
+
var fs19 = __toESM(require("fs"));
|
|
6598
|
+
var path23 = __toESM(require("path"));
|
|
6446
6599
|
var import_node_child_process8 = require("child_process");
|
|
6447
6600
|
|
|
6448
6601
|
// ../core/src/diff-anchors.ts
|
|
@@ -6453,8 +6606,8 @@ var INDEX_LINE = /^index ([0-9a-f]+)\.\.([0-9a-f]+)(?: |$)/i;
|
|
|
6453
6606
|
function blobOf(id) {
|
|
6454
6607
|
return /^0+$/.test(id) ? void 0 : id.toLowerCase();
|
|
6455
6608
|
}
|
|
6456
|
-
function stripPrefix(
|
|
6457
|
-
const unquoted =
|
|
6609
|
+
function stripPrefix(path26) {
|
|
6610
|
+
const unquoted = path26.startsWith('"') && path26.endsWith('"') ? path26.slice(1, -1) : path26;
|
|
6458
6611
|
return unquoted.replace(/^[ab]\//, "");
|
|
6459
6612
|
}
|
|
6460
6613
|
function parseUnifiedDiff(text) {
|
|
@@ -6571,8 +6724,8 @@ function pathGlobToRegExp(glob) {
|
|
|
6571
6724
|
});
|
|
6572
6725
|
return new RegExp(`^(?:${parts.join("|")})$`);
|
|
6573
6726
|
}
|
|
6574
|
-
function isTranslationFile(
|
|
6575
|
-
const posix2 =
|
|
6727
|
+
function isTranslationFile(path26, globs = DEFAULT_TRANSLATION_GLOBS) {
|
|
6728
|
+
const posix2 = path26.replace(/\\/g, "/");
|
|
6576
6729
|
if (!TRANSLATION_EXTENSIONS.test(posix2)) return false;
|
|
6577
6730
|
return globs.some((g) => pathGlobToRegExp(g).test(posix2));
|
|
6578
6731
|
}
|
|
@@ -6712,13 +6865,13 @@ function unquoteYaml(raw) {
|
|
|
6712
6865
|
function decodeXml2(text) {
|
|
6713
6866
|
return text.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
6714
6867
|
}
|
|
6715
|
-
function parseTranslationFile(
|
|
6868
|
+
function parseTranslationFile(path26, content) {
|
|
6716
6869
|
const lines = content.split(/\r?\n/);
|
|
6717
6870
|
const out = [];
|
|
6718
|
-
const ext = /\.([a-z]+)$/i.exec(
|
|
6871
|
+
const ext = /\.([a-z]+)$/i.exec(path26)?.[1]?.toLowerCase();
|
|
6719
6872
|
if (ext === "json") {
|
|
6720
6873
|
const stack = [];
|
|
6721
|
-
const
|
|
6874
|
+
const path27 = (key) => [...stack.map((f) => f.key), key].join(".");
|
|
6722
6875
|
lines.forEach((text, i) => {
|
|
6723
6876
|
const t = text.trim();
|
|
6724
6877
|
const top = stack[stack.length - 1];
|
|
@@ -6727,14 +6880,14 @@ function parseTranslationFile(path25, content) {
|
|
|
6727
6880
|
const key = JSON.parse(`"${pair[1]}"`);
|
|
6728
6881
|
const rest = pair[2];
|
|
6729
6882
|
const str = /^"((?:[^"\\]|\\.)*)"/.exec(rest);
|
|
6730
|
-
if (str) out.push({ key:
|
|
6883
|
+
if (str) out.push({ key: path27(key), value: JSON.parse(`"${str[1]}"`), line: i + 1 });
|
|
6731
6884
|
else if (/^[[{]\s*$/.test(rest)) stack.push({ key, array: rest.startsWith("["), next: 0 });
|
|
6732
6885
|
return;
|
|
6733
6886
|
}
|
|
6734
6887
|
if (top?.array) {
|
|
6735
6888
|
const str = /^"((?:[^"\\]|\\.)*)"\s*,?$/.exec(t);
|
|
6736
6889
|
if (str) {
|
|
6737
|
-
out.push({ key:
|
|
6890
|
+
out.push({ key: path27(top.next++), value: JSON.parse(`"${str[1]}"`), line: i + 1 });
|
|
6738
6891
|
return;
|
|
6739
6892
|
}
|
|
6740
6893
|
if (/^[[{]\s*$/.test(t)) {
|
|
@@ -6798,8 +6951,8 @@ function parseTranslationFile(path25, content) {
|
|
|
6798
6951
|
}
|
|
6799
6952
|
return out;
|
|
6800
6953
|
}
|
|
6801
|
-
function translationLineToken(
|
|
6802
|
-
const ext = /\.([a-z]+)$/i.exec(
|
|
6954
|
+
function translationLineToken(path26, text, line) {
|
|
6955
|
+
const ext = /\.([a-z]+)$/i.exec(path26)?.[1]?.toLowerCase();
|
|
6803
6956
|
let key;
|
|
6804
6957
|
let value;
|
|
6805
6958
|
if (ext === "json") {
|
|
@@ -6836,9 +6989,9 @@ function translationLineToken(path25, text, line) {
|
|
|
6836
6989
|
if (value === void 0 || !keepable(value)) return null;
|
|
6837
6990
|
return { kind: "translation", group: `translation:${key ?? ""}`, value, key, line };
|
|
6838
6991
|
}
|
|
6839
|
-
function lineTokens(
|
|
6992
|
+
function lineTokens(path26, text, line, side, attributes, options) {
|
|
6840
6993
|
const spans = [];
|
|
6841
|
-
const markup = MARKUP_FILE.test(
|
|
6994
|
+
const markup = MARKUP_FILE.test(path26);
|
|
6842
6995
|
return [
|
|
6843
6996
|
...attributeTokens(text, attributes, line, spans),
|
|
6844
6997
|
...translationRefTokens(text, line, side, options.translations, spans),
|
|
@@ -6846,10 +6999,10 @@ function lineTokens(path25, text, line, side, attributes, options) {
|
|
|
6846
6999
|
...textTokens(text, line, markup)
|
|
6847
7000
|
];
|
|
6848
7001
|
}
|
|
6849
|
-
function keysByLine(
|
|
6850
|
-
const content = options.readFile?.(
|
|
7002
|
+
function keysByLine(path26, side, options) {
|
|
7003
|
+
const content = options.readFile?.(path26, side);
|
|
6851
7004
|
if (content === void 0) return null;
|
|
6852
|
-
return new Map(parseTranslationFile(
|
|
7005
|
+
return new Map(parseTranslationFile(path26, content).map((e) => [e.line, e.key]));
|
|
6853
7006
|
}
|
|
6854
7007
|
function tokenId(t) {
|
|
6855
7008
|
return `${t.group}\0${t.value}`;
|
|
@@ -7149,7 +7302,7 @@ function slotMatches(slot, text) {
|
|
|
7149
7302
|
return textMatches(slot.value, slot.exact, text);
|
|
7150
7303
|
}
|
|
7151
7304
|
}
|
|
7152
|
-
var filePath = (
|
|
7305
|
+
var filePath = (path26) => path26.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
7153
7306
|
function sameFilePath(a, b) {
|
|
7154
7307
|
const x = filePath(a);
|
|
7155
7308
|
const y = filePath(b);
|
|
@@ -7287,8 +7440,8 @@ function diffImpactInput(files) {
|
|
|
7287
7440
|
}
|
|
7288
7441
|
|
|
7289
7442
|
// src/cli/add-reporter.ts
|
|
7290
|
-
var
|
|
7291
|
-
var
|
|
7443
|
+
var fs18 = __toESM(require("fs"));
|
|
7444
|
+
var path22 = __toESM(require("path"));
|
|
7292
7445
|
var import_node_module2 = require("module");
|
|
7293
7446
|
|
|
7294
7447
|
// src/internal/support/playwright-version.ts
|
|
@@ -7328,9 +7481,9 @@ function resolveConfigPath(cwd, playwrightArgs2) {
|
|
|
7328
7481
|
const arg = playwrightArgs2[i];
|
|
7329
7482
|
if (arg === "--config" || arg === "-c") {
|
|
7330
7483
|
const next = playwrightArgs2[i + 1];
|
|
7331
|
-
if (next) return
|
|
7484
|
+
if (next) return path22.resolve(cwd, next);
|
|
7332
7485
|
} else if (arg.startsWith("--config=")) {
|
|
7333
|
-
return
|
|
7486
|
+
return path22.resolve(cwd, arg.slice("--config=".length));
|
|
7334
7487
|
}
|
|
7335
7488
|
}
|
|
7336
7489
|
return detectProject(cwd).configPath;
|
|
@@ -7338,14 +7491,14 @@ function resolveConfigPath(cwd, playwrightArgs2) {
|
|
|
7338
7491
|
function readConfigSource(configPath) {
|
|
7339
7492
|
if (!configPath) return null;
|
|
7340
7493
|
try {
|
|
7341
|
-
return
|
|
7494
|
+
return fs18.readFileSync(configPath, "utf-8");
|
|
7342
7495
|
} catch {
|
|
7343
7496
|
return null;
|
|
7344
7497
|
}
|
|
7345
7498
|
}
|
|
7346
7499
|
function readInstalledPlaywrightVersion(cwd) {
|
|
7347
7500
|
try {
|
|
7348
|
-
const require2 = (0, import_node_module2.createRequire)(
|
|
7501
|
+
const require2 = (0, import_node_module2.createRequire)(path22.join(cwd, "noop.js"));
|
|
7349
7502
|
for (const id of ["@playwright/test/package.json", "playwright/package.json"]) {
|
|
7350
7503
|
try {
|
|
7351
7504
|
return require2(id).version ?? null;
|
|
@@ -7478,13 +7631,13 @@ function parseSelectArgs(argv, env, dirs = [], command = "piwi select") {
|
|
|
7478
7631
|
extra
|
|
7479
7632
|
};
|
|
7480
7633
|
}
|
|
7481
|
-
var CACHE_FILE =
|
|
7634
|
+
var CACHE_FILE = path23.join(".piwi", "selection-cache.json");
|
|
7482
7635
|
function cacheKey(args) {
|
|
7483
7636
|
return `${args.project.toLowerCase()}:${args.key}:${args.format}:${args.budgetMs ?? 0}:${args.shard ?? ""}:${args.order ?? ""}`;
|
|
7484
7637
|
}
|
|
7485
7638
|
function readCache(args) {
|
|
7486
7639
|
try {
|
|
7487
|
-
const store = JSON.parse(
|
|
7640
|
+
const store = JSON.parse(fs19.readFileSync(CACHE_FILE, "utf-8"));
|
|
7488
7641
|
return store[cacheKey(args)] ?? null;
|
|
7489
7642
|
} catch {
|
|
7490
7643
|
return null;
|
|
@@ -7494,12 +7647,12 @@ function writeCache(args, resolution) {
|
|
|
7494
7647
|
try {
|
|
7495
7648
|
let store = {};
|
|
7496
7649
|
try {
|
|
7497
|
-
store = JSON.parse(
|
|
7650
|
+
store = JSON.parse(fs19.readFileSync(CACHE_FILE, "utf-8"));
|
|
7498
7651
|
} catch {
|
|
7499
7652
|
}
|
|
7500
7653
|
store[cacheKey(args)] = resolution;
|
|
7501
|
-
|
|
7502
|
-
|
|
7654
|
+
fs19.mkdirSync(path23.dirname(CACHE_FILE), { recursive: true });
|
|
7655
|
+
fs19.writeFileSync(CACHE_FILE, JSON.stringify(store, null, 2));
|
|
7503
7656
|
} catch {
|
|
7504
7657
|
}
|
|
7505
7658
|
}
|
|
@@ -7732,8 +7885,8 @@ async function runRun(argv, env = process.env) {
|
|
|
7732
7885
|
}
|
|
7733
7886
|
|
|
7734
7887
|
// src/cli/preflight.ts
|
|
7735
|
-
var
|
|
7736
|
-
var
|
|
7888
|
+
var fs20 = __toESM(require("fs"));
|
|
7889
|
+
var path24 = __toESM(require("path"));
|
|
7737
7890
|
var import_node_child_process9 = require("child_process");
|
|
7738
7891
|
|
|
7739
7892
|
// ../core/src/locator-edit.ts
|
|
@@ -7886,7 +8039,7 @@ function translationLookup(repoRoot, base, locale) {
|
|
|
7886
8039
|
const build = (side) => {
|
|
7887
8040
|
const map = /* @__PURE__ */ new Map();
|
|
7888
8041
|
for (const file of files) {
|
|
7889
|
-
const content = side === "new" ? readText(
|
|
8042
|
+
const content = side === "new" ? readText(path24.join(repoRoot, file)) : tryGit(repoRoot, ["show", `${base}:${file}`]);
|
|
7890
8043
|
if (content === void 0) continue;
|
|
7891
8044
|
for (const entry of parseTranslationFile(file, content)) {
|
|
7892
8045
|
if (!map.has(entry.key)) map.set(entry.key, entry.value);
|
|
@@ -7905,34 +8058,34 @@ function prefersLocale(file, locale) {
|
|
|
7905
8058
|
}
|
|
7906
8059
|
function readText(file) {
|
|
7907
8060
|
try {
|
|
7908
|
-
return
|
|
8061
|
+
return fs20.readFileSync(file, "utf-8");
|
|
7909
8062
|
} catch {
|
|
7910
8063
|
return void 0;
|
|
7911
8064
|
}
|
|
7912
8065
|
}
|
|
7913
|
-
var CACHE_FILE2 =
|
|
8066
|
+
var CACHE_FILE2 = path24.join(".piwi", "locator-index.json");
|
|
7914
8067
|
function cacheKey2(connection, branch) {
|
|
7915
8068
|
return `${connection.serverUrl}|${connection.project}|${branch ?? ""}`;
|
|
7916
8069
|
}
|
|
7917
8070
|
function readCache2(root, key) {
|
|
7918
8071
|
try {
|
|
7919
|
-
const store = JSON.parse(
|
|
8072
|
+
const store = JSON.parse(fs20.readFileSync(path24.join(root, CACHE_FILE2), "utf-8"));
|
|
7920
8073
|
return store[key] ?? null;
|
|
7921
8074
|
} catch {
|
|
7922
8075
|
return null;
|
|
7923
8076
|
}
|
|
7924
8077
|
}
|
|
7925
8078
|
function writeCache2(root, key, index) {
|
|
7926
|
-
const file =
|
|
8079
|
+
const file = path24.join(root, CACHE_FILE2);
|
|
7927
8080
|
try {
|
|
7928
8081
|
let store = {};
|
|
7929
8082
|
try {
|
|
7930
|
-
store = JSON.parse(
|
|
8083
|
+
store = JSON.parse(fs20.readFileSync(file, "utf-8"));
|
|
7931
8084
|
} catch {
|
|
7932
8085
|
}
|
|
7933
8086
|
store[key] = { savedAt: (/* @__PURE__ */ new Date()).toISOString(), index };
|
|
7934
|
-
|
|
7935
|
-
|
|
8087
|
+
fs20.mkdirSync(path24.dirname(file), { recursive: true });
|
|
8088
|
+
fs20.writeFileSync(file, JSON.stringify(store));
|
|
7936
8089
|
} catch {
|
|
7937
8090
|
}
|
|
7938
8091
|
}
|
|
@@ -7948,7 +8101,7 @@ function planSites(b, testRoot) {
|
|
|
7948
8101
|
const sites = [...new Set(b.uses.flatMap((u) => u.callSites))];
|
|
7949
8102
|
return sites.map((callSite) => {
|
|
7950
8103
|
if (!b.rewrite || !b.replacements?.length) return { callSite, action: "none" };
|
|
7951
|
-
const file =
|
|
8104
|
+
const file = path24.resolve(testRoot, callSiteFile(callSite));
|
|
7952
8105
|
const lineNo = callSiteLine(callSite);
|
|
7953
8106
|
const text = readText(file);
|
|
7954
8107
|
if (text === void 0 || lineNo === null) return { callSite, action: "elsewhere" };
|
|
@@ -7991,7 +8144,7 @@ function applyEdits(breaks, replacementsOf) {
|
|
|
7991
8144
|
}
|
|
7992
8145
|
const edited = [];
|
|
7993
8146
|
for (const [file, edits] of byFile) {
|
|
7994
|
-
const text =
|
|
8147
|
+
const text = fs20.readFileSync(file, "utf-8");
|
|
7995
8148
|
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
7996
8149
|
const lines = text.split(/\r?\n/);
|
|
7997
8150
|
for (const e of edits) {
|
|
@@ -8001,7 +8154,7 @@ function applyEdits(breaks, replacementsOf) {
|
|
|
8001
8154
|
}
|
|
8002
8155
|
const next = lines.join(eol);
|
|
8003
8156
|
if (next !== text) {
|
|
8004
|
-
|
|
8157
|
+
fs20.writeFileSync(file, next);
|
|
8005
8158
|
edited.push(file);
|
|
8006
8159
|
}
|
|
8007
8160
|
}
|
|
@@ -8112,7 +8265,7 @@ async function runPreflight(argv, env = process.env, cwd = process.cwd()) {
|
|
|
8112
8265
|
console.error("piwi preflight: not inside a git repository");
|
|
8113
8266
|
return EXIT_ERROR8;
|
|
8114
8267
|
}
|
|
8115
|
-
const testRoot =
|
|
8268
|
+
const testRoot = path24.resolve(cwd, args.testRoot ?? findPlaywrightRoot(cwd, repoRoot) ?? cwd);
|
|
8116
8269
|
let files;
|
|
8117
8270
|
try {
|
|
8118
8271
|
files = parseUnifiedDiff(
|
|
@@ -8161,7 +8314,7 @@ async function runPreflight(argv, env = process.env, cwd = process.cwd()) {
|
|
|
8161
8314
|
testIdAttributes: index.testIdAttributes ?? void 0,
|
|
8162
8315
|
isTestFile: (file) => TEST_FILE.test(file),
|
|
8163
8316
|
translations: translationLookup(repoRoot, args.base, args.locale),
|
|
8164
|
-
readFile: (file, side) => side === "new" ? readText(
|
|
8317
|
+
readFile: (file, side) => side === "new" ? readText(path24.join(repoRoot, file)) : tryGit(repoRoot, ["show", `${args.base}:${file}`])
|
|
8165
8318
|
});
|
|
8166
8319
|
const found = predictLocatorBreaks(anchors, index, { reach: await loadReach(connection, projectId, args.branch) });
|
|
8167
8320
|
const replacementsOf = /* @__PURE__ */ new Map();
|
|
@@ -8207,8 +8360,8 @@ async function runPreflight(argv, env = process.env, cwd = process.cwd()) {
|
|
|
8207
8360
|
if (args.json) console.log(JSON.stringify(result, null, 2));
|
|
8208
8361
|
else {
|
|
8209
8362
|
const rel = (file) => {
|
|
8210
|
-
const abs =
|
|
8211
|
-
const r =
|
|
8363
|
+
const abs = path24.isAbsolute(file) ? file : path24.resolve(testRoot, file);
|
|
8364
|
+
const r = path24.relative(cwd, abs).split(path24.sep).join("/");
|
|
8212
8365
|
return r.startsWith("..") ? file : r || file;
|
|
8213
8366
|
};
|
|
8214
8367
|
console.log(renderPreflight(result, rel));
|
|
@@ -8238,9 +8391,9 @@ async function runPreflight(argv, env = process.env, cwd = process.cwd()) {
|
|
|
8238
8391
|
}
|
|
8239
8392
|
|
|
8240
8393
|
// src/cli/probe.ts
|
|
8241
|
-
var
|
|
8242
|
-
var
|
|
8243
|
-
var
|
|
8394
|
+
var fs21 = __toESM(require("fs"));
|
|
8395
|
+
var os5 = __toESM(require("os"));
|
|
8396
|
+
var path25 = __toESM(require("path"));
|
|
8244
8397
|
var EXIT_OK8 = 0;
|
|
8245
8398
|
var EXIT_ERROR9 = 2;
|
|
8246
8399
|
var USAGE11 = `
|
|
@@ -8309,7 +8462,7 @@ async function runProbe(argv) {
|
|
|
8309
8462
|
const planUrl = `${serverUrl}/api/projects/${projectId}/probes/plan${budget ? `?budget=${encodeURIComponent(budget)}` : ""}`;
|
|
8310
8463
|
let plan;
|
|
8311
8464
|
try {
|
|
8312
|
-
const res = await
|
|
8465
|
+
const res = await cliFetch(planUrl, { headers: authHeaders4 });
|
|
8313
8466
|
if (!res.ok) throw new Error(`dashboard returned ${res.status}`);
|
|
8314
8467
|
plan = await res.json();
|
|
8315
8468
|
} catch (e) {
|
|
@@ -8321,12 +8474,12 @@ async function runProbe(argv) {
|
|
|
8321
8474
|
return EXIT_OK8;
|
|
8322
8475
|
}
|
|
8323
8476
|
console.error(`piwi probe: ${plan.items.length} pair(s) to probe (budget ${plan.budget}).`);
|
|
8324
|
-
const dir =
|
|
8325
|
-
const planFile =
|
|
8326
|
-
const resultsFile =
|
|
8327
|
-
const runOutputFile =
|
|
8328
|
-
|
|
8329
|
-
|
|
8477
|
+
const dir = fs21.mkdtempSync(path25.join(os5.tmpdir(), "piwi-probe-"));
|
|
8478
|
+
const planFile = path25.join(dir, "plan.json");
|
|
8479
|
+
const resultsFile = path25.join(dir, "results.jsonl");
|
|
8480
|
+
const runOutputFile = path25.join(dir, "run.json");
|
|
8481
|
+
fs21.writeFileSync(planFile, JSON.stringify(plan));
|
|
8482
|
+
fs21.writeFileSync(resultsFile, "");
|
|
8330
8483
|
const pwArgs = probePlaywrightArgs(
|
|
8331
8484
|
playwrightArgs2,
|
|
8332
8485
|
plan.items.map((i) => i.testTitle)
|
|
@@ -8341,7 +8494,7 @@ async function runProbe(argv) {
|
|
|
8341
8494
|
[PIWI_ENV_KEYS.outputFile]: runOutputFile
|
|
8342
8495
|
};
|
|
8343
8496
|
await spawnPlaywright(pwArgs, childEnv, { command: "piwi probe" });
|
|
8344
|
-
const lines =
|
|
8497
|
+
const lines = fs21.readFileSync(resultsFile, "utf8").split("\n").filter(Boolean);
|
|
8345
8498
|
const results = [];
|
|
8346
8499
|
for (const line of lines) {
|
|
8347
8500
|
try {
|
|
@@ -8355,12 +8508,12 @@ async function runProbe(argv) {
|
|
|
8355
8508
|
}
|
|
8356
8509
|
let runId = null;
|
|
8357
8510
|
try {
|
|
8358
|
-
const out = JSON.parse(
|
|
8511
|
+
const out = JSON.parse(fs21.readFileSync(runOutputFile, "utf8"));
|
|
8359
8512
|
if (typeof out.runId === "number") runId = out.runId;
|
|
8360
8513
|
} catch {
|
|
8361
8514
|
}
|
|
8362
8515
|
try {
|
|
8363
|
-
const res = await
|
|
8516
|
+
const res = await cliFetch(`${serverUrl}/api/projects/${projectId}/probes/results`, {
|
|
8364
8517
|
method: "POST",
|
|
8365
8518
|
headers: { "Content-Type": "application/json", ...authHeaders4 },
|
|
8366
8519
|
body: JSON.stringify({ runId, results })
|
|
@@ -8380,7 +8533,7 @@ async function runProbe(argv) {
|
|
|
8380
8533
|
}
|
|
8381
8534
|
|
|
8382
8535
|
// src/cli/quality-report.ts
|
|
8383
|
-
var
|
|
8536
|
+
var fs22 = __toESM(require("fs"));
|
|
8384
8537
|
var EXIT_OK9 = 0;
|
|
8385
8538
|
var EXIT_VERDICT = 1;
|
|
8386
8539
|
var EXIT_ERROR10 = 2;
|
|
@@ -8484,7 +8637,7 @@ function failsOn(tone, failOn) {
|
|
|
8484
8637
|
return failOn === "mixed" ? tone !== "good" : tone === "bad";
|
|
8485
8638
|
}
|
|
8486
8639
|
async function fetchReport(args, query) {
|
|
8487
|
-
const res = await
|
|
8640
|
+
const res = await cliFetch(`${args.serverUrl}/api/reports/preview?${query}`, {
|
|
8488
8641
|
headers: args.apiKey ? { "X-API-Key": args.apiKey } : {}
|
|
8489
8642
|
});
|
|
8490
8643
|
if (!res.ok) {
|
|
@@ -8506,7 +8659,7 @@ async function runQualityReport(argv) {
|
|
|
8506
8659
|
}
|
|
8507
8660
|
const res = await fetchReport(args, reportQuery(args, projectIds, args.format));
|
|
8508
8661
|
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
8509
|
-
if (args.output)
|
|
8662
|
+
if (args.output) fs22.writeFileSync(args.output, bytes);
|
|
8510
8663
|
else process.stdout.write(bytes);
|
|
8511
8664
|
if (!args.failOn) return EXIT_OK9;
|
|
8512
8665
|
const bundle = args.format === "json" ? JSON.parse(new TextDecoder().decode(bytes)) : await (await fetchReport(args, reportQuery(args, projectIds, "json"))).json();
|