@framers/agentos-ext-github 0.1.0 → 0.1.1
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/LICENSE +96 -21
- package/dist/GitHubRepoIndexer.d.ts +88 -0
- package/dist/GitHubRepoIndexer.d.ts.map +1 -0
- package/dist/GitHubRepoIndexer.js +252 -0
- package/dist/GitHubRepoIndexer.js.map +1 -0
- package/dist/GitHubService.d.ts +58 -1
- package/dist/GitHubService.d.ts.map +1 -1
- package/dist/GitHubService.js +83 -1
- package/dist/GitHubService.js.map +1 -1
- package/dist/__tests__/fileAndBranchTools.test.d.ts +6 -0
- package/dist/__tests__/fileAndBranchTools.test.d.ts.map +1 -0
- package/dist/__tests__/fileAndBranchTools.test.js +310 -0
- package/dist/__tests__/fileAndBranchTools.test.js.map +1 -0
- package/dist/__tests__/indexer.test.d.ts +6 -0
- package/dist/__tests__/indexer.test.d.ts.map +1 -0
- package/dist/__tests__/indexer.test.js +239 -0
- package/dist/__tests__/indexer.test.js.map +1 -0
- package/dist/__tests__/issueTools.test.d.ts +5 -0
- package/dist/__tests__/issueTools.test.d.ts.map +1 -0
- package/dist/__tests__/issueTools.test.js +183 -0
- package/dist/__tests__/issueTools.test.js.map +1 -0
- package/dist/__tests__/prTools.test.d.ts +5 -0
- package/dist/__tests__/prTools.test.d.ts.map +1 -0
- package/dist/__tests__/prTools.test.js +318 -0
- package/dist/__tests__/prTools.test.js.map +1 -0
- package/dist/__tests__/releaseAndActionsTools.test.d.ts +6 -0
- package/dist/__tests__/releaseAndActionsTools.test.d.ts.map +1 -0
- package/dist/__tests__/releaseAndActionsTools.test.js +315 -0
- package/dist/__tests__/releaseAndActionsTools.test.js.map +1 -0
- package/dist/__tests__/repoTools.test.d.ts +6 -0
- package/dist/__tests__/repoTools.test.d.ts.map +1 -0
- package/dist/__tests__/repoTools.test.js +308 -0
- package/dist/__tests__/repoTools.test.js.map +1 -0
- package/dist/__tests__/service.test.d.ts +6 -0
- package/dist/__tests__/service.test.d.ts.map +1 -0
- package/dist/__tests__/service.test.js +173 -0
- package/dist/__tests__/service.test.js.map +1 -0
- package/dist/index.d.ts +41 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -1
- package/dist/index.js.map +1 -1
- package/dist/tools/actionsList.d.ts +48 -0
- package/dist/tools/actionsList.d.ts.map +1 -0
- package/dist/tools/actionsList.js +71 -0
- package/dist/tools/actionsList.js.map +1 -0
- package/dist/tools/actionsTrigger.d.ts +56 -0
- package/dist/tools/actionsTrigger.d.ts.map +1 -0
- package/dist/tools/actionsTrigger.js +62 -0
- package/dist/tools/actionsTrigger.js.map +1 -0
- package/dist/tools/branchCreate.d.ts +47 -0
- package/dist/tools/branchCreate.d.ts.map +1 -0
- package/dist/tools/branchCreate.js +68 -0
- package/dist/tools/branchCreate.js.map +1 -0
- package/dist/tools/branchList.d.ts +45 -0
- package/dist/tools/branchList.d.ts.map +1 -0
- package/dist/tools/branchList.js +47 -0
- package/dist/tools/branchList.js.map +1 -0
- package/dist/tools/commentList.d.ts +48 -0
- package/dist/tools/commentList.d.ts.map +1 -0
- package/dist/tools/commentList.js +52 -0
- package/dist/tools/commentList.js.map +1 -0
- package/dist/tools/commitList.d.ts +65 -0
- package/dist/tools/commitList.d.ts.map +1 -0
- package/dist/tools/commitList.js +58 -0
- package/dist/tools/commitList.js.map +1 -0
- package/dist/tools/fileRead.d.ts.map +1 -1
- package/dist/tools/fileRead.js +1 -0
- package/dist/tools/fileRead.js.map +1 -1
- package/dist/tools/fileWrite.d.ts +61 -0
- package/dist/tools/fileWrite.d.ts.map +1 -0
- package/dist/tools/fileWrite.js +56 -0
- package/dist/tools/fileWrite.js.map +1 -0
- package/dist/tools/gistCreate.d.ts.map +1 -1
- package/dist/tools/gistCreate.js +1 -0
- package/dist/tools/gistCreate.js.map +1 -1
- package/dist/tools/issueCreate.d.ts.map +1 -1
- package/dist/tools/issueCreate.js +1 -0
- package/dist/tools/issueCreate.js.map +1 -1
- package/dist/tools/issueList.d.ts.map +1 -1
- package/dist/tools/issueList.js +1 -0
- package/dist/tools/issueList.js.map +1 -1
- package/dist/tools/issueUpdate.d.ts +75 -0
- package/dist/tools/issueUpdate.d.ts.map +1 -0
- package/dist/tools/issueUpdate.js +80 -0
- package/dist/tools/issueUpdate.js.map +1 -0
- package/dist/tools/prCommentCreate.d.ts +48 -0
- package/dist/tools/prCommentCreate.d.ts.map +1 -0
- package/dist/tools/prCommentCreate.js +50 -0
- package/dist/tools/prCommentCreate.js.map +1 -0
- package/dist/tools/prCommentList.d.ts +48 -0
- package/dist/tools/prCommentList.d.ts.map +1 -0
- package/dist/tools/prCommentList.js +53 -0
- package/dist/tools/prCommentList.js.map +1 -0
- package/dist/tools/prCreate.d.ts.map +1 -1
- package/dist/tools/prCreate.js +1 -0
- package/dist/tools/prCreate.js.map +1 -1
- package/dist/tools/prDiff.d.ts +48 -0
- package/dist/tools/prDiff.d.ts.map +1 -0
- package/dist/tools/prDiff.js +75 -0
- package/dist/tools/prDiff.js.map +1 -0
- package/dist/tools/prList.d.ts.map +1 -1
- package/dist/tools/prList.js +1 -0
- package/dist/tools/prList.js.map +1 -1
- package/dist/tools/prMerge.d.ts +59 -0
- package/dist/tools/prMerge.d.ts.map +1 -0
- package/dist/tools/prMerge.js +58 -0
- package/dist/tools/prMerge.js.map +1 -0
- package/dist/tools/prReview.d.ts +81 -0
- package/dist/tools/prReview.d.ts.map +1 -0
- package/dist/tools/prReview.js +70 -0
- package/dist/tools/prReview.js.map +1 -0
- package/dist/tools/releaseCreate.d.ts +73 -0
- package/dist/tools/releaseCreate.d.ts.map +1 -0
- package/dist/tools/releaseCreate.js +69 -0
- package/dist/tools/releaseCreate.js.map +1 -0
- package/dist/tools/releaseList.d.ts +42 -0
- package/dist/tools/releaseList.d.ts.map +1 -0
- package/dist/tools/releaseList.js +50 -0
- package/dist/tools/releaseList.js.map +1 -0
- package/dist/tools/repoCreate.d.ts +55 -0
- package/dist/tools/repoCreate.d.ts.map +1 -0
- package/dist/tools/repoCreate.js +54 -0
- package/dist/tools/repoCreate.js.map +1 -0
- package/dist/tools/repoIndex.d.ts +47 -0
- package/dist/tools/repoIndex.d.ts.map +1 -0
- package/dist/tools/repoIndex.js +127 -0
- package/dist/tools/repoIndex.js.map +1 -0
- package/dist/tools/repoInfo.d.ts +35 -0
- package/dist/tools/repoInfo.d.ts.map +1 -0
- package/dist/tools/repoInfo.js +60 -0
- package/dist/tools/repoInfo.js.map +1 -0
- package/dist/tools/repoList.d.ts +47 -0
- package/dist/tools/repoList.d.ts.map +1 -0
- package/dist/tools/repoList.js +74 -0
- package/dist/tools/repoList.js.map +1 -0
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/search.js +1 -0
- package/dist/tools/search.js.map +1 -1
- package/manifest.json +30 -6
- package/package.json +10 -6
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Tests for release and actions tools:
|
|
4
|
+
* releaseList, releaseCreate, actionsList, actionsTrigger.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
|
+
import { GitHubReleaseListTool } from '../tools/releaseList.js';
|
|
8
|
+
import { GitHubReleaseCreateTool } from '../tools/releaseCreate.js';
|
|
9
|
+
import { GitHubActionsListTool } from '../tools/actionsList.js';
|
|
10
|
+
import { GitHubActionsTriggerTool } from '../tools/actionsTrigger.js';
|
|
11
|
+
/** Creates a mock GitHubService with stubs for repos and actions API. */
|
|
12
|
+
function createMockService() {
|
|
13
|
+
const octokit = {
|
|
14
|
+
rest: {
|
|
15
|
+
repos: {
|
|
16
|
+
listReleases: vi.fn(),
|
|
17
|
+
createRelease: vi.fn(),
|
|
18
|
+
},
|
|
19
|
+
actions: {
|
|
20
|
+
listWorkflowRunsForRepo: vi.fn(),
|
|
21
|
+
listWorkflowRuns: vi.fn(),
|
|
22
|
+
createWorkflowDispatch: vi.fn(),
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
return { getOctokit: () => octokit };
|
|
27
|
+
}
|
|
28
|
+
/* -------------------------------------------------------------------------- */
|
|
29
|
+
/* GitHubReleaseListTool */
|
|
30
|
+
/* -------------------------------------------------------------------------- */
|
|
31
|
+
describe('GitHubReleaseListTool', () => {
|
|
32
|
+
let service;
|
|
33
|
+
let tool;
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
service = createMockService();
|
|
36
|
+
tool = new GitHubReleaseListTool(service);
|
|
37
|
+
});
|
|
38
|
+
it('has correct metadata', () => {
|
|
39
|
+
expect(tool.name).toBe('github_release_list');
|
|
40
|
+
expect(tool.hasSideEffects).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
it('lists releases', async () => {
|
|
43
|
+
const octokit = service.getOctokit();
|
|
44
|
+
octokit.rest.repos.listReleases.mockResolvedValue({
|
|
45
|
+
data: [
|
|
46
|
+
{
|
|
47
|
+
tag_name: 'v1.0.0',
|
|
48
|
+
name: 'Release 1.0',
|
|
49
|
+
draft: false,
|
|
50
|
+
prerelease: false,
|
|
51
|
+
published_at: '2024-06-01T00:00:00Z',
|
|
52
|
+
html_url: 'https://github.com/o/r/releases/tag/v1.0.0',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
tag_name: 'v0.9.0-beta',
|
|
56
|
+
name: 'Beta',
|
|
57
|
+
draft: false,
|
|
58
|
+
prerelease: true,
|
|
59
|
+
published_at: '2024-05-01T00:00:00Z',
|
|
60
|
+
html_url: 'https://github.com/o/r/releases/tag/v0.9.0-beta',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
const result = await tool.execute({ owner: 'o', repo: 'r' });
|
|
65
|
+
expect(result.success).toBe(true);
|
|
66
|
+
expect(result.data).toEqual([
|
|
67
|
+
{
|
|
68
|
+
tag: 'v1.0.0',
|
|
69
|
+
name: 'Release 1.0',
|
|
70
|
+
draft: false,
|
|
71
|
+
prerelease: false,
|
|
72
|
+
publishedAt: '2024-06-01T00:00:00Z',
|
|
73
|
+
url: 'https://github.com/o/r/releases/tag/v1.0.0',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
tag: 'v0.9.0-beta',
|
|
77
|
+
name: 'Beta',
|
|
78
|
+
draft: false,
|
|
79
|
+
prerelease: true,
|
|
80
|
+
publishedAt: '2024-05-01T00:00:00Z',
|
|
81
|
+
url: 'https://github.com/o/r/releases/tag/v0.9.0-beta',
|
|
82
|
+
},
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
it('clamps per_page to 30', async () => {
|
|
86
|
+
const octokit = service.getOctokit();
|
|
87
|
+
octokit.rest.repos.listReleases.mockResolvedValue({ data: [] });
|
|
88
|
+
await tool.execute({ owner: 'o', repo: 'r', per_page: 50 });
|
|
89
|
+
const callArgs = octokit.rest.repos.listReleases.mock.calls[0][0];
|
|
90
|
+
expect(callArgs.per_page).toBe(30);
|
|
91
|
+
});
|
|
92
|
+
it('returns error on API failure', async () => {
|
|
93
|
+
const octokit = service.getOctokit();
|
|
94
|
+
octokit.rest.repos.listReleases.mockRejectedValue(new Error('Not Found'));
|
|
95
|
+
const result = await tool.execute({ owner: 'o', repo: 'r' });
|
|
96
|
+
expect(result.success).toBe(false);
|
|
97
|
+
expect(result.error).toBe('Not Found');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
/* -------------------------------------------------------------------------- */
|
|
101
|
+
/* GitHubReleaseCreateTool */
|
|
102
|
+
/* -------------------------------------------------------------------------- */
|
|
103
|
+
describe('GitHubReleaseCreateTool', () => {
|
|
104
|
+
let service;
|
|
105
|
+
let tool;
|
|
106
|
+
beforeEach(() => {
|
|
107
|
+
service = createMockService();
|
|
108
|
+
tool = new GitHubReleaseCreateTool(service);
|
|
109
|
+
});
|
|
110
|
+
it('has correct metadata', () => {
|
|
111
|
+
expect(tool.name).toBe('github_release_create');
|
|
112
|
+
expect(tool.hasSideEffects).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
it('creates a release with minimal args', async () => {
|
|
115
|
+
const octokit = service.getOctokit();
|
|
116
|
+
octokit.rest.repos.createRelease.mockResolvedValue({
|
|
117
|
+
data: {
|
|
118
|
+
id: 1001,
|
|
119
|
+
tag_name: 'v2.0.0',
|
|
120
|
+
name: null,
|
|
121
|
+
draft: false,
|
|
122
|
+
prerelease: false,
|
|
123
|
+
html_url: 'https://github.com/o/r/releases/tag/v2.0.0',
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
const result = await tool.execute({ owner: 'o', repo: 'r', tag_name: 'v2.0.0' });
|
|
127
|
+
expect(result.success).toBe(true);
|
|
128
|
+
expect(result.data).toEqual({
|
|
129
|
+
id: 1001,
|
|
130
|
+
tag: 'v2.0.0',
|
|
131
|
+
name: null,
|
|
132
|
+
draft: false,
|
|
133
|
+
prerelease: false,
|
|
134
|
+
url: 'https://github.com/o/r/releases/tag/v2.0.0',
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
it('creates a draft prerelease with all options', async () => {
|
|
138
|
+
const octokit = service.getOctokit();
|
|
139
|
+
octokit.rest.repos.createRelease.mockResolvedValue({
|
|
140
|
+
data: {
|
|
141
|
+
id: 1002,
|
|
142
|
+
tag_name: 'v3.0.0-rc1',
|
|
143
|
+
name: 'RC1',
|
|
144
|
+
draft: true,
|
|
145
|
+
prerelease: true,
|
|
146
|
+
html_url: 'https://github.com/o/r/releases/tag/v3.0.0-rc1',
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
await tool.execute({
|
|
150
|
+
owner: 'o',
|
|
151
|
+
repo: 'r',
|
|
152
|
+
tag_name: 'v3.0.0-rc1',
|
|
153
|
+
name: 'RC1',
|
|
154
|
+
body: 'Release candidate',
|
|
155
|
+
draft: true,
|
|
156
|
+
prerelease: true,
|
|
157
|
+
target_commitish: 'release/3.0',
|
|
158
|
+
generate_release_notes: true,
|
|
159
|
+
});
|
|
160
|
+
const callArgs = octokit.rest.repos.createRelease.mock.calls[0][0];
|
|
161
|
+
expect(callArgs.tag_name).toBe('v3.0.0-rc1');
|
|
162
|
+
expect(callArgs.draft).toBe(true);
|
|
163
|
+
expect(callArgs.prerelease).toBe(true);
|
|
164
|
+
expect(callArgs.target_commitish).toBe('release/3.0');
|
|
165
|
+
expect(callArgs.generate_release_notes).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
it('returns error on API failure', async () => {
|
|
168
|
+
const octokit = service.getOctokit();
|
|
169
|
+
octokit.rest.repos.createRelease.mockRejectedValue(new Error('Validation Failed'));
|
|
170
|
+
const result = await tool.execute({ owner: 'o', repo: 'r', tag_name: 'bad' });
|
|
171
|
+
expect(result.success).toBe(false);
|
|
172
|
+
expect(result.error).toBe('Validation Failed');
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
/* -------------------------------------------------------------------------- */
|
|
176
|
+
/* GitHubActionsListTool */
|
|
177
|
+
/* -------------------------------------------------------------------------- */
|
|
178
|
+
describe('GitHubActionsListTool', () => {
|
|
179
|
+
let service;
|
|
180
|
+
let tool;
|
|
181
|
+
beforeEach(() => {
|
|
182
|
+
service = createMockService();
|
|
183
|
+
tool = new GitHubActionsListTool(service);
|
|
184
|
+
});
|
|
185
|
+
it('has correct metadata', () => {
|
|
186
|
+
expect(tool.name).toBe('github_actions_list');
|
|
187
|
+
expect(tool.hasSideEffects).toBe(false);
|
|
188
|
+
});
|
|
189
|
+
it('lists runs for repo when no workflow_id given', async () => {
|
|
190
|
+
const octokit = service.getOctokit();
|
|
191
|
+
octokit.rest.actions.listWorkflowRunsForRepo.mockResolvedValue({
|
|
192
|
+
data: {
|
|
193
|
+
workflow_runs: [
|
|
194
|
+
{
|
|
195
|
+
id: 9001,
|
|
196
|
+
name: 'CI',
|
|
197
|
+
status: 'completed',
|
|
198
|
+
conclusion: 'success',
|
|
199
|
+
head_branch: 'master',
|
|
200
|
+
event: 'push',
|
|
201
|
+
created_at: '2024-07-01T00:00:00Z',
|
|
202
|
+
html_url: 'https://github.com/o/r/actions/runs/9001',
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
const result = await tool.execute({ owner: 'o', repo: 'r' });
|
|
208
|
+
expect(result.success).toBe(true);
|
|
209
|
+
expect(result.data).toEqual([
|
|
210
|
+
{
|
|
211
|
+
id: 9001,
|
|
212
|
+
name: 'CI',
|
|
213
|
+
status: 'completed',
|
|
214
|
+
conclusion: 'success',
|
|
215
|
+
branch: 'master',
|
|
216
|
+
event: 'push',
|
|
217
|
+
createdAt: '2024-07-01T00:00:00Z',
|
|
218
|
+
url: 'https://github.com/o/r/actions/runs/9001',
|
|
219
|
+
},
|
|
220
|
+
]);
|
|
221
|
+
expect(octokit.rest.actions.listWorkflowRunsForRepo).toHaveBeenCalled();
|
|
222
|
+
expect(octokit.rest.actions.listWorkflowRuns).not.toHaveBeenCalled();
|
|
223
|
+
});
|
|
224
|
+
it('lists runs for specific workflow when workflow_id given', async () => {
|
|
225
|
+
const octokit = service.getOctokit();
|
|
226
|
+
octokit.rest.actions.listWorkflowRuns.mockResolvedValue({
|
|
227
|
+
data: {
|
|
228
|
+
workflow_runs: [
|
|
229
|
+
{
|
|
230
|
+
id: 9002,
|
|
231
|
+
name: 'Deploy',
|
|
232
|
+
status: 'in_progress',
|
|
233
|
+
conclusion: null,
|
|
234
|
+
head_branch: 'release',
|
|
235
|
+
event: 'workflow_dispatch',
|
|
236
|
+
created_at: '2024-07-02T00:00:00Z',
|
|
237
|
+
html_url: 'https://github.com/o/r/actions/runs/9002',
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
const result = await tool.execute({ owner: 'o', repo: 'r', workflow_id: 'deploy.yml' });
|
|
243
|
+
expect(result.success).toBe(true);
|
|
244
|
+
expect(octokit.rest.actions.listWorkflowRuns).toHaveBeenCalled();
|
|
245
|
+
const callArgs = octokit.rest.actions.listWorkflowRuns.mock.calls[0][0];
|
|
246
|
+
expect(callArgs.workflow_id).toBe('deploy.yml');
|
|
247
|
+
expect(octokit.rest.actions.listWorkflowRunsForRepo).not.toHaveBeenCalled();
|
|
248
|
+
});
|
|
249
|
+
it('clamps per_page to 30', async () => {
|
|
250
|
+
const octokit = service.getOctokit();
|
|
251
|
+
octokit.rest.actions.listWorkflowRunsForRepo.mockResolvedValue({
|
|
252
|
+
data: { workflow_runs: [] },
|
|
253
|
+
});
|
|
254
|
+
await tool.execute({ owner: 'o', repo: 'r', per_page: 100 });
|
|
255
|
+
const callArgs = octokit.rest.actions.listWorkflowRunsForRepo.mock.calls[0][0];
|
|
256
|
+
expect(callArgs.per_page).toBe(30);
|
|
257
|
+
});
|
|
258
|
+
it('returns error on API failure', async () => {
|
|
259
|
+
const octokit = service.getOctokit();
|
|
260
|
+
octokit.rest.actions.listWorkflowRunsForRepo.mockRejectedValue(new Error('Forbidden'));
|
|
261
|
+
const result = await tool.execute({ owner: 'o', repo: 'r' });
|
|
262
|
+
expect(result.success).toBe(false);
|
|
263
|
+
expect(result.error).toBe('Forbidden');
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
/* -------------------------------------------------------------------------- */
|
|
267
|
+
/* GitHubActionsTriggerTool */
|
|
268
|
+
/* -------------------------------------------------------------------------- */
|
|
269
|
+
describe('GitHubActionsTriggerTool', () => {
|
|
270
|
+
let service;
|
|
271
|
+
let tool;
|
|
272
|
+
beforeEach(() => {
|
|
273
|
+
service = createMockService();
|
|
274
|
+
tool = new GitHubActionsTriggerTool(service);
|
|
275
|
+
});
|
|
276
|
+
it('has correct metadata', () => {
|
|
277
|
+
expect(tool.name).toBe('github_actions_trigger');
|
|
278
|
+
expect(tool.hasSideEffects).toBe(true);
|
|
279
|
+
});
|
|
280
|
+
it('triggers workflow with default ref', async () => {
|
|
281
|
+
const octokit = service.getOctokit();
|
|
282
|
+
octokit.rest.actions.createWorkflowDispatch.mockResolvedValue({});
|
|
283
|
+
const result = await tool.execute({ owner: 'o', repo: 'r', workflow_id: 'deploy.yml' });
|
|
284
|
+
expect(result.success).toBe(true);
|
|
285
|
+
expect(result.data).toEqual({
|
|
286
|
+
workflow_id: 'deploy.yml',
|
|
287
|
+
ref: 'master',
|
|
288
|
+
message: 'Workflow dispatch event triggered successfully',
|
|
289
|
+
});
|
|
290
|
+
const callArgs = octokit.rest.actions.createWorkflowDispatch.mock.calls[0][0];
|
|
291
|
+
expect(callArgs.ref).toBe('master');
|
|
292
|
+
});
|
|
293
|
+
it('triggers workflow with custom ref and inputs', async () => {
|
|
294
|
+
const octokit = service.getOctokit();
|
|
295
|
+
octokit.rest.actions.createWorkflowDispatch.mockResolvedValue({});
|
|
296
|
+
await tool.execute({
|
|
297
|
+
owner: 'o',
|
|
298
|
+
repo: 'r',
|
|
299
|
+
workflow_id: 'build.yml',
|
|
300
|
+
ref: 'release/2.0',
|
|
301
|
+
inputs: { environment: 'staging', debug: 'true' },
|
|
302
|
+
});
|
|
303
|
+
const callArgs = octokit.rest.actions.createWorkflowDispatch.mock.calls[0][0];
|
|
304
|
+
expect(callArgs.ref).toBe('release/2.0');
|
|
305
|
+
expect(callArgs.inputs).toEqual({ environment: 'staging', debug: 'true' });
|
|
306
|
+
});
|
|
307
|
+
it('returns error on API failure', async () => {
|
|
308
|
+
const octokit = service.getOctokit();
|
|
309
|
+
octokit.rest.actions.createWorkflowDispatch.mockRejectedValue(new Error('Workflow does not have workflow_dispatch trigger'));
|
|
310
|
+
const result = await tool.execute({ owner: 'o', repo: 'r', workflow_id: 'ci.yml' });
|
|
311
|
+
expect(result.success).toBe(false);
|
|
312
|
+
expect(result.error).toBe('Workflow does not have workflow_dispatch trigger');
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
//# sourceMappingURL=releaseAndActionsTools.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"releaseAndActionsTools.test.js","sourceRoot":"","sources":["../../src/__tests__/releaseAndActionsTools.test.ts"],"names":[],"mappings":"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__/repoTools.test.ts"],"names":[],"mappings":"AACA;;;GAGG"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Unit tests for the repository tools:
|
|
4
|
+
* GitHubRepoListTool, GitHubRepoInfoTool, GitHubRepoCreateTool, GitHubRepoIndexTool.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
|
+
import { GitHubService } from '../GitHubService.js';
|
|
8
|
+
import { GitHubRepoListTool } from '../tools/repoList.js';
|
|
9
|
+
import { GitHubRepoInfoTool } from '../tools/repoInfo.js';
|
|
10
|
+
import { GitHubRepoCreateTool } from '../tools/repoCreate.js';
|
|
11
|
+
import { GitHubRepoIndexTool } from '../tools/repoIndex.js';
|
|
12
|
+
/* ---------- Octokit mock ---------- */
|
|
13
|
+
const mockListForUser = vi.fn();
|
|
14
|
+
const mockListForOrg = vi.fn();
|
|
15
|
+
const mockReposGet = vi.fn();
|
|
16
|
+
const mockCreateForAuthenticatedUser = vi.fn();
|
|
17
|
+
const mockGetAuthenticated = vi.fn();
|
|
18
|
+
const mockGetTree = vi.fn();
|
|
19
|
+
const mockGetContent = vi.fn();
|
|
20
|
+
const mockRateLimitGet = vi.fn();
|
|
21
|
+
vi.mock('@octokit/rest', () => ({
|
|
22
|
+
Octokit: vi.fn().mockImplementation(() => ({
|
|
23
|
+
rest: {
|
|
24
|
+
users: { getAuthenticated: mockGetAuthenticated },
|
|
25
|
+
repos: {
|
|
26
|
+
listForUser: mockListForUser,
|
|
27
|
+
listForOrg: mockListForOrg,
|
|
28
|
+
get: mockReposGet,
|
|
29
|
+
getContent: mockGetContent,
|
|
30
|
+
createForAuthenticatedUser: mockCreateForAuthenticatedUser,
|
|
31
|
+
},
|
|
32
|
+
git: { getTree: mockGetTree },
|
|
33
|
+
rateLimit: { get: mockRateLimitGet },
|
|
34
|
+
},
|
|
35
|
+
})),
|
|
36
|
+
}));
|
|
37
|
+
/* ---------- Helpers ---------- */
|
|
38
|
+
let service;
|
|
39
|
+
const SAMPLE_REPO = {
|
|
40
|
+
name: 'my-repo',
|
|
41
|
+
full_name: 'octocat/my-repo',
|
|
42
|
+
description: 'A sample repo',
|
|
43
|
+
language: 'TypeScript',
|
|
44
|
+
stargazers_count: 100,
|
|
45
|
+
forks_count: 10,
|
|
46
|
+
visibility: 'public',
|
|
47
|
+
updated_at: '2025-06-01T00:00:00Z',
|
|
48
|
+
html_url: 'https://github.com/octocat/my-repo',
|
|
49
|
+
private: false,
|
|
50
|
+
};
|
|
51
|
+
beforeEach(async () => {
|
|
52
|
+
vi.clearAllMocks();
|
|
53
|
+
mockGetAuthenticated.mockResolvedValue({ data: { login: 'testuser' } });
|
|
54
|
+
service = new GitHubService('ghp_test');
|
|
55
|
+
await service.initialize();
|
|
56
|
+
});
|
|
57
|
+
/* ---------- GitHubRepoListTool ---------- */
|
|
58
|
+
describe('GitHubRepoListTool', () => {
|
|
59
|
+
let tool;
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
tool = new GitHubRepoListTool(service);
|
|
62
|
+
});
|
|
63
|
+
it('has correct static properties', () => {
|
|
64
|
+
expect(tool.name).toBe('github_repo_list');
|
|
65
|
+
expect(tool.category).toBe('developer');
|
|
66
|
+
expect(tool.hasSideEffects).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
it('lists repos for a user by default', async () => {
|
|
69
|
+
mockListForUser.mockResolvedValue({ data: [SAMPLE_REPO] });
|
|
70
|
+
const result = await tool.execute({ username: 'octocat' });
|
|
71
|
+
expect(result.success).toBe(true);
|
|
72
|
+
expect(mockListForUser).toHaveBeenCalledWith(expect.objectContaining({ username: 'octocat', sort: 'updated', per_page: 30 }));
|
|
73
|
+
const data = result.data;
|
|
74
|
+
expect(data).toHaveLength(1);
|
|
75
|
+
expect(data[0].full_name).toBe('octocat/my-repo');
|
|
76
|
+
expect(data[0].stars).toBe(100);
|
|
77
|
+
});
|
|
78
|
+
it('lists repos for an org when type=org', async () => {
|
|
79
|
+
mockListForOrg.mockResolvedValue({ data: [SAMPLE_REPO] });
|
|
80
|
+
const result = await tool.execute({ username: 'github', type: 'org' });
|
|
81
|
+
expect(result.success).toBe(true);
|
|
82
|
+
expect(mockListForOrg).toHaveBeenCalledWith(expect.objectContaining({ org: 'github' }));
|
|
83
|
+
});
|
|
84
|
+
it('caps per_page at 100', async () => {
|
|
85
|
+
mockListForUser.mockResolvedValue({ data: [] });
|
|
86
|
+
await tool.execute({ username: 'u', per_page: 999 });
|
|
87
|
+
expect(mockListForUser).toHaveBeenCalledWith(expect.objectContaining({ per_page: 100 }));
|
|
88
|
+
});
|
|
89
|
+
it('returns error on failure', async () => {
|
|
90
|
+
mockListForUser.mockRejectedValue(new Error('Not Found'));
|
|
91
|
+
const result = await tool.execute({ username: 'ghost' });
|
|
92
|
+
expect(result.success).toBe(false);
|
|
93
|
+
expect(result.error).toBe('Not Found');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
/* ---------- GitHubRepoInfoTool ---------- */
|
|
97
|
+
describe('GitHubRepoInfoTool', () => {
|
|
98
|
+
let tool;
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
tool = new GitHubRepoInfoTool(service);
|
|
101
|
+
});
|
|
102
|
+
it('has correct static properties', () => {
|
|
103
|
+
expect(tool.name).toBe('github_repo_info');
|
|
104
|
+
expect(tool.hasSideEffects).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
it('returns detailed repo metadata', async () => {
|
|
107
|
+
mockReposGet.mockResolvedValue({
|
|
108
|
+
data: {
|
|
109
|
+
name: 'repo',
|
|
110
|
+
full_name: 'o/repo',
|
|
111
|
+
description: 'desc',
|
|
112
|
+
language: 'Go',
|
|
113
|
+
stargazers_count: 5,
|
|
114
|
+
forks_count: 1,
|
|
115
|
+
open_issues_count: 3,
|
|
116
|
+
topics: ['go'],
|
|
117
|
+
default_branch: 'main',
|
|
118
|
+
visibility: 'public',
|
|
119
|
+
license: { spdx_id: 'Apache-2.0' },
|
|
120
|
+
created_at: '2024-01-01T00:00:00Z',
|
|
121
|
+
updated_at: '2025-01-01T00:00:00Z',
|
|
122
|
+
pushed_at: '2025-01-01T00:00:00Z',
|
|
123
|
+
size: 1024,
|
|
124
|
+
html_url: 'https://github.com/o/repo',
|
|
125
|
+
clone_url: 'https://github.com/o/repo.git',
|
|
126
|
+
has_issues: true,
|
|
127
|
+
has_wiki: false,
|
|
128
|
+
archived: false,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
const result = await tool.execute({ owner: 'o', repo: 'repo' });
|
|
132
|
+
expect(result.success).toBe(true);
|
|
133
|
+
const data = result.data;
|
|
134
|
+
expect(data.full_name).toBe('o/repo');
|
|
135
|
+
expect(data.topics).toEqual(['go']);
|
|
136
|
+
expect(data.license).toBe('Apache-2.0');
|
|
137
|
+
expect(data.archived).toBe(false);
|
|
138
|
+
});
|
|
139
|
+
it('returns error on failure', async () => {
|
|
140
|
+
mockReposGet.mockRejectedValue(new Error('Not Found'));
|
|
141
|
+
const result = await tool.execute({ owner: 'x', repo: 'y' });
|
|
142
|
+
expect(result.success).toBe(false);
|
|
143
|
+
expect(result.error).toBe('Not Found');
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
/* ---------- GitHubRepoCreateTool ---------- */
|
|
147
|
+
describe('GitHubRepoCreateTool', () => {
|
|
148
|
+
let tool;
|
|
149
|
+
beforeEach(() => {
|
|
150
|
+
tool = new GitHubRepoCreateTool(service);
|
|
151
|
+
});
|
|
152
|
+
it('has correct static properties', () => {
|
|
153
|
+
expect(tool.name).toBe('github_repo_create');
|
|
154
|
+
expect(tool.hasSideEffects).toBe(true);
|
|
155
|
+
});
|
|
156
|
+
it('creates a repo with default options', async () => {
|
|
157
|
+
mockCreateForAuthenticatedUser.mockResolvedValue({
|
|
158
|
+
data: {
|
|
159
|
+
name: 'new-repo',
|
|
160
|
+
full_name: 'testuser/new-repo',
|
|
161
|
+
html_url: 'https://github.com/testuser/new-repo',
|
|
162
|
+
clone_url: 'https://github.com/testuser/new-repo.git',
|
|
163
|
+
private: false,
|
|
164
|
+
default_branch: 'main',
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
const result = await tool.execute({ name: 'new-repo' });
|
|
168
|
+
expect(result.success).toBe(true);
|
|
169
|
+
expect(mockCreateForAuthenticatedUser).toHaveBeenCalledWith(expect.objectContaining({
|
|
170
|
+
name: 'new-repo',
|
|
171
|
+
private: false,
|
|
172
|
+
auto_init: false,
|
|
173
|
+
}));
|
|
174
|
+
const data = result.data;
|
|
175
|
+
expect(data.full_name).toBe('testuser/new-repo');
|
|
176
|
+
expect(data.clone_url).toBe('https://github.com/testuser/new-repo.git');
|
|
177
|
+
});
|
|
178
|
+
it('passes optional fields through', async () => {
|
|
179
|
+
mockCreateForAuthenticatedUser.mockResolvedValue({
|
|
180
|
+
data: {
|
|
181
|
+
name: 'priv',
|
|
182
|
+
full_name: 'testuser/priv',
|
|
183
|
+
html_url: 'https://github.com/testuser/priv',
|
|
184
|
+
clone_url: 'https://github.com/testuser/priv.git',
|
|
185
|
+
private: true,
|
|
186
|
+
default_branch: 'main',
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
await tool.execute({
|
|
190
|
+
name: 'priv',
|
|
191
|
+
description: 'Private repo',
|
|
192
|
+
private: true,
|
|
193
|
+
auto_init: true,
|
|
194
|
+
gitignore_template: 'Node',
|
|
195
|
+
license_template: 'mit',
|
|
196
|
+
});
|
|
197
|
+
expect(mockCreateForAuthenticatedUser).toHaveBeenCalledWith(expect.objectContaining({
|
|
198
|
+
private: true,
|
|
199
|
+
auto_init: true,
|
|
200
|
+
gitignore_template: 'Node',
|
|
201
|
+
license_template: 'mit',
|
|
202
|
+
}));
|
|
203
|
+
});
|
|
204
|
+
it('returns error on failure', async () => {
|
|
205
|
+
mockCreateForAuthenticatedUser.mockRejectedValue(new Error('Validation Failed'));
|
|
206
|
+
const result = await tool.execute({ name: '' });
|
|
207
|
+
expect(result.success).toBe(false);
|
|
208
|
+
expect(result.error).toBe('Validation Failed');
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
/* ---------- GitHubRepoIndexTool ---------- */
|
|
212
|
+
describe('GitHubRepoIndexTool', () => {
|
|
213
|
+
let tool;
|
|
214
|
+
beforeEach(() => {
|
|
215
|
+
tool = new GitHubRepoIndexTool(service);
|
|
216
|
+
});
|
|
217
|
+
it('has correct static properties', () => {
|
|
218
|
+
expect(tool.name).toBe('github_repo_index');
|
|
219
|
+
expect(tool.hasSideEffects).toBe(false);
|
|
220
|
+
});
|
|
221
|
+
it('returns chunks for metadata, tree, README, and package.json', async () => {
|
|
222
|
+
// Mock getRepoMetadata (via repos.get)
|
|
223
|
+
mockReposGet.mockResolvedValue({
|
|
224
|
+
data: {
|
|
225
|
+
name: 'repo',
|
|
226
|
+
full_name: 'o/repo',
|
|
227
|
+
description: 'A repo',
|
|
228
|
+
language: 'TypeScript',
|
|
229
|
+
stargazers_count: 10,
|
|
230
|
+
forks_count: 2,
|
|
231
|
+
topics: ['ts'],
|
|
232
|
+
default_branch: 'main',
|
|
233
|
+
visibility: 'public',
|
|
234
|
+
license: { spdx_id: 'MIT' },
|
|
235
|
+
pushed_at: '2025-01-01T00:00:00Z',
|
|
236
|
+
html_url: 'https://github.com/o/repo',
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
// Mock getRepoTree (via git.getTree)
|
|
240
|
+
mockGetTree.mockResolvedValue({
|
|
241
|
+
data: {
|
|
242
|
+
tree: [
|
|
243
|
+
{ path: 'README.md', type: 'blob', size: 500 },
|
|
244
|
+
{ path: 'package.json', type: 'blob', size: 200 },
|
|
245
|
+
{ path: 'src', type: 'tree' },
|
|
246
|
+
{ path: 'src/index.ts', type: 'blob', size: 100 },
|
|
247
|
+
{ path: 'docs/guide.md', type: 'blob', size: 300 },
|
|
248
|
+
],
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
// Mock getFileContent (via repos.getContent)
|
|
252
|
+
const b64 = (s) => Buffer.from(s).toString('base64');
|
|
253
|
+
mockGetContent.mockImplementation(async ({ path }) => {
|
|
254
|
+
if (path === 'README.md') {
|
|
255
|
+
return { data: { type: 'file', content: b64('# Hello'), path, size: 7, sha: 'a' } };
|
|
256
|
+
}
|
|
257
|
+
if (path === 'docs/guide.md') {
|
|
258
|
+
return { data: { type: 'file', content: b64('## Guide'), path, size: 8, sha: 'b' } };
|
|
259
|
+
}
|
|
260
|
+
if (path === 'package.json') {
|
|
261
|
+
return { data: { type: 'file', content: b64('{"name":"repo"}'), path, size: 15, sha: 'c' } };
|
|
262
|
+
}
|
|
263
|
+
throw new Error('Not found');
|
|
264
|
+
});
|
|
265
|
+
const result = await tool.execute({ owner: 'o', repo: 'repo' });
|
|
266
|
+
expect(result.success).toBe(true);
|
|
267
|
+
const data = result.data;
|
|
268
|
+
expect(data.chunk_count).toBe(5); // metadata + tree + readme + 1 doc + package.json
|
|
269
|
+
const types = data.chunks.map((c) => c.type);
|
|
270
|
+
expect(types).toContain('metadata');
|
|
271
|
+
expect(types).toContain('tree');
|
|
272
|
+
expect(types).toContain('readme');
|
|
273
|
+
expect(types).toContain('doc');
|
|
274
|
+
expect(types).toContain('package_json');
|
|
275
|
+
const readme = data.chunks.find((c) => c.type === 'readme');
|
|
276
|
+
expect(readme.content).toBe('# Hello');
|
|
277
|
+
});
|
|
278
|
+
it('uses custom ref when provided', async () => {
|
|
279
|
+
mockReposGet.mockResolvedValue({
|
|
280
|
+
data: {
|
|
281
|
+
name: 'r',
|
|
282
|
+
full_name: 'o/r',
|
|
283
|
+
description: null,
|
|
284
|
+
language: null,
|
|
285
|
+
stargazers_count: 0,
|
|
286
|
+
forks_count: 0,
|
|
287
|
+
topics: [],
|
|
288
|
+
default_branch: 'main',
|
|
289
|
+
visibility: 'public',
|
|
290
|
+
license: null,
|
|
291
|
+
pushed_at: null,
|
|
292
|
+
html_url: 'https://github.com/o/r',
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
mockGetTree.mockResolvedValue({ data: { tree: [] } });
|
|
296
|
+
const result = await tool.execute({ owner: 'o', repo: 'r', ref: 'develop' });
|
|
297
|
+
expect(result.success).toBe(true);
|
|
298
|
+
expect(mockGetTree).toHaveBeenCalledWith(expect.objectContaining({ tree_sha: 'develop' }));
|
|
299
|
+
expect(result.data.ref).toBe('develop');
|
|
300
|
+
});
|
|
301
|
+
it('returns error on failure', async () => {
|
|
302
|
+
mockReposGet.mockRejectedValue(new Error('Not Found'));
|
|
303
|
+
const result = await tool.execute({ owner: 'x', repo: 'y' });
|
|
304
|
+
expect(result.success).toBe(false);
|
|
305
|
+
expect(result.error).toBe('Not Found');
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
//# sourceMappingURL=repoTools.test.js.map
|