@systemfsoftware/stryker-ignorer-kit 0.0.0

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 ADDED
@@ -0,0 +1,203 @@
1
+ Copyright (c) 2026 Ryan Lee (systemfsoftware)
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright 2026 Ryan Lee (systemfsoftware)
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # @systemfsoftware/stryker-ignorer-kit
2
+
3
+ Authoring and testing kit for the Stryker ignorer family: write an ignorer as
4
+ typed visitors, verify it from source snippets.
5
+
6
+ An **ignorer** tells the mutation engine which code to leave alone. The engine
7
+ consults every configured ignorer at each mutant candidate node; returning a
8
+ reason string suppresses that node's mutants, `undefined` declines. This kit
9
+ supplies the two layers an author actually works in — the authoring API
10
+ (`defineIgnorer`) and the testing harness (`testIgnorer`) — and compiles down to
11
+ the plain `{ name, shouldIgnore }` wire contract the engine loads.
12
+
13
+ ## Write a new ignorer from scratch
14
+
15
+ ### 1. The package
16
+
17
+ Create `packages/ignorers/<your-ignorer>/` (the workspace glob picks it up) with
18
+ the family tooling set cloned from a sibling, and these dependencies:
19
+
20
+ ```json
21
+ {
22
+ "dependencies": {
23
+ "@systemfsoftware/stryker-ignorer-interface": "workspace:^",
24
+ "@systemfsoftware/stryker-ignorer-kit": "workspace:^"
25
+ }
26
+ }
27
+ ```
28
+
29
+ The interface package is types only (the AST vocabulary); the kit's root entry
30
+ is parser-free. Your module exports one array:
31
+
32
+ ```ts
33
+ export const strykerIgnorers = [myIgnorer]
34
+ ```
35
+
36
+ Consumers wire the pair in their Stryker config — `plugins` takes the module
37
+ specifier, `ignorers` the ignorer's own name (`myIgnorer`'s `name`); a mismatched
38
+ pair fails silent-green, so keep the two strings in step.
39
+
40
+ ### 2. The visitors
41
+
42
+ `defineIgnorer` takes a visitor map keyed by AST node kind. Each visitor receives
43
+ its node **narrowed to that kind** plus a typed context for the ancestor chain,
44
+ and returns a reason string or `undefined` to decline:
45
+
46
+ ```ts
47
+ import type { CallExpression, Expression, Node } from '@systemfsoftware/stryker-ignorer-interface'
48
+ import { defineIgnorer } from '@systemfsoftware/stryker-ignorer-kit'
49
+
50
+ export const INSIDE_TRACE = 'inside `logger.trace(...)` — diagnostic noise, not production behaviour'
51
+ export const METRIC_NAME = 'a metric name — mutating it only renames telemetry'
52
+
53
+ function isTraceCallee(callee: Expression): boolean {
54
+ return callee.type === 'MemberExpression' && !callee.computed &&
55
+ callee.object.type === 'Identifier' && callee.object.name === 'logger' &&
56
+ callee.property.type === 'Identifier' && callee.property.name === 'trace'
57
+ }
58
+
59
+ function isLoggerTrace(node: Node): boolean {
60
+ return node.type === 'CallExpression' && isTraceCallee(node.callee)
61
+ }
62
+
63
+ function isMetricCounter(call: CallExpression): boolean {
64
+ return call.callee.type === 'MemberExpression' && !call.callee.computed &&
65
+ call.callee.object.type === 'Identifier' && call.callee.object.name === 'metrics' &&
66
+ call.callee.property.type === 'Identifier' && call.callee.property.name === 'counter'
67
+ }
68
+
69
+ export const strykerIgnorers = [
70
+ defineIgnorer({
71
+ name: 'telemetry-calls',
72
+ visitors: {
73
+ // Point rule: the metric-name argument itself.
74
+ Literal: (node, ctx) => {
75
+ const call = ctx.parentIf('CallExpression')
76
+ return call !== undefined && isMetricCounter(call) && call.arguments[0] === node
77
+ ? METRIC_NAME
78
+ : undefined
79
+ },
80
+ // Subtree rule: everything evaluated inside a logger.trace call.
81
+ onAnyNode: (_node, ctx) => (ctx.ancestors.some(isLoggerTrace) ? INSIDE_TRACE : undefined),
82
+ },
83
+ }),
84
+ ]
85
+ ```
86
+
87
+ The context, nearest-first:
88
+
89
+ | Member | Meaning |
90
+ | ---------------------- | ------------------------------------------------------------------ |
91
+ | `ctx.ancestors` | the raw chain, parent first, root last, excluding the visited node |
92
+ | `ctx.parentIf(kind)` | the immediate parent narrowed to `kind`, else `undefined` |
93
+ | `ctx.ancestorIf(kind)` | the nearest chain member of `kind`, else `undefined` |
94
+
95
+ Keys are ESTree discriminants: string, number, and boolean literals all arrive as
96
+ `'Literal'` (narrow further on `typeof node.value`), not `'StringLiteral'`.
97
+ A visitor returning `undefined` falls through to `onAnyNode`; a node no typed
98
+ visitor claims goes straight there.
99
+
100
+ ### 3. The tests
101
+
102
+ `testIgnorer` (from the `./tester` entry) parses your snippets with the same
103
+ parser convention the instrumenter uses, walks them with host-shaped ancestor
104
+ semantics, and consults your ignorer at every node. One runner test is registered
105
+ per case:
106
+
107
+ ```ts
108
+ import { testIgnorer } from '@systemfsoftware/stryker-ignorer-kit/tester'
109
+ import { strykerIgnorers } from '../src/mod.js'
110
+
111
+ await testIgnorer(strykerIgnorers[0], {
112
+ kept: [
113
+ { name: 'ordinary call', code: 'const client = createClient(host)' },
114
+ { name: 'logger.info still mutates', code: 'logger.info("ready")' },
115
+ ],
116
+ ignored: [
117
+ {
118
+ name: 'metric name',
119
+ code: 'metrics.counter("requests")',
120
+ ignores: [{ text: '"requests"', reason: METRIC_NAME }],
121
+ },
122
+ {
123
+ name: 'everything under logger.trace',
124
+ code: 'logger.trace(sum(a, b))',
125
+ ignores: ['sum(a, b)', 'a', 'b'],
126
+ },
127
+ ],
128
+ })
129
+ ```
130
+
131
+ Case semantics:
132
+
133
+ - **kept** — no node in the snippet may yield a reason.
134
+ - **ignored** — each expectation must match a _distinct_ ignored span (multiset);
135
+ extra ignored spans do not fail (containment, not totality).
136
+ - Spans are source-text slices, quotes included: the string literal in
137
+ `metrics.counter("requests")` is `"requests"`, not `requests`.
138
+ - A bare string expectation matches on text; `{ text, reason }` pins the reason.
139
+ - `lang` defaults to `ts`; override per case (`js`, `jsx`, `tsx`).
140
+ - A failing case throws an enumeration of its snippet, expectations, and received
141
+ spans (text, node type, reason). Where no runner globals exist, `testIgnorer`
142
+ runs every case and throws one aggregate error naming all failures.
143
+ - `keeps` (either case kind) names spans that must **stay live** even when siblings in the
144
+ same snippet are ignored — for rows that pin one node's liveness inside a partly-ignored
145
+ expression. A kept case without `keeps` still asserts nothing at all is ignored.
146
+
147
+ ### 4. Ship it
148
+
149
+ `pnpm --filter <your-package> test` green, `api:update` for the report, a
150
+ changeset entry, and the AGENTS/README wording true to what ships. The family
151
+ rules bind: zero Effect, no type assertions, complexity ≤ 2 per function —
152
+ narrow with small type-predicate functions, as above.
153
+
154
+ ## Semantics worth knowing
155
+
156
+ - The engine consults ignorers **per mutant candidate**, point-only: a reason on
157
+ node X suppresses X's mutants; descendants are visited and re-judged on their
158
+ own. Subtree behaviour therefore comes from scanning `ctx.ancestors`, never
159
+ from pruning.
160
+ - Ancestor chains are **nearest-first**: `ancestors[0]` is the parent.
161
+ - Stryker `StrykerIgnore`/`Restore` directives and `excludedMutations` win before
162
+ any ignorer is asked; among ignorers, the first reason in configured order wins.
163
+ - The tester walks every node (a superset of host consultation), so a green suite
164
+ pins your decision policy; host consult policy stays pinned by the engine and
165
+ instrumenter suites.
166
+
167
+ ## API reference
168
+
169
+ | Export | Entry | What it is |
170
+ | -------------------------------------------------------------------------- | ---------- | -------------------------------------------------------------------------- |
171
+ | `defineIgnorer(definition)` | `.` | compiles `{ name, visitors }` to the `Ignorer` wire contract |
172
+ | `IgnorerVisitors`, `IgnorerVisitor`, `IgnorerContext`, `IgnorerDefinition` | `.` | authoring types |
173
+ | `testIgnorer(subject, cases)` | `./tester` | snippet harness; one test per case, aggregate throw without runner globals |
174
+ | `IgnorerCases`, `IgnoredCase`, `KeptCase`, `IgnoredSpan`, `ScriptLang` | `./tester` | case types |
175
+
176
+ ## License
177
+
178
+ [Apache 2.0](LICENSE)
@@ -0,0 +1,24 @@
1
+ import { Ignorer, Node } from "@systemfsoftware/stryker-ignorer-interface";
2
+ //#region src/mod.d.ts
3
+ export interface IgnorerContext {
4
+ /** Nearest-first as the host hands it over; the parent is the first element. */
5
+ readonly ancestors: readonly Node[];
6
+ parentIf<K extends Node['type']>(kind: K): Extract<Node, {
7
+ readonly type: K;
8
+ }> | undefined;
9
+ ancestorIf<K extends Node['type']>(kind: K): Extract<Node, {
10
+ readonly type: K;
11
+ }> | undefined;
12
+ }
13
+ export type IgnorerVisitor<K extends Node['type']> = (node: Extract<Node, {
14
+ readonly type: K;
15
+ }>, ctx: IgnorerContext) => string | undefined;
16
+ export type IgnorerVisitors = { readonly [K in Node['type']]?: IgnorerVisitor<K>; } & {
17
+ readonly onAnyNode?: (node: Node, ctx: IgnorerContext) => string | undefined;
18
+ };
19
+ export interface IgnorerDefinition {
20
+ readonly name: string;
21
+ readonly visitors: IgnorerVisitors;
22
+ }
23
+ export declare function defineIgnorer(definition: IgnorerDefinition): Ignorer;
24
+ //#endregion
package/dist/index.mjs ADDED
@@ -0,0 +1,38 @@
1
+ //#region src/mod.ts
2
+ function isNodeOfType(node, kind) {
3
+ return node !== void 0 && node.type === kind;
4
+ }
5
+ function makeContext(ancestors) {
6
+ return {
7
+ ancestors,
8
+ parentIf: (kind) => isNodeOfType(ancestors[0], kind) ? ancestors[0] : void 0,
9
+ ancestorIf: (kind) => ancestors.find((ancestor) => isNodeOfType(ancestor, kind))
10
+ };
11
+ }
12
+ function isVisitor(value) {
13
+ return typeof value === "function";
14
+ }
15
+ function typedVisitor(visitors, node) {
16
+ const entry = visitors[node.type];
17
+ return isVisitor(entry) ? entry : void 0;
18
+ }
19
+ function callTyped(visitors, node, ctx) {
20
+ const visit = typedVisitor(visitors, node);
21
+ return visit === void 0 ? void 0 : visit(node, ctx);
22
+ }
23
+ function callAny(visitors, node, ctx) {
24
+ return visitors.onAnyNode?.(node, ctx);
25
+ }
26
+ function decide(visitors, node, ctx) {
27
+ const reason = callTyped(visitors, node, ctx);
28
+ return reason === void 0 ? callAny(visitors, node, ctx) : reason;
29
+ }
30
+ function defineIgnorer(definition) {
31
+ const visitors = definition.visitors;
32
+ return {
33
+ name: definition.name,
34
+ shouldIgnore: (node, ancestors) => decide(visitors, node, makeContext(ancestors))
35
+ };
36
+ }
37
+ //#endregion
38
+ export { defineIgnorer };
@@ -0,0 +1,32 @@
1
+ import { Ignorer } from "@systemfsoftware/stryker-ignorer-interface";
2
+ //#region src/tester.d.ts
3
+ export type ScriptLang = 'js' | 'jsx' | 'ts' | 'tsx';
4
+ export interface IgnoredSpan {
5
+ readonly text: string;
6
+ readonly reason?: string;
7
+ }
8
+ export interface IgnoredCase {
9
+ readonly name: string;
10
+ readonly code: string;
11
+ readonly lang?: ScriptLang;
12
+ readonly ignores: readonly (string | IgnoredSpan)[];
13
+ readonly keeps?: readonly string[];
14
+ }
15
+ export interface KeptCase {
16
+ readonly name: string;
17
+ readonly code: string;
18
+ readonly lang?: ScriptLang;
19
+ readonly keeps?: readonly string[];
20
+ }
21
+ export interface IgnorerCases {
22
+ readonly ignored?: readonly IgnoredCase[];
23
+ readonly kept?: readonly KeptCase[];
24
+ }
25
+ /**
26
+ * Parses each case with the instrumenter's parser convention, walks with host-shaped
27
+ * ancestor semantics, and consults the subject at every node. With runner globals present
28
+ * this registers one test per case under the subject's name; without them it runs every
29
+ * case here and rejects with one error enumerating every failing case.
30
+ */
31
+ export declare function testIgnorer(subject: Ignorer, cases: IgnorerCases): Promise<void>;
32
+ //#endregion
@@ -0,0 +1,224 @@
1
+ import { parseAndWalk } from "oxc-walker";
2
+ //#region src/tester.ts
3
+ let oxc;
4
+ async function loadOxc() {
5
+ if (oxc === void 0) oxc = await import("oxc-parser");
6
+ return oxc;
7
+ }
8
+ const fileNames = {
9
+ js: "case.js",
10
+ jsx: "case.jsx",
11
+ ts: "case.ts",
12
+ tsx: "case.tsx"
13
+ };
14
+ function toSpan(expect) {
15
+ return typeof expect === "string" ? { text: expect } : expect;
16
+ }
17
+ function langOf(one) {
18
+ return one.lang ?? "ts";
19
+ }
20
+ function keepsOf(one) {
21
+ return one.keeps ?? [];
22
+ }
23
+ function toKept(one) {
24
+ return {
25
+ kind: "kept",
26
+ name: one.name,
27
+ code: one.code,
28
+ lang: langOf(one),
29
+ expects: [],
30
+ keeps: keepsOf(one)
31
+ };
32
+ }
33
+ function toIgnored(one) {
34
+ return {
35
+ kind: "ignored",
36
+ name: one.name,
37
+ code: one.code,
38
+ lang: langOf(one),
39
+ expects: one.ignores.map(toSpan),
40
+ keeps: keepsOf(one)
41
+ };
42
+ }
43
+ function keptFiles(kept) {
44
+ return (kept ?? []).map(toKept);
45
+ }
46
+ function ignoredFiles(ignored) {
47
+ return (ignored ?? []).map(toIgnored);
48
+ }
49
+ function toFiles(cases) {
50
+ return [...keptFiles(cases.kept), ...ignoredFiles(cases.ignored)];
51
+ }
52
+ function errorMessage(error) {
53
+ return error.message;
54
+ }
55
+ function parseFailure(errors) {
56
+ return `parse failed: ${errors.map(errorMessage).join("; ")}`;
57
+ }
58
+ function recordIfIgnored(subject, node, ancestors, received, file) {
59
+ const reason = subject.shouldIgnore(node, [...ancestors]);
60
+ if (reason !== void 0) received.push({
61
+ text: file.code.slice(node.start, node.end),
62
+ reason,
63
+ type: node.type
64
+ });
65
+ }
66
+ async function collect(subject, file) {
67
+ const { parseSync } = await loadOxc();
68
+ const received = [];
69
+ const ancestors = [];
70
+ const result = parseAndWalk(file.code, fileNames[file.lang], {
71
+ parseSync,
72
+ parseOptions: {
73
+ lang: file.lang,
74
+ range: true
75
+ },
76
+ enter(node) {
77
+ recordIfIgnored(subject, node, ancestors, received, file);
78
+ ancestors.unshift(node);
79
+ },
80
+ leave() {
81
+ ancestors.shift();
82
+ }
83
+ });
84
+ return result.errors.length > 0 ? parseFailure(result.errors) : received;
85
+ }
86
+ function allIgnoredFailures(received) {
87
+ return received.length === 0 ? [] : [`expected nothing ignored, received ${received.length} span(s)`];
88
+ }
89
+ function keepFailure(received, keep) {
90
+ const hit = received.find((span) => span.text === keep);
91
+ return hit === void 0 ? [] : [`expected span ${JSON.stringify(keep)} to stay live, but it was ignored${reasonSuffix(hit.reason)}`];
92
+ }
93
+ function keepFailures(file, received) {
94
+ return file.keeps.flatMap((keep) => keepFailure(received, keep));
95
+ }
96
+ function keptFailures(file, received) {
97
+ return file.keeps.length === 0 ? allIgnoredFailures(received) : keepFailures(file, received);
98
+ }
99
+ function keptOutcome(file, received) {
100
+ const failures = keptFailures(file, received);
101
+ return {
102
+ file,
103
+ passed: failures.length === 0,
104
+ failures,
105
+ received
106
+ };
107
+ }
108
+ function reasonMatches(actual, pinned) {
109
+ return pinned === void 0 || actual === pinned;
110
+ }
111
+ function spansMatch(span, expect) {
112
+ return span.text === expect.text && reasonMatches(span.reason, expect.reason);
113
+ }
114
+ function pinnedSuffix(expect) {
115
+ return expect.reason === void 0 ? "" : ` with reason ${JSON.stringify(expect.reason)}`;
116
+ }
117
+ function missingMessage(expect) {
118
+ return `expected ignored span ${JSON.stringify(expect.text)}${pinnedSuffix(expect)} was not ignored`;
119
+ }
120
+ function expectFailures(pool, expect) {
121
+ const at = pool.findIndex((span) => spansMatch(span, expect));
122
+ if (at === -1) return [missingMessage(expect)];
123
+ pool.splice(at, 1);
124
+ return [];
125
+ }
126
+ function ignoredOutcome(file, received) {
127
+ const pool = [...received];
128
+ const failures = [...file.expects.flatMap((expect) => expectFailures(pool, expect)), ...keepFailures(file, received)];
129
+ return {
130
+ file,
131
+ passed: failures.length === 0,
132
+ failures,
133
+ received
134
+ };
135
+ }
136
+ function judge(file, received) {
137
+ return file.kind === "kept" ? keptOutcome(file, received) : ignoredOutcome(file, received);
138
+ }
139
+ function reasonSuffix(reason) {
140
+ return ` reason ${JSON.stringify(reason)}`;
141
+ }
142
+ function spanLine(span) {
143
+ return `- ${JSON.stringify(span.text)} (${span.type})${reasonSuffix(span.reason)}`;
144
+ }
145
+ function failureLine(failure) {
146
+ return `- ${failure}`;
147
+ }
148
+ function receivedLines(received) {
149
+ return received.length === 0 ? ["- none"] : received.map(spanLine);
150
+ }
151
+ function messageFor(outcome) {
152
+ return [
153
+ `case ${JSON.stringify(outcome.file.name)} (${outcome.file.kind}) failed:`,
154
+ "code:",
155
+ outcome.file.code,
156
+ "failures:",
157
+ ...outcome.failures.map(failureLine),
158
+ "received ignored spans:",
159
+ ...receivedLines(outcome.received)
160
+ ].join("\n");
161
+ }
162
+ async function outcomeOf(subject, file) {
163
+ const result = await collect(subject, file);
164
+ return typeof result === "string" ? {
165
+ file,
166
+ passed: false,
167
+ failures: [result],
168
+ received: []
169
+ } : judge(file, result);
170
+ }
171
+ function isDescribe(value) {
172
+ return typeof value === "function";
173
+ }
174
+ function isIt(value) {
175
+ return typeof value === "function";
176
+ }
177
+ function globalDescribe() {
178
+ const value = Reflect.get(globalThis, "describe");
179
+ return isDescribe(value) ? value : void 0;
180
+ }
181
+ function globalIt() {
182
+ const value = Reflect.get(globalThis, "it");
183
+ return isIt(value) ? value : void 0;
184
+ }
185
+ function withIt(describe) {
186
+ const it = globalIt();
187
+ return it === void 0 ? void 0 : {
188
+ describe,
189
+ it
190
+ };
191
+ }
192
+ function runner() {
193
+ const describe = globalDescribe();
194
+ return describe === void 0 ? void 0 : withIt(describe);
195
+ }
196
+ async function runAll(subject, files) {
197
+ const failed = (await Promise.all(files.map((file) => outcomeOf(subject, file)))).filter((outcome) => outcome.passed === false);
198
+ if (failed.length > 0) throw new Error(failed.map(messageFor).join("\n\n"));
199
+ }
200
+ function registerCase(run, subject, file) {
201
+ run.it(file.name, async () => {
202
+ const outcome = await outcomeOf(subject, file);
203
+ if (outcome.passed === false) throw new Error(messageFor(outcome));
204
+ });
205
+ }
206
+ function registerAll(run, subject, files) {
207
+ run.describe(subject.name, () => {
208
+ for (const file of files) registerCase(run, subject, file);
209
+ });
210
+ }
211
+ /**
212
+ * Parses each case with the instrumenter's parser convention, walks with host-shaped
213
+ * ancestor semantics, and consults the subject at every node. With runner globals present
214
+ * this registers one test per case under the subject's name; without them it runs every
215
+ * case here and rejects with one error enumerating every failing case.
216
+ */
217
+ async function testIgnorer(subject, cases) {
218
+ const run = runner();
219
+ const files = toFiles(cases);
220
+ if (run === void 0) await runAll(subject, files);
221
+ else registerAll(run, subject, files);
222
+ }
223
+ //#endregion
224
+ export { testIgnorer };
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@systemfsoftware/stryker-ignorer-kit",
3
+ "license": "Apache-2.0",
4
+ "version": "0.0.0",
5
+ "author": "Ryan Lee <drdgvhbh@gmail.com>",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/systemfsoftware/stryker-js-effect.git",
9
+ "directory": "packages/ignorers/kit"
10
+ },
11
+ "homepage": "https://github.com/systemfsoftware/stryker-js-effect/tree/main/packages/ignorers/kit#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/systemfsoftware/stryker-js-effect/issues"
14
+ },
15
+ "description": "Authoring and testing kit for Stryker ignorers — typed visitors compiled to the Ignorer wire contract, and a RuleTester-shaped harness that verifies them from source snippets.",
16
+ "keywords": [
17
+ "stryker",
18
+ "stryker-mutator",
19
+ "mutation-testing",
20
+ "ignorer",
21
+ "testing"
22
+ ],
23
+ "type": "module",
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.mjs"
31
+ },
32
+ "./tester": {
33
+ "types": "./dist/tester.d.ts",
34
+ "default": "./dist/tester.mjs"
35
+ },
36
+ "./package.json": "./package.json"
37
+ },
38
+ "dependencies": {
39
+ "@oxc-project/types": "^0.140.0",
40
+ "oxc-parser": "^0.140.0",
41
+ "oxc-walker": "^1",
42
+ "@systemfsoftware/stryker-ignorer-interface": "^0.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@microsoft/api-extractor": "^7",
46
+ "@systemfsoftware/arethetypeswrong-cli": "^4",
47
+ "@systemfsoftware/tsconfig": "^1",
48
+ "@types/node": "^24",
49
+ "@vitest/coverage-v8": "^4",
50
+ "concurrently": "^10",
51
+ "oxlint": "^1",
52
+ "rimraf": "^6.1.3",
53
+ "tsdown": "^0.23.0",
54
+ "typescript": "^7",
55
+ "vitest": "^4",
56
+ "@systemfsoftware/tsdown-config": "^0.1.0",
57
+ "@systemfsoftware/oxlint-ignorer-config": "^0.0.0",
58
+ "@systemfsoftware/vitest-config": "^0.1.0"
59
+ },
60
+ "publishConfig": {
61
+ "access": "public",
62
+ "provenance": true
63
+ },
64
+ "scripts": {
65
+ "build": "tsdown",
66
+ "clean": "rimraf dist",
67
+ "typecheck": "tsc --noEmit --incremental && tsc -p tsconfig.node.json --noEmit",
68
+ "test": "vitest run",
69
+ "lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
70
+ "attw": "attw --pack .",
71
+ "api:check": "concurrently --kill-others-on-fail \"api-extractor run\" \"api-extractor run --config api-extractor.tester.json\"",
72
+ "api:update": "concurrently --kill-others-on-fail \"api-extractor run --local\" \"api-extractor run --local --config api-extractor.tester.json\""
73
+ }
74
+ }