@plune-ai/cli 0.38.0 → 0.39.1

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.
@@ -710,68 +710,14 @@ function chunk(items, size) {
710
710
  for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
711
711
  return out;
712
712
  }
713
- function warnIfDropped(sent, run, log) {
714
- const names = Object.keys(sent);
715
- if (names.length === 0) return;
716
- if (names.some((name) => run[name] != null)) return;
717
- log(
718
- `plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
719
- );
720
- }
721
- async function startRun(passed, declared) {
722
- const env = readEnv();
723
- if (env.shardError !== void 0) throw new Error(env.shardError);
724
- if (env.configurationError !== void 0 && passed.configuration === void 0) throw new Error(env.configurationError);
725
- const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
726
- const cfg = { ...env.config, ...stated };
727
- const configuration = cfg.configuration !== void 0 && Object.keys(cfg.configuration).length > 0 ? cfg.configuration : void 0;
728
- const log = cfg.log ?? ((line) => void process.stderr.write(`${line}
729
- `));
730
- const fallbackPath = cfg.fallbackPath ?? DEFAULT_FALLBACK_PATH;
731
- const externalKey = cfg.externalKey ?? null;
732
- const sessionMarker = randomUUID();
733
- const batchSize = Math.min(cfg.batchSize ?? BATCH_DEFAULT, BATCH_MAX);
734
- const offerDiscovered = cfg.offerDiscovered ?? false;
735
- const token = cfg.token ?? loadToken() ?? "";
736
- const uploadsAtOnce = Math.min(Math.max(Math.floor(cfg.uploadConcurrency ?? UPLOAD_CONCURRENCY.default), UPLOAD_CONCURRENCY.min), UPLOAD_CONCURRENCY.max);
737
- const uploadRetries = Math.min(Math.max(Math.floor(cfg.uploadRetries ?? UPLOAD_RETRIES.default), UPLOAD_RETRIES.min), UPLOAD_RETRIES.max);
713
+ function fileSender(options) {
714
+ const { client, log, stats, uploadsAtOnce, uploadRetries } = options;
715
+ const without = options.without ?? "its result is reported without it";
738
716
  let retried = 0;
739
717
  let uploadMs = 0;
740
718
  let requests = 0;
741
719
  let existed = 0;
742
720
  let batchMissing = false;
743
- const client = createClient({
744
- apiUrl: resolveApiUrl(cfg.apiUrl),
745
- token,
746
- uploadRetries,
747
- onRetry: () => void (retried += 1),
748
- ...cfg.fetchImpl !== void 0 ? { fetchImpl: cfg.fetchImpl } : {}
749
- });
750
- const stats = {
751
- accepted: 0,
752
- duplicate: 0,
753
- conflict: 0,
754
- rejected: 0,
755
- unresolved: 0,
756
- offered: 0,
757
- created: 0,
758
- unoffered: 0,
759
- deferred: 0,
760
- screenshots: { uploaded: 0, skipped: 0, failed: 0 },
761
- textFiles: { uploaded: 0, skipped: 0, failed: 0 },
762
- otherFiles: { uploaded: 0, skipped: 0, failed: 0 }
763
- };
764
- const resolved = /* @__PURE__ */ new Map();
765
- let buffer = [];
766
- const discoveries = /* @__PURE__ */ new Map();
767
- const held = /* @__PURE__ */ new Map();
768
- let createdWithResult = 0;
769
- let createdUndelivered = 0;
770
- let runId = null;
771
- let joined = false;
772
- let offline = token === "";
773
- let done = false;
774
- const shortened = /* @__PURE__ */ new Set();
775
721
  const skipsSaid = /* @__PURE__ */ new Set();
776
722
  const countsOf = (kind) => kind === "text" ? stats.textFiles : kind === "file" ? stats.otherFiles : stats.screenshots;
777
723
  let bucketSeen = false;
@@ -780,168 +726,6 @@ async function startRun(passed, declared) {
780
726
  const failedSaid = /* @__PURE__ */ new Set();
781
727
  const codesSaid = /* @__PURE__ */ new Set();
782
728
  const rooms = /* @__PURE__ */ new Map();
783
- function bound(keys) {
784
- return keys.map((key) => {
785
- const fit = boundKey(key);
786
- if (fit !== key && !shortened.has(key.value)) {
787
- shortened.add(key.value);
788
- if (shortened.size === 1) {
789
- log(
790
- `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.`
791
- );
792
- }
793
- }
794
- return fit;
795
- });
796
- }
797
- const expected = declared?.map(bound);
798
- if (offline) {
799
- log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
800
- }
801
- for (const warning of env.warnings) log(`plune: ${warning}`);
802
- if (env.ignored.length > 0) {
803
- log(`plune: ignoring ${env.ignored.join(", ")} \u2014 a run has nowhere to store them yet.`);
804
- }
805
- function defer(results) {
806
- appendBatch(fallbackPath, {
807
- runId,
808
- externalKey,
809
- session: sessionMarker,
810
- ...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
811
- ...configuration !== void 0 ? { configuration } : {},
812
- results: results.map(onDisk)
813
- });
814
- stats.deferred += results.length;
815
- }
816
- async function resolveKeys(values) {
817
- const unknown = values.filter((k) => !resolved.has(keyId(k)));
818
- if (unknown.length === 0 || offline) return;
819
- for (const part of chunk(unknown, RESOLVE_CHUNK)) {
820
- const out = await client.post(
821
- "/v1/test-cases/resolve",
822
- { keys: part }
823
- );
824
- if (!out.ok || !Array.isArray(out.body?.results)) {
825
- log(`plune: could not look up test cases (${out.ok ? "the answer had no results" : out.detail || out.kind}).`);
826
- return;
827
- }
828
- for (const row of out.body.results) {
829
- if (typeof row?.key?.value === "string") resolved.set(keyId(row.key), row.testCaseId);
830
- }
831
- }
832
- }
833
- if (!offline) {
834
- if (expected !== void 0) await resolveKeys(expected.flat());
835
- const stated2 = expected?.slice(0, EXPECTED_MAX) ?? [];
836
- const configuration2 = stated2.length === 0 ? void 0 : {
837
- expected: stated2.flatMap((keys) => {
838
- const hit = keys.map((k) => resolved.get(keyId(k))).find((v) => typeof v === "string");
839
- if (typeof hit === "string") return [{ testCaseId: hit }];
840
- return keys[0] === void 0 ? [] : [{ externalKey: keys[0] }];
841
- }),
842
- // The claim travels with the list it is about (D20). A runner that could not enumerate
843
- // its tests has no list, and a claim without one is nothing the platform can check —
844
- // so it is not sent, rather than sent and silently meaningless.
845
- ...cfg.full === true ? { full: true } : {}
846
- };
847
- if (expected !== void 0 && expected.length > EXPECTED_MAX) {
848
- log(`plune: ${expected.length} tests is more than the run configuration holds \u2014 reporting the first ${EXPECTED_MAX}.`);
849
- }
850
- const described = {
851
- ...cfg.title !== void 0 ? { title: cfg.title } : {},
852
- ...cfg.environment !== void 0 ? { environment: cfg.environment } : {},
853
- ...cfg.labels !== void 0 ? { labels: cfg.labels } : {}
854
- };
855
- const request = {
856
- schemaVersion: 2,
857
- kind: cfg.kind ?? "automated",
858
- ...externalKey !== null ? { externalKey } : {},
859
- ...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
860
- ...configuration2 !== void 0 ? { configuration: configuration2 } : {},
861
- // Named even when nobody named it — the list has to read without opening a row. Only what
862
- // the caller DESCRIBED goes to `warnIfDropped` below: a title this side invented is not one
863
- // a person will miss, and a deployment older than the field must not be nagged on every run.
864
- title: defaultRunTitle(),
865
- ...described
866
- };
867
- let start = await client.post("/v1/runs", request);
868
- if (!start.ok && start.status === 413 && configuration2 !== void 0) {
869
- log(
870
- `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.`
871
- );
872
- start = await client.post("/v1/runs", { ...request, configuration: void 0 });
873
- }
874
- if (start.ok && typeof start.body?.run?.id === "string") {
875
- runId = start.body.run.id;
876
- joined = start.status === 200;
877
- warnIfDropped(described, start.body.run, log);
878
- } else {
879
- const why = start.ok ? "the answer had no run" : start.detail || start.kind;
880
- log(`plune: could not start the run (${why}). Results will be written to ${fallbackPath}.`);
881
- }
882
- }
883
- function matchFor(result) {
884
- if (result.testCaseId !== void 0) return { kind: "found", testCaseId: result.testCaseId };
885
- let unanswered = false;
886
- for (const key of result.keys) {
887
- const hit = resolved.get(keyId(key));
888
- if (typeof hit === "string") return { kind: "found", testCaseId: hit };
889
- if (hit === void 0) unanswered = true;
890
- }
891
- return unanswered ? { kind: "unanswered" } : { kind: "unmatched" };
892
- }
893
- function remember(result) {
894
- if (!offerDiscovered) return;
895
- if (result.title === void 0 || result.specRef === void 0) return;
896
- if (result.keys.length === 0) return;
897
- const title = boundTitle(result.title);
898
- if (title !== result.title) shortened.add(result.title);
899
- discoveries.set(keyId(result.keys[0]), {
900
- keys: result.keys,
901
- title,
902
- source: result.source,
903
- specRef: result.specRef,
904
- rawStatus: result.rawStatus
905
- });
906
- for (const key of result.keys) held.set(keyId(key), result);
907
- }
908
- async function offer() {
909
- if (discoveries.size === 0 || offline || runId === null) return;
910
- const batches = chunk([...discoveries.values()], DISCOVER_MAX);
911
- for (const [index, batch] of batches.entries()) {
912
- const out = await client.post("/v1/review-items/discovered", {
913
- discovered: batch,
914
- runId
915
- });
916
- if (!out.ok || !Array.isArray(out.body?.results)) {
917
- stats.unoffered = batches.slice(index).reduce((n, rest) => n + rest.length, 0);
918
- stats.unofferedWhy = whyUnoffered(out);
919
- log(
920
- `plune: could not offer ${stats.unoffered} unknown test(s) for review (${out.ok ? "the answer had no results" : out.detail || out.kind}).`
921
- );
922
- return;
923
- }
924
- stats.offered += out.body.results.filter((r) => r?.outcome === "queued").length;
925
- const made = out.body.results.filter((r) => r?.outcome === "created");
926
- stats.created += made.length;
927
- const submissions = [];
928
- const filesByKey = /* @__PURE__ */ new Map();
929
- for (const r of made) {
930
- const pending = typeof r.id === "string" && r.id !== "" && typeof r.key?.value === "string" ? held.get(keyId(r.key)) : void 0;
931
- if (pending === void 0) continue;
932
- for (const key of pending.keys) held.delete(keyId(key));
933
- const { keys: _keys, files, ...rest } = pending;
934
- submissions.push({ ...rest, testCaseId: r.id });
935
- if (files !== void 0) filesByKey.set(pending.resultKey, files);
936
- }
937
- if (submissions.length > 0) {
938
- const before = stats.deferred;
939
- await send(submissions, filesByKey);
940
- createdWithResult += submissions.length;
941
- createdUndelivered += stats.deferred - before;
942
- }
943
- }
944
- }
945
729
  function skip(kind, name, why) {
946
730
  countsOf(kind).skipped += 1;
947
731
  if (why === "noStorage") noStorage += 1;
@@ -951,24 +735,25 @@ async function startRun(passed, declared) {
951
735
  if (why === "noStorage") log(`plune: "${name}" not stored \u2014 ${SKIPPED[why]}.`);
952
736
  else log(`plune: ${KINDS[kind].label} "${name}" not uploaded \u2014 ${SKIPPED[why]}.`);
953
737
  }
738
+ const filesOf2 = (job) => `/v1/${job.owner ?? "results"}/${encodeURIComponent(job.id)}/files`;
954
739
  function ask(job, size) {
955
740
  requests += 1;
956
- return client.post(`/v1/results/${encodeURIComponent(job.id)}/files/uploads`, {
957
- files: [{ name: job.name, contentType: job.type, size }]
741
+ return client.post(`${filesOf2(job)}/uploads`, {
742
+ files: [{ name: job.name, contentType: job.type, size, ...job.key !== void 0 ? { key: job.key } : {} }]
958
743
  }, uploadRetries);
959
744
  }
960
745
  function failed(job, why) {
961
746
  countsOf(job.kind).failed += 1;
962
747
  if (!failedSaid.has(job.kind)) {
963
748
  failedSaid.add(job.kind);
964
- log(`plune: could not upload a ${KINDS[job.kind].label} (${why}) \u2014 its result is reported without it.`);
749
+ log(`plune: could not upload a ${KINDS[job.kind].label} (${why}) \u2014 ${without}.`);
965
750
  }
966
751
  }
967
752
  function failedToBucket(job, code) {
968
753
  countsOf(job.kind).failed += 1;
969
754
  if (codesSaid.has(code)) return;
970
755
  codesSaid.add(code);
971
- log(`plune: "${job.name}" not uploaded to your bucket (${code}) \u2014 its result is reported without it.`);
756
+ log(`plune: "${job.name}" not uploaded to your bucket (${code}) \u2014 ${without}.`);
972
757
  }
973
758
  function refusedHere(job, size) {
974
759
  if (job.kind === "screenshot") {
@@ -996,7 +781,7 @@ async function startRun(passed, declared) {
996
781
  if (refusal !== void 0) return skip(kind, job.name, refusal);
997
782
  requests += 1;
998
783
  const out = await client.upload(
999
- `/v1/results/${encodeURIComponent(job.id)}/files?name=${encodeURIComponent(job.name)}`,
784
+ `${filesOf2(job)}?name=${encodeURIComponent(job.name)}`,
1000
785
  bytes,
1001
786
  job.type
1002
787
  );
@@ -1018,8 +803,8 @@ async function startRun(passed, declared) {
1018
803
  link = fresh;
1019
804
  }
1020
805
  requests += 1;
1021
- const done2 = await client.post(`/v1/files/${encodeURIComponent(link.id)}/complete`, {}, uploadRetries);
1022
- if (!done2.ok) return failedToBucket(job, codeOf(done2));
806
+ const done = await client.post(`/v1/files/${encodeURIComponent(link.id)}/complete`, {}, uploadRetries);
807
+ if (!done.ok) return failedToBucket(job, codeOf(done));
1023
808
  countsOf(job.kind).uploaded += 1;
1024
809
  }
1025
810
  let free = uploadsAtOnce;
@@ -1346,6 +1131,250 @@ async function startRun(passed, declared) {
1346
1131
  else await uploadBatched(jobs);
1347
1132
  uploadMs += Date.now() - started;
1348
1133
  }
1134
+ return {
1135
+ upload,
1136
+ uploadEach,
1137
+ onRetry: () => void (retried += 1),
1138
+ get bucketSeen() {
1139
+ return bucketSeen;
1140
+ },
1141
+ get noStorage() {
1142
+ return noStorage;
1143
+ },
1144
+ get existed() {
1145
+ return existed;
1146
+ },
1147
+ get retried() {
1148
+ return retried;
1149
+ },
1150
+ get uploadMs() {
1151
+ return uploadMs;
1152
+ },
1153
+ get requests() {
1154
+ return requests;
1155
+ }
1156
+ };
1157
+ }
1158
+ function warnIfDropped(sent, run, log) {
1159
+ const names = Object.keys(sent);
1160
+ if (names.length === 0) return;
1161
+ if (names.some((name) => run[name] != null)) return;
1162
+ log(
1163
+ `plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
1164
+ );
1165
+ }
1166
+ async function startRun(passed, declared) {
1167
+ const env = readEnv();
1168
+ if (env.shardError !== void 0) throw new Error(env.shardError);
1169
+ if (env.configurationError !== void 0 && passed.configuration === void 0) throw new Error(env.configurationError);
1170
+ const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
1171
+ const cfg = { ...env.config, ...stated };
1172
+ const configuration = cfg.configuration !== void 0 && Object.keys(cfg.configuration).length > 0 ? cfg.configuration : void 0;
1173
+ const log = cfg.log ?? ((line) => void process.stderr.write(`${line}
1174
+ `));
1175
+ const fallbackPath = cfg.fallbackPath ?? DEFAULT_FALLBACK_PATH;
1176
+ const externalKey = cfg.externalKey ?? null;
1177
+ const sessionMarker = randomUUID();
1178
+ const batchSize = Math.min(cfg.batchSize ?? BATCH_DEFAULT, BATCH_MAX);
1179
+ const offerDiscovered = cfg.offerDiscovered ?? false;
1180
+ const token = cfg.token ?? loadToken() ?? "";
1181
+ const uploadsAtOnce = Math.min(Math.max(Math.floor(cfg.uploadConcurrency ?? UPLOAD_CONCURRENCY.default), UPLOAD_CONCURRENCY.min), UPLOAD_CONCURRENCY.max);
1182
+ const uploadRetries = Math.min(Math.max(Math.floor(cfg.uploadRetries ?? UPLOAD_RETRIES.default), UPLOAD_RETRIES.min), UPLOAD_RETRIES.max);
1183
+ const client = createClient({
1184
+ apiUrl: resolveApiUrl(cfg.apiUrl),
1185
+ token,
1186
+ uploadRetries,
1187
+ onRetry: () => files.onRetry(),
1188
+ ...cfg.fetchImpl !== void 0 ? { fetchImpl: cfg.fetchImpl } : {}
1189
+ });
1190
+ const stats = {
1191
+ accepted: 0,
1192
+ duplicate: 0,
1193
+ conflict: 0,
1194
+ rejected: 0,
1195
+ unresolved: 0,
1196
+ offered: 0,
1197
+ created: 0,
1198
+ unoffered: 0,
1199
+ deferred: 0,
1200
+ screenshots: { uploaded: 0, skipped: 0, failed: 0 },
1201
+ textFiles: { uploaded: 0, skipped: 0, failed: 0 },
1202
+ otherFiles: { uploaded: 0, skipped: 0, failed: 0 }
1203
+ };
1204
+ const files = fileSender({ client, log, stats, uploadsAtOnce, uploadRetries });
1205
+ const resolved = /* @__PURE__ */ new Map();
1206
+ let buffer = [];
1207
+ const discoveries = /* @__PURE__ */ new Map();
1208
+ const held = /* @__PURE__ */ new Map();
1209
+ let createdWithResult = 0;
1210
+ let createdUndelivered = 0;
1211
+ let runId = null;
1212
+ let joined = false;
1213
+ let offline = token === "";
1214
+ let done = false;
1215
+ const shortened = /* @__PURE__ */ new Set();
1216
+ function bound(keys) {
1217
+ return keys.map((key) => {
1218
+ const fit = boundKey(key);
1219
+ if (fit !== key && !shortened.has(key.value)) {
1220
+ shortened.add(key.value);
1221
+ if (shortened.size === 1) {
1222
+ log(
1223
+ `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.`
1224
+ );
1225
+ }
1226
+ }
1227
+ return fit;
1228
+ });
1229
+ }
1230
+ const expected = declared?.map(bound);
1231
+ if (offline) {
1232
+ log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
1233
+ }
1234
+ for (const warning of env.warnings) log(`plune: ${warning}`);
1235
+ if (env.ignored.length > 0) {
1236
+ log(`plune: ignoring ${env.ignored.join(", ")} \u2014 a run has nowhere to store them yet.`);
1237
+ }
1238
+ function defer(results) {
1239
+ appendBatch(fallbackPath, {
1240
+ runId,
1241
+ externalKey,
1242
+ session: sessionMarker,
1243
+ ...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
1244
+ ...configuration !== void 0 ? { configuration } : {},
1245
+ results: results.map(onDisk)
1246
+ });
1247
+ stats.deferred += results.length;
1248
+ }
1249
+ async function resolveKeys(values) {
1250
+ const unknown = values.filter((k) => !resolved.has(keyId(k)));
1251
+ if (unknown.length === 0 || offline) return;
1252
+ for (const part of chunk(unknown, RESOLVE_CHUNK)) {
1253
+ const out = await client.post(
1254
+ "/v1/test-cases/resolve",
1255
+ { keys: part }
1256
+ );
1257
+ if (!out.ok || !Array.isArray(out.body?.results)) {
1258
+ log(`plune: could not look up test cases (${out.ok ? "the answer had no results" : out.detail || out.kind}).`);
1259
+ return;
1260
+ }
1261
+ for (const row of out.body.results) {
1262
+ if (typeof row?.key?.value === "string") resolved.set(keyId(row.key), row.testCaseId);
1263
+ }
1264
+ }
1265
+ }
1266
+ if (!offline) {
1267
+ if (expected !== void 0) await resolveKeys(expected.flat());
1268
+ const stated2 = expected?.slice(0, EXPECTED_MAX) ?? [];
1269
+ const configuration2 = stated2.length === 0 ? void 0 : {
1270
+ expected: stated2.flatMap((keys) => {
1271
+ const hit = keys.map((k) => resolved.get(keyId(k))).find((v) => typeof v === "string");
1272
+ if (typeof hit === "string") return [{ testCaseId: hit }];
1273
+ return keys[0] === void 0 ? [] : [{ externalKey: keys[0] }];
1274
+ }),
1275
+ // The claim travels with the list it is about. A runner that could not enumerate
1276
+ // its tests has no list, and a claim without one is nothing the platform can check —
1277
+ // so it is not sent, rather than sent and silently meaningless.
1278
+ ...cfg.full === true ? { full: true } : {}
1279
+ };
1280
+ if (expected !== void 0 && expected.length > EXPECTED_MAX) {
1281
+ log(`plune: ${expected.length} tests is more than the run configuration holds \u2014 reporting the first ${EXPECTED_MAX}.`);
1282
+ }
1283
+ const described = {
1284
+ ...cfg.title !== void 0 ? { title: cfg.title } : {},
1285
+ ...cfg.environment !== void 0 ? { environment: cfg.environment } : {},
1286
+ ...cfg.labels !== void 0 ? { labels: cfg.labels } : {}
1287
+ };
1288
+ const request = {
1289
+ schemaVersion: 2,
1290
+ kind: cfg.kind ?? "automated",
1291
+ ...externalKey !== null ? { externalKey } : {},
1292
+ ...cfg.meta !== void 0 ? { meta: cfg.meta } : {},
1293
+ ...configuration2 !== void 0 ? { configuration: configuration2 } : {},
1294
+ // Named even when nobody named it — the list has to read without opening a row. Only what
1295
+ // the caller DESCRIBED goes to `warnIfDropped` below: a title this side invented is not one
1296
+ // a person will miss, and a deployment older than the field must not be nagged on every run.
1297
+ title: defaultRunTitle(),
1298
+ ...described
1299
+ };
1300
+ let start = await client.post("/v1/runs", request);
1301
+ if (!start.ok && start.status === 413 && configuration2 !== void 0) {
1302
+ log(
1303
+ `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.`
1304
+ );
1305
+ start = await client.post("/v1/runs", { ...request, configuration: void 0 });
1306
+ }
1307
+ if (start.ok && typeof start.body?.run?.id === "string") {
1308
+ runId = start.body.run.id;
1309
+ joined = start.status === 200;
1310
+ warnIfDropped(described, start.body.run, log);
1311
+ } else {
1312
+ const why = start.ok ? "the answer had no run" : start.detail || start.kind;
1313
+ log(`plune: could not start the run (${why}). Results will be written to ${fallbackPath}.`);
1314
+ }
1315
+ }
1316
+ function matchFor(result) {
1317
+ if (result.testCaseId !== void 0) return { kind: "found", testCaseId: result.testCaseId };
1318
+ let unanswered = false;
1319
+ for (const key of result.keys) {
1320
+ const hit = resolved.get(keyId(key));
1321
+ if (typeof hit === "string") return { kind: "found", testCaseId: hit };
1322
+ if (hit === void 0) unanswered = true;
1323
+ }
1324
+ return unanswered ? { kind: "unanswered" } : { kind: "unmatched" };
1325
+ }
1326
+ function remember(result) {
1327
+ if (!offerDiscovered) return;
1328
+ if (result.title === void 0 || result.specRef === void 0) return;
1329
+ if (result.keys.length === 0) return;
1330
+ const title = boundTitle(result.title);
1331
+ if (title !== result.title) shortened.add(result.title);
1332
+ discoveries.set(keyId(result.keys[0]), {
1333
+ keys: result.keys,
1334
+ title,
1335
+ source: result.source,
1336
+ specRef: result.specRef,
1337
+ rawStatus: result.rawStatus
1338
+ });
1339
+ for (const key of result.keys) held.set(keyId(key), result);
1340
+ }
1341
+ async function offer() {
1342
+ if (discoveries.size === 0 || offline || runId === null) return;
1343
+ const batches = chunk([...discoveries.values()], DISCOVER_MAX);
1344
+ for (const [index, batch] of batches.entries()) {
1345
+ const out = await client.post("/v1/review-items/discovered", {
1346
+ discovered: batch,
1347
+ runId
1348
+ });
1349
+ if (!out.ok || !Array.isArray(out.body?.results)) {
1350
+ stats.unoffered = batches.slice(index).reduce((n, rest) => n + rest.length, 0);
1351
+ stats.unofferedWhy = whyUnoffered(out);
1352
+ log(
1353
+ `plune: could not offer ${stats.unoffered} unknown test(s) for review (${out.ok ? "the answer had no results" : out.detail || out.kind}).`
1354
+ );
1355
+ return;
1356
+ }
1357
+ stats.offered += out.body.results.filter((r) => r?.outcome === "queued").length;
1358
+ const made = out.body.results.filter((r) => r?.outcome === "created");
1359
+ stats.created += made.length;
1360
+ const submissions = [];
1361
+ const filesByKey = /* @__PURE__ */ new Map();
1362
+ for (const r of made) {
1363
+ const pending = typeof r.id === "string" && r.id !== "" && typeof r.key?.value === "string" ? held.get(keyId(r.key)) : void 0;
1364
+ if (pending === void 0) continue;
1365
+ for (const key of pending.keys) held.delete(keyId(key));
1366
+ const { keys: _keys, files: files2, ...rest } = pending;
1367
+ submissions.push({ ...rest, testCaseId: r.id });
1368
+ if (files2 !== void 0) filesByKey.set(pending.resultKey, files2);
1369
+ }
1370
+ if (submissions.length > 0) {
1371
+ const before = stats.deferred;
1372
+ await send(submissions, filesByKey);
1373
+ createdWithResult += submissions.length;
1374
+ createdUndelivered += stats.deferred - before;
1375
+ }
1376
+ }
1377
+ }
1349
1378
  const sending = /* @__PURE__ */ new Set();
1350
1379
  let sendError;
1351
1380
  let answered = false;
@@ -1386,9 +1415,9 @@ async function startRun(passed, declared) {
1386
1415
  for (const result of pending) {
1387
1416
  const match = matchFor(result);
1388
1417
  if (match.kind === "found") {
1389
- const { keys: _keys, files, ...rest } = result;
1418
+ const { keys: _keys, files: files2, ...rest } = result;
1390
1419
  submissions.push({ ...rest, testCaseId: match.testCaseId });
1391
- if (files !== void 0) filesByKey.set(result.resultKey, files);
1420
+ if (files2 !== void 0) filesByKey.set(result.resultKey, files2);
1392
1421
  } else if (match.kind === "unmatched") {
1393
1422
  stats.unresolved += 1;
1394
1423
  remember(result);
@@ -1411,7 +1440,7 @@ async function startRun(passed, declared) {
1411
1440
  }
1412
1441
  const out = await client.post(
1413
1442
  `/v1/runs/${runId}/results`,
1414
- // The job's combination on every batch (plune-ai/plune#1251); a refusal of it is a 422 said below as it came.
1443
+ // The job's combination on every batch; a refusal of it is a 422 said below as it came.
1415
1444
  { results: part, ...configuration !== void 0 ? { configuration } : {} }
1416
1445
  );
1417
1446
  const counts = out.ok ? out.body?.counts : void 0;
@@ -1419,7 +1448,7 @@ async function startRun(passed, declared) {
1419
1448
  if (told.length > 0) {
1420
1449
  for (const k of told) stats[k] += counts[k];
1421
1450
  progress();
1422
- await upload(out.ok ? out.body?.items : void 0, filesByKey);
1451
+ await files.upload(out.ok ? out.body?.items : void 0, filesByKey);
1423
1452
  answered = true;
1424
1453
  continue;
1425
1454
  }
@@ -1455,10 +1484,10 @@ async function startRun(passed, declared) {
1455
1484
  }
1456
1485
  const kinds = [stats.screenshots, stats.textFiles, stats.otherFiles];
1457
1486
  const sum = (what) => kinds.reduce((n, counts) => n + counts[what], 0);
1458
- if (bucketSeen) {
1459
- const other = sum("skipped") - noStorage;
1487
+ if (files.bucketSeen) {
1488
+ const other = sum("skipped") - files.noStorage;
1460
1489
  parts.push(
1461
- `${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` : "")
1490
+ `${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` : "")
1462
1491
  );
1463
1492
  } else {
1464
1493
  for (const said of [tally(stats.screenshots, "screenshot"), tally(stats.textFiles, "text file")]) {
@@ -1470,11 +1499,10 @@ async function startRun(passed, declared) {
1470
1499
  }
1471
1500
  if (stats.deferred > 0) parts.push(`${stats.deferred} not delivered \u2014 written to ${fallbackPath}`);
1472
1501
  if (shortened.size > 0) parts.push(`${shortened.size} test name(s) shortened to fit a key`);
1473
- const files = [stats.screenshots, stats.textFiles, stats.otherFiles];
1474
- const total = (what) => files.reduce((n, counts) => n + counts[what], 0);
1475
- if (total("uploaded") + total("skipped") + total("failed") + existed > 0) {
1502
+ const total = (what) => kinds.reduce((n, counts) => n + counts[what], 0);
1503
+ if (total("uploaded") + total("skipped") + total("failed") + files.existed > 0) {
1476
1504
  log(
1477
- `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)`
1505
+ `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)`
1478
1506
  );
1479
1507
  }
1480
1508
  log(`plune: ${parts.join(" \xB7 ")}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plune-ai/cli",
3
- "version": "0.38.0",
3
+ "version": "0.39.1",
4
4
  "description": "AI-powered assertion testing for LLM apps — write assertions, run them against any provider, get a pass/fail report (local, CI, or diff).",
5
5
  "keywords": [
6
6
  "ai",