File tree Expand file tree Collapse file tree
extensions/usage/providers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ export async function waitForUsage<T>(
8282 promise : Promise < T > ,
8383 signal : AbortSignal ,
8484) : Promise < T > {
85+ signal . throwIfAborted ( ) ;
8586 let onAbort : ( ( ) => void ) | undefined ;
8687 const aborted = new Promise < never > ( ( _resolve , reject ) => {
8788 onAbort = ( ) => reject ( signal . reason ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { DEFAULT_ADAPTERS } from "../../../extensions/usage/providers/registry.t
1111import {
1212 computeUsageStatus ,
1313 parseTimestamp ,
14+ waitForUsage ,
1415} from "../../../extensions/usage/providers/utils.ts" ;
1516
1617function jwt ( payload : Record < string , unknown > ) {
@@ -25,6 +26,17 @@ function payloadFetch(payload: unknown): typeof fetch {
2526 return async ( ) => Response . json ( payload ) ;
2627}
2728
29+ test ( "a pre-cancelled quota wait cannot return an already-fulfilled result" , async ( ) => {
30+ const controller = new AbortController ( ) ;
31+ const reason = new Error ( "cancelled fixture" ) ;
32+ controller . abort ( reason ) ;
33+
34+ await assert . rejects (
35+ waitForUsage ( Promise . resolve ( "stale quota" ) , controller . signal ) ,
36+ ( error : unknown ) => error === reason ,
37+ ) ;
38+ } ) ;
39+
2840test ( "Cursor uses its session cookie, authoritative percentages and independent account metadata" , async ( ) => {
2941 const calls : Array < { url : string ; init ?: RequestInit } > = [ ] ;
3042 const report = await cursorAdapter . fetchUsage (
You can’t perform that action at this time.
0 commit comments