Skip to content

Commit 393d7b3

Browse files
test(server): re-record Cursor replay fixtures and cover skills live (#13493)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 8d7d885 commit 393d7b3

22 files changed

Lines changed: 1091 additions & 935 deletions

‎apps/server/scripts/record-cursor-agent-sdk-replay-fixture.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ import {
1616
PROVIDER_THREAD_RESUME_FIRST_PROMPT,
1717
PROVIDER_THREAD_RESUME_SECOND_PROMPT,
1818
PROPOSED_PLAN_PROMPT,
19+
READ_ONLY_NEVER_POLICY,
1920
SIMPLE_PROMPT,
21+
SKILL_INVOCATION_CURSOR_MESSAGE,
2022
SUBAGENT_PROMPT,
2123
TODO_LIST_PROMPT,
2224
TOOL_CALL_READ_ONLY_PROMPT,
2325
TURN_INTERRUPT_MID_TOOL_PROMPT,
26+
WORKSPACE_NEVER_POLICY,
2427
} from "../src/orchestration-v2/testkit/fixtures/shared.ts";
28+
import { skillInvocationInput } from "../src/orchestration-v2/testkit/fixtures/skill_invocation/input.ts";
2529
import {
2630
cursorReplayPromptsForWorkspace,
2731
cursorReplayTranscriptCwd,
@@ -56,24 +60,36 @@ const RECORDINGS = {
5660
prompts: [PROPOSED_PLAN_PROMPT],
5761
output: "../src/orchestration-v2/testkit/fixtures/proposed_plan/cursor_transcript.ndjson",
5862
interactionMode: "plan",
63+
runtimePolicyOverride: READ_ONLY_NEVER_POLICY,
5964
},
6065
todo_list: {
6166
prompts: [TODO_LIST_PROMPT],
6267
output: "../src/orchestration-v2/testkit/fixtures/todo_list/cursor_transcript.ndjson",
68+
runtimePolicyOverride: READ_ONLY_NEVER_POLICY,
6369
},
6470
subagent: {
6571
prompts: [SUBAGENT_PROMPT],
6672
output: "../src/orchestration-v2/testkit/fixtures/subagent/cursor_transcript.ndjson",
73+
runtimePolicyOverride: READ_ONLY_NEVER_POLICY,
6774
},
6875
tool_call_read_only: {
6976
prompts: [TOOL_CALL_READ_ONLY_PROMPT],
7077
output: "../src/orchestration-v2/testkit/fixtures/tool_call_read_only/cursor_transcript.ndjson",
78+
runtimePolicyOverride: READ_ONLY_NEVER_POLICY,
7179
},
7280
turn_interrupt_mid_tool: {
7381
prompts: [TURN_INTERRUPT_MID_TOOL_PROMPT],
7482
output:
7583
"../src/orchestration-v2/testkit/fixtures/turn_interrupt_mid_tool/cursor_transcript.ndjson",
7684
interruptAfterToolStart: true,
85+
runtimePolicyOverride: WORKSPACE_NEVER_POLICY,
86+
},
87+
skill_invocation: {
88+
// The adapter rewrites a discovered `$review` mention to Cursor's native
89+
// `/review` invocation before sending, so the SDK sees the rewritten form.
90+
prompts: [SKILL_INVOCATION_CURSOR_MESSAGE],
91+
output: "../src/orchestration-v2/testkit/fixtures/skill_invocation/cursor_transcript.ndjson",
92+
workspaceFiles: skillInvocationInput().workspaceFiles,
7793
},
7894
} as const;
7995

@@ -112,8 +128,12 @@ async function prepareWorkspace(scenario: RecordingName): Promise<{
112128
owned: false,
113129
};
114130
}
131+
const recording = RECORDINGS[scenario];
115132
return {
116-
cwd: await makeCheckpointWorkspace(`cursor-agent-sdk-record-${scenario}`),
133+
cwd: await makeCheckpointWorkspace(
134+
`cursor-agent-sdk-record-${scenario}`,
135+
"workspaceFiles" in recording ? recording.workspaceFiles : undefined,
136+
),
117137
owned: true,
118138
};
119139
}
@@ -189,6 +209,9 @@ try {
189209
...(transcriptCwd === undefined ? {} : { transcriptCwd }),
190210
apiKey,
191211
...("interactionMode" in recording ? { interactionMode: recording.interactionMode } : {}),
212+
...("runtimePolicyOverride" in recording
213+
? { runtimePolicyOverride: recording.runtimePolicyOverride }
214+
: {}),
192215
...("interruptAfterToolStart" in recording
193216
? { interruptAfterToolStart: recording.interruptAfterToolStart }
194217
: {}),

‎apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.test.ts‎

Lines changed: 22 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -39,128 +39,6 @@ import { isCursorCancellationError, loggedCursorAgentOptions } from "./CursorAge
3939
const decodeCursorSettings = Schema.decodeEffect(CursorSettings);
4040

4141
describe("CursorAdapterV2", () => {
42-
it.effect("sends discovered skills as native slash invocations with runtime instructions", () =>
43-
Effect.gen(function* () {
44-
const fileSystem = yield* FileSystem.FileSystem;
45-
const path = yield* Path.Path;
46-
const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-skills-" });
47-
const skillDirectory = path.join(workspace, ".cursor", "skills", "review");
48-
yield* fileSystem.makeDirectory(skillDirectory, { recursive: true });
49-
yield* fileSystem.writeFileString(
50-
path.join(skillDirectory, "SKILL.md"),
51-
"---\nname: review\n---\nReview the changes.",
52-
);
53-
const sentMessages: Array<string> = [];
54-
const instanceId = ProviderInstanceId.make("cursor");
55-
const threadId = ThreadId.make("cursor-skills-thread");
56-
const modelSelection = { instanceId, model: "composer-2.5" };
57-
const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({
58-
runtimeMode: "full-access",
59-
interactionMode: "default",
60-
cwd: workspace,
61-
});
62-
const adapter = makeCursorAdapterV2({
63-
instanceId,
64-
settings: yield* decodeCursorSettings({}),
65-
environment: { HOME: workspace },
66-
fileSystem,
67-
path,
68-
idAllocator: yield* IdAllocatorV2,
69-
serverConfig: yield* ServerConfig.pipe(
70-
Effect.provide(serverConfigLayerTest(workspace, { prefix: "cursor-v2-skills-config-" })),
71-
),
72-
runner: {
73-
assertComplete: Effect.void,
74-
open: () =>
75-
Effect.succeed({
76-
agentId: "native-cursor-skills",
77-
listMessages: Effect.succeed([]),
78-
close: Effect.void,
79-
send: (input) =>
80-
Effect.sync(() => {
81-
sentMessages.push(
82-
typeof input.message === "string" ? input.message : input.message.text,
83-
);
84-
return {
85-
agentId: "native-cursor-skills",
86-
runId: "native-cursor-run",
87-
wait: Effect.succeed({
88-
id: "native-cursor-run",
89-
requestId: "native-request",
90-
status: "finished" as const,
91-
model: { id: "composer-2.5" },
92-
durationMs: 1,
93-
}),
94-
cancel: Effect.void,
95-
};
96-
}),
97-
}),
98-
},
99-
});
100-
const runtime = yield* adapter.openSession({
101-
threadId,
102-
providerSessionId: ProviderSessionId.make("cursor-skills-session"),
103-
modelSelection,
104-
runtimePolicy,
105-
});
106-
const providerThread = yield* runtime.ensureThread({
107-
threadId,
108-
modelSelection,
109-
runtimePolicy,
110-
});
111-
const now = yield* DateTime.now;
112-
yield* runtime.startTurn({
113-
threadId,
114-
providerThread,
115-
modelSelection,
116-
runtimePolicy,
117-
runId: RunId.make("cursor-skills-run"),
118-
runOrdinal: 1,
119-
providerTurnOrdinal: 1,
120-
attemptId: RunAttemptId.make("cursor-skills-attempt"),
121-
rootNodeId: NodeId.make("cursor-skills-root"),
122-
appThread: {
123-
id: threadId,
124-
projectId: ProjectId.make("cursor-skills-project"),
125-
createdBy: "user",
126-
creationSource: "web",
127-
title: "Cursor skills",
128-
providerInstanceId: instanceId,
129-
modelSelection,
130-
runtimeMode: "full-access",
131-
interactionMode: "default",
132-
branch: null,
133-
worktreePath: null,
134-
activeProviderThreadId: providerThread.id,
135-
lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
136-
forkedFrom: null,
137-
createdAt: now,
138-
updatedAt: now,
139-
archivedAt: null,
140-
settledOverride: null,
141-
settledAt: null,
142-
lastVisitedAt: null,
143-
deletedAt: null,
144-
},
145-
message: {
146-
messageId: MessageId.make("cursor-skills-message"),
147-
createdBy: "user",
148-
creationSource: "web",
149-
text: "$review this with $HOME and $missing",
150-
attachments: [],
151-
},
152-
});
153-
yield* runtime.events.pipe(
154-
Stream.filter((event) => event.type === "turn.terminal"),
155-
Stream.runHead,
156-
);
157-
assert.lengthOf(sentMessages, 1);
158-
assert.isTrue(sentMessages[0]!.startsWith("/review this with $HOME and $missing\n\n"));
159-
assert.include(sentMessages[0]!, "Cursor");
160-
assert.include(sentMessages[0]!, "T3 Code");
161-
}).pipe(Effect.scoped, Effect.provide(Layer.merge(NodeServices.layer, idAllocatorLayer))),
162-
);
163-
16442
for (const { status, model } of [
16543
{ status: "finished", model: undefined },
16644
{ status: "cancelled", model: "claude-opus-4-6" },
@@ -202,20 +80,29 @@ describe("CursorAdapterV2", () => {
20280
close: Effect.void,
20381
send: (input) =>
20482
Effect.gen(function* () {
205-
yield* input.onDelta!({
206-
type: "tool-call-started",
207-
modelCallId: "model-call",
208-
callId: "task-call",
209-
toolCall: {
210-
type: "task",
211-
args: {
212-
description: "Review",
213-
prompt: "Review the code.",
214-
subagentType: { kind: "generalPurpose" },
215-
...(model === undefined ? {} : { model }),
216-
},
83+
// Recorded Cursor task calls (see fixtures/subagent) stream a
84+
// partial-tool-call before tool-call-started with the same args.
85+
// The run then ends without tool-call-completed, which a live
86+
// run cannot produce on demand.
87+
const taskToolCall = {
88+
type: "task" as const,
89+
args: {
90+
description: "Review",
91+
prompt: "Review the code.",
92+
subagentType: { kind: "unspecified" },
93+
...(model === undefined ? {} : { model }),
94+
agentId: "cursor-task-agent",
95+
mode: "unspecified" as const,
21796
},
218-
}).pipe(Effect.orDie);
97+
};
98+
for (const type of ["partial-tool-call", "tool-call-started"] as const) {
99+
yield* input.onDelta!({
100+
type,
101+
modelCallId: "model-call",
102+
callId: "task-call",
103+
toolCall: taskToolCall,
104+
}).pipe(Effect.orDie);
105+
}
219106
return {
220107
agentId: "native-cursor-lifecycle",
221108
runId: "native-cursor-run",

‎apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.ts‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { HostProcessEnvironment } from "@t3tools/shared/hostProcess";
12
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
23
import { DEFAULT_SIGNAL_EXPORT } from "@t3tools/shared/observability";
34
import type { InteractionUpdate, RunResult } from "@cursor/sdk";
@@ -44,6 +45,7 @@ import {
4445
makeCursorAgentOptions,
4546
} from "./CursorAdapterV2.ts";
4647
import type { ProviderAdapterV2RuntimePolicy } from "../ProviderAdapter.ts";
48+
import type { RuntimePolicyV2Override } from "../RuntimePolicy.ts";
4749

4850
const CursorAgentSdkReplayTranscript = Schema.Struct({
4951
provider: Schema.Literal(CURSOR_PROVIDER),
@@ -620,6 +622,16 @@ export function makeCursorProviderAdapterRegistryReplayLayer(
620622
ServerConfig,
621623
makeReplayServerConfig(transcript.scenario).pipe(Effect.orDie),
622624
).pipe(Layer.provide(NodeServices.layer));
625+
// Skill discovery also scans user roots under HOME; an empty HOME keeps
626+
// replays from picking up the host's own skills.
627+
const hostEnvironmentLayer = Layer.effect(
628+
HostProcessEnvironment,
629+
Effect.gen(function* () {
630+
const fs = yield* FileSystem.FileSystem;
631+
const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cursor-replay-home-" });
632+
return { HOME: home };
633+
}).pipe(Effect.orDie),
634+
).pipe(Layer.provide(NodeServices.layer));
623635
return makeProviderAdapterRegistryDriverLayer({
624636
drivers: [CursorAdapterV2Driver],
625637
configMap: {
@@ -632,6 +644,7 @@ export function makeCursorProviderAdapterRegistryReplayLayer(
632644
Layer.mergeAll(
633645
makeCursorAgentSdkReplayLayer(transcript, options),
634646
serverConfigLayer,
647+
hostEnvironmentLayer,
635648
NodeServices.layer,
636649
idAllocatorLayer,
637650
),
@@ -670,24 +683,35 @@ export const CursorOrchestratorReplayHarness: OrchestratorV2ProviderReplayHarnes
670683
makeCursorProviderAdapterRegistryReplayLayer(transcript),
671684
};
672685

686+
function sanitizeReplayText(
687+
text: string,
688+
replacements: ReadonlyArray<readonly [string, string]>,
689+
): string {
690+
return replacements.reduce(
691+
(current, [from, to]) => (from.length === 0 ? current : current.replaceAll(from, to)),
692+
text,
693+
);
694+
}
695+
673696
function sanitizeReplayValue(
674697
value: unknown,
675698
replacements: ReadonlyArray<readonly [string, string]>,
676699
): unknown {
677700
if (typeof value === "string") {
678-
return replacements.reduce(
679-
(text, [from, to]) => (from.length === 0 ? text : text.replaceAll(from, to)),
680-
value,
681-
);
701+
return sanitizeReplayText(value, replacements);
682702
}
683703
if (Array.isArray(value)) {
684704
return value.map((entry) => sanitizeReplayValue(entry, replacements));
685705
}
686706
if (typeof value !== "object" || value === null) {
687707
return value;
688708
}
709+
// Keys too: grep results are keyed by workspace path.
689710
return Object.fromEntries(
690-
Object.entries(value).map(([key, entry]) => [key, sanitizeReplayValue(entry, replacements)]),
711+
Object.entries(value).map(([key, entry]) => [
712+
sanitizeReplayText(key, replacements),
713+
sanitizeReplayValue(entry, replacements),
714+
]),
691715
);
692716
}
693717

@@ -733,13 +757,14 @@ async function waitForRecordingSignal(signal: Promise<void>, description: string
733757
function recordingRuntimePolicy(input: {
734758
readonly cwd: string;
735759
readonly interactionMode: "default" | "plan";
760+
readonly override?: Pick<RuntimePolicyV2Override, "approvalPolicy" | "sandboxPolicy">;
736761
}): ProviderAdapterV2RuntimePolicy {
737762
return {
738763
runtimeMode: "full-access",
739764
interactionMode: input.interactionMode,
740765
cwd: input.cwd,
741-
approvalPolicy: "never",
742-
sandboxPolicy: {
766+
approvalPolicy: input.override?.approvalPolicy ?? "never",
767+
sandboxPolicy: input.override?.sandboxPolicy ?? {
743768
type: "dangerFullAccess",
744769
networkAccess: true,
745770
},
@@ -756,6 +781,11 @@ export async function recordCursorAgentSdkReplayTranscript(input: {
756781
/** Stable fixture cwd used to sanitize runtime-only workspace paths in recorded updates. */
757782
readonly transcriptCwd?: string;
758783
readonly interactionMode?: "default" | "plan";
784+
/** The replay fixture's policy override, so the recorded agent.open frame matches replay. */
785+
readonly runtimePolicyOverride?: Pick<
786+
RuntimePolicyV2Override,
787+
"approvalPolicy" | "sandboxPolicy"
788+
>;
759789
readonly apiKey?: string;
760790
readonly interruptAfterToolStart?: boolean;
761791
readonly interruptAfterRunStartPromptIndex?: number;
@@ -788,6 +818,7 @@ export async function recordCursorAgentSdkReplayTranscript(input: {
788818
const runtimePolicy = recordingRuntimePolicy({
789819
cwd: input.cwd,
790820
interactionMode,
821+
...(input.runtimePolicyOverride === undefined ? {} : { override: input.runtimePolicyOverride }),
791822
});
792823
const options = makeCursorAgentOptions({
793824
...(input.apiKey === undefined ? {} : { apiKey: input.apiKey }),
@@ -816,8 +847,11 @@ export async function recordCursorAgentSdkReplayTranscript(input: {
816847
},
817848
});
818849

850+
// Agents sometimes search the workspace's parent too; map it to /tmp so the
851+
// recording host's temp layout stays out of the fixture.
819852
const replacements: ReadonlyArray<readonly [string, string]> = [
820853
[input.cwd, input.transcriptCwd ?? `/tmp/cursor-replay-${input.scenario}`],
854+
[input.cwd.slice(0, input.cwd.lastIndexOf("/")), "/tmp"],
821855
];
822856

823857
try {
@@ -954,6 +988,11 @@ export async function recordCursorAgentSdkReplayTranscript(input: {
954988
toolStarted.promise,
955989
"Cursor SDK tool-call-started before interrupt",
956990
);
991+
// Cancelling synchronously from the SDK's tool-call-started callback
992+
// leaves an unhandled AbortError inside @cursor/sdk that kills the
993+
// process (reproduced on 1.0.22, 1.0.31, and 1.0.32). Cancelling from a
994+
// later timer was clean in the same probes; 10 ms is that deferral.
995+
await Effect.runPromise(Effect.sleep("10 millis"));
957996
entries.push({
958997
type: "expect_outbound",
959998
label: `run.cancel:${index + 1}`,

0 commit comments

Comments
 (0)