@@ -77,6 +77,30 @@ async function createOrg(cap: string[]): Promise<{ status: number; body: any }>
7777 return { status : response . status , body : await response . json ( ) } ;
7878}
7979
80+ // An ordinary PAT, paired with an ability that denies everything. Nothing on this route may
81+ // consult it — the route has no org to scope a gate to, and on cloud the plugin returns a
82+ // deny-shaped ability when there is no org context.
83+ async function createOrgWithPat ( ) : Promise < { status : number ; body : any } > {
84+ mocks . authenticatePat . mockImplementation ( async ( ) => ( {
85+ ok : true ,
86+ userId : USER_ID ,
87+ tokenId : "pat_1" ,
88+ lastAccessedAt : new Date ( ) ,
89+ ability : { can : ( ) => false , canSuper : ( ) => false } ,
90+ } ) ) ;
91+
92+ const response = await action ( {
93+ request : new Request ( "https://api.trigger.dev/api/v1/orgs" , {
94+ method : "POST" ,
95+ headers : { Authorization : "Bearer tr_pat_1234" , "Content-Type" : "application/json" } ,
96+ body : JSON . stringify ( { title : "New Org" } ) ,
97+ } ) ,
98+ params : { } ,
99+ context : { } ,
100+ } as any ) ;
101+ return { status : response . status , body : await response . json ( ) } ;
102+ }
103+
80104const AGENT_ENVIRONMENT_ID = "env_dev" ;
81105
82106async function listProjects ( ) : Promise < { status : number ; body : any } > {
@@ -146,6 +170,13 @@ describe("creating an organization over the API", () => {
146170 expect ( mocks . createOrganization ) . not . toHaveBeenCalled ( ) ;
147171 } ) ;
148172
173+ it ( "admits an ordinary PAT without consulting its ability" , async ( ) => {
174+ const result = await createOrgWithPat ( ) ;
175+
176+ expect ( result . status ) . toBe ( 201 ) ;
177+ expect ( result . body . slug ) . toBe ( "new-org" ) ;
178+ } ) ;
179+
149180 it ( "still admits a token that carries the universal grant" , async ( ) => {
150181 const result = await createOrg ( [ "admin" ] ) ;
151182
0 commit comments