@plune-ai/cli 0.37.0 → 0.39.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 +53 -13
- package/THIRD_PARTY_NOTICES +229 -0
- package/dist/cli.cjs +28785 -10697
- package/dist/index.cjs +3461 -252
- package/dist/index.d.cts +63 -9
- package/dist/index.d.ts +63 -9
- package/dist/index.js +3461 -252
- package/dist/mcp-tools.cjs +10 -10
- package/dist/mcp-tools.d.cts +7 -7
- package/dist/mcp-tools.d.ts +7 -7
- package/dist/mcp-tools.js +10 -10
- package/dist/reporter-core.cjs +264 -236
- package/dist/reporter-core.d.cts +111 -112
- package/dist/reporter-core.d.ts +111 -112
- package/dist/reporter-core.js +264 -236
- package/package.json +1 -1
- package/skills/qa-mission/SKILL.md +141 -58
- package/skills/qa-mission/references/tool-calls.md +40 -0
package/dist/reporter-core.cjs
CHANGED
|
@@ -760,68 +760,14 @@ function chunk(items, size) {
|
|
|
760
760
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
761
761
|
return out;
|
|
762
762
|
}
|
|
763
|
-
function
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
if (names.some((name) => run[name] != null)) return;
|
|
767
|
-
log(
|
|
768
|
-
`plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
|
|
769
|
-
);
|
|
770
|
-
}
|
|
771
|
-
async function startRun(passed, declared) {
|
|
772
|
-
const env = readEnv();
|
|
773
|
-
if (env.shardError !== void 0) throw new Error(env.shardError);
|
|
774
|
-
if (env.configurationError !== void 0 && passed.configuration === void 0) throw new Error(env.configurationError);
|
|
775
|
-
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
776
|
-
const cfg = { ...env.config, ...stated };
|
|
777
|
-
const configuration = cfg.configuration !== void 0 && Object.keys(cfg.configuration).length > 0 ? cfg.configuration : void 0;
|
|
778
|
-
const log = cfg.log ?? ((line) => void process.stderr.write(`${line}
|
|
779
|
-
`));
|
|
780
|
-
const fallbackPath = cfg.fallbackPath ?? DEFAULT_FALLBACK_PATH;
|
|
781
|
-
const externalKey = cfg.externalKey ?? null;
|
|
782
|
-
const sessionMarker = (0, import_node_crypto2.randomUUID)();
|
|
783
|
-
const batchSize = Math.min(cfg.batchSize ?? BATCH_DEFAULT, BATCH_MAX);
|
|
784
|
-
const offerDiscovered = cfg.offerDiscovered ?? false;
|
|
785
|
-
const token = cfg.token ?? loadToken() ?? "";
|
|
786
|
-
const uploadsAtOnce = Math.min(Math.max(Math.floor(cfg.uploadConcurrency ?? UPLOAD_CONCURRENCY.default), UPLOAD_CONCURRENCY.min), UPLOAD_CONCURRENCY.max);
|
|
787
|
-
const uploadRetries = Math.min(Math.max(Math.floor(cfg.uploadRetries ?? UPLOAD_RETRIES.default), UPLOAD_RETRIES.min), UPLOAD_RETRIES.max);
|
|
763
|
+
function fileSender(options) {
|
|
764
|
+
const { client, log, stats, uploadsAtOnce, uploadRetries } = options;
|
|
765
|
+
const without = options.without ?? "its result is reported without it";
|
|
788
766
|
let retried = 0;
|
|
789
767
|
let uploadMs = 0;
|
|
790
768
|
let requests = 0;
|
|
791
769
|
let existed = 0;
|
|
792
770
|
let batchMissing = false;
|
|
793
|
-
const client = createClient({
|
|
794
|
-
apiUrl: resolveApiUrl(cfg.apiUrl),
|
|
795
|
-
token,
|
|
796
|
-
uploadRetries,
|
|
797
|
-
onRetry: () => void (retried += 1),
|
|
798
|
-
...cfg.fetchImpl !== void 0 ? { fetchImpl: cfg.fetchImpl } : {}
|
|
799
|
-
});
|
|
800
|
-
const stats = {
|
|
801
|
-
accepted: 0,
|
|
802
|
-
duplicate: 0,
|
|
803
|
-
conflict: 0,
|
|
804
|
-
rejected: 0,
|
|
805
|
-
unresolved: 0,
|
|
806
|
-
offered: 0,
|
|
807
|
-
created: 0,
|
|
808
|
-
unoffered: 0,
|
|
809
|
-
deferred: 0,
|
|
810
|
-
screenshots: { uploaded: 0, skipped: 0, failed: 0 },
|
|
811
|
-
textFiles: { uploaded: 0, skipped: 0, failed: 0 },
|
|
812
|
-
otherFiles: { uploaded: 0, skipped: 0, failed: 0 }
|
|
813
|
-
};
|
|
814
|
-
const resolved = /* @__PURE__ */ new Map();
|
|
815
|
-
let buffer = [];
|
|
816
|
-
const discoveries = /* @__PURE__ */ new Map();
|
|
817
|
-
const held = /* @__PURE__ */ new Map();
|
|
818
|
-
let createdWithResult = 0;
|
|
819
|
-
let createdUndelivered = 0;
|
|
820
|
-
let runId = null;
|
|
821
|
-
let joined = false;
|
|
822
|
-
let offline = token === "";
|
|
823
|
-
let done = false;
|
|
824
|
-
const shortened = /* @__PURE__ */ new Set();
|
|
825
771
|
const skipsSaid = /* @__PURE__ */ new Set();
|
|
826
772
|
const countsOf = (kind) => kind === "text" ? stats.textFiles : kind === "file" ? stats.otherFiles : stats.screenshots;
|
|
827
773
|
let bucketSeen = false;
|
|
@@ -830,168 +776,6 @@ async function startRun(passed, declared) {
|
|
|
830
776
|
const failedSaid = /* @__PURE__ */ new Set();
|
|
831
777
|
const codesSaid = /* @__PURE__ */ new Set();
|
|
832
778
|
const rooms = /* @__PURE__ */ new Map();
|
|
833
|
-
function bound(keys) {
|
|
834
|
-
return keys.map((key) => {
|
|
835
|
-
const fit = boundKey(key);
|
|
836
|
-
if (fit !== key && !shortened.has(key.value)) {
|
|
837
|
-
shortened.add(key.value);
|
|
838
|
-
if (shortened.size === 1) {
|
|
839
|
-
log(
|
|
840
|
-
`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.`
|
|
841
|
-
);
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
return fit;
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
const expected = declared?.map(bound);
|
|
848
|
-
if (offline) {
|
|
849
|
-
log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
|
|
850
|
-
}
|
|
851
|
-
for (const warning of env.warnings) log(`plune: ${warning}`);
|
|
852
|
-
if (env.ignored.length > 0) {
|
|
853
|
-
log(`plune: ignoring ${env.ignored.join(", ")} \u2014 a run has nowhere to store them yet.`);
|
|
854
|
-
}
|
|
855
|
-
function defer(results) {
|
|
856
|
-
appendBatch(fallbackPath, {
|
|
857
|
-
runId,
|
|
858
|
-
externalKey,
|
|
859
|
-
session: sessionMarker,
|
|
860
|
-
...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
|
|
861
|
-
...configuration !== void 0 ? { configuration } : {},
|
|
862
|
-
results: results.map(onDisk)
|
|
863
|
-
});
|
|
864
|
-
stats.deferred += results.length;
|
|
865
|
-
}
|
|
866
|
-
async function resolveKeys(values) {
|
|
867
|
-
const unknown = values.filter((k) => !resolved.has(keyId(k)));
|
|
868
|
-
if (unknown.length === 0 || offline) return;
|
|
869
|
-
for (const part of chunk(unknown, RESOLVE_CHUNK)) {
|
|
870
|
-
const out = await client.post(
|
|
871
|
-
"/v1/test-cases/resolve",
|
|
872
|
-
{ keys: part }
|
|
873
|
-
);
|
|
874
|
-
if (!out.ok || !Array.isArray(out.body?.results)) {
|
|
875
|
-
log(`plune: could not look up test cases (${out.ok ? "the answer had no results" : out.detail || out.kind}).`);
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
for (const row of out.body.results) {
|
|
879
|
-
if (typeof row?.key?.value === "string") resolved.set(keyId(row.key), row.testCaseId);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
if (!offline) {
|
|
884
|
-
if (expected !== void 0) await resolveKeys(expected.flat());
|
|
885
|
-
const stated2 = expected?.slice(0, EXPECTED_MAX) ?? [];
|
|
886
|
-
const configuration2 = stated2.length === 0 ? void 0 : {
|
|
887
|
-
expected: stated2.flatMap((keys) => {
|
|
888
|
-
const hit = keys.map((k) => resolved.get(keyId(k))).find((v) => typeof v === "string");
|
|
889
|
-
if (typeof hit === "string") return [{ testCaseId: hit }];
|
|
890
|
-
return keys[0] === void 0 ? [] : [{ externalKey: keys[0] }];
|
|
891
|
-
}),
|
|
892
|
-
// The claim travels with the list it is about (D20). A runner that could not enumerate
|
|
893
|
-
// its tests has no list, and a claim without one is nothing the platform can check —
|
|
894
|
-
// so it is not sent, rather than sent and silently meaningless.
|
|
895
|
-
...cfg.full === true ? { full: true } : {}
|
|
896
|
-
};
|
|
897
|
-
if (expected !== void 0 && expected.length > EXPECTED_MAX) {
|
|
898
|
-
log(`plune: ${expected.length} tests is more than the run configuration holds \u2014 reporting the first ${EXPECTED_MAX}.`);
|
|
899
|
-
}
|
|
900
|
-
const described = {
|
|
901
|
-
...cfg.title !== void 0 ? { title: cfg.title } : {},
|
|
902
|
-
...cfg.environment !== void 0 ? { environment: cfg.environment } : {},
|
|
903
|
-
...cfg.labels !== void 0 ? { labels: cfg.labels } : {}
|
|
904
|
-
};
|
|
905
|
-
const request = {
|
|
906
|
-
schemaVersion: 2,
|
|
907
|
-
kind: cfg.kind ?? "automated",
|
|
908
|
-
...externalKey !== null ? { externalKey } : {},
|
|
909
|
-
...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
|
|
910
|
-
...configuration2 !== void 0 ? { configuration: configuration2 } : {},
|
|
911
|
-
// Named even when nobody named it — the list has to read without opening a row. Only what
|
|
912
|
-
// the caller DESCRIBED goes to `warnIfDropped` below: a title this side invented is not one
|
|
913
|
-
// a person will miss, and a deployment older than the field must not be nagged on every run.
|
|
914
|
-
title: defaultRunTitle(),
|
|
915
|
-
...described
|
|
916
|
-
};
|
|
917
|
-
let start = await client.post("/v1/runs", request);
|
|
918
|
-
if (!start.ok && start.status === 413 && configuration2 !== void 0) {
|
|
919
|
-
log(
|
|
920
|
-
`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.`
|
|
921
|
-
);
|
|
922
|
-
start = await client.post("/v1/runs", { ...request, configuration: void 0 });
|
|
923
|
-
}
|
|
924
|
-
if (start.ok && typeof start.body?.run?.id === "string") {
|
|
925
|
-
runId = start.body.run.id;
|
|
926
|
-
joined = start.status === 200;
|
|
927
|
-
warnIfDropped(described, start.body.run, log);
|
|
928
|
-
} else {
|
|
929
|
-
const why = start.ok ? "the answer had no run" : start.detail || start.kind;
|
|
930
|
-
log(`plune: could not start the run (${why}). Results will be written to ${fallbackPath}.`);
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
function matchFor(result) {
|
|
934
|
-
if (result.testCaseId !== void 0) return { kind: "found", testCaseId: result.testCaseId };
|
|
935
|
-
let unanswered = false;
|
|
936
|
-
for (const key of result.keys) {
|
|
937
|
-
const hit = resolved.get(keyId(key));
|
|
938
|
-
if (typeof hit === "string") return { kind: "found", testCaseId: hit };
|
|
939
|
-
if (hit === void 0) unanswered = true;
|
|
940
|
-
}
|
|
941
|
-
return unanswered ? { kind: "unanswered" } : { kind: "unmatched" };
|
|
942
|
-
}
|
|
943
|
-
function remember(result) {
|
|
944
|
-
if (!offerDiscovered) return;
|
|
945
|
-
if (result.title === void 0 || result.specRef === void 0) return;
|
|
946
|
-
if (result.keys.length === 0) return;
|
|
947
|
-
const title = boundTitle(result.title);
|
|
948
|
-
if (title !== result.title) shortened.add(result.title);
|
|
949
|
-
discoveries.set(keyId(result.keys[0]), {
|
|
950
|
-
keys: result.keys,
|
|
951
|
-
title,
|
|
952
|
-
source: result.source,
|
|
953
|
-
specRef: result.specRef,
|
|
954
|
-
rawStatus: result.rawStatus
|
|
955
|
-
});
|
|
956
|
-
for (const key of result.keys) held.set(keyId(key), result);
|
|
957
|
-
}
|
|
958
|
-
async function offer() {
|
|
959
|
-
if (discoveries.size === 0 || offline || runId === null) return;
|
|
960
|
-
const batches = chunk([...discoveries.values()], DISCOVER_MAX);
|
|
961
|
-
for (const [index, batch] of batches.entries()) {
|
|
962
|
-
const out = await client.post("/v1/review-items/discovered", {
|
|
963
|
-
discovered: batch,
|
|
964
|
-
runId
|
|
965
|
-
});
|
|
966
|
-
if (!out.ok || !Array.isArray(out.body?.results)) {
|
|
967
|
-
stats.unoffered = batches.slice(index).reduce((n, rest) => n + rest.length, 0);
|
|
968
|
-
stats.unofferedWhy = whyUnoffered(out);
|
|
969
|
-
log(
|
|
970
|
-
`plune: could not offer ${stats.unoffered} unknown test(s) for review (${out.ok ? "the answer had no results" : out.detail || out.kind}).`
|
|
971
|
-
);
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
|
-
stats.offered += out.body.results.filter((r) => r?.outcome === "queued").length;
|
|
975
|
-
const made = out.body.results.filter((r) => r?.outcome === "created");
|
|
976
|
-
stats.created += made.length;
|
|
977
|
-
const submissions = [];
|
|
978
|
-
const filesByKey = /* @__PURE__ */ new Map();
|
|
979
|
-
for (const r of made) {
|
|
980
|
-
const pending = typeof r.id === "string" && r.id !== "" && typeof r.key?.value === "string" ? held.get(keyId(r.key)) : void 0;
|
|
981
|
-
if (pending === void 0) continue;
|
|
982
|
-
for (const key of pending.keys) held.delete(keyId(key));
|
|
983
|
-
const { keys: _keys, files, ...rest } = pending;
|
|
984
|
-
submissions.push({ ...rest, testCaseId: r.id });
|
|
985
|
-
if (files !== void 0) filesByKey.set(pending.resultKey, files);
|
|
986
|
-
}
|
|
987
|
-
if (submissions.length > 0) {
|
|
988
|
-
const before = stats.deferred;
|
|
989
|
-
await send(submissions, filesByKey);
|
|
990
|
-
createdWithResult += submissions.length;
|
|
991
|
-
createdUndelivered += stats.deferred - before;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
779
|
function skip(kind, name, why) {
|
|
996
780
|
countsOf(kind).skipped += 1;
|
|
997
781
|
if (why === "noStorage") noStorage += 1;
|
|
@@ -1001,9 +785,10 @@ async function startRun(passed, declared) {
|
|
|
1001
785
|
if (why === "noStorage") log(`plune: "${name}" not stored \u2014 ${SKIPPED[why]}.`);
|
|
1002
786
|
else log(`plune: ${KINDS[kind].label} "${name}" not uploaded \u2014 ${SKIPPED[why]}.`);
|
|
1003
787
|
}
|
|
788
|
+
const filesOf2 = (job) => `/v1/${job.owner ?? "results"}/${encodeURIComponent(job.id)}/files`;
|
|
1004
789
|
function ask(job, size) {
|
|
1005
790
|
requests += 1;
|
|
1006
|
-
return client.post(
|
|
791
|
+
return client.post(`${filesOf2(job)}/uploads`, {
|
|
1007
792
|
files: [{ name: job.name, contentType: job.type, size }]
|
|
1008
793
|
}, uploadRetries);
|
|
1009
794
|
}
|
|
@@ -1011,14 +796,14 @@ async function startRun(passed, declared) {
|
|
|
1011
796
|
countsOf(job.kind).failed += 1;
|
|
1012
797
|
if (!failedSaid.has(job.kind)) {
|
|
1013
798
|
failedSaid.add(job.kind);
|
|
1014
|
-
log(`plune: could not upload a ${KINDS[job.kind].label} (${why}) \u2014
|
|
799
|
+
log(`plune: could not upload a ${KINDS[job.kind].label} (${why}) \u2014 ${without}.`);
|
|
1015
800
|
}
|
|
1016
801
|
}
|
|
1017
802
|
function failedToBucket(job, code) {
|
|
1018
803
|
countsOf(job.kind).failed += 1;
|
|
1019
804
|
if (codesSaid.has(code)) return;
|
|
1020
805
|
codesSaid.add(code);
|
|
1021
|
-
log(`plune: "${job.name}" not uploaded to your bucket (${code}) \u2014
|
|
806
|
+
log(`plune: "${job.name}" not uploaded to your bucket (${code}) \u2014 ${without}.`);
|
|
1022
807
|
}
|
|
1023
808
|
function refusedHere(job, size) {
|
|
1024
809
|
if (job.kind === "screenshot") {
|
|
@@ -1046,7 +831,7 @@ async function startRun(passed, declared) {
|
|
|
1046
831
|
if (refusal !== void 0) return skip(kind, job.name, refusal);
|
|
1047
832
|
requests += 1;
|
|
1048
833
|
const out = await client.upload(
|
|
1049
|
-
|
|
834
|
+
`${filesOf2(job)}?name=${encodeURIComponent(job.name)}`,
|
|
1050
835
|
bytes,
|
|
1051
836
|
job.type
|
|
1052
837
|
);
|
|
@@ -1068,8 +853,8 @@ async function startRun(passed, declared) {
|
|
|
1068
853
|
link = fresh;
|
|
1069
854
|
}
|
|
1070
855
|
requests += 1;
|
|
1071
|
-
const
|
|
1072
|
-
if (!
|
|
856
|
+
const done = await client.post(`/v1/files/${encodeURIComponent(link.id)}/complete`, {}, uploadRetries);
|
|
857
|
+
if (!done.ok) return failedToBucket(job, codeOf(done));
|
|
1073
858
|
countsOf(job.kind).uploaded += 1;
|
|
1074
859
|
}
|
|
1075
860
|
let free = uploadsAtOnce;
|
|
@@ -1396,6 +1181,250 @@ async function startRun(passed, declared) {
|
|
|
1396
1181
|
else await uploadBatched(jobs);
|
|
1397
1182
|
uploadMs += Date.now() - started;
|
|
1398
1183
|
}
|
|
1184
|
+
return {
|
|
1185
|
+
upload,
|
|
1186
|
+
uploadEach,
|
|
1187
|
+
onRetry: () => void (retried += 1),
|
|
1188
|
+
get bucketSeen() {
|
|
1189
|
+
return bucketSeen;
|
|
1190
|
+
},
|
|
1191
|
+
get noStorage() {
|
|
1192
|
+
return noStorage;
|
|
1193
|
+
},
|
|
1194
|
+
get existed() {
|
|
1195
|
+
return existed;
|
|
1196
|
+
},
|
|
1197
|
+
get retried() {
|
|
1198
|
+
return retried;
|
|
1199
|
+
},
|
|
1200
|
+
get uploadMs() {
|
|
1201
|
+
return uploadMs;
|
|
1202
|
+
},
|
|
1203
|
+
get requests() {
|
|
1204
|
+
return requests;
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
function warnIfDropped(sent, run, log) {
|
|
1209
|
+
const names = Object.keys(sent);
|
|
1210
|
+
if (names.length === 0) return;
|
|
1211
|
+
if (names.some((name) => run[name] != null)) return;
|
|
1212
|
+
log(
|
|
1213
|
+
`plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
async function startRun(passed, declared) {
|
|
1217
|
+
const env = readEnv();
|
|
1218
|
+
if (env.shardError !== void 0) throw new Error(env.shardError);
|
|
1219
|
+
if (env.configurationError !== void 0 && passed.configuration === void 0) throw new Error(env.configurationError);
|
|
1220
|
+
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
1221
|
+
const cfg = { ...env.config, ...stated };
|
|
1222
|
+
const configuration = cfg.configuration !== void 0 && Object.keys(cfg.configuration).length > 0 ? cfg.configuration : void 0;
|
|
1223
|
+
const log = cfg.log ?? ((line) => void process.stderr.write(`${line}
|
|
1224
|
+
`));
|
|
1225
|
+
const fallbackPath = cfg.fallbackPath ?? DEFAULT_FALLBACK_PATH;
|
|
1226
|
+
const externalKey = cfg.externalKey ?? null;
|
|
1227
|
+
const sessionMarker = (0, import_node_crypto2.randomUUID)();
|
|
1228
|
+
const batchSize = Math.min(cfg.batchSize ?? BATCH_DEFAULT, BATCH_MAX);
|
|
1229
|
+
const offerDiscovered = cfg.offerDiscovered ?? false;
|
|
1230
|
+
const token = cfg.token ?? loadToken() ?? "";
|
|
1231
|
+
const uploadsAtOnce = Math.min(Math.max(Math.floor(cfg.uploadConcurrency ?? UPLOAD_CONCURRENCY.default), UPLOAD_CONCURRENCY.min), UPLOAD_CONCURRENCY.max);
|
|
1232
|
+
const uploadRetries = Math.min(Math.max(Math.floor(cfg.uploadRetries ?? UPLOAD_RETRIES.default), UPLOAD_RETRIES.min), UPLOAD_RETRIES.max);
|
|
1233
|
+
const client = createClient({
|
|
1234
|
+
apiUrl: resolveApiUrl(cfg.apiUrl),
|
|
1235
|
+
token,
|
|
1236
|
+
uploadRetries,
|
|
1237
|
+
onRetry: () => files.onRetry(),
|
|
1238
|
+
...cfg.fetchImpl !== void 0 ? { fetchImpl: cfg.fetchImpl } : {}
|
|
1239
|
+
});
|
|
1240
|
+
const stats = {
|
|
1241
|
+
accepted: 0,
|
|
1242
|
+
duplicate: 0,
|
|
1243
|
+
conflict: 0,
|
|
1244
|
+
rejected: 0,
|
|
1245
|
+
unresolved: 0,
|
|
1246
|
+
offered: 0,
|
|
1247
|
+
created: 0,
|
|
1248
|
+
unoffered: 0,
|
|
1249
|
+
deferred: 0,
|
|
1250
|
+
screenshots: { uploaded: 0, skipped: 0, failed: 0 },
|
|
1251
|
+
textFiles: { uploaded: 0, skipped: 0, failed: 0 },
|
|
1252
|
+
otherFiles: { uploaded: 0, skipped: 0, failed: 0 }
|
|
1253
|
+
};
|
|
1254
|
+
const files = fileSender({ client, log, stats, uploadsAtOnce, uploadRetries });
|
|
1255
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
1256
|
+
let buffer = [];
|
|
1257
|
+
const discoveries = /* @__PURE__ */ new Map();
|
|
1258
|
+
const held = /* @__PURE__ */ new Map();
|
|
1259
|
+
let createdWithResult = 0;
|
|
1260
|
+
let createdUndelivered = 0;
|
|
1261
|
+
let runId = null;
|
|
1262
|
+
let joined = false;
|
|
1263
|
+
let offline = token === "";
|
|
1264
|
+
let done = false;
|
|
1265
|
+
const shortened = /* @__PURE__ */ new Set();
|
|
1266
|
+
function bound(keys) {
|
|
1267
|
+
return keys.map((key) => {
|
|
1268
|
+
const fit = boundKey(key);
|
|
1269
|
+
if (fit !== key && !shortened.has(key.value)) {
|
|
1270
|
+
shortened.add(key.value);
|
|
1271
|
+
if (shortened.size === 1) {
|
|
1272
|
+
log(
|
|
1273
|
+
`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.`
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
return fit;
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
const expected = declared?.map(bound);
|
|
1281
|
+
if (offline) {
|
|
1282
|
+
log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
|
|
1283
|
+
}
|
|
1284
|
+
for (const warning of env.warnings) log(`plune: ${warning}`);
|
|
1285
|
+
if (env.ignored.length > 0) {
|
|
1286
|
+
log(`plune: ignoring ${env.ignored.join(", ")} \u2014 a run has nowhere to store them yet.`);
|
|
1287
|
+
}
|
|
1288
|
+
function defer(results) {
|
|
1289
|
+
appendBatch(fallbackPath, {
|
|
1290
|
+
runId,
|
|
1291
|
+
externalKey,
|
|
1292
|
+
session: sessionMarker,
|
|
1293
|
+
...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
|
|
1294
|
+
...configuration !== void 0 ? { configuration } : {},
|
|
1295
|
+
results: results.map(onDisk)
|
|
1296
|
+
});
|
|
1297
|
+
stats.deferred += results.length;
|
|
1298
|
+
}
|
|
1299
|
+
async function resolveKeys(values) {
|
|
1300
|
+
const unknown = values.filter((k) => !resolved.has(keyId(k)));
|
|
1301
|
+
if (unknown.length === 0 || offline) return;
|
|
1302
|
+
for (const part of chunk(unknown, RESOLVE_CHUNK)) {
|
|
1303
|
+
const out = await client.post(
|
|
1304
|
+
"/v1/test-cases/resolve",
|
|
1305
|
+
{ keys: part }
|
|
1306
|
+
);
|
|
1307
|
+
if (!out.ok || !Array.isArray(out.body?.results)) {
|
|
1308
|
+
log(`plune: could not look up test cases (${out.ok ? "the answer had no results" : out.detail || out.kind}).`);
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
for (const row of out.body.results) {
|
|
1312
|
+
if (typeof row?.key?.value === "string") resolved.set(keyId(row.key), row.testCaseId);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
if (!offline) {
|
|
1317
|
+
if (expected !== void 0) await resolveKeys(expected.flat());
|
|
1318
|
+
const stated2 = expected?.slice(0, EXPECTED_MAX) ?? [];
|
|
1319
|
+
const configuration2 = stated2.length === 0 ? void 0 : {
|
|
1320
|
+
expected: stated2.flatMap((keys) => {
|
|
1321
|
+
const hit = keys.map((k) => resolved.get(keyId(k))).find((v) => typeof v === "string");
|
|
1322
|
+
if (typeof hit === "string") return [{ testCaseId: hit }];
|
|
1323
|
+
return keys[0] === void 0 ? [] : [{ externalKey: keys[0] }];
|
|
1324
|
+
}),
|
|
1325
|
+
// The claim travels with the list it is about. A runner that could not enumerate
|
|
1326
|
+
// its tests has no list, and a claim without one is nothing the platform can check —
|
|
1327
|
+
// so it is not sent, rather than sent and silently meaningless.
|
|
1328
|
+
...cfg.full === true ? { full: true } : {}
|
|
1329
|
+
};
|
|
1330
|
+
if (expected !== void 0 && expected.length > EXPECTED_MAX) {
|
|
1331
|
+
log(`plune: ${expected.length} tests is more than the run configuration holds \u2014 reporting the first ${EXPECTED_MAX}.`);
|
|
1332
|
+
}
|
|
1333
|
+
const described = {
|
|
1334
|
+
...cfg.title !== void 0 ? { title: cfg.title } : {},
|
|
1335
|
+
...cfg.environment !== void 0 ? { environment: cfg.environment } : {},
|
|
1336
|
+
...cfg.labels !== void 0 ? { labels: cfg.labels } : {}
|
|
1337
|
+
};
|
|
1338
|
+
const request = {
|
|
1339
|
+
schemaVersion: 2,
|
|
1340
|
+
kind: cfg.kind ?? "automated",
|
|
1341
|
+
...externalKey !== null ? { externalKey } : {},
|
|
1342
|
+
...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
|
|
1343
|
+
...configuration2 !== void 0 ? { configuration: configuration2 } : {},
|
|
1344
|
+
// Named even when nobody named it — the list has to read without opening a row. Only what
|
|
1345
|
+
// the caller DESCRIBED goes to `warnIfDropped` below: a title this side invented is not one
|
|
1346
|
+
// a person will miss, and a deployment older than the field must not be nagged on every run.
|
|
1347
|
+
title: defaultRunTitle(),
|
|
1348
|
+
...described
|
|
1349
|
+
};
|
|
1350
|
+
let start = await client.post("/v1/runs", request);
|
|
1351
|
+
if (!start.ok && start.status === 413 && configuration2 !== void 0) {
|
|
1352
|
+
log(
|
|
1353
|
+
`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.`
|
|
1354
|
+
);
|
|
1355
|
+
start = await client.post("/v1/runs", { ...request, configuration: void 0 });
|
|
1356
|
+
}
|
|
1357
|
+
if (start.ok && typeof start.body?.run?.id === "string") {
|
|
1358
|
+
runId = start.body.run.id;
|
|
1359
|
+
joined = start.status === 200;
|
|
1360
|
+
warnIfDropped(described, start.body.run, log);
|
|
1361
|
+
} else {
|
|
1362
|
+
const why = start.ok ? "the answer had no run" : start.detail || start.kind;
|
|
1363
|
+
log(`plune: could not start the run (${why}). Results will be written to ${fallbackPath}.`);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
function matchFor(result) {
|
|
1367
|
+
if (result.testCaseId !== void 0) return { kind: "found", testCaseId: result.testCaseId };
|
|
1368
|
+
let unanswered = false;
|
|
1369
|
+
for (const key of result.keys) {
|
|
1370
|
+
const hit = resolved.get(keyId(key));
|
|
1371
|
+
if (typeof hit === "string") return { kind: "found", testCaseId: hit };
|
|
1372
|
+
if (hit === void 0) unanswered = true;
|
|
1373
|
+
}
|
|
1374
|
+
return unanswered ? { kind: "unanswered" } : { kind: "unmatched" };
|
|
1375
|
+
}
|
|
1376
|
+
function remember(result) {
|
|
1377
|
+
if (!offerDiscovered) return;
|
|
1378
|
+
if (result.title === void 0 || result.specRef === void 0) return;
|
|
1379
|
+
if (result.keys.length === 0) return;
|
|
1380
|
+
const title = boundTitle(result.title);
|
|
1381
|
+
if (title !== result.title) shortened.add(result.title);
|
|
1382
|
+
discoveries.set(keyId(result.keys[0]), {
|
|
1383
|
+
keys: result.keys,
|
|
1384
|
+
title,
|
|
1385
|
+
source: result.source,
|
|
1386
|
+
specRef: result.specRef,
|
|
1387
|
+
rawStatus: result.rawStatus
|
|
1388
|
+
});
|
|
1389
|
+
for (const key of result.keys) held.set(keyId(key), result);
|
|
1390
|
+
}
|
|
1391
|
+
async function offer() {
|
|
1392
|
+
if (discoveries.size === 0 || offline || runId === null) return;
|
|
1393
|
+
const batches = chunk([...discoveries.values()], DISCOVER_MAX);
|
|
1394
|
+
for (const [index, batch] of batches.entries()) {
|
|
1395
|
+
const out = await client.post("/v1/review-items/discovered", {
|
|
1396
|
+
discovered: batch,
|
|
1397
|
+
runId
|
|
1398
|
+
});
|
|
1399
|
+
if (!out.ok || !Array.isArray(out.body?.results)) {
|
|
1400
|
+
stats.unoffered = batches.slice(index).reduce((n, rest) => n + rest.length, 0);
|
|
1401
|
+
stats.unofferedWhy = whyUnoffered(out);
|
|
1402
|
+
log(
|
|
1403
|
+
`plune: could not offer ${stats.unoffered} unknown test(s) for review (${out.ok ? "the answer had no results" : out.detail || out.kind}).`
|
|
1404
|
+
);
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
stats.offered += out.body.results.filter((r) => r?.outcome === "queued").length;
|
|
1408
|
+
const made = out.body.results.filter((r) => r?.outcome === "created");
|
|
1409
|
+
stats.created += made.length;
|
|
1410
|
+
const submissions = [];
|
|
1411
|
+
const filesByKey = /* @__PURE__ */ new Map();
|
|
1412
|
+
for (const r of made) {
|
|
1413
|
+
const pending = typeof r.id === "string" && r.id !== "" && typeof r.key?.value === "string" ? held.get(keyId(r.key)) : void 0;
|
|
1414
|
+
if (pending === void 0) continue;
|
|
1415
|
+
for (const key of pending.keys) held.delete(keyId(key));
|
|
1416
|
+
const { keys: _keys, files: files2, ...rest } = pending;
|
|
1417
|
+
submissions.push({ ...rest, testCaseId: r.id });
|
|
1418
|
+
if (files2 !== void 0) filesByKey.set(pending.resultKey, files2);
|
|
1419
|
+
}
|
|
1420
|
+
if (submissions.length > 0) {
|
|
1421
|
+
const before = stats.deferred;
|
|
1422
|
+
await send(submissions, filesByKey);
|
|
1423
|
+
createdWithResult += submissions.length;
|
|
1424
|
+
createdUndelivered += stats.deferred - before;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1399
1428
|
const sending = /* @__PURE__ */ new Set();
|
|
1400
1429
|
let sendError;
|
|
1401
1430
|
let answered = false;
|
|
@@ -1436,9 +1465,9 @@ async function startRun(passed, declared) {
|
|
|
1436
1465
|
for (const result of pending) {
|
|
1437
1466
|
const match = matchFor(result);
|
|
1438
1467
|
if (match.kind === "found") {
|
|
1439
|
-
const { keys: _keys, files, ...rest } = result;
|
|
1468
|
+
const { keys: _keys, files: files2, ...rest } = result;
|
|
1440
1469
|
submissions.push({ ...rest, testCaseId: match.testCaseId });
|
|
1441
|
-
if (
|
|
1470
|
+
if (files2 !== void 0) filesByKey.set(result.resultKey, files2);
|
|
1442
1471
|
} else if (match.kind === "unmatched") {
|
|
1443
1472
|
stats.unresolved += 1;
|
|
1444
1473
|
remember(result);
|
|
@@ -1461,7 +1490,7 @@ async function startRun(passed, declared) {
|
|
|
1461
1490
|
}
|
|
1462
1491
|
const out = await client.post(
|
|
1463
1492
|
`/v1/runs/${runId}/results`,
|
|
1464
|
-
// The job's combination on every batch
|
|
1493
|
+
// The job's combination on every batch; a refusal of it is a 422 said below as it came.
|
|
1465
1494
|
{ results: part, ...configuration !== void 0 ? { configuration } : {} }
|
|
1466
1495
|
);
|
|
1467
1496
|
const counts = out.ok ? out.body?.counts : void 0;
|
|
@@ -1469,7 +1498,7 @@ async function startRun(passed, declared) {
|
|
|
1469
1498
|
if (told.length > 0) {
|
|
1470
1499
|
for (const k of told) stats[k] += counts[k];
|
|
1471
1500
|
progress();
|
|
1472
|
-
await upload(out.ok ? out.body?.items : void 0, filesByKey);
|
|
1501
|
+
await files.upload(out.ok ? out.body?.items : void 0, filesByKey);
|
|
1473
1502
|
answered = true;
|
|
1474
1503
|
continue;
|
|
1475
1504
|
}
|
|
@@ -1505,10 +1534,10 @@ async function startRun(passed, declared) {
|
|
|
1505
1534
|
}
|
|
1506
1535
|
const kinds = [stats.screenshots, stats.textFiles, stats.otherFiles];
|
|
1507
1536
|
const sum = (what) => kinds.reduce((n, counts) => n + counts[what], 0);
|
|
1508
|
-
if (bucketSeen) {
|
|
1509
|
-
const other = sum("skipped") - noStorage;
|
|
1537
|
+
if (files.bucketSeen) {
|
|
1538
|
+
const other = sum("skipped") - files.noStorage;
|
|
1510
1539
|
parts.push(
|
|
1511
|
-
`${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` : "")
|
|
1540
|
+
`${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` : "")
|
|
1512
1541
|
);
|
|
1513
1542
|
} else {
|
|
1514
1543
|
for (const said of [tally(stats.screenshots, "screenshot"), tally(stats.textFiles, "text file")]) {
|
|
@@ -1520,11 +1549,10 @@ async function startRun(passed, declared) {
|
|
|
1520
1549
|
}
|
|
1521
1550
|
if (stats.deferred > 0) parts.push(`${stats.deferred} not delivered \u2014 written to ${fallbackPath}`);
|
|
1522
1551
|
if (shortened.size > 0) parts.push(`${shortened.size} test name(s) shortened to fit a key`);
|
|
1523
|
-
const
|
|
1524
|
-
|
|
1525
|
-
if (total("uploaded") + total("skipped") + total("failed") + existed > 0) {
|
|
1552
|
+
const total = (what) => kinds.reduce((n, counts) => n + counts[what], 0);
|
|
1553
|
+
if (total("uploaded") + total("skipped") + total("failed") + files.existed > 0) {
|
|
1526
1554
|
log(
|
|
1527
|
-
`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)`
|
|
1555
|
+
`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)`
|
|
1528
1556
|
);
|
|
1529
1557
|
}
|
|
1530
1558
|
log(`plune: ${parts.join(" \xB7 ")}`);
|