@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
22import {
33 createExceptionFromTelemetry ,
44 getExceptionTelemetryContext ,
5+ shouldBypassNonProTelemetrySampling ,
56} from "@/lib/posthogTelemetry" ;
67
78describe ( "createExceptionFromTelemetry" , ( ) => {
@@ -26,6 +27,74 @@ describe("createExceptionFromTelemetry", () => {
2627 } ) ;
2728} ) ;
2829
30+ describe ( "shouldBypassNonProTelemetrySampling" , ( ) => {
31+ it ( "always sends sandbox.script.* events for non-Pro sampling" , ( ) => {
32+ expect (
33+ shouldBypassNonProTelemetrySampling ( {
34+ event : "sandbox.script.completed" ,
35+ properties : { chatId : 1 , appId : 2 } ,
36+ } ) ,
37+ ) . toBe ( true ) ;
38+ expect (
39+ shouldBypassNonProTelemetrySampling ( {
40+ event : "sandbox.script.truncated" ,
41+ properties : { chatId : 1 } ,
42+ } ) ,
43+ ) . toBe ( true ) ;
44+ expect (
45+ shouldBypassNonProTelemetrySampling ( {
46+ event : "sandbox.script.failed" ,
47+ properties : { error : "Unexpected token" } ,
48+ } ) ,
49+ ) . toBe ( true ) ;
50+ expect (
51+ shouldBypassNonProTelemetrySampling ( {
52+ event : "sandbox.script.timeout" ,
53+ properties : { error : "Script timed out" } ,
54+ } ) ,
55+ ) . toBe ( true ) ;
56+ } ) ;
57+
58+ it ( "does not bypass unrelated sandbox telemetry" , ( ) => {
59+ expect (
60+ shouldBypassNonProTelemetrySampling ( {
61+ event : "sandbox.tool.unused_with_attachment" ,
62+ properties : { chatId : 1 } ,
63+ } ) ,
64+ ) . toBe ( false ) ;
65+ } ) ;
66+
67+ it ( "still bypasses sampling for error-shaped events" , ( ) => {
68+ expect (
69+ shouldBypassNonProTelemetrySampling ( {
70+ event : "$exception" ,
71+ properties : { exception_message : "boom" } ,
72+ } ) ,
73+ ) . toBe ( true ) ;
74+ expect (
75+ shouldBypassNonProTelemetrySampling ( {
76+ event : "extra-files:error" ,
77+ properties : { } ,
78+ } ) ,
79+ ) . toBe ( true ) ;
80+ expect (
81+ shouldBypassNonProTelemetrySampling ( {
82+ event : "app:crash_detected" ,
83+ properties : { error : true } ,
84+ } ) ,
85+ ) . toBe ( true ) ;
86+ } ) ;
87+
88+ it ( "allows routine events to be sampled" , ( ) => {
89+ expect (
90+ shouldBypassNonProTelemetrySampling ( {
91+ event : "chat:submit" ,
92+ properties : { chatMode : "build" } ,
93+ } ) ,
94+ ) . toBe ( false ) ;
95+ } ) ;
96+ } ) ;
97+
2998describe ( "getExceptionTelemetryContext" , ( ) => {
3099 it ( "removes exception payload fields before passing custom context to PostHog" , ( ) => {
31100 expect (
0 commit comments