@@ -8,11 +8,11 @@ import { authenticateForDeploy, userIdForDeploy } from "./auth.js";
88import { readAuthConfigProfile } from "../utilities/configFiles.js" ;
99
1010describe ( "authenticateForDeploy" , ( ) => {
11- it ( "gives TRIGGER_SECRET_KEY precedence without logging in" , async ( ) => {
11+ it ( "uses an API key from TRIGGER_ACCESS_TOKEN without logging in" , async ( ) => {
1212 let loginCalled = false ;
1313
1414 const result = await authenticateForDeploy ( {
15- secretKey : "tr_prod_sk_deploy" ,
15+ accessToken : "tr_prod_sk_deploy" ,
1616 apiUrl : "https://example.trigger.dev" ,
1717 profile : "default" ,
1818 silent : true ,
@@ -37,7 +37,7 @@ describe("authenticateForDeploy", () => {
3737
3838 it ( "derives hosted dashboard links without user metadata" , async ( ) => {
3939 const result = await authenticateForDeploy ( {
40- secretKey : "tr_preview_sk_deploy" ,
40+ accessToken : "tr_preview_sk_deploy" ,
4141 apiUrl : "https://api.example.trigger.dev" ,
4242 profile : "default" ,
4343 silent : true ,
@@ -52,7 +52,7 @@ describe("authenticateForDeploy", () => {
5252
5353 it ( "uses the normal cloud URLs when no API URL is set" , async ( ) => {
5454 const result = await authenticateForDeploy ( {
55- secretKey : "tr_prod_sk_deploy" ,
55+ accessToken : "tr_prod_sk_deploy" ,
5656 profile : "default" ,
5757 silent : true ,
5858 login : async ( ) => ( { ok : false , error : "should not be called" } ) ,
@@ -70,7 +70,7 @@ describe("authenticateForDeploy", () => {
7070 } ) ;
7171
7272 const result = await authenticateForDeploy ( {
73- secretKey : "tr_prod_sk_deploy" ,
73+ accessToken : "tr_prod_sk_deploy" ,
7474 profile : "selfhosted" ,
7575 silent : true ,
7676 login : async ( ) => ( { ok : false , error : "should not be called" } ) ,
@@ -88,7 +88,7 @@ describe("authenticateForDeploy", () => {
8888 } ) ;
8989
9090 const result = await authenticateForDeploy ( {
91- secretKey : "tr_prod_sk_deploy" ,
91+ accessToken : "tr_prod_sk_deploy" ,
9292 apiUrl : "https://api.trigger.dev" ,
9393 profile : "selfhosted" ,
9494 silent : true ,
@@ -100,9 +100,10 @@ describe("authenticateForDeploy", () => {
100100 } ) ;
101101 } ) ;
102102
103- it ( "keeps login authentication when no secret key is set " , async ( ) => {
103+ it ( "passes a PAT through to the login path " , async ( ) => {
104104 let loginOptions : unknown ;
105105 const result = await authenticateForDeploy ( {
106+ accessToken : "tr_pat_abc123" ,
106107 apiUrl : "https://example.trigger.dev" ,
107108 profile : "ci" ,
108109 silent : false ,
@@ -121,52 +122,53 @@ describe("authenticateForDeploy", () => {
121122 expect ( result ) . toEqual ( { ok : false , error : "login result" } ) ;
122123 } ) ;
123124
124- it ( "rejects a PAT in TRIGGER_SECRET_KEY with a helpful error" , async ( ) => {
125- const result = await authenticateForDeploy ( {
126- secretKey : "tr_pat_abc123" ,
127- profile : "default" ,
128- silent : true ,
129- login : async ( ) => ( { ok : false , error : "should not be called" } ) ,
130- } ) ;
131-
132- expect ( result ) . toEqual ( {
133- ok : false ,
134- error : expect . stringContaining ( "TRIGGER_ACCESS_TOKEN" ) ,
135- } ) ;
136- } ) ;
137-
138- it ( "rejects an OAT in TRIGGER_SECRET_KEY with a helpful error" , async ( ) => {
125+ it ( "passes an OAT through to the login path" , async ( ) => {
126+ let loginOptions : unknown ;
139127 const result = await authenticateForDeploy ( {
140- secretKey : "tr_oat_abc123" ,
141- profile : "default" ,
142- silent : true ,
143- login : async ( ) => ( { ok : false , error : "should not be called" } ) ,
128+ accessToken : "tr_oat_abc123" ,
129+ apiUrl : "https://example.trigger.dev" ,
130+ profile : "ci" ,
131+ silent : false ,
132+ login : async ( options ) => {
133+ loginOptions = options ;
134+ return { ok : false , error : "login result" } ;
135+ } ,
144136 } ) ;
145137
146- expect ( result ) . toEqual ( {
147- ok : false ,
148- error : expect . stringContaining ( "TRIGGER_ACCESS_TOKEN" ) ,
138+ expect ( loginOptions ) . toEqual ( {
139+ embedded : true ,
140+ defaultApiUrl : "https://example.trigger.dev" ,
141+ profile : "ci" ,
142+ silent : false ,
149143 } ) ;
144+ expect ( result ) . toEqual ( { ok : false , error : "login result" } ) ;
150145 } ) ;
151146
152- it ( "rejects a secret key that doesn't look like an API key" , async ( ) => {
147+ it ( "keeps login authentication when no access token is set" , async ( ) => {
148+ let loginOptions : unknown ;
153149 const result = await authenticateForDeploy ( {
154- secretKey : "not-a-valid-key" ,
155- profile : "default" ,
156- silent : true ,
157- login : async ( ) => ( { ok : false , error : "should not be called" } ) ,
150+ apiUrl : "https://example.trigger.dev" ,
151+ profile : "ci" ,
152+ silent : false ,
153+ login : async ( options ) => {
154+ loginOptions = options ;
155+ return { ok : false , error : "login result" } ;
156+ } ,
158157 } ) ;
159158
160- expect ( result ) . toEqual ( {
161- ok : false ,
162- error : expect . stringContaining ( "does not look like a Trigger.dev API key" ) ,
159+ expect ( loginOptions ) . toEqual ( {
160+ embedded : true ,
161+ defaultApiUrl : "https://example.trigger.dev" ,
162+ profile : "ci" ,
163+ silent : false ,
163164 } ) ;
165+ expect ( result ) . toEqual ( { ok : false , error : "login result" } ) ;
164166 } ) ;
165167
166168 it ( "throws a descriptive error for an invalid API URL" , async ( ) => {
167169 await expect (
168170 authenticateForDeploy ( {
169- secretKey : "tr_prod_sk_deploy" ,
171+ accessToken : "tr_prod_sk_deploy" ,
170172 apiUrl : "not-a-url" ,
171173 profile : "default" ,
172174 silent : true ,
0 commit comments