@cursor/july 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/agent-serve.js +0 -0
- package/dist/channels/github/instrument.d.ts +20 -0
- package/dist/channels/github/instrument.d.ts.map +1 -0
- package/dist/channels/slack/api.d.ts +2 -0
- package/dist/channels/slack/api.d.ts.map +1 -1
- package/dist/channels/slack/api.js +3 -0
- package/dist/channels/slack/bot-mentions.d.ts +106 -0
- package/dist/channels/slack/bot-mentions.d.ts.map +1 -0
- package/dist/channels/slack/bot-mentions.js +243 -0
- package/dist/channels/slack/dispatch.d.ts +6 -0
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/dispatch.js +24 -3
- package/dist/channels/slack/inbound.d.ts +10 -1
- package/dist/channels/slack/inbound.d.ts.map +1 -1
- package/dist/channels/slack/inbound.js +12 -4
- package/dist/channels/slack/index.d.ts +1 -0
- package/dist/channels/slack/index.d.ts.map +1 -1
- package/dist/channels/slack/index.js +1 -0
- package/dist/channels/slack/slack-channel.d.ts.map +1 -1
- package/dist/channels/slack/slack-channel.js +61 -22
- package/dist/channels/slack/types.d.ts +58 -0
- package/dist/channels/slack/types.d.ts.map +1 -1
- package/dist/docs/404.html +1 -1
- package/dist/docs/ab.html +2 -2
- package/dist/docs/assets/{app.T-5ImnM3.js → app.jDxLzWv4.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DoJHJjqF.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.OMGMWH6H.js → VPLocalSearchBox.Y6bDR1-a.js} +1 -1
- package/dist/docs/assets/chunks/{theme.DLg4yB4D.js → theme.CLazCWlJ.js} +2 -2
- package/dist/docs/building-with-agents.html +2 -2
- package/dist/docs/concepts.html +2 -2
- package/dist/docs/deployment.html +2 -2
- package/dist/docs/evals.html +2 -2
- package/dist/docs/example-agents/approval-buddy.html +2 -2
- package/dist/docs/example-agents/benny.html +2 -2
- package/dist/docs/example-agents/bugbot.html +2 -2
- package/dist/docs/example-agents/codebase-wiki.html +2 -2
- package/dist/docs/example-agents/codeowners-review.html +2 -2
- package/dist/docs/example-agents/concierge.html +2 -2
- package/dist/docs/example-agents/fsd.html +2 -2
- package/dist/docs/example-agents/index.html +2 -2
- package/dist/docs/example-agents/knowledge-base.html +2 -2
- package/dist/docs/example-agents/oncall.html +2 -2
- package/dist/docs/example-agents/security-reviewer.html +2 -2
- package/dist/docs/example-agents/slack-agent.html +2 -2
- package/dist/docs/example-agents/weather-agent.html +2 -2
- package/dist/docs/guides/agent-to-agent.html +2 -2
- package/dist/docs/guides/cloud-runtime.html +2 -2
- package/dist/docs/guides/github.html +2 -2
- package/dist/docs/guides/human-in-the-loop.html +2 -2
- package/dist/docs/guides/mcp-oauth.html +2 -2
- package/dist/docs/guides/slack.html +2 -2
- package/dist/docs/guides/webhooks.html +2 -2
- package/dist/docs/hillclimbing.html +2 -2
- package/dist/docs/index.html +2 -2
- package/dist/docs/quickstart.html +2 -2
- package/dist/docs/reference/agent-config.html +2 -2
- package/dist/docs/reference/channels.html +2 -2
- package/dist/docs/reference/cli.html +2 -2
- package/dist/docs/reference/connections.html +2 -2
- package/dist/docs/reference/hooks.html +2 -2
- package/dist/docs/reference/http-api.html +2 -2
- package/dist/docs/reference/instructions.html +2 -2
- package/dist/docs/reference/playground.html +2 -2
- package/dist/docs/reference/project-layout.html +2 -2
- package/dist/docs/reference/prompt.html +2 -2
- package/dist/docs/reference/schedules.html +2 -2
- package/dist/docs/reference/sessions.html +2 -2
- package/dist/docs/reference/skills.html +2 -2
- package/dist/docs/reference/subagents.html +2 -2
- package/dist/docs/reference/tools.html +2 -2
- package/dist/docs/scaffolding-agents.html +2 -2
- package/dist/docs/storage.html +2 -2
- package/dist/docs/troubleshooting.html +2 -2
- package/dist/internal/json-dir-store.d.ts +32 -0
- package/dist/internal/json-dir-store.d.ts.map +1 -0
- package/dist/internal/json-dir-store.js +100 -0
- package/dist/internal/resolved-connections.d.ts +1 -1
- package/dist/internal/resolved-connections.d.ts.map +1 -1
- package/dist/internal/resolved-connections.js +10 -0
- package/dist/internal/session-engine.d.ts +4 -1
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +13 -2
- package/dist/playground/assets/index-CjOQ4hN9.css +1 -0
- package/dist/playground/assets/index-dshZQJCp.js +85 -0
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -0
- package/package.json +24 -24
- package/src/bin/agent-serve.version.test.ts +62 -0
- package/src/channels/github/api.test.ts +64 -0
- package/src/channels/github/auth.test.ts +105 -0
- package/src/channels/github/cursor-account.test.ts +204 -0
- package/src/channels/github/forward.test.ts +457 -0
- package/src/channels/github/github.test.ts +937 -0
- package/src/channels/github/replay.test.ts +179 -0
- package/src/channels/slack/api.post-message.test.ts +148 -0
- package/src/channels/slack/api.ts +5 -0
- package/src/channels/slack/approvals.test.ts +328 -0
- package/src/channels/slack/block-actions.test.ts +452 -0
- package/src/channels/slack/bot-mentions.test.ts +217 -0
- package/src/channels/slack/bot-mentions.ts +315 -0
- package/src/channels/slack/channel-watch.test.ts +363 -0
- package/src/channels/slack/cursor-account.test.ts +253 -0
- package/src/channels/slack/defaults.final-post.test.ts +182 -0
- package/src/channels/slack/dispatch.test.ts +795 -0
- package/src/channels/slack/dispatch.ts +27 -1
- package/src/channels/slack/eval-directive.test.ts +273 -0
- package/src/channels/slack/inbound.ts +25 -4
- package/src/channels/slack/index.ts +1 -0
- package/src/channels/slack/message-body.test.ts +54 -0
- package/src/channels/slack/nudge-store.test.ts +143 -0
- package/src/channels/slack/slack-channel.ts +66 -8
- package/src/channels/slack/slack.test.ts +391 -0
- package/src/channels/slack/stop.test.ts +23 -0
- package/src/channels/slack/thread-context.test.ts +202 -0
- package/src/channels/slack/types.ts +60 -0
- package/src/evals/assertions.test.ts +580 -0
- package/src/evals/expect.test.ts +144 -0
- package/src/evals/judge.test.ts +181 -0
- package/src/evals/loaders.test.ts +132 -0
- package/src/evals/matchers.test.ts +95 -0
- package/src/evals/reporters.test.ts +303 -0
- package/src/evals/run-facts.test.ts +259 -0
- package/src/internal/ab-snapshot.test.ts +325 -0
- package/src/internal/approval-gate.test.ts +49 -0
- package/src/internal/approvals.integration.test.ts +383 -0
- package/src/internal/authored-loaders.test.ts +31 -0
- package/src/internal/builtin-tools/reminders.test.ts +201 -0
- package/src/internal/channel-route-schema.test.ts +294 -0
- package/src/internal/chat-attach.test.ts +262 -0
- package/src/internal/cli-deploy.test.ts +1991 -0
- package/src/internal/cli-mcp.test.ts +789 -0
- package/src/internal/cli-skills.test.ts +133 -0
- package/src/internal/cli-slack.test.ts +1647 -0
- package/src/internal/cloud-merge.test.ts +74 -0
- package/src/internal/cron.test.ts +22 -0
- package/src/internal/cursor/account-mcp.test.ts +807 -0
- package/src/internal/cursor/backend-client.test.ts +591 -0
- package/src/internal/cursor/credentials.test.ts +351 -0
- package/src/internal/cursor/github-credentials.test.ts +136 -0
- package/src/internal/cursor-account-mcp-auth.test.ts +310 -0
- package/src/internal/cursor-account.integration.test.ts +441 -0
- package/src/internal/cursor-event-relay.test.ts +746 -0
- package/src/internal/cursor-github-credentials.integration.test.ts +271 -0
- package/src/internal/cursor-slack-relay.test.ts +525 -0
- package/src/internal/deploy-source.test.ts +111 -0
- package/src/internal/discovery.builtin-tools.test.ts +94 -0
- package/src/internal/discovery.concurrency.test.ts +60 -0
- package/src/internal/discovery.cursor-account.test.ts +133 -0
- package/src/internal/discovery.cwd.test.ts +83 -0
- package/src/internal/discovery.hosting.test.ts +80 -0
- package/src/internal/discovery.identity.test.ts +44 -0
- package/src/internal/docs-site.test.ts +66 -0
- package/src/internal/duration.test.ts +29 -0
- package/src/internal/eval-judge-model.test.ts +187 -0
- package/src/internal/eval-run-store.cancel.test.ts +142 -0
- package/src/internal/eval-run-store.storage.test.ts +211 -0
- package/src/internal/eval-runner.http.test.ts +403 -0
- package/src/internal/eval-runner.run.test.ts +928 -0
- package/src/internal/evals-client.test.ts +307 -0
- package/src/internal/event-mapper.test.ts +243 -0
- package/src/internal/github-fanout.test.ts +213 -0
- package/src/internal/handleAgentServeTrigger.test.ts +179 -0
- package/src/internal/host-kv.test.ts +82 -0
- package/src/internal/host-platforms.test.ts +126 -0
- package/src/internal/http-channel.test.ts +402 -0
- package/src/internal/init-project.test.ts +269 -0
- package/src/internal/install-cursor-skills.test.ts +262 -0
- package/src/internal/local-env.test.ts +100 -0
- package/src/internal/log-ring.test.ts +31 -0
- package/src/internal/logs-client.test.ts +350 -0
- package/src/internal/mcp-endpoint.test.ts +436 -0
- package/src/internal/mcp-host.test.ts +298 -0
- package/src/internal/mcp-oauth.test.ts +148 -0
- package/src/internal/net.test.ts +17 -0
- package/src/internal/peer-connections.test.ts +128 -0
- package/src/internal/peer-mcp.integration.test.ts +289 -0
- package/src/internal/playground/toolchain.test.ts +53 -0
- package/src/internal/playground-cli.test.ts +187 -0
- package/src/internal/playground-proxy.test.ts +376 -0
- package/src/internal/prompt-context.integration.test.ts +232 -0
- package/src/internal/prompt-context.test.ts +127 -0
- package/src/internal/reminder-runner.test.ts +390 -0
- package/src/internal/reminder-store.test.ts +53 -0
- package/src/internal/request-headers.test.ts +27 -0
- package/src/internal/resolve-prod-target.test.ts +787 -0
- package/src/internal/resolved-connections.test.ts +295 -0
- package/src/internal/resolved-connections.ts +18 -1
- package/src/internal/router.test.ts +57 -0
- package/src/internal/sdk-runner.test.ts +290 -0
- package/src/internal/session-engine.coalesce.test.ts +169 -0
- package/src/internal/session-engine.concurrency.test.ts +250 -0
- package/src/internal/session-engine.host-oauth-mcp.test.ts +110 -0
- package/src/internal/session-engine.interrupt.test.ts +577 -0
- package/src/internal/session-engine.storage.test.ts +547 -0
- package/src/internal/session-engine.ts +15 -1
- package/src/internal/session-urls.test.ts +28 -0
- package/src/internal/sessions-client.test.ts +518 -0
- package/src/internal/storage-coordinator.test.ts +517 -0
- package/src/internal/tool-call.test.ts +458 -0
- package/src/internal/tool-result.test.ts +52 -0
- package/src/internal/trajectory.approvals.test.ts +83 -0
- package/src/internal/trajectory.subagents.test.ts +198 -0
- package/src/internal/turn-governor.test.ts +137 -0
- package/src/internal/update-check.test.ts +485 -0
- package/src/internal/workspace.test.ts +81 -0
- package/src/storage-backends/cursor-hosted.test.ts +121 -0
- package/src/types.ts +12 -0
- package/dist/docs/assets/chunks/@localSearchIndexroot.CvejISXF.js +0 -1
- package/dist/playground/assets/index-CidizGZv.css +0 -1
- package/dist/playground/assets/index-CuiAKZaP.js +0 -85
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type { SessionEvent } from "../types.js";
|
|
3
|
+
import { buildTrajectory, formatTrajectoryText } from "./trajectory.js";
|
|
4
|
+
|
|
5
|
+
function ev(
|
|
6
|
+
partial: Omit<SessionEvent, "index" | "sessionId" | "at"> & {
|
|
7
|
+
index?: number;
|
|
8
|
+
}
|
|
9
|
+
): SessionEvent {
|
|
10
|
+
return {
|
|
11
|
+
index: partial.index ?? 0,
|
|
12
|
+
sessionId: "sess_1",
|
|
13
|
+
at: "2026-01-01T00:00:00.000Z",
|
|
14
|
+
...partial,
|
|
15
|
+
} as SessionEvent;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("buildTrajectory subagent progress", () => {
|
|
19
|
+
it("keeps bare top-level task in toolCalls for calledTool evals", () => {
|
|
20
|
+
const traj = buildTrajectory([
|
|
21
|
+
ev({ type: "session.started", data: { channelId: "http" } }),
|
|
22
|
+
ev({
|
|
23
|
+
type: "message.received",
|
|
24
|
+
turnId: "turn_1",
|
|
25
|
+
data: { text: "review this" },
|
|
26
|
+
}),
|
|
27
|
+
ev({
|
|
28
|
+
type: "actions.requested",
|
|
29
|
+
turnId: "turn_1",
|
|
30
|
+
data: {
|
|
31
|
+
calls: [
|
|
32
|
+
{
|
|
33
|
+
callId: "task-1",
|
|
34
|
+
toolName: "task",
|
|
35
|
+
args: { description: "deep review" },
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
ev({
|
|
41
|
+
type: "subagent.called",
|
|
42
|
+
turnId: "turn_1",
|
|
43
|
+
data: {
|
|
44
|
+
callId: "task-1",
|
|
45
|
+
name: "reviewer",
|
|
46
|
+
description: "deep review",
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
ev({
|
|
50
|
+
type: "actions.requested",
|
|
51
|
+
turnId: "turn_1",
|
|
52
|
+
data: {
|
|
53
|
+
parentCallId: "task-1",
|
|
54
|
+
calls: [
|
|
55
|
+
{
|
|
56
|
+
callId: "shell-1",
|
|
57
|
+
toolName: "shell",
|
|
58
|
+
args: { command: "ls" },
|
|
59
|
+
parentCallId: "task-1",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
ev({
|
|
65
|
+
type: "action.result",
|
|
66
|
+
turnId: "turn_1",
|
|
67
|
+
data: {
|
|
68
|
+
callId: "shell-1",
|
|
69
|
+
toolName: "shell",
|
|
70
|
+
output: "ok",
|
|
71
|
+
isError: false,
|
|
72
|
+
parentCallId: "task-1",
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
ev({
|
|
76
|
+
type: "subagent.completed",
|
|
77
|
+
turnId: "turn_1",
|
|
78
|
+
data: { callId: "task-1", name: "reviewer" },
|
|
79
|
+
}),
|
|
80
|
+
ev({
|
|
81
|
+
type: "action.result",
|
|
82
|
+
turnId: "turn_1",
|
|
83
|
+
data: {
|
|
84
|
+
callId: "task-1",
|
|
85
|
+
toolName: "task",
|
|
86
|
+
output: { done: true },
|
|
87
|
+
isError: false,
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
ev({
|
|
91
|
+
type: "message.completed",
|
|
92
|
+
turnId: "turn_1",
|
|
93
|
+
data: { text: "Parent reply.", finishReason: "stop" },
|
|
94
|
+
}),
|
|
95
|
+
ev({ type: "turn.completed", turnId: "turn_1", data: {} }),
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
const turn = traj.turns[0]!;
|
|
99
|
+
expect(turn.toolCalls.map((c) => c.toolName)).toContain("task");
|
|
100
|
+
expect(turn.toolCalls.find((c) => c.toolName === "task")).toMatchObject({
|
|
101
|
+
callId: "task-1",
|
|
102
|
+
output: { done: true },
|
|
103
|
+
});
|
|
104
|
+
expect(turn.subagents).toHaveLength(1);
|
|
105
|
+
expect(turn.subagents[0]?.toolCalls.map((c) => c.toolName)).toEqual([
|
|
106
|
+
"shell",
|
|
107
|
+
]);
|
|
108
|
+
expect(turn.assistantText).toBe("Parent reply.");
|
|
109
|
+
expect(traj.finalText).toBe("Parent reply.");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("does not let nested message.completed overwrite parent assistantText", () => {
|
|
113
|
+
const traj = buildTrajectory([
|
|
114
|
+
ev({
|
|
115
|
+
type: "message.received",
|
|
116
|
+
turnId: "turn_1",
|
|
117
|
+
data: { text: "hi" },
|
|
118
|
+
}),
|
|
119
|
+
ev({
|
|
120
|
+
type: "subagent.called",
|
|
121
|
+
turnId: "turn_1",
|
|
122
|
+
data: { callId: "task-1", name: "worker" },
|
|
123
|
+
}),
|
|
124
|
+
ev({
|
|
125
|
+
type: "message.completed",
|
|
126
|
+
turnId: "turn_1",
|
|
127
|
+
data: {
|
|
128
|
+
text: "Nested says hi.",
|
|
129
|
+
finishReason: "stop",
|
|
130
|
+
parentCallId: "task-1",
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
133
|
+
ev({
|
|
134
|
+
type: "message.completed",
|
|
135
|
+
turnId: "turn_1",
|
|
136
|
+
data: { text: "Parent final.", finishReason: "stop" },
|
|
137
|
+
}),
|
|
138
|
+
ev({ type: "turn.completed", turnId: "turn_1", data: {} }),
|
|
139
|
+
]);
|
|
140
|
+
|
|
141
|
+
expect(traj.turns[0]?.assistantText).toBe("Parent final.");
|
|
142
|
+
expect(traj.finalText).toBe("Parent final.");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("does not let nested reasoning.appended overwrite parent reasoningText", () => {
|
|
146
|
+
const traj = buildTrajectory([
|
|
147
|
+
ev({
|
|
148
|
+
type: "reasoning.appended",
|
|
149
|
+
turnId: "turn_1",
|
|
150
|
+
data: {
|
|
151
|
+
delta: "parent think",
|
|
152
|
+
text: "parent think",
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
ev({
|
|
156
|
+
type: "reasoning.appended",
|
|
157
|
+
turnId: "turn_1",
|
|
158
|
+
data: {
|
|
159
|
+
delta: "nested think",
|
|
160
|
+
text: "nested think",
|
|
161
|
+
parentCallId: "task-1",
|
|
162
|
+
},
|
|
163
|
+
}),
|
|
164
|
+
ev({ type: "turn.completed", turnId: "turn_1", data: {} }),
|
|
165
|
+
]);
|
|
166
|
+
|
|
167
|
+
expect(traj.turns[0]?.reasoningText).toBe("parent think");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("formatTrajectoryText includes nested subagent tools", () => {
|
|
171
|
+
const traj = buildTrajectory([
|
|
172
|
+
ev({
|
|
173
|
+
type: "subagent.called",
|
|
174
|
+
turnId: "turn_1",
|
|
175
|
+
data: { callId: "task-1", name: "worker", description: "do work" },
|
|
176
|
+
}),
|
|
177
|
+
ev({
|
|
178
|
+
type: "actions.requested",
|
|
179
|
+
turnId: "turn_1",
|
|
180
|
+
data: {
|
|
181
|
+
calls: [
|
|
182
|
+
{
|
|
183
|
+
callId: "read-1",
|
|
184
|
+
toolName: "read",
|
|
185
|
+
args: { path: "a.ts" },
|
|
186
|
+
parentCallId: "task-1",
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
}),
|
|
191
|
+
ev({ type: "turn.completed", turnId: "turn_1", data: {} }),
|
|
192
|
+
]);
|
|
193
|
+
|
|
194
|
+
const text = formatTrajectoryText(traj);
|
|
195
|
+
expect(text).toContain("task worker");
|
|
196
|
+
expect(text).toContain("read");
|
|
197
|
+
});
|
|
198
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { TurnGovernor, type TurnPermit } from "./turn-governor.js";
|
|
3
|
+
|
|
4
|
+
describe("TurnGovernor", () => {
|
|
5
|
+
it("grants immediately with no limit configured", async () => {
|
|
6
|
+
const governor = new TurnGovernor(undefined);
|
|
7
|
+
expect(governor.limited).toBe(false);
|
|
8
|
+
const permit = await governor.acquire({ sessionId: "s1" });
|
|
9
|
+
expect(permit).toBeDefined();
|
|
10
|
+
expect(governor.queuedCount).toBe(0);
|
|
11
|
+
permit?.release();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("queues FIFO beyond the limit and wakes waiters in order", async () => {
|
|
15
|
+
const governor = new TurnGovernor({ maxRunningTurns: 2 });
|
|
16
|
+
const first = await governor.acquire({ sessionId: "s1" });
|
|
17
|
+
const second = await governor.acquire({ sessionId: "s2" });
|
|
18
|
+
expect(governor.runningCount).toBe(2);
|
|
19
|
+
|
|
20
|
+
const positions: Array<{ sessionId: string; position: number }> = [];
|
|
21
|
+
const grants: string[] = [];
|
|
22
|
+
const third = governor
|
|
23
|
+
.acquire({
|
|
24
|
+
sessionId: "s3",
|
|
25
|
+
onQueued: (position) => positions.push({ sessionId: "s3", position }),
|
|
26
|
+
})
|
|
27
|
+
.then((permit) => {
|
|
28
|
+
grants.push("s3");
|
|
29
|
+
return permit;
|
|
30
|
+
});
|
|
31
|
+
const fourth = governor
|
|
32
|
+
.acquire({
|
|
33
|
+
sessionId: "s4",
|
|
34
|
+
onQueued: (position) => positions.push({ sessionId: "s4", position }),
|
|
35
|
+
})
|
|
36
|
+
.then((permit) => {
|
|
37
|
+
grants.push("s4");
|
|
38
|
+
return permit;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
expect(positions).toEqual([
|
|
42
|
+
{ sessionId: "s3", position: 1 },
|
|
43
|
+
{ sessionId: "s4", position: 2 },
|
|
44
|
+
]);
|
|
45
|
+
expect(governor.queuedCount).toBe(2);
|
|
46
|
+
expect(governor.isQueued("s3")).toBe(true);
|
|
47
|
+
expect(governor.isQueued("s4")).toBe(true);
|
|
48
|
+
|
|
49
|
+
first?.release();
|
|
50
|
+
const thirdPermit = await third;
|
|
51
|
+
expect(grants).toEqual(["s3"]);
|
|
52
|
+
expect(governor.isQueued("s3")).toBe(false);
|
|
53
|
+
expect(governor.runningCount).toBe(2);
|
|
54
|
+
|
|
55
|
+
second?.release();
|
|
56
|
+
const fourthPermit = await fourth;
|
|
57
|
+
expect(grants).toEqual(["s3", "s4"]);
|
|
58
|
+
expect(governor.queuedCount).toBe(0);
|
|
59
|
+
|
|
60
|
+
thirdPermit?.release();
|
|
61
|
+
fourthPermit?.release();
|
|
62
|
+
expect(governor.runningCount).toBe(0);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("resolves undefined when the signal aborts while waiting", async () => {
|
|
66
|
+
const governor = new TurnGovernor({ maxRunningTurns: 1 });
|
|
67
|
+
const holder = await governor.acquire({ sessionId: "s1" });
|
|
68
|
+
|
|
69
|
+
const abort = new AbortController();
|
|
70
|
+
const waiting = governor.acquire({
|
|
71
|
+
sessionId: "s2",
|
|
72
|
+
signal: abort.signal,
|
|
73
|
+
});
|
|
74
|
+
expect(governor.isQueued("s2")).toBe(true);
|
|
75
|
+
|
|
76
|
+
abort.abort();
|
|
77
|
+
expect(await waiting).toBeUndefined();
|
|
78
|
+
expect(governor.isQueued("s2")).toBe(false);
|
|
79
|
+
expect(governor.queuedCount).toBe(0);
|
|
80
|
+
|
|
81
|
+
// The abandoned wait must not consume the slot when it frees.
|
|
82
|
+
holder?.release();
|
|
83
|
+
const next = await governor.acquire({ sessionId: "s3" });
|
|
84
|
+
expect(next).toBeDefined();
|
|
85
|
+
next?.release();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("resolves undefined without enqueuing when already aborted", async () => {
|
|
89
|
+
const governor = new TurnGovernor({ maxRunningTurns: 1 });
|
|
90
|
+
const holder = await governor.acquire({ sessionId: "s1" });
|
|
91
|
+
const abort = new AbortController();
|
|
92
|
+
abort.abort();
|
|
93
|
+
let queued = false;
|
|
94
|
+
const permit = await governor.acquire({
|
|
95
|
+
sessionId: "s2",
|
|
96
|
+
signal: abort.signal,
|
|
97
|
+
onQueued: () => {
|
|
98
|
+
queued = true;
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
expect(permit).toBeUndefined();
|
|
102
|
+
expect(queued).toBe(false);
|
|
103
|
+
holder?.release();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("release is idempotent", async () => {
|
|
107
|
+
const governor = new TurnGovernor({ maxRunningTurns: 1 });
|
|
108
|
+
const first = (await governor.acquire({ sessionId: "s1" })) as TurnPermit;
|
|
109
|
+
first.release();
|
|
110
|
+
first.release();
|
|
111
|
+
expect(governor.runningCount).toBe(0);
|
|
112
|
+
const second = await governor.acquire({ sessionId: "s2" });
|
|
113
|
+
expect(second).toBeDefined();
|
|
114
|
+
expect(governor.runningCount).toBe(1);
|
|
115
|
+
second?.release();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("keeps FIFO order over grants freed by aborted waiters", async () => {
|
|
119
|
+
const governor = new TurnGovernor({ maxRunningTurns: 1 });
|
|
120
|
+
const holder = await governor.acquire({ sessionId: "s1" });
|
|
121
|
+
const abortSecond = new AbortController();
|
|
122
|
+
const second = governor.acquire({
|
|
123
|
+
sessionId: "s2",
|
|
124
|
+
signal: abortSecond.signal,
|
|
125
|
+
});
|
|
126
|
+
const third = governor.acquire({ sessionId: "s3" });
|
|
127
|
+
|
|
128
|
+
abortSecond.abort();
|
|
129
|
+
expect(await second).toBeUndefined();
|
|
130
|
+
|
|
131
|
+
holder?.release();
|
|
132
|
+
const thirdPermit = await third;
|
|
133
|
+
expect(thirdPermit).toBeDefined();
|
|
134
|
+
expect(governor.queuedCount).toBe(0);
|
|
135
|
+
thirdPermit?.release();
|
|
136
|
+
});
|
|
137
|
+
});
|