|
| 1 | +import { expect, test } from "@effect/vitest"; |
| 2 | + |
| 3 | +import { crashReportFingerprint, type CrashEvent } from "./crash-fingerprint"; |
| 4 | + |
| 5 | +// Chromium's soft-assert path (`NOTREACHED()`/`DCHECK`) dumps and keeps |
| 6 | +// running. Sentry titles each one with the faulting load address, so one |
| 7 | +// condition arrives as a new issue every time the address moves. |
| 8 | +const softAssertEvent = (address: string): CrashEvent => ({ |
| 9 | + exception: { |
| 10 | + values: [ |
| 11 | + { |
| 12 | + type: "Fatal Error", |
| 13 | + value: `Simulated Exception / ${address}`, |
| 14 | + mechanism: { type: "minidump" }, |
| 15 | + stacktrace: { |
| 16 | + frames: [ |
| 17 | + { function: "logging::NotReachedLogMessage::~NotReachedLogMessage" }, |
| 18 | + { function: "logging::HandleCheckErrorLogMessage" }, |
| 19 | + { function: "base::debug::DumpWithoutCrashing" }, |
| 20 | + { function: "crash_reporter::DumpWithoutCrashing" }, |
| 21 | + ], |
| 22 | + }, |
| 23 | + }, |
| 24 | + ], |
| 25 | + }, |
| 26 | +}); |
| 27 | + |
| 28 | +test("address-keyed Chromium soft asserts collapse to one fingerprint", () => { |
| 29 | + const first = crashReportFingerprint(softAssertEvent("0x00000001a2b3c4d5")); |
| 30 | + const second = crashReportFingerprint(softAssertEvent("0x00000007e8f9a0b1")); |
| 31 | + |
| 32 | + expect(first).toEqual(["chromium-dump-without-crashing"]); |
| 33 | + expect(first).toEqual(second); |
| 34 | +}); |
| 35 | + |
| 36 | +test("a real native abort keeps Sentry's own grouping", () => { |
| 37 | + const abortEvent: CrashEvent = { |
| 38 | + exception: { |
| 39 | + values: [ |
| 40 | + { |
| 41 | + type: "EXC_CRASH", |
| 42 | + value: "SIGABRT", |
| 43 | + mechanism: { type: "minidump" }, |
| 44 | + stacktrace: { |
| 45 | + frames: [ |
| 46 | + { function: "abort" }, |
| 47 | + { function: "pthread_kill" }, |
| 48 | + { function: "__pthread_kill" }, |
| 49 | + ], |
| 50 | + }, |
| 51 | + }, |
| 52 | + ], |
| 53 | + }, |
| 54 | + }; |
| 55 | + |
| 56 | + expect(crashReportFingerprint(abortEvent)).toBeUndefined(); |
| 57 | +}); |
| 58 | + |
| 59 | +test("renderer chunk hashes are normalized out of the fingerprint", () => { |
| 60 | + const rendererEvent = (chunkHash: string): CrashEvent => ({ |
| 61 | + culprit: `loadConnections(assets/atoms-${chunkHash})`, |
| 62 | + exception: { |
| 63 | + values: [ |
| 64 | + { |
| 65 | + type: "TypeError", |
| 66 | + value: "cannot read properties of undefined", |
| 67 | + stacktrace: { |
| 68 | + frames: [ |
| 69 | + { |
| 70 | + filename: `http://127.0.0.1:4789/assets/atoms-${chunkHash}.js`, |
| 71 | + module: `atoms-${chunkHash}`, |
| 72 | + function: "loadConnections", |
| 73 | + in_app: true, |
| 74 | + }, |
| 75 | + ], |
| 76 | + }, |
| 77 | + }, |
| 78 | + ], |
| 79 | + }, |
| 80 | + }); |
| 81 | + |
| 82 | + const release1 = crashReportFingerprint(rendererEvent("Yemn7yhP")); |
| 83 | + const release2 = crashReportFingerprint(rendererEvent("CeCENfWa")); |
| 84 | + |
| 85 | + expect(release1).toEqual(["TypeError", "loadConnections@atoms"]); |
| 86 | + expect(release1).toEqual(release2); |
| 87 | +}); |
| 88 | + |
| 89 | +test("events with no volatile grouping input are left alone", () => { |
| 90 | + expect(crashReportFingerprint({})).toBeUndefined(); |
| 91 | + expect( |
| 92 | + crashReportFingerprint({ |
| 93 | + exception: { |
| 94 | + values: [ |
| 95 | + { |
| 96 | + type: "Error", |
| 97 | + stacktrace: { |
| 98 | + frames: [{ filename: "/src/main/sidecar.ts", function: "startSidecar" }], |
| 99 | + }, |
| 100 | + }, |
| 101 | + ], |
| 102 | + }, |
| 103 | + }), |
| 104 | + ).toBeUndefined(); |
| 105 | +}); |
0 commit comments