|
1 | 1 | 'use strict'; |
2 | 2 |
|
| 3 | +const assert = require('assert'); |
3 | 4 | const fixtures = require('./fixtures'); |
4 | 5 | const path = require('path'); |
5 | 6 |
|
6 | 7 | function debuggerFixturePath(name) { |
7 | 8 | return path.relative(process.cwd(), fixtures.path('debugger', name)); |
8 | 9 | } |
9 | 10 |
|
10 | | -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); |
12 | 47 | } |
13 | 48 |
|
14 | 49 | module.exports = { |
15 | | - escapeRegex, |
| 50 | + assertProbeJson, |
| 51 | + assertProbeText, |
16 | 52 | missScript: debuggerFixturePath('probe-miss.js'), |
17 | 53 | probeScript: debuggerFixturePath('probe.js'), |
18 | 54 | throwScript: debuggerFixturePath('probe-throw.js'), |
|
0 commit comments