@@ -18,16 +18,26 @@ import {
1818const US_BASE = 'https://logfire-us.pydantic.dev'
1919const EU_BASE = 'https://logfire-eu.pydantic.dev'
2020
21+ /**
22+ * Synthetic read tokens. Only the `pylf_v{n}_{region}_` prefix is meaningful to
23+ * the code under test, so the suffix is deliberately not token-shaped — these
24+ * are fixtures, never credentials.
25+ */
26+ const US_TOKEN = 'pylf_v1_us_NOT-A-REAL-TOKEN'
27+ const EU_TOKEN = 'pylf_v1_eu_NOT-A-REAL-TOKEN'
28+ const EU_TOKEN_V2 = 'pylf_v2_eu_NOT-A-REAL-TOKEN'
29+ const UNKNOWN_REGION_TOKEN = 'pylf_v1_apac_NOT-A-REAL-TOKEN'
30+
2131describe ( 'getLogfireBaseUrl' , ( ) => {
2232 it ( 'prefers an explicit region over the token prefix' , ( ) => {
23- expect ( getLogfireBaseUrl ( 'pylf_v1_eu_abc' , 'us' ) ) . toBe ( US_BASE )
24- expect ( getLogfireBaseUrl ( 'pylf_v1_us_abc' , 'eu' ) ) . toBe ( EU_BASE )
33+ expect ( getLogfireBaseUrl ( EU_TOKEN , 'us' ) ) . toBe ( US_BASE )
34+ expect ( getLogfireBaseUrl ( US_TOKEN , 'eu' ) ) . toBe ( EU_BASE )
2535 } )
2636
2737 it ( 'reads the region from the token prefix when set to auto' , ( ) => {
28- expect ( getLogfireBaseUrl ( 'pylf_v1_eu_abc' , 'auto' ) ) . toBe ( EU_BASE )
29- expect ( getLogfireBaseUrl ( 'pylf_v1_us_abc' , 'auto' ) ) . toBe ( US_BASE )
30- expect ( getLogfireBaseUrl ( 'pylf_v2_eu_abc' ) ) . toBe ( EU_BASE )
38+ expect ( getLogfireBaseUrl ( EU_TOKEN , 'auto' ) ) . toBe ( EU_BASE )
39+ expect ( getLogfireBaseUrl ( US_TOKEN , 'auto' ) ) . toBe ( US_BASE )
40+ expect ( getLogfireBaseUrl ( EU_TOKEN_V2 ) ) . toBe ( EU_BASE )
3141 } )
3242
3343 it ( 'treats a token with no region prefix as US' , ( ) => {
@@ -36,19 +46,19 @@ describe('getLogfireBaseUrl', () => {
3646 } )
3747
3848 it ( 'refuses to guess a host for a region it does not know' , ( ) => {
39- expect ( ( ) => getLogfireBaseUrl ( 'pylf_v1_apac_abc' ) ) . toThrow (
49+ expect ( ( ) => getLogfireBaseUrl ( UNKNOWN_REGION_TOKEN ) ) . toThrow (
4050 "Unrecognized Logfire token region 'apac'"
4151 )
4252 } )
4353
4454 it ( 'rejects an explicit region outside the known set rather than building undefined/' , ( ) => {
45- expect ( ( ) => getLogfireBaseUrl ( 'pylf_v1_us_abc' , 'apac' as unknown as LogfireRegion ) ) . toThrow (
55+ expect ( ( ) => getLogfireBaseUrl ( US_TOKEN , 'apac' as unknown as LogfireRegion ) ) . toThrow (
4656 "Unrecognized Logfire region 'apac'"
4757 )
4858 } )
4959
5060 it ( 'lets a self-hosted host override both the region and the token prefix' , ( ) => {
51- expect ( getLogfireBaseUrl ( 'pylf_v1_eu_abc' , 'us' , 'https://logfire.example.com' ) ) . toBe (
61+ expect ( getLogfireBaseUrl ( EU_TOKEN , 'us' , 'https://logfire.example.com' ) ) . toBe (
5262 'https://logfire.example.com'
5363 )
5464 } )
@@ -78,8 +88,8 @@ describe('getLogfireBaseUrl', () => {
7888 } )
7989
8090 it ( 'ignores a blank host and falls back to region resolution' , ( ) => {
81- expect ( getLogfireBaseUrl ( 'pylf_v1_eu_abc' , 'auto' , ' ' ) ) . toBe ( EU_BASE )
82- expect ( getLogfireBaseUrl ( 'pylf_v1_eu_abc' , 'auto' , undefined ) ) . toBe ( EU_BASE )
91+ expect ( getLogfireBaseUrl ( EU_TOKEN , 'auto' , ' ' ) ) . toBe ( EU_BASE )
92+ expect ( getLogfireBaseUrl ( EU_TOKEN , 'auto' , undefined ) ) . toBe ( EU_BASE )
8393 } )
8494
8595 it ( 'rejects a host carrying a query string or fragment that would swallow the path' , ( ) => {
@@ -100,7 +110,7 @@ describe('getLogfireBaseUrl', () => {
100110
101111describe ( 'logfireHeaders' , ( ) => {
102112 it ( 'trims the token so a pasted value does not corrupt the bearer credential' , ( ) => {
103- expect ( logfireHeaders ( ' pylf_v1_us_abc\n' ) . Authorization ) . toBe ( ' Bearer pylf_v1_us_abc' )
113+ expect ( logfireHeaders ( ` ${ US_TOKEN } \n` ) . Authorization ) . toBe ( ` Bearer ${ US_TOKEN } ` )
104114 } )
105115} )
106116
0 commit comments