@plune-ai/cli 0.30.2 → 0.31.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/README.md +32 -1
- package/dist/cli.cjs +200 -134
- package/dist/index.cjs +90 -66
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +90 -66
- package/dist/reporter-core.cjs +31 -4
- package/dist/reporter-core.d.cts +13 -0
- package/dist/reporter-core.d.ts +13 -0
- package/dist/reporter-core.js +31 -4
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -512,7 +512,7 @@ var init_retry = __esm({
|
|
|
512
512
|
"use strict";
|
|
513
513
|
init_cjs_shims();
|
|
514
514
|
init_errors2();
|
|
515
|
-
defaultSleep = (ms) => new Promise((
|
|
515
|
+
defaultSleep = (ms) => new Promise((resolve11) => setTimeout(resolve11, ms));
|
|
516
516
|
}
|
|
517
517
|
});
|
|
518
518
|
|
|
@@ -2458,7 +2458,7 @@ function parseRetryAfter(raw, now = Date.now()) {
|
|
|
2458
2458
|
return Math.min(Math.max(seconds, 0) * 1e3, RETRY_AFTER_CAP_MS);
|
|
2459
2459
|
}
|
|
2460
2460
|
function nodeTransport(url, init, idleMs = IDLE_MS) {
|
|
2461
|
-
return new Promise((
|
|
2461
|
+
return new Promise((resolve11, reject) => {
|
|
2462
2462
|
const target = new URL(url);
|
|
2463
2463
|
const send = target.protocol === "https:" ? import_node_https.request : import_node_http.request;
|
|
2464
2464
|
const agent = POOLS[target.protocol === "https:" ? "https:" : "http:"];
|
|
@@ -2469,7 +2469,7 @@ function nodeTransport(url, init, idleMs = IDLE_MS) {
|
|
|
2469
2469
|
res.on("end", () => {
|
|
2470
2470
|
const status = res.statusCode ?? 0;
|
|
2471
2471
|
const text2 = Buffer.concat(chunks).toString("utf8");
|
|
2472
|
-
|
|
2472
|
+
resolve11({
|
|
2473
2473
|
ok: status >= 200 && status <= 299,
|
|
2474
2474
|
status,
|
|
2475
2475
|
headers: {
|
|
@@ -2488,12 +2488,12 @@ function nodeTransport(url, init, idleMs = IDLE_MS) {
|
|
|
2488
2488
|
});
|
|
2489
2489
|
}
|
|
2490
2490
|
function nodePut(url, headers, source, idleMs) {
|
|
2491
|
-
return new Promise((
|
|
2491
|
+
return new Promise((resolve11, reject) => {
|
|
2492
2492
|
const target = new URL(url);
|
|
2493
2493
|
const send = target.protocol === "https:" ? import_node_https.request : import_node_http.request;
|
|
2494
2494
|
const length = "body" in source ? source.body.length : source.size;
|
|
2495
2495
|
let answered;
|
|
2496
|
-
const settle = (err) => answered !== void 0 ?
|
|
2496
|
+
const settle = (err) => answered !== void 0 ? resolve11(answered) : reject(err);
|
|
2497
2497
|
const req = send(
|
|
2498
2498
|
target,
|
|
2499
2499
|
{ method: "PUT", headers: { ...withoutLength(headers), "content-length": String(length) } },
|
|
@@ -2502,7 +2502,7 @@ function nodePut(url, headers, source, idleMs) {
|
|
|
2502
2502
|
answered = { status: res.statusCode ?? 0, retryAfter: Array.isArray(retry) ? retry[0] ?? null : retry ?? null };
|
|
2503
2503
|
res.on("error", settle);
|
|
2504
2504
|
res.on("close", () => {
|
|
2505
|
-
|
|
2505
|
+
resolve11(answered);
|
|
2506
2506
|
req.destroy();
|
|
2507
2507
|
});
|
|
2508
2508
|
res.resume();
|
|
@@ -2565,7 +2565,7 @@ function createClient(opts) {
|
|
|
2565
2565
|
}
|
|
2566
2566
|
const base = opts.apiUrl.replace(/\/+$/, "");
|
|
2567
2567
|
const scrub = (text2) => opts.token === "" ? text2 : text2.split(opts.token).join("***");
|
|
2568
|
-
async function send(method,
|
|
2568
|
+
async function send(method, path18, payload, retries = DEFAULT_RETRIES) {
|
|
2569
2569
|
let last = {
|
|
2570
2570
|
kind: "unavailable",
|
|
2571
2571
|
status: null,
|
|
@@ -2576,7 +2576,7 @@ function createClient(opts) {
|
|
|
2576
2576
|
await respectPause(mine);
|
|
2577
2577
|
let res;
|
|
2578
2578
|
try {
|
|
2579
|
-
res = await doFetch(`${base}${
|
|
2579
|
+
res = await doFetch(`${base}${path18}`, {
|
|
2580
2580
|
method,
|
|
2581
2581
|
headers: { "content-type": payload?.type ?? "application/json", authorization: `Bearer ${opts.token}` },
|
|
2582
2582
|
// A DELETE carries none. Sending `"undefined"` as a body is what a naive
|
|
@@ -2615,10 +2615,10 @@ function createClient(opts) {
|
|
|
2615
2615
|
return { ok: false, ...last };
|
|
2616
2616
|
}
|
|
2617
2617
|
return {
|
|
2618
|
-
post: (
|
|
2619
|
-
upload: (
|
|
2620
|
-
del: (
|
|
2621
|
-
get: (
|
|
2618
|
+
post: (path18, body, retries) => send("POST", path18, { body: JSON.stringify(body), type: "application/json" }, retries),
|
|
2619
|
+
upload: (path18, bytes, contentType) => send("POST", path18, { body: bytes, type: contentType }, uploadRetries ?? DEFAULT_RETRIES),
|
|
2620
|
+
del: (path18) => send("DELETE", path18),
|
|
2621
|
+
get: (path18) => send("GET", path18),
|
|
2622
2622
|
async put(url, headers, source) {
|
|
2623
2623
|
const putRetries = uploadRetries ?? 3;
|
|
2624
2624
|
let last = { ok: false, status: null, code: "network" };
|
|
@@ -2688,6 +2688,25 @@ function shardOf(env) {
|
|
|
2688
2688
|
error: `PLUNE_SHARD=${JSON.stringify(raw.slice(0, 40))} is not "k/N" with 1 <= k <= N <= ${SHARDS_MAX} (for example 2/4) - nothing was sent.`
|
|
2689
2689
|
};
|
|
2690
2690
|
}
|
|
2691
|
+
function configurationOf(env) {
|
|
2692
|
+
const raw = value(env, "PLUNE_CONFIGURATION");
|
|
2693
|
+
if (raw === void 0) return {};
|
|
2694
|
+
const pairs = [];
|
|
2695
|
+
for (const pair of raw.split(";").map((s) => s.trim()).filter((s) => s !== "")) {
|
|
2696
|
+
const at = pair.indexOf("=");
|
|
2697
|
+
const name = at < 0 ? "" : pair.slice(0, at).trim();
|
|
2698
|
+
const label = at < 0 ? "" : pair.slice(at + 1).trim();
|
|
2699
|
+
const twice = pairs.find(([seen]) => seen.toLowerCase() === name.toLowerCase());
|
|
2700
|
+
const why = at < 0 ? 'has no "="' : name === "" ? "has no group name" : label === "" ? "has no value" : twice !== void 0 ? `names the group ${JSON.stringify(twice[0])} a second time` : void 0;
|
|
2701
|
+
if (why !== void 0) {
|
|
2702
|
+
return {
|
|
2703
|
+
error: `PLUNE_CONFIGURATION: ${JSON.stringify(pair.slice(0, 40))} ${why} - write it as "Group=Value;Group=Value" (for example "Browser=Chrome;Operating system=Windows") - nothing was sent.`
|
|
2704
|
+
};
|
|
2705
|
+
}
|
|
2706
|
+
pairs.push([name, label]);
|
|
2707
|
+
}
|
|
2708
|
+
return pairs.length === 0 ? {} : { configuration: Object.fromEntries(pairs) };
|
|
2709
|
+
}
|
|
2691
2710
|
function value(env, name) {
|
|
2692
2711
|
const raw = env[name]?.trim();
|
|
2693
2712
|
return raw === void 0 || raw === "" ? void 0 : raw;
|
|
@@ -2732,6 +2751,7 @@ function readEnv(env = process.env) {
|
|
|
2732
2751
|
const offerDiscovered = flag(env, "PLUNE_CREATE");
|
|
2733
2752
|
const full = flag(env, "PLUNE_FULL_RUN");
|
|
2734
2753
|
const { shard, error: shardError } = shardOf(env);
|
|
2754
|
+
const { configuration, error: configurationError } = configurationOf(env);
|
|
2735
2755
|
return {
|
|
2736
2756
|
config: {
|
|
2737
2757
|
...externalKey !== void 0 ? { externalKey } : {},
|
|
@@ -2744,6 +2764,7 @@ function readEnv(env = process.env) {
|
|
|
2744
2764
|
...title !== void 0 ? { title } : {},
|
|
2745
2765
|
...environment !== void 0 ? { environment } : {},
|
|
2746
2766
|
...labels !== void 0 ? { labels } : {},
|
|
2767
|
+
...configuration !== void 0 ? { configuration } : {},
|
|
2747
2768
|
// Only when set: `false` here would outrank a config file that asked for it, and an unset
|
|
2748
2769
|
// variable is not an instruction.
|
|
2749
2770
|
...offerDiscovered ? { offerDiscovered } : {},
|
|
@@ -2757,6 +2778,7 @@ function readEnv(env = process.env) {
|
|
|
2757
2778
|
keepOpen: flag(env, "PLUNE_SHARED_RUN") || flag(env, "PLUNE_PROCEED") || shard !== void 0 || shardError !== void 0,
|
|
2758
2779
|
...shard !== void 0 ? { shard } : {},
|
|
2759
2780
|
...shardError !== void 0 ? { shardError } : {},
|
|
2781
|
+
...configurationError !== void 0 ? { configurationError } : {},
|
|
2760
2782
|
...importTimeout !== void 0 ? { importTimeout } : {},
|
|
2761
2783
|
ignored: UNSUPPORTED_VARS.filter((name) => value(env, name) !== void 0),
|
|
2762
2784
|
warnings
|
|
@@ -2813,6 +2835,7 @@ function appendBatch(file, batch) {
|
|
|
2813
2835
|
externalKey: batch.externalKey,
|
|
2814
2836
|
...batch.session !== void 0 ? { session: batch.session } : {},
|
|
2815
2837
|
...batch.meta !== void 0 ? { meta: batch.meta } : {},
|
|
2838
|
+
...batch.configuration !== void 0 ? { configuration: batch.configuration } : {},
|
|
2816
2839
|
results: batch.results
|
|
2817
2840
|
};
|
|
2818
2841
|
fs6.appendFileSync(file, `${JSON.stringify(line)}
|
|
@@ -2876,12 +2899,12 @@ function machineless(raw, repoRoot, home) {
|
|
|
2876
2899
|
if (repoRoot === void 0) text2 = text2.replace(ANY_HOME, "~");
|
|
2877
2900
|
return text2;
|
|
2878
2901
|
}
|
|
2879
|
-
function pathIn(
|
|
2880
|
-
const parts =
|
|
2902
|
+
function pathIn(path18) {
|
|
2903
|
+
const parts = path18.split(/[\\/]+/);
|
|
2881
2904
|
while (parts.length > 1 && parts.at(-1) === "") parts.pop();
|
|
2882
2905
|
if (!parts.some((part) => part !== "" && !/^[A-Za-z]:$/.test(part))) return void 0;
|
|
2883
2906
|
const joined = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]+");
|
|
2884
|
-
const escaped = /^\/(?!\/)/.test(
|
|
2907
|
+
const escaped = /^\/(?!\/)/.test(path18) ? joined.replace("[\\\\/]+", "\\\\*\\/") : joined;
|
|
2885
2908
|
const url = "(?:(?:file|webpack|webpack-internal):(?:\\\\*\\/){2,3})?";
|
|
2886
2909
|
return new RegExp(`${url}${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
|
|
2887
2910
|
}
|
|
@@ -2927,12 +2950,12 @@ function placeOf(error, testFile) {
|
|
|
2927
2950
|
}
|
|
2928
2951
|
function fileOf(raw) {
|
|
2929
2952
|
if (!raw.startsWith("file://")) return raw;
|
|
2930
|
-
let
|
|
2953
|
+
let path18 = raw.slice("file://".length);
|
|
2931
2954
|
try {
|
|
2932
|
-
|
|
2955
|
+
path18 = decodeURIComponent(path18);
|
|
2933
2956
|
} catch {
|
|
2934
2957
|
}
|
|
2935
|
-
return /^\/[A-Za-z]:\//.test(
|
|
2958
|
+
return /^\/[A-Za-z]:\//.test(path18) ? path18.slice(1) : path18;
|
|
2936
2959
|
}
|
|
2937
2960
|
function fromRoot(place, root) {
|
|
2938
2961
|
if (place === void 0 || root === void 0 || !Number.isInteger(place.line) || place.line < 1) return void 0;
|
|
@@ -2972,14 +2995,14 @@ var init_failure_detail = __esm({
|
|
|
2972
2995
|
FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
2973
2996
|
FRAME_MAX = 8192;
|
|
2974
2997
|
firstLine = (text2) => (0, import_node_util.stripVTControlCharacters)(text2).split("\n").map((line) => line.trim()).find((line) => line !== "");
|
|
2975
|
-
normal = (
|
|
2998
|
+
normal = (path18) => import_node_path2.posix.normalize(path18.replace(/\\/g, "/")).replace(/^([a-z]):/, (_, drive) => `${drive.toUpperCase()}:`);
|
|
2976
2999
|
}
|
|
2977
3000
|
});
|
|
2978
3001
|
|
|
2979
3002
|
// src/reporter-core/files-batch.ts
|
|
2980
|
-
async function sha256File(
|
|
3003
|
+
async function sha256File(path18) {
|
|
2981
3004
|
const hash = (0, import_node_crypto2.createHash)("sha256");
|
|
2982
|
-
for await (const part of (0, import_node_fs4.createReadStream)(
|
|
3005
|
+
for await (const part of (0, import_node_fs4.createReadStream)(path18)) hash.update(part);
|
|
2983
3006
|
return hash.digest("hex");
|
|
2984
3007
|
}
|
|
2985
3008
|
var import_node_crypto2, import_node_fs4, FILES_BATCH_MAX, DIRECT_BATCH_BYTES, BATCH_PIPELINES, sha256Bytes, BUCKET_CODES;
|
|
@@ -3102,8 +3125,10 @@ function warnIfDropped(sent, run, log) {
|
|
|
3102
3125
|
async function startRun(passed, declared2) {
|
|
3103
3126
|
const env = readEnv();
|
|
3104
3127
|
if (env.shardError !== void 0) throw new Error(env.shardError);
|
|
3128
|
+
if (env.configurationError !== void 0 && passed.configuration === void 0) throw new Error(env.configurationError);
|
|
3105
3129
|
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
3106
3130
|
const cfg = { ...env.config, ...stated };
|
|
3131
|
+
const configuration = cfg.configuration !== void 0 && Object.keys(cfg.configuration).length > 0 ? cfg.configuration : void 0;
|
|
3107
3132
|
const log = cfg.log ?? ((line) => void process.stderr.write(`${line}
|
|
3108
3133
|
`));
|
|
3109
3134
|
const fallbackPath = cfg.fallbackPath ?? DEFAULT_FALLBACK_PATH;
|
|
@@ -3187,6 +3212,7 @@ async function startRun(passed, declared2) {
|
|
|
3187
3212
|
externalKey,
|
|
3188
3213
|
session: sessionMarker,
|
|
3189
3214
|
...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
|
|
3215
|
+
...configuration !== void 0 ? { configuration } : {},
|
|
3190
3216
|
results: results.map(onDisk)
|
|
3191
3217
|
});
|
|
3192
3218
|
stats.deferred += results.length;
|
|
@@ -3211,7 +3237,7 @@ async function startRun(passed, declared2) {
|
|
|
3211
3237
|
if (!offline) {
|
|
3212
3238
|
if (expected !== void 0) await resolveKeys(expected.flat());
|
|
3213
3239
|
const stated2 = expected?.slice(0, EXPECTED_MAX) ?? [];
|
|
3214
|
-
const
|
|
3240
|
+
const configuration2 = stated2.length === 0 ? void 0 : {
|
|
3215
3241
|
expected: stated2.flatMap((keys) => {
|
|
3216
3242
|
const hit = keys.map((k) => resolved.get(k.value)).find((v) => typeof v === "string");
|
|
3217
3243
|
if (typeof hit === "string") return [{ testCaseId: hit }];
|
|
@@ -3235,7 +3261,7 @@ async function startRun(passed, declared2) {
|
|
|
3235
3261
|
kind: cfg.kind ?? "automated",
|
|
3236
3262
|
...externalKey !== null ? { externalKey } : {},
|
|
3237
3263
|
...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
|
|
3238
|
-
...
|
|
3264
|
+
...configuration2 !== void 0 ? { configuration: configuration2 } : {},
|
|
3239
3265
|
// Named even when nobody named it — the list has to read without opening a row. Only what
|
|
3240
3266
|
// the caller DESCRIBED goes to `warnIfDropped` below: a title this side invented is not one
|
|
3241
3267
|
// a person will miss, and a deployment older than the field must not be nagged on every run.
|
|
@@ -3243,7 +3269,7 @@ async function startRun(passed, declared2) {
|
|
|
3243
3269
|
...described
|
|
3244
3270
|
};
|
|
3245
3271
|
let start = await client.post("/v1/runs", request);
|
|
3246
|
-
if (!start.ok && start.status === 413 &&
|
|
3272
|
+
if (!start.ok && start.status === 413 && configuration2 !== void 0) {
|
|
3247
3273
|
log(
|
|
3248
3274
|
`plune: the platform refused the run's list of expected tests as too large (${start.detail || start.kind}) \u2014 starting without it: the results still land, but this run counts no tests that did not run, and claims no full run.`
|
|
3249
3275
|
);
|
|
@@ -3403,7 +3429,7 @@ async function startRun(passed, declared2) {
|
|
|
3403
3429
|
let free = uploadsAtOnce;
|
|
3404
3430
|
const waiting = [];
|
|
3405
3431
|
async function gated(work) {
|
|
3406
|
-
if (free === 0) await new Promise((
|
|
3432
|
+
if (free === 0) await new Promise((resolve11) => waiting.push(resolve11));
|
|
3407
3433
|
else free -= 1;
|
|
3408
3434
|
try {
|
|
3409
3435
|
return await work();
|
|
@@ -3789,7 +3815,8 @@ async function startRun(passed, declared2) {
|
|
|
3789
3815
|
}
|
|
3790
3816
|
const out = await client.post(
|
|
3791
3817
|
`/v1/runs/${runId}/results`,
|
|
3792
|
-
|
|
3818
|
+
// The job's combination on every batch (plune-ai/plune#1251); a refusal of it is a 422 said below as it came.
|
|
3819
|
+
{ results: part, ...configuration !== void 0 ? { configuration } : {} }
|
|
3793
3820
|
);
|
|
3794
3821
|
const counts = out.ok ? out.body?.counts : void 0;
|
|
3795
3822
|
const told = COUNTED.filter((k) => typeof counts?.[k] === "number");
|
|
@@ -4121,14 +4148,14 @@ async function handleRunExec(options) {
|
|
|
4121
4148
|
if (command === void 0) throw new RunCommandError("Nothing to run \u2014 pass a command after `--`.");
|
|
4122
4149
|
const run = await handleRunStart(options);
|
|
4123
4150
|
const spawnImpl = options.spawnImpl ?? import_node_child_process.spawn;
|
|
4124
|
-
const code = await new Promise((
|
|
4151
|
+
const code = await new Promise((resolve11) => {
|
|
4125
4152
|
const child = spawnImpl(command, args, {
|
|
4126
4153
|
stdio: "inherit",
|
|
4127
4154
|
shell: process.platform === "win32",
|
|
4128
4155
|
env: { ...process.env, PLUNE_RUN: run.externalKey, PLUNE_PROCEED: "1" }
|
|
4129
4156
|
});
|
|
4130
|
-
child.on("close", (exitCode) =>
|
|
4131
|
-
child.on("error", () =>
|
|
4157
|
+
child.on("close", (exitCode) => resolve11(exitCode ?? 1));
|
|
4158
|
+
child.on("error", () => resolve11(1));
|
|
4132
4159
|
});
|
|
4133
4160
|
return handleRunFinish(run.id, options, code);
|
|
4134
4161
|
}
|
|
@@ -4162,7 +4189,10 @@ async function handleRunReport(options = {}) {
|
|
|
4162
4189
|
for (const line of group) {
|
|
4163
4190
|
const ready = line.results.filter((r) => !isPending(r));
|
|
4164
4191
|
if (line.runId !== null && ready.length > 0) {
|
|
4165
|
-
const out = await client.post(`/v1/runs/${line.runId}/results`, {
|
|
4192
|
+
const out = await client.post(`/v1/runs/${line.runId}/results`, {
|
|
4193
|
+
results: ready,
|
|
4194
|
+
...line.configuration !== void 0 ? { configuration: line.configuration } : {}
|
|
4195
|
+
});
|
|
4166
4196
|
if (out.ok) result.sent += ready.length;
|
|
4167
4197
|
else {
|
|
4168
4198
|
result.failed += ready.length;
|
|
@@ -4182,6 +4212,8 @@ async function handleRunReport(options = {}) {
|
|
|
4182
4212
|
...first.externalKey !== null ? { externalKey: first.externalKey } : {},
|
|
4183
4213
|
// Where the run came from, as the reporter recorded it (plune#927) — never this machine's own.
|
|
4184
4214
|
...first.meta !== void 0 ? { meta: first.meta } : {},
|
|
4215
|
+
// The combination the line recorded, or none (`{}`) — never this machine's `PLUNE_CONFIGURATION` (plune-ai/plune#1251).
|
|
4216
|
+
configuration: first.configuration ?? {},
|
|
4185
4217
|
// The replay does not know whether the run is complete, so it must not say that it is.
|
|
4186
4218
|
log: write
|
|
4187
4219
|
});
|
|
@@ -4323,6 +4355,85 @@ var init_run_result_schema = __esm({
|
|
|
4323
4355
|
}
|
|
4324
4356
|
});
|
|
4325
4357
|
|
|
4358
|
+
// src/cli/commands/job-reporter.ts
|
|
4359
|
+
var JOB_TIMEOUT_MS, JOB_SUBJECT_NAME_MAX, JOB_REASON_MAX, JobReporter;
|
|
4360
|
+
var init_job_reporter = __esm({
|
|
4361
|
+
"src/cli/commands/job-reporter.ts"() {
|
|
4362
|
+
"use strict";
|
|
4363
|
+
init_cjs_shims();
|
|
4364
|
+
JOB_TIMEOUT_MS = 5e3;
|
|
4365
|
+
JOB_SUBJECT_NAME_MAX = 200;
|
|
4366
|
+
JOB_REASON_MAX = 2e3;
|
|
4367
|
+
JobReporter = class {
|
|
4368
|
+
constructor(doFetch, base, token, kind) {
|
|
4369
|
+
this.doFetch = doFetch;
|
|
4370
|
+
this.base = base;
|
|
4371
|
+
this.token = token;
|
|
4372
|
+
this.kind = kind;
|
|
4373
|
+
}
|
|
4374
|
+
doFetch;
|
|
4375
|
+
base;
|
|
4376
|
+
token;
|
|
4377
|
+
kind;
|
|
4378
|
+
id;
|
|
4379
|
+
/** The upload's rows, the job's `total`; `null` while there are none to count. */
|
|
4380
|
+
size = null;
|
|
4381
|
+
/** The first report the platform did not take, for the CLI to say once. */
|
|
4382
|
+
problem;
|
|
4383
|
+
async send(method, route, body) {
|
|
4384
|
+
try {
|
|
4385
|
+
const res = await this.doFetch(`${this.base}/v1/jobs${route}`, {
|
|
4386
|
+
method,
|
|
4387
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${this.token}` },
|
|
4388
|
+
body: JSON.stringify(body),
|
|
4389
|
+
signal: AbortSignal.timeout(JOB_TIMEOUT_MS)
|
|
4390
|
+
});
|
|
4391
|
+
const json = await res.json().catch(() => void 0);
|
|
4392
|
+
if (res.ok) return json ?? {};
|
|
4393
|
+
if (route === "" && (res.status === 404 || res.status === 405)) return void 0;
|
|
4394
|
+
this.problem ??= `HTTP ${res.status}${typeof json?.error === "string" ? ` \u2014 ${json.error}` : ""}`;
|
|
4395
|
+
} catch (err) {
|
|
4396
|
+
this.problem ??= err instanceof Error ? err.message : String(err);
|
|
4397
|
+
}
|
|
4398
|
+
return void 0;
|
|
4399
|
+
}
|
|
4400
|
+
async open(subjectName, rows) {
|
|
4401
|
+
this.size = Number.isInteger(rows) && rows > 0 ? rows : null;
|
|
4402
|
+
const name = subjectName.trim().slice(0, JOB_SUBJECT_NAME_MAX);
|
|
4403
|
+
const body = await this.send("POST", "", {
|
|
4404
|
+
kind: this.kind,
|
|
4405
|
+
...name !== "" ? { subjectName: name } : {},
|
|
4406
|
+
...this.size !== null ? { progress: { done: 0, total: this.size } } : {}
|
|
4407
|
+
});
|
|
4408
|
+
if (typeof body?.id === "string") this.id = body.id;
|
|
4409
|
+
}
|
|
4410
|
+
/**
|
|
4411
|
+
* The upload is in: every row is on the platform. `subjectId` is what the job works on, learnt from the upload's
|
|
4412
|
+
* answer (the run an ingest landed in): the platform takes it while the job names none (#1279).
|
|
4413
|
+
*/
|
|
4414
|
+
async uploaded(at) {
|
|
4415
|
+
if (this.id === void 0) return;
|
|
4416
|
+
await this.send("PATCH", `/${encodeURIComponent(this.id)}/progress`, {
|
|
4417
|
+
done: this.size,
|
|
4418
|
+
total: this.size,
|
|
4419
|
+
...at.cursor !== void 0 ? { cursor: at.cursor } : {},
|
|
4420
|
+
...at.subjectId !== void 0 ? { subjectId: at.subjectId } : {}
|
|
4421
|
+
});
|
|
4422
|
+
}
|
|
4423
|
+
async finish(outcome) {
|
|
4424
|
+
if (this.id === void 0) return;
|
|
4425
|
+
const id = this.id;
|
|
4426
|
+
this.id = void 0;
|
|
4427
|
+
await this.send(
|
|
4428
|
+
"PATCH",
|
|
4429
|
+
`/${encodeURIComponent(id)}/state`,
|
|
4430
|
+
outcome.ok ? { state: "completed" } : { state: "failed", reason: outcome.reason.slice(0, JOB_REASON_MAX) }
|
|
4431
|
+
);
|
|
4432
|
+
}
|
|
4433
|
+
};
|
|
4434
|
+
}
|
|
4435
|
+
});
|
|
4436
|
+
|
|
4326
4437
|
// src/cli/commands/sync.ts
|
|
4327
4438
|
var sync_exports = {};
|
|
4328
4439
|
__export(sync_exports, {
|
|
@@ -4375,7 +4486,7 @@ async function handleSync(deps = {}) {
|
|
|
4375
4486
|
const payload = JSON.stringify(run);
|
|
4376
4487
|
const idempotencyKey = (0, import_node_crypto4.createHash)("sha256").update(payload).digest("hex");
|
|
4377
4488
|
const bearer = token;
|
|
4378
|
-
const job = new JobReporter(doFetch, apiUrl, bearer);
|
|
4489
|
+
const job = new JobReporter(doFetch, apiUrl, bearer, "sync");
|
|
4379
4490
|
await job.open(path9.basename(deps.file !== void 0 ? path9.resolve(cwd, deps.file) : cwd), run.summary.total);
|
|
4380
4491
|
try {
|
|
4381
4492
|
const result = await upload();
|
|
@@ -4409,7 +4520,7 @@ async function handleSync(deps = {}) {
|
|
|
4409
4520
|
const body = await res.json().catch(() => ({}));
|
|
4410
4521
|
const id = typeof body.id === "string" ? body.id : "";
|
|
4411
4522
|
const result = { id, url: `${endpoint}/${id}` };
|
|
4412
|
-
await job.uploaded(id || void 0);
|
|
4523
|
+
await job.uploaded({ cursor: id || void 0 });
|
|
4413
4524
|
if (deps.failOnFailures === true) {
|
|
4414
4525
|
result.gate = gateExit(await readVerdict(doFetch, `${endpoint}/${id}/summary`, bearer));
|
|
4415
4526
|
}
|
|
@@ -4436,7 +4547,7 @@ function reportSyncFailure(err, write) {
|
|
|
4436
4547
|
}
|
|
4437
4548
|
return null;
|
|
4438
4549
|
}
|
|
4439
|
-
var import_node_crypto4, fs8, path9, NotLoggedInError, TokenRejectedError, SyncFileError, SyncNetworkError, SyncHttpError
|
|
4550
|
+
var import_node_crypto4, fs8, path9, NotLoggedInError, TokenRejectedError, SyncFileError, SyncNetworkError, SyncHttpError;
|
|
4440
4551
|
var init_sync = __esm({
|
|
4441
4552
|
"src/cli/commands/sync.ts"() {
|
|
4442
4553
|
"use strict";
|
|
@@ -4448,6 +4559,7 @@ var init_sync = __esm({
|
|
|
4448
4559
|
init_api_url();
|
|
4449
4560
|
init_credentials();
|
|
4450
4561
|
init_gate();
|
|
4562
|
+
init_job_reporter();
|
|
4451
4563
|
NotLoggedInError = class extends Error {
|
|
4452
4564
|
constructor() {
|
|
4453
4565
|
super('Not logged in. Run "plune login" first, or set PLUNE_TOKEN.');
|
|
@@ -4484,71 +4596,6 @@ var init_sync = __esm({
|
|
|
4484
4596
|
}
|
|
4485
4597
|
status;
|
|
4486
4598
|
};
|
|
4487
|
-
JOB_KIND = "sync";
|
|
4488
|
-
JOB_TIMEOUT_MS = 5e3;
|
|
4489
|
-
JOB_SUBJECT_NAME_MAX = 200;
|
|
4490
|
-
JOB_REASON_MAX = 2e3;
|
|
4491
|
-
JobReporter = class {
|
|
4492
|
-
constructor(doFetch, base, token) {
|
|
4493
|
-
this.doFetch = doFetch;
|
|
4494
|
-
this.base = base;
|
|
4495
|
-
this.token = token;
|
|
4496
|
-
}
|
|
4497
|
-
doFetch;
|
|
4498
|
-
base;
|
|
4499
|
-
token;
|
|
4500
|
-
id;
|
|
4501
|
-
/** The run's rows, the job's `total`; `null` while there are none to count. */
|
|
4502
|
-
size = null;
|
|
4503
|
-
/** The first report the platform did not take, for the CLI to say once. */
|
|
4504
|
-
problem;
|
|
4505
|
-
async send(method, route, body) {
|
|
4506
|
-
try {
|
|
4507
|
-
const res = await this.doFetch(`${this.base}/v1/jobs${route}`, {
|
|
4508
|
-
method,
|
|
4509
|
-
headers: { "content-type": "application/json", authorization: `Bearer ${this.token}` },
|
|
4510
|
-
body: JSON.stringify(body),
|
|
4511
|
-
signal: AbortSignal.timeout(JOB_TIMEOUT_MS)
|
|
4512
|
-
});
|
|
4513
|
-
const json = await res.json().catch(() => void 0);
|
|
4514
|
-
if (res.ok) return json ?? {};
|
|
4515
|
-
if (route === "" && (res.status === 404 || res.status === 405)) return void 0;
|
|
4516
|
-
this.problem ??= `HTTP ${res.status}${typeof json?.error === "string" ? ` \u2014 ${json.error}` : ""}`;
|
|
4517
|
-
} catch (err) {
|
|
4518
|
-
this.problem ??= err instanceof Error ? err.message : String(err);
|
|
4519
|
-
}
|
|
4520
|
-
return void 0;
|
|
4521
|
-
}
|
|
4522
|
-
async open(subjectName, rows) {
|
|
4523
|
-
this.size = Number.isInteger(rows) && rows > 0 ? rows : null;
|
|
4524
|
-
const name = subjectName.trim().slice(0, JOB_SUBJECT_NAME_MAX);
|
|
4525
|
-
const body = await this.send("POST", "", {
|
|
4526
|
-
kind: JOB_KIND,
|
|
4527
|
-
...name !== "" ? { subjectName: name } : {},
|
|
4528
|
-
...this.size !== null ? { progress: { done: 0, total: this.size } } : {}
|
|
4529
|
-
});
|
|
4530
|
-
if (typeof body?.id === "string") this.id = body.id;
|
|
4531
|
-
}
|
|
4532
|
-
/** The upload is in: every row of the run is on the platform. */
|
|
4533
|
-
async uploaded(cursor) {
|
|
4534
|
-
if (this.id === void 0) return;
|
|
4535
|
-
await this.send("PATCH", `/${encodeURIComponent(this.id)}/progress`, {
|
|
4536
|
-
done: this.size,
|
|
4537
|
-
total: this.size,
|
|
4538
|
-
...cursor !== void 0 ? { cursor } : {}
|
|
4539
|
-
});
|
|
4540
|
-
}
|
|
4541
|
-
async finish(outcome) {
|
|
4542
|
-
if (this.id === void 0) return;
|
|
4543
|
-
const id = this.id;
|
|
4544
|
-
this.id = void 0;
|
|
4545
|
-
await this.send(
|
|
4546
|
-
"PATCH",
|
|
4547
|
-
`/${encodeURIComponent(id)}/state`,
|
|
4548
|
-
outcome.ok ? { state: "completed" } : { state: "failed", reason: outcome.reason.slice(0, JOB_REASON_MAX) }
|
|
4549
|
-
);
|
|
4550
|
-
}
|
|
4551
|
-
};
|
|
4552
4599
|
}
|
|
4553
4600
|
});
|
|
4554
4601
|
|
|
@@ -4585,10 +4632,10 @@ function platformGet(deps) {
|
|
|
4585
4632
|
const token = (deps.loadToken ?? loadToken)();
|
|
4586
4633
|
if (token === null) throw new NotLoggedInError();
|
|
4587
4634
|
const doFetch = deps.fetchImpl ?? fetch;
|
|
4588
|
-
return async (
|
|
4635
|
+
return async (path18) => {
|
|
4589
4636
|
let res;
|
|
4590
4637
|
try {
|
|
4591
|
-
res = await doFetch(`${apiUrl}${
|
|
4638
|
+
res = await doFetch(`${apiUrl}${path18}`, { headers: { authorization: `Bearer ${token}` } });
|
|
4592
4639
|
} catch {
|
|
4593
4640
|
throw new SyncNetworkError(apiUrl);
|
|
4594
4641
|
}
|
|
@@ -4929,9 +4976,9 @@ var init_attachments = __esm({
|
|
|
4929
4976
|
});
|
|
4930
4977
|
|
|
4931
4978
|
// src/importers/allure.ts
|
|
4932
|
-
function isFolder(
|
|
4979
|
+
function isFolder(path18) {
|
|
4933
4980
|
try {
|
|
4934
|
-
return fs11.statSync(
|
|
4981
|
+
return fs11.statSync(path18).isDirectory();
|
|
4935
4982
|
} catch {
|
|
4936
4983
|
return false;
|
|
4937
4984
|
}
|
|
@@ -5439,10 +5486,10 @@ function attemptOf(result, file, ctx) {
|
|
|
5439
5486
|
...typeof at?.file === "string" && typeof at.line === "number" ? { location: { file: at.file, line: at.line, ...typeof at.column === "number" ? { column: at.column } : {} } } : {}
|
|
5440
5487
|
})),
|
|
5441
5488
|
steps: steps(result.steps),
|
|
5442
|
-
attachments: (result.attachments ?? []).map(({ name, contentType, path:
|
|
5489
|
+
attachments: (result.attachments ?? []).map(({ name, contentType, path: path18, body }) => ({
|
|
5443
5490
|
name: name ?? "",
|
|
5444
5491
|
...contentType !== void 0 ? { contentType } : {},
|
|
5445
|
-
...
|
|
5492
|
+
...path18 !== void 0 ? { path: path18 } : {},
|
|
5446
5493
|
// Decoded only where the platform would take it (plune-ai/plune#928): a report of screenshots kept as
|
|
5447
5494
|
// bodies is megabytes of base64 that nothing here will read.
|
|
5448
5495
|
...typeof body === "string" && isTextType(contentType) ? { body: Buffer.from(body, "base64") } : {}
|
|
@@ -5629,7 +5676,7 @@ async function timeoutMessage(limit, runId, ours, options) {
|
|
|
5629
5676
|
if (!ours) return `${head}; run ${runId} is shared with other jobs and was left open - close it with "plune run finish ${runId}" once they are done, then import this report again.`;
|
|
5630
5677
|
const wait = options.terminateWaitMs ?? 15e3;
|
|
5631
5678
|
let timer;
|
|
5632
|
-
const gaveUp = new Promise((
|
|
5679
|
+
const gaveUp = new Promise((resolve11) => timer = setTimeout(() => resolve11("gaveup"), wait));
|
|
5633
5680
|
const quiet = () => void 0;
|
|
5634
5681
|
const closed = handleRunFinish(runId, { ...options, write: quiet, terminate: true, reason: `import timed out after ${limit} s` }).then(
|
|
5635
5682
|
() => true,
|
|
@@ -5698,7 +5745,7 @@ async function handleRunImport(options) {
|
|
|
5698
5745
|
else {
|
|
5699
5746
|
sent.catch(() => void 0);
|
|
5700
5747
|
let timer;
|
|
5701
|
-
const late = new Promise((
|
|
5748
|
+
const late = new Promise((resolve11) => timer = setTimeout(() => resolve11("late"), limit * 1e3));
|
|
5702
5749
|
const first = await Promise.race([sent, late]).finally(() => clearTimeout(timer));
|
|
5703
5750
|
if (first === "late") {
|
|
5704
5751
|
throw new ImportTimeoutError(await timeoutMessage(limit, session?.runId ?? null, !env.keepOpen, { ...options, apiUrl, token }));
|
|
@@ -6517,28 +6564,42 @@ async function handleIngest(deps) {
|
|
|
6517
6564
|
const payload = await readCairnRun(dir);
|
|
6518
6565
|
const doFetch = deps.fetchImpl ?? fetch;
|
|
6519
6566
|
const endpoint = `${apiUrl}/v1/ingest/cairn`;
|
|
6520
|
-
|
|
6567
|
+
const job = new JobReporter(doFetch, apiUrl, token, "ingest");
|
|
6568
|
+
await job.open(path17.basename(path17.resolve(dir)), payload.cases.length);
|
|
6521
6569
|
try {
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
} catch {
|
|
6528
|
-
|
|
6570
|
+
const result = await upload();
|
|
6571
|
+
await job.uploaded({ subjectId: result.runId || void 0 });
|
|
6572
|
+
await job.finish({ ok: true });
|
|
6573
|
+
if (job.problem !== void 0) result.jobProblem = job.problem;
|
|
6574
|
+
return result;
|
|
6575
|
+
} catch (err) {
|
|
6576
|
+
await job.finish({ ok: false, reason: err instanceof Error && err.message.trim() || "Ingest failed." });
|
|
6577
|
+
throw err;
|
|
6529
6578
|
}
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6579
|
+
async function upload() {
|
|
6580
|
+
let res;
|
|
6581
|
+
try {
|
|
6582
|
+
res = await doFetch(endpoint, {
|
|
6583
|
+
method: "POST",
|
|
6584
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
|
|
6585
|
+
body: JSON.stringify(payload)
|
|
6586
|
+
});
|
|
6587
|
+
} catch {
|
|
6588
|
+
throw new IngestNetworkError(apiUrl);
|
|
6589
|
+
}
|
|
6590
|
+
if (!res.ok) {
|
|
6591
|
+
const detail = await safeErrorDetail4(res);
|
|
6592
|
+
if (res.status === 401) throw new IngestTokenRejectedError();
|
|
6593
|
+
throw new IngestHttpError(res.status, detail);
|
|
6594
|
+
}
|
|
6595
|
+
const body = await res.json().catch(() => ({}));
|
|
6596
|
+
return {
|
|
6597
|
+
runId: typeof body.runId === "string" ? body.runId : "",
|
|
6598
|
+
linked: typeof body.linked === "number" ? body.linked : 0,
|
|
6599
|
+
proposed: typeof body.proposed === "number" ? body.proposed : 0,
|
|
6600
|
+
skipped: typeof body.skipped === "number" ? body.skipped : 0
|
|
6601
|
+
};
|
|
6534
6602
|
}
|
|
6535
|
-
const body = await res.json().catch(() => ({}));
|
|
6536
|
-
return {
|
|
6537
|
-
runId: typeof body.runId === "string" ? body.runId : "",
|
|
6538
|
-
linked: typeof body.linked === "number" ? body.linked : 0,
|
|
6539
|
-
proposed: typeof body.proposed === "number" ? body.proposed : 0,
|
|
6540
|
-
skipped: typeof body.skipped === "number" ? body.skipped : 0
|
|
6541
|
-
};
|
|
6542
6603
|
}
|
|
6543
6604
|
function reportIngestFailure(err, write) {
|
|
6544
6605
|
if (err instanceof IngestNotLoggedInError || err instanceof IngestTokenRejectedError || err instanceof CairnRunNotFoundError || err instanceof NoCairnRunsError || err instanceof CairnRunVersionError || err instanceof CairnRunPartialError || err instanceof CairnEvidenceAmbiguousError) {
|
|
@@ -6563,14 +6624,16 @@ function formatIngestResult(r) {
|
|
|
6563
6624
|
return `${lines.join("\n")}
|
|
6564
6625
|
`;
|
|
6565
6626
|
}
|
|
6566
|
-
var IngestNotLoggedInError, IngestTokenRejectedError, IngestNetworkError, IngestHttpError;
|
|
6627
|
+
var path17, IngestNotLoggedInError, IngestTokenRejectedError, IngestNetworkError, IngestHttpError;
|
|
6567
6628
|
var init_ingest = __esm({
|
|
6568
6629
|
"src/cli/commands/ingest.ts"() {
|
|
6569
6630
|
"use strict";
|
|
6570
6631
|
init_cjs_shims();
|
|
6632
|
+
path17 = __toESM(require("path"), 1);
|
|
6571
6633
|
init_api_url();
|
|
6572
6634
|
init_credentials();
|
|
6573
6635
|
init_cairn_artifact();
|
|
6636
|
+
init_job_reporter();
|
|
6574
6637
|
IngestNotLoggedInError = class extends Error {
|
|
6575
6638
|
constructor() {
|
|
6576
6639
|
super('Not logged in. Run "plune login" first, or set PLUNE_TOKEN.');
|
|
@@ -7644,10 +7707,10 @@ ${missed.map((m) => ` - ${m}`).join("\n")}
|
|
|
7644
7707
|
const { handleLogin: handleLogin2, reportLoginFailure: reportLoginFailure2 } = await Promise.resolve().then(() => (init_login(), login_exports));
|
|
7645
7708
|
try {
|
|
7646
7709
|
const token = options.token ?? await readTokenFromStdin();
|
|
7647
|
-
const { path:
|
|
7710
|
+
const { path: path18, verified } = await handleLogin2({ token, skipVerify: options.skipVerify });
|
|
7648
7711
|
process.stdout.write(
|
|
7649
|
-
verified ? `Logged in. Token checked against the API and saved to ${
|
|
7650
|
-
` : `Token saved to ${
|
|
7712
|
+
verified ? `Logged in. Token checked against the API and saved to ${path18}
|
|
7713
|
+
` : `Token saved to ${path18} WITHOUT being checked (--skip-verify).
|
|
7651
7714
|
`
|
|
7652
7715
|
);
|
|
7653
7716
|
} catch (err) {
|
|
@@ -7664,9 +7727,9 @@ ${missed.map((m) => ` - ${m}`).join("\n")}
|
|
|
7664
7727
|
const verbose = command.optsWithGlobals().verbose === true;
|
|
7665
7728
|
const { handleLogout: handleLogout2 } = await Promise.resolve().then(() => (init_logout(), logout_exports));
|
|
7666
7729
|
try {
|
|
7667
|
-
const { removed, path:
|
|
7730
|
+
const { removed, path: path18 } = handleLogout2();
|
|
7668
7731
|
process.stdout.write(
|
|
7669
|
-
removed ? `Logged out. Removed ${
|
|
7732
|
+
removed ? `Logged out. Removed ${path18}
|
|
7670
7733
|
` : "Not logged in \u2014 nothing to remove.\n"
|
|
7671
7734
|
);
|
|
7672
7735
|
} catch (err) {
|
|
@@ -7710,9 +7773,12 @@ ${missed.map((m) => ` - ${m}`).join("\n")}
|
|
|
7710
7773
|
const verbose = globals.verbose === true;
|
|
7711
7774
|
const { handleIngest: handleIngest2, reportIngestFailure: reportIngestFailure2, formatIngestResult: formatIngestResult2 } = await Promise.resolve().then(() => (init_ingest(), ingest_exports));
|
|
7712
7775
|
try {
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
)
|
|
7776
|
+
const result = await handleIngest2({ ...dir !== void 0 ? { dir } : {} });
|
|
7777
|
+
process.stdout.write(formatIngestResult2(result));
|
|
7778
|
+
if (result.jobProblem !== void 0) {
|
|
7779
|
+
process.stderr.write(`plune: could not report this ingest to the job queue (${result.jobProblem}) \u2014 the run is recorded.
|
|
7780
|
+
`);
|
|
7781
|
+
}
|
|
7716
7782
|
} catch (err) {
|
|
7717
7783
|
const code = reportIngestFailure2(err, (s) => process.stderr.write(s));
|
|
7718
7784
|
if (code !== null) {
|