@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 90 lines 3.69 KB
Raw
1 import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2 import * as NodeServices from "@effect/platform-node/NodeServices";
3 import { assert, 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 ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions";
9 import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
10 import * as HostProcess from "@t3tools/shared/HostProcess";
11 import * as Effect from "effect/Effect";
12 import * as HttpClient from "effect/http/HttpClient";
13 import * as Layer from "effect/Layer";
14 import * as Path from "effect/Path";
15 import * as Schema from "effect/Schema";
16 import * as Sink from "effect/Sink";
17 import * as Stream from "effect/Stream";
18 import * as ChildProcess from "effect/process/ChildProcess";
19 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
20
21 import { FxSettings } from "../settings.ts";
22 import { FxDriver } from "./driver.ts";
23
24 const homeRelativeSettings = Schema.decodeSync(FxSettings)({ binaryPath: "~/.local/bin/fx" });
25
26 const layerTest = TestProviderHost.layer({ runBackgroundWork: false }).pipe(
27 Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
28 Layer.provideMerge(IdAllocator.layer),
29 Layer.provideMerge(McpProviderSessions.layer),
30 Layer.provideMerge(ProviderLatestVersions.layer),
31 Layer.provideMerge(
32 Layer.succeed(
33 ProviderEventLoggers.ProviderEventLoggers,
34 ProviderEventLoggers.NoOpProviderEventLoggers,
35 ),
36 ),
37 Layer.provideMerge(
38 Layer.succeed(
39 HttpClient.HttpClient,
40 HttpClient.make(() => Effect.die("Unexpected HTTP request")),
41 ),
42 ),
43 );
44
45 /** Records each spawned command and answers only `--version`. */
46 function recordingSpawner(launches: Array<string>) {
47 return ChildProcessSpawner.make((command) => {
48 const standard = ChildProcess.isStandardCommand(command);
49 if (standard) launches.push(command.command);
50 const version = standard && command.args.join(" ") === "--version";
51 return Effect.succeed(
52 ChildProcessSpawner.makeHandle({
53 pid: ChildProcessSpawner.ProcessId(1),
54 exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(version ? 0 : 2)),
55 isRunning: Effect.succeed(false),
56 kill: () => Effect.void,
57 unref: Effect.succeed(Effect.void),
58 stdin: Sink.drain,
59 stdout: version ? Stream.encodeText(Stream.make("fx 0.0.13\n")) : Stream.empty,
60 stderr: Stream.empty,
61 all: Stream.empty,
62 getInputFd: () => Sink.drain,
63 getOutputFd: () => Stream.empty,
64 }),
65 );
66 });
67 }
68
69 it.layer(layerTest)("FxDriver binary path", (it) => {
70 it.effect("probes a ~/ binary path from the home directory", () =>
71 Effect.gen(function* () {
72 const path = yield* Path.Path;
73 const launches: Array<string> = [];
74 const instance = yield* FxDriver.create({
75 instanceId: ProviderInstanceId.make("fx-home"),
76 displayName: undefined,
77 enabled: true,
78 environment: [],
79 config: homeRelativeSettings,
80 }).pipe(
81 Effect.provideService(HostProcess.HomeDirectory, "/test-home"),
82 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, recordingSpawner(launches)),
83 );
84 const snapshot = yield* instance.snapshot.refresh;
85 assert.isNotEmpty(launches);
86 assert.deepEqual([...new Set(launches)], [path.join("/test-home", ".local", "bin", "fx")]);
87 assert.isTrue(snapshot.installed);
88 }),
89 );
90 });