Skip to content

Commit c0bdef1

Browse files
fix(mutation-gate): pin CallExpression equivalents to their own node column
Review follow-ups: descendant-column matching in validateEquivalenceEntries is now limited to the condition-shaped mutators whose Stryker location can start at a sub-expression (ConditionalExpression, LogicalOperator). Every other mutator must start exactly at the recorded column, so an identifier left at a removed inner call former column no longer validates a CallExpression entry; a source-edit rejection test covers outer(inner(arg)) -> outer(arg). Removed the registry equivalence for the openai-codex OAuth ConditionalExpression mutant as requested; the unrelated stream-consumer equivalence is unchanged. node --test scripts/stryker-diff.test.mjs passes.
1 parent b9a23aa commit c0bdef1

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

‎scripts/stryker-diff.mjs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ const MUTATOR_NODE_PREDICATES = new Map([
533533
],
534534
])
535535

536+
// Mutators whose Stryker start location can point at a sub-expression of the mutated node.
537+
const MUTATOR_SUBELEMENT_LOCATIONS = new Set(["ConditionalExpression", "LogicalOperator"])
538+
536539
function lineHasMutatorNode(source, filePath, line, column, mutator) {
537540
const predicate = MUTATOR_NODE_PREDICATES.get(mutator)
538541
if (!predicate) return false
@@ -548,10 +551,17 @@ function lineHasMutatorNode(source, filePath, line, column, mutator) {
548551
// expression descendants on that line. Pinning the column stops a same-line edit from
549552
// silently re-binding an accepted equivalence to a different mutant.
550553
let found = false
554+
// Stryker reports a condition-shaped mutant's location at the mutated sub-expression (for an
555+
// if statement the test, for a logical expression the operand), so only those mutators may
556+
// match a descendant at the recorded column. Every other mutator must have its own node start
557+
// exactly at the column: an identifier that happens to sit at a removed call's former column
558+
// must not validate a CallExpression entry.
559+
const allowDescendantColumn = MUTATOR_SUBELEMENT_LOCATIONS.has(mutator)
551560
function matchesColumn(node) {
552561
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile))
553562
if (start.line + 1 !== editorLine) return false
554563
if (start.character === column) return true
564+
if (!allowDescendantColumn) return false
555565
let childMatch = false
556566
ts.forEachChild(node, (child) => {
557567
if (childMatch) return

‎scripts/stryker-diff.test.mjs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,31 @@ describe("accepted equivalent mutants", () => {
12991299
)
13001300
})
13011301

1302+
it("rejects a CallExpression entry whose recorded column now holds only an identifier", () => {
1303+
// A registered call edited from outer(inner(arg)) to outer(arg) leaves the identifier
1304+
// arg at the removed inner call's former column. Descendant-column matching is only for
1305+
// condition-shaped mutators, so an identifier must not validate a CallExpression entry.
1306+
const sourceBefore = "const y = outer(inner(arg))\n"
1307+
const sourceAfter = "const y = outer(arg)\n"
1308+
const entry = {
1309+
file: "src/example.ts",
1310+
line: 0,
1311+
column: 16,
1312+
mutator: "CallExpression",
1313+
replacement: "undefined",
1314+
reason: "example",
1315+
}
1316+
1317+
assert.deepEqual(
1318+
validateEquivalenceEntries([entry], () => sourceBefore),
1319+
[],
1320+
)
1321+
assert.match(
1322+
validateEquivalenceEntries([entry], () => sourceAfter).join("\n"),
1323+
/src\/example\.ts:0:16: expected CallExpression code at line 1/,
1324+
)
1325+
})
1326+
13021327
it("rejects an entry with an unknown mutator or missing file", () => {
13031328
const source = "const a = 1\n"
13041329
const unknown = { file: "src/example.ts", line: 0, mutator: "NotAMutator", replacement: "x", reason: "example" }

‎scripts/stryker-equivalences.json‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
{
22
"$comment": "Maintainer-reviewed equivalent mutants for the changed-code mutation gate. Each entry accepts exactly one mutant (file, start line, mutator name, replacement) as equivalent, with the review rationale. Entries are validated against the checked-in source before mutation testing; a missing file, unknown mutator, or line that no longer contains the named mutator fails the gate. Entries that do not match a reported mutant produce advisories for the tested files. Add entries only with maintainer approval; never add in-source Stryker directives. Lines are Stryker report lines (0-based): the editor shows the code at line + 1. Entries include the Stryker start column so a same-line change cannot silently re-bind an entry to a different mutant.",
33
"equivalences": [
4-
{
5-
"file": "src/api/providers/openai-codex.ts",
6-
"line": 274,
7-
"mutator": "ConditionalExpression",
8-
"replacement": "false",
9-
"reason": "the false mutant differs only if an abort lands between the OAuth race settle and this catch, a microtask window",
10-
"column": 7
11-
},
124
{
135
"file": "src/api/providers/openai-codex.ts",
146
"line": 1457,

0 commit comments

Comments
 (0)