@venizia/dev-configs 0.4.3 → 0.4.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/LICENSE.md +2 -5
- package/README.md +15 -2
- package/dist/checks/catalog.d.ts +39 -0
- package/dist/checks/catalog.d.ts.map +1 -0
- package/dist/checks/catalog.js +94 -0
- package/dist/checks/catalog.js.map +1 -0
- package/dist/checks/index.d.ts +15 -0
- package/dist/checks/index.d.ts.map +1 -0
- package/dist/checks/index.js +31 -0
- package/dist/checks/index.js.map +1 -0
- package/dist/checks/module-cycles.d.ts +22 -0
- package/dist/checks/module-cycles.d.ts.map +1 -0
- package/dist/checks/module-cycles.js +149 -0
- package/dist/checks/module-cycles.js.map +1 -0
- package/dist/checks/purity/manifest.d.ts +94 -0
- package/dist/checks/purity/manifest.d.ts.map +1 -0
- package/dist/checks/purity/manifest.js +177 -0
- package/dist/checks/purity/manifest.js.map +1 -0
- package/dist/checks/purity/probe.d.ts +68 -0
- package/dist/checks/purity/probe.d.ts.map +1 -0
- package/dist/checks/purity/probe.js +295 -0
- package/dist/checks/purity/probe.js.map +1 -0
- package/dist/checks/purity/run.d.ts +47 -0
- package/dist/checks/purity/run.d.ts.map +1 -0
- package/dist/checks/purity/run.js +121 -0
- package/dist/checks/purity/run.js.map +1 -0
- package/dist/checks/split-report.d.ts +19 -0
- package/dist/checks/split-report.d.ts.map +1 -0
- package/dist/checks/split-report.js +123 -0
- package/dist/checks/split-report.js.map +1 -0
- package/dist/checks/test-controls.d.ts +46 -0
- package/dist/checks/test-controls.d.ts.map +1 -0
- package/dist/checks/test-controls.js +78 -0
- package/dist/checks/test-controls.js.map +1 -0
- package/dist/checks/test-dead-code.d.ts +18 -0
- package/dist/checks/test-dead-code.d.ts.map +1 -0
- package/dist/checks/test-dead-code.js +50 -0
- package/dist/checks/test-dead-code.js.map +1 -0
- package/dist/checks/test-mutate.d.ts +58 -0
- package/dist/checks/test-mutate.d.ts.map +1 -0
- package/dist/checks/test-mutate.js +165 -0
- package/dist/checks/test-mutate.js.map +1 -0
- package/dist/checks/test-weight.d.ts +64 -0
- package/dist/checks/test-weight.d.ts.map +1 -0
- package/dist/checks/test-weight.js +124 -0
- package/dist/checks/test-weight.js.map +1 -0
- package/dist/cli/check.d.ts +14 -0
- package/dist/cli/check.d.ts.map +1 -0
- package/dist/cli/check.js +319 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/codemod/const-classes.d.ts +80 -0
- package/dist/cli/codemod/const-classes.d.ts.map +1 -0
- package/dist/cli/codemod/const-classes.js +603 -0
- package/dist/cli/codemod/const-classes.js.map +1 -0
- package/dist/cli/codemod/drop-redundant-casts.d.ts +112 -0
- package/dist/cli/codemod/drop-redundant-casts.d.ts.map +1 -0
- package/dist/cli/codemod/drop-redundant-casts.js +780 -0
- package/dist/cli/codemod/drop-redundant-casts.js.map +1 -0
- package/dist/cli/codemod/index.d.ts +2 -1
- package/dist/cli/codemod/index.d.ts.map +1 -1
- package/dist/cli/codemod/index.js +25 -7
- package/dist/cli/codemod/index.js.map +1 -1
- package/dist/cli/codemod/model-settings.d.ts.map +1 -1
- package/dist/cli/codemod/model-settings.js +39 -2
- package/dist/cli/codemod/model-settings.js.map +1 -1
- package/dist/cli/index.js +9 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +2 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/repo-tmp.d.ts +12 -0
- package/dist/testing/repo-tmp.d.ts.map +1 -0
- package/dist/testing/repo-tmp.js +67 -0
- package/dist/testing/repo-tmp.js.map +1 -0
- package/dist/testing/spawn.helper.d.ts +13 -0
- package/dist/testing/spawn.helper.d.ts.map +1 -0
- package/dist/testing/spawn.helper.js +22 -0
- package/dist/testing/spawn.helper.js.map +1 -0
- package/dist/testing/tmpdir-preload.d.ts +2 -0
- package/dist/testing/tmpdir-preload.d.ts.map +1 -0
- package/dist/testing/tmpdir-preload.js +11 -0
- package/dist/testing/tmpdir-preload.js.map +1 -0
- package/package.json +9 -1
- package/src/tsconfig/tsconfig.base.json +5 -2
- package/src/tsconfig/tsconfig.common.json +2 -2
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replays the mutation proof of the trim-tests method. A ledger line says: "this test (the
|
|
3
|
+
* candidate) is redundant because that test (the survivor) already catches the same break". The
|
|
4
|
+
* replay applies the break (the mutant) to a file, runs the survivor and the candidate, and puts the
|
|
5
|
+
* file back. The survivor must go red. The candidate must go red too, unless the line says it is
|
|
6
|
+
* vacuous and a second mutant leaves it green as well.
|
|
7
|
+
*
|
|
8
|
+
* The mutant edits the file the test really loads: the package's own `src` for a test that imports
|
|
9
|
+
* through the `@/` alias, or the `dist` of the dependency for a test that reaches another package
|
|
10
|
+
* through its `exports`. A rebuild is never needed.
|
|
11
|
+
*/
|
|
12
|
+
export interface IMutant {
|
|
13
|
+
/** Repository-relative file to edit (a `src` file, or a `dist` file of a dependency). */
|
|
14
|
+
file: string;
|
|
15
|
+
/** Text that must occur exactly once in the file. */
|
|
16
|
+
find: string;
|
|
17
|
+
replace: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ILedgerLine {
|
|
20
|
+
id: string;
|
|
21
|
+
/** Repository-relative test file that is deleted. */
|
|
22
|
+
candidate: string;
|
|
23
|
+
/** Run only the cases whose name matches (`bun test -t`). Default: the whole file. */
|
|
24
|
+
candidateName?: string;
|
|
25
|
+
/** Repository-relative test file that stays. */
|
|
26
|
+
survivor: string;
|
|
27
|
+
survivorName?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The break. An array applies every edit together: a survivor in the package that owns the code
|
|
30
|
+
* loads its `src`, a candidate in another package loads that package's `dist`, so one break is two edits.
|
|
31
|
+
*/
|
|
32
|
+
mutant: IMutant | IMutant[];
|
|
33
|
+
/** The source line the mutant stands for, `path:line`; recorded, not used by the replay. */
|
|
34
|
+
srcLine?: string;
|
|
35
|
+
/** `red` (default): the candidate must fail. `vacuous`: it must stay green under `mutant` AND `secondMutant`. */
|
|
36
|
+
expectCandidate?: 'red' | 'vacuous';
|
|
37
|
+
secondMutant?: IMutant | IMutant[];
|
|
38
|
+
}
|
|
39
|
+
export interface ILedger {
|
|
40
|
+
mutants: ILedgerLine[];
|
|
41
|
+
}
|
|
42
|
+
export interface ILedgerResult {
|
|
43
|
+
id: string;
|
|
44
|
+
survivorRed: boolean;
|
|
45
|
+
candidateRed: boolean;
|
|
46
|
+
/** Only for a `vacuous` line: whether the candidate also stayed green under the second mutant. */
|
|
47
|
+
candidateGreenUnderSecond?: boolean;
|
|
48
|
+
ok: boolean;
|
|
49
|
+
problem?: string;
|
|
50
|
+
}
|
|
51
|
+
/** Replays every line; never throws for a green survivor (that is a result), only for an unusable ledger. */
|
|
52
|
+
export declare const replayLedger: (opts: {
|
|
53
|
+
root: string;
|
|
54
|
+
ledger: ILedger;
|
|
55
|
+
scratch?: string;
|
|
56
|
+
}) => ILedgerResult[];
|
|
57
|
+
export declare const formatLedgerResults: (results: ILedgerResult[]) => string[];
|
|
58
|
+
//# sourceMappingURL=test-mutate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-mutate.d.ts","sourceRoot":"","sources":["../../src/checks/test-mutate.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,OAAO;IACtB,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,MAAM,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC;IAC5B,4FAA4F;IAC5F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iHAAiH;IACjH,eAAe,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IACpC,YAAY,CAAC,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC;CACpC;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,kGAAkG;IAClG,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAgJD,6GAA6G;AAC7G,eAAO,MAAM,YAAY,GAAI,MAAM;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,KAAG,aAAa,EAuDhB,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,SAAS,aAAa,EAAE,KAAG,MAAM,EAWpE,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatLedgerResults = exports.replayLedger = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const TEST_TIMEOUT_MILLISECONDS = 300_000;
|
|
9
|
+
/** The one place this tool builds an `Error`: `getError` would make dev-configs depend on inversion, which depends on dev-configs. */
|
|
10
|
+
// eslint-disable-next-line venizia/no-new-error -- getError would be a dev-configs -> inversion cycle
|
|
11
|
+
const replayError = (message) => new Error(message);
|
|
12
|
+
const checksum = (bytes) => (0, node_crypto_1.createHash)('sha256').update(bytes).digest('hex');
|
|
13
|
+
/** The nearest folder at or above the test file that holds a `package.json`: where `bun test` runs. */
|
|
14
|
+
const packageDirectoryOf = (opts) => {
|
|
15
|
+
let current = (0, node_path_1.dirname)((0, node_path_1.join)(opts.root, opts.file));
|
|
16
|
+
for (;;) {
|
|
17
|
+
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(current, 'package.json'))) {
|
|
18
|
+
return current;
|
|
19
|
+
}
|
|
20
|
+
const parent = (0, node_path_1.dirname)(current);
|
|
21
|
+
if (parent === current || parent.length < opts.root.length) {
|
|
22
|
+
return opts.root;
|
|
23
|
+
}
|
|
24
|
+
current = parent;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/** Runs one test file (or the cases matching `name`) and reports whether it failed. */
|
|
28
|
+
const runIsRed = (opts) => {
|
|
29
|
+
const directory = packageDirectoryOf({ root: opts.root, file: opts.file });
|
|
30
|
+
const target = (0, node_path_1.join)(opts.root, opts.file).slice(directory.length + 1);
|
|
31
|
+
const args = ['test', target, ...(opts.name ? ['-t', opts.name] : [])];
|
|
32
|
+
const result = (0, node_child_process_1.spawnSync)('bun', args, {
|
|
33
|
+
cwd: directory,
|
|
34
|
+
encoding: 'utf8',
|
|
35
|
+
timeout: TEST_TIMEOUT_MILLISECONDS,
|
|
36
|
+
killSignal: 'SIGKILL',
|
|
37
|
+
env: { ...process.env, NODE_ENV: 'test' },
|
|
38
|
+
});
|
|
39
|
+
if (result.error) {
|
|
40
|
+
throw replayError(`[test-mutate] could not run bun test ${target}: ${result.error.message}`);
|
|
41
|
+
}
|
|
42
|
+
// A name filter that matches nothing runs no case and exits 0: that would read as "green" and could
|
|
43
|
+
// hide a typo as a vacuous test, so a run that executed nothing is an unusable ledger line.
|
|
44
|
+
const output = `${result.stdout ?? ''}${result.stderr ?? ''}`;
|
|
45
|
+
const passed = Number(/^\s*(\d+) pass/m.exec(output)?.[1] ?? 0);
|
|
46
|
+
const failed = Number(/^\s*(\d+) fail/m.exec(output)?.[1] ?? 0);
|
|
47
|
+
if (passed + failed === 0) {
|
|
48
|
+
throw replayError(`[test-mutate] bun test ${target}${opts.name ? ` -t ${opts.name}` : ''} ran no case | check the file and the name`);
|
|
49
|
+
}
|
|
50
|
+
return result.status !== 0 || failed > 0;
|
|
51
|
+
};
|
|
52
|
+
/** Applies `mutant`, runs `action`, and puts the file back byte for byte, verified by checksum. */
|
|
53
|
+
const withMutant = (opts) => {
|
|
54
|
+
const path = (0, node_path_1.join)(opts.root, opts.mutant.file);
|
|
55
|
+
const original = (0, node_fs_1.readFileSync)(path);
|
|
56
|
+
const text = original.toString('utf8');
|
|
57
|
+
const occurrences = text.split(opts.mutant.find).length - 1;
|
|
58
|
+
if (occurrences !== 1) {
|
|
59
|
+
throw replayError(`[test-mutate][${opts.id}] \`find\` occurs ${occurrences} times in ${opts.mutant.file}, it must occur exactly once`);
|
|
60
|
+
}
|
|
61
|
+
(0, node_fs_1.mkdirSync)(opts.scratch, { recursive: true });
|
|
62
|
+
const backup = (0, node_path_1.join)(opts.scratch, `test-mutate-${opts.id.replace(/[^\w.-]/g, '_')}.orig`);
|
|
63
|
+
if ((0, node_fs_1.existsSync)(backup)) {
|
|
64
|
+
throw replayError(`[test-mutate][${opts.id}] a backup from an interrupted run exists: ${backup} | restore ${opts.mutant.file} from it, then delete it`);
|
|
65
|
+
}
|
|
66
|
+
(0, node_fs_1.writeFileSync)(backup, original);
|
|
67
|
+
const expected = checksum(original);
|
|
68
|
+
let outcome;
|
|
69
|
+
try {
|
|
70
|
+
(0, node_fs_1.writeFileSync)(path, text.replace(opts.mutant.find, () => opts.mutant.replace));
|
|
71
|
+
outcome = { value: opts.action() };
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
outcome = { error };
|
|
75
|
+
}
|
|
76
|
+
// Restored whatever the action did, and checked, before its result or error is passed on.
|
|
77
|
+
(0, node_fs_1.writeFileSync)(path, original);
|
|
78
|
+
if (checksum((0, node_fs_1.readFileSync)(path)) !== expected) {
|
|
79
|
+
throw replayError(`[test-mutate][${opts.id}] ${opts.mutant.file} was not restored | the backup is ${backup}`);
|
|
80
|
+
}
|
|
81
|
+
(0, node_fs_1.rmSync)(backup, { force: true });
|
|
82
|
+
if ('error' in outcome) {
|
|
83
|
+
throw outcome.error;
|
|
84
|
+
}
|
|
85
|
+
return outcome.value;
|
|
86
|
+
};
|
|
87
|
+
/** Applies every edit of `mutant`, runs `action`, and puts each file back byte for byte, verified by checksum. */
|
|
88
|
+
const withMutants = (opts) => {
|
|
89
|
+
const edits = Array.isArray(opts.mutant) ? opts.mutant : [opts.mutant];
|
|
90
|
+
const apply = (index) => index === edits.length
|
|
91
|
+
? opts.action()
|
|
92
|
+
: withMutant({
|
|
93
|
+
root: opts.root,
|
|
94
|
+
mutant: edits[index],
|
|
95
|
+
scratch: opts.scratch,
|
|
96
|
+
id: `${opts.id}-${index}`,
|
|
97
|
+
action: () => apply(index + 1),
|
|
98
|
+
});
|
|
99
|
+
return apply(0);
|
|
100
|
+
};
|
|
101
|
+
/** Replays every line; never throws for a green survivor (that is a result), only for an unusable ledger. */
|
|
102
|
+
const replayLedger = (opts) => {
|
|
103
|
+
const root = (0, node_path_1.resolve)(opts.root);
|
|
104
|
+
const scratch = opts.scratch ?? (0, node_path_1.join)(root, '.agents/local/tmp');
|
|
105
|
+
const results = [];
|
|
106
|
+
for (const line of opts.ledger.mutants) {
|
|
107
|
+
const { survivorRed, candidateRed } = withMutants({
|
|
108
|
+
root,
|
|
109
|
+
mutant: line.mutant,
|
|
110
|
+
scratch,
|
|
111
|
+
id: line.id,
|
|
112
|
+
action: () => ({
|
|
113
|
+
survivorRed: runIsRed({ root, file: line.survivor, name: line.survivorName }),
|
|
114
|
+
candidateRed: runIsRed({ root, file: line.candidate, name: line.candidateName }),
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
const result = { id: line.id, survivorRed, candidateRed, ok: true };
|
|
118
|
+
const expectation = line.expectCandidate ?? 'red';
|
|
119
|
+
if (!survivorRed) {
|
|
120
|
+
result.ok = false;
|
|
121
|
+
result.problem =
|
|
122
|
+
'the survivor stayed green under the mutant: it does not cover the behaviour';
|
|
123
|
+
}
|
|
124
|
+
else if (expectation === 'red' && !candidateRed) {
|
|
125
|
+
result.ok = false;
|
|
126
|
+
result.problem =
|
|
127
|
+
'the candidate stayed green under the mutant: record it as vacuous with a second mutant, or pick a mutant it checks';
|
|
128
|
+
}
|
|
129
|
+
else if (expectation === 'vacuous') {
|
|
130
|
+
if (!line.secondMutant) {
|
|
131
|
+
result.ok = false;
|
|
132
|
+
result.problem = 'a vacuous line needs a secondMutant';
|
|
133
|
+
}
|
|
134
|
+
else if (candidateRed) {
|
|
135
|
+
result.ok = false;
|
|
136
|
+
result.problem = 'the candidate went red under the mutant: it is not vacuous';
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const greenUnderSecond = !withMutants({
|
|
140
|
+
root,
|
|
141
|
+
mutant: line.secondMutant,
|
|
142
|
+
scratch,
|
|
143
|
+
id: `${line.id}-second`,
|
|
144
|
+
action: () => runIsRed({ root, file: line.candidate, name: line.candidateName }),
|
|
145
|
+
});
|
|
146
|
+
result.candidateGreenUnderSecond = greenUnderSecond;
|
|
147
|
+
if (!greenUnderSecond) {
|
|
148
|
+
result.ok = false;
|
|
149
|
+
result.problem = 'the candidate went red under the second mutant: it is not vacuous';
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
results.push(result);
|
|
154
|
+
}
|
|
155
|
+
return results;
|
|
156
|
+
};
|
|
157
|
+
exports.replayLedger = replayLedger;
|
|
158
|
+
const formatLedgerResults = (results) => {
|
|
159
|
+
const lines = results.map((result) => `${result.ok ? 'ok ' : 'FAIL'} ${result.id}: survivor ${result.survivorRed ? 'red' : 'GREEN'}, candidate ${result.candidateRed ? 'red' : 'green'}${result.problem ? ` | ${result.problem}` : ''}`);
|
|
160
|
+
const failed = results.filter((result) => !result.ok).length;
|
|
161
|
+
lines.push(`\n[test-mutate] ${results.length - failed}/${results.length} ledger lines hold${failed ? `, ${failed} do not` : ''}.`);
|
|
162
|
+
return lines;
|
|
163
|
+
};
|
|
164
|
+
exports.formatLedgerResults = formatLedgerResults;
|
|
165
|
+
//# sourceMappingURL=test-mutate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-mutate.js","sourceRoot":"","sources":["../../src/checks/test-mutate.ts"],"names":[],"mappings":";;;AAAA,2DAA+C;AAC/C,6CAAyC;AACzC,qCAAqF;AACrF,yCAAmD;AAwDnD,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,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAE7F,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;QAChC,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,M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CAAC,CAAC,MAAM,CAAC;IAC7D,KAAK,CAAC,IAAI,CACR,mBAAmB,OAAO,CAAC,MAAM,GAAG,MAAM,IAAI,OAAO,CAAC,MAAM,qBAAqB,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,CACvH,CAAC;IAEF,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAXW,QAAA,mBAAmB,uBAW9B","sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { createHash } from 'node:crypto';\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\nexport interface ILedgerLine {\n id: string;\n /** Repository-relative test file that is deleted. */\n candidate: string;\n /** Run only the cases whose name matches (`bun test -t`). Default: the whole file. */\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 /** `red` (default): the candidate must fail. `vacuous`: it must stay green under `mutant` AND `secondMutant`. */\n expectCandidate?: 'red' | 'vacuous';\n secondMutant?: IMutant | IMutant[];\n}\n\nexport interface ILedger {\n mutants: ILedgerLine[];\n}\n\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\nconst checksum = (bytes: Buffer): string => createHash('sha256').update(bytes).digest('hex');\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 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 by checksum. */\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 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 const expected = checksum(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 (checksum(readFileSync(path)) !== expected) {\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 by checksum. */\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 every line; never throws for a green survivor (that is a result), only for an unusable ledger. */\nexport const replayLedger = (opts: {\n root: string;\n ledger: ILedger;\n scratch?: string;\n}): 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\nexport const formatLedgerResults = (results: ILedgerResult[]): string[] => {\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"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the JUnit report of `bun test --reporter=junit` and says where the test time and the test
|
|
3
|
+
* count are: per file, per package, the heaviest files, duplicates by name, files that assert nothing,
|
|
4
|
+
* and skips. The first step of the trim-tests method (`.agents/knowledge/process/trimming-tests.md`).
|
|
5
|
+
*
|
|
6
|
+
* The numbers are only as good as the run that made them: a `--parallel` run times each file under
|
|
7
|
+
* contention, so a file that takes 7 s there can take 1 s alone. Re-time a suspect file alone.
|
|
8
|
+
*/
|
|
9
|
+
export interface ITestWeightInput {
|
|
10
|
+
/** Names the report in the output: the package. */
|
|
11
|
+
label: string;
|
|
12
|
+
xml: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ITestFileWeight {
|
|
15
|
+
label: string;
|
|
16
|
+
file: string;
|
|
17
|
+
milliseconds: number;
|
|
18
|
+
cases: number;
|
|
19
|
+
assertions: number;
|
|
20
|
+
skipped: number;
|
|
21
|
+
slowestCase: string;
|
|
22
|
+
slowestMilliseconds: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ITestWeightReport {
|
|
25
|
+
files: ITestFileWeight[];
|
|
26
|
+
totalMilliseconds: number;
|
|
27
|
+
totalCases: number;
|
|
28
|
+
totalAssertions: number;
|
|
29
|
+
totalSkipped: number;
|
|
30
|
+
perLabel: Array<{
|
|
31
|
+
label: string;
|
|
32
|
+
files: number;
|
|
33
|
+
cases: number;
|
|
34
|
+
milliseconds: number;
|
|
35
|
+
}>;
|
|
36
|
+
/** Heaviest first. */
|
|
37
|
+
heaviest: ITestFileWeight[];
|
|
38
|
+
/** How many of the heaviest files hold 80% of the time. */
|
|
39
|
+
filesFor80Percent: number;
|
|
40
|
+
/** Files that take under 100 ms, and what they cost together. */
|
|
41
|
+
lightFiles: {
|
|
42
|
+
count: number;
|
|
43
|
+
milliseconds: number;
|
|
44
|
+
};
|
|
45
|
+
/** The same suite and case name in more than one file. */
|
|
46
|
+
sameNameAcrossFiles: Array<{
|
|
47
|
+
name: string;
|
|
48
|
+
files: string[];
|
|
49
|
+
}>;
|
|
50
|
+
zeroAssertionFiles: string[];
|
|
51
|
+
skippedFiles: Array<{
|
|
52
|
+
file: string;
|
|
53
|
+
skipped: number;
|
|
54
|
+
}>;
|
|
55
|
+
}
|
|
56
|
+
export declare const analyseJunit: (opts: {
|
|
57
|
+
reports: ITestWeightInput[];
|
|
58
|
+
}) => ITestWeightReport;
|
|
59
|
+
/** The report as the lines `devz check test-weight` prints. */
|
|
60
|
+
export declare const formatTestWeight: (opts: {
|
|
61
|
+
report: ITestWeightReport;
|
|
62
|
+
top?: number;
|
|
63
|
+
}) => string[];
|
|
64
|
+
//# sourceMappingURL=test-weight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-weight.d.ts","sourceRoot":"","sources":["../../src/checks/test-weight.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,e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amp: '&',
|
|
6
|
+
lt: '<',
|
|
7
|
+
gt: '>',
|
|
8
|
+
quot: '"',
|
|
9
|
+
apos: "'",
|
|
10
|
+
};
|
|
11
|
+
const decodeEntities = (text) => text.replace(/&(#x[0-9a-fA-F]+|#\d+|[a-z]+);/g, (whole, body) => {
|
|
12
|
+
if (body.startsWith('#x')) {
|
|
13
|
+
return String.fromCodePoint(Number.parseInt(body.slice(2), 16));
|
|
14
|
+
}
|
|
15
|
+
if (body.startsWith('#')) {
|
|
16
|
+
return String.fromCodePoint(Number.parseInt(body.slice(1), 10));
|
|
17
|
+
}
|
|
18
|
+
return ENTITIES[body] ?? whole;
|
|
19
|
+
});
|
|
20
|
+
/** Bun writes a file as a top-level suite whose `name` equals its `file`. */
|
|
21
|
+
const FILE_SUITE = /<testsuite name="([^"]+\.(?:test|spec)\.[cm]?[jt]sx?)" file="[^"]+" tests="(\d+)" assertions="(\d+)" failures="\d+" skipped="(\d+)" time="([\d.eE+-]+)"/g;
|
|
22
|
+
const CASE = /<testcase name="([^"]*)" classname="([^"]*)" time="([\d.eE+-]+)" file="([^"]+)"/g;
|
|
23
|
+
const LIGHT_FILE_MILLISECONDS = 100;
|
|
24
|
+
const HEAVY_SHARE = 0.8;
|
|
25
|
+
const analyseJunit = (opts) => {
|
|
26
|
+
const files = [];
|
|
27
|
+
const names = new Map();
|
|
28
|
+
for (const { label, xml } of opts.reports) {
|
|
29
|
+
const start = files.length;
|
|
30
|
+
for (const match of xml.matchAll(FILE_SUITE)) {
|
|
31
|
+
files.push({
|
|
32
|
+
label,
|
|
33
|
+
file: match[1],
|
|
34
|
+
milliseconds: Number(match[5]) * 1000,
|
|
35
|
+
cases: Number(match[2]),
|
|
36
|
+
assertions: Number(match[3]),
|
|
37
|
+
skipped: Number(match[4]),
|
|
38
|
+
slowestCase: '',
|
|
39
|
+
slowestMilliseconds: 0,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const byFile = new Map(files.slice(start).map((entry) => [entry.file, entry]));
|
|
43
|
+
for (const match of xml.matchAll(CASE)) {
|
|
44
|
+
const caseName = decodeEntities(match[1]);
|
|
45
|
+
const suiteName = decodeEntities(match[2]);
|
|
46
|
+
const entry = byFile.get(match[4]);
|
|
47
|
+
const milliseconds = Number(match[3]) * 1000;
|
|
48
|
+
if (entry && milliseconds > entry.slowestMilliseconds) {
|
|
49
|
+
entry.slowestMilliseconds = milliseconds;
|
|
50
|
+
entry.slowestCase = caseName;
|
|
51
|
+
}
|
|
52
|
+
const key = `${suiteName} > ${caseName}`;
|
|
53
|
+
const where = names.get(key) ?? new Set();
|
|
54
|
+
where.add(`${label}/${match[4]}`);
|
|
55
|
+
names.set(key, where);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const heaviest = [...files].sort((left, right) => right.milliseconds - left.milliseconds);
|
|
59
|
+
const totalMilliseconds = files.reduce((sum, entry) => sum + entry.milliseconds, 0);
|
|
60
|
+
let accumulated = 0;
|
|
61
|
+
let filesFor80Percent = 0;
|
|
62
|
+
for (const entry of heaviest) {
|
|
63
|
+
accumulated += entry.milliseconds;
|
|
64
|
+
filesFor80Percent += 1;
|
|
65
|
+
if (accumulated >= totalMilliseconds * HEAVY_SHARE) {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const light = files.filter((entry) => entry.milliseconds < LIGHT_FILE_MILLISECONDS);
|
|
70
|
+
const labels = [...new Set(files.map((entry) => entry.label))];
|
|
71
|
+
return {
|
|
72
|
+
files,
|
|
73
|
+
totalMilliseconds,
|
|
74
|
+
totalCases: files.reduce((sum, entry) => sum + entry.cases, 0),
|
|
75
|
+
totalAssertions: files.reduce((sum, entry) => sum + entry.assertions, 0),
|
|
76
|
+
totalSkipped: files.reduce((sum, entry) => sum + entry.skipped, 0),
|
|
77
|
+
perLabel: labels.map((label) => {
|
|
78
|
+
const own = files.filter((entry) => entry.label === label);
|
|
79
|
+
return {
|
|
80
|
+
label,
|
|
81
|
+
files: own.length,
|
|
82
|
+
cases: own.reduce((sum, entry) => sum + entry.cases, 0),
|
|
83
|
+
milliseconds: own.reduce((sum, entry) => sum + entry.milliseconds, 0),
|
|
84
|
+
};
|
|
85
|
+
}),
|
|
86
|
+
heaviest,
|
|
87
|
+
filesFor80Percent,
|
|
88
|
+
lightFiles: {
|
|
89
|
+
count: light.length,
|
|
90
|
+
milliseconds: light.reduce((sum, entry) => sum + entry.milliseconds, 0),
|
|
91
|
+
},
|
|
92
|
+
sameNameAcrossFiles: [...names.entries()]
|
|
93
|
+
.filter(([, where]) => where.size > 1)
|
|
94
|
+
.map(([name, where]) => ({ name, files: [...where].sort() })),
|
|
95
|
+
zeroAssertionFiles: files.filter((entry) => entry.assertions === 0).map((entry) => entry.file),
|
|
96
|
+
skippedFiles: files
|
|
97
|
+
.filter((entry) => entry.skipped > 0)
|
|
98
|
+
.map((entry) => ({ file: `${entry.label}/${entry.file}`, skipped: entry.skipped })),
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
exports.analyseJunit = analyseJunit;
|
|
102
|
+
/** The report as the lines `devz check test-weight` prints. */
|
|
103
|
+
const formatTestWeight = (opts) => {
|
|
104
|
+
const { report, top = 25 } = opts;
|
|
105
|
+
const seconds = (milliseconds) => (milliseconds / 1000).toFixed(1);
|
|
106
|
+
const lines = [
|
|
107
|
+
`files ${report.files.length} | cases ${report.totalCases} | assertions ${report.totalAssertions} | skipped ${report.totalSkipped} | sum of file times ${seconds(report.totalMilliseconds)} s`,
|
|
108
|
+
];
|
|
109
|
+
for (const row of report.perLabel) {
|
|
110
|
+
lines.push(` ${row.label.padEnd(14)} files ${String(row.files).padStart(4)} cases ${String(row.cases).padStart(5)} time ${seconds(row.milliseconds).padStart(7)} s`);
|
|
111
|
+
}
|
|
112
|
+
lines.push('', `heaviest ${top} files:`);
|
|
113
|
+
for (const entry of report.heaviest.slice(0, top)) {
|
|
114
|
+
lines.push(`${entry.milliseconds.toFixed(0).padStart(8)} ms ${String(entry.cases).padStart(5)} cases slowest ${entry.slowestMilliseconds.toFixed(0).padStart(7)} ms ${entry.label}/${entry.file}`);
|
|
115
|
+
}
|
|
116
|
+
lines.push('', `80% of the time is in the ${report.filesFor80Percent} heaviest files of ${report.files.length}`, `files under ${LIGHT_FILE_MILLISECONDS} ms: ${report.lightFiles.count}, together ${seconds(report.lightFiles.milliseconds)} s`, `same suite and case name in more than one file: ${report.sameNameAcrossFiles.length}`);
|
|
117
|
+
for (const duplicate of report.sameNameAcrossFiles.slice(0, 10)) {
|
|
118
|
+
lines.push(` ${duplicate.name.slice(0, 90)} -> ${duplicate.files.join(', ')}`);
|
|
119
|
+
}
|
|
120
|
+
lines.push(`files with 0 assertions: ${report.zeroAssertionFiles.length}${report.zeroAssertionFiles.length ? ` (${report.zeroAssertionFiles.slice(0, 3).join(', ')})` : ''}`, `files with skipped cases: ${report.skippedFiles.length} (${report.skippedFiles.reduce((sum, entry) => sum + entry.skipped, 0)} cases)`);
|
|
121
|
+
return lines;
|
|
122
|
+
};
|
|
123
|
+
exports.formatTestWeight = formatTestWeight;
|
|
124
|
+
//# sourceMappingURL=test-weight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-weight.js","sourceRoot":"","sources":["../../src/checks/test-weight.ts"],"names":[],"mappings":";;;AA4CA,MAAM,QAAQ,GAA2B;IACvC,GAAG,EAAE,GAAG;IACR,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,GAAG;IACP,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,GAAG;CACV,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,IAAY,EAAU,EAAE,CAC9C,IAAI,CAAC,OAAO,CAAC,iCAAiC,EAAE,CAAC,KAAK,EAAE,IAAY,EAAE,EAAE;IACtE,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAA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CAAC,KAAK,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EACjK,6BAA6B,MAAM,CAAC,YAAY,CAAC,MAAM,KAAK,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CACxI,CAAC;IAEF,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AApCW,QAAA,gBAAgB,oBAoC3B","sourcesContent":["/**\n * Reads the JUnit report of `bun test --reporter=junit` and says where the test time and the test\n * count are: per file, per package, the heaviest files, duplicates by name, files that assert nothing,\n * and skips. The first step of the trim-tests method (`.agents/knowledge/process/trimming-tests.md`).\n *\n * The numbers are only as good as the run that made them: a `--parallel` run times each file under\n * contention, so a file that takes 7 s there can take 1 s alone. Re-time a suspect file alone.\n */\nexport interface ITestWeightInput {\n /** Names the report in the output: the package. */\n label: string;\n xml: string;\n}\n\nexport interface ITestFileWeight {\n label: string;\n file: string;\n milliseconds: number;\n cases: number;\n assertions: number;\n skipped: number;\n slowestCase: string;\n slowestMilliseconds: number;\n}\n\nexport interface ITestWeightReport {\n files: ITestFileWeight[];\n totalMilliseconds: number;\n totalCases: number;\n totalAssertions: number;\n totalSkipped: number;\n perLabel: Array<{ label: string; files: number; cases: number; milliseconds: number }>;\n /** Heaviest first. */\n heaviest: ITestFileWeight[];\n /** How many of the heaviest files hold 80% of the time. */\n filesFor80Percent: number;\n /** Files that take under 100 ms, and what they cost together. */\n lightFiles: { count: number; milliseconds: number };\n /** The same suite and case name in more than one file. */\n sameNameAcrossFiles: Array<{ name: string; files: string[] }>;\n zeroAssertionFiles: string[];\n skippedFiles: Array<{ file: string; skipped: number }>;\n}\n\nconst ENTITIES: Record<string, string> = {\n amp: '&',\n lt: '<',\n gt: '>',\n quot: '\"',\n apos: \"'\",\n};\n\nconst decodeEntities = (text: string): string =>\n text.replace(/&(#x[0-9a-fA-F]+|#\\d+|[a-z]+);/g, (whole, body: string) => {\n if (body.startsWith('#x')) {\n return String.fromCodePoint(Number.parseInt(body.slice(2), 16));\n }\n\n if (body.startsWith('#')) {\n return String.fromCodePoint(Number.parseInt(body.slice(1), 10));\n }\n\n return ENTITIES[body] ?? whole;\n });\n\n/** Bun writes a file as a top-level suite whose `name` equals its `file`. */\nconst FILE_SUITE =\n /<testsuite name=\"([^\"]+\\.(?:test|spec)\\.[cm]?[jt]sx?)\" file=\"[^\"]+\" tests=\"(\\d+)\" assertions=\"(\\d+)\" failures=\"\\d+\" skipped=\"(\\d+)\" time=\"([\\d.eE+-]+)\"/g;\nconst CASE = /<testcase name=\"([^\"]*)\" classname=\"([^\"]*)\" time=\"([\\d.eE+-]+)\" file=\"([^\"]+)\"/g;\n\nconst LIGHT_FILE_MILLISECONDS = 100;\nconst HEAVY_SHARE = 0.8;\n\nexport const analyseJunit = (opts: { reports: ITestWeightInput[] }): ITestWeightReport => {\n const files: ITestFileWeight[] = [];\n const names = new Map<string, Set<string>>();\n\n for (const { label, xml } of opts.reports) {\n const start = files.length;\n\n for (const match of xml.matchAll(FILE_SUITE)) {\n files.push({\n label,\n file: match[1],\n milliseconds: Number(match[5]) * 1000,\n cases: Number(match[2]),\n assertions: Number(match[3]),\n skipped: Number(match[4]),\n slowestCase: '',\n slowestMilliseconds: 0,\n });\n }\n\n const byFile = new Map(files.slice(start).map((entry) => [entry.file, entry]));\n for (const match of xml.matchAll(CASE)) {\n const caseName = decodeEntities(match[1]);\n const suiteName = decodeEntities(match[2]);\n const entry = byFile.get(match[4]);\n const milliseconds = Number(match[3]) * 1000;\n\n if (entry && milliseconds > entry.slowestMilliseconds) {\n entry.slowestMilliseconds = milliseconds;\n entry.slowestCase = caseName;\n }\n\n const key = `${suiteName} > ${caseName}`;\n const where = names.get(key) ?? new Set<string>();\n where.add(`${label}/${match[4]}`);\n names.set(key, where);\n }\n }\n\n const heaviest = [...files].sort((left, right) => right.milliseconds - left.milliseconds);\n const totalMilliseconds = files.reduce((sum, entry) => sum + entry.milliseconds, 0);\n\n let accumulated = 0;\n let filesFor80Percent = 0;\n for (const entry of heaviest) {\n accumulated += entry.milliseconds;\n filesFor80Percent += 1;\n\n if (accumulated >= totalMilliseconds * HEAVY_SHARE) {\n break;\n }\n }\n\n const light = files.filter((entry) => entry.milliseconds < LIGHT_FILE_MILLISECONDS);\n const labels = [...new Set(files.map((entry) => entry.label))];\n\n return {\n files,\n totalMilliseconds,\n totalCases: files.reduce((sum, entry) => sum + entry.cases, 0),\n totalAssertions: files.reduce((sum, entry) => sum + entry.assertions, 0),\n totalSkipped: files.reduce((sum, entry) => sum + entry.skipped, 0),\n perLabel: labels.map((label) => {\n const own = files.filter((entry) => entry.label === label);\n return {\n label,\n files: own.length,\n cases: own.reduce((sum, entry) => sum + entry.cases, 0),\n milliseconds: own.reduce((sum, entry) => sum + entry.milliseconds, 0),\n };\n }),\n heaviest,\n filesFor80Percent,\n lightFiles: {\n count: light.length,\n milliseconds: light.reduce((sum, entry) => sum + entry.milliseconds, 0),\n },\n sameNameAcrossFiles: [...names.entries()]\n .filter(([, where]) => where.size > 1)\n .map(([name, where]) => ({ name, files: [...where].sort() })),\n zeroAssertionFiles: files.filter((entry) => entry.assertions === 0).map((entry) => entry.file),\n skippedFiles: files\n .filter((entry) => entry.skipped > 0)\n .map((entry) => ({ file: `${entry.label}/${entry.file}`, skipped: entry.skipped })),\n };\n};\n\n/** The report as the lines `devz check test-weight` prints. */\nexport const formatTestWeight = (opts: { report: ITestWeightReport; top?: number }): string[] => {\n const { report, top = 25 } = opts;\n const seconds = (milliseconds: number): string => (milliseconds / 1000).toFixed(1);\n const lines: string[] = [\n `files ${report.files.length} | cases ${report.totalCases} | assertions ${report.totalAssertions} | skipped ${report.totalSkipped} | sum of file times ${seconds(report.totalMilliseconds)} s`,\n ];\n\n for (const row of report.perLabel) {\n lines.push(\n ` ${row.label.padEnd(14)} files ${String(row.files).padStart(4)} cases ${String(row.cases).padStart(5)} time ${seconds(row.milliseconds).padStart(7)} s`,\n );\n }\n\n lines.push('', `heaviest ${top} files:`);\n for (const entry of report.heaviest.slice(0, top)) {\n lines.push(\n `${entry.milliseconds.toFixed(0).padStart(8)} ms ${String(entry.cases).padStart(5)} cases slowest ${entry.slowestMilliseconds.toFixed(0).padStart(7)} ms ${entry.label}/${entry.file}`,\n );\n }\n\n lines.push(\n '',\n `80% of the time is in the ${report.filesFor80Percent} heaviest files of ${report.files.length}`,\n `files under ${LIGHT_FILE_MILLISECONDS} ms: ${report.lightFiles.count}, together ${seconds(report.lightFiles.milliseconds)} s`,\n `same suite and case name in more than one file: ${report.sameNameAcrossFiles.length}`,\n );\n for (const duplicate of report.sameNameAcrossFiles.slice(0, 10)) {\n lines.push(` ${duplicate.name.slice(0, 90)} -> ${duplicate.files.join(', ')}`);\n }\n\n lines.push(\n `files with 0 assertions: ${report.zeroAssertionFiles.length}${report.zeroAssertionFiles.length ? ` (${report.zeroAssertionFiles.slice(0, 3).join(', ')})` : ''}`,\n `files with skipped cases: ${report.skippedFiles.length} (${report.skippedFiles.reduce((sum, entry) => sum + entry.skipped, 0)} cases)`,\n );\n\n return lines;\n};\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** `devz check <name>`: runs one of the shared repository gates in the current folder. */
|
|
2
|
+
export declare class CheckCommand {
|
|
3
|
+
private static runTestWeight;
|
|
4
|
+
private static runTestDeadCode;
|
|
5
|
+
private static runTestMutate;
|
|
6
|
+
private static runTestControls;
|
|
7
|
+
private static runSplitReport;
|
|
8
|
+
private static runCatalog;
|
|
9
|
+
static run(opts: {
|
|
10
|
+
root: string;
|
|
11
|
+
args?: string[];
|
|
12
|
+
}): Promise<number>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/cli/check.ts"],"names":[],"mappings":"AAwIA,0FAA0F;AAC1F,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,aAAa;IA8B5B,OAAO,CAAC,MAAM,CAAC,eAAe;IAqB9B,OAAO,CAAC,MAAM,CAAC,aAAa;mBA2BP,eAAe;IAmCpC,OAAO,CAAC,MAAM,CAAC,cAAc;mBAkBR,UAAU;WAsClB,GAAG,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAiG3E"}
|