Fix Effect child process launch typing

Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
Cursor AgentandJulius Marminge committed 2026-05-07 19:20:53 +00:00
1 parent 15f47dbd9b
commit 1c691e0ebb
3 files changed
+48 -36

No files matched your search

+3 -2
View File
@@ -1,7 +1,7 @@
import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, it } from "@effect/vitest";
import { assertSuccess } from "@effect/vitest/utils";
import { FileSystem, Path, Effect, Layer, Sink, Stream } from "effect";
import { FileSystem, Path, Effect, Sink, Stream } from "effect";
import { ChildProcessSpawner } from "effect/unstable/process";
import {
@@ -490,6 +490,7 @@ it.layer(NodeServices.layer)("launchDetached", (it) => {
kill: () => Effect.void,
unref: Effect.sync(() => {
unrefCalled = true;
return Effect.void;
}),
stdin: Sink.drain,
stdout: Stream.empty,
@@ -505,7 +506,7 @@ it.layer(NodeServices.layer)("launchDetached", (it) => {
command: process.execPath,
args: ["-e", "process.exit(0)"],
}).pipe(
Effect.provide(Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner)),
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
Effect.result,
);
+35 -24
View File
@@ -190,31 +190,42 @@ const launchDetachedWithSpawner = (
return yield* new OpenError({ message: `Editor command not found: ${launch.command}` });
}
const isWin32 = process.platform === "win32";
const child = yield* spawner
.spawn(
ChildProcess.make(launch.command, isWin32 ? launch.args.map((a) => `"${a}"`) : [
...launch.args,
], {
detached: true,
stdin: "ignore",
stdout: "ignore",
stderr: "ignore",
shell: isWin32,
}),
)
.pipe(
Effect.mapError(
(cause) => new OpenError({ message: "failed to spawn detached process", cause }),
),
);
yield* child.unref;
yield* Effect.scoped(
Effect.gen(function* () {
const isWin32 = process.platform === "win32";
const child = yield* spawner
.spawn(
ChildProcess.make(
launch.command,
isWin32 ? launch.args.map((a) => `"${a}"`) : [...launch.args],
{
detached: true,
stdin: "ignore",
stdout: "ignore",
stderr: "ignore",
shell: isWin32,
},
),
)
.pipe(
Effect.mapError(
(cause) => new OpenError({ message: "failed to spawn detached process", cause }),
),
);
const _reref = yield* child.unref.pipe(
Effect.mapError(
(cause) => new OpenError({ message: "failed to unref detached process", cause }),
),
);
}),
);
});
export const launchDetached = (launch: EditorLaunch) =>
Effect.flatMap(ChildProcessSpawner.ChildProcessSpawner, (spawner) =>
launchDetachedWithSpawner(launch, spawner),
);
Effect.gen(function* () {
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
return yield* launchDetachedWithSpawner(launch, spawner);
});
const make = Effect.gen(function* () {
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
@@ -228,10 +239,10 @@ const make = Effect.gen(function* () {
Effect.tryPromise({
try: () => open.default(target),
catch: (cause) => new OpenError({ message: "Browser auto-open failed", cause }),
}),
}).pipe(Effect.asVoid),
openInEditor: (input) =>
Effect.flatMap(resolveEditorLaunch(input), (launch) =>
launchDetachedWithSpawner(launch, spawner)
launchDetachedWithSpawner(launch, spawner),
),
} satisfies OpenShape;
});
@@ -1,9 +1,4 @@
import {
CommandId,
EventId,
ProjectId,
type OrchestrationEvent,
} from "@t3tools/contracts";
import { CommandId, EventId, ProjectId } from "@t3tools/contracts";
import { assert, it } from "@effect/vitest";
import { DateTime, Duration, Effect, Layer } from "effect";
import { TestClock } from "effect/testing";
@@ -49,10 +44,15 @@ it.effect("uses the Effect clock for generated project update timestamps", () =>
},
readModel,
});
const event = (Array.isArray(result) ? result[0] : result) as Extract<
Omit<OrchestrationEvent, "sequence">,
{ type: "project.meta-updated" }
>;
if (Array.isArray(result)) {
assert.fail("expected a single project meta-updated event");
return;
}
if (result.type !== "project.meta-updated") {
assert.fail(`expected project.meta-updated, received ${result.type}`);
return;
}
const event = result;
assert.equal(event.occurredAt, expectedNow);
assert.equal(event.payload.updatedAt, expectedNow);