diff --git a/src/main/lib/executionTap.test.ts b/src/main/lib/executionTap.test.ts index 174da34b..016582bd 100644 --- a/src/main/lib/executionTap.test.ts +++ b/src/main/lib/executionTap.test.ts @@ -176,6 +176,34 @@ describe('executionTap', () => { expect(events).toContain('comfy.desktop.execution.completed') }) + it('tags every emission with source_layer="comfyui" so engine-origin events are filterable in PostHog', () => { + const tap = createExecutionTap({ installationId: 'inst-1' }) + tap.ingest( + [ + 'got prompt', + 'Prompt executed in 1.0 seconds', + 'Failed to validate prompt for output 7:', + 'Traceback (most recent call last):', + ' File "x.py", line 1, in ', + ' raise RuntimeError("boom")', + 'RuntimeError: boom', + '', + 'next-line' + ].join('\n'), + 'stderr' + ) + tap.flushSummary() + // Cover every event family this tap emits — none should leak without the tag. + const families = new Set(captured.map((c) => c.event)) + expect(families).toContain('comfy.desktop.execution.started') + expect(families).toContain('comfy.desktop.execution.completed') + expect(families).toContain('comfy.desktop.execution.error') + expect(families).toContain('comfy.desktop.execution.session_summary') + for (const c of captured) { + expect(c.ctx['source_layer']).toBe('comfyui') + } + }) + it('redacts Bearer tokens and api keys from traceback messages (secret scrub)', () => { const bearer = 'Bearer ' + 'a'.repeat(30) const apiKey = 's' + 'k-' + 'a'.repeat(24) diff --git a/src/main/lib/executionTap.ts b/src/main/lib/executionTap.ts index 49cce339..795b12bb 100644 --- a/src/main/lib/executionTap.ts +++ b/src/main/lib/executionTap.ts @@ -83,10 +83,15 @@ export function createExecutionTap(opts: { tracebackPhase: 'none' } + // Every event emitted from this tap originates in the ComfyUI Python + // subprocess (parsed from its stdout/stderr). Tagging at the baseContext + // level lets PostHog separate engine-origin errors from any future + // shell-origin emissions without renaming the event family. const baseContext = { installation_id: state.installationId, variant: state.variant, - release: state.release + release: state.release, + source_layer: 'comfyui' as const } function pushPromptStart(): void {