@plune-ai/playwright 0.7.3 → 0.7.5

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 CHANGED
@@ -402,6 +402,7 @@ function readEnv(env = process.env) {
402
402
  ...shardError !== void 0 ? { shardError } : {},
403
403
  ...configurationError !== void 0 ? { configurationError } : {},
404
404
  ...importTimeout !== void 0 ? { importTimeout } : {},
405
+ secretCheck: !["0", "false", "no", "off"].includes(value(env, "PLUNE_SECRET_CHECK")?.toLowerCase() ?? ""),
405
406
  ignored: UNSUPPORTED_VARS.filter((name) => value(env, name) !== void 0),
406
407
  warnings
407
408
  };
@@ -748,6 +749,30 @@ function maskCredentials(text) {
748
749
  "$1$2\u2039credential\u203A"
749
750
  ).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
  }
752
+ function credentialsIn(text) {
753
+ const masked = maskCredentials(text);
754
+ if (masked === text) return [];
755
+ const found = [];
756
+ let from = 0;
757
+ let at = 0;
758
+ for (let open = masked.indexOf("\u2039", at); open >= 0; open = masked.indexOf("\u2039", at)) {
759
+ const start = from + (open - at);
760
+ let close = masked.indexOf("\u203A", open);
761
+ while (close >= 0 && masked[close + 1] === "\u2039") close = masked.indexOf("\u203A", close + 1);
762
+ if (close < 0) break;
763
+ const next = masked.indexOf("\u2039", close + 1);
764
+ const tail = masked.slice(close + 1, next < 0 ? void 0 : next);
765
+ const end = next < 0 ? text.length - tail.length : text.indexOf(tail, start);
766
+ if (end < start) break;
767
+ const marker = masked.slice(open, close + 1);
768
+ if (!(end - start === marker.length && text.startsWith(marker, start))) {
769
+ found.push({ line: text.slice(0, start).split("\n").length, length: end - start });
770
+ }
771
+ from = end + tail.length;
772
+ at = close + 1 + tail.length;
773
+ }
774
+ return found;
775
+ }
751
776
  function snapshotAt(at, files) {
752
777
  let source = files.get(at.file);
753
778
  if (source === void 0) {
@@ -848,8 +873,8 @@ function textRefusal(bytes) {
848
873
  return void 0;
849
874
  }
850
875
  function withoutTargets(result) {
851
- if (result.targets === void 0) return result;
852
- const { targets: _targets, ...rest } = result;
876
+ if (result.targets === void 0 && result.traceUrl === void 0) return result;
877
+ const { targets: _targets, traceUrl: _traceUrl, ...rest } = result;
853
878
  return rest;
854
879
  }
855
880
  function onDisk(deferred) {
@@ -1687,8 +1712,8 @@ async function startRun(passed, declared2) {
1687
1712
  { results, ...configuration !== void 0 ? { configuration } : {} }
1688
1713
  );
1689
1714
  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.");
1715
+ if (!out.ok && out.kind === "invalid" && out.status === 400 && part.some((r) => r.targets !== void 0 || r.traceUrl !== void 0)) {
1716
+ if (!targetsRefused) log("plune: the platform does not take targets or a trace link on a result yet \u2014 the results are sent without them.");
1692
1717
  targetsRefused = true;
1693
1718
  part = part.map(withoutTargets);
1694
1719
  out = await post(part);
@@ -1760,6 +1785,27 @@ async function startRun(passed, declared2) {
1760
1785
  log(`::warning::${stats.deferred} result(s) were not delivered to Plune \u2014 see the reporting step's log.`);
1761
1786
  }
1762
1787
  }
1788
+ async function warnOfSecrets(result) {
1789
+ const of = printable(result.title ?? result.resultKey);
1790
+ const say = (what, text) => {
1791
+ for (const { line, length } of credentialsIn(text)) {
1792
+ log(
1793
+ `plune: ${what} of "${of}" holds what looks like a secret on line ${line} (${length} characters) \u2014 sent as it is; mask it in the test, or set PLUNE_SECRET_CHECK=0 to turn this check off.`
1794
+ );
1795
+ }
1796
+ };
1797
+ const error = result.errorContext ?? result.failure?.headline;
1798
+ if (error !== void 0) say("the error text", error);
1799
+ for (const file of result.files ?? []) {
1800
+ if (!isTextType(file.contentType)) continue;
1801
+ let bytes = file.body;
1802
+ if (bytes === void 0 && file.path !== void 0) {
1803
+ const size = await import_fs.promises.stat(file.path).then((s) => s.size, () => Infinity);
1804
+ if (size <= TEXT_BYTES) bytes = await import_fs.promises.readFile(file.path).catch(() => void 0);
1805
+ }
1806
+ if (bytes !== void 0 && bytes.length <= TEXT_BYTES) say(`the attachment "${printable(file.name)}"`, bytes.toString("utf8"));
1807
+ }
1808
+ }
1763
1809
  const shardLines = [];
1764
1810
  return {
1765
1811
  get runId() {
@@ -1773,6 +1819,7 @@ async function startRun(passed, declared2) {
1773
1819
  },
1774
1820
  async add(result) {
1775
1821
  const { codeAt, ...rest } = result;
1822
+ if (env.secretCheck) await warnOfSecrets(result);
1776
1823
  const text = codeAt === void 0 ? void 0 : snapshotAt(codeAt, specFiles);
1777
1824
  if (text !== void 0) snapshotByKey.set(result.resultKey, text);
1778
1825
  buffer.push({ ...rest, keys: bound(result.keys) });
package/dist/index.js CHANGED
@@ -368,6 +368,7 @@ function readEnv(env = process.env) {
368
368
  ...shardError !== void 0 ? { shardError } : {},
369
369
  ...configurationError !== void 0 ? { configurationError } : {},
370
370
  ...importTimeout !== void 0 ? { importTimeout } : {},
371
+ secretCheck: !["0", "false", "no", "off"].includes(value(env, "PLUNE_SECRET_CHECK")?.toLowerCase() ?? ""),
371
372
  ignored: UNSUPPORTED_VARS.filter((name) => value(env, name) !== void 0),
372
373
  warnings
373
374
  };
@@ -714,6 +715,30 @@ function maskCredentials(text) {
714
715
  "$1$2\u2039credential\u203A"
715
716
  ).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@");
716
717
  }
718
+ function credentialsIn(text) {
719
+ const masked = maskCredentials(text);
720
+ if (masked === text) return [];
721
+ const found = [];
722
+ let from = 0;
723
+ let at = 0;
724
+ for (let open = masked.indexOf("\u2039", at); open >= 0; open = masked.indexOf("\u2039", at)) {
725
+ const start = from + (open - at);
726
+ let close = masked.indexOf("\u203A", open);
727
+ while (close >= 0 && masked[close + 1] === "\u2039") close = masked.indexOf("\u203A", close + 1);
728
+ if (close < 0) break;
729
+ const next = masked.indexOf("\u2039", close + 1);
730
+ const tail = masked.slice(close + 1, next < 0 ? void 0 : next);
731
+ const end = next < 0 ? text.length - tail.length : text.indexOf(tail, start);
732
+ if (end < start) break;
733
+ const marker = masked.slice(open, close + 1);
734
+ if (!(end - start === marker.length && text.startsWith(marker, start))) {
735
+ found.push({ line: text.slice(0, start).split("\n").length, length: end - start });
736
+ }
737
+ from = end + tail.length;
738
+ at = close + 1 + tail.length;
739
+ }
740
+ return found;
741
+ }
717
742
  function snapshotAt(at, files) {
718
743
  let source = files.get(at.file);
719
744
  if (source === void 0) {
@@ -814,8 +839,8 @@ function textRefusal(bytes) {
814
839
  return void 0;
815
840
  }
816
841
  function withoutTargets(result) {
817
- if (result.targets === void 0) return result;
818
- const { targets: _targets, ...rest } = result;
842
+ if (result.targets === void 0 && result.traceUrl === void 0) return result;
843
+ const { targets: _targets, traceUrl: _traceUrl, ...rest } = result;
819
844
  return rest;
820
845
  }
821
846
  function onDisk(deferred) {
@@ -1653,8 +1678,8 @@ async function startRun(passed, declared2) {
1653
1678
  { results, ...configuration !== void 0 ? { configuration } : {} }
1654
1679
  );
1655
1680
  let out = await post(part);
1656
- if (!out.ok && out.kind === "invalid" && out.status === 400 && part.some((r) => r.targets !== void 0)) {
1657
- if (!targetsRefused) log("plune: the platform does not take targets on a result yet \u2014 the results are sent without them.");
1681
+ if (!out.ok && out.kind === "invalid" && out.status === 400 && part.some((r) => r.targets !== void 0 || r.traceUrl !== void 0)) {
1682
+ if (!targetsRefused) log("plune: the platform does not take targets or a trace link on a result yet \u2014 the results are sent without them.");
1658
1683
  targetsRefused = true;
1659
1684
  part = part.map(withoutTargets);
1660
1685
  out = await post(part);
@@ -1726,6 +1751,27 @@ async function startRun(passed, declared2) {
1726
1751
  log(`::warning::${stats.deferred} result(s) were not delivered to Plune \u2014 see the reporting step's log.`);
1727
1752
  }
1728
1753
  }
1754
+ async function warnOfSecrets(result) {
1755
+ const of = printable(result.title ?? result.resultKey);
1756
+ const say = (what, text) => {
1757
+ for (const { line, length } of credentialsIn(text)) {
1758
+ log(
1759
+ `plune: ${what} of "${of}" holds what looks like a secret on line ${line} (${length} characters) \u2014 sent as it is; mask it in the test, or set PLUNE_SECRET_CHECK=0 to turn this check off.`
1760
+ );
1761
+ }
1762
+ };
1763
+ const error = result.errorContext ?? result.failure?.headline;
1764
+ if (error !== void 0) say("the error text", error);
1765
+ for (const file of result.files ?? []) {
1766
+ if (!isTextType(file.contentType)) continue;
1767
+ let bytes = file.body;
1768
+ if (bytes === void 0 && file.path !== void 0) {
1769
+ const size = await disk.stat(file.path).then((s) => s.size, () => Infinity);
1770
+ if (size <= TEXT_BYTES) bytes = await disk.readFile(file.path).catch(() => void 0);
1771
+ }
1772
+ if (bytes !== void 0 && bytes.length <= TEXT_BYTES) say(`the attachment "${printable(file.name)}"`, bytes.toString("utf8"));
1773
+ }
1774
+ }
1729
1775
  const shardLines = [];
1730
1776
  return {
1731
1777
  get runId() {
@@ -1739,6 +1785,7 @@ async function startRun(passed, declared2) {
1739
1785
  },
1740
1786
  async add(result) {
1741
1787
  const { codeAt, ...rest } = result;
1788
+ if (env.secretCheck) await warnOfSecrets(result);
1742
1789
  const text = codeAt === void 0 ? void 0 : snapshotAt(codeAt, specFiles);
1743
1790
  if (text !== void 0) snapshotByKey.set(result.resultKey, text);
1744
1791
  buffer.push({ ...rest, keys: bound(result.keys) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plune-ai/playwright",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Report Playwright results to Plune — a reporter and, later, a test importer.",
5
5
  "keywords": [
6
6
  "playwright",
@@ -38,7 +38,7 @@
38
38
  "tsup": "^8.0.0",
39
39
  "typescript": "^5.4.0",
40
40
  "vitest": "^1.6.0",
41
- "@plune-ai/cli": "0.39.4"
41
+ "@plune-ai/cli": "0.39.8"
42
42
  },
43
43
  "repository": {
44
44
  "type": "git",