Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions packages/provider-cursor/src/server/adapter.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// @effect-diagnostics nodeBuiltinImport:off -- The grep converter is read synchronously from the installed SDK chunk.
import * as NodeFS from "node:fs";
import * as NodeModule from "node:module";
import * as NodePath from "node:path";

import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, describe, it } from "@effect/vitest";
import type { InteractionUpdate } from "@cursor/sdk";
Expand Down Expand Up @@ -35,6 +40,27 @@ import {
import * as CursorAgentSdk from "./CursorAgentSdk.ts";
import { ConfigurationError } from "./sdk.ts";

// The SDK does not export its grep result converter, so find it in the installed build's chunks.
const loadInstalledCursorGrepResultConverter = (build: "esm" | "cjs") => {
const sdkEntry = NodeModule.createRequire(import.meta.url).resolve("@cursor/sdk");
const buildDir = NodePath.join(NodePath.dirname(sdkEntry), "..", build);
const anchorPattern =
/function [\w$]+\(e\)\{if\(e\?\.result\?\.case\)switch\(e\.result\.case\)\{case"content":return\{type:"content"/;
const chunk = NodeFS.readdirSync(buildDir)
.filter((name) => name.endsWith(".js"))
.map((name) => NodeFS.readFileSync(NodePath.join(buildDir, name), "utf8"))
.find((source) => anchorPattern.test(source));
assert.isDefined(chunk, `Cursor SDK grep result converter not found in ${buildDir}`);
const anchor = chunk.search(anchorPattern);
let depth = 0;
let end = chunk.indexOf("{", anchor);
for (; end < chunk.length; end++) {
if (chunk[end] === "{") depth++;
if (chunk[end] === "}" && --depth === 0) break;
}
return new Function(`return (${chunk.slice(anchor, end + 1)})`)() as (result: unknown) => unknown;
};

describe("CursorAdapterV2", () => {
it.effect.each([
{ status: "finished", model: undefined, lateModel: undefined },
Expand Down Expand Up @@ -1714,4 +1740,55 @@ describe("CursorAdapterV2", () => {
},
);
});

it.each(["esm", "cjs"] as const)(
"keeps grouped grep content match text, lines, and totals in the %s Cursor SDK build",
(build) => {
const convertGrepResult = loadInstalledCursorGrepResultConverter(build);

assert.deepEqual(
convertGrepResult({
result: {
case: "content",
value: {
matches: [
{
file: "src/one.ts",
matches: [
{ lineNumber: 10, content: "before one", isContextLine: true },
{ lineNumber: 11, content: "needle one", isContextLine: false },
{ lineNumber: 12, content: "after one", isContextLine: true },
],
},
{
file: "src/two.ts",
matches: [{ lineNumber: 3, content: "needle two", isContextLine: false }],
},
],
totalLines: 4,
totalMatchedLines: 7,
clientTruncated: true,
ripgrepTruncated: false,
},
},
}),
{
type: "content",
output: {
matches: [
{
file: "src/one.ts",
lineNumber: 11,
line: "needle one",
beforeContext: ["before one"],
afterContext: ["after one"],
},
{ file: "src/two.ts", lineNumber: 3, line: "needle two" },
],
totalMatches: 7,
},
},
);
},
);
});
30 changes: 30 additions & 0 deletions patches/@cursor__sdk@1.0.38.patch

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ patchedDependencies:
# Observe the owned host exit independently of descendants retaining its stdio.
"@muse-code/sdk@1.4.6": patches/@muse-code__sdk@1.4.6.patch
app-builder-lib@26.16.1: patches/app-builder-lib@26.16.1.patch
# Grep content results are grouped per file; the converter read them as flat matches (#24919).
"@cursor/sdk@1.0.38": patches/@cursor__sdk@1.0.38.patch

peerDependencyRules:
allowAny:
Expand Down
Loading