testomatio-reporter-cli 2.18.0 → 2.19.0-beta

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testomatio-reporter-cli",
3
- "version": "2.18.0",
3
+ "version": "2.19.0-beta",
4
4
  "description": "Yarn Berry compatible standalone CLI for @testomatio/reporter",
5
5
  "type": "module",
6
6
  "bin": {
package/src/constants.js CHANGED
@@ -60,6 +60,10 @@ const REPORTER_REQUEST_RETRIES = {
60
60
 
61
61
  const DEBUG_FILE = 'testomatio.debug';
62
62
 
63
+ // temporary S3 tokens live ~1 hour; refresh credentials well before that so artifact
64
+ // uploads keep working on long runs
65
+ const S3_CREDENTIALS_REFRESH_INTERVAL_MS = 40 * 60 * 1000;
66
+
63
67
  function getCreateRunRequestTimeout() {
64
68
  return Math.max(REQUEST_TIMEOUT, 80 * 1000);
65
69
  }
@@ -78,4 +82,5 @@ export {
78
82
  REPORTER_REQUEST_RETRIES,
79
83
  SCREENSHOTS_ON_STEPS,
80
84
  DEBUG_FILE,
85
+ S3_CREDENTIALS_REFRESH_INTERVAL_MS,
81
86
  };
@@ -9,6 +9,7 @@ import {
9
9
  REQUEST_TIMEOUT,
10
10
  getCreateRunRequestTimeout,
11
11
  REPORTER_REQUEST_RETRIES,
12
+ S3_CREDENTIALS_REFRESH_INTERVAL_MS,
12
13
  } from '../constants.js';
13
14
  import {
14
15
  isValidUrl,
@@ -72,6 +73,8 @@ class TestomatioPipe {
72
73
  this.retriesTimestamps = [];
73
74
  this.reportingCanceledDueToReqFailures = false;
74
75
  this.notReportedTestsCount = 0;
76
+ /** @type {NodeJS.Timeout | null} */
77
+ this.s3CredentialsRefreshTimer = null;
75
78
 
76
79
  this.isEnabled = false;
77
80
  this.url = params.testomatioUrl || process.env.TESTOMATIO_URL || 'https://app.testomat.io';
@@ -346,7 +349,10 @@ class TestomatioPipe {
346
349
  timeout: getCreateRunRequestTimeout(),
347
350
  responseType: 'json',
348
351
  });
349
- if (resp.data.artifacts) setS3Credentials(resp.data.artifacts);
352
+ if (resp.data.artifacts) {
353
+ setS3Credentials(resp.data.artifacts);
354
+ this.#startS3CredentialsRefresh(runParams);
355
+ }
350
356
  if (resp.data.url) {
351
357
  const respUrl = new URL(resp.data.url);
352
358
  this.runUrl = `${this.url}${respUrl.pathname}`;
@@ -374,7 +380,10 @@ class TestomatioPipe {
374
380
  this.runUrl = `${this.url}/${resp.data.url.split('/').splice(3).join('/')}`;
375
381
  this.runPublicUrl = resp.data.public_url;
376
382
 
377
- if (resp.data.artifacts) setS3Credentials(resp.data.artifacts);
383
+ if (resp.data.artifacts) {
384
+ setS3Credentials(resp.data.artifacts);
385
+ this.#startS3CredentialsRefresh(runParams);
386
+ }
378
387
 
379
388
  this.store.runUrl = this.runUrl;
380
389
  this.store.runPublicUrl = this.runPublicUrl;
@@ -401,6 +410,49 @@ class TestomatioPipe {
401
410
  debug('"createRun" function finished');
402
411
  }
403
412
 
413
+ /**
414
+ * Starts periodic refreshing of S3 credentials for long runs.
415
+ * Temporary S3 tokens (STS) expire after ~1 hour, so without refreshing,
416
+ * artifact uploads fail for every test reported later in the run.
417
+ * The same run params are re-sent on refresh (same as updating an existing run),
418
+ * and fresh credentials are taken from the response's `artifacts` field.
419
+ * @param {Record<string, any>} runParams
420
+ */
421
+ #startS3CredentialsRefresh(runParams) {
422
+ if (this.s3CredentialsRefreshTimer) return;
423
+ this.s3CredentialsRefreshTimer = setInterval(() => {
424
+ this.#refreshS3Credentials(runParams);
425
+ }, S3_CREDENTIALS_REFRESH_INTERVAL_MS);
426
+ this.s3CredentialsRefreshTimer.unref?.();
427
+ debug(`S3 credentials refresh started (every ${S3_CREDENTIALS_REFRESH_INTERVAL_MS / 60000} min)`);
428
+ }
429
+
430
+ #refreshS3Credentials = async runParams => {
431
+ if (!this.isEnabled || !this.runId) return;
432
+ const { ci, access_event, ...refreshParams } = runParams;
433
+ try {
434
+ const resp = await this.client.request({
435
+ method: 'PUT',
436
+ url: `/api/reporter/${this.runId}`,
437
+ data: { ...refreshParams, api_key: this.apiKey },
438
+ responseType: 'json',
439
+ });
440
+ if (resp.data?.artifacts) {
441
+ setS3Credentials(resp.data.artifacts);
442
+ debug('S3 credentials refreshed');
443
+ }
444
+ } catch (err) {
445
+ debug('Failed to refresh S3 credentials:', err.message || err);
446
+ }
447
+ };
448
+
449
+ #stopS3CredentialsRefresh() {
450
+ if (this.s3CredentialsRefreshTimer) {
451
+ clearInterval(this.s3CredentialsRefreshTimer);
452
+ this.s3CredentialsRefreshTimer = null;
453
+ }
454
+ }
455
+
404
456
  /**
405
457
  * Decides whether to skip test reporting in case of too many request failures
406
458
  * @returns {boolean}
@@ -545,6 +597,7 @@ class TestomatioPipe {
545
597
  async finishRun(params) {
546
598
  if (!this.isEnabled) return;
547
599
 
600
+ this.#stopS3CredentialsRefresh();
548
601
  await this.#batchUpload();
549
602
  if (this.batch.intervalFunction) {
550
603
  clearInterval(this.batch.intervalFunction);
@@ -637,6 +690,7 @@ class TestomatioPipe {
637
690
  this.isEnabled = false;
638
691
  this.apiKey = null;
639
692
 
693
+ this.#stopS3CredentialsRefresh();
640
694
  // clear interval function, otherwise the proccess will continue indefinitely
641
695
  if (this.batch.intervalFunction) {
642
696
  clearInterval(this.batch.intervalFunction);