Extract breadcrumb recording into a collection-safe leaf module
Playwright loads spec imports at collection time, and e2e specs import
terminal-module constants (e.g. terminal-attention.spec.ts pulls
POST_REPLAY_MODE_RESET from layout-serialization, whose chain reaches
replay-guard). The breadcrumb import added to the terminal modules made
that chain reach crash-diagnostics.ts, whose top-level import.meta.hot
and webview-registry import crash Playwright's transform
("ReferenceError: exports is not defined in ES module scope") — every
e2e shard failed at collection before running a single test.
Move recordRendererCrashBreadcrumb into crash-breadcrumb-recorder.ts
(type-only imports, no import.meta) and point the terminal modules and
their test mocks at it; crash-diagnostics re-exports for existing
callers. Full e2e suite collects again (262 tests / 94 files); unit
suites, typecheck, lint green. No runtime behavior change.
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -11,7 +11,7 @@ const mocks = vi.hoisted(() => ({
|
||||
recordRendererCrashBreadcrumb: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/crash-diagnostics', () => ({
|
||||
vi.mock('@/lib/crash-breadcrumb-recorder', () => ({
|
||||
recordRendererCrashBreadcrumb: mocks.recordRendererCrashBreadcrumb
|
||||
}))
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ManagedPane } from '@/lib/pane-manager/pane-manager'
|
||||
import { writeForegroundTerminalChunk } from '@/lib/pane-manager/pane-terminal-foreground-render-settle'
|
||||
import { recordRendererCrashBreadcrumb } from '@/lib/crash-diagnostics'
|
||||
import { recordRendererCrashBreadcrumb } from '@/lib/crash-breadcrumb-recorder'
|
||||
|
||||
// Why: xterm.js auto-responds to terminal query sequences (DA1 `CSI c`,
|
||||
// DECRQM `CSI ? Ps $ p`, OSC 10/11 color queries, focus events, CPR) by
|
||||
|
||||
@@ -9,7 +9,7 @@ const mocks = vi.hoisted(() => ({
|
||||
recordRendererCrashBreadcrumb: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/crash-diagnostics', () => ({
|
||||
vi.mock('@/lib/crash-breadcrumb-recorder', () => ({
|
||||
recordRendererCrashBreadcrumb: mocks.recordRendererCrashBreadcrumb
|
||||
}))
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { recordRendererCrashBreadcrumb } from '@/lib/crash-diagnostics'
|
||||
import { recordRendererCrashBreadcrumb } from '@/lib/crash-breadcrumb-recorder'
|
||||
|
||||
// Why: xterm's EscapeSequenceParser invokes custom CSI/OSC handlers
|
||||
// synchronously inside WriteBuffer._innerWrite, which has no try/catch. A
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { CrashReportBreadcrumbData } from '../../../shared/crash-reporting'
|
||||
|
||||
// Why a leaf module: terminal modules (replay-guard, output scheduler, parser
|
||||
// guards) record breadcrumbs, and e2e specs import those modules' constants —
|
||||
// Playwright loads spec imports at collection time under a transform that
|
||||
// cannot handle crash-diagnostics.ts (top-level `import.meta.hot` plus the
|
||||
// webview-registry import chain). Keep this file free of value imports and
|
||||
// import.meta so it stays loadable from any context.
|
||||
|
||||
/** Best-effort breadcrumb recording; must never create or mask failures. */
|
||||
export function recordRendererCrashBreadcrumb(
|
||||
name: string,
|
||||
data?: CrashReportBreadcrumbData
|
||||
): void {
|
||||
if (typeof window === 'undefined') {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const api = (window as Window & { api?: Window['api'] }).api
|
||||
api?.crashReports.recordBreadcrumb({ name, ...(data ? { data } : {}) })
|
||||
} catch {
|
||||
// Best-effort crash evidence only.
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import type {
|
||||
CrashReportDetailValue
|
||||
} from '../../../shared/crash-reporting'
|
||||
import { getBrowserWebviewMemoryProfile } from '../components/browser-pane/webview-registry'
|
||||
import { recordRendererCrashBreadcrumb } from './crash-breadcrumb-recorder'
|
||||
|
||||
const RENDERER_MEMORY_SAMPLE_INTERVAL_MS = 60_000
|
||||
const BYTES_PER_MEGABYTE = 1024 * 1024
|
||||
@@ -16,22 +17,10 @@ type BrowserPerformanceMemory = {
|
||||
let rendererCrashDiagnosticsInstalled = false
|
||||
let rendererMemoryInterval: number | null = null
|
||||
|
||||
export function recordRendererCrashBreadcrumb(
|
||||
name: string,
|
||||
data?: CrashReportBreadcrumbData
|
||||
): void {
|
||||
if (typeof window === 'undefined') {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// Why: crash diagnostics must never create or mask renderer startup failures.
|
||||
const api = (window as Window & { api?: Window['api'] }).api
|
||||
api?.crashReports.recordBreadcrumb({ name, ...(data ? { data } : {}) })
|
||||
} catch {
|
||||
// Best-effort crash evidence only.
|
||||
}
|
||||
}
|
||||
// Why re-exported from a leaf module: terminal modules and their e2e-visible
|
||||
// import chains need breadcrumb recording without this file's import.meta /
|
||||
// webview-registry baggage. See crash-breadcrumb-recorder.ts.
|
||||
export { recordRendererCrashBreadcrumb } from './crash-breadcrumb-recorder'
|
||||
|
||||
export function installRendererCrashDiagnostics(): void {
|
||||
if (rendererCrashDiagnosticsInstalled || typeof window === 'undefined') {
|
||||
|
||||
@@ -9,7 +9,7 @@ const mocks = vi.hoisted(() => ({
|
||||
recordRendererCrashBreadcrumb: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/crash-diagnostics', () => ({
|
||||
vi.mock('@/lib/crash-breadcrumb-recorder', () => ({
|
||||
recordRendererCrashBreadcrumb: mocks.recordRendererCrashBreadcrumb
|
||||
}))
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
enforceTerminalWriteScrollIntent
|
||||
} from './terminal-scroll-intent'
|
||||
import { runGuardedWriteCompletionStep } from './xterm-write-callback-guard'
|
||||
import { recordRendererCrashBreadcrumb } from '@/lib/crash-diagnostics'
|
||||
import { recordRendererCrashBreadcrumb } from '@/lib/crash-breadcrumb-recorder'
|
||||
import {
|
||||
TERMINAL_OUTPUT_BACKLOG_MIN_CAP_CHARS,
|
||||
terminalOutputBacklogCapChars
|
||||
|
||||
@@ -9,7 +9,7 @@ const mocks = vi.hoisted(() => ({
|
||||
recordRendererCrashBreadcrumb: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/crash-diagnostics', () => ({
|
||||
vi.mock('@/lib/crash-breadcrumb-recorder', () => ({
|
||||
recordRendererCrashBreadcrumb: mocks.recordRendererCrashBreadcrumb
|
||||
}))
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { recordRendererCrashBreadcrumb } from '@/lib/crash-diagnostics'
|
||||
import { recordRendererCrashBreadcrumb } from '@/lib/crash-breadcrumb-recorder'
|
||||
|
||||
// Why: xterm's WriteBuffer._innerWrite invokes write-completion callbacks with
|
||||
// no try/catch; a synchronous throw skips the loop's tail re-schedule, and
|
||||
|
||||
Reference in New Issue
Block a user