tewip-ai 0.18.4 → 0.18.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.
@@ -5,6 +5,7 @@
5
5
  import { existsSync } from 'node:fs';
6
6
  import { join } from 'node:path';
7
7
  import { spawnSync } from 'node:child_process';
8
+ const NEWLINE = String.fromCharCode(10);
8
9
  const run = (command, cwd, timeoutMs = 5 * 60_000) => {
9
10
  const r = spawnSync(command, { cwd, shell: true, encoding: 'utf8', timeout: timeoutMs, maxBuffer: 40 * 1024 * 1024 });
10
11
  return { code: r.status ?? 1, out: `${r.stdout ?? ''}`, err: `${r.stderr ?? ''}` };
@@ -15,14 +16,26 @@ export const bySeverity = (a, b) => SEVERITY_ORDER.indexOf(a.severity.toLowerCas
15
16
  /** `npm audit --json`, which needs no install and no account: every Node project already has it. */
16
17
  export function npmAudit(root) {
17
18
  if (!existsSync(join(root, 'package.json')))
18
- return [];
19
- const { out } = run('npm audit --json', root);
19
+ return { findings: [], problem: null };
20
+ const { out, err } = run('npm audit --json', root);
20
21
  let report;
21
22
  try {
22
23
  report = JSON.parse(out);
23
24
  }
24
25
  catch {
25
- return [];
26
+ return { findings: [], problem: `npm audit did not return a report${err.trim() ? `: ${err.trim().split(NEWLINE)[0].slice(0, 120)}` : ''}` };
27
+ }
28
+ // npm reports a refusal inside the JSON and still exits 0: no lockfile, a registry that will not
29
+ // answer, a private registry needing credentials. None of those is "nothing found".
30
+ // Two shapes, both exiting 0. A refusal names itself - {"error":{"code":"ENOLOCK","summary":...}}
31
+ // - while a registry that cannot be reached leaves those fields empty and puts the reason in
32
+ // `message`. Reading summary with ?? kept the empty string, so an unreachable registry passed for
33
+ // a clean audit on a project with three known advisories.
34
+ const failure = report.error || (report.message && !report.vulnerabilities);
35
+ if (failure) {
36
+ const reason = [report.error?.summary, report.error?.code, report.message, 'npm audit could not run'].find((x) => typeof x === 'string' && x.trim());
37
+ const hint = report.error?.code === 'ENOLOCK' ? ' (run `npm i --package-lock-only` first)' : '';
38
+ return { findings: [], problem: `${String(reason).slice(0, 160)}${hint}` };
26
39
  }
27
40
  const findings = [];
28
41
  for (const [name, entry] of Object.entries(report.vulnerabilities ?? {})) {
@@ -40,7 +53,7 @@ export function npmAudit(root) {
40
53
  dev: Boolean(entry.isDirect === false ? false : entry.dev ?? false) || Boolean(entry.effects?.length === 0 && entry.dev),
41
54
  });
42
55
  }
43
- return findings;
56
+ return { findings, problem: null };
44
57
  }
45
58
  /** `pip-audit`, when the project is Python and the tool is installed. */
46
59
  export function pipAudit(root) {
@@ -105,8 +118,12 @@ export function auditDependencies(root) {
105
118
  const missing = [];
106
119
  const findings = [];
107
120
  if (existsSync(join(root, 'package.json'))) {
108
- ran.push('npm audit');
109
- findings.push(...npmAudit(root));
121
+ const npm = npmAudit(root);
122
+ if (npm.problem)
123
+ missing.push(`npm audit could not run: ${npm.problem}`);
124
+ else
125
+ ran.push('npm audit');
126
+ findings.push(...npm.findings);
110
127
  }
111
128
  const python = ['requirements.txt', 'pyproject.toml', 'setup.py'].some((f) => existsSync(join(root, f)));
112
129
  if (python) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tewip-ai",
3
- "version": "0.18.4",
3
+ "version": "0.18.5",
4
4
  "description": "Tewip finds why each failing test failed - real bug, flaky test, environment, test data or changed selector - for any stack, from the command line, CI, or your editor.",
5
5
  "keywords": [
6
6
  "test-failures",