|
22 | 22 | * `tasks/result` and `tasks/list`, which the extension does not define. |
23 | 23 | */ |
24 | 24 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
25 | | -import { clearTasks, TASKS_EXTENSION } from "../server/tasks.js"; |
| 25 | +import { clearTasks, MAX_TASKS, TASKS_EXTENSION } from "../server/tasks.js"; |
26 | 26 | import { STAGE_DURATION, STAGES } from "../tools/simulate-research-query.js"; |
27 | 27 | import { connectRaw as rawClient, type RawSession } from "./harness.js"; |
28 | 28 |
|
@@ -148,6 +148,26 @@ describe("the extension", () => { |
148 | 148 | }, |
149 | 149 | ); |
150 | 150 |
|
| 151 | + it("keeps at most MAX_TASKS, dropping the oldest", async () => { |
| 152 | + peer = await rawClient(TASKS); |
| 153 | + const first = await peer.call("simulate-research-query", { topic: "t" }); |
| 154 | + for (let i = 1; i < MAX_TASKS; i++) { |
| 155 | + await peer.call("simulate-research-query", { topic: "t" }); |
| 156 | + } |
| 157 | + expect((await peer.get(first.taskId as string)).status).toBe("working"); |
| 158 | + await peer.call("simulate-research-query", { topic: "t" }); |
| 159 | + const response = await peer.request("tasks/get", { taskId: first.taskId }); |
| 160 | + expect(response.error).toMatchObject({ code: -32602 }); |
| 161 | + }); |
| 162 | + |
| 163 | + it("refuses a topic longer than it will keep", async () => { |
| 164 | + peer = await rawClient(TASKS); |
| 165 | + const result = await peer.call("simulate-research-query", { |
| 166 | + topic: "x".repeat(1001), |
| 167 | + }); |
| 168 | + expect(result.isError).toBe(true); |
| 169 | + }); |
| 170 | + |
151 | 171 | it("drops a task once its TTL has passed", async () => { |
152 | 172 | peer = await rawClient(TASKS); |
153 | 173 | const created = await peer.call("simulate-research-query", { topic: "t" }); |
|
0 commit comments