Files
orca/src/shared/posix-wait-status.test.ts
T
Brennan Benson 8e0dad8e21 fix(crash-reporting): decode POSIX wait statuses in crash-report display and record OS session ends (#14659)
* fix(crash-reporting): decode POSIX wait statuses for display and record Windows session-end reasons

Chromium on POSIX hands render/child-process-gone the raw waitpid() status, so
crash reports read "Exit code: 61696" where exit status 241 is meant (field:
61696=exit 241, 9=SIGKILL, 133=SIGTRAP+core, darwin crashed 5=SIGTRAP). Decode
at the display layer only: the stored exitCode stays raw, Windows codes and
launch-failed launch-error codes render unchanged, and the process-gone span
gains a crash.exit_code_decoded attribute.

Also durably record a system_session_end breadcrumb (with WindowSessionEndEvent
reasons) when Windows session-end fires, so bundles can tell OS shutdown from a
user task-kill in killed/exit-1 sweeps.

* test(crash-reporting): pin the exit(0) no-suffix rendering

Adversarial mutation review: removing the exit-0 suppression in
formatCrashReportExitCode survived the suite — nothing pinned that a clean
exit(0) renders without an '(exit status 0)' suffix.

* test(crash-reporting): decode-attribute tests use synchronous child kills

Renderer killed events gain a 250ms sibling-kill settle once the
correlation branch lands, which (a) defers the span past the test's
platform stub so the decode gate reads the real host platform, and (b)
adds a deferred span that breaks the exact sink assertion. The decode
gate is source-agnostic, and a non-recoverable child kill persists
synchronously on every branch of the stack, so coverage is unchanged and
the platform stub is deterministic on any CI host.

* fix(crash-reporting): keep session-end reasons type-safe
2026-08-16 15:45:38 -07:00

68 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { decodePosixWaitStatus, describePosixWaitStatus } from './posix-wait-status'
describe('decodePosixWaitStatus', () => {
it('decodes normal exits from the high byte', () => {
expect(decodePosixWaitStatus(61696)).toEqual({ kind: 'exited', exitStatus: 241 })
expect(decodePosixWaitStatus(512)).toEqual({ kind: 'exited', exitStatus: 2 })
expect(decodePosixWaitStatus(0)).toEqual({ kind: 'exited', exitStatus: 0 })
})
it('decodes signal terminations with the core-dump flag', () => {
expect(decodePosixWaitStatus(9)).toEqual({
kind: 'signaled',
signal: 9,
signalName: 'SIGKILL',
coreDumped: false
})
expect(decodePosixWaitStatus(133)).toEqual({
kind: 'signaled',
signal: 5,
signalName: 'SIGTRAP',
coreDumped: true
})
})
it('leaves platform-divergent signal numbers unnamed', () => {
// 7 = SIGBUS on Linux but SIGEMT on macOS; naming it would mislabel one of them.
expect(decodePosixWaitStatus(7)).toEqual({
kind: 'signaled',
signal: 7,
signalName: null,
coreDumped: false
})
})
it('rejects values that are not dead-process wait statuses', () => {
expect(decodePosixWaitStatus(-536870904)).toBeNull()
expect(decodePosixWaitStatus(0x10000)).toBeNull()
expect(decodePosixWaitStatus(0x7f)).toBeNull()
expect(decodePosixWaitStatus(0.5)).toBeNull()
})
})
describe('describePosixWaitStatus', () => {
it('phrases each decode shape', () => {
expect(describePosixWaitStatus({ kind: 'exited', exitStatus: 241 })).toBe('exit status 241')
expect(
describePosixWaitStatus({
kind: 'signaled',
signal: 9,
signalName: 'SIGKILL',
coreDumped: false
})
).toBe('SIGKILL')
expect(
describePosixWaitStatus({
kind: 'signaled',
signal: 5,
signalName: 'SIGTRAP',
coreDumped: true
})
).toBe('SIGTRAP, core dumped')
expect(
describePosixWaitStatus({ kind: 'signaled', signal: 7, signalName: null, coreDumped: false })
).toBe('signal 7')
})
})