braintrust-logger.test.ts72 lines · main
1import { describe, expect, it } from 'vitest'
2
3import { isTracingAllowed } from './braintrust-logger'
4
5const baseAllowed = {
6 orgHasHipaaAddon: false,
7 projectIsSensitive: false,
8 projectRegion: 'us-east-1',
9}
10
11describe('isTracingAllowed', () => {
12 it('allows tracing when all flags are explicitly off/non-EU', () => {
13 expect(isTracingAllowed(baseAllowed)).toBe(true)
14 })
15
16 it('disallows tracing when HIPAA addon is active and project is sensitive', () => {
17 expect(
18 isTracingAllowed({ ...baseAllowed, orgHasHipaaAddon: true, projectIsSensitive: true })
19 ).toBe(false)
20 })
21
22 it('allows tracing when HIPAA addon is active but project is not sensitive', () => {
23 expect(
24 isTracingAllowed({ ...baseAllowed, orgHasHipaaAddon: true, projectIsSensitive: false })
25 ).toBe(true)
26 })
27
28 it('allows tracing when project is sensitive but no HIPAA addon', () => {
29 expect(
30 isTracingAllowed({ ...baseAllowed, orgHasHipaaAddon: false, projectIsSensitive: true })
31 ).toBe(true)
32 })
33
34 it('disallows tracing for EU regions', () => {
35 expect(isTracingAllowed({ ...baseAllowed, projectRegion: 'eu-west-1' })).toBe(false)
36 expect(isTracingAllowed({ ...baseAllowed, projectRegion: 'eu-central-1' })).toBe(false)
37 })
38
39 it('allows tracing for non-EU regions', () => {
40 expect(isTracingAllowed({ ...baseAllowed, projectRegion: 'ap-southeast-1' })).toBe(true)
41 })
42
43 it('allows tracing when HIPAA addon is false and is_sensitive is null (DB default)', () => {
44 expect(isTracingAllowed({ ...baseAllowed, projectIsSensitive: null })).toBe(true)
45 })
46
47 it('disallows tracing when HIPAA addon is unknown and is_sensitive is null', () => {
48 expect(
49 isTracingAllowed({ ...baseAllowed, orgHasHipaaAddon: undefined, projectIsSensitive: null })
50 ).toBe(false)
51 })
52
53 it('disallows tracing when flags are undefined (unknown = restricted)', () => {
54 expect(
55 isTracingAllowed({
56 orgHasHipaaAddon: undefined,
57 projectIsSensitive: undefined,
58 projectRegion: undefined,
59 })
60 ).toBe(false)
61 expect(isTracingAllowed({ ...baseAllowed, projectRegion: undefined })).toBe(false)
62 expect(isTracingAllowed({ ...baseAllowed, orgHasHipaaAddon: undefined })).toBe(false)
63 // projectIsSensitive unknown only matters when orgHasHipaaAddon is also unknown
64 expect(
65 isTracingAllowed({
66 ...baseAllowed,
67 orgHasHipaaAddon: undefined,
68 projectIsSensitive: undefined,
69 })
70 ).toBe(false)
71 })
72})