@venizia/dev-configs 0.5.0-7 → 0.5.0-9
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 +15 -11
- package/dist/checks/purity/manifest.js +11 -3
- package/dist/checks/purity/manifest.js.map +1 -1
- package/dist/checks/purity/probe.js +19 -2
- package/dist/checks/purity/probe.js.map +1 -1
- package/dist/checks/split-report.js +2 -1
- package/dist/checks/split-report.js.map +1 -1
- package/dist/checks/test-controls.d.ts +9 -1
- package/dist/checks/test-controls.js +9 -3
- package/dist/checks/test-controls.js.map +1 -1
- package/dist/checks/test-dead-code.d.ts +9 -1
- package/dist/checks/test-dead-code.js +13 -2
- package/dist/checks/test-dead-code.js.map +1 -1
- package/dist/checks/test-mutate.d.ts +9 -1
- package/dist/checks/test-mutate.js +12 -6
- package/dist/checks/test-mutate.js.map +1 -1
- package/dist/cli/check.d.ts +0 -1
- package/dist/cli/check.js +42 -68
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/clean.js +3 -2
- package/dist/cli/clean.js.map +1 -1
- package/dist/cli/codemod/any-aliases.js +13 -12
- package/dist/cli/codemod/any-aliases.js.map +1 -1
- package/dist/cli/codemod/async-style.d.ts +1 -1
- package/dist/cli/codemod/async-style.js +17 -16
- package/dist/cli/codemod/async-style.js.map +1 -1
- package/dist/cli/codemod/binding-keys.js +14 -13
- package/dist/cli/codemod/binding-keys.js.map +1 -1
- package/dist/cli/codemod/class-renames.d.ts +1 -1
- package/dist/cli/codemod/class-renames.js +30 -11
- package/dist/cli/codemod/class-renames.js.map +1 -1
- package/dist/cli/codemod/connector-imports.js +12 -11
- package/dist/cli/codemod/connector-imports.js.map +1 -1
- package/dist/cli/codemod/const-classes.d.ts +1 -1
- package/dist/cli/codemod/const-classes.js +21 -20
- package/dist/cli/codemod/const-classes.js.map +1 -1
- package/dist/cli/codemod/drop-redundant-casts.d.ts +6 -1
- package/dist/cli/codemod/drop-redundant-casts.js +27 -19
- package/dist/cli/codemod/drop-redundant-casts.js.map +1 -1
- package/dist/cli/codemod/env-get.d.ts +3 -3
- package/dist/cli/codemod/env-get.js +18 -17
- package/dist/cli/codemod/env-get.js.map +1 -1
- package/dist/cli/codemod/files.js +2 -2
- package/dist/cli/codemod/files.js.map +1 -1
- package/dist/cli/codemod/function-to-arrow.d.ts +76 -0
- package/dist/cli/codemod/function-to-arrow.js +357 -0
- package/dist/cli/codemod/function-to-arrow.js.map +1 -0
- package/dist/cli/codemod/index.js +19 -4
- package/dist/cli/codemod/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/index.js +13 -12
- package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
- package/dist/cli/codemod/typed-route-context.d.ts +27 -0
- package/dist/cli/codemod/typed-route-context.js +570 -0
- package/dist/cli/codemod/typed-route-context.js.map +1 -0
- package/dist/cli/index.js +5 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/common/cli-output.d.ts +16 -0
- package/dist/common/cli-output.js +49 -0
- package/dist/common/cli-output.js.map +1 -0
- package/dist/compilers/bun.js +1 -1
- package/dist/compilers/bun.js.map +1 -1
- package/dist/linters/eslint.js +1 -1
- package/dist/linters/eslint.js.map +1 -1
- package/dist/linters/house/browser-api-patterns.d.ts +1 -3
- package/dist/linters/house/browser-api-patterns.js +1 -3
- package/dist/linters/house/browser-api-patterns.js.map +1 -1
- package/dist/linters/house/common.d.ts +8 -2
- package/dist/linters/house/common.js +8 -2
- package/dist/linters/house/common.js.map +1 -1
- package/dist/linters/house/configs.js +8 -6
- package/dist/linters/house/configs.js.map +1 -1
- package/dist/linters/house/const-class-values.rule.d.ts +2 -2
- package/dist/linters/house/const-class-values.rule.js +14 -5
- package/dist/linters/house/const-class-values.rule.js.map +1 -1
- package/dist/linters/house/effect-cleanup-consistency.rule.d.ts +2 -2
- package/dist/linters/house/effect-cleanup-consistency.rule.js +1 -1
- package/dist/linters/house/effect-cleanup-consistency.rule.js.map +1 -1
- package/dist/linters/house/framework-api-patterns.d.ts +54 -0
- package/dist/linters/house/framework-api-patterns.js +62 -0
- package/dist/linters/house/framework-api-patterns.js.map +1 -0
- package/dist/linters/house/framework-exports.d.ts +1 -1
- package/dist/linters/house/framework-exports.js +13 -13
- package/dist/linters/house/framework-exports.js.map +1 -1
- package/dist/linters/house/index.d.ts +3 -4
- package/dist/linters/house/index.js +4 -6
- package/dist/linters/house/index.js.map +1 -1
- package/dist/linters/house/max-params-own.rule.d.ts +2 -2
- package/dist/linters/house/max-params-own.rule.js +1 -1
- package/dist/linters/house/max-params-own.rule.js.map +1 -1
- package/dist/linters/house/no-async-hook-callback.rule.d.ts +2 -2
- package/dist/linters/house/no-async-hook-callback.rule.js +1 -1
- package/dist/linters/house/no-async-hook-callback.rule.js.map +1 -1
- package/dist/linters/house/no-await-new-chain.rule.d.ts +2 -2
- package/dist/linters/house/no-await-new-chain.rule.js +1 -1
- package/dist/linters/house/no-await-new-chain.rule.js.map +1 -1
- package/dist/linters/house/no-await-promise-chain.rule.d.ts +2 -2
- package/dist/linters/house/no-await-promise-chain.rule.js +5 -5
- package/dist/linters/house/no-await-promise-chain.rule.js.map +1 -1
- package/dist/linters/house/no-inline-await.rule.d.ts +2 -2
- package/dist/linters/house/no-inline-await.rule.js +1 -1
- package/dist/linters/house/no-inline-await.rule.js.map +1 -1
- package/dist/linters/house/no-leaked-render.rule.d.ts +2 -2
- package/dist/linters/house/no-leaked-render.rule.js +1 -1
- package/dist/linters/house/no-leaked-render.rule.js.map +1 -1
- package/dist/linters/house/no-new-error.rule.d.ts +2 -2
- package/dist/linters/house/no-new-error.rule.js +2 -2
- package/dist/linters/house/no-new-error.rule.js.map +1 -1
- package/dist/linters/house/no-parent-import.rule.d.ts +5 -2
- package/dist/linters/house/no-parent-import.rule.js +5 -2
- package/dist/linters/house/no-parent-import.rule.js.map +1 -1
- package/dist/linters/house/no-return-await.rule.d.ts +2 -2
- package/dist/linters/house/no-return-await.rule.js +1 -1
- package/dist/linters/house/no-return-await.rule.js.map +1 -1
- package/dist/linters/house/no-shadow-framework-type.rule.d.ts +2 -2
- package/dist/linters/house/no-shadow-framework-type.rule.js +2 -2
- package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -1
- package/dist/linters/house/no-silent-catch.rule.d.ts +2 -2
- package/dist/linters/house/no-silent-catch.rule.js +3 -3
- package/dist/linters/house/no-silent-catch.rule.js.map +1 -1
- package/dist/linters/house/no-unbraced-case.rule.d.ts +2 -2
- package/dist/linters/house/no-unbraced-case.rule.js +1 -1
- package/dist/linters/house/no-unbraced-case.rule.js.map +1 -1
- package/dist/linters/house/plugin.d.ts +1 -1
- package/dist/linters/house/plugin.js +6 -5
- package/dist/linters/house/plugin.js.map +1 -1
- package/dist/linters/house/prefer-framework-api.rule.d.ts +39 -7
- package/dist/linters/house/prefer-framework-api.rule.js +285 -12
- package/dist/linters/house/prefer-framework-api.rule.js.map +1 -1
- package/dist/linters/house/prefer-promise-sleep.rule.d.ts +2 -2
- package/dist/linters/house/prefer-promise-sleep.rule.js +3 -2
- package/dist/linters/house/prefer-promise-sleep.rule.js.map +1 -1
- package/dist/linters/house/prefer-tnullable.rule.d.ts +2 -2
- package/dist/linters/house/prefer-tnullable.rule.js +2 -2
- package/dist/linters/house/prefer-tnullable.rule.js.map +1 -1
- package/dist/linters/house/typed-route-context.rule.d.ts +19 -0
- package/dist/linters/house/typed-route-context.rule.js +322 -0
- package/dist/linters/house/typed-route-context.rule.js.map +1 -0
- package/dist/linters/house/zod-schema-convention.rule.d.ts +82 -0
- package/dist/linters/house/zod-schema-convention.rule.js +477 -0
- package/dist/linters/house/zod-schema-convention.rule.js.map +1 -0
- package/dist/linters/oxlint.js +11 -1
- package/dist/linters/oxlint.js.map +1 -1
- package/dist/linters/react-eslint.js.map +1 -1
- package/dist/linters/rules/naming-convention.rule.d.ts +4 -1
- package/dist/linters/rules/naming-convention.rule.js +30 -1
- package/dist/linters/rules/naming-convention.rule.js.map +1 -1
- package/dist/linters/rules/no-restricted-properties.rule.js +1 -1
- package/dist/linters/rules/no-restricted-properties.rule.js.map +1 -1
- package/dist/testing/spawn.utility.js +1 -1
- package/dist/testing/spawn.utility.js.map +1 -1
- package/package.json +5 -5
- package/dist/checks/use-when-baseline.d.ts +0 -25
- package/dist/checks/use-when-baseline.js +0 -38
- package/dist/checks/use-when-baseline.js.map +0 -1
- package/dist/linters/house/framework-rule-apis.d.ts +0 -24
- package/dist/linters/house/framework-rule-apis.js +0 -48
- package/dist/linters/house/framework-rule-apis.js.map +0 -1
- package/dist/linters/house/public-surface.d.ts +0 -57
- package/dist/linters/house/public-surface.js +0 -174
- package/dist/linters/house/public-surface.js.map +0 -1
- package/dist/linters/house/published-package-configs.d.ts +0 -23
- package/dist/linters/house/published-package-configs.js +0 -42
- package/dist/linters/house/published-package-configs.js.map +0 -1
- package/dist/linters/house/require-use-when.rule.d.ts +0 -42
- package/dist/linters/house/require-use-when.rule.js +0 -175
- package/dist/linters/house/require-use-when.rule.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-dead-code.js","sourceRoot":"","sources":["../../src/checks/test-dead-code.ts"],"names":[],"mappings":";;;AAAA,2DAA+C;AAC/C,yCAAoC;
|
|
1
|
+
{"version":3,"file":"test-dead-code.js","sourceRoot":"","sources":["../../src/checks/test-dead-code.ts"],"names":[],"mappings":";;;AAAA,2DAA+C;AAC/C,yCAAoC;AAIpC,sDAAsD;AACtD,MAAa,0BAA0B;aACrB,iBAAY,GAAG,cAAc,CAAC;aAC9B,sBAAiB,GAAG,mBAAmB,CAAC;;AAF1D,gEAGC;AAoBD,MAAM,iBAAiB,GAAG,kCAAkC,CAAC;AAC7D,MAAM,SAAS,GAAG,gCAAgC,CAAC;AAEnD,MAAM,GAAG,GAAG,CAAC,IAAsC,EAAsC,EAAE;IACzF,MAAM,MAAM,GAAG,IAAA,8BAAS,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE;QACzC,GAAG,EAAE,IAAI,CAAC,IAAI;QACd,QAAQ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EAAE,IAAI,EAAE,CAAC,EAC9E,CAAC;gBACD,SAAS;YACX,CAAC;YAED,MAAM,MAAM,GAAG,IAAA,mBAAO,EAAC,UAAU,CAAC,CAAC;YACnC,MAAM,gBAAgB,GACpB,MAAM,KAAK,GAAG,IAAI,mBAAmB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAEzF,UAAU,CAAC,IAAI,CAAC;gBACd,IAAI;gBACJ,IAAI,EAAE,gBAAgB;oBACpB,CAAC,CAAC,0BAA0B,CAAC,iBAAiB;oBAC9C,CAAC,CAAC,0BAA0B,CAAC,YAAY;aAC5C,CAAC,CAAC;QACL,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AAtCD,8CAsCC","sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { dirname } from 'node:path';\n\nimport type { TConstValue } from '../linters/rules/common';\n\n/** Why a support file is a candidate for deletion. */\nexport class DeadTestCodeCandidateTypes {\n static readonly UNREFERENCED = 'unreferenced';\n static readonly FOLDER_REFERENCED = 'folder-referenced';\n}\n\n/** One of `DeadTestCodeCandidateTypes`. */\nexport type TDeadTestCodeCandidateType = TConstValue<typeof DeadTestCodeCandidateTypes>;\n\n/**\n * Support files of the tests (fixtures, helpers, probes) that no other file refers to. The second\n * step of the trim-tests method. The output is CANDIDATES: a fixture can be loaded by a path built at\n * run time or by scanning a folder, so a candidate is deleted only after the package suite is green\n * without it.\n */\nexport interface IDeadTestCodeCandidate {\n file: string;\n /**\n * `unreferenced`: neither its name nor its path under `__tests__` appears in another file, nor does\n * its folder. `folder-referenced`: only its folder path does, so a scan of that folder may load it.\n */\n type: TDeadTestCodeCandidateType;\n}\n\nconst SUPPORT_EXTENSION = /\\.(?:[cm]?[jt]sx?|json|sql|txt)$/;\nconst TEST_FILE = /\\.(?:test|spec)\\.[cm]?[jt]sx?$/;\n\nconst git = (opts: { root: string; args: string[] }): { status: number; stdout: string } => {\n const result = spawnSync('git', opts.args, {\n cwd: opts.root,\n encoding: 'utf8',\n maxBuffer: 256 * 1024 * 1024,\n });\n\n return { status: result.status ?? 1, stdout: result.stdout ?? '' };\n};\n\n/** Files other than `self` whose text contains `needle` (a fixed string). */\nconst referencedElsewhere = (opts: { root: string; needle: string; self: string }): boolean => {\n const result = git({ root: opts.root, args: ['grep', '-l', '-I', '-F', '-e', opts.needle] });\n\n return result.stdout.split('\\n').some((line) => line !== '' && line !== opts.self);\n};\n\nconst escapeForRegex = (text: string): string => text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** Files other than `self` that mention the name of the file as a path segment or an import. */\nconst nameReferencedElsewhere = (opts: { root: string; stem: string; self: string }): boolean => {\n const pattern = `[/'\"\\`]${escapeForRegex(opts.stem)}(\\\\.|'|\"|\\`|$)`;\n const result = git({ root: opts.root, args: ['grep', '-l', '-I', '-E', '-e', pattern] });\n\n return result.stdout.split('\\n').some((line) => line !== '' && line !== opts.self);\n};\n\n/** Finds support files under `__tests__` (fixtures, helpers) that no tracked file refers to, using `git grep` in the given repository. */\nexport class DeadTestCodeCheck {\n static find(opts: { root: string }): IDeadTestCodeCandidate[] {\n const tracked = git({ root: opts.root, args: ['ls-files'] }).stdout.split('\\n');\n const support = tracked.filter(\n (file) =>\n file.includes('/__tests__/') &&\n SUPPORT_EXTENSION.test(file) &&\n !TEST_FILE.test(file) &&\n !file.endsWith('.d.ts'),\n );\n const candidates: IDeadTestCodeCandidate[] = [];\n\n for (const file of support) {\n const underTests = file.slice(file.indexOf('/__tests__/') + '/__tests__/'.length);\n const stem = underTests.split('/').pop()!.replace(SUPPORT_EXTENSION, '');\n const withoutExtension = underTests.replace(SUPPORT_EXTENSION, '');\n\n if (\n nameReferencedElsewhere({ root: opts.root, stem, self: file }) ||\n referencedElsewhere({ root: opts.root, needle: withoutExtension, self: file })\n ) {\n continue;\n }\n\n const folder = dirname(underTests);\n const folderReferenced =\n folder !== '.' && referencedElsewhere({ root: opts.root, needle: folder, self: file });\n\n candidates.push({\n file,\n type: folderReferenced\n ? DeadTestCodeCandidateTypes.FOLDER_REFERENCED\n : DeadTestCodeCandidateTypes.UNREFERENCED,\n });\n }\n\n return candidates;\n }\n}\n"]}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import type { TConstValue } from '../linters/rules/common';
|
|
2
|
+
/** What a ledger line expects of the candidate test under the mutant. */
|
|
3
|
+
export declare class CandidateExpectations {
|
|
4
|
+
static readonly RED = "red";
|
|
5
|
+
static readonly VACUOUS = "vacuous";
|
|
6
|
+
}
|
|
7
|
+
/** One of `CandidateExpectations`. */
|
|
8
|
+
export type TCandidateExpectation = TConstValue<typeof CandidateExpectations>;
|
|
1
9
|
/**
|
|
2
10
|
* Replays the mutation proof of the trim-tests method. A ledger line says: "this test (the
|
|
3
11
|
* candidate) is redundant because that test (the survivor) already catches the same break". The
|
|
@@ -42,7 +50,7 @@ export interface ILedgerLine {
|
|
|
42
50
|
*
|
|
43
51
|
* @default 'red'
|
|
44
52
|
*/
|
|
45
|
-
expectCandidate?:
|
|
53
|
+
expectCandidate?: TCandidateExpectation;
|
|
46
54
|
secondMutant?: IMutant | IMutant[];
|
|
47
55
|
}
|
|
48
56
|
/** The mutation ledger: every line to replay. */
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TestMutateCheck = void 0;
|
|
3
|
+
exports.TestMutateCheck = exports.CandidateExpectations = void 0;
|
|
4
4
|
const node_child_process_1 = require("node:child_process");
|
|
5
5
|
const node_fs_1 = require("node:fs");
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
|
+
/** What a ledger line expects of the candidate test under the mutant. */
|
|
8
|
+
class CandidateExpectations {
|
|
9
|
+
static { this.RED = 'red'; }
|
|
10
|
+
static { this.VACUOUS = 'vacuous'; }
|
|
11
|
+
}
|
|
12
|
+
exports.CandidateExpectations = CandidateExpectations;
|
|
7
13
|
const TEST_TIMEOUT_MILLISECONDS = 300_000;
|
|
8
14
|
/** The one place this tool builds an `Error`: `getError` would make dev-configs depend on inversion, which depends on dev-configs. */
|
|
9
|
-
// eslint-disable-next-line venizia/no-new-error -- getError would be a dev-configs -> inversion cycle
|
|
15
|
+
// eslint-disable-next-line @venizia/no-new-error -- getError would be a dev-configs -> inversion cycle
|
|
10
16
|
const replayError = (message) => new Error(message);
|
|
11
17
|
/** The nearest folder at or above the test file that holds a `package.json`: where `bun test` runs. */
|
|
12
18
|
const packageDirectoryOf = (opts) => {
|
|
@@ -26,7 +32,7 @@ const packageDirectoryOf = (opts) => {
|
|
|
26
32
|
const runIsRed = (opts) => {
|
|
27
33
|
const directory = packageDirectoryOf({ root: opts.root, file: opts.file });
|
|
28
34
|
const target = (0, node_path_1.join)(opts.root, opts.file).slice(directory.length + 1);
|
|
29
|
-
const args = ['test', target, ...(opts.name ? ['-t', opts.name] : [])];
|
|
35
|
+
const args = ['test', target, '--max-concurrency=6', ...(opts.name ? ['-t', opts.name] : [])];
|
|
30
36
|
const result = (0, node_child_process_1.spawnSync)('bun', args, {
|
|
31
37
|
cwd: directory,
|
|
32
38
|
encoding: 'utf8',
|
|
@@ -114,18 +120,18 @@ class TestMutateCheck {
|
|
|
114
120
|
}),
|
|
115
121
|
});
|
|
116
122
|
const result = { id: line.id, survivorRed, candidateRed, ok: true };
|
|
117
|
-
const expectation = line.expectCandidate ??
|
|
123
|
+
const expectation = line.expectCandidate ?? CandidateExpectations.RED;
|
|
118
124
|
if (!survivorRed) {
|
|
119
125
|
result.ok = false;
|
|
120
126
|
result.problem =
|
|
121
127
|
'the survivor stayed green under the mutant: it does not cover the behaviour';
|
|
122
128
|
}
|
|
123
|
-
else if (expectation ===
|
|
129
|
+
else if (expectation === CandidateExpectations.RED && !candidateRed) {
|
|
124
130
|
result.ok = false;
|
|
125
131
|
result.problem =
|
|
126
132
|
'the candidate stayed green under the mutant: record it as vacuous with a second mutant, or pick a mutant it checks';
|
|
127
133
|
}
|
|
128
|
-
else if (expectation ===
|
|
134
|
+
else if (expectation === CandidateExpectations.VACUOUS) {
|
|
129
135
|
if (!line.secondMutant) {
|
|
130
136
|
result.ok = false;
|
|
131
137
|
result.problem = 'a vacuous line needs a secondMutant';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-mutate.js","sourceRoot":"","sources":["../../src/checks/test-mutate.ts"],"names":[],"mappings":";;;AAAA,2DAA+C;AAC/C,qCAAqF;AACrF,yCAAmD;AAmEnD,MAAM,yBAAyB,GAAG,OAAO,CAAC;AAE1C,sIAAsI;AACtI,sGAAsG;AACtG,MAAM,WAAW,GAAG,CAAC,OAAe,EAAS,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAEnE,uGAAuG;AACvG,MAAM,kBAAkB,GAAG,CAAC,IAAoC,EAAU,EAAE;IAC1E,IAAI,OAAO,GAAG,IAAA,mBAAO,EAAC,IAAA,gBAAI,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAElD,SAAS,CAAC;QACR,IAAI,IAAA,oBAAU,EAAC,IAAA,gBAAI,EAAC,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;YAC9C,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,MAAM,MAAM,GAAG,IAAA,mBAAO,EAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAC3D,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;QAED,OAAO,GAAG,MAAM,CAAC;IACnB,CAAC;AACH,CAAC,CAAC;AAEF,uFAAuF;AACvF,MAAM,QAAQ,GAAG,CAAC,IAAmD,EAAW,EAAE;IAChF,MAAM,SAAS,GAAG,kBAAkB,CAAC,EAA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K,CAAC;IACf,CAAC;CACF;AAzED,0CAyEC","sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\n\n/**\n * Replays the mutation proof of the trim-tests method. A ledger line says: \"this test (the\n * candidate) is redundant because that test (the survivor) already catches the same break\". The\n * replay applies the break (the mutant) to a file, runs the survivor and the candidate, and puts the\n * file back. The survivor must go red. The candidate must go red too, unless the line says it is\n * vacuous and a second mutant leaves it green as well.\n *\n * The mutant edits the file the test really loads: the package's own `src` for a test that imports\n * through the `@/` alias, or the `dist` of the dependency for a test that reaches another package\n * through its `exports`. A rebuild is never needed.\n */\nexport interface IMutant {\n /** Repository-relative file to edit (a `src` file, or a `dist` file of a dependency). */\n file: string;\n /** Text that must occur exactly once in the file. */\n find: string;\n replace: string;\n}\n\n/** One ledger line: a candidate test that the survivor test makes redundant, or one that proves nothing (`vacuous`). */\nexport interface ILedgerLine {\n id: string;\n /** Repository-relative test file that is deleted. */\n candidate: string;\n /**\n * Run only the cases whose name matches (`bun test -t`).\n *\n * @default the whole file\n */\n candidateName?: string;\n /** Repository-relative test file that stays. */\n survivor: string;\n survivorName?: string;\n /**\n * The break. An array applies every edit together: a survivor in the package that owns the code\n * loads its `src`, a candidate in another package loads that package's `dist`, so one break is two edits.\n */\n mutant: IMutant | IMutant[];\n /** The source line the mutant stands for, `path:line`; recorded, not used by the replay. */\n srcLine?: string;\n /**\n * `red`: the candidate must fail. `vacuous`: it must stay green under `mutant` AND `secondMutant`.\n *\n * @default 'red'\n */\n expectCandidate?: 'red' | 'vacuous';\n secondMutant?: IMutant | IMutant[];\n}\n\n/** The mutation ledger: every line to replay. */\nexport interface ILedger {\n mutants: ILedgerLine[];\n}\n\n/** Result of replaying one ledger line; `ok` is false when the claim does not hold, with the reason in `problem`. */\nexport interface ILedgerResult {\n id: string;\n survivorRed: boolean;\n candidateRed: boolean;\n /** Only for a `vacuous` line: whether the candidate also stayed green under the second mutant. */\n candidateGreenUnderSecond?: boolean;\n ok: boolean;\n problem?: string;\n}\n\nconst TEST_TIMEOUT_MILLISECONDS = 300_000;\n\n/** The one place this tool builds an `Error`: `getError` would make dev-configs depend on inversion, which depends on dev-configs. */\n// eslint-disable-next-line venizia/no-new-error -- getError would be a dev-configs -> inversion cycle\nconst replayError = (message: string): Error => new Error(message);\n\n/** The nearest folder at or above the test file that holds a `package.json`: where `bun test` runs. */\nconst packageDirectoryOf = (opts: { root: string; file: string }): string => {\n let current = dirname(join(opts.root, opts.file));\n\n for (;;) {\n if (existsSync(join(current, 'package.json'))) {\n return current;\n }\n\n const parent = dirname(current);\n\n if (parent === current || parent.length < opts.root.length) {\n return opts.root;\n }\n\n current = parent;\n }\n};\n\n/** Runs one test file (or the cases matching `name`) and reports whether it failed. */\nconst runIsRed = (opts: { root: string; file: string; name?: string }): boolean => {\n const directory = packageDirectoryOf({ root: opts.root, file: opts.file });\n const target = join(opts.root, opts.file).slice(directory.length + 1);\n const args = ['test', target, ...(opts.name ? ['-t', opts.name] : [])];\n const result = spawnSync('bun', args, {\n cwd: directory,\n encoding: 'utf8',\n timeout: TEST_TIMEOUT_MILLISECONDS,\n killSignal: 'SIGKILL',\n env: { ...process.env, NODE_ENV: 'test' },\n });\n\n if (result.error) {\n throw replayError(`[test-mutate] could not run bun test ${target}: ${result.error.message}`);\n }\n\n // A name filter that matches nothing runs no case and exits 0: that would read as \"green\" and could\n // hide a typo as a vacuous test, so a run that executed nothing is an unusable ledger line.\n const output = `${result.stdout ?? ''}${result.stderr ?? ''}`;\n const passed = Number(/^\\s*(\\d+) pass/m.exec(output)?.[1] ?? 0);\n const failed = Number(/^\\s*(\\d+) fail/m.exec(output)?.[1] ?? 0);\n\n if (passed + failed === 0) {\n throw replayError(\n `[test-mutate] bun test ${target}${opts.name ? ` -t ${opts.name}` : ''} ran no case | check the file and the name`,\n );\n }\n\n return result.status !== 0 || failed > 0;\n};\n\n/** Applies `mutant`, runs `action`, and puts the file back byte for byte, verified byte for byte. */\nconst withMutant = <T>(opts: {\n root: string;\n mutant: IMutant;\n scratch: string;\n id: string;\n action: () => T;\n}): T => {\n const path = join(opts.root, opts.mutant.file);\n const original = readFileSync(path);\n const text = original.toString('utf8');\n const occurrences = text.split(opts.mutant.find).length - 1;\n\n if (occurrences !== 1) {\n throw replayError(\n `[test-mutate][${opts.id}] \\`find\\` occurs ${occurrences} times in ${opts.mutant.file}, it must occur exactly once`,\n );\n }\n\n mkdirSync(opts.scratch, { recursive: true });\n const backup = join(opts.scratch, `test-mutate-${opts.id.replace(/[^\\w.-]/g, '_')}.orig`);\n\n if (existsSync(backup)) {\n throw replayError(\n `[test-mutate][${opts.id}] a backup from an interrupted run exists: ${backup} | restore ${opts.mutant.file} from it, then delete it`,\n );\n }\n\n writeFileSync(backup, original);\n\n let outcome: { value: T } | { error: unknown };\n\n try {\n writeFileSync(\n path,\n text.replace(opts.mutant.find, () => opts.mutant.replace),\n );\n outcome = { value: opts.action() };\n } catch (error) {\n outcome = { error };\n }\n\n // Restored whatever the action did, and checked, before its result or error is passed on.\n writeFileSync(path, original);\n\n if (!readFileSync(path).equals(original)) {\n throw replayError(\n `[test-mutate][${opts.id}] ${opts.mutant.file} was not restored | the backup is ${backup}`,\n );\n }\n\n rmSync(backup, { force: true });\n\n if ('error' in outcome) {\n throw outcome.error;\n }\n\n return outcome.value;\n};\n\n/** Applies every edit of `mutant`, runs `action`, and puts each file back byte for byte, verified byte for byte. */\nconst withMutants = <T>(opts: {\n root: string;\n mutant: IMutant | IMutant[];\n scratch: string;\n id: string;\n action: () => T;\n}): T => {\n const edits = Array.isArray(opts.mutant) ? opts.mutant : [opts.mutant];\n\n const apply = (index: number): T =>\n index === edits.length\n ? opts.action()\n : withMutant({\n root: opts.root,\n mutant: edits[index],\n scratch: opts.scratch,\n id: `${opts.id}-${index}`,\n action: () => apply(index + 1),\n });\n\n return apply(0);\n};\n\n/** Replays the mutation ledger of the trim-tests method: applies each break, runs the survivor and candidate tests, and restores the file. */\nexport class TestMutateCheck {\n /** Replays every line; never throws for a green survivor (that is a result), only for an unusable ledger. */\n static replayLedger(opts: { root: string; ledger: ILedger; scratch?: string }): ILedgerResult[] {\n const root = resolve(opts.root);\n const scratch = opts.scratch ?? join(root, '.agents/local/tmp');\n const results: ILedgerResult[] = [];\n\n for (const line of opts.ledger.mutants) {\n const { survivorRed, candidateRed } = withMutants({\n root,\n mutant: line.mutant,\n scratch,\n id: line.id,\n action: () => ({\n survivorRed: runIsRed({ root, file: line.survivor, name: line.survivorName }),\n candidateRed: runIsRed({ root, file: line.candidate, name: line.candidateName }),\n }),\n });\n const result: ILedgerResult = { id: line.id, survivorRed, candidateRed, ok: true };\n const expectation = line.expectCandidate ?? 'red';\n\n if (!survivorRed) {\n result.ok = false;\n result.problem =\n 'the survivor stayed green under the mutant: it does not cover the behaviour';\n } else if (expectation === 'red' && !candidateRed) {\n result.ok = false;\n result.problem =\n 'the candidate stayed green under the mutant: record it as vacuous with a second mutant, or pick a mutant it checks';\n } else if (expectation === 'vacuous') {\n if (!line.secondMutant) {\n result.ok = false;\n result.problem = 'a vacuous line needs a secondMutant';\n } else if (candidateRed) {\n result.ok = false;\n result.problem = 'the candidate went red under the mutant: it is not vacuous';\n } else {\n const greenUnderSecond = !withMutants({\n root,\n mutant: line.secondMutant,\n scratch,\n id: `${line.id}-second`,\n action: () => runIsRed({ root, file: line.candidate, name: line.candidateName }),\n });\n result.candidateGreenUnderSecond = greenUnderSecond;\n\n if (!greenUnderSecond) {\n result.ok = false;\n result.problem = 'the candidate went red under the second mutant: it is not vacuous';\n }\n }\n }\n\n results.push(result);\n }\n\n return results;\n }\n\n /** The report lines of a replay, one per ledger line and a closing tally. */\n static formatLedgerResults(opts: { results: ILedgerResult[] }): string[] {\n const { results } = opts;\n const lines = results.map(\n (result) =>\n `${result.ok ? 'ok ' : 'FAIL'} ${result.id}: survivor ${result.survivorRed ? 'red' : 'GREEN'}, candidate ${result.candidateRed ? 'red' : 'green'}${result.problem ? ` | ${result.problem}` : ''}`,\n );\n const failed = results.filter((result) => !result.ok).length;\n lines.push(\n `\\n[test-mutate] ${results.length - failed}/${results.length} ledger lines hold${failed ? `, ${failed} do not` : ''}.`,\n );\n\n return lines;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"test-mutate.js","sourceRoot":"","sources":["../../src/checks/test-mutate.ts"],"names":[],"mappings":";;;AAAA,2DAA+C;AAC/C,qCAAqF;AACrF,yCAAmD;AAInD,yEAAyE;AACzE,MAAa,qBAAqB;aAChB,QAAG,GAAG,KAAK,CAAC;aACZ,YAAO,GAAG,SAAS,CAAC;;AAFtC,sDAGC;AAsED,MAAM,yBAAyB,GAAG,OAAO,CAAC;AAE1C,sIAAsI;AACtI,uGAAuG;AACvG,MAAM,WAAW,GAAG,CAAC,OAAe,EAAS,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAEnE,uGAAuG;AACvG,MAAM,kBAAkB,GAAG,CAAC,IAAoC,EAAU,EAAE;IAC1E,IAAI,OAAO,GAAG,IAAA,mBAAO,EAAC,IAAA,gBAAI,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAElD,SAAS,CAAC;QACR,IAAI,IAAA,oBAAU,EAAC,IAAA,gBAAI,EAAC,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;YAC9C,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,MAAM,MAAM,GAAG,IAAA,mBAAO,EAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAC3D,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;QAED,OAAO,GAAG,MAAM,CAAC;IACnB,CAAC;AACH,CAAC,CAAC;AAEF,uFAAuF;AACvF,MAAM,QAAQ,GAAG,CAAC,IA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AAC,MAAM,qBAAqB,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,CACvH,CAAC;QAEF,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAzED,0CAyEC","sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\n\nimport type { TConstValue } from '../linters/rules/common';\n\n/** What a ledger line expects of the candidate test under the mutant. */\nexport class CandidateExpectations {\n static readonly RED = 'red';\n static readonly VACUOUS = 'vacuous';\n}\n\n/** One of `CandidateExpectations`. */\nexport type TCandidateExpectation = TConstValue<typeof CandidateExpectations>;\n\n/**\n * Replays the mutation proof of the trim-tests method. A ledger line says: \"this test (the\n * candidate) is redundant because that test (the survivor) already catches the same break\". The\n * replay applies the break (the mutant) to a file, runs the survivor and the candidate, and puts the\n * file back. The survivor must go red. The candidate must go red too, unless the line says it is\n * vacuous and a second mutant leaves it green as well.\n *\n * The mutant edits the file the test really loads: the package's own `src` for a test that imports\n * through the `@/` alias, or the `dist` of the dependency for a test that reaches another package\n * through its `exports`. A rebuild is never needed.\n */\nexport interface IMutant {\n /** Repository-relative file to edit (a `src` file, or a `dist` file of a dependency). */\n file: string;\n /** Text that must occur exactly once in the file. */\n find: string;\n replace: string;\n}\n\n/** One ledger line: a candidate test that the survivor test makes redundant, or one that proves nothing (`vacuous`). */\nexport interface ILedgerLine {\n id: string;\n /** Repository-relative test file that is deleted. */\n candidate: string;\n /**\n * Run only the cases whose name matches (`bun test -t`).\n *\n * @default the whole file\n */\n candidateName?: string;\n /** Repository-relative test file that stays. */\n survivor: string;\n survivorName?: string;\n /**\n * The break. An array applies every edit together: a survivor in the package that owns the code\n * loads its `src`, a candidate in another package loads that package's `dist`, so one break is two edits.\n */\n mutant: IMutant | IMutant[];\n /** The source line the mutant stands for, `path:line`; recorded, not used by the replay. */\n srcLine?: string;\n /**\n * `red`: the candidate must fail. `vacuous`: it must stay green under `mutant` AND `secondMutant`.\n *\n * @default 'red'\n */\n expectCandidate?: TCandidateExpectation;\n secondMutant?: IMutant | IMutant[];\n}\n\n/** The mutation ledger: every line to replay. */\nexport interface ILedger {\n mutants: ILedgerLine[];\n}\n\n/** Result of replaying one ledger line; `ok` is false when the claim does not hold, with the reason in `problem`. */\nexport interface ILedgerResult {\n id: string;\n survivorRed: boolean;\n candidateRed: boolean;\n /** Only for a `vacuous` line: whether the candidate also stayed green under the second mutant. */\n candidateGreenUnderSecond?: boolean;\n ok: boolean;\n problem?: string;\n}\n\nconst TEST_TIMEOUT_MILLISECONDS = 300_000;\n\n/** The one place this tool builds an `Error`: `getError` would make dev-configs depend on inversion, which depends on dev-configs. */\n// eslint-disable-next-line @venizia/no-new-error -- getError would be a dev-configs -> inversion cycle\nconst replayError = (message: string): Error => new Error(message);\n\n/** The nearest folder at or above the test file that holds a `package.json`: where `bun test` runs. */\nconst packageDirectoryOf = (opts: { root: string; file: string }): string => {\n let current = dirname(join(opts.root, opts.file));\n\n for (;;) {\n if (existsSync(join(current, 'package.json'))) {\n return current;\n }\n\n const parent = dirname(current);\n\n if (parent === current || parent.length < opts.root.length) {\n return opts.root;\n }\n\n current = parent;\n }\n};\n\n/** Runs one test file (or the cases matching `name`) and reports whether it failed. */\nconst runIsRed = (opts: { root: string; file: string; name?: string }): boolean => {\n const directory = packageDirectoryOf({ root: opts.root, file: opts.file });\n const target = join(opts.root, opts.file).slice(directory.length + 1);\n const args = ['test', target, '--max-concurrency=6', ...(opts.name ? ['-t', opts.name] : [])];\n const result = spawnSync('bun', args, {\n cwd: directory,\n encoding: 'utf8',\n timeout: TEST_TIMEOUT_MILLISECONDS,\n killSignal: 'SIGKILL',\n env: { ...process.env, NODE_ENV: 'test' },\n });\n\n if (result.error) {\n throw replayError(`[test-mutate] could not run bun test ${target}: ${result.error.message}`);\n }\n\n // A name filter that matches nothing runs no case and exits 0: that would read as \"green\" and could\n // hide a typo as a vacuous test, so a run that executed nothing is an unusable ledger line.\n const output = `${result.stdout ?? ''}${result.stderr ?? ''}`;\n const passed = Number(/^\\s*(\\d+) pass/m.exec(output)?.[1] ?? 0);\n const failed = Number(/^\\s*(\\d+) fail/m.exec(output)?.[1] ?? 0);\n\n if (passed + failed === 0) {\n throw replayError(\n `[test-mutate] bun test ${target}${opts.name ? ` -t ${opts.name}` : ''} ran no case | check the file and the name`,\n );\n }\n\n return result.status !== 0 || failed > 0;\n};\n\n/** Applies `mutant`, runs `action`, and puts the file back byte for byte, verified byte for byte. */\nconst withMutant = <T>(opts: {\n root: string;\n mutant: IMutant;\n scratch: string;\n id: string;\n action: () => T;\n}): T => {\n const path = join(opts.root, opts.mutant.file);\n const original = readFileSync(path);\n const text = original.toString('utf8');\n const occurrences = text.split(opts.mutant.find).length - 1;\n\n if (occurrences !== 1) {\n throw replayError(\n `[test-mutate][${opts.id}] \\`find\\` occurs ${occurrences} times in ${opts.mutant.file}, it must occur exactly once`,\n );\n }\n\n mkdirSync(opts.scratch, { recursive: true });\n const backup = join(opts.scratch, `test-mutate-${opts.id.replace(/[^\\w.-]/g, '_')}.orig`);\n\n if (existsSync(backup)) {\n throw replayError(\n `[test-mutate][${opts.id}] a backup from an interrupted run exists: ${backup} | restore ${opts.mutant.file} from it, then delete it`,\n );\n }\n\n writeFileSync(backup, original);\n\n let outcome: { value: T } | { error: unknown };\n\n try {\n writeFileSync(\n path,\n text.replace(opts.mutant.find, () => opts.mutant.replace),\n );\n outcome = { value: opts.action() };\n } catch (error) {\n outcome = { error };\n }\n\n // Restored whatever the action did, and checked, before its result or error is passed on.\n writeFileSync(path, original);\n\n if (!readFileSync(path).equals(original)) {\n throw replayError(\n `[test-mutate][${opts.id}] ${opts.mutant.file} was not restored | the backup is ${backup}`,\n );\n }\n\n rmSync(backup, { force: true });\n\n if ('error' in outcome) {\n throw outcome.error;\n }\n\n return outcome.value;\n};\n\n/** Applies every edit of `mutant`, runs `action`, and puts each file back byte for byte, verified byte for byte. */\nconst withMutants = <T>(opts: {\n root: string;\n mutant: IMutant | IMutant[];\n scratch: string;\n id: string;\n action: () => T;\n}): T => {\n const edits = Array.isArray(opts.mutant) ? opts.mutant : [opts.mutant];\n\n const apply = (index: number): T =>\n index === edits.length\n ? opts.action()\n : withMutant({\n root: opts.root,\n mutant: edits[index],\n scratch: opts.scratch,\n id: `${opts.id}-${index}`,\n action: () => apply(index + 1),\n });\n\n return apply(0);\n};\n\n/** Replays the mutation ledger of the trim-tests method: applies each break, runs the survivor and candidate tests, and restores the file. */\nexport class TestMutateCheck {\n /** Replays every line; never throws for a green survivor (that is a result), only for an unusable ledger. */\n static replayLedger(opts: { root: string; ledger: ILedger; scratch?: string }): ILedgerResult[] {\n const root = resolve(opts.root);\n const scratch = opts.scratch ?? join(root, '.agents/local/tmp');\n const results: ILedgerResult[] = [];\n\n for (const line of opts.ledger.mutants) {\n const { survivorRed, candidateRed } = withMutants({\n root,\n mutant: line.mutant,\n scratch,\n id: line.id,\n action: () => ({\n survivorRed: runIsRed({ root, file: line.survivor, name: line.survivorName }),\n candidateRed: runIsRed({ root, file: line.candidate, name: line.candidateName }),\n }),\n });\n const result: ILedgerResult = { id: line.id, survivorRed, candidateRed, ok: true };\n const expectation = line.expectCandidate ?? CandidateExpectations.RED;\n\n if (!survivorRed) {\n result.ok = false;\n result.problem =\n 'the survivor stayed green under the mutant: it does not cover the behaviour';\n } else if (expectation === CandidateExpectations.RED && !candidateRed) {\n result.ok = false;\n result.problem =\n 'the candidate stayed green under the mutant: record it as vacuous with a second mutant, or pick a mutant it checks';\n } else if (expectation === CandidateExpectations.VACUOUS) {\n if (!line.secondMutant) {\n result.ok = false;\n result.problem = 'a vacuous line needs a secondMutant';\n } else if (candidateRed) {\n result.ok = false;\n result.problem = 'the candidate went red under the mutant: it is not vacuous';\n } else {\n const greenUnderSecond = !withMutants({\n root,\n mutant: line.secondMutant,\n scratch,\n id: `${line.id}-second`,\n action: () => runIsRed({ root, file: line.candidate, name: line.candidateName }),\n });\n result.candidateGreenUnderSecond = greenUnderSecond;\n\n if (!greenUnderSecond) {\n result.ok = false;\n result.problem = 'the candidate went red under the second mutant: it is not vacuous';\n }\n }\n }\n\n results.push(result);\n }\n\n return results;\n }\n\n /** The report lines of a replay, one per ledger line and a closing tally. */\n static formatLedgerResults(opts: { results: ILedgerResult[] }): string[] {\n const { results } = opts;\n const lines = results.map(\n (result) =>\n `${result.ok ? 'ok ' : 'FAIL'} ${result.id}: survivor ${result.survivorRed ? 'red' : 'GREEN'}, candidate ${result.candidateRed ? 'red' : 'green'}${result.problem ? ` | ${result.problem}` : ''}`,\n );\n const failed = results.filter((result) => !result.ok).length;\n lines.push(\n `\\n[test-mutate] ${results.length - failed}/${results.length} ledger lines hold${failed ? `, ${failed} do not` : ''}.`,\n );\n\n return lines;\n }\n}\n"]}
|
package/dist/cli/check.d.ts
CHANGED
package/dist/cli/check.js
CHANGED
|
@@ -7,11 +7,11 @@ const catalog_1 = require("../checks/catalog");
|
|
|
7
7
|
const module_cycles_1 = require("../checks/module-cycles");
|
|
8
8
|
const run_1 = require("../checks/purity/run");
|
|
9
9
|
const split_report_1 = require("../checks/split-report");
|
|
10
|
-
const use_when_baseline_1 = require("../checks/use-when-baseline");
|
|
11
10
|
const test_controls_1 = require("../checks/test-controls");
|
|
12
11
|
const test_dead_code_1 = require("../checks/test-dead-code");
|
|
13
12
|
const test_mutate_1 = require("../checks/test-mutate");
|
|
14
13
|
const test_weight_1 = require("../checks/test-weight");
|
|
14
|
+
const cli_output_1 = require("../common/cli-output");
|
|
15
15
|
const USAGE = `Usage: devz check <name> [options]
|
|
16
16
|
|
|
17
17
|
Checks:
|
|
@@ -24,8 +24,6 @@ Checks:
|
|
|
24
24
|
test-dead-code list support files under __tests__ that no other file refers to (candidates)
|
|
25
25
|
test-mutate <ledger.json> replay a mutation ledger: the survivor must go red under each mutant
|
|
26
26
|
test-controls <registry.json> fail when a registered positive-control test is gone
|
|
27
|
-
use-when-baseline [--write] [--out <file>] [--entry <file>]...
|
|
28
|
-
list (or write) the exports of the package in this folder that still lack a @useWhen
|
|
29
27
|
|
|
30
28
|
purity
|
|
31
29
|
--claims <file> a module that exports PURITY_CLAIMS (the claims) and, optionally, PURITY_OPTIONS
|
|
@@ -35,7 +33,7 @@ purity
|
|
|
35
33
|
|
|
36
34
|
test-weight, test-dead-code, test-mutate, test-controls: the tools of the trim-tests method, see
|
|
37
35
|
.agents/knowledge/process/trimming-tests.md in the IGNIS repository. Produce the JUnit files with
|
|
38
|
-
bun test ./src --parallel --reporter=junit --reporter-outfile=<file>.
|
|
36
|
+
bun test ./src --parallel=6 --max-concurrency=6 --reporter=junit --reporter-outfile=<file>.
|
|
39
37
|
|
|
40
38
|
module-cycles
|
|
41
39
|
<dir>, or --dist <dir> the built folder (dist/esm); exits 1 when more cycles than --max, 2 on a usage error
|
|
@@ -108,7 +106,7 @@ class CheckCommand {
|
|
|
108
106
|
static runTestWeight(opts) {
|
|
109
107
|
const parsed = parseRepeatable({ args: opts.args, repeatable: [], single: ['top'] });
|
|
110
108
|
if (typeof parsed === 'string' || parsed.positionals.length === 0) {
|
|
111
|
-
|
|
109
|
+
cli_output_1.CliOutput.error(`devz check test-weight: ${typeof parsed === 'string' ? parsed : 'give at least one JUnit file'}\n${USAGE}`);
|
|
112
110
|
return USAGE_ERROR_CODE;
|
|
113
111
|
}
|
|
114
112
|
const reports = parsed.positionals.map((file) => {
|
|
@@ -120,7 +118,7 @@ class CheckCommand {
|
|
|
120
118
|
});
|
|
121
119
|
const missing = parsed.positionals.filter((file) => !(0, node_fs_1.existsSync)((0, node_path_1.resolve)(opts.root, file)));
|
|
122
120
|
if (missing.length > 0) {
|
|
123
|
-
|
|
121
|
+
cli_output_1.CliOutput.error(`devz check test-weight: not found: ${missing.join(', ')}`);
|
|
124
122
|
return USAGE_ERROR_CODE;
|
|
125
123
|
}
|
|
126
124
|
const top = parsed.values.top?.[0] === undefined ? undefined : Number(parsed.values.top[0]);
|
|
@@ -128,79 +126,82 @@ class CheckCommand {
|
|
|
128
126
|
report: test_weight_1.TestWeightCheck.analyseJunit({ reports }),
|
|
129
127
|
top,
|
|
130
128
|
})) {
|
|
131
|
-
|
|
129
|
+
cli_output_1.CliOutput.log(line);
|
|
132
130
|
}
|
|
133
131
|
return 0;
|
|
134
132
|
}
|
|
135
133
|
static runTestDeadCode(opts) {
|
|
136
134
|
if (opts.args.length > 0) {
|
|
137
|
-
|
|
135
|
+
cli_output_1.CliOutput.error(`devz check test-dead-code: unexpected argument "${opts.args[0]}"\n${USAGE}`);
|
|
138
136
|
return USAGE_ERROR_CODE;
|
|
139
137
|
}
|
|
140
138
|
const candidates = test_dead_code_1.DeadTestCodeCheck.find({ root: opts.root });
|
|
141
|
-
for (const
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
for (const type of [
|
|
140
|
+
test_dead_code_1.DeadTestCodeCandidateTypes.UNREFERENCED,
|
|
141
|
+
test_dead_code_1.DeadTestCodeCandidateTypes.FOLDER_REFERENCED,
|
|
142
|
+
]) {
|
|
143
|
+
const own = candidates.filter((candidate) => candidate.type === type);
|
|
144
|
+
cli_output_1.CliOutput.log(`${type}: ${own.length}`);
|
|
144
145
|
for (const candidate of own) {
|
|
145
|
-
|
|
146
|
+
cli_output_1.CliOutput.log(` ${candidate.file}`);
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
|
-
|
|
149
|
+
cli_output_1.CliOutput.log('\nThese are candidates: delete one, run the package suite, and keep it if anything fails or loads it by a built path.');
|
|
149
150
|
return 0;
|
|
150
151
|
}
|
|
151
152
|
static runTestMutate(opts) {
|
|
152
153
|
const [file, ...extra] = opts.args;
|
|
153
154
|
if (file === undefined || extra.length > 0) {
|
|
154
|
-
|
|
155
|
+
cli_output_1.CliOutput.error(`devz check test-mutate: give one ledger file\n${USAGE}`);
|
|
155
156
|
return USAGE_ERROR_CODE;
|
|
156
157
|
}
|
|
157
158
|
const path = (0, node_path_1.resolve)(opts.root, file);
|
|
158
159
|
if (!(0, node_fs_1.existsSync)(path)) {
|
|
159
|
-
|
|
160
|
+
cli_output_1.CliOutput.error(`devz check test-mutate: ledger not found: ${file}`);
|
|
160
161
|
return USAGE_ERROR_CODE;
|
|
161
162
|
}
|
|
162
163
|
const ledger = JSON.parse((0, node_fs_1.readFileSync)(path, 'utf8'));
|
|
163
164
|
if (!Array.isArray(ledger.mutants)) {
|
|
164
|
-
|
|
165
|
+
cli_output_1.CliOutput.error(`devz check test-mutate: ${file} has no "mutants" array`);
|
|
165
166
|
return USAGE_ERROR_CODE;
|
|
166
167
|
}
|
|
167
168
|
const results = test_mutate_1.TestMutateCheck.replayLedger({ root: opts.root, ledger });
|
|
168
169
|
for (const line of test_mutate_1.TestMutateCheck.formatLedgerResults({ results })) {
|
|
169
|
-
|
|
170
|
+
cli_output_1.CliOutput.log(line);
|
|
170
171
|
}
|
|
171
172
|
return results.every((result) => result.ok) ? 0 : 1;
|
|
172
173
|
}
|
|
173
174
|
static async runTestControls(opts) {
|
|
174
175
|
const [file, ...extra] = opts.args;
|
|
175
176
|
if (file === undefined || extra.length > 0) {
|
|
176
|
-
|
|
177
|
+
cli_output_1.CliOutput.error(`devz check test-controls: give one registry file\n${USAGE}`);
|
|
177
178
|
return USAGE_ERROR_CODE;
|
|
178
179
|
}
|
|
179
180
|
const path = (0, node_path_1.resolve)(opts.root, file);
|
|
180
181
|
if (!(0, node_fs_1.existsSync)(path)) {
|
|
181
|
-
|
|
182
|
+
cli_output_1.CliOutput.error(`devz check test-controls: registry not found: ${file}`);
|
|
182
183
|
return USAGE_ERROR_CODE;
|
|
183
184
|
}
|
|
184
185
|
const registry = JSON.parse((0, node_fs_1.readFileSync)(path, 'utf8'));
|
|
185
186
|
if (!Array.isArray(registry.controls)) {
|
|
186
|
-
|
|
187
|
+
cli_output_1.CliOutput.error(`devz check test-controls: ${file} has no "controls" array`);
|
|
187
188
|
return USAGE_ERROR_CODE;
|
|
188
189
|
}
|
|
189
190
|
const report = await test_controls_1.TestControlsCheck.run({ root: opts.root, controls: registry.controls });
|
|
190
191
|
if (report.problems.length === 0) {
|
|
191
|
-
|
|
192
|
+
cli_output_1.CliOutput.log(`test-controls: OK - ${report.checked} registered controls found`);
|
|
192
193
|
return 0;
|
|
193
194
|
}
|
|
194
|
-
|
|
195
|
+
cli_output_1.CliOutput.error(`test-controls: ${report.problems.length} of ${report.checked} registered controls are gone:`);
|
|
195
196
|
for (const problem of report.problems) {
|
|
196
|
-
|
|
197
|
+
cli_output_1.CliOutput.error(` [${problem.entry.gate}] ${problem.message}`);
|
|
197
198
|
}
|
|
198
199
|
return 1;
|
|
199
200
|
}
|
|
200
201
|
static runSplitReport(opts) {
|
|
201
202
|
const parsed = parseRepeatable({ args: opts.args, repeatable: [], single: ['dist'] });
|
|
202
203
|
if (typeof parsed === 'string') {
|
|
203
|
-
|
|
204
|
+
cli_output_1.CliOutput.error(`devz check split-report: ${parsed}\n${USAGE}`);
|
|
204
205
|
return USAGE_ERROR_CODE;
|
|
205
206
|
}
|
|
206
207
|
const targets = parsed.positionals.length
|
|
@@ -218,7 +219,7 @@ class CheckCommand {
|
|
|
218
219
|
single: ['preset-prefix'],
|
|
219
220
|
});
|
|
220
221
|
if (typeof parsed === 'string' || parsed.positionals.length > 0) {
|
|
221
|
-
|
|
222
|
+
cli_output_1.CliOutput.error(`devz check catalog: ${typeof parsed === 'string' ? parsed : `unexpected argument "${parsed.positionals[0]}"`}\n${USAGE}`);
|
|
222
223
|
return USAGE_ERROR_CODE;
|
|
223
224
|
}
|
|
224
225
|
const report = await catalog_1.CatalogCheck.find({
|
|
@@ -228,55 +229,31 @@ class CheckCommand {
|
|
|
228
229
|
presetPrefix: parsed.values['preset-prefix']?.[0],
|
|
229
230
|
});
|
|
230
231
|
if (report.noCatalog) {
|
|
231
|
-
|
|
232
|
+
cli_output_1.CliOutput.error('check-catalog: no `workspaces.catalog` in the root package.json');
|
|
232
233
|
return 1;
|
|
233
234
|
}
|
|
234
235
|
if (report.problems.length === 0) {
|
|
235
|
-
|
|
236
|
+
cli_output_1.CliOutput.log(`check-catalog: OK - ${report.entries} entries, ${report.referenced} referenced`);
|
|
236
237
|
return 0;
|
|
237
238
|
}
|
|
238
|
-
|
|
239
|
+
cli_output_1.CliOutput.error(`check-catalog: ${report.problems.length} problem(s):`);
|
|
239
240
|
for (const problem of report.problems) {
|
|
240
|
-
|
|
241
|
+
cli_output_1.CliOutput.error(` ${problem.file}: ${problem.message}`);
|
|
241
242
|
}
|
|
242
243
|
return 1;
|
|
243
244
|
}
|
|
244
|
-
static runUseWhenBaseline(opts) {
|
|
245
|
-
const write = opts.args.includes('--write');
|
|
246
|
-
const parsed = parseRepeatable({
|
|
247
|
-
args: opts.args.filter((arg) => arg !== '--write'),
|
|
248
|
-
repeatable: ['entry'],
|
|
249
|
-
single: ['out'],
|
|
250
|
-
});
|
|
251
|
-
if (typeof parsed === 'string' || parsed.positionals.length > 0) {
|
|
252
|
-
console.error(`devz check use-when-baseline: ${typeof parsed === 'string' ? parsed : `unexpected argument "${parsed.positionals[0]}"`}\n${USAGE}`);
|
|
253
|
-
return USAGE_ERROR_CODE;
|
|
254
|
-
}
|
|
255
|
-
const entries = use_when_baseline_1.UseWhenBaseline.entries({ directory: opts.root, entries: parsed.values.entry });
|
|
256
|
-
const target = use_when_baseline_1.UseWhenBaseline.pathOf({ root: opts.root, out: parsed.values.out?.[0] });
|
|
257
|
-
if (write) {
|
|
258
|
-
(0, node_fs_1.writeFileSync)(target, use_when_baseline_1.UseWhenBaseline.render({ entries }));
|
|
259
|
-
console.log(`use-when-baseline: wrote ${entries.length} entries to ${(0, node_path_1.relative)(opts.root, target)}`);
|
|
260
|
-
return 0;
|
|
261
|
-
}
|
|
262
|
-
console.log(`use-when-baseline: ${entries.length} exports lack a @useWhen`);
|
|
263
|
-
for (const entry of entries) {
|
|
264
|
-
console.log(` ${entry}`);
|
|
265
|
-
}
|
|
266
|
-
return 0;
|
|
267
|
-
}
|
|
268
245
|
static async run(opts) {
|
|
269
246
|
const { root, args = [] } = opts;
|
|
270
247
|
const [name, ...rest] = args;
|
|
271
248
|
if (name === undefined || name === '--help' || name === '-h') {
|
|
272
|
-
|
|
249
|
+
cli_output_1.CliOutput.log(USAGE);
|
|
273
250
|
return name === undefined ? USAGE_ERROR_CODE : 0;
|
|
274
251
|
}
|
|
275
252
|
if (name === 'module-cycles') {
|
|
276
253
|
return module_cycles_1.ModuleCyclesCheck.run({
|
|
277
254
|
args: rest,
|
|
278
|
-
print: (line) =>
|
|
279
|
-
printError: (line) =>
|
|
255
|
+
print: (line) => cli_output_1.CliOutput.log(line),
|
|
256
|
+
printError: (line) => cli_output_1.CliOutput.error(line),
|
|
280
257
|
});
|
|
281
258
|
}
|
|
282
259
|
if (name === 'split-report') {
|
|
@@ -294,39 +271,36 @@ class CheckCommand {
|
|
|
294
271
|
if (name === 'test-mutate') {
|
|
295
272
|
return CheckCommand.runTestMutate({ root, args: rest });
|
|
296
273
|
}
|
|
297
|
-
if (name === 'use-when-baseline') {
|
|
298
|
-
return CheckCommand.runUseWhenBaseline({ root, args: rest });
|
|
299
|
-
}
|
|
300
274
|
if (name === 'test-controls') {
|
|
301
275
|
return CheckCommand.runTestControls({ root, args: rest });
|
|
302
276
|
}
|
|
303
277
|
if (name !== 'purity') {
|
|
304
|
-
|
|
278
|
+
cli_output_1.CliOutput.error(`devz check: unknown check "${name}"\n${USAGE}`);
|
|
305
279
|
return USAGE_ERROR_CODE;
|
|
306
280
|
}
|
|
307
281
|
if (rest.includes('--help') || rest.includes('-h')) {
|
|
308
|
-
|
|
282
|
+
cli_output_1.CliOutput.log(USAGE);
|
|
309
283
|
return 0;
|
|
310
284
|
}
|
|
311
285
|
const parsed = parsePurityArguments(rest);
|
|
312
286
|
if (typeof parsed === 'string') {
|
|
313
|
-
|
|
287
|
+
cli_output_1.CliOutput.error(`devz check purity: ${parsed}\n${USAGE}`);
|
|
314
288
|
return USAGE_ERROR_CODE;
|
|
315
289
|
}
|
|
316
290
|
if (parsed.claimsFile === undefined) {
|
|
317
|
-
|
|
291
|
+
cli_output_1.CliOutput.error(`devz check purity: --claims <file> is required\n${USAGE}`);
|
|
318
292
|
return USAGE_ERROR_CODE;
|
|
319
293
|
}
|
|
320
294
|
const claimsPath = (0, node_path_1.isAbsolute)(parsed.claimsFile)
|
|
321
295
|
? parsed.claimsFile
|
|
322
296
|
: (0, node_path_1.resolve)(root, parsed.claimsFile);
|
|
323
297
|
if (!(0, node_fs_1.existsSync)(claimsPath)) {
|
|
324
|
-
|
|
298
|
+
cli_output_1.CliOutput.error(`devz check purity: claims file not found: ${parsed.claimsFile}`);
|
|
325
299
|
return USAGE_ERROR_CODE;
|
|
326
300
|
}
|
|
327
301
|
const claimsModule = await import(claimsPath);
|
|
328
302
|
if (!Array.isArray(claimsModule.PURITY_CLAIMS)) {
|
|
329
|
-
|
|
303
|
+
cli_output_1.CliOutput.error(`devz check purity: ${parsed.claimsFile} does not export PURITY_CLAIMS`);
|
|
330
304
|
return USAGE_ERROR_CODE;
|
|
331
305
|
}
|
|
332
306
|
const lines = [];
|
|
@@ -336,14 +310,14 @@ class CheckCommand {
|
|
|
336
310
|
options: claimsModule.PURITY_OPTIONS,
|
|
337
311
|
filter: parsed.filter,
|
|
338
312
|
claimsFile: (0, node_path_1.relative)(root, claimsPath),
|
|
339
|
-
print: (line) => (parsed.json ? lines.push(line) :
|
|
340
|
-
printError: (line) =>
|
|
313
|
+
print: (line) => (parsed.json ? lines.push(line) : cli_output_1.CliOutput.log(line)),
|
|
314
|
+
printError: (line) => cli_output_1.CliOutput.error(line),
|
|
341
315
|
});
|
|
342
316
|
if (report === undefined) {
|
|
343
317
|
return 1;
|
|
344
318
|
}
|
|
345
319
|
if (parsed.json) {
|
|
346
|
-
|
|
320
|
+
cli_output_1.CliOutput.log(JSON.stringify(report, null, 2));
|
|
347
321
|
}
|
|
348
322
|
return report.failed > 0 ? 1 : 0;
|
|
349
323
|
}
|