History

Address Codex review feedback

Julius Marminge committed 6 months ago

Commit fa4a29f1 parent 3a38f065 files · +75 −8Browse files

Showing the changes to packages/effect-codex-app-server (2 of 5 files). Show all

Unified · Split

2 files
  1. packages/effect-codex-app-server/src/client.test.ts +30 −0
  2. packages/effect-codex-app-server/src/client.ts +7 −5
packages/effect-codex-app-server/src/client.test.ts+30−0
@@ -121,4 +121,34 @@ it.layer(NodeServices.layer)("effect-codex-app-server client", (it) => { · 120 unmodified lines
121121 ]);
122122 }),
123123 );
124+
125+ it.effect("initializes a command-backed app-server client", () =>
126+ Effect.gen(function* () {
127+ const path = yield* Path.Path;
128+ const scope = yield* Scope.make();
129+ const clientLayer = CodexClient.layerCommand({
130+ command: "bun",
131+ args: ["run", yield* mockPeerPath],
132+ cwd: path.join(import.meta.dirname, ".."),
133+ });
134+ const context = yield* Layer.buildWithScope(clientLayer, scope);
135+
136+ const initialized = yield* Effect.gen(function* () {
137+ const client = yield* CodexClient.CodexAppServerClient;
138+ return yield* client.request("initialize", {
139+ clientInfo: {
140+ name: "effect-codex-app-server-test",
141+ title: "Effect Codex App Server Test",
142+ version: "0.0.0",
143+ },
144+ capabilities: {
145+ experimentalApi: true,
146+ optOutNotificationMethods: null,
147+ },
148+ });
149+ }).pipe(Effect.provide(context), Effect.ensuring(Scope.close(scope, Exit.void)));
150+
151+ assert.equal(initialized.userAgent, "mock-codex-app-server");
152+ }),
153+ );
124154 });
packages/effect-codex-app-server/src/client.ts+7−5
@@ -281,7 +281,7 @@ export const layerCommand = ( · 280 unmodified lines
281281 ...(options.env ? { env: { ...process.env, ...options.env } } : {}),
282282 shell: process.platform === "win32",
283283 });
284− const handle = yield* spawner.spawn(command).pipe(
284+ return yield* spawner.spawn(command).pipe(
285285 Effect.mapError(
286286 (cause) =>
287287 new CodexError.CodexAppServerSpawnError({
@@ -290,9 +290,11 @@ export const layerCommand = ( · 2 unmodified lines
290290 }),
291291 ),
292292 );
293− const client = yield* make(makeChildStdio(handle), options, makeTerminationError(handle));
294− return { client, handle };
295293 }),
296− ({ handle }) => handle.kill().pipe(Effect.orDie),
297− ).pipe(Effect.map(({ client }) => client)),
294+ (handle) => handle.kill().pipe(Effect.orDie),
295+ ).pipe(
296+ Effect.flatMap((handle) =>
297+ make(makeChildStdio(handle), options, makeTerminationError(handle)),
298+ ),
299+ ),
298300 );