Skip to content

Commit dd882d9

Browse files
test(cursor): derive the active-run conflict from the stored runs
AI-assisted; verified with the tests and tools listed above.
1 parent 0840af4 commit dd882d9

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const cursorSdkMock = vi.hoisted(() => {
1616
const closeExecutionOrder: Array<string> = [];
1717
const runOperations: Array<string> = [];
1818
let agentCloseFailure: unknown;
19-
let staleRunActive = false;
2019
// The local store lists runs oldest first, like the real SDK.
2120
let storedRuns: Array<{ readonly id: string; readonly status: string }> = [];
2221
const runWait = vi.fn(async () => ({
@@ -40,7 +39,7 @@ const cursorSdkMock = vi.hoisted(() => {
4039
options: { readonly onDelta?: (input: { readonly update: unknown }) => Promise<void> },
4140
) => {
4241
runOperations.push("run.start");
43-
if (staleRunActive) {
42+
if (storedRuns.some((run) => run.status === "running")) {
4443
throw new Error("Agent agent-cursor-agent-sdk-test already has active run");
4544
}
4645
await options.onDelta?.({
@@ -69,21 +68,19 @@ const cursorSdkMock = vi.hoisted(() => {
6968
}));
7069
const listRuns = vi.fn(async (_agentId: string, options?: ListRunsOptions) => {
7170
runOperations.push("agent.listRuns");
72-
const runs = staleRunActive ? storedRuns : [];
7371
// Mirrors the SDK's opaque cursor pagination with its default page size of 50.
7472
const offset = options?.cursor === undefined ? 0 : Number(options.cursor);
7573
const end = offset + (options?.limit ?? 50);
7674
return {
77-
items: runs.slice(offset, end),
78-
...(end < runs.length ? { nextCursor: String(end) } : {}),
75+
items: storedRuns.slice(offset, end),
76+
...(end < storedRuns.length ? { nextCursor: String(end) } : {}),
7977
};
8078
});
8179
const cancelRun = vi.fn(async (runId: string) => {
8280
runOperations.push("agent.cancelRun");
8381
storedRuns = storedRuns.map((run) =>
8482
run.id === runId ? { ...run, status: "cancelled" } : run,
8583
);
86-
staleRunActive = storedRuns.some((run) => run.status === "running");
8784
});
8885

8986
return {
@@ -100,13 +97,8 @@ const cursorSdkMock = vi.hoisted(() => {
10097
setAgentCloseFailure: (failure: unknown) => {
10198
agentCloseFailure = failure;
10299
},
103-
setStaleRunActive: (active: boolean) => {
104-
staleRunActive = active;
105-
storedRuns = active ? [{ id: "run-stale", status: "running" }] : [];
106-
},
107100
setStoredRuns: (runs: Array<{ readonly id: string; readonly status: string }>) => {
108101
storedRuns = runs;
109-
staleRunActive = runs.some((run) => run.status === "running");
110102
},
111103
};
112104
});
@@ -192,7 +184,7 @@ describe("CursorAgentSdkRunner", () => {
192184
cursorSdkMock.runOperations.length = 0;
193185
cursorSdkMock.listRuns.mockClear();
194186
cursorSdkMock.cancelRun.mockClear();
195-
cursorSdkMock.setStaleRunActive(true);
187+
cursorSdkMock.setStoredRuns([{ id: "run-stale", status: "running" }]);
196188

197189
const runner = yield* CursorAgentSdk.CursorAgentSdkRunner;
198190
const session = yield* runner.open({

0 commit comments

Comments
 (0)