Skip to content

Commit 135b7d6

Browse files
committed
test(kernel): close remaining mutation gaps in firstStderrLine/detail helpers (#1456)
Each addition here was verified against a hand-applied mutation (matching Stryker's actual survivor diffs) before landing, confirming it fails on the mutant and passes on the original: - firstStderrLine: line-trim-before-prefix-match (a real skip-pattern line ahead of the leading-whitespace one is required, since redactDiagnosticData already .trim()s the whole stderr string once before firstStderrLine ever sees it), and the >200-char truncation branch (both sides of the boundary: 200 exact vs 201+). - stringDetail/booleanDetail: reject a wrong-typed diagnosticId/logPath/ hint/retriable instead of surfacing it. - stripDiagnosticMeta: details drops to undefined once stripping the known meta keys leaves nothing behind.
1 parent a6e095e commit 135b7d6

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

‎src/kernel/__tests__/errors.test.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,83 @@ test('normalizeError strips a zero-space "error:" prefix without requiring or ov
290290
assert.equal(normalized.message, 'simctl boot failed: immediate text');
291291
});
292292

293+
test('normalizeError trims each stderr line before prefix-matching, so leading whitespace cannot defeat the anchored noise-prefix regex', () => {
294+
// The leading-whitespace line must NOT be the string's first/last line: the
295+
// whole `details.stderr` value is `.trim()`-ed once by redaction before
296+
// firstStderrLine ever sees it, which would otherwise erase exactly the
297+
// whitespace this test needs to keep. A real skip-pattern line ahead of it
298+
// keeps that whitespace internal to the string.
299+
const err = new AppError('COMMAND_FAILED', 'simctl boot failed', {
300+
processExitError: true,
301+
stderr:
302+
'An error was encountered processing the command (domain=X):\n' +
303+
' error: leading whitespace line\n',
304+
});
305+
const normalized = normalizeError(err);
306+
assert.equal(normalized.message, 'simctl boot failed: leading whitespace line');
307+
});
308+
309+
// firstStderrLine truncates an excerpt over 200 characters; pin both sides of
310+
// that boundary explicitly since a passing-but-short-excerpt test can never
311+
// exercise it.
312+
313+
test('normalizeError truncates a stderr excerpt over 200 characters and appends an ellipsis', () => {
314+
const longLine = 'x'.repeat(250);
315+
const err = new AppError('COMMAND_FAILED', 'simctl boot failed', {
316+
processExitError: true,
317+
stderr: `${longLine}\n`,
318+
});
319+
const normalized = normalizeError(err);
320+
assert.equal(normalized.message, `simctl boot failed: ${'x'.repeat(200)}...`);
321+
});
322+
323+
test('normalizeError leaves a stderr excerpt of exactly 200 characters untruncated', () => {
324+
const exactLine = 'y'.repeat(200);
325+
const err = new AppError('COMMAND_FAILED', 'simctl boot failed', {
326+
processExitError: true,
327+
stderr: `${exactLine}\n`,
328+
});
329+
const normalized = normalizeError(err);
330+
assert.equal(normalized.message, `simctl boot failed: ${exactLine}`);
331+
});
332+
333+
// --- stringDetail/booleanDetail/stripDiagnosticMeta: type-guard and
334+
// empty-after-stripping contracts normalizeError relies on ---
335+
336+
test('normalizeError ignores a non-string details.diagnosticId/logPath/hint rather than surfacing the wrong-typed value', () => {
337+
const normalized = normalizeError(
338+
new AppError('COMMAND_FAILED', 'runner failed', {
339+
diagnosticId: 12345 as unknown as string,
340+
logPath: true as unknown as string,
341+
hint: [] as unknown as string,
342+
}),
343+
);
344+
assert.equal(normalized.diagnosticId, undefined);
345+
assert.equal(normalized.logPath, undefined);
346+
// hint falls back to the code's default once the non-string value is rejected.
347+
assert.equal(normalized.hint, defaultHintForCode('COMMAND_FAILED'));
348+
});
349+
350+
test('normalizeError ignores a non-boolean details.retriable and falls back to the code-level default', () => {
351+
const normalized = normalizeError(
352+
new AppError('DEVICE_IN_USE', 'device busy', { retriable: 'yes' as unknown as boolean }),
353+
);
354+
assert.equal(normalized.retriable, true); // retriableForErrorCode('DEVICE_IN_USE') default, not the string.
355+
});
356+
357+
test('normalizeError omits details entirely once stripping diagnostic-meta keys leaves nothing behind', () => {
358+
const normalized = normalizeError(
359+
new AppError('COMMAND_FAILED', 'runner failed', {
360+
hint: 'custom hint',
361+
diagnosticId: 'diag-1',
362+
logPath: '/tmp/diag.log',
363+
retriable: true,
364+
supportedOn: 'ios',
365+
}),
366+
);
367+
assert.equal(normalized.details, undefined);
368+
});
369+
293370
// --- AppError: construction contract ---
294371

295372
test('AppError is a real Error carrying code/message/details/cause', () => {

0 commit comments

Comments
 (0)