◐ Shell
clean mode source ↗

test: normalize known inspector crash as completion · nodejs/node@da4dd86

11

'use strict';

223+

const assert = require('assert');

34

const fixtures = require('./fixtures');

45

const path = require('path');

5667

function debuggerFixturePath(name) {

78

return path.relative(process.cwd(), fixtures.path('debugger', name));

89

}

91010-

function escapeRegex(string) {

11-

return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');

11+

// Work around a pre-existing inspector issue: if the debuggee exits too quickly

12+

// the inspector can segfault while tearing down. For now normalize the segfault

13+

// back to the expected terminal event (e.g. "completed" or "miss")

14+

// until the upstream bug is fixed.

15+

// See https://github.com/nodejs/node/issues/62765

16+

// https://github.com/nodejs/node/issues/58245

17+

const probeTargetExitSignal = 'SIGSEGV';

18+19+

function assertProbeJson(output, expected) {

20+

const normalized = JSON.parse(output);

21+

const lastResult = normalized.results?.[normalized.results.length - 1];

22+23+

if (lastResult?.event === 'error' &&

24+

lastResult.error?.code === 'probe_target_exit' &&

25+

lastResult.error?.signal === probeTargetExitSignal) {

26+

// Log to facilitate debugging if this normalization is occurring.

27+

console.log('Normalizing trailing SIGSEGV in JSON probe output');

28+

normalized.results[normalized.results.length - 1] = expected.results.at(-1);

29+

}

30+31+

assert.deepStrictEqual(normalized, expected);

32+

}

33+34+

function assertProbeText(output, expected) {

35+

const signalPrefix = `Target exited with signal ${probeTargetExitSignal}`;

36+

const idx = output.indexOf(signalPrefix);

37+

let normalized;

38+

if (idx !== -1) {

39+

// Log to facilitate debugging if this normalization is occurring.

40+

console.log('Normalizing trailing SIGSEGV in text probe output');

41+

const lineStart = output.lastIndexOf('\n', idx);

42+

normalized = (lineStart === -1 ? '' : output.slice(0, lineStart)) + '\nCompleted';

43+

} else {

44+

normalized = output;

45+

}

46+

assert.strictEqual(normalized, expected);

1247

}

13481449

module.exports = {

15-

escapeRegex,

50+

assertProbeJson,

51+

assertProbeText,

1652

missScript: debuggerFixturePath('probe-miss.js'),

1753

probeScript: debuggerFixturePath('probe.js'),

1854

throwScript: debuggerFixturePath('probe-throw.js'),