Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
import * as Predicate from "effect/Predicate";
import * as NetService from "@akeru/shared/Net";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
import * as Sink from "effect/Sink";
import * as Stream from "effect/Stream";
import { HttpClient, HttpClientResponse } from "effect/unstable/http";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
export const TEST_NODE_ENGINE_RANGE = "^22.16 || ^23.11 || >=24.10";
export const makeSuccessfulProcess = (stdout: string) => {
const stdoutStream = Stream.make(new TextEncoder().encode(stdout));
return ChildProcessSpawner.makeHandle({
pid: ChildProcessSpawner.ProcessId(123),
stdout: stdoutStream,
stderr: Stream.empty,
all: stdoutStream,
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
isRunning: Effect.succeed(false),
kill: () => Effect.void,
stdin: Sink.drain,
getInputFd: () => Sink.drain,
getOutputFd: () => Stream.empty,
unref: Effect.succeed(Effect.void),
});
};
export const makeDelayedSuccessfulProcess = (stdout: string, delayMs: number) => {
const process = makeSuccessfulProcess(stdout);
return {
...process,
exitCode: Effect.sleep(Duration.millis(delayMs)).pipe(
Effect.as(ChildProcessSpawner.ExitCode(0)),
),
};
};
export const makeRunningProcess = (onKill: () => void) => {
let finish: ((exitCode: ChildProcessSpawner.ExitCode) => void) | null = null;
return ChildProcessSpawner.makeHandle({
pid: ChildProcessSpawner.ProcessId(123),
stdout: Stream.empty,
stderr: Stream.empty,
all: Stream.empty,
exitCode: Effect.callback<ChildProcessSpawner.ExitCode>((resume) => {
finish = (exitCode) => resume(Effect.succeed(exitCode));
return Effect.sync(() => {
finish = null;
});
}),
isRunning: Effect.succeed(true),
kill: () =>
Effect.sync(() => {
onKill();
finish?.(ChildProcessSpawner.ExitCode(143));
}),
stdin: Sink.drain,
getInputFd: () => Sink.drain,
getOutputFd: () => Stream.empty,
unref: Effect.succeed(Effect.void),
});
};
export const testHttpClient = HttpClient.make((request) =>
Effect.succeed(HttpClientResponse.fromWeb(request, new Response("", { status: 200 }))),
);
export const hangingHttpClient = HttpClient.make(() => Effect.never);
export const testNetService = NetService.NetService.of({
canListenOnHost: () => Effect.succeed(true),
isPortAvailableOnLoopback: () => Effect.succeed(true),
hasListenerOnHost: () => Effect.succeed(false),
reserveLoopbackPort: () => Effect.succeed(41_773),
findAvailablePort: (preferred) => Effect.succeed(preferred),
});
export function commandArgs(command: ChildProcess.Command): ReadonlyArray<string> {
return Predicate.isTagged(command, "StandardCommand") ? command.args : [];
}