@@ -12,7 +12,6 @@ import {
1212} from '@lib/gateway-session' ;
1313import type { HostResolution } from '@lib/host-resolution' ;
1414import { ErrorCodes } from '@lib/errors' ;
15- import { setLegacyGatewayFallback } from '@lib/legacy-gateway' ;
1615import { WizardError } from '@utils/wizard-abort' ;
1716import { analytics } from '@utils/analytics' ;
1817import { logToFile } from '@utils/debug' ;
@@ -46,10 +45,7 @@ const renderArg = (a: unknown): string => {
4645const loggedLines = ( ) =>
4746 vi . mocked ( logToFile ) . mock . calls . map ( ( call ) => call . map ( renderArg ) . join ( ' ' ) ) ;
4847
49- const host = {
50- region : 'us' ,
51- apiHost : 'https://us.posthog.com' ,
52- } as unknown as HostResolution ;
48+ const host = { apiHost : 'https://us.posthog.com' } as unknown as HostResolution ;
5349
5450describe ( 'gatewayAuth' , ( ) => {
5551 const fetchMock = vi . fn ( ) ;
@@ -574,91 +570,6 @@ describe('gatewayAuth', () => {
574570 ) . rejects . toBeInstanceOf ( GatewayMintRefused ) ;
575571 } ) ;
576572
577- describe ( 'CI legacy fallback' , ( ) => {
578- const refused = ( status : number ) => ( {
579- ok : false ,
580- status,
581- json : ( ) => Promise . resolve ( { } ) ,
582- } ) ;
583-
584- beforeEach ( ( ) => setLegacyGatewayFallback ( true ) ) ;
585- afterEach ( ( ) => setLegacyGatewayFallback ( false ) ) ;
586-
587- it ( 'stays on the legacy gateway when the mint does not take the credential' , async ( ) => {
588- // A personal API key 401s at the mint; the legacy gateway authenticates it itself.
589- fetchMock . mockResolvedValue ( refused ( 401 ) ) ;
590- const auth = await gatewayAuth ( host , 'phx_personal' , 'integration' ) ;
591- expect ( auth ) . toMatchObject ( {
592- gatewayUrl : 'https://gateway.us.posthog.com/wizard' ,
593- token : 'phx_personal' ,
594- legacy : true ,
595- } ) ;
596- expect ( isPastRefresh ( auth ) ) . toBe ( false ) ;
597- } ) ;
598-
599- it ( 'picks the legacy gateway for the region, or the local one for a dev host' , async ( ) => {
600- fetchMock . mockResolvedValue ( refused ( 401 ) ) ;
601- const urlFor = async ( region : string , apiHost : string ) => {
602- resetGatewaySession ( ) ;
603- const h = { region, apiHost } as unknown as HostResolution ;
604- return ( await gatewayAuth ( h , 'phx_personal' , 'integration' ) ) . gatewayUrl ;
605- } ;
606- expect ( await urlFor ( 'eu' , 'https://eu.i.posthog.com' ) ) . toBe (
607- 'https://gateway.eu.posthog.com/wizard' ,
608- ) ;
609- expect ( await urlFor ( 'us' , 'http://localhost:8010' ) ) . toBe (
610- 'http://localhost:3308/wizard' ,
611- ) ;
612- expect ( await urlFor ( 'us' , 'http://host.docker.internal:8010' ) ) . toBe (
613- 'http://host.docker.internal:3308/wizard' ,
614- ) ;
615- } ) ;
616-
617- it ( 'stays on the legacy gateway when the instance has no mint' , async ( ) => {
618- fetchMock . mockResolvedValue ( refused ( 404 ) ) ;
619- const auth = await gatewayAuth ( host , 'phx_personal' , 'integration' ) ;
620- expect ( auth . legacy ) . toBe ( true ) ;
621- } ) ;
622-
623- it ( 'caches the fallback instead of re-asking the mint per caller' , async ( ) => {
624- fetchMock . mockResolvedValue ( refused ( 401 ) ) ;
625- await gatewayAuth ( host , 'phx_personal' , 'integration' ) ;
626- await gatewayAuth ( host , 'phx_personal' , 'integration' ) ;
627- expect ( fetchMock ) . toHaveBeenCalledTimes ( 1 ) ;
628- } ) ;
629-
630- it ( 'still fails a policy refusal' , async ( ) => {
631- // 403/429/400 are decisions about the run, which the legacy gateway would not enforce.
632- fetchMock . mockResolvedValue ( refused ( 403 ) ) ;
633- await expect (
634- gatewayAuth ( host , 'phx_personal' , 'integration' ) ,
635- ) . rejects . toBeInstanceOf ( GatewayMintRefused ) ;
636- } ) ;
637-
638- it ( 'still mints when the mint accepts the credential' , async ( ) => {
639- fetchMock . mockResolvedValue ( {
640- ok : true ,
641- json : ( ) =>
642- Promise . resolve ( {
643- token : 'phe_minted' ,
644- expires_at : new Date ( Date . now ( ) + 3600_000 ) . toISOString ( ) ,
645- gateway_url : 'https://gateway.us.posthog.com' ,
646- } ) ,
647- } ) ;
648- const auth = await gatewayAuth ( host , 'pha_app' , 'integration' ) ;
649- expect ( auth . token ) . toBe ( 'phe_minted' ) ;
650- expect ( auth . legacy ) . toBeUndefined ( ) ;
651- } ) ;
652-
653- it ( 'does not fall back outside CI' , async ( ) => {
654- setLegacyGatewayFallback ( false ) ;
655- fetchMock . mockResolvedValue ( refused ( 401 ) ) ;
656- await expect (
657- gatewayAuth ( host , 'phx_personal' , 'integration' ) ,
658- ) . rejects . toBeInstanceOf ( GatewayMintRefused ) ;
659- } ) ;
660- } ) ;
661-
662573 it ( "names the run's program in the mint request" , async ( ) => {
663574 fetchMock . mockResolvedValue ( {
664575 ok : true ,
0 commit comments