@cursor/july 0.1.19 → 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/AGENTS.md +10 -0
- 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.CrsWMchO.js → app.jDxLzWv4.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DoJHJjqF.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.D1JqzSh8.js → VPLocalSearchBox.Y6bDR1-a.js} +1 -1
- package/dist/docs/assets/chunks/{theme.DaBvZYwl.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-C2SU2xV5.js → index-dshZQJCp.js} +46 -46
- 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 +25 -25
- package/skills/create-agent/SKILL.md +36 -4
- package/skills/evals/SKILL.md +3 -0
- package/skills/framework-map/SKILL.md +14 -0
- package/skills/github/SKILL.md +6 -1
- package/skills/hillclimb/SKILL.md +28 -7
- 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.BnHRjfoe.js +0 -1
- package/dist/playground/assets/index-CidizGZv.css +0 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
const execFileMock = vi.hoisted(() => vi.fn());
|
|
4
|
+
const createAppAuthMock = vi.hoisted(() => vi.fn());
|
|
5
|
+
|
|
6
|
+
vi.mock("node:child_process", () => ({
|
|
7
|
+
execFile: execFileMock,
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
vi.mock("@octokit/auth-app", () => ({
|
|
11
|
+
createAppAuth: createAppAuthMock,
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
import * as auth from "./auth.js";
|
|
15
|
+
|
|
16
|
+
function clearAuthEnv(): void {
|
|
17
|
+
delete process.env.GITHUB_TOKEN;
|
|
18
|
+
delete process.env.GH_TOKEN;
|
|
19
|
+
delete process.env.GITHUB_APP_ID;
|
|
20
|
+
delete process.env.GITHUB_APP_PRIVATE_KEY;
|
|
21
|
+
delete process.env.GITHUB_APP_INSTALLATION_ID;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe("resolveGitHubAccessToken", () => {
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
auth.clearGitHubAuthCaches();
|
|
27
|
+
execFileMock.mockReset();
|
|
28
|
+
createAppAuthMock.mockReset();
|
|
29
|
+
clearAuthEnv();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
auth.clearGitHubAuthCaches();
|
|
34
|
+
execFileMock.mockReset();
|
|
35
|
+
createAppAuthMock.mockReset();
|
|
36
|
+
clearAuthEnv();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("prefers App installation tokens over ambient PAT when App creds are set", async () => {
|
|
40
|
+
process.env.GITHUB_TOKEN = "pat-should-not-win";
|
|
41
|
+
process.env.GITHUB_APP_ID = "123";
|
|
42
|
+
process.env.GITHUB_APP_PRIVATE_KEY =
|
|
43
|
+
"-----BEGIN PRIVATE KEY-----\nabc\n-----END PRIVATE KEY-----";
|
|
44
|
+
createAppAuthMock.mockReturnValue(
|
|
45
|
+
async () => ({ token: "ghs_installation" }) as never
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
await expect(
|
|
49
|
+
auth.resolveGitHubAccessToken({ installationId: 42 })
|
|
50
|
+
).resolves.toBe("ghs_installation");
|
|
51
|
+
expect(createAppAuthMock).toHaveBeenCalledOnce();
|
|
52
|
+
expect(execFileMock).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("falls back to PAT when App credentials are unset (local testing)", async () => {
|
|
56
|
+
process.env.GITHUB_TOKEN = "local-pat";
|
|
57
|
+
|
|
58
|
+
await expect(
|
|
59
|
+
auth.resolveGitHubAccessToken({ installationId: 42 })
|
|
60
|
+
).resolves.toBe("local-pat");
|
|
61
|
+
expect(createAppAuthMock).not.toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("uses GITHUB_APP_INSTALLATION_ID for host-scoped App auth", async () => {
|
|
65
|
+
process.env.GITHUB_APP_ID = "123";
|
|
66
|
+
process.env.GITHUB_APP_PRIVATE_KEY =
|
|
67
|
+
"-----BEGIN PRIVATE KEY-----\nabc\n-----END PRIVATE KEY-----";
|
|
68
|
+
process.env.GITHUB_APP_INSTALLATION_ID = "99";
|
|
69
|
+
createAppAuthMock.mockReturnValue(
|
|
70
|
+
async () => ({ token: "ghs_host" }) as never
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
await expect(auth.resolveGitHubAccessToken({})).resolves.toBe("ghs_host");
|
|
74
|
+
expect(createAppAuthMock).toHaveBeenCalledOnce();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("ensureGhCliTokenEnv", () => {
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
auth.clearGitHubAuthCaches();
|
|
81
|
+
execFileMock.mockReset();
|
|
82
|
+
createAppAuthMock.mockReset();
|
|
83
|
+
clearAuthEnv();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
afterEach(() => {
|
|
87
|
+
auth.clearGitHubAuthCaches();
|
|
88
|
+
execFileMock.mockReset();
|
|
89
|
+
createAppAuthMock.mockReset();
|
|
90
|
+
clearAuthEnv();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("exports an App installation token as GH_TOKEN for gh CLI", async () => {
|
|
94
|
+
process.env.GITHUB_APP_ID = "123";
|
|
95
|
+
process.env.GITHUB_APP_PRIVATE_KEY =
|
|
96
|
+
"-----BEGIN PRIVATE KEY-----\nabc\n-----END PRIVATE KEY-----";
|
|
97
|
+
process.env.GITHUB_APP_INSTALLATION_ID = "99";
|
|
98
|
+
createAppAuthMock.mockReturnValue(
|
|
99
|
+
async () => ({ token: "ghs_for_gh" }) as never
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
await expect(auth.ensureGhCliTokenEnv()).resolves.toBe(true);
|
|
103
|
+
expect(process.env.GH_TOKEN).toBe("ghs_for_gh");
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { createGitHubOctokit } from "./api.js";
|
|
3
|
+
import { resolveCredentialValue } from "./auth.js";
|
|
4
|
+
import {
|
|
5
|
+
getGithubCursorAccountRuntime,
|
|
6
|
+
resolveCursorGithubPermissions,
|
|
7
|
+
resolveCursorGithubProxyUrl,
|
|
8
|
+
} from "./cursor-account.js";
|
|
9
|
+
import { getGitHubChannelOptions, githubChannel } from "./github-channel.js";
|
|
10
|
+
|
|
11
|
+
describe("githubChannel({ cursorAccount })", () => {
|
|
12
|
+
it("binds outbound API auth without rewriting authored cursorAccount options", async () => {
|
|
13
|
+
const definition = githubChannel({
|
|
14
|
+
cursorAccount: { repos: ["Acme/Widgets"], permissions: "read" },
|
|
15
|
+
});
|
|
16
|
+
const runtime = getGithubCursorAccountRuntime(definition);
|
|
17
|
+
|
|
18
|
+
expect(runtime?.options.cursorAccount).toEqual({
|
|
19
|
+
repos: ["Acme/Widgets"],
|
|
20
|
+
permissions: "read",
|
|
21
|
+
});
|
|
22
|
+
expect(runtime?.scope).toEqual({
|
|
23
|
+
owner: "acme",
|
|
24
|
+
repos: ["acme/widgets"],
|
|
25
|
+
permissions: "read",
|
|
26
|
+
});
|
|
27
|
+
expect(() => runtime?.credentials.getToken()).toThrow(/has not been bound/);
|
|
28
|
+
runtime?.credentials.bind(async () => "ghs_cursor_account");
|
|
29
|
+
await expect(
|
|
30
|
+
resolveCredentialValue(
|
|
31
|
+
getGitHubChannelOptions(definition)?.credentials?.token
|
|
32
|
+
)
|
|
33
|
+
).resolves.toBe("ghs_cursor_account");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("defaults permissions to pr-write on the private scope", () => {
|
|
37
|
+
const definition = githubChannel({
|
|
38
|
+
cursorAccount: { repos: ["acme/widgets"] },
|
|
39
|
+
});
|
|
40
|
+
expect(getGithubCursorAccountRuntime(definition)?.scope).toEqual({
|
|
41
|
+
owner: "acme",
|
|
42
|
+
repos: ["acme/widgets"],
|
|
43
|
+
permissions: "pr-write",
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("allows a webhook secret but rejects separate outbound credentials", () => {
|
|
48
|
+
expect(() =>
|
|
49
|
+
githubChannel({
|
|
50
|
+
cursorAccount: true,
|
|
51
|
+
credentials: { webhookSecret: "signing-secret" },
|
|
52
|
+
})
|
|
53
|
+
).not.toThrow();
|
|
54
|
+
expect(() =>
|
|
55
|
+
githubChannel({
|
|
56
|
+
cursorAccount: true,
|
|
57
|
+
credentials: { token: "ghp_dedicated" },
|
|
58
|
+
})
|
|
59
|
+
).toThrow(/cannot be combined/);
|
|
60
|
+
expect(() =>
|
|
61
|
+
githubChannel({
|
|
62
|
+
cursorAccount: true,
|
|
63
|
+
credentials: { appId: 1, privateKey: "pem" },
|
|
64
|
+
})
|
|
65
|
+
).toThrow(/cannot be combined/);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("rejects an empty inline repository scope", () => {
|
|
69
|
+
expect(() => githubChannel({ cursorAccount: { repos: [] } })).toThrow(
|
|
70
|
+
/require at least one repository/
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it.each([
|
|
75
|
+
[["acme/widgets", "other/tools"], /must share one owner/],
|
|
76
|
+
[["https://github.com/acme/widgets"], /expected owner\/repo/],
|
|
77
|
+
[
|
|
78
|
+
Array.from({ length: 21 }, (_, index) => `acme/repo-${index}`),
|
|
79
|
+
/at most 20 repositories/,
|
|
80
|
+
],
|
|
81
|
+
])("rejects an unsupported repository scope", (repos, error) => {
|
|
82
|
+
expect(() => githubChannel({ cursorAccount: { repos } })).toThrow(error);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("treats cursorAccount false as disabled", () => {
|
|
86
|
+
expect(
|
|
87
|
+
getGithubCursorAccountRuntime(githubChannel({ cursorAccount: false }))
|
|
88
|
+
).toBeUndefined();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("accepts contents-write permissions on the private scope", () => {
|
|
92
|
+
const definition = githubChannel({
|
|
93
|
+
cursorAccount: {
|
|
94
|
+
repos: ["acme/widgets"],
|
|
95
|
+
permissions: "contents-write",
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
expect(getGithubCursorAccountRuntime(definition)?.scope?.permissions).toBe(
|
|
99
|
+
"contents-write"
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("resolveCursorGithubPermissions", () => {
|
|
105
|
+
it("escalates to the most privileged requested tier", () => {
|
|
106
|
+
expect(resolveCursorGithubPermissions(["read", "pr-write"])).toBe(
|
|
107
|
+
"pr-write"
|
|
108
|
+
);
|
|
109
|
+
expect(
|
|
110
|
+
resolveCursorGithubPermissions(["read", "contents-write", "pr-write"])
|
|
111
|
+
).toBe("contents-write");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("cursor-account GitHub proxy mode", () => {
|
|
116
|
+
afterEach(() => {
|
|
117
|
+
delete process.env.AGENT_SERVE_GITHUB_PROXY_URL;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
function captureFetch(): {
|
|
121
|
+
fetchImpl: typeof fetch;
|
|
122
|
+
requests: { url: string; headers: Headers }[];
|
|
123
|
+
} {
|
|
124
|
+
const requests: { url: string; headers: Headers }[] = [];
|
|
125
|
+
const fetchImpl: typeof fetch = async (input, init) => {
|
|
126
|
+
requests.push({
|
|
127
|
+
url: input instanceof Request ? input.url : String(input),
|
|
128
|
+
headers:
|
|
129
|
+
input instanceof Request ? input.headers : new Headers(init?.headers),
|
|
130
|
+
});
|
|
131
|
+
return Response.json({ id: 1 });
|
|
132
|
+
};
|
|
133
|
+
return { fetchImpl, requests };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
it("resolves the proxy URL from the backend base URL or env override", () => {
|
|
137
|
+
expect(resolveCursorGithubProxyUrl("https://api.cursor.com")).toBe(
|
|
138
|
+
"https://api.cursor.com/v0/github-proxy"
|
|
139
|
+
);
|
|
140
|
+
process.env.AGENT_SERVE_GITHUB_PROXY_URL =
|
|
141
|
+
"https://backend.local:8000/v0/github-proxy/";
|
|
142
|
+
expect(resolveCursorGithubProxyUrl("https://api.cursor.com")).toBe(
|
|
143
|
+
"https://backend.local:8000/v0/github-proxy"
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("routes channel Octokit calls to the bound proxy with scope headers", async () => {
|
|
148
|
+
const definition = githubChannel({
|
|
149
|
+
cursorAccount: { repos: ["acme/widgets"], permissions: "pr-write" },
|
|
150
|
+
});
|
|
151
|
+
const runtime = getGithubCursorAccountRuntime(definition);
|
|
152
|
+
runtime?.credentials.bind(async () => "crsr_api_key");
|
|
153
|
+
runtime?.credentials.bindProxyTransport({
|
|
154
|
+
apiBaseUrl: "https://api.cursor.com/v0/github-proxy",
|
|
155
|
+
headers: {
|
|
156
|
+
"x-cursor-github-repos": "acme/widgets",
|
|
157
|
+
"x-cursor-github-permissions": "pr-write",
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const { fetchImpl, requests } = captureFetch();
|
|
162
|
+
const octokit = await createGitHubOctokit({
|
|
163
|
+
api: { fetch: fetchImpl },
|
|
164
|
+
credentials: getGitHubChannelOptions(definition)?.credentials,
|
|
165
|
+
});
|
|
166
|
+
await octokit.request("GET /repos/{owner}/{repo}", {
|
|
167
|
+
owner: "acme",
|
|
168
|
+
repo: "widgets",
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
expect(requests).toHaveLength(1);
|
|
172
|
+
const { url, headers } = requests[0]!;
|
|
173
|
+
expect(url).toBe(
|
|
174
|
+
"https://api.cursor.com/v0/github-proxy/repos/acme/widgets"
|
|
175
|
+
);
|
|
176
|
+
expect(headers.get("authorization")).toBe("Bearer crsr_api_key");
|
|
177
|
+
expect(headers.get("x-cursor-github-repos")).toBe("acme/widgets");
|
|
178
|
+
expect(headers.get("x-cursor-github-permissions")).toBe("pr-write");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("keeps raw-token mode when no proxy transport is bound", async () => {
|
|
182
|
+
const definition = githubChannel({
|
|
183
|
+
cursorAccount: { repos: ["acme/widgets"] },
|
|
184
|
+
});
|
|
185
|
+
getGithubCursorAccountRuntime(definition)?.credentials.bind(
|
|
186
|
+
async () => "ghs_raw"
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
const { fetchImpl, requests } = captureFetch();
|
|
190
|
+
const octokit = await createGitHubOctokit({
|
|
191
|
+
api: { fetch: fetchImpl },
|
|
192
|
+
credentials: getGitHubChannelOptions(definition)?.credentials,
|
|
193
|
+
});
|
|
194
|
+
await octokit.request("GET /repos/{owner}/{repo}", {
|
|
195
|
+
owner: "acme",
|
|
196
|
+
repo: "widgets",
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const { url, headers } = requests[0]!;
|
|
200
|
+
expect(url).toBe("https://api.github.com/repos/acme/widgets");
|
|
201
|
+
expect(headers.get("authorization")).toBe("Bearer ghs_raw");
|
|
202
|
+
expect(headers.get("x-cursor-github-repos")).toBeNull();
|
|
203
|
+
});
|
|
204
|
+
});
|