@plune-ai/playwright 0.7.1 → 0.7.3
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/index.cjs +510 -246
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +513 -249
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,7 @@ var import_crypto2 = require("crypto");
|
|
|
58
58
|
var import_fs5 = require("fs");
|
|
59
59
|
var fs = __toESM(require("fs"), 1);
|
|
60
60
|
var path2 = __toESM(require("path"), 1);
|
|
61
|
+
var import_fs6 = require("fs");
|
|
61
62
|
var import_crypto3 = require("crypto");
|
|
62
63
|
var DEFAULT_API_URL = "https://beta-api.plune.ai";
|
|
63
64
|
function resolveApiUrl(explicit) {
|
|
@@ -259,6 +260,7 @@ function createClient(opts) {
|
|
|
259
260
|
upload: (path3, bytes, contentType) => send("POST", path3, { body: bytes, type: contentType }, uploadRetries ?? DEFAULT_RETRIES),
|
|
260
261
|
del: (path3) => send("DELETE", path3),
|
|
261
262
|
get: (path3) => send("GET", path3),
|
|
263
|
+
patch: (path3, body) => send("PATCH", path3, { body: JSON.stringify(body), type: "application/json" }),
|
|
262
264
|
async put(url, headers, source) {
|
|
263
265
|
const putRetries = uploadRetries ?? 3;
|
|
264
266
|
let last = { ok: false, status: null, code: "network" };
|
|
@@ -466,7 +468,7 @@ function cutErrorContext(attempt, home) {
|
|
|
466
468
|
const text = attempt.errors.map((e) => e.text).filter((t) => t !== "").join("\n\n");
|
|
467
469
|
return cut(machineless(text, attempt.repoRoot, home));
|
|
468
470
|
}
|
|
469
|
-
var printable = (text) => text.replace(/[\u0000-\u001f\u007f-\u009f]/g, "?");
|
|
471
|
+
var printable = (text) => text.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, "?");
|
|
470
472
|
var mediaTypeOf = (contentType) => contentType?.split(";")[0]?.trim().toLowerCase() || void 0;
|
|
471
473
|
var TEXT_TYPES = /* @__PURE__ */ new Set(["application/json", "text/plain"]);
|
|
472
474
|
var isTextType = (contentType) => TEXT_TYPES.has(mediaTypeOf(contentType) ?? "");
|
|
@@ -598,10 +600,175 @@ function appendBatch(file, batch) {
|
|
|
598
600
|
fs.appendFileSync(file, `${JSON.stringify(line)}
|
|
599
601
|
`, "utf8");
|
|
600
602
|
}
|
|
603
|
+
var SNAPSHOT_MAX_BYTES = 16384;
|
|
604
|
+
var CALL = /\b(?:test|it)(?:\.(?:skip|fixme|only|fail|slow))?\s*\(/g;
|
|
605
|
+
var BEFORE_REGEX = /* @__PURE__ */ new Set([..."(,=:[!&|?{};+-*%<>~^"]);
|
|
606
|
+
function skipString(src, i, quote) {
|
|
607
|
+
for (let j = i + 1; j < src.length; j += 1) {
|
|
608
|
+
const c = src[j];
|
|
609
|
+
if (c === "\\") j += 1;
|
|
610
|
+
else if (c === quote) return j + 1;
|
|
611
|
+
else if (c === "\n") return -1;
|
|
612
|
+
}
|
|
613
|
+
return -1;
|
|
614
|
+
}
|
|
615
|
+
function skipTemplate(src, i) {
|
|
616
|
+
for (let j = i + 1; j < src.length; j += 1) {
|
|
617
|
+
const c = src[j];
|
|
618
|
+
if (c === "\\") j += 1;
|
|
619
|
+
else if (c === "`") return j + 1;
|
|
620
|
+
else if (c === "$" && src[j + 1] === "{") {
|
|
621
|
+
const end = matching(src, j + 2, "}");
|
|
622
|
+
if (end < 0) return -1;
|
|
623
|
+
j = end;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return -1;
|
|
627
|
+
}
|
|
628
|
+
function skipRegex(src, i) {
|
|
629
|
+
let inClass = false;
|
|
630
|
+
for (let j = i + 1; j < src.length; j += 1) {
|
|
631
|
+
const c = src[j];
|
|
632
|
+
if (c === "\\") j += 1;
|
|
633
|
+
else if (c === "\n") return -1;
|
|
634
|
+
else if (c === "[") inClass = true;
|
|
635
|
+
else if (c === "]") inClass = false;
|
|
636
|
+
else if (c === "/" && !inClass) {
|
|
637
|
+
let k = j + 1;
|
|
638
|
+
while (k < src.length && /[a-z]/i.test(src[k])) k += 1;
|
|
639
|
+
return k;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return -1;
|
|
643
|
+
}
|
|
644
|
+
function matching(src, i, close) {
|
|
645
|
+
const stack = [close];
|
|
646
|
+
let prev = "(";
|
|
647
|
+
while (i < src.length) {
|
|
648
|
+
const c = src[i];
|
|
649
|
+
const next = src[i + 1];
|
|
650
|
+
let to = -2;
|
|
651
|
+
if (c === "/" && next === "/") to = src.indexOf("\n", i);
|
|
652
|
+
else if (c === "/" && next === "*")
|
|
653
|
+
to = src.indexOf("*/", i + 2) < 0 ? -1 : src.indexOf("*/", i + 2) + 2;
|
|
654
|
+
else if (c === "'" || c === '"') to = skipString(src, i, c);
|
|
655
|
+
else if (c === "`") to = skipTemplate(src, i);
|
|
656
|
+
else if (c === "/" && BEFORE_REGEX.has(prev)) to = skipRegex(src, i);
|
|
657
|
+
if (to === -1) return -1;
|
|
658
|
+
if (to !== -2) {
|
|
659
|
+
if (c !== "/" || next !== "/" && next !== "*") prev = "a";
|
|
660
|
+
i = to;
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
if (c === "(") stack.push(")");
|
|
664
|
+
else if (c === "[") stack.push("]");
|
|
665
|
+
else if (c === "{") stack.push("}");
|
|
666
|
+
else if (c === ")" || c === "]" || c === "}") {
|
|
667
|
+
if (stack.pop() !== c) return -1;
|
|
668
|
+
if (stack.length === 0) return i;
|
|
669
|
+
}
|
|
670
|
+
if (!/\s/.test(c)) prev = c;
|
|
671
|
+
i += 1;
|
|
672
|
+
}
|
|
673
|
+
return -1;
|
|
674
|
+
}
|
|
675
|
+
function callTextAt(source, line, column) {
|
|
676
|
+
const lines = source.split("\n");
|
|
677
|
+
if (line < 1 || line > lines.length) return void 0;
|
|
678
|
+
const lineStart = lines.slice(0, line - 1).reduce((n, l) => n + l.length + 1, 0);
|
|
679
|
+
const lineEnd = lineStart + lines[line - 1].length;
|
|
680
|
+
const heads = [];
|
|
681
|
+
CALL.lastIndex = lineStart;
|
|
682
|
+
for (let h = CALL.exec(source); h !== null && h.index < lineEnd; h = CALL.exec(source))
|
|
683
|
+
heads.push(h);
|
|
684
|
+
const at = column === void 0 ? -1 : lineStart + column - 1;
|
|
685
|
+
const head = heads.find((h) => h.index <= at && at < h.index + h[0].length) ?? (heads.length === 1 ? heads[0] : void 0);
|
|
686
|
+
if (head === void 0) return void 0;
|
|
687
|
+
const end = matching(source, head.index + head[0].length, ")");
|
|
688
|
+
if (end < 0) return void 0;
|
|
689
|
+
const text = source.slice(head.index, end + 1).replace(/\r\n/g, "\n");
|
|
690
|
+
return Buffer.byteLength(text, "utf8") <= SNAPSHOT_MAX_BYTES ? text : void 0;
|
|
691
|
+
}
|
|
692
|
+
var CREDENTIAL = "password|passphrase|passwd|pass|pwd|token|secret|api[-_]?key|private[-_]?key|credential|auth|session|cookie";
|
|
693
|
+
var LITERAL = String.raw`(?<q>['"\x60])(?:\\.|(?!\k<q>)[^\\\n])*\k<q>`;
|
|
694
|
+
var TYPING = "(?:fill|type|pressSequentially)";
|
|
695
|
+
var SHAPES = [
|
|
696
|
+
{ kind: "github-token", re: /\b(?:ghp|gho|ghs|ghu)_[A-Za-z0-9]{36}\b|\bgithub_pat_\w{20,}/g },
|
|
697
|
+
{ kind: "api-key", re: /\bsk-[\w-]{20,}/g },
|
|
698
|
+
{ kind: "api-key", re: /\b[sr]k_(?:live|test)_[A-Za-z0-9]{10,}/g },
|
|
699
|
+
{ kind: "npm-token", re: /\bnpm_[A-Za-z0-9]{20,}/g },
|
|
700
|
+
{ kind: "google-key", re: /\bAIza[\w-]{30,}/g },
|
|
701
|
+
{ kind: "plune-token", re: /\bplune_[A-Za-z0-9_]{16,}/g },
|
|
702
|
+
{ kind: "aws-key", re: /\bAKIA[0-9A-Z]{16}\b/g },
|
|
703
|
+
{ kind: "slack-token", re: /\bxox[abprs]-[A-Za-z0-9-]{10,}/g },
|
|
704
|
+
{
|
|
705
|
+
kind: "private-key",
|
|
706
|
+
re: /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g
|
|
707
|
+
},
|
|
708
|
+
{ kind: "jwt", re: /\beyJ[\w-]{10,}\.[\w-]{10,}\.[\w-]{10,}/g }
|
|
709
|
+
];
|
|
710
|
+
var PLACES = [
|
|
711
|
+
// `password = '…'`, `apiKey: "…"`, `'x-api-key': '…'`
|
|
712
|
+
new RegExp(
|
|
713
|
+
String.raw`(?<lead>\b(?<role>[\w$-]*(?:${CREDENTIAL})[\w$-]*)['"]?\s*[:=]\s*)${LITERAL}`,
|
|
714
|
+
"gi"
|
|
715
|
+
),
|
|
716
|
+
// `setToken('…')`: the call is named for a credential
|
|
717
|
+
new RegExp(String.raw`(?<lead>\b(?<role>[\w$]*(?:${CREDENTIAL})[\w$]*)\s*\(\s*)${LITERAL}`, "gi"),
|
|
718
|
+
// `.fill('#password', '…')`, `.type('#pwd', '…')`: the field is named in the same call
|
|
719
|
+
new RegExp(
|
|
720
|
+
String.raw`(?<lead>\.${TYPING}\(\s*['"][^'"\n]*?(?<role>${CREDENTIAL})[^'"\n]*['"]\s*,\s*)${LITERAL}`,
|
|
721
|
+
"gi"
|
|
722
|
+
),
|
|
723
|
+
// `getByLabel('Password').fill('…')`, `getByRole('textbox', { name: 'Password' }).type('…')`: … or
|
|
724
|
+
// anywhere in the call the typing is chained off
|
|
725
|
+
new RegExp(
|
|
726
|
+
String.raw`(?<lead>\([^()\n]*?(?<role>${CREDENTIAL})[^()\n]*\)\s*\.${TYPING}\(\s*)${LITERAL}`,
|
|
727
|
+
"gi"
|
|
728
|
+
),
|
|
729
|
+
// `{ name: 'session', value: '…' }`: a cookie (or any name/value pair) named for a credential
|
|
730
|
+
new RegExp(
|
|
731
|
+
String.raw`(?<lead>\bname\s*:\s*['"][^'"\n]*?(?<role>${CREDENTIAL})[^'"\n]*['"]\s*,\s*value\s*:\s*)${LITERAL}`,
|
|
732
|
+
"gi"
|
|
733
|
+
)
|
|
734
|
+
];
|
|
735
|
+
var HEADER_LINE = /((?:^|\\[nr]|\x60)[ \t>*<+-]*['"]?)((?:proxy-)?authorization|(?:set-)?cookie|[\w-]*session[\w-]*)(['"]?[ \t]*:[ \t]*)(?![\w$.]+(?:\([^()\n]*\))?[ \t]*[,;)}\]])[^\s'"\x60\\][^\r\n'"\x60\\]*/gim;
|
|
736
|
+
var QUERY_PARAM = /([?&][\w.-]*(?:token|key|secret|password|passwd|pass|pwd|auth|signature|sig|credential|session)[\w.-]*=)(?!‹)[^&#\s'"\x60]+/gi;
|
|
737
|
+
function maskCredentials(text) {
|
|
738
|
+
let out = text;
|
|
739
|
+
for (const { kind, re } of SHAPES) out = out.replace(re, `\u2039${kind}\u203A`);
|
|
740
|
+
for (const re of PLACES) {
|
|
741
|
+
out = out.replace(re, (...args) => {
|
|
742
|
+
const groups = args.at(-1);
|
|
743
|
+
return `${groups.lead}${groups.q}\u2039${groups.role.toLowerCase().replace(/^[^a-z]+/, "")}\u203A${groups.q}`;
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
return out.replace(HEADER_LINE, "$1$2$3\u2039header\u203A").replace(/\b(Bearer)([ \t]+)(?!‹)[\w.~+/=-]{8,}/g, "$1$2\u2039credential\u203A").replace(
|
|
747
|
+
/\b(Basic|Token)([ \t]+)(?!‹)(?=[\w.~+/=-]*[\d=+/]|[\w.~+/=-]*[a-z][\w.~+/=-]*[A-Z])[\w.~+/=-]{8,}/g,
|
|
748
|
+
"$1$2\u2039credential\u203A"
|
|
749
|
+
).replace(/\b(PLUNE_[A-Z0-9_]*=)(?!‹)[^\s'"\x60;,)]+/g, "$1\u2039env-secret\u203A").replace(QUERY_PARAM, "$1\u2039credential\u203A").replace(/\b([a-z][\w+.-]*:\/\/)[^\s/@'"\x60]+@/gi, "$1\u2039credential\u203A@");
|
|
750
|
+
}
|
|
751
|
+
function snapshotAt(at, files) {
|
|
752
|
+
let source = files.get(at.file);
|
|
753
|
+
if (source === void 0) {
|
|
754
|
+
try {
|
|
755
|
+
source = (0, import_fs6.readFileSync)(at.file, "utf8");
|
|
756
|
+
} catch {
|
|
757
|
+
source = null;
|
|
758
|
+
}
|
|
759
|
+
files.set(at.file, source);
|
|
760
|
+
}
|
|
761
|
+
if (source === null) return void 0;
|
|
762
|
+
const text = callTextAt(source, at.line, at.column);
|
|
763
|
+
if (text === void 0) return void 0;
|
|
764
|
+
const masked = maskCredentials(text);
|
|
765
|
+
return Buffer.byteLength(masked, "utf8") <= SNAPSHOT_MAX_BYTES ? masked : void 0;
|
|
766
|
+
}
|
|
601
767
|
var RESOLVE_CHUNK = 500;
|
|
602
768
|
var BATCH_MAX = 500;
|
|
603
769
|
var DISCOVER_MAX = 500;
|
|
604
770
|
var BATCH_DEFAULT = 500;
|
|
771
|
+
var SNAPSHOT_UPDATES_MAX = 100;
|
|
605
772
|
var SEND_CONCURRENCY = 4;
|
|
606
773
|
var EXPECTED_MAX = 1e4;
|
|
607
774
|
var KEY_MAX = 1024;
|
|
@@ -680,7 +847,13 @@ function textRefusal(bytes) {
|
|
|
680
847
|
}
|
|
681
848
|
return void 0;
|
|
682
849
|
}
|
|
683
|
-
function
|
|
850
|
+
function withoutTargets(result) {
|
|
851
|
+
if (result.targets === void 0) return result;
|
|
852
|
+
const { targets: _targets, ...rest } = result;
|
|
853
|
+
return rest;
|
|
854
|
+
}
|
|
855
|
+
function onDisk(deferred) {
|
|
856
|
+
const result = withoutTargets(deferred);
|
|
684
857
|
if (!("files" in result) || result.files === void 0) return result;
|
|
685
858
|
const { files, ...rest } = result;
|
|
686
859
|
const kept = files.filter((f) => f.path !== void 0).map(({ body: _body, ...file }) => file);
|
|
@@ -731,68 +904,14 @@ function chunk(items, size) {
|
|
|
731
904
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
732
905
|
return out;
|
|
733
906
|
}
|
|
734
|
-
function
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
if (names.some((name) => run[name] != null)) return;
|
|
738
|
-
log(
|
|
739
|
-
`plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
|
|
740
|
-
);
|
|
741
|
-
}
|
|
742
|
-
async function startRun(passed, declared2) {
|
|
743
|
-
const env = readEnv();
|
|
744
|
-
if (env.shardError !== void 0) throw new Error(env.shardError);
|
|
745
|
-
if (env.configurationError !== void 0 && passed.configuration === void 0) throw new Error(env.configurationError);
|
|
746
|
-
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
747
|
-
const cfg = { ...env.config, ...stated };
|
|
748
|
-
const configuration = cfg.configuration !== void 0 && Object.keys(cfg.configuration).length > 0 ? cfg.configuration : void 0;
|
|
749
|
-
const log = cfg.log ?? ((line) => void process.stderr.write(`${line}
|
|
750
|
-
`));
|
|
751
|
-
const fallbackPath = cfg.fallbackPath ?? DEFAULT_FALLBACK_PATH;
|
|
752
|
-
const externalKey = cfg.externalKey ?? null;
|
|
753
|
-
const sessionMarker = (0, import_crypto.randomUUID)();
|
|
754
|
-
const batchSize = Math.min(cfg.batchSize ?? BATCH_DEFAULT, BATCH_MAX);
|
|
755
|
-
const offerDiscovered = cfg.offerDiscovered ?? false;
|
|
756
|
-
const token = cfg.token ?? loadToken() ?? "";
|
|
757
|
-
const uploadsAtOnce = Math.min(Math.max(Math.floor(cfg.uploadConcurrency ?? UPLOAD_CONCURRENCY.default), UPLOAD_CONCURRENCY.min), UPLOAD_CONCURRENCY.max);
|
|
758
|
-
const uploadRetries = Math.min(Math.max(Math.floor(cfg.uploadRetries ?? UPLOAD_RETRIES.default), UPLOAD_RETRIES.min), UPLOAD_RETRIES.max);
|
|
907
|
+
function fileSender(options) {
|
|
908
|
+
const { client, log, stats, uploadsAtOnce, uploadRetries } = options;
|
|
909
|
+
const without = options.without ?? "its result is reported without it";
|
|
759
910
|
let retried = 0;
|
|
760
911
|
let uploadMs = 0;
|
|
761
912
|
let requests = 0;
|
|
762
913
|
let existed = 0;
|
|
763
914
|
let batchMissing = false;
|
|
764
|
-
const client = createClient({
|
|
765
|
-
apiUrl: resolveApiUrl(cfg.apiUrl),
|
|
766
|
-
token,
|
|
767
|
-
uploadRetries,
|
|
768
|
-
onRetry: () => void (retried += 1),
|
|
769
|
-
...cfg.fetchImpl !== void 0 ? { fetchImpl: cfg.fetchImpl } : {}
|
|
770
|
-
});
|
|
771
|
-
const stats = {
|
|
772
|
-
accepted: 0,
|
|
773
|
-
duplicate: 0,
|
|
774
|
-
conflict: 0,
|
|
775
|
-
rejected: 0,
|
|
776
|
-
unresolved: 0,
|
|
777
|
-
offered: 0,
|
|
778
|
-
created: 0,
|
|
779
|
-
unoffered: 0,
|
|
780
|
-
deferred: 0,
|
|
781
|
-
screenshots: { uploaded: 0, skipped: 0, failed: 0 },
|
|
782
|
-
textFiles: { uploaded: 0, skipped: 0, failed: 0 },
|
|
783
|
-
otherFiles: { uploaded: 0, skipped: 0, failed: 0 }
|
|
784
|
-
};
|
|
785
|
-
const resolved = /* @__PURE__ */ new Map();
|
|
786
|
-
let buffer = [];
|
|
787
|
-
const discoveries = /* @__PURE__ */ new Map();
|
|
788
|
-
const held = /* @__PURE__ */ new Map();
|
|
789
|
-
let createdWithResult = 0;
|
|
790
|
-
let createdUndelivered = 0;
|
|
791
|
-
let runId = null;
|
|
792
|
-
let joined = false;
|
|
793
|
-
let offline = token === "";
|
|
794
|
-
let done = false;
|
|
795
|
-
const shortened = /* @__PURE__ */ new Set();
|
|
796
915
|
const skipsSaid = /* @__PURE__ */ new Set();
|
|
797
916
|
const countsOf = (kind) => kind === "text" ? stats.textFiles : kind === "file" ? stats.otherFiles : stats.screenshots;
|
|
798
917
|
let bucketSeen = false;
|
|
@@ -801,168 +920,6 @@ async function startRun(passed, declared2) {
|
|
|
801
920
|
const failedSaid = /* @__PURE__ */ new Set();
|
|
802
921
|
const codesSaid = /* @__PURE__ */ new Set();
|
|
803
922
|
const rooms = /* @__PURE__ */ new Map();
|
|
804
|
-
function bound(keys) {
|
|
805
|
-
return keys.map((key) => {
|
|
806
|
-
const fit = boundKey(key);
|
|
807
|
-
if (fit !== key && !shortened.has(key.value)) {
|
|
808
|
-
shortened.add(key.value);
|
|
809
|
-
if (shortened.size === 1) {
|
|
810
|
-
log(
|
|
811
|
-
`plune: a test name longer than ${KEY_MAX} characters was shortened to fit its key \u2014 ${JSON.stringify(printable(key.value.slice(0, 80)))}\u2026 Give the test a shorter name; until then this is its identity.`
|
|
812
|
-
);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
return fit;
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
const expected = declared2?.map(bound);
|
|
819
|
-
if (offline) {
|
|
820
|
-
log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
|
|
821
|
-
}
|
|
822
|
-
for (const warning of env.warnings) log(`plune: ${warning}`);
|
|
823
|
-
if (env.ignored.length > 0) {
|
|
824
|
-
log(`plune: ignoring ${env.ignored.join(", ")} \u2014 a run has nowhere to store them yet.`);
|
|
825
|
-
}
|
|
826
|
-
function defer(results) {
|
|
827
|
-
appendBatch(fallbackPath, {
|
|
828
|
-
runId,
|
|
829
|
-
externalKey,
|
|
830
|
-
session: sessionMarker,
|
|
831
|
-
...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
|
|
832
|
-
...configuration !== void 0 ? { configuration } : {},
|
|
833
|
-
results: results.map(onDisk)
|
|
834
|
-
});
|
|
835
|
-
stats.deferred += results.length;
|
|
836
|
-
}
|
|
837
|
-
async function resolveKeys(values) {
|
|
838
|
-
const unknown = values.filter((k) => !resolved.has(keyId(k)));
|
|
839
|
-
if (unknown.length === 0 || offline) return;
|
|
840
|
-
for (const part of chunk(unknown, RESOLVE_CHUNK)) {
|
|
841
|
-
const out = await client.post(
|
|
842
|
-
"/v1/test-cases/resolve",
|
|
843
|
-
{ keys: part }
|
|
844
|
-
);
|
|
845
|
-
if (!out.ok || !Array.isArray(out.body?.results)) {
|
|
846
|
-
log(`plune: could not look up test cases (${out.ok ? "the answer had no results" : out.detail || out.kind}).`);
|
|
847
|
-
return;
|
|
848
|
-
}
|
|
849
|
-
for (const row of out.body.results) {
|
|
850
|
-
if (typeof row?.key?.value === "string") resolved.set(keyId(row.key), row.testCaseId);
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
if (!offline) {
|
|
855
|
-
if (expected !== void 0) await resolveKeys(expected.flat());
|
|
856
|
-
const stated2 = expected?.slice(0, EXPECTED_MAX) ?? [];
|
|
857
|
-
const configuration2 = stated2.length === 0 ? void 0 : {
|
|
858
|
-
expected: stated2.flatMap((keys) => {
|
|
859
|
-
const hit = keys.map((k) => resolved.get(keyId(k))).find((v) => typeof v === "string");
|
|
860
|
-
if (typeof hit === "string") return [{ testCaseId: hit }];
|
|
861
|
-
return keys[0] === void 0 ? [] : [{ externalKey: keys[0] }];
|
|
862
|
-
}),
|
|
863
|
-
// The claim travels with the list it is about (D20). A runner that could not enumerate
|
|
864
|
-
// its tests has no list, and a claim without one is nothing the platform can check —
|
|
865
|
-
// so it is not sent, rather than sent and silently meaningless.
|
|
866
|
-
...cfg.full === true ? { full: true } : {}
|
|
867
|
-
};
|
|
868
|
-
if (expected !== void 0 && expected.length > EXPECTED_MAX) {
|
|
869
|
-
log(`plune: ${expected.length} tests is more than the run configuration holds \u2014 reporting the first ${EXPECTED_MAX}.`);
|
|
870
|
-
}
|
|
871
|
-
const described = {
|
|
872
|
-
...cfg.title !== void 0 ? { title: cfg.title } : {},
|
|
873
|
-
...cfg.environment !== void 0 ? { environment: cfg.environment } : {},
|
|
874
|
-
...cfg.labels !== void 0 ? { labels: cfg.labels } : {}
|
|
875
|
-
};
|
|
876
|
-
const request = {
|
|
877
|
-
schemaVersion: 2,
|
|
878
|
-
kind: cfg.kind ?? "automated",
|
|
879
|
-
...externalKey !== null ? { externalKey } : {},
|
|
880
|
-
...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
|
|
881
|
-
...configuration2 !== void 0 ? { configuration: configuration2 } : {},
|
|
882
|
-
// Named even when nobody named it — the list has to read without opening a row. Only what
|
|
883
|
-
// the caller DESCRIBED goes to `warnIfDropped` below: a title this side invented is not one
|
|
884
|
-
// a person will miss, and a deployment older than the field must not be nagged on every run.
|
|
885
|
-
title: defaultRunTitle(),
|
|
886
|
-
...described
|
|
887
|
-
};
|
|
888
|
-
let start = await client.post("/v1/runs", request);
|
|
889
|
-
if (!start.ok && start.status === 413 && configuration2 !== void 0) {
|
|
890
|
-
log(
|
|
891
|
-
`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.`
|
|
892
|
-
);
|
|
893
|
-
start = await client.post("/v1/runs", { ...request, configuration: void 0 });
|
|
894
|
-
}
|
|
895
|
-
if (start.ok && typeof start.body?.run?.id === "string") {
|
|
896
|
-
runId = start.body.run.id;
|
|
897
|
-
joined = start.status === 200;
|
|
898
|
-
warnIfDropped(described, start.body.run, log);
|
|
899
|
-
} else {
|
|
900
|
-
const why = start.ok ? "the answer had no run" : start.detail || start.kind;
|
|
901
|
-
log(`plune: could not start the run (${why}). Results will be written to ${fallbackPath}.`);
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
function matchFor(result) {
|
|
905
|
-
if (result.testCaseId !== void 0) return { kind: "found", testCaseId: result.testCaseId };
|
|
906
|
-
let unanswered = false;
|
|
907
|
-
for (const key of result.keys) {
|
|
908
|
-
const hit = resolved.get(keyId(key));
|
|
909
|
-
if (typeof hit === "string") return { kind: "found", testCaseId: hit };
|
|
910
|
-
if (hit === void 0) unanswered = true;
|
|
911
|
-
}
|
|
912
|
-
return unanswered ? { kind: "unanswered" } : { kind: "unmatched" };
|
|
913
|
-
}
|
|
914
|
-
function remember(result) {
|
|
915
|
-
if (!offerDiscovered) return;
|
|
916
|
-
if (result.title === void 0 || result.specRef === void 0) return;
|
|
917
|
-
if (result.keys.length === 0) return;
|
|
918
|
-
const title = boundTitle(result.title);
|
|
919
|
-
if (title !== result.title) shortened.add(result.title);
|
|
920
|
-
discoveries.set(keyId(result.keys[0]), {
|
|
921
|
-
keys: result.keys,
|
|
922
|
-
title,
|
|
923
|
-
source: result.source,
|
|
924
|
-
specRef: result.specRef,
|
|
925
|
-
rawStatus: result.rawStatus
|
|
926
|
-
});
|
|
927
|
-
for (const key of result.keys) held.set(keyId(key), result);
|
|
928
|
-
}
|
|
929
|
-
async function offer() {
|
|
930
|
-
if (discoveries.size === 0 || offline || runId === null) return;
|
|
931
|
-
const batches = chunk([...discoveries.values()], DISCOVER_MAX);
|
|
932
|
-
for (const [index, batch] of batches.entries()) {
|
|
933
|
-
const out = await client.post("/v1/review-items/discovered", {
|
|
934
|
-
discovered: batch,
|
|
935
|
-
runId
|
|
936
|
-
});
|
|
937
|
-
if (!out.ok || !Array.isArray(out.body?.results)) {
|
|
938
|
-
stats.unoffered = batches.slice(index).reduce((n, rest) => n + rest.length, 0);
|
|
939
|
-
stats.unofferedWhy = whyUnoffered(out);
|
|
940
|
-
log(
|
|
941
|
-
`plune: could not offer ${stats.unoffered} unknown test(s) for review (${out.ok ? "the answer had no results" : out.detail || out.kind}).`
|
|
942
|
-
);
|
|
943
|
-
return;
|
|
944
|
-
}
|
|
945
|
-
stats.offered += out.body.results.filter((r) => r?.outcome === "queued").length;
|
|
946
|
-
const made = out.body.results.filter((r) => r?.outcome === "created");
|
|
947
|
-
stats.created += made.length;
|
|
948
|
-
const submissions = [];
|
|
949
|
-
const filesByKey = /* @__PURE__ */ new Map();
|
|
950
|
-
for (const r of made) {
|
|
951
|
-
const pending = typeof r.id === "string" && r.id !== "" && typeof r.key?.value === "string" ? held.get(keyId(r.key)) : void 0;
|
|
952
|
-
if (pending === void 0) continue;
|
|
953
|
-
for (const key of pending.keys) held.delete(keyId(key));
|
|
954
|
-
const { keys: _keys, files, ...rest } = pending;
|
|
955
|
-
submissions.push({ ...rest, testCaseId: r.id });
|
|
956
|
-
if (files !== void 0) filesByKey.set(pending.resultKey, files);
|
|
957
|
-
}
|
|
958
|
-
if (submissions.length > 0) {
|
|
959
|
-
const before = stats.deferred;
|
|
960
|
-
await send(submissions, filesByKey);
|
|
961
|
-
createdWithResult += submissions.length;
|
|
962
|
-
createdUndelivered += stats.deferred - before;
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
923
|
function skip(kind, name, why) {
|
|
967
924
|
countsOf(kind).skipped += 1;
|
|
968
925
|
if (why === "noStorage") noStorage += 1;
|
|
@@ -972,24 +929,25 @@ async function startRun(passed, declared2) {
|
|
|
972
929
|
if (why === "noStorage") log(`plune: "${name}" not stored \u2014 ${SKIPPED[why]}.`);
|
|
973
930
|
else log(`plune: ${KINDS[kind].label} "${name}" not uploaded \u2014 ${SKIPPED[why]}.`);
|
|
974
931
|
}
|
|
932
|
+
const filesOf2 = (job) => `/v1/${job.owner ?? "results"}/${encodeURIComponent(job.id)}/files`;
|
|
975
933
|
function ask(job, size) {
|
|
976
934
|
requests += 1;
|
|
977
|
-
return client.post(
|
|
978
|
-
files: [{ name: job.name, contentType: job.type, size }]
|
|
935
|
+
return client.post(`${filesOf2(job)}/uploads`, {
|
|
936
|
+
files: [{ name: job.name, contentType: job.type, size, ...job.key !== void 0 ? { key: job.key } : {} }]
|
|
979
937
|
}, uploadRetries);
|
|
980
938
|
}
|
|
981
939
|
function failed(job, why) {
|
|
982
940
|
countsOf(job.kind).failed += 1;
|
|
983
941
|
if (!failedSaid.has(job.kind)) {
|
|
984
942
|
failedSaid.add(job.kind);
|
|
985
|
-
log(`plune: could not upload a ${KINDS[job.kind].label} (${why}) \u2014
|
|
943
|
+
log(`plune: could not upload a ${KINDS[job.kind].label} (${why}) \u2014 ${without}.`);
|
|
986
944
|
}
|
|
987
945
|
}
|
|
988
946
|
function failedToBucket(job, code) {
|
|
989
947
|
countsOf(job.kind).failed += 1;
|
|
990
948
|
if (codesSaid.has(code)) return;
|
|
991
949
|
codesSaid.add(code);
|
|
992
|
-
log(`plune: "${job.name}" not uploaded to your bucket (${code}) \u2014
|
|
950
|
+
log(`plune: "${job.name}" not uploaded to your bucket (${code}) \u2014 ${without}.`);
|
|
993
951
|
}
|
|
994
952
|
function refusedHere(job, size) {
|
|
995
953
|
if (job.kind === "screenshot") {
|
|
@@ -1017,7 +975,7 @@ async function startRun(passed, declared2) {
|
|
|
1017
975
|
if (refusal !== void 0) return skip(kind, job.name, refusal);
|
|
1018
976
|
requests += 1;
|
|
1019
977
|
const out = await client.upload(
|
|
1020
|
-
|
|
978
|
+
`${filesOf2(job)}?name=${encodeURIComponent(job.name)}`,
|
|
1021
979
|
bytes,
|
|
1022
980
|
job.type
|
|
1023
981
|
);
|
|
@@ -1039,8 +997,8 @@ async function startRun(passed, declared2) {
|
|
|
1039
997
|
link = fresh;
|
|
1040
998
|
}
|
|
1041
999
|
requests += 1;
|
|
1042
|
-
const
|
|
1043
|
-
if (!
|
|
1000
|
+
const done = await client.post(`/v1/files/${encodeURIComponent(link.id)}/complete`, {}, uploadRetries);
|
|
1001
|
+
if (!done.ok) return failedToBucket(job, codeOf(done));
|
|
1044
1002
|
countsOf(job.kind).uploaded += 1;
|
|
1045
1003
|
}
|
|
1046
1004
|
let free = uploadsAtOnce;
|
|
@@ -1367,6 +1325,296 @@ async function startRun(passed, declared2) {
|
|
|
1367
1325
|
else await uploadBatched(jobs);
|
|
1368
1326
|
uploadMs += Date.now() - started;
|
|
1369
1327
|
}
|
|
1328
|
+
return {
|
|
1329
|
+
upload,
|
|
1330
|
+
uploadEach,
|
|
1331
|
+
onRetry: () => void (retried += 1),
|
|
1332
|
+
get bucketSeen() {
|
|
1333
|
+
return bucketSeen;
|
|
1334
|
+
},
|
|
1335
|
+
get noStorage() {
|
|
1336
|
+
return noStorage;
|
|
1337
|
+
},
|
|
1338
|
+
get existed() {
|
|
1339
|
+
return existed;
|
|
1340
|
+
},
|
|
1341
|
+
get retried() {
|
|
1342
|
+
return retried;
|
|
1343
|
+
},
|
|
1344
|
+
get uploadMs() {
|
|
1345
|
+
return uploadMs;
|
|
1346
|
+
},
|
|
1347
|
+
get requests() {
|
|
1348
|
+
return requests;
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
function warnIfDropped(sent, run, log) {
|
|
1353
|
+
const names = Object.keys(sent);
|
|
1354
|
+
if (names.length === 0) return;
|
|
1355
|
+
if (names.some((name) => run[name] != null)) return;
|
|
1356
|
+
log(
|
|
1357
|
+
`plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
|
|
1358
|
+
);
|
|
1359
|
+
}
|
|
1360
|
+
async function startRun(passed, declared2) {
|
|
1361
|
+
const env = readEnv();
|
|
1362
|
+
if (env.shardError !== void 0) throw new Error(env.shardError);
|
|
1363
|
+
if (env.configurationError !== void 0 && passed.configuration === void 0) throw new Error(env.configurationError);
|
|
1364
|
+
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
1365
|
+
const cfg = { ...env.config, ...stated };
|
|
1366
|
+
const configuration = cfg.configuration !== void 0 && Object.keys(cfg.configuration).length > 0 ? cfg.configuration : void 0;
|
|
1367
|
+
const log = cfg.log ?? ((line) => void process.stderr.write(`${line}
|
|
1368
|
+
`));
|
|
1369
|
+
const fallbackPath = cfg.fallbackPath ?? DEFAULT_FALLBACK_PATH;
|
|
1370
|
+
const externalKey = cfg.externalKey ?? null;
|
|
1371
|
+
const sessionMarker = (0, import_crypto.randomUUID)();
|
|
1372
|
+
const batchSize = Math.min(cfg.batchSize ?? BATCH_DEFAULT, BATCH_MAX);
|
|
1373
|
+
const offerDiscovered = cfg.offerDiscovered ?? false;
|
|
1374
|
+
const token = cfg.token ?? loadToken() ?? "";
|
|
1375
|
+
const uploadsAtOnce = Math.min(Math.max(Math.floor(cfg.uploadConcurrency ?? UPLOAD_CONCURRENCY.default), UPLOAD_CONCURRENCY.min), UPLOAD_CONCURRENCY.max);
|
|
1376
|
+
const uploadRetries = Math.min(Math.max(Math.floor(cfg.uploadRetries ?? UPLOAD_RETRIES.default), UPLOAD_RETRIES.min), UPLOAD_RETRIES.max);
|
|
1377
|
+
const client = createClient({
|
|
1378
|
+
apiUrl: resolveApiUrl(cfg.apiUrl),
|
|
1379
|
+
token,
|
|
1380
|
+
uploadRetries,
|
|
1381
|
+
onRetry: () => files.onRetry(),
|
|
1382
|
+
...cfg.fetchImpl !== void 0 ? { fetchImpl: cfg.fetchImpl } : {}
|
|
1383
|
+
});
|
|
1384
|
+
const stats = {
|
|
1385
|
+
accepted: 0,
|
|
1386
|
+
duplicate: 0,
|
|
1387
|
+
conflict: 0,
|
|
1388
|
+
rejected: 0,
|
|
1389
|
+
unresolved: 0,
|
|
1390
|
+
offered: 0,
|
|
1391
|
+
created: 0,
|
|
1392
|
+
unoffered: 0,
|
|
1393
|
+
deferred: 0,
|
|
1394
|
+
screenshots: { uploaded: 0, skipped: 0, failed: 0 },
|
|
1395
|
+
textFiles: { uploaded: 0, skipped: 0, failed: 0 },
|
|
1396
|
+
otherFiles: { uploaded: 0, skipped: 0, failed: 0 }
|
|
1397
|
+
};
|
|
1398
|
+
const files = fileSender({ client, log, stats, uploadsAtOnce, uploadRetries });
|
|
1399
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
1400
|
+
let buffer = [];
|
|
1401
|
+
const discoveries = /* @__PURE__ */ new Map();
|
|
1402
|
+
const held = /* @__PURE__ */ new Map();
|
|
1403
|
+
let createdWithResult = 0;
|
|
1404
|
+
let createdUndelivered = 0;
|
|
1405
|
+
let runId = null;
|
|
1406
|
+
let joined = false;
|
|
1407
|
+
let offline = token === "";
|
|
1408
|
+
let targetsRefused = false;
|
|
1409
|
+
let done = false;
|
|
1410
|
+
const shortened = /* @__PURE__ */ new Set();
|
|
1411
|
+
const specFiles = /* @__PURE__ */ new Map();
|
|
1412
|
+
const snapshotByKey = /* @__PURE__ */ new Map();
|
|
1413
|
+
const snapshots = /* @__PURE__ */ new Map();
|
|
1414
|
+
function bound(keys) {
|
|
1415
|
+
return keys.map((key) => {
|
|
1416
|
+
const fit = boundKey(key);
|
|
1417
|
+
if (fit !== key && !shortened.has(key.value)) {
|
|
1418
|
+
shortened.add(key.value);
|
|
1419
|
+
if (shortened.size === 1) {
|
|
1420
|
+
log(
|
|
1421
|
+
`plune: a test name longer than ${KEY_MAX} characters was shortened to fit its key \u2014 ${JSON.stringify(printable(key.value.slice(0, 80)))}\u2026 Give the test a shorter name; until then this is its identity.`
|
|
1422
|
+
);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
return fit;
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
const expected = declared2?.map(bound);
|
|
1429
|
+
if (offline) {
|
|
1430
|
+
log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
|
|
1431
|
+
}
|
|
1432
|
+
for (const warning of env.warnings) log(`plune: ${warning}`);
|
|
1433
|
+
if (env.ignored.length > 0) {
|
|
1434
|
+
log(`plune: ignoring ${env.ignored.join(", ")} \u2014 a run has nowhere to store them yet.`);
|
|
1435
|
+
}
|
|
1436
|
+
function defer(results) {
|
|
1437
|
+
appendBatch(fallbackPath, {
|
|
1438
|
+
runId,
|
|
1439
|
+
externalKey,
|
|
1440
|
+
session: sessionMarker,
|
|
1441
|
+
...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
|
|
1442
|
+
...configuration !== void 0 ? { configuration } : {},
|
|
1443
|
+
results: results.map(onDisk)
|
|
1444
|
+
});
|
|
1445
|
+
stats.deferred += results.length;
|
|
1446
|
+
}
|
|
1447
|
+
async function resolveKeys(values) {
|
|
1448
|
+
const unknown = values.filter((k) => !resolved.has(keyId(k)));
|
|
1449
|
+
if (unknown.length === 0 || offline) return;
|
|
1450
|
+
for (const part of chunk(unknown, RESOLVE_CHUNK)) {
|
|
1451
|
+
const out = await client.post(
|
|
1452
|
+
"/v1/test-cases/resolve",
|
|
1453
|
+
{ keys: part }
|
|
1454
|
+
);
|
|
1455
|
+
if (!out.ok || !Array.isArray(out.body?.results)) {
|
|
1456
|
+
log(`plune: could not look up test cases (${out.ok ? "the answer had no results" : out.detail || out.kind}).`);
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
for (const row of out.body.results) {
|
|
1460
|
+
if (typeof row?.key?.value === "string") resolved.set(keyId(row.key), row.testCaseId);
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
if (!offline) {
|
|
1465
|
+
if (expected !== void 0) await resolveKeys(expected.flat());
|
|
1466
|
+
const stated2 = expected?.slice(0, EXPECTED_MAX) ?? [];
|
|
1467
|
+
const configuration2 = stated2.length === 0 ? void 0 : {
|
|
1468
|
+
expected: stated2.flatMap((keys) => {
|
|
1469
|
+
const hit = keys.map((k) => resolved.get(keyId(k))).find((v) => typeof v === "string");
|
|
1470
|
+
if (typeof hit === "string") return [{ testCaseId: hit }];
|
|
1471
|
+
return keys[0] === void 0 ? [] : [{ externalKey: keys[0] }];
|
|
1472
|
+
}),
|
|
1473
|
+
// The claim travels with the list it is about. A runner that could not enumerate
|
|
1474
|
+
// its tests has no list, and a claim without one is nothing the platform can check —
|
|
1475
|
+
// so it is not sent, rather than sent and silently meaningless.
|
|
1476
|
+
...cfg.full === true ? { full: true } : {}
|
|
1477
|
+
};
|
|
1478
|
+
if (expected !== void 0 && expected.length > EXPECTED_MAX) {
|
|
1479
|
+
log(`plune: ${expected.length} tests is more than the run configuration holds \u2014 reporting the first ${EXPECTED_MAX}.`);
|
|
1480
|
+
}
|
|
1481
|
+
const described = {
|
|
1482
|
+
...cfg.title !== void 0 ? { title: cfg.title } : {},
|
|
1483
|
+
...cfg.environment !== void 0 ? { environment: cfg.environment } : {},
|
|
1484
|
+
...cfg.labels !== void 0 ? { labels: cfg.labels } : {}
|
|
1485
|
+
};
|
|
1486
|
+
const request = {
|
|
1487
|
+
schemaVersion: 2,
|
|
1488
|
+
kind: cfg.kind ?? "automated",
|
|
1489
|
+
...externalKey !== null ? { externalKey } : {},
|
|
1490
|
+
...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
|
|
1491
|
+
...configuration2 !== void 0 ? { configuration: configuration2 } : {},
|
|
1492
|
+
// Named even when nobody named it — the list has to read without opening a row. Only what
|
|
1493
|
+
// the caller DESCRIBED goes to `warnIfDropped` below: a title this side invented is not one
|
|
1494
|
+
// a person will miss, and a deployment older than the field must not be nagged on every run.
|
|
1495
|
+
title: defaultRunTitle(),
|
|
1496
|
+
...described
|
|
1497
|
+
};
|
|
1498
|
+
let start = await client.post("/v1/runs", request);
|
|
1499
|
+
if (!start.ok && start.status === 413 && configuration2 !== void 0) {
|
|
1500
|
+
log(
|
|
1501
|
+
`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.`
|
|
1502
|
+
);
|
|
1503
|
+
start = await client.post("/v1/runs", { ...request, configuration: void 0 });
|
|
1504
|
+
}
|
|
1505
|
+
if (start.ok && typeof start.body?.run?.id === "string") {
|
|
1506
|
+
runId = start.body.run.id;
|
|
1507
|
+
joined = start.status === 200;
|
|
1508
|
+
warnIfDropped(described, start.body.run, log);
|
|
1509
|
+
} else {
|
|
1510
|
+
const why = start.ok ? "the answer had no run" : start.detail || start.kind;
|
|
1511
|
+
log(`plune: could not start the run (${why}). Results will be written to ${fallbackPath}.`);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
function matchFor(result) {
|
|
1515
|
+
if (result.testCaseId !== void 0) return { kind: "found", testCaseId: result.testCaseId };
|
|
1516
|
+
let unanswered = false;
|
|
1517
|
+
for (const key of result.keys) {
|
|
1518
|
+
const hit = resolved.get(keyId(key));
|
|
1519
|
+
if (typeof hit === "string") return { kind: "found", testCaseId: hit };
|
|
1520
|
+
if (hit === void 0) unanswered = true;
|
|
1521
|
+
}
|
|
1522
|
+
return unanswered ? { kind: "unanswered" } : { kind: "unmatched" };
|
|
1523
|
+
}
|
|
1524
|
+
function remember(result) {
|
|
1525
|
+
if (!offerDiscovered) return;
|
|
1526
|
+
if (result.title === void 0 || result.specRef === void 0) return;
|
|
1527
|
+
if (result.keys.length === 0) return;
|
|
1528
|
+
const title = boundTitle(result.title);
|
|
1529
|
+
if (title !== result.title) shortened.add(result.title);
|
|
1530
|
+
discoveries.set(keyId(result.keys[0]), {
|
|
1531
|
+
keys: result.keys,
|
|
1532
|
+
title,
|
|
1533
|
+
source: result.source,
|
|
1534
|
+
specRef: result.specRef,
|
|
1535
|
+
rawStatus: result.rawStatus
|
|
1536
|
+
});
|
|
1537
|
+
for (const key of result.keys) held.set(keyId(key), result);
|
|
1538
|
+
}
|
|
1539
|
+
async function offer() {
|
|
1540
|
+
if (discoveries.size === 0 || offline || runId === null) return;
|
|
1541
|
+
const batches = chunk([...discoveries.values()], DISCOVER_MAX);
|
|
1542
|
+
for (const [index, batch] of batches.entries()) {
|
|
1543
|
+
const out = await client.post("/v1/review-items/discovered", {
|
|
1544
|
+
discovered: batch,
|
|
1545
|
+
runId
|
|
1546
|
+
});
|
|
1547
|
+
if (!out.ok || !Array.isArray(out.body?.results)) {
|
|
1548
|
+
stats.unoffered = batches.slice(index).reduce((n, rest) => n + rest.length, 0);
|
|
1549
|
+
stats.unofferedWhy = whyUnoffered(out);
|
|
1550
|
+
log(
|
|
1551
|
+
`plune: could not offer ${stats.unoffered} unknown test(s) for review (${out.ok ? "the answer had no results" : out.detail || out.kind}).`
|
|
1552
|
+
);
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
stats.offered += out.body.results.filter((r) => r?.outcome === "queued").length;
|
|
1556
|
+
const made = out.body.results.filter((r) => r?.outcome === "created");
|
|
1557
|
+
stats.created += made.length;
|
|
1558
|
+
const submissions = [];
|
|
1559
|
+
const filesByKey = /* @__PURE__ */ new Map();
|
|
1560
|
+
for (const r of made) {
|
|
1561
|
+
const pending = typeof r.id === "string" && r.id !== "" && typeof r.key?.value === "string" ? held.get(keyId(r.key)) : void 0;
|
|
1562
|
+
if (pending === void 0) continue;
|
|
1563
|
+
for (const key of pending.keys) held.delete(keyId(key));
|
|
1564
|
+
const { keys: _keys, files: files2, ...rest } = pending;
|
|
1565
|
+
submissions.push({ ...rest, testCaseId: r.id });
|
|
1566
|
+
if (files2 !== void 0) filesByKey.set(pending.resultKey, files2);
|
|
1567
|
+
const text = snapshotByKey.get(pending.resultKey);
|
|
1568
|
+
if (text !== void 0) snapshots.set(r.id, text);
|
|
1569
|
+
}
|
|
1570
|
+
if (submissions.length > 0) {
|
|
1571
|
+
const before = stats.deferred;
|
|
1572
|
+
await send(submissions, filesByKey);
|
|
1573
|
+
createdWithResult += submissions.length;
|
|
1574
|
+
createdUndelivered += stats.deferred - before;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
async function syncSnapshots() {
|
|
1579
|
+
if (snapshots.size === 0 || offline) return;
|
|
1580
|
+
const stored = /* @__PURE__ */ new Map();
|
|
1581
|
+
let cursor = null;
|
|
1582
|
+
do {
|
|
1583
|
+
const query = `type=automated&stability=0&limit=200${cursor === null ? "" : `&cursor=${encodeURIComponent(cursor)}`}`;
|
|
1584
|
+
const out = await client.get(`/v1/test-cases?${query}`);
|
|
1585
|
+
if (!out.ok || !Array.isArray(out.body?.testCases)) {
|
|
1586
|
+
log(`plune: could not update the code snapshots (${out.ok ? "the case list had no cases" : out.detail || out.kind}).`);
|
|
1587
|
+
return;
|
|
1588
|
+
}
|
|
1589
|
+
for (const row of out.body.testCases) {
|
|
1590
|
+
if (typeof row?.id === "string" && snapshots.has(row.id)) stored.set(row.id, row.codeSnapshotHash ?? null);
|
|
1591
|
+
}
|
|
1592
|
+
cursor = typeof out.body.nextCursor === "string" ? out.body.nextCursor : null;
|
|
1593
|
+
} while (cursor !== null && stored.size < snapshots.size);
|
|
1594
|
+
const sha = (text) => (0, import_crypto.createHash)("sha256").update(text).digest("hex");
|
|
1595
|
+
const due = [...snapshots].filter(([id, text]) => stored.has(id) && stored.get(id) !== sha(text)).sort(([a], [b]) => sha(`${runId}:${a}`).localeCompare(sha(`${runId}:${b}`)));
|
|
1596
|
+
let updated = 0;
|
|
1597
|
+
let refused = 0;
|
|
1598
|
+
let tried = 0;
|
|
1599
|
+
for (const [id, text] of due.slice(0, SNAPSHOT_UPDATES_MAX)) {
|
|
1600
|
+
tried += 1;
|
|
1601
|
+
const out = await client.patch(`/v1/test-cases/${encodeURIComponent(id)}`, { codeSnapshot: text });
|
|
1602
|
+
if (out.ok) {
|
|
1603
|
+
updated += 1;
|
|
1604
|
+
continue;
|
|
1605
|
+
}
|
|
1606
|
+
if (out.kind === "auth" || out.kind === "unavailable" || out.status === 429) {
|
|
1607
|
+
log(`plune: could not update the code snapshot of test case ${id} (${out.detail || out.kind}); the rest are left as they are.`);
|
|
1608
|
+
break;
|
|
1609
|
+
}
|
|
1610
|
+
refused += 1;
|
|
1611
|
+
}
|
|
1612
|
+
const left = due.length - tried;
|
|
1613
|
+
const parts = [`${updated} code snapshot(s) updated`];
|
|
1614
|
+
if (refused > 0) parts.push(`${refused} not updated`);
|
|
1615
|
+
if (left > 0 && tried === Math.min(due.length, SNAPSHOT_UPDATES_MAX)) parts.push(`${left} left for the next run`);
|
|
1616
|
+
if (updated + refused > 0) log(`plune: ${parts.join(", ")}`);
|
|
1617
|
+
}
|
|
1370
1618
|
const sending = /* @__PURE__ */ new Set();
|
|
1371
1619
|
let sendError;
|
|
1372
1620
|
let answered = false;
|
|
@@ -1407,9 +1655,11 @@ async function startRun(passed, declared2) {
|
|
|
1407
1655
|
for (const result of pending) {
|
|
1408
1656
|
const match = matchFor(result);
|
|
1409
1657
|
if (match.kind === "found") {
|
|
1410
|
-
const { keys: _keys, files, ...rest } = result;
|
|
1658
|
+
const { keys: _keys, files: files2, ...rest } = result;
|
|
1411
1659
|
submissions.push({ ...rest, testCaseId: match.testCaseId });
|
|
1412
|
-
|
|
1660
|
+
const text = snapshotByKey.get(result.resultKey);
|
|
1661
|
+
if (text !== void 0) snapshots.set(match.testCaseId, text);
|
|
1662
|
+
if (files2 !== void 0) filesByKey.set(result.resultKey, files2);
|
|
1413
1663
|
} else if (match.kind === "unmatched") {
|
|
1414
1664
|
stats.unresolved += 1;
|
|
1415
1665
|
remember(result);
|
|
@@ -1425,22 +1675,30 @@ async function startRun(passed, declared2) {
|
|
|
1425
1675
|
await send(submissions, filesByKey);
|
|
1426
1676
|
}
|
|
1427
1677
|
async function send(submissions, filesByKey) {
|
|
1428
|
-
for (const
|
|
1678
|
+
for (const packedPart of packed(submissions)) {
|
|
1679
|
+
let part = targetsRefused ? packedPart.map(withoutTargets) : packedPart;
|
|
1429
1680
|
if (offline) {
|
|
1430
1681
|
defer(part);
|
|
1431
1682
|
continue;
|
|
1432
1683
|
}
|
|
1433
|
-
const
|
|
1684
|
+
const post = (results) => client.post(
|
|
1434
1685
|
`/v1/runs/${runId}/results`,
|
|
1435
|
-
// The job's combination on every batch
|
|
1436
|
-
{ results
|
|
1686
|
+
// The job's combination on every batch; a refusal of it is a 422 said below as it came.
|
|
1687
|
+
{ results, ...configuration !== void 0 ? { configuration } : {} }
|
|
1437
1688
|
);
|
|
1689
|
+
let out = await post(part);
|
|
1690
|
+
if (!out.ok && out.kind === "invalid" && out.status === 400 && part.some((r) => r.targets !== void 0)) {
|
|
1691
|
+
if (!targetsRefused) log("plune: the platform does not take targets on a result yet \u2014 the results are sent without them.");
|
|
1692
|
+
targetsRefused = true;
|
|
1693
|
+
part = part.map(withoutTargets);
|
|
1694
|
+
out = await post(part);
|
|
1695
|
+
}
|
|
1438
1696
|
const counts = out.ok ? out.body?.counts : void 0;
|
|
1439
1697
|
const told = COUNTED.filter((k) => typeof counts?.[k] === "number");
|
|
1440
1698
|
if (told.length > 0) {
|
|
1441
1699
|
for (const k of told) stats[k] += counts[k];
|
|
1442
1700
|
progress();
|
|
1443
|
-
await upload(out.ok ? out.body?.items : void 0, filesByKey);
|
|
1701
|
+
await files.upload(out.ok ? out.body?.items : void 0, filesByKey);
|
|
1444
1702
|
answered = true;
|
|
1445
1703
|
continue;
|
|
1446
1704
|
}
|
|
@@ -1476,10 +1734,10 @@ async function startRun(passed, declared2) {
|
|
|
1476
1734
|
}
|
|
1477
1735
|
const kinds = [stats.screenshots, stats.textFiles, stats.otherFiles];
|
|
1478
1736
|
const sum = (what) => kinds.reduce((n, counts) => n + counts[what], 0);
|
|
1479
|
-
if (bucketSeen) {
|
|
1480
|
-
const other = sum("skipped") - noStorage;
|
|
1737
|
+
if (files.bucketSeen) {
|
|
1738
|
+
const other = sum("skipped") - files.noStorage;
|
|
1481
1739
|
parts.push(
|
|
1482
|
-
`${sum("uploaded")} file(s) uploaded to your bucket` + (noStorage > 0 ? `, ${noStorage} skipped (no bucket connected)` : "") + (other > 0 ? `, ${other} skipped` : "") + (sum("failed") > 0 ? `, ${sum("failed")} failed to upload` : "")
|
|
1740
|
+
`${sum("uploaded")} file(s) uploaded to your bucket` + (files.noStorage > 0 ? `, ${files.noStorage} skipped (no bucket connected)` : "") + (other > 0 ? `, ${other} skipped` : "") + (sum("failed") > 0 ? `, ${sum("failed")} failed to upload` : "")
|
|
1483
1741
|
);
|
|
1484
1742
|
} else {
|
|
1485
1743
|
for (const said of [tally(stats.screenshots, "screenshot"), tally(stats.textFiles, "text file")]) {
|
|
@@ -1491,11 +1749,10 @@ async function startRun(passed, declared2) {
|
|
|
1491
1749
|
}
|
|
1492
1750
|
if (stats.deferred > 0) parts.push(`${stats.deferred} not delivered \u2014 written to ${fallbackPath}`);
|
|
1493
1751
|
if (shortened.size > 0) parts.push(`${shortened.size} test name(s) shortened to fit a key`);
|
|
1494
|
-
const
|
|
1495
|
-
|
|
1496
|
-
if (total("uploaded") + total("skipped") + total("failed") + existed > 0) {
|
|
1752
|
+
const total = (what) => kinds.reduce((n, counts) => n + counts[what], 0);
|
|
1753
|
+
if (total("uploaded") + total("skipped") + total("failed") + files.existed > 0) {
|
|
1497
1754
|
log(
|
|
1498
|
-
`plune: files \u2014 ${total("uploaded")} uploaded, ${total("skipped")} skipped, ${existed} already there (skipped), ${retried} retried, ${total("failed")} dropped, in ${(uploadMs / 1e3).toFixed(1)} s (${uploadsAtOnce} at once, ${requests} request(s) to Plune)`
|
|
1755
|
+
`plune: files \u2014 ${total("uploaded")} uploaded, ${total("skipped")} skipped, ${files.existed} already there (skipped), ${files.retried} retried, ${total("failed")} dropped, in ${(files.uploadMs / 1e3).toFixed(1)} s (${uploadsAtOnce} at once, ${files.requests} request(s) to Plune)`
|
|
1499
1756
|
);
|
|
1500
1757
|
}
|
|
1501
1758
|
log(`plune: ${parts.join(" \xB7 ")}`);
|
|
@@ -1515,7 +1772,10 @@ async function startRun(passed, declared2) {
|
|
|
1515
1772
|
return stats;
|
|
1516
1773
|
},
|
|
1517
1774
|
async add(result) {
|
|
1518
|
-
|
|
1775
|
+
const { codeAt, ...rest } = result;
|
|
1776
|
+
const text = codeAt === void 0 ? void 0 : snapshotAt(codeAt, specFiles);
|
|
1777
|
+
if (text !== void 0) snapshotByKey.set(result.resultKey, text);
|
|
1778
|
+
buffer.push({ ...rest, keys: bound(result.keys) });
|
|
1519
1779
|
if (buffer.length >= batchSize) await flushBuffer();
|
|
1520
1780
|
},
|
|
1521
1781
|
flush,
|
|
@@ -1524,6 +1784,7 @@ async function startRun(passed, declared2) {
|
|
|
1524
1784
|
done = true;
|
|
1525
1785
|
await flush();
|
|
1526
1786
|
await offer();
|
|
1787
|
+
await syncSnapshots();
|
|
1527
1788
|
let frozen;
|
|
1528
1789
|
if (runId !== null && !offline) {
|
|
1529
1790
|
const out = await client.post(`/v1/runs/${runId}/events`, {
|
|
@@ -1547,6 +1808,7 @@ async function startRun(passed, declared2) {
|
|
|
1547
1808
|
done = true;
|
|
1548
1809
|
await flush();
|
|
1549
1810
|
await offer();
|
|
1811
|
+
await syncSnapshots();
|
|
1550
1812
|
let frozen;
|
|
1551
1813
|
const after = [];
|
|
1552
1814
|
const shard = env.shard;
|
|
@@ -1678,7 +1940,7 @@ function attemptOf(test, result, ctx) {
|
|
|
1678
1940
|
name,
|
|
1679
1941
|
contentType,
|
|
1680
1942
|
...path3 !== void 0 ? { path: path3 } : {},
|
|
1681
|
-
// What a test attached from memory has no file: the bytes are the reporter's only copy
|
|
1943
|
+
// What a test attached from memory has no file: the bytes are the reporter's only copy.
|
|
1682
1944
|
...body !== void 0 ? { body } : {}
|
|
1683
1945
|
})),
|
|
1684
1946
|
...ctx.buildHref !== void 0 ? { buildHref: ctx.buildHref } : {},
|
|
@@ -1705,13 +1967,15 @@ function pendingFrom(test, result, ctx, ids = {}) {
|
|
|
1705
1967
|
// Anything the test named itself comes before what we derived from its location: a Qase or
|
|
1706
1968
|
// TestRail id written by a fixture is a deliberate statement, and a file path is a guess.
|
|
1707
1969
|
keys: [...metadata?.keys ?? [], ...keysFor(test)],
|
|
1708
|
-
// Read only if nothing resolves this test, and then it is what the review queue shows
|
|
1970
|
+
// Read only if nothing resolves this test, and then it is what the review queue shows.
|
|
1709
1971
|
// The full `describe > title` path rather than `test.title` alone: two suites in one file
|
|
1710
1972
|
// routinely share a title, and "adds an item" on its own is not something a person can judge.
|
|
1711
1973
|
title: titlesOf(test).join(" \u203A "),
|
|
1712
1974
|
// The line as well as the file. A reviewer's first move on an unknown test is to open it, and
|
|
1713
1975
|
// `specRef` is the only thing the entry carries that can take them there.
|
|
1714
1976
|
specRef: `${fileOf2(test)}:${test.location.line}`,
|
|
1977
|
+
// Where the core reads the test's text for its case's code snapshot; never sent as it is.
|
|
1978
|
+
codeAt: { file: test.location.file, line: test.location.line, column: test.location.column },
|
|
1715
1979
|
source: SOURCE,
|
|
1716
1980
|
// The runner's own word, untouched. Mapping it is the platform's job and a project's setting.
|
|
1717
1981
|
rawStatus: result.status,
|
|
@@ -1785,7 +2049,7 @@ var PluneReporter = class {
|
|
|
1785
2049
|
...this.options.externalKey !== void 0 ? { externalKey: this.options.externalKey } : {},
|
|
1786
2050
|
...this.options.batchSize !== void 0 ? { batchSize: this.options.batchSize } : {},
|
|
1787
2051
|
...this.options.fallbackPath !== void 0 ? { fallbackPath: this.options.fallbackPath } : {},
|
|
1788
|
-
// Where it ran
|
|
2052
|
+
// Where it ran: the commit Playwright wrote into `metadata.ci`, and its branch —
|
|
1789
2053
|
// which Playwright gives on GitLab and Jenkins, and the core reads from the job on GitHub.
|
|
1790
2054
|
meta: { runner: SOURCE, ...ciUrl !== void 0 ? { ciUrl } : {}, ...ciCommit(ci) }
|
|
1791
2055
|
},
|