@systemfsoftware/stryker-plugins 0.7.0 → 0.8.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/README.md
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
1
|
# @systemfsoftware/stryker-plugins
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+

|
|
4
|
+

|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
> Stop Effect `Schema` declarations from dragging your Stryker score below 100%.
|
|
6
7
|
|
|
7
|
-
A
|
|
8
|
+
A brand description, a `_tag`, a `title` — mutate any of them and the source changes but the behaviour does not, so no test can ever kill the mutant. Those unkillable mutants sit in your report forever, indistinguishable from real coverage gaps. This [Stryker](https://stryker-mutator.io) Ignore plugin removes them, so the score that remains is behaviour.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
- `Schema.TaggedClass` / `Schema.TaggedError` `_tag` identifiers,
|
|
11
|
-
- the field schemas of those declarations,
|
|
12
|
-
- `optionalWith` default values,
|
|
13
|
-
- the documentation entries of an `annotations({…})` call — `identifier`, `description`, `title`, `documentation`, `examples`,
|
|
14
|
-
- an `annotations({…})` object whose entries are _all_ documentation.
|
|
15
|
-
|
|
16
|
-
The last two are deliberately asymmetric. Replacing a `title` cannot change what a
|
|
17
|
-
schema does, so it is ignored wherever it appears. Emptying the whole object can —
|
|
18
|
-
`annotations({ arbitrary })` holds the generator the property tests draw from, and
|
|
19
|
-
dropping it silently changes what gets generated. So an object is ignored only when
|
|
20
|
-
every entry in it documents; one behaviour-bearing sibling keeps the object mutated
|
|
21
|
-
while its documentation entries stay ignored.
|
|
22
|
-
|
|
23
|
-
`arbitrary`, `pretty`, `equivalence`, `message`, `jsonSchema` and `parseIssueTitle`
|
|
24
|
-
are absent from the documentation set by design: each alters observable behaviour, so
|
|
25
|
-
a surviving mutant of one is a test gap to close, never an equivalent mutant to hide.
|
|
26
|
-
|
|
27
|
-
Schema declarations are **data, not behaviour** (Constitution Article III §4) — mutating them produces unkillable equivalent mutants that drag a mutation score below 100% for no real coverage gap. This plugin removes that noise so the score reflects logic.
|
|
28
|
-
|
|
29
|
-
## Usage
|
|
10
|
+
## Install
|
|
30
11
|
|
|
31
12
|
```bash
|
|
32
13
|
pnpm add -D @systemfsoftware/stryker-plugins
|
|
@@ -45,5 +26,35 @@ In `stryker.config.json`:
|
|
|
45
26
|
}
|
|
46
27
|
```
|
|
47
28
|
|
|
29
|
+
Mutants it recognizes are reported as `Ignored`, each carrying the reason it was safe to skip.
|
|
30
|
+
|
|
48
31
|
> [!NOTE]
|
|
49
32
|
> `@stryker-mutator/api` is a peer dependency — your Stryker install provides it. `effect` is a direct dependency (the plugin decodes AST nodes with `Schema`).
|
|
33
|
+
|
|
34
|
+
## What it ignores
|
|
35
|
+
|
|
36
|
+
| Declaration | Example |
|
|
37
|
+
| --------------------------------------------------------- | ------------------------------------------------------------------- |
|
|
38
|
+
| Brand descriptions | `Symbol.for('UserId')` |
|
|
39
|
+
| `TaggedClass` / `TaggedError` tags | `S.TaggedClass<A>()('Placed', {…})` |
|
|
40
|
+
| The field schemas of those declarations | the `{…}` above |
|
|
41
|
+
| `optionalWith` defaults | `S.optionalWith(S.Number, { default: () => 0 })` |
|
|
42
|
+
| Documentation annotations | `identifier`, `description`, `title`, `documentation`, `examples` |
|
|
43
|
+
| An `annotations({…})` object that is _only_ documentation | `S.annotations({ title: 'Amount' })` |
|
|
44
|
+
| A `TemplateLiteral` head a piped `pattern` already forces | `S.TemplateLiteral('usr', S.String).pipe(S.pattern(/^usr[a-z]*$/))` |
|
|
45
|
+
|
|
46
|
+
## Where the line is
|
|
47
|
+
|
|
48
|
+
Every ignore is proven redundant, never merely assumed — anything a test could observe keeps its mutants.
|
|
49
|
+
|
|
50
|
+
`arbitrary`, `pretty`, `equivalence`, `message`, `jsonSchema` and `parseIssueTitle` are **not** documentation: each changes what the schema does, so a survivor there is a test gap to close. That is why the two `annotations` rules differ — a `title` is ignored wherever it appears, but the enclosing object is ignored only when every entry documents, since emptying an object holding an `arbitrary` would silently change what your property tests generate.
|
|
51
|
+
|
|
52
|
+
The `TemplateLiteral` head is ignored only where the piped pattern makes it unobservable: the head must be the first span with no regex metacharacters, and the pattern must be an unflagged regex literal opening `^` + that head, with no quantifier making its final character optional. A head with no pattern keeps its mutants, and so do `/^usr?…/`, `/^usr…/i`, `/^usr…/m`, and every span past the first.
|
|
53
|
+
|
|
54
|
+
## Contributing
|
|
55
|
+
|
|
56
|
+
Development setup and workflow: [AGENTS.md](AGENTS.md).
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
[MIT](LICENSE)
|
|
@@ -9,6 +9,11 @@ const StringLiteral = Schema.Struct({
|
|
|
9
9
|
type: Schema.Literal("StringLiteral"),
|
|
10
10
|
value: Schema.String
|
|
11
11
|
});
|
|
12
|
+
const RegExpLiteral = Schema.Struct({
|
|
13
|
+
type: Schema.Literal("RegExpLiteral"),
|
|
14
|
+
pattern: Schema.String,
|
|
15
|
+
flags: Schema.String
|
|
16
|
+
});
|
|
12
17
|
const ObjectExpression = Schema.Struct({ type: Schema.Literal("ObjectExpression") });
|
|
13
18
|
const ArrowFunctionExpression = Schema.Struct({ type: Schema.Literal("ArrowFunctionExpression") });
|
|
14
19
|
const UnknownNode = Schema.Struct({ type: Schema.String });
|
|
@@ -22,7 +27,7 @@ const CallExpression = Schema.suspend(() => Schema.Struct({
|
|
|
22
27
|
callee: Schema.suspend(() => AstNode),
|
|
23
28
|
arguments: Schema.Array(Schema.suspend(() => AstNode))
|
|
24
29
|
}));
|
|
25
|
-
const AstNode = Schema.suspend(() => Schema.Union(Identifier, StringLiteral, ObjectExpression, ArrowFunctionExpression, MemberExpression, CallExpression, UnknownNode));
|
|
30
|
+
const AstNode = Schema.suspend(() => Schema.Union(Identifier, StringLiteral, RegExpLiteral, ObjectExpression, ArrowFunctionExpression, MemberExpression, CallExpression, UnknownNode));
|
|
26
31
|
//#endregion
|
|
27
32
|
//#region src/effect-schema-ignorer/schema-declaration-ignore.ts
|
|
28
33
|
const SYMBOL_DESCRIPTION_IGNORED = "Symbol.for() brand description is identity-only data, not behaviour";
|
|
@@ -31,6 +36,7 @@ const TAGGED_FIELDS_IGNORED = "TaggedClass/TaggedError field schema is a declara
|
|
|
31
36
|
const OPTIONAL_DEFAULT_IGNORED = "optionalWith default value is config, not behaviour";
|
|
32
37
|
const ANNOTATION_OBJECT_IGNORED = "annotations object holding only documentation is a declaration, not behaviour";
|
|
33
38
|
const ANNOTATION_TEXT_IGNORED = "annotation documentation value is declaration data, not behaviour";
|
|
39
|
+
const TEMPLATE_HEAD_IGNORED = "TemplateLiteral head re-stated by an anchored pattern filter is a declaration of the encoded type, not behaviour";
|
|
34
40
|
/**
|
|
35
41
|
* The Effect `Schema` annotations that describe a schema without changing what
|
|
36
42
|
* it does. `arbitrary`, `pretty`, `equivalence`, `message`, `jsonSchema` and
|
|
@@ -69,6 +75,7 @@ const isMemberExpression = Schema.is(MemberExpression);
|
|
|
69
75
|
const isCallExpression = Schema.is(CallExpression);
|
|
70
76
|
const isDocumentationProperty = Schema.is(DocumentationProperty);
|
|
71
77
|
const isDocumentationObject = Schema.is(DocumentationObject);
|
|
78
|
+
const isRegExpLiteral = Schema.is(RegExpLiteral);
|
|
72
79
|
const isNamedMember = (node, object, property) => isMemberExpression(node) && isIdentifier(node.object) && node.object.name === object && isIdentifier(node.property) && node.property.name === property;
|
|
73
80
|
const isSymbolForCallee = (callee) => isNamedMember(callee, "Symbol", "for");
|
|
74
81
|
const isTaggedFactoryReference = (reference) => isMemberExpression(reference) && isIdentifier(reference.property) && TAGGED_FACTORIES.includes(reference.property.name);
|
|
@@ -76,6 +83,41 @@ const isTaggedFactoryCallee = (callee) => isCallExpression(callee) && isTaggedFa
|
|
|
76
83
|
const isArgumentOf = (node, parent, index, calleeMatches) => isCallExpression(parent) && calleeMatches(parent.callee) && parent.arguments[index] === node;
|
|
77
84
|
const isOptionalWithCallee = (callee) => isNamedMember(callee, "S", "optionalWith");
|
|
78
85
|
const isAnnotationsCallee = (callee) => isMemberExpression(callee) && isIdentifier(callee.property) && callee.property.name === "annotations";
|
|
86
|
+
/**
|
|
87
|
+
* A head whose every character stands for itself inside a regex. `a.b` is
|
|
88
|
+
* excluded because `^a.b` would also admit `axb`, which the head refuses.
|
|
89
|
+
*/
|
|
90
|
+
const REGEX_INERT_HEAD = /^[A-Za-z0-9_]+$/;
|
|
91
|
+
/** `?`, `*` and `{` make the character before them optional, so `^usr?` never forces the `r`. */
|
|
92
|
+
const OPTIONAL_QUANTIFIERS = [
|
|
93
|
+
"?",
|
|
94
|
+
"*",
|
|
95
|
+
"{"
|
|
96
|
+
];
|
|
97
|
+
const isNamedMethodCallee = (callee, method) => isMemberExpression(callee) && isIdentifier(callee.property) && callee.property.name === method;
|
|
98
|
+
/**
|
|
99
|
+
* Whether an unflagged, `^`-anchored regex admits only strings opening with
|
|
100
|
+
* `head`. Flags are refused outright: `i` would admit another casing and `m`
|
|
101
|
+
* would let `^` match a line start, and the head rejects both — so it decides.
|
|
102
|
+
*/
|
|
103
|
+
const forcesPrefix = (regex, head) => isRegExpLiteral(regex) && regex.flags === "" && regex.pattern.startsWith(`^${head}`) && !OPTIONAL_QUANTIFIERS.includes(regex.pattern.charAt(head.length + 1));
|
|
104
|
+
const patternForcesPrefix = (argument, head) => isCallExpression(argument) && isNamedMethodCallee(argument.callee, "pattern") && argument.arguments.some((regex) => forcesPrefix(regex, head));
|
|
105
|
+
/**
|
|
106
|
+
* The head of a `TemplateLiteral` piped straight into a `pattern` that already
|
|
107
|
+
* forces that same prefix. Effect rejects refinements as spans, so a prefixed
|
|
108
|
+
* wire format can only earn its `` `${head}${string}` `` type this way, and the
|
|
109
|
+
* prefix ends up stated twice by construction. Emptying the head then changes
|
|
110
|
+
* nothing observable: the filter still refuses every input the head would have
|
|
111
|
+
* refused, and Effect derives the arbitrary from the filter's regex rather than
|
|
112
|
+
* the head. Only the encoded *type* moves, which no test can see.
|
|
113
|
+
*
|
|
114
|
+
* Restricted to argument 0: a trailing span sits past the anchor, so an
|
|
115
|
+
* anchored prefix proves nothing about it and its mutants stay.
|
|
116
|
+
*/
|
|
117
|
+
const templateHeadRule = {
|
|
118
|
+
matches: (node, parent, grandparent, ancestor) => isStringLiteral(node) && REGEX_INERT_HEAD.test(node.value) && isArgumentOf(node, parent, 0, (callee) => isNamedMethodCallee(callee, "TemplateLiteral")) && isMemberExpression(grandparent) && grandparent.object === parent && isIdentifier(grandparent.property) && grandparent.property.name === "pipe" && isCallExpression(ancestor) && ancestor.callee === grandparent && ancestor.arguments.some((argument) => patternForcesPrefix(argument, node.value)),
|
|
119
|
+
reason: TEMPLATE_HEAD_IGNORED
|
|
120
|
+
};
|
|
79
121
|
const argumentRule = (is, argumentIndex, calleeMatches, reason) => ({
|
|
80
122
|
matches: (node, parent) => is(node) && isArgumentOf(node, parent, argumentIndex, calleeMatches),
|
|
81
123
|
reason
|
|
@@ -97,7 +139,8 @@ const RULES = [
|
|
|
97
139
|
argumentRule(isObjectExpression, 1, isTaggedFactoryCallee, TAGGED_FIELDS_IGNORED),
|
|
98
140
|
argumentRule(isArrowFunctionExpression, 1, isOptionalWithCallee, OPTIONAL_DEFAULT_IGNORED),
|
|
99
141
|
argumentRule(isDocumentationObject, 0, isAnnotationsCallee, ANNOTATION_OBJECT_IGNORED),
|
|
100
|
-
documentationValueRule
|
|
142
|
+
documentationValueRule,
|
|
143
|
+
templateHeadRule
|
|
101
144
|
];
|
|
102
145
|
const decideSchemaDeclarationIgnore = (node, parent, grandparent, ancestor) => RULES.find((rule) => rule.matches(node, parent, grandparent, ancestor))?.reason;
|
|
103
146
|
//#endregion
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as strykerPlugins } from "./effect-schema-ignorer-
|
|
1
|
+
import { t as strykerPlugins } from "./effect-schema-ignorer-C8RpAXcS.mjs";
|
|
2
2
|
export { strykerPlugins };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as strykerPlugins$2 } from "./effect-schema-ignorer-
|
|
1
|
+
import { t as strykerPlugins$2 } from "./effect-schema-ignorer-C8RpAXcS.mjs";
|
|
2
2
|
import { PluginKind, declareValuePlugin } from "@stryker-mutator/api/plugin";
|
|
3
3
|
import { Schema } from "effect";
|
|
4
4
|
//#region src/in-source-test-ignorer/ast-node.schema.ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemfsoftware/stryker-plugins",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"vitest": "^4",
|
|
54
54
|
"@systemfsoftware/arethetypeswrong-cli": "^1.0.7",
|
|
55
55
|
"@systemfsoftware/effect-schema-law": "^0.5.0",
|
|
56
|
-
"@systemfsoftware/effect-schema-vite": "^1.4.0",
|
|
57
56
|
"@systemfsoftware/oxlint-config": "^0.1.0",
|
|
57
|
+
"@systemfsoftware/effect-schema-vite": "^1.4.0",
|
|
58
58
|
"@systemfsoftware/stryker-js-core": "^1.1.6",
|
|
59
59
|
"@systemfsoftware/tsconfig": "^1.2.6",
|
|
60
60
|
"@systemfsoftware/vitest-config": "^0.1.0",
|