Skip to content

Commit 83d02c2

Browse files
committed
fix: add post-replace assertions to catch silent mutation failures (#539)
1 parent e640a4b commit 83d02c2

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

tests/integration/incremental-edge-parity.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ describe('Incremental edge parity (CI gate)', () => {
130130
let src = fs.readFileSync(p, 'utf-8');
131131
// Change add implementation but keep the same signature and exports
132132
src = src.replace('return a + b;', 'return b + a;');
133+
if (!src.includes('return b + a;'))
134+
throw new Error('Mutation failed: target string not found in math.js');
133135
fs.writeFileSync(p, src);
134136
});
135137
}, 60_000);
@@ -156,6 +158,8 @@ describe('Incremental edge parity (CI gate)', () => {
156158
'module.exports = { add, multiply, square };',
157159
`function subtract(a, b) {\n return a - b;\n}\n\nmodule.exports = { add, multiply, square, subtract };`,
158160
);
161+
if (!src.includes('subtract'))
162+
throw new Error('Mutation failed: module.exports replacement not applied in math.js');
159163
fs.writeFileSync(mathPath, src);
160164

161165
// Have index.js import and call the new function
@@ -165,10 +169,14 @@ describe('Incremental edge parity (CI gate)', () => {
165169
"const { add } = require('./math');",
166170
"const { add, subtract } = require('./math');",
167171
);
172+
if (!indexSrc.includes('subtract'))
173+
throw new Error('Mutation failed: require replacement not applied in index.js');
168174
indexSrc = indexSrc.replace(
169175
'console.log(add(1, 2));',
170176
'console.log(add(1, 2));\n console.log(subtract(5, 3));',
171177
);
178+
if (!indexSrc.includes('subtract(5, 3)'))
179+
throw new Error('Mutation failed: console.log replacement not applied in index.js');
172180
fs.writeFileSync(indexPath, indexSrc);
173181
});
174182
}, 60_000);
@@ -207,10 +215,15 @@ describe('Incremental edge parity (CI gate)', () => {
207215
// Update index.js to remove the require
208216
const indexPath = path.join(dir, 'index.js');
209217
let src = fs.readFileSync(indexPath, 'utf-8');
218+
const before = src;
210219
src = src.replace("const { sumOfSquares, Calculator } = require('./utils');\n", '');
211220
src = src.replace(' console.log(sumOfSquares(3, 4));\n', '');
212221
src = src.replace(' const calc = new Calculator();\n', '');
213222
src = src.replace(' console.log(calc.compute(5, 6));\n', '');
223+
if (src === before)
224+
throw new Error(
225+
'Mutation failed: no replacements applied in index.js for file deletion scenario',
226+
);
214227
fs.writeFileSync(indexPath, src);
215228
});
216229
}, 60_000);

0 commit comments

Comments
 (0)