braintrust-logger.test.ts 2.4 KB

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