targeted-mutation 0.2.1 → 0.2.3

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 CHANGED
@@ -1,6 +1,10 @@
1
1
  # targeted-mutation
2
2
 
3
- `targeted-mutation` finds the tests your suite is missing. It watches the values your tests actually pass through comparisons, tries the smallest wrong implementation those values cannot tell apart from yours, and prints the test that would catch it.
3
+ [![npm](https://img.shields.io/npm/v/targeted-mutation.svg)](https://www.npmjs.com/package/targeted-mutation)
4
+ [![CI](https://github.com/t-k/targeted-mutation-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/t-k/targeted-mutation-ts/actions/workflows/ci.yml)
5
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
6
+
7
+ **Targeted mutation testing for JavaScript and TypeScript**: `targeted-mutation` finds the tests your suite is missing. It watches the values your tests actually pass through comparisons, tries the smallest wrong implementation those values cannot tell apart from yours, and prints the test that would catch it.
4
8
 
5
9
  ```ts
6
10
  export const isAdult = (age: number) => age >= 18;
package/bin/tmt.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync, realpathSync } from 'node:fs';
3
+ import { relative } from 'node:path';
3
4
  import { parseArgs } from 'node:util';
4
5
  import { chooseFormat, renderText, usage } from '../src/cli-output.mjs';
5
6
  import { enablePreparedTypeScript } from '../src/typescript-compiler.mjs';
@@ -108,6 +109,16 @@ try {
108
109
  runValues['copy-exclude'] = [...new Set([...(runValues['copy-exclude'] ?? []), ...ignoredExclusions])];
109
110
  }
110
111
  }
112
+ if (runValues['copy-exclude']?.length) {
113
+ const { resolveCopyExclusions } = await import('../src/vitest.mjs');
114
+ const activeExclusions = resolveCopyExclusions(validated.root, runValues['copy-exclude'], {
115
+ onMissing: path => {
116
+ const safePath = /[\x00-\x1f\x7f]/.test(path) ? JSON.stringify(path) : path;
117
+ process.stderr.write(`Warning: Copy exclusion does not exist, skipping: ${safePath}\n`);
118
+ },
119
+ });
120
+ runValues['copy-exclude'] = activeExclusions.map(entry => relative(validated.root, entry));
121
+ }
111
122
  const logProgress = runValues.progress ? message => process.stderr.write(`[tmt] ${message}\n`) : () => {};
112
123
  enablePreparedTypeScript();
113
124
  let result;
package/docs/analysis.md CHANGED
@@ -18,7 +18,7 @@ npx targeted-mutation analyze . packages/example/src/ranges.ts --since HEAD^ \
18
18
  --copy-exclude benchmarks --audit
19
19
  ```
20
20
 
21
- `--config` selects a project-relative Vitest or Playwright config. Repeat `--test FILE` to run specific, project-relative test files in every phase, including witness runs. With Playwright the files are passed to `playwright test` as path filters, so a suite with several browsers and many specs can start with the one spec that covers the source. The report records the selection and errors if the config collects missing or additional test files. Any conclusions from a selected suite apply to that suite. Repeat `--copy-exclude PATH` to omit local assets or build caches from every temporary copy while leaving the original checkout intact. A selected suite should retain the files and build outputs it needs. The runner already omits `.worktree` and `.worktrees`. Source discovery skips excluded paths. Provide exclusions inside the project without traversing symbolic links, and keep `node_modules` available for the test runner.
21
+ `--config` selects a project-relative Vitest or Playwright config. Repeat `--test FILE` to run specific, project-relative test files in every phase, including witness runs. With Playwright the files are passed to `playwright test` as path filters, so a suite with several browsers and many specs can start with the one spec that covers the source. The report records the selection and errors if the config collects missing or additional test files. Any conclusions from a selected suite apply to that suite. Repeat `--copy-exclude PATH` to omit local assets or build caches from every temporary copy while leaving the original checkout intact. Missing exclusion paths emit a single warning to `stderr` and are skipped so fixed scripts work on clean checkouts before build artifacts exist. A selected suite should retain the files and build outputs it needs. The runner already omits `.worktree` and `.worktrees`. Source discovery skips excluded paths. Provide exclusions inside the project without traversing symbolic links, and keep `node_modules` available for the test runner.
22
22
 
23
23
  Automatic scope includes JavaScript and TypeScript source, including JSX and module-specific extensions. It skips conventional test, spec, declaration and runner configuration filenames. With `--since`, Git supplies tracked and changed paths in bulk. Only changed tracked files in scope need a line diff. A new, untracked file counts as changed unless Git ignores it: generated clients and build output under `.gitignore` are left out of discovery, and naming such a file on the command line still selects it.
24
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "targeted-mutation",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Find the tests a JavaScript or TypeScript suite is missing by trying small, targeted source edits against it.",
5
5
  "keywords": [
6
6
  "mutation-testing",
@@ -43,9 +43,9 @@
43
43
  "NOTICE"
44
44
  ],
45
45
  "optionalDependencies": {
46
- "@targeted-mutation/tmt-darwin-arm64": "0.2.1",
47
- "@targeted-mutation/tmt-darwin-x64": "0.2.1",
48
- "@targeted-mutation/tmt-linux-arm64": "0.2.1",
49
- "@targeted-mutation/tmt-linux-x64": "0.2.1"
46
+ "@targeted-mutation/tmt-darwin-arm64": "0.2.3",
47
+ "@targeted-mutation/tmt-darwin-x64": "0.2.3",
48
+ "@targeted-mutation/tmt-linux-arm64": "0.2.3",
49
+ "@targeted-mutation/tmt-linux-x64": "0.2.3"
50
50
  }
51
51
  }
@@ -12,7 +12,7 @@ Scope (analyze):
12
12
  without pinning the result, and give the value to compare with (Vitest).
13
13
  --undo-changes With --since: also put each change back as it was at REV and run the suite.
14
14
  A change the tests pass without is reported as UNTESTED CHANGE.
15
- --copy-exclude PATH Leave a project path out of the temporary copies. Repeatable.
15
+ --copy-exclude PATH Leave a project path out of the temporary copies (warns and skips if missing). Repeatable.
16
16
  --copy-exclude-gitignore Also exclude gitignored paths (except node_modules) from temporary copies.
17
17
  --exclude-rule RULE Exclude a mutation rule (e.g. nullish-equality/v1). Repeatable.
18
18
  --no-config Ignore targeted-mutation.config.{json,mjs} and package.json#targetedMutation.
@@ -147,7 +147,7 @@ export function assessTrial(trial, expectedTests, hitLimit) {
147
147
  }
148
148
  if (hitCount > 0 && ['failed', 'interrupted'].includes(reason) && failed.length &&
149
149
  failed.every(test => expectedTests.has(test.id)) && [...expectedTests].every(([id, test]) =>
150
- registered.has(id) || reason === 'interrupted' && !collectedModules.has(moduleKey(test)))) {
150
+ registered.has(id) || !collectedModules.has(moduleKey(test)))) {
151
151
  return { status: 'killed', tests: failed.map(({ id, name, file, project }) => ({ id, name, file, project })) };
152
152
  }
153
153
  if (hitCount > 0 && reason === 'passed' && !failed.length && [...expectedTests.keys()].every(id => actualPassed.has(id))) {
package/src/vitest.mjs CHANGED
@@ -42,29 +42,65 @@ export function inside(root, path) {
42
42
  return target;
43
43
  }
44
44
 
45
- export function resolveCopyExclusions(source, exclude = []) {
46
- return exclude.map(path => {
45
+ const normalizeExclusionKey = value => (process.platform === 'win32' ? value.toLowerCase() : value);
46
+
47
+ export function resolveCopyExclusions(source, exclude = [], { onMissing } = {}) {
48
+ const resolved = [];
49
+ const seenResolved = new Set();
50
+ const seenMissing = new Set();
51
+ const caseInsensitive = process.platform === 'win32' || process.platform === 'darwin';
52
+ for (const path of exclude) {
47
53
  const candidate = resolve(source, path);
48
54
  const fromRoot = relative(source, candidate);
49
55
  if (!fromRoot || isAbsolute(path) || isAbsolute(fromRoot) || fromRoot === '..' || fromRoot.startsWith('..' + sep)) {
50
56
  throw new Error(`Copy exclusion must be inside the project: ${path}`);
51
57
  }
52
58
  const components = fromRoot.split(sep);
53
- const dependency = components.indexOf('node_modules');
59
+ const dependency = components.findIndex(part => (caseInsensitive ? part.toLowerCase() : part) === 'node_modules');
54
60
  if (dependency === 0) throw new Error(`Copy exclusion cannot target node_modules: ${path}`);
55
61
  if (dependency > 0 && dependency !== components.length - 1) {
56
62
  throw new Error(`Copy exclusion cannot target node_modules contents: ${path}`);
57
63
  }
58
- if (!existsSync(candidate)) throw new Error(`Copy exclusion does not exist: ${path}`);
59
- const parent = dirname(candidate);
60
- if (realpathSync(parent) !== parent) throw new Error(`Copy exclusion must not traverse a symbolic link: ${path}`);
61
- return candidate;
62
- });
64
+ let cursor = source;
65
+ let parentMissing = false;
66
+ for (let i = 0; i < components.length - 1; i++) {
67
+ cursor = resolve(cursor, components[i]);
68
+ const stat = lstatSync(cursor, { throwIfNoEntry: false });
69
+ if (!stat) {
70
+ parentMissing = true;
71
+ break;
72
+ }
73
+ if (stat.isSymbolicLink() || realpathSync(cursor) !== cursor) {
74
+ throw new Error(`Copy exclusion must not traverse a symbolic link: ${path}`);
75
+ }
76
+ if (!stat.isDirectory()) {
77
+ parentMissing = true;
78
+ break;
79
+ }
80
+ }
81
+ const key = normalizeExclusionKey(candidate);
82
+ if (parentMissing || !lstatSync(candidate, { throwIfNoEntry: false })) {
83
+ if (!seenMissing.has(key)) {
84
+ seenMissing.add(key);
85
+ onMissing?.(path, candidate);
86
+ }
87
+ continue;
88
+ }
89
+ if (!seenResolved.has(key)) {
90
+ seenResolved.add(key);
91
+ resolved.push(candidate);
92
+ }
93
+ }
94
+ return resolved;
63
95
  }
64
96
 
65
97
  export function copyPathIsExcluded(source, path, exclusions) {
98
+ const normalizedPath = normalizeExclusionKey(path);
66
99
  return relative(source, path).split(sep).some(part => excluded.has(part)) ||
67
- exclusions.some(exclusion => path === exclusion || path.startsWith(exclusion + sep));
100
+ exclusions.some(exclusion => {
101
+ const normalizedExclusion = normalizeExclusionKey(exclusion);
102
+ return normalizedPath === normalizedExclusion || normalizedPath.startsWith(normalizedExclusion + sep);
103
+ });
68
104
  }
69
105
 
70
106
  function linkInstalledModules(source, root, projectModules, installed, tools) {