|
| 1 | +import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; |
| 2 | +import * as NodeServices from "@effect/platform-node/NodeServices"; |
1 | 3 | import { assert, describe, it } from "@effect/vitest"; |
| 4 | +import { ProviderInstanceId } from "@t3tools/contracts"; |
| 5 | +import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; |
| 6 | +import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions"; |
| 7 | +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; |
| 8 | +import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost"; |
| 9 | +import * as HostProcess from "@t3tools/shared/HostProcess"; |
| 10 | +import * as Effect from "effect/Effect"; |
| 11 | +import * as Layer from "effect/Layer"; |
| 12 | +import * as Path from "effect/Path"; |
2 | 13 | import * as Schema from "effect/Schema"; |
| 14 | +import * as Sink from "effect/Sink"; |
| 15 | +import * as Stream from "effect/Stream"; |
| 16 | +import * as ChildProcess from "effect/process/ChildProcess"; |
| 17 | +import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; |
3 | 18 |
|
4 | 19 | import { KiroSettings } from "../settings.ts"; |
5 | 20 | import { buildKiroAcpSpawnInput } from "./acpSupport.ts"; |
| 21 | +import { KiroDriver } from "./driver.ts"; |
6 | 22 | import { kiroAuthFromWhoami } from "./status.ts"; |
7 | 23 |
|
8 | 24 | const decodeSettings = Schema.decodeUnknownSync(KiroSettings); |
@@ -64,3 +80,65 @@ describe("KiroDriver", () => { |
64 | 80 | }); |
65 | 81 | }); |
66 | 82 | }); |
| 83 | + |
| 84 | +const layerTest = TestProviderHost.layer({ runBackgroundWork: false }).pipe( |
| 85 | + Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)), |
| 86 | + Layer.provideMerge(IdAllocator.layer), |
| 87 | + Layer.provideMerge(McpProviderSessions.layer), |
| 88 | + Layer.provideMerge( |
| 89 | + Layer.succeed( |
| 90 | + ProviderEventLoggers.ProviderEventLoggers, |
| 91 | + ProviderEventLoggers.NoOpProviderEventLoggers, |
| 92 | + ), |
| 93 | + ), |
| 94 | +); |
| 95 | + |
| 96 | +/** Records each spawned command and answers only `--version`. */ |
| 97 | +function recordingSpawner(launches: Array<string>) { |
| 98 | + return ChildProcessSpawner.make((command) => { |
| 99 | + const standard = ChildProcess.isStandardCommand(command); |
| 100 | + if (standard) launches.push(command.command); |
| 101 | + const version = standard && command.args.join(" ") === "--version"; |
| 102 | + return Effect.succeed( |
| 103 | + ChildProcessSpawner.makeHandle({ |
| 104 | + pid: ChildProcessSpawner.ProcessId(1), |
| 105 | + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(version ? 0 : 2)), |
| 106 | + isRunning: Effect.succeed(false), |
| 107 | + kill: () => Effect.void, |
| 108 | + unref: Effect.succeed(Effect.void), |
| 109 | + stdin: Sink.drain, |
| 110 | + stdout: version ? Stream.encodeText(Stream.make("2.32.0\n")) : Stream.empty, |
| 111 | + stderr: Stream.empty, |
| 112 | + all: Stream.empty, |
| 113 | + getInputFd: () => Sink.drain, |
| 114 | + getOutputFd: () => Stream.empty, |
| 115 | + }), |
| 116 | + ); |
| 117 | + }); |
| 118 | +} |
| 119 | + |
| 120 | +it.layer(layerTest)("KiroDriver binary path", (it) => { |
| 121 | + it.effect("probes a ~/ binary path from the home directory", () => |
| 122 | + Effect.gen(function* () { |
| 123 | + const path = yield* Path.Path; |
| 124 | + const launches: Array<string> = []; |
| 125 | + const instance = yield* KiroDriver.create({ |
| 126 | + instanceId: ProviderInstanceId.make("kiro-home"), |
| 127 | + displayName: undefined, |
| 128 | + enabled: true, |
| 129 | + environment: [], |
| 130 | + config: decodeSettings({ binaryPath: "~/.local/bin/kiro-cli" }), |
| 131 | + }).pipe( |
| 132 | + Effect.provideService(HostProcess.HomeDirectory, "/test-home"), |
| 133 | + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, recordingSpawner(launches)), |
| 134 | + ); |
| 135 | + const snapshot = yield* instance.snapshot.refresh; |
| 136 | + assert.isNotEmpty(launches); |
| 137 | + assert.deepEqual( |
| 138 | + [...new Set(launches)], |
| 139 | + [path.join("/test-home", ".local", "bin", "kiro-cli")], |
| 140 | + ); |
| 141 | + assert.isTrue(snapshot.installed); |
| 142 | + }).pipe(Effect.scoped), |
| 143 | + ); |
| 144 | +}); |
0 commit comments