+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
227 lines
9.4 KiB
TypeScript
227 lines
9.4 KiB
TypeScript
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
import { describe, expect, it } from "@effect/vitest";
|
|
import * as Effect from "effect/Effect";
|
|
import * as FileSystem from "effect/FileSystem";
|
|
import * as Path from "effect/Path";
|
|
import * as Result from "effect/Result";
|
|
|
|
import {
|
|
HostProcessArguments,
|
|
HostProcessExecutablePath,
|
|
HostProcessIsExecutable,
|
|
HostProcessPlatform,
|
|
} from "./hostProcess.ts";
|
|
import { resolveNodeExecutable, resolveSelfInvocation, selfInvocationArgs } from "./nodeRuntime.ts";
|
|
import { symlinksSupported } from "./testing/symlinks.ts";
|
|
|
|
describe("Self invocation", () => {
|
|
it.effect("runs the entrypoint script with the current runtime", () =>
|
|
Effect.gen(function* () {
|
|
const path = yield* Path.Path;
|
|
const invocation = yield* resolveSelfInvocation().pipe(
|
|
Effect.provideService(HostProcessExecutablePath, "/runtime/node"),
|
|
Effect.provideService(HostProcessIsExecutable, false),
|
|
Effect.provideService(HostProcessArguments, ["/runtime/node", "dist/bin.mjs", "serve"]),
|
|
);
|
|
expect(invocation.command).toBe("/runtime/node");
|
|
expect(invocation.entrypoint).toBe(path.resolve("dist/bin.mjs"));
|
|
expect(selfInvocationArgs(invocation, ["acp-mcp-bridge"])).toEqual([
|
|
path.resolve("dist/bin.mjs"),
|
|
"acp-mcp-bridge",
|
|
]);
|
|
}).pipe(Effect.provide(NodeServices.layer)),
|
|
);
|
|
|
|
it.effect("passes subcommands straight to the standalone executable", () =>
|
|
Effect.gen(function* () {
|
|
// Node repeats the binary at argv[1] for a single-executable; it is not a script.
|
|
const invocation = yield* resolveSelfInvocation().pipe(
|
|
Effect.provideService(HostProcessExecutablePath, "/packaged/t3"),
|
|
Effect.provideService(HostProcessIsExecutable, true),
|
|
Effect.provideService(HostProcessArguments, ["/packaged/t3", "/packaged/t3", "serve"]),
|
|
);
|
|
expect(invocation).toEqual({ command: "/packaged/t3", entrypoint: undefined });
|
|
expect(selfInvocationArgs(invocation, ["acp-mcp-bridge"])).toEqual(["acp-mcp-bridge"]);
|
|
}).pipe(Effect.provide(NodeServices.layer)),
|
|
);
|
|
});
|
|
|
|
describe("Node runtime selection", () => {
|
|
it.effect("keeps the current Node or Electron runtime without requiring Node on PATH", () =>
|
|
Effect.gen(function* () {
|
|
for (const executable of ["/runtime/node", "/Applications/T3 Code.app/Electron"]) {
|
|
expect(
|
|
yield* resolveNodeExecutable("Local device support", { PATH: "" }).pipe(
|
|
Effect.provideService(HostProcessExecutablePath, executable),
|
|
Effect.provideService(HostProcessIsExecutable, false),
|
|
),
|
|
).toBe(executable);
|
|
}
|
|
}).pipe(Effect.provide(NodeServices.layer)),
|
|
);
|
|
|
|
it.effect("uses installed Node instead of the standalone T3 executable", () =>
|
|
Effect.gen(function* () {
|
|
const path = yield* Path.Path;
|
|
expect(
|
|
yield* resolveNodeExecutable("Local device support", {
|
|
PATH: path.dirname(process.execPath),
|
|
}),
|
|
).toBe(process.execPath);
|
|
}).pipe(
|
|
Effect.provideService(HostProcessExecutablePath, "/packaged/t3"),
|
|
Effect.provideService(HostProcessIsExecutable, true),
|
|
Effect.provide(NodeServices.layer),
|
|
),
|
|
);
|
|
|
|
it.effect("explains how to install Node when a standalone helper has no runtime", () =>
|
|
Effect.gen(function* () {
|
|
const error = yield* resolveNodeExecutable("Local device support", { PATH: "" }).pipe(
|
|
Effect.flip,
|
|
);
|
|
expect(error._tag).toBe("NodeRuntimeUnavailableError");
|
|
expect(error.message).toContain("Local device support requires Node.js");
|
|
expect(error.message).toContain("Install Node.js");
|
|
}).pipe(
|
|
Effect.provideService(HostProcessIsExecutable, true),
|
|
Effect.provide(NodeServices.layer),
|
|
),
|
|
);
|
|
|
|
it.effect("finds a newly installed runtime immediately after a failed lookup", () =>
|
|
Effect.gen(function* () {
|
|
const fs = yield* FileSystem.FileSystem;
|
|
const path = yield* Path.Path;
|
|
const directory = yield* fs.makeTempDirectoryScoped();
|
|
const platform = yield* HostProcessPlatform;
|
|
const node = path.join(directory, platform === "win32" ? "node.exe" : "node");
|
|
const env = { PATH: directory };
|
|
expect(
|
|
Result.isFailure(
|
|
yield* resolveNodeExecutable("Local device support", env).pipe(Effect.result),
|
|
),
|
|
).toBe(true);
|
|
yield* fs.copyFile(process.execPath, node);
|
|
yield* fs.chmod(node, 0o755);
|
|
expect(yield* resolveNodeExecutable("Local device support", env)).toBe(node);
|
|
}).pipe(
|
|
Effect.scoped,
|
|
Effect.provideService(HostProcessExecutablePath, "/packaged/t3"),
|
|
Effect.provideService(HostProcessIsExecutable, true),
|
|
Effect.provide(NodeServices.layer),
|
|
),
|
|
);
|
|
|
|
it.effect("uses node.exe even when Windows batch wrappers appear first on PATH", () =>
|
|
Effect.gen(function* () {
|
|
const fs = yield* FileSystem.FileSystem;
|
|
const path = yield* Path.Path;
|
|
const directory = yield* fs.makeTempDirectoryScoped();
|
|
const wrappers = path.join(directory, "wrappers");
|
|
const runtime = path.join(directory, "runtime");
|
|
yield* fs.makeDirectory(wrappers);
|
|
yield* fs.makeDirectory(runtime);
|
|
yield* fs.writeFileString(path.join(wrappers, "node.cmd"), "@echo off");
|
|
yield* fs.writeFileString(path.join(wrappers, "node.bat"), "@echo off");
|
|
const node = path.join(runtime, "node.exe");
|
|
yield* fs.copyFile(process.execPath, node);
|
|
expect(
|
|
yield* resolveNodeExecutable("Local device support", {
|
|
PATH: `${wrappers};${runtime}`,
|
|
PATHEXT: ".CMD;.BAT",
|
|
}),
|
|
).toBe(node);
|
|
}).pipe(
|
|
Effect.scoped,
|
|
Effect.provideService(HostProcessExecutablePath, "/packaged/t3"),
|
|
Effect.provideService(HostProcessIsExecutable, true),
|
|
Effect.provideService(HostProcessPlatform, "win32"),
|
|
Effect.provide(NodeServices.layer),
|
|
),
|
|
);
|
|
|
|
it.effect("reports install guidance when Windows only has batch runtime wrappers", () =>
|
|
Effect.gen(function* () {
|
|
const fs = yield* FileSystem.FileSystem;
|
|
const path = yield* Path.Path;
|
|
const directory = yield* fs.makeTempDirectoryScoped();
|
|
yield* fs.writeFileString(path.join(directory, "node.cmd"), "@echo off");
|
|
yield* fs.writeFileString(path.join(directory, "node.bat"), "@echo off");
|
|
const error = yield* resolveNodeExecutable("Local device support", {
|
|
PATH: directory,
|
|
PATHEXT: ".CMD;.BAT;.EXE",
|
|
}).pipe(Effect.flip);
|
|
expect(error._tag).toBe("NodeRuntimeUnavailableError");
|
|
expect(error.message).toContain("Install Node.js");
|
|
}).pipe(
|
|
Effect.scoped,
|
|
Effect.provideService(HostProcessIsExecutable, true),
|
|
Effect.provideService(HostProcessPlatform, "win32"),
|
|
Effect.provide(NodeServices.layer),
|
|
),
|
|
);
|
|
|
|
it.effect("rejects a hard-linked node alias pointing back at the standalone app", () =>
|
|
Effect.gen(function* () {
|
|
const fs = yield* FileSystem.FileSystem;
|
|
const path = yield* Path.Path;
|
|
const directory = yield* fs.makeTempDirectoryScoped();
|
|
const platform = yield* HostProcessPlatform;
|
|
const executable = path.join(directory, platform === "win32" ? "t3.exe" : "t3");
|
|
const node = path.join(directory, platform === "win32" ? "node.exe" : "node");
|
|
yield* fs.writeFileString(executable, "standalone executable fixture");
|
|
yield* fs.chmod(executable, 0o755);
|
|
yield* fs.link(executable, node);
|
|
const error = yield* resolveNodeExecutable("Local device support", { PATH: directory }).pipe(
|
|
Effect.provideService(HostProcessExecutablePath, executable),
|
|
Effect.flip,
|
|
);
|
|
expect(error._tag).toBe("NodeRuntimeUnavailableError");
|
|
expect(error.message).toContain("Install Node.js");
|
|
}).pipe(
|
|
Effect.scoped,
|
|
Effect.provideService(HostProcessIsExecutable, true),
|
|
Effect.provide(NodeServices.layer),
|
|
),
|
|
);
|
|
|
|
it.effect.skipIf(!symlinksSupported)("preserves the node alias used by runtime launchers", () =>
|
|
Effect.gen(function* () {
|
|
const fs = yield* FileSystem.FileSystem;
|
|
const path = yield* Path.Path;
|
|
const directory = yield* fs.makeTempDirectoryScoped();
|
|
const platform = yield* HostProcessPlatform;
|
|
const node = path.join(directory, platform === "win32" ? "node.exe" : "node");
|
|
yield* fs.symlink(process.execPath, node);
|
|
expect(yield* resolveNodeExecutable("Local device support", { PATH: directory })).toBe(node);
|
|
}).pipe(
|
|
Effect.scoped,
|
|
Effect.provideService(HostProcessExecutablePath, "/packaged/t3"),
|
|
Effect.provideService(HostProcessIsExecutable, true),
|
|
Effect.provide(NodeServices.layer),
|
|
),
|
|
);
|
|
|
|
it.effect.skipIf(!symlinksSupported)(
|
|
"rejects a node alias pointing back at the standalone app",
|
|
() =>
|
|
Effect.gen(function* () {
|
|
const fs = yield* FileSystem.FileSystem;
|
|
const path = yield* Path.Path;
|
|
const directory = yield* fs.makeTempDirectoryScoped();
|
|
const platform = yield* HostProcessPlatform;
|
|
const node = path.join(directory, platform === "win32" ? "node.exe" : "node");
|
|
yield* fs.symlink(process.execPath, node);
|
|
const error = yield* resolveNodeExecutable("Local device support", {
|
|
PATH: directory,
|
|
}).pipe(Effect.flip);
|
|
expect(error.message).toContain("Install Node.js");
|
|
}).pipe(
|
|
Effect.scoped,
|
|
Effect.provideService(HostProcessIsExecutable, true),
|
|
Effect.provide(NodeServices.layer),
|
|
),
|
|
);
|
|
});
|