@shipfox/api-integration-github 2.0.0
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/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-type$colon$emit.log +1 -0
- package/.turbo/turbo-type.log +1 -0
- package/CHANGELOG.md +138 -0
- package/LICENSE +21 -0
- package/dist/api/client.d.ts +90 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +306 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/installation-token-envelope.d.ts +36 -0
- package/dist/api/installation-token-envelope.d.ts.map +1 -0
- package/dist/api/installation-token-envelope.js +123 -0
- package/dist/api/installation-token-envelope.js.map +1 -0
- package/dist/api/installation-token-provider.d.ts +23 -0
- package/dist/api/installation-token-provider.d.ts.map +1 -0
- package/dist/api/installation-token-provider.js +130 -0
- package/dist/api/installation-token-provider.js.map +1 -0
- package/dist/api/shared-installation-token-cache.d.ts +43 -0
- package/dist/api/shared-installation-token-cache.d.ts.map +1 -0
- package/dist/api/shared-installation-token-cache.js +224 -0
- package/dist/api/shared-installation-token-cache.js.map +1 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +44 -0
- package/dist/config.js.map +1 -0
- package/dist/core/actions-logs.d.ts +47 -0
- package/dist/core/actions-logs.d.ts.map +1 -0
- package/dist/core/actions-logs.js +134 -0
- package/dist/core/actions-logs.js.map +1 -0
- package/dist/core/agent-tool-selection.d.ts +4 -0
- package/dist/core/agent-tool-selection.d.ts.map +1 -0
- package/dist/core/agent-tool-selection.js +38 -0
- package/dist/core/agent-tool-selection.js.map +1 -0
- package/dist/core/agent-tools.d.ts +50 -0
- package/dist/core/agent-tools.d.ts.map +1 -0
- package/dist/core/agent-tools.js +1122 -0
- package/dist/core/agent-tools.js.map +1 -0
- package/dist/core/errors.d.ts +15 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +22 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/install.d.ts +38 -0
- package/dist/core/install.d.ts.map +1 -0
- package/dist/core/install.js +64 -0
- package/dist/core/install.js.map +1 -0
- package/dist/core/source-control.d.ts +15 -0
- package/dist/core/source-control.d.ts.map +1 -0
- package/dist/core/source-control.js +175 -0
- package/dist/core/source-control.js.map +1 -0
- package/dist/core/state.d.ts +12 -0
- package/dist/core/state.d.ts.map +1 -0
- package/dist/core/state.js +54 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/webhook.d.ts +20 -0
- package/dist/core/webhook.d.ts.map +1 -0
- package/dist/core/webhook.js +216 -0
- package/dist/core/webhook.js.map +1 -0
- package/dist/db/db.d.ts +433 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +18 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/installation-token-lock.d.ts +8 -0
- package/dist/db/installation-token-lock.d.ts.map +1 -0
- package/dist/db/installation-token-lock.js +37 -0
- package/dist/db/installation-token-lock.js.map +1 -0
- package/dist/db/installations.d.ts +33 -0
- package/dist/db/installations.d.ts.map +1 -0
- package/dist/db/installations.js +56 -0
- package/dist/db/installations.js.map +1 -0
- package/dist/db/migrations.d.ts +2 -0
- package/dist/db/migrations.d.ts.map +1 -0
- package/dist/db/migrations.js +5 -0
- package/dist/db/migrations.js.map +1 -0
- package/dist/db/schema/common.d.ts +2 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +4 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/installations.d.ts +218 -0
- package/dist/db/schema/installations.d.ts.map +1 -0
- package/dist/db/schema/installations.js +46 -0
- package/dist/db/schema/installations.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +3 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +14 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +75 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/presentation/dto/integrations.d.ts +15 -0
- package/dist/presentation/dto/integrations.d.ts.map +1 -0
- package/dist/presentation/dto/integrations.js +10 -0
- package/dist/presentation/dto/integrations.js.map +1 -0
- package/dist/presentation/e2eRoutes/create-connection.d.ts +11 -0
- package/dist/presentation/e2eRoutes/create-connection.d.ts.map +1 -0
- package/dist/presentation/e2eRoutes/create-connection.js +57 -0
- package/dist/presentation/e2eRoutes/create-connection.js.map +1 -0
- package/dist/presentation/e2eRoutes/index.d.ts +5 -0
- package/dist/presentation/e2eRoutes/index.d.ts.map +1 -0
- package/dist/presentation/e2eRoutes/index.js +11 -0
- package/dist/presentation/e2eRoutes/index.js.map +1 -0
- package/dist/presentation/routes/errors.d.ts +2 -0
- package/dist/presentation/routes/errors.d.ts.map +1 -0
- package/dist/presentation/routes/errors.js +46 -0
- package/dist/presentation/routes/errors.js.map +1 -0
- package/dist/presentation/routes/install.d.ts +13 -0
- package/dist/presentation/routes/install.d.ts.map +1 -0
- package/dist/presentation/routes/install.js +77 -0
- package/dist/presentation/routes/install.js.map +1 -0
- package/dist/presentation/routes/webhooks.d.ts +16 -0
- package/dist/presentation/routes/webhooks.d.ts.map +1 -0
- package/dist/presentation/routes/webhooks.js +110 -0
- package/dist/presentation/routes/webhooks.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +17 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +7 -0
- package/package.json +71 -0
- package/src/api/client.test.ts +94 -0
- package/src/api/client.ts +525 -0
- package/src/api/installation-token-envelope.ts +171 -0
- package/src/api/installation-token-provider.test.ts +241 -0
- package/src/api/installation-token-provider.ts +224 -0
- package/src/api/shared-installation-token-cache.test.ts +294 -0
- package/src/api/shared-installation-token-cache.ts +346 -0
- package/src/config.test.ts +14 -0
- package/src/config.ts +47 -0
- package/src/connection-external-url.test.ts +78 -0
- package/src/core/actions-logs.test.ts +156 -0
- package/src/core/actions-logs.ts +186 -0
- package/src/core/agent-tool-selection.test.ts +41 -0
- package/src/core/agent-tool-selection.ts +42 -0
- package/src/core/agent-tools.test.ts +539 -0
- package/src/core/agent-tools.ts +1269 -0
- package/src/core/errors.ts +23 -0
- package/src/core/install.test.ts +238 -0
- package/src/core/install.ts +119 -0
- package/src/core/source-control.test.ts +327 -0
- package/src/core/source-control.ts +223 -0
- package/src/core/state.test.ts +43 -0
- package/src/core/state.ts +85 -0
- package/src/core/webhook.test.ts +522 -0
- package/src/core/webhook.ts +296 -0
- package/src/db/db.ts +18 -0
- package/src/db/installation-token-lock.test.ts +68 -0
- package/src/db/installation-token-lock.ts +39 -0
- package/src/db/installations.test.ts +67 -0
- package/src/db/installations.ts +108 -0
- package/src/db/migrations.ts +4 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/installations.ts +46 -0
- package/src/index.ts +124 -0
- package/src/metrics/index.ts +1 -0
- package/src/metrics/instance.ts +82 -0
- package/src/presentation/dto/integrations.ts +8 -0
- package/src/presentation/e2eRoutes/create-connection.ts +70 -0
- package/src/presentation/e2eRoutes/index.test.ts +126 -0
- package/src/presentation/e2eRoutes/index.ts +14 -0
- package/src/presentation/routes/errors.ts +43 -0
- package/src/presentation/routes/install.test.ts +279 -0
- package/src/presentation/routes/install.ts +93 -0
- package/src/presentation/routes/webhooks.test.ts +560 -0
- package/src/presentation/routes/webhooks.ts +115 -0
- package/test/env.ts +16 -0
- package/test/factories/github-installation.ts +35 -0
- package/test/factories/index.ts +1 -0
- package/test/fixtures/github-webhook.ts +20 -0
- package/test/globalSetup.ts +14 -0
- package/test/index.ts +2 -0
- package/test/setup.ts +17 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.test.json +9 -0
- package/vitest.config.ts +12 -0
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import type {GithubApiClient} from '#api/client.js';
|
|
2
|
+
import {DEFAULT_JOB_LOG_TAIL_LINES} from '#core/actions-logs.js';
|
|
3
|
+
import {
|
|
4
|
+
type GithubAgentToolId,
|
|
5
|
+
GithubAgentToolsProvider,
|
|
6
|
+
githubAgentToolCatalog,
|
|
7
|
+
githubAgentToolSelectionCatalog,
|
|
8
|
+
} from '#core/agent-tools.js';
|
|
9
|
+
import {createGithubIntegrationProvider} from '#index.js';
|
|
10
|
+
|
|
11
|
+
const expectedCatalogRows = [
|
|
12
|
+
{
|
|
13
|
+
id: 'issue_read',
|
|
14
|
+
category: 'issues',
|
|
15
|
+
sensitivity: 'read',
|
|
16
|
+
sensitive: false,
|
|
17
|
+
requiredScope: [{permission: 'issues', access: 'read'}],
|
|
18
|
+
methods: ['get', 'get_comments', 'get_sub_issues', 'get_parent', 'get_labels'],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 'list_issue_types',
|
|
22
|
+
category: 'issues',
|
|
23
|
+
sensitivity: 'read',
|
|
24
|
+
sensitive: false,
|
|
25
|
+
requiredScope: [{permission: 'issues', access: 'read'}],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'list_issues',
|
|
29
|
+
category: 'issues',
|
|
30
|
+
sensitivity: 'read',
|
|
31
|
+
sensitive: false,
|
|
32
|
+
requiredScope: [{permission: 'issues', access: 'read'}],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 'search_issues',
|
|
36
|
+
category: 'issues',
|
|
37
|
+
sensitivity: 'read',
|
|
38
|
+
sensitive: false,
|
|
39
|
+
requiredScope: [{permission: 'issues', access: 'read'}],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'add_issue_comment',
|
|
43
|
+
category: 'issues',
|
|
44
|
+
sensitivity: 'write',
|
|
45
|
+
sensitive: false,
|
|
46
|
+
requiredScope: [{permission: 'issues', access: 'write'}],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 'issue_write',
|
|
50
|
+
category: 'issues',
|
|
51
|
+
sensitivity: 'write',
|
|
52
|
+
sensitive: false,
|
|
53
|
+
requiredScope: [{permission: 'issues', access: 'write'}],
|
|
54
|
+
methods: ['create', 'update'],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: 'sub_issue_write',
|
|
58
|
+
category: 'issues',
|
|
59
|
+
sensitivity: 'write',
|
|
60
|
+
sensitive: false,
|
|
61
|
+
requiredScope: [{permission: 'issues', access: 'write'}],
|
|
62
|
+
methods: ['add', 'remove', 'reprioritize'],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'pull_request_read',
|
|
66
|
+
category: 'pull_requests',
|
|
67
|
+
sensitivity: 'read',
|
|
68
|
+
sensitive: false,
|
|
69
|
+
requiredScope: [
|
|
70
|
+
{permission: 'pull_requests', access: 'read'},
|
|
71
|
+
{permission: 'issues', access: 'read'},
|
|
72
|
+
],
|
|
73
|
+
methods: [
|
|
74
|
+
'get',
|
|
75
|
+
'get_diff',
|
|
76
|
+
'get_status',
|
|
77
|
+
'get_files',
|
|
78
|
+
'get_commits',
|
|
79
|
+
'get_review_comments',
|
|
80
|
+
'get_reviews',
|
|
81
|
+
'get_comments',
|
|
82
|
+
'get_check_runs',
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'list_pull_requests',
|
|
87
|
+
category: 'pull_requests',
|
|
88
|
+
sensitivity: 'read',
|
|
89
|
+
sensitive: false,
|
|
90
|
+
requiredScope: [{permission: 'pull_requests', access: 'read'}],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: 'search_pull_requests',
|
|
94
|
+
category: 'pull_requests',
|
|
95
|
+
sensitivity: 'read',
|
|
96
|
+
sensitive: false,
|
|
97
|
+
requiredScope: [{permission: 'pull_requests', access: 'read'}],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: 'create_pull_request',
|
|
101
|
+
category: 'pull_requests',
|
|
102
|
+
sensitivity: 'write',
|
|
103
|
+
sensitive: false,
|
|
104
|
+
requiredScope: [{permission: 'pull_requests', access: 'write'}],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: 'update_pull_request',
|
|
108
|
+
category: 'pull_requests',
|
|
109
|
+
sensitivity: 'write',
|
|
110
|
+
sensitive: false,
|
|
111
|
+
requiredScope: [{permission: 'pull_requests', access: 'write'}],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: 'add_reply_to_pull_request_comment',
|
|
115
|
+
category: 'pull_requests',
|
|
116
|
+
sensitivity: 'write',
|
|
117
|
+
sensitive: false,
|
|
118
|
+
requiredScope: [{permission: 'pull_requests', access: 'write'}],
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: 'merge_pull_request',
|
|
122
|
+
category: 'pull_requests',
|
|
123
|
+
sensitivity: 'write',
|
|
124
|
+
sensitive: true,
|
|
125
|
+
requiredScope: [
|
|
126
|
+
{permission: 'pull_requests', access: 'write'},
|
|
127
|
+
{permission: 'contents', access: 'write'},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: 'update_pull_request_branch',
|
|
132
|
+
category: 'pull_requests',
|
|
133
|
+
sensitivity: 'write',
|
|
134
|
+
sensitive: false,
|
|
135
|
+
requiredScope: [{permission: 'pull_requests', access: 'write'}],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: 'pull_request_review_write',
|
|
139
|
+
category: 'pull_requests',
|
|
140
|
+
sensitivity: 'write',
|
|
141
|
+
sensitive: false,
|
|
142
|
+
requiredScope: [{permission: 'pull_requests', access: 'write'}],
|
|
143
|
+
methods: ['create', 'submit_pending', 'delete_pending', 'resolve_thread', 'unresolve_thread'],
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: 'add_comment_to_pending_review',
|
|
147
|
+
category: 'pull_requests',
|
|
148
|
+
sensitivity: 'write',
|
|
149
|
+
sensitive: false,
|
|
150
|
+
requiredScope: [{permission: 'pull_requests', access: 'write'}],
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
id: 'actions_list',
|
|
154
|
+
category: 'actions',
|
|
155
|
+
sensitivity: 'read',
|
|
156
|
+
sensitive: false,
|
|
157
|
+
requiredScope: [{permission: 'actions', access: 'read'}],
|
|
158
|
+
methods: [
|
|
159
|
+
'list_workflows',
|
|
160
|
+
'list_workflow_runs',
|
|
161
|
+
'list_workflow_jobs',
|
|
162
|
+
'list_workflow_run_artifacts',
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
id: 'actions_get',
|
|
167
|
+
category: 'actions',
|
|
168
|
+
sensitivity: 'read',
|
|
169
|
+
sensitive: false,
|
|
170
|
+
requiredScope: [{permission: 'actions', access: 'read'}],
|
|
171
|
+
methods: [
|
|
172
|
+
'get_workflow',
|
|
173
|
+
'get_workflow_run',
|
|
174
|
+
'get_workflow_job',
|
|
175
|
+
'download_workflow_run_artifact',
|
|
176
|
+
'get_workflow_run_usage',
|
|
177
|
+
'get_workflow_run_logs_url',
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
id: 'actions_run_trigger',
|
|
182
|
+
category: 'actions',
|
|
183
|
+
sensitivity: 'write',
|
|
184
|
+
sensitive: true,
|
|
185
|
+
requiredScope: [{permission: 'actions', access: 'write'}],
|
|
186
|
+
methods: [
|
|
187
|
+
'run_workflow',
|
|
188
|
+
'rerun_workflow_run',
|
|
189
|
+
'rerun_failed_jobs',
|
|
190
|
+
'cancel_workflow_run',
|
|
191
|
+
'delete_workflow_run_logs',
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
id: 'get_job_logs',
|
|
196
|
+
category: 'actions',
|
|
197
|
+
sensitivity: 'read',
|
|
198
|
+
sensitive: false,
|
|
199
|
+
requiredScope: [{permission: 'actions', access: 'read'}],
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
describe('github agent tool catalog', () => {
|
|
204
|
+
it('matches the GitHub MCP-style tool rows', () => {
|
|
205
|
+
const rows = githubAgentToolCatalog.map(
|
|
206
|
+
({id, category, sensitivity, sensitive, requiredScope, methods}) => ({
|
|
207
|
+
id,
|
|
208
|
+
category,
|
|
209
|
+
sensitivity,
|
|
210
|
+
sensitive,
|
|
211
|
+
requiredScope,
|
|
212
|
+
...(methods ? {methods: methods.map((method) => method.id)} : {}),
|
|
213
|
+
}),
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
expect(rows).toEqual(expectedCatalogRows);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('defines descriptions and schemas for every tool and method', () => {
|
|
220
|
+
const entriesMissingCatalogData = githubAgentToolCatalog.filter(
|
|
221
|
+
(entry) =>
|
|
222
|
+
entry.description.trim().length === 0 ||
|
|
223
|
+
entry.inputSchema.type !== 'object' ||
|
|
224
|
+
entry.outputSchema?.type !== 'object' ||
|
|
225
|
+
entry.methods?.some((method) => method.description.trim().length === 0),
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
expect(entriesMissingCatalogData).toEqual([]);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('defines method enums for method-based tools', () => {
|
|
232
|
+
const entriesWithWrongMethodEnums = githubAgentToolCatalog.filter((entry) => {
|
|
233
|
+
if (!entry.methods) return false;
|
|
234
|
+
|
|
235
|
+
const inputSchema = entry.inputSchema as {
|
|
236
|
+
properties?: Record<string, {enum?: unknown[] | undefined}> | undefined;
|
|
237
|
+
};
|
|
238
|
+
const methodProperty = inputSchema.properties?.method;
|
|
239
|
+
return (
|
|
240
|
+
!methodProperty ||
|
|
241
|
+
!Array.isArray(methodProperty.enum) ||
|
|
242
|
+
methodProperty.enum.join(',') !== entry.methods.map((method) => method.id).join(',')
|
|
243
|
+
);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
expect(entriesWithWrongMethodEnums).toEqual([]);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('uses unique bare native ids', () => {
|
|
250
|
+
const ids = githubAgentToolCatalog.map((entry) => entry.id);
|
|
251
|
+
const uniqueIds = new Set(ids);
|
|
252
|
+
|
|
253
|
+
expect(uniqueIds.size).toBe(ids.length);
|
|
254
|
+
expect(ids.every((id) => !id.includes('.') && !id.includes('__'))).toBe(true);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('keeps reviewed input constraints aligned with GitHub operations', () => {
|
|
258
|
+
const listIssueTypesSchema = inputSchemaFor('list_issue_types');
|
|
259
|
+
const addIssueCommentSchema = inputSchemaFor('add_issue_comment');
|
|
260
|
+
const updatePullRequestSchema = inputSchemaFor('update_pull_request');
|
|
261
|
+
const addReplySchema = inputSchemaFor('add_reply_to_pull_request_comment');
|
|
262
|
+
const actionsRunTriggerSchema = inputSchemaFor('actions_run_trigger');
|
|
263
|
+
const getJobLogsSchema = inputSchemaFor('get_job_logs');
|
|
264
|
+
|
|
265
|
+
expect(listIssueTypesSchema.required).toEqual(['owner']);
|
|
266
|
+
expect(updatePullRequestSchema.properties).not.toHaveProperty('draft');
|
|
267
|
+
expect(addIssueCommentSchema.anyOf).toEqual([
|
|
268
|
+
{required: ['issue_number', 'body']},
|
|
269
|
+
{required: ['issue_number', 'reaction']},
|
|
270
|
+
{required: ['comment_id', 'reaction']},
|
|
271
|
+
]);
|
|
272
|
+
expect(addReplySchema.anyOf).toEqual([
|
|
273
|
+
{required: ['pull_number', 'body']},
|
|
274
|
+
{required: ['reaction']},
|
|
275
|
+
]);
|
|
276
|
+
expect(actionsRunTriggerSchema.oneOf).toEqual([
|
|
277
|
+
{properties: {method: {const: 'run_workflow'}}, required: ['workflow_id', 'ref']},
|
|
278
|
+
{properties: {method: {const: 'rerun_workflow_run'}}, required: ['run_id']},
|
|
279
|
+
{properties: {method: {const: 'rerun_failed_jobs'}}, required: ['run_id']},
|
|
280
|
+
{properties: {method: {const: 'cancel_workflow_run'}}, required: ['run_id']},
|
|
281
|
+
{properties: {method: {const: 'delete_workflow_run_logs'}}, required: ['run_id']},
|
|
282
|
+
]);
|
|
283
|
+
expect(getJobLogsSchema.properties?.return_content).toMatchObject({
|
|
284
|
+
type: 'boolean',
|
|
285
|
+
});
|
|
286
|
+
expect(getJobLogsSchema.properties?.job_id).toMatchObject({type: 'number'});
|
|
287
|
+
expect(getJobLogsSchema.properties?.run_id).toMatchObject({type: 'number'});
|
|
288
|
+
expect(getJobLogsSchema.properties?.tail_lines).toMatchObject({
|
|
289
|
+
type: 'number',
|
|
290
|
+
default: DEFAULT_JOB_LOG_TAIL_LINES,
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('exposes the catalog through the provider adapter', () => {
|
|
295
|
+
const provider = createProvider();
|
|
296
|
+
const catalog = provider.adapters.agent_tools?.catalog();
|
|
297
|
+
const selectionCatalog = provider.adapters.agent_tools?.selectionCatalog();
|
|
298
|
+
|
|
299
|
+
expect(provider.adapters.agent_tools).toBeDefined();
|
|
300
|
+
expect(catalog).toBe(githubAgentToolCatalog);
|
|
301
|
+
expect(selectionCatalog).toBe(githubAgentToolSelectionCatalog);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('fails closed when the connection has no GitHub installation', async () => {
|
|
305
|
+
const provider = new GithubAgentToolsProvider({
|
|
306
|
+
getInstallationByConnectionId: vi.fn(() => Promise.resolve(undefined)),
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
const result = provider.openSession({
|
|
310
|
+
connection: connection(),
|
|
311
|
+
tools: [githubAgentToolCatalog[0]],
|
|
312
|
+
scope: undefined,
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
await expect(result).rejects.toMatchObject({reason: 'installation-not-found'});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('opens a provider-owned installation session and dispatches the selected operation', async () => {
|
|
319
|
+
const request = vi.fn(() => Promise.resolve({data: {number: 1}}));
|
|
320
|
+
let clientToken: string | undefined;
|
|
321
|
+
const provider = new GithubAgentToolsProvider({
|
|
322
|
+
getInstallationByConnectionId: vi.fn(() => Promise.resolve(installation())),
|
|
323
|
+
tokenProvider: {
|
|
324
|
+
getInstallationAccessToken: vi.fn(() =>
|
|
325
|
+
Promise.resolve({
|
|
326
|
+
token: 'installation-token',
|
|
327
|
+
expiresAt: new Date(),
|
|
328
|
+
permissions: {issues: 'read' as const},
|
|
329
|
+
}),
|
|
330
|
+
),
|
|
331
|
+
},
|
|
332
|
+
createClient: vi.fn((token) => {
|
|
333
|
+
clientToken = token;
|
|
334
|
+
return {request};
|
|
335
|
+
}),
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
const session = await provider.openSession({
|
|
339
|
+
connection: connection(),
|
|
340
|
+
tools: [githubAgentToolCatalog[0]],
|
|
341
|
+
scope: undefined,
|
|
342
|
+
});
|
|
343
|
+
const result = await session.call({
|
|
344
|
+
toolId: 'issue_read',
|
|
345
|
+
arguments: {method: 'get', owner: 'shipfox', repo: 'platform', issue_number: 1},
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
expect(request).toHaveBeenCalledWith('GET /repos/{owner}/{repo}/issues/{issue_number}', {
|
|
349
|
+
owner: 'shipfox',
|
|
350
|
+
repo: 'platform',
|
|
351
|
+
issue_number: 1,
|
|
352
|
+
});
|
|
353
|
+
expect(clientToken).toBe('installation-token');
|
|
354
|
+
expect(result).toEqual({
|
|
355
|
+
content: [{type: 'text', text: '{"number":1}'}],
|
|
356
|
+
structuredContent: {number: 1},
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it.each([
|
|
361
|
+
{
|
|
362
|
+
toolId: 'list_issue_types',
|
|
363
|
+
arguments: {owner: 'shipfox'},
|
|
364
|
+
data: [{id: 1}],
|
|
365
|
+
expected: {issue_types: [{id: 1}]},
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
toolId: 'list_issues',
|
|
369
|
+
arguments: {owner: 'shipfox', repo: 'platform'},
|
|
370
|
+
data: [{number: 1}],
|
|
371
|
+
expected: {issues: [{number: 1}]},
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
toolId: 'search_issues',
|
|
375
|
+
arguments: {query: 'is:open'},
|
|
376
|
+
data: {items: [{number: 1}], total_count: 1},
|
|
377
|
+
expected: {issues: [{number: 1}]},
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
toolId: 'list_pull_requests',
|
|
381
|
+
arguments: {owner: 'shipfox', repo: 'platform'},
|
|
382
|
+
data: [{number: 2}],
|
|
383
|
+
expected: {pull_requests: [{number: 2}]},
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
toolId: 'search_pull_requests',
|
|
387
|
+
arguments: {query: 'is:open'},
|
|
388
|
+
data: {items: [{number: 2}], total_count: 1},
|
|
389
|
+
expected: {pull_requests: [{number: 2}]},
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
toolId: 'create_pull_request',
|
|
393
|
+
arguments: {
|
|
394
|
+
owner: 'shipfox',
|
|
395
|
+
repo: 'platform',
|
|
396
|
+
title: 'Title',
|
|
397
|
+
head: 'feature',
|
|
398
|
+
base: 'main',
|
|
399
|
+
},
|
|
400
|
+
data: {number: 2},
|
|
401
|
+
expected: {pull_request: {number: 2}},
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
toolId: 'update_pull_request',
|
|
405
|
+
arguments: {owner: 'shipfox', repo: 'platform', pull_number: 2},
|
|
406
|
+
data: {number: 2, title: 'Updated'},
|
|
407
|
+
expected: {pull_request: {number: 2, title: 'Updated'}},
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
toolId: 'merge_pull_request',
|
|
411
|
+
arguments: {owner: 'shipfox', repo: 'platform', pull_number: 2},
|
|
412
|
+
data: {merged: true},
|
|
413
|
+
expected: {merge: {merged: true}},
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
toolId: 'pull_request_read',
|
|
417
|
+
arguments: {
|
|
418
|
+
method: 'get_diff',
|
|
419
|
+
owner: 'shipfox',
|
|
420
|
+
repo: 'platform',
|
|
421
|
+
pull_number: 2,
|
|
422
|
+
},
|
|
423
|
+
data: 'diff --git a/file b/file',
|
|
424
|
+
expected: {result: 'diff --git a/file b/file'},
|
|
425
|
+
},
|
|
426
|
+
] satisfies Array<{
|
|
427
|
+
toolId: GithubAgentToolId;
|
|
428
|
+
arguments: Record<string, unknown>;
|
|
429
|
+
data: unknown;
|
|
430
|
+
expected: Record<string, unknown>;
|
|
431
|
+
}>)('projects $toolId responses to their output schema', async (testCase) => {
|
|
432
|
+
const result = await callGithubTool(testCase.toolId, testCase.arguments, testCase.data);
|
|
433
|
+
|
|
434
|
+
expect(result).toEqual({
|
|
435
|
+
content: [{type: 'text', text: JSON.stringify(testCase.expected)}],
|
|
436
|
+
structuredContent: testCase.expected,
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
async function callGithubTool(
|
|
442
|
+
toolId: GithubAgentToolId,
|
|
443
|
+
arguments_: Record<string, unknown>,
|
|
444
|
+
data: unknown,
|
|
445
|
+
) {
|
|
446
|
+
const tool = githubAgentToolCatalog.find((entry) => entry.id === toolId);
|
|
447
|
+
if (!tool) throw new Error(`Missing GitHub tool: ${toolId}`);
|
|
448
|
+
const provider = new GithubAgentToolsProvider({
|
|
449
|
+
getInstallationByConnectionId: vi.fn(() => Promise.resolve(installation())),
|
|
450
|
+
tokenProvider: {
|
|
451
|
+
getInstallationAccessToken: vi.fn(() =>
|
|
452
|
+
Promise.resolve({
|
|
453
|
+
token: 'installation-token',
|
|
454
|
+
expiresAt: new Date(),
|
|
455
|
+
permissions: {
|
|
456
|
+
actions: 'write' as const,
|
|
457
|
+
contents: 'write' as const,
|
|
458
|
+
issues: 'write' as const,
|
|
459
|
+
pull_requests: 'write' as const,
|
|
460
|
+
},
|
|
461
|
+
}),
|
|
462
|
+
),
|
|
463
|
+
},
|
|
464
|
+
createClient: vi.fn(() => ({request: vi.fn(() => Promise.resolve({data}))})),
|
|
465
|
+
});
|
|
466
|
+
const session = await provider.openSession({
|
|
467
|
+
connection: connection(),
|
|
468
|
+
tools: [tool],
|
|
469
|
+
scope: undefined,
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
return await session.call({toolId, arguments: arguments_});
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function connection() {
|
|
476
|
+
return {
|
|
477
|
+
id: 'connection-1',
|
|
478
|
+
workspaceId: 'workspace-1',
|
|
479
|
+
provider: 'github' as const,
|
|
480
|
+
externalAccountId: 'github:1',
|
|
481
|
+
slug: 'github-main',
|
|
482
|
+
displayName: 'GitHub',
|
|
483
|
+
lifecycleStatus: 'active' as const,
|
|
484
|
+
createdAt: new Date(),
|
|
485
|
+
updatedAt: new Date(),
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function installation() {
|
|
490
|
+
return {
|
|
491
|
+
id: 'installation-row-1',
|
|
492
|
+
connectionId: 'connection-1',
|
|
493
|
+
installationId: '1',
|
|
494
|
+
accountLogin: 'shipfox',
|
|
495
|
+
accountType: 'Organization',
|
|
496
|
+
repositorySelection: 'all',
|
|
497
|
+
suspendedAt: null,
|
|
498
|
+
deletedAt: null,
|
|
499
|
+
latestEvent: {},
|
|
500
|
+
installerUserId: null,
|
|
501
|
+
createdAt: new Date(),
|
|
502
|
+
updatedAt: new Date(),
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function createProvider() {
|
|
507
|
+
return createGithubIntegrationProvider({
|
|
508
|
+
github: githubClient(),
|
|
509
|
+
getExistingGithubConnection: vi.fn(() => Promise.resolve(undefined)),
|
|
510
|
+
connectGithubInstallation: vi.fn() as never,
|
|
511
|
+
coreDb: vi.fn() as never,
|
|
512
|
+
publishIntegrationEventReceived: vi.fn(() => Promise.resolve({published: false})),
|
|
513
|
+
publishSourcePush: vi.fn(() => Promise.resolve({published: false})),
|
|
514
|
+
recordDeliveryOnly: vi.fn(() => Promise.resolve()),
|
|
515
|
+
getIntegrationConnectionById: vi.fn(() => Promise.resolve(undefined)),
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function githubClient(): GithubApiClient {
|
|
520
|
+
return {
|
|
521
|
+
exchangeOAuthCode: vi.fn(() => Promise.reject(new Error('not used'))),
|
|
522
|
+
listUserInstallations: vi.fn(() => Promise.reject(new Error('not used'))),
|
|
523
|
+
getInstallation: vi.fn(() => Promise.reject(new Error('not used'))),
|
|
524
|
+
listInstallationRepositories: vi.fn(() => Promise.reject(new Error('not used'))),
|
|
525
|
+
getRepository: vi.fn(() => Promise.reject(new Error('not used'))),
|
|
526
|
+
listRepositoryFiles: vi.fn(() => Promise.reject(new Error('not used'))),
|
|
527
|
+
fetchRepositoryFile: vi.fn(() => Promise.reject(new Error('not used'))),
|
|
528
|
+
createInstallationAccessToken: vi.fn(() => Promise.reject(new Error('not used'))),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function inputSchemaFor(id: (typeof githubAgentToolCatalog)[number]['id']) {
|
|
533
|
+
return githubAgentToolCatalog.find((entry) => entry.id === id)?.inputSchema as {
|
|
534
|
+
properties?: Record<string, unknown> | undefined;
|
|
535
|
+
required?: string[] | undefined;
|
|
536
|
+
anyOf?: unknown[] | undefined;
|
|
537
|
+
oneOf?: unknown[] | undefined;
|
|
538
|
+
};
|
|
539
|
+
}
|