Skip to content

Commit 3958063

Browse files
test(cursor): use Effect for SDK subprocess probes
1 parent c047776 commit 3958063

1 file changed

Lines changed: 83 additions & 80 deletions

File tree

‎packages/provider-cursor/src/server/sdk.test.ts‎

Lines changed: 83 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
// @effect-diagnostics nodeBuiltinImport:off globalTimers:off -- The probe is a plain Node child; this deadline kills it if it hangs.
2-
import * as NodeChildProcess from "node:child_process";
3-
import { describe, expect, it } from "vite-plus/test";
1+
import * as NodeServices from "@effect/platform-node/NodeServices";
2+
import { describe, expect, it } from "@effect/vitest";
3+
import * as HostProcess from "@t3tools/shared/HostProcess";
4+
import * as Effect from "effect/Effect";
5+
import * as Stream from "effect/Stream";
6+
import * as ChildProcess from "effect/process/ChildProcess";
7+
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
48

59
const cursorSdkUrl = new URL("./sdk.ts", import.meta.url).href;
610

@@ -118,85 +122,84 @@ console.error("Unknown Cursor SDK model probe: " + mode);
118122
process.exit(2);
119123
`;
120124

121-
function runProbe(mode: string): Promise<{ code: number | null; stdout: string; stderr: string }> {
122-
return new Promise((resolve, reject) => {
123-
const child = NodeChildProcess.spawn(
124-
process.execPath,
125-
[
126-
"--experimental-strip-types",
127-
"--disable-warning=ExperimentalWarning",
128-
"--input-type=module",
129-
"-e",
130-
probeProgram,
131-
mode,
132-
],
133-
{ stdio: ["ignore", "pipe", "pipe"] },
125+
const runProbe = Effect.fnUntraced(
126+
function* (mode: string) {
127+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
128+
const child = yield* spawner.spawn(
129+
ChildProcess.make(
130+
HostProcess.ExecutablePath.defaultValue(),
131+
[
132+
"--experimental-strip-types",
133+
"--disable-warning=ExperimentalWarning",
134+
"--input-type=module",
135+
"-e",
136+
probeProgram,
137+
mode,
138+
],
139+
{ stdin: "ignore" },
140+
),
134141
);
135-
let stdout = "";
136-
let stderr = "";
137-
child.stdout.setEncoding("utf8");
138-
child.stderr.setEncoding("utf8");
139-
child.stdout.on("data", (chunk: string) => {
140-
stdout += chunk;
141-
});
142-
child.stderr.on("data", (chunk: string) => {
143-
stderr += chunk;
144-
});
145-
const timer = setTimeout(() => {
146-
child.kill();
147-
reject(new Error(`probe ${mode} timed out`));
148-
}, 5_000);
149-
child.on("error", reject);
150-
child.on("close", (code) => {
151-
clearTimeout(timer);
152-
resolve({ code, stdout, stderr });
153-
});
154-
});
155-
}
142+
return yield* Effect.all(
143+
{
144+
code: child.exitCode,
145+
stdout: child.stdout.pipe(Stream.decodeText(), Stream.mkString),
146+
stderr: child.stderr.pipe(Stream.decodeText(), Stream.mkString),
147+
},
148+
{ concurrency: "unbounded" },
149+
);
150+
},
151+
Effect.scoped,
152+
Effect.timeout("5 seconds"),
153+
Effect.provide(NodeServices.layer),
154+
);
156155

157156
describe("Cursor long-context requests", () => {
158-
it("sets Max Mode in real SDK sends for the reported context tiers", async () => {
159-
const result = await runProbe("sdk-model-requests");
160-
expect(result.code, result.stderr.slice(-2_000)).toBe(0);
161-
expect(JSON.parse(result.stdout)).toEqual([
162-
{ model: "grok-4.7", context: "500k", maxMode: true },
163-
{ model: "grok-4.7", context: "256k", maxMode: false },
164-
{ model: "claude-opus-5-5", context: "1m", maxMode: true },
165-
{ model: "claude-opus-5-5", context: "300k", maxMode: false },
166-
]);
167-
});
157+
it.live("sets Max Mode in real SDK sends for the reported context tiers", () =>
158+
Effect.gen(function* () {
159+
const result = yield* runProbe("sdk-model-requests");
160+
expect(result.code, result.stderr.slice(-2_000)).toBe(0);
161+
expect(JSON.parse(result.stdout)).toEqual([
162+
{ model: "grok-4.7", context: "500k", maxMode: true },
163+
{ model: "grok-4.7", context: "256k", maxMode: false },
164+
{ model: "claude-opus-5-5", context: "1m", maxMode: true },
165+
{ model: "claude-opus-5-5", context: "300k", maxMode: false },
166+
]);
167+
}),
168+
);
168169

169-
it("serializes Max Mode for long tiers and preserves standard requests", async () => {
170-
const result = await runProbe("model-requests");
171-
expect(result.code).toBe(0);
172-
const { requests, unrelatedMaxMode } = JSON.parse(result.stdout);
173-
expect(requests.map((request: { maxMode: boolean }) => request.maxMode)).toEqual([
174-
true,
175-
true,
176-
true,
177-
true,
178-
false,
179-
false,
180-
false,
181-
false,
182-
false,
183-
false,
184-
false,
185-
true,
186-
]);
187-
expect(requests[0]).toEqual({
188-
maxMode: true,
189-
modelId: "claude-opus-5-5",
190-
parameters: [
191-
{ id: "reasoning_effort", value: "high" },
192-
{ id: "context", value: "1m" },
193-
{ id: "fast", value: "true" },
194-
],
195-
sourceUnchanged: true,
196-
});
197-
expect(requests.every((request: { sourceUnchanged: boolean }) => request.sourceUnchanged)).toBe(
198-
true,
199-
);
200-
expect(unrelatedMaxMode).toBe(false);
201-
});
170+
it.live("serializes Max Mode for long tiers and preserves standard requests", () =>
171+
Effect.gen(function* () {
172+
const result = yield* runProbe("model-requests");
173+
expect(result.code).toBe(0);
174+
const { requests, unrelatedMaxMode } = JSON.parse(result.stdout);
175+
expect(requests.map((request: { maxMode: boolean }) => request.maxMode)).toEqual([
176+
true,
177+
true,
178+
true,
179+
true,
180+
false,
181+
false,
182+
false,
183+
false,
184+
false,
185+
false,
186+
false,
187+
true,
188+
]);
189+
expect(requests[0]).toEqual({
190+
maxMode: true,
191+
modelId: "claude-opus-5-5",
192+
parameters: [
193+
{ id: "reasoning_effort", value: "high" },
194+
{ id: "context", value: "1m" },
195+
{ id: "fast", value: "true" },
196+
],
197+
sourceUnchanged: true,
198+
});
199+
expect(
200+
requests.every((request: { sourceUnchanged: boolean }) => request.sourceUnchanged),
201+
).toBe(true);
202+
expect(unrelatedMaxMode).toBe(false);
203+
}),
204+
);
202205
});

0 commit comments

Comments
 (0)