11import {
22 EnvironmentId ,
3+ ProviderDriverKind ,
4+ ProviderInstanceId ,
35 UsageDay ,
46 USAGE_CONTRACT_VERSION ,
7+ type ServerProvider ,
58 type UsageSummary ,
69} from "@t3tools/contracts" ;
710import * as Effect from "effect/Effect" ;
@@ -10,7 +13,7 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
1013
1114import type { EnvironmentPresentation } from "../connection/presentation.ts" ;
1215import { EnvironmentRpcUnavailableError } from "../rpc/client.ts" ;
13- import { refreshUsage , refreshUsageLimits } from "./usage.ts" ;
16+ import { needsCursorKeychainAccess , refreshUsage , refreshUsageLimits } from "./usage.ts" ;
1417
1518const input = {
1619 sinceDay : UsageDay . make ( "2026-09-05" ) ,
@@ -238,3 +241,48 @@ describe("limits refresh cooldown", () => {
238241 }
239242 } ) ;
240243} ) ;
244+
245+ describe ( "needsCursorKeychainAccess" , ( ) => {
246+ const cursorPrompt : UsageSummary = {
247+ ...summary ,
248+ sources : [
249+ {
250+ fingerprint : {
251+ hostId : "host" ,
252+ provider : "cursor" ,
253+ resolvedHomePath : "/Users/me/.cursor/auth.json" ,
254+ volumeId : "volume" ,
255+ } ,
256+ status : "ok" ,
257+ scannedFiles : 0 ,
258+ skippedFiles : 0 ,
259+ malformedRecords : 0 ,
260+ distinctSessions : 0 ,
261+ message : "Cursor account usage is off on this environment." ,
262+ action : "enableCursorKeychain" ,
263+ } ,
264+ ] ,
265+ } ;
266+ const cursor = ( status : ServerProvider [ "status" ] ) : ServerProvider => ( {
267+ instanceId : ProviderInstanceId . make ( "cursor" ) ,
268+ driver : ProviderDriverKind . make ( "cursor" ) ,
269+ enabled : status !== "disabled" ,
270+ installed : status === "ready" ,
271+ version : null ,
272+ status,
273+ auth : { status : "unknown" } ,
274+ checkedAt : "2026-09-05T12:00:00.000Z" ,
275+ models : [ ] ,
276+ slashCommands : [ ] ,
277+ skills : [ ] ,
278+ } ) ;
279+
280+ it ( "offers access only when Cursor is ready on that environment" , ( ) => {
281+ expect ( needsCursorKeychainAccess ( cursorPrompt , [ cursor ( "ready" ) ] ) ) . toBe ( true ) ;
282+ expect ( needsCursorKeychainAccess ( cursorPrompt , [ cursor ( "error" ) ] ) ) . toBe ( false ) ;
283+ expect ( needsCursorKeychainAccess ( cursorPrompt , [ cursor ( "disabled" ) ] ) ) . toBe ( false ) ;
284+ expect ( needsCursorKeychainAccess ( cursorPrompt , [ ] ) ) . toBe ( false ) ;
285+ expect ( needsCursorKeychainAccess ( cursorPrompt , null ) ) . toBe ( false ) ;
286+ expect ( needsCursorKeychainAccess ( summary , [ cursor ( "ready" ) ] ) ) . toBe ( false ) ;
287+ } ) ;
288+ } ) ;
0 commit comments