@@ -3,13 +3,16 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
33import { assert , describe , it } from "@effect/vitest" ;
44import { KiroSettings } from "@t3tools/provider-kiro/settings" ;
55import * as Deferred from "effect/Deferred" ;
6+ import type * as Duration from "effect/Duration" ;
67import * as Effect from "effect/Effect" ;
8+ import * as Fiber from "effect/Fiber" ;
79import * as Layer from "effect/Layer" ;
810import * as Queue from "effect/Queue" ;
911import * as Schema from "effect/Schema" ;
1012import * as Sink from "effect/Sink" ;
1113import * as Stream from "effect/Stream" ;
1214import { ChildProcess , ChildProcessSpawner } from "effect/process" ;
15+ import * as TestClock from "effect/testing/TestClock" ;
1316
1417import {
1518 checkKiroProviderStatus ,
@@ -23,18 +26,25 @@ const settings = Schema.decodeSync(KiroSettings)({ enabled: true });
2326interface CliOutput {
2427 readonly stdout : string ;
2528 readonly code : number ;
29+ /** Holds stdout and the exit back this long, like a CLI slow to answer. */
30+ readonly delay ?: Duration . Input ;
2631}
2732
2833function processHandle ( output : CliOutput ) {
34+ const answered = Effect . sleep ( output . delay ?? 0 ) ;
2935 return ChildProcessSpawner . makeHandle ( {
3036 pid : ChildProcessSpawner . ProcessId ( 900_000_002 ) ,
31- exitCode : Effect . succeed ( ChildProcessSpawner . ExitCode ( output . code ) ) ,
37+ exitCode : Effect . as ( answered , ChildProcessSpawner . ExitCode ( output . code ) ) ,
3238 isRunning : Effect . succeed ( false ) ,
3339 kill : ( ) => Effect . void ,
3440 unref : Effect . succeed ( Effect . void ) ,
3541 stdin : Sink . drain ,
36- stdout :
37- output . stdout . length === 0 ? Stream . empty : Stream . succeed ( encoder . encode ( output . stdout ) ) ,
42+ stdout : Stream . unwrap (
43+ Effect . as (
44+ answered ,
45+ output . stdout . length === 0 ? Stream . empty : Stream . succeed ( encoder . encode ( output . stdout ) ) ,
46+ ) ,
47+ ) ,
3848 stderr : Stream . empty ,
3949 all : Stream . empty ,
4050 getInputFd : ( ) => Sink . drain ,
@@ -123,6 +133,35 @@ const check = (
123133 } ) . pipe ( Effect . provide ( Layer . mergeAll ( NodeServices . layer , NodeCrypto . layer ) ) ) ;
124134
125135describe ( "KiroProvider" , ( ) => {
136+ it . effect . each ( [
137+ {
138+ label : "answers after 6 s" ,
139+ delay : "6 seconds" ,
140+ status : "ready" ,
141+ version : "2.27.0" ,
142+ message : undefined ,
143+ } ,
144+ {
145+ label : "never answers" ,
146+ delay : "Infinity" ,
147+ status : "error" ,
148+ version : null ,
149+ message : "Failed to run `kiro-cli --version`." ,
150+ } ,
151+ ] as const ) ( "gives `kiro-cli --version` 10 s when it $label" , ( row ) =>
152+ Effect . gen ( function * ( ) {
153+ const fiber = yield * check ( {
154+ "--version" : { stdout : "kiro-cli 2.27.0\n" , code : 0 , delay : row . delay } ,
155+ "whoami --format json" : { stdout : '{"accountType":"ApiKey","email":null}\n' , code : 0 } ,
156+ } ) . pipe ( Effect . forkChild ) ;
157+ yield * TestClock . adjust ( "10 seconds" ) ;
158+ const { snapshot } = yield * Fiber . join ( fiber ) ;
159+ assert . equal ( snapshot . status , row . status ) ;
160+ assert . equal ( snapshot . version , row . version ) ;
161+ assert . equal ( snapshot . message , row . message ) ;
162+ } ) ,
163+ ) ;
164+
126165 it . effect ( "reports a CLI whose version probe exits nonzero as failing to run" , ( ) =>
127166 Effect . gen ( function * ( ) {
128167 const { snapshot, invoked } = yield * check ( {
0 commit comments