plugin-git-manager 1.2.26 → 1.2.28
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/README.md +133 -108
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +3 -3
- package/client.js +1 -1
- package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
- package/dist/client/900.a48beac7e2ebee7d.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
- package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
- package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
- package/dist/client-v2/900.e6155002a9c97e7f.js +10 -0
- package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +307 -297
- package/dist/locale/vi-VN.json +295 -292
- package/dist/locale/zh-CN.json +61 -51
- package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/git-actions.js +90 -36
- package/dist/server/actions/gitlab-api.js +4 -2
- package/dist/server/actions/poller.js +5 -2
- package/dist/server/actions/review.js +20 -10
- package/dist/server/plugin.js +6 -4
- package/dist/server/poller.js +46 -45
- package/dist/server/request-method-policy.js +75 -0
- package/dist/server/services/registry-content-service.js +23 -10
- package/dist/server/utils/get-repo-account.js +3 -2
- package/dist/server/utils/url-security.js +24 -0
- package/package.json +61 -43
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/__tests__/RunReviewButton.test.tsx +73 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +374 -374
- package/src/client/components/FileExplorer.tsx +386 -386
- package/src/client/components/GitAccounts.tsx +179 -179
- package/src/client/components/GitManagerSettings.tsx +160 -160
- package/src/client/components/GitOperations.tsx +220 -220
- package/src/client/components/LLMModelSelect.tsx +63 -63
- package/src/client/components/LLMServiceSelect.tsx +58 -58
- package/src/client/components/MarkdownView.tsx +80 -80
- package/src/client/components/MergeRequests.tsx +790 -790
- package/src/client/components/PollingStatus.tsx +225 -225
- package/src/client/components/RepositoryConfig.tsx +335 -335
- package/src/client/components/RepositoryPermissions.tsx +123 -123
- package/src/client/components/ReviewFlows.tsx +303 -303
- package/src/client/components/ReviewHistory.tsx +566 -566
- package/src/client/components/RunReviewButton.tsx +63 -55
- package/src/client/context/GitManagerContext.tsx +92 -92
- package/src/client/index.tsx +91 -82
- package/src/client/locale.ts +9 -9
- package/src/client/promptTemplates.ts +31 -31
- package/src/client-v2/ai-context.tsx +99 -0
- package/src/client-v2/components/SubtreeSplits.tsx +547 -547
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/locale.ts +8 -8
- package/src/client-v2/plugin.tsx +67 -39
- package/src/index.ts +2 -2
- package/src/locale/en-US.json +307 -297
- package/src/locale/vi-VN.json +295 -292
- package/src/locale/zh-CN.json +61 -51
- package/src/server/__tests__/git-actions.test.ts +24 -24
- package/src/server/__tests__/git-security.test.ts +170 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -17
- package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
- package/src/server/__tests__/poller.test.ts +37 -37
- package/src/server/__tests__/repository-access.test.ts +752 -752
- package/src/server/__tests__/review.test.ts +137 -137
- package/src/server/__tests__/role-permissions.test.ts +147 -147
- package/src/server/__tests__/smoke.test.ts +139 -17
- package/src/server/__tests__/subtree.test.ts +85 -85
- package/src/server/actions/git-actions.ts +540 -480
- package/src/server/actions/gitlab-api.ts +422 -411
- package/src/server/actions/poller.ts +39 -27
- package/src/server/actions/review.ts +1388 -1369
- package/src/server/actions/role-permissions.ts +321 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +319 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +199 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewFlows.ts +108 -108
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +2 -2
- package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
- package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
- package/src/server/plugin.ts +372 -361
- package/src/server/poller.ts +351 -352
- package/src/server/repository-access.ts +773 -773
- package/src/server/request-method-policy.ts +55 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/registry-content-service.ts +33 -11
- package/src/server/utils/__tests__/redact.test.ts +56 -56
- package/src/server/utils/__tests__/url-security.test.ts +85 -85
- package/src/server/utils/get-repo-account.ts +51 -41
- package/src/server/utils/gitlab-url.ts +38 -38
- package/src/server/utils/redact.ts +87 -87
- package/src/server/utils/url-security.ts +128 -95
- package/dist/client/900.acf7d1fa22f95e71.js +0 -10
- package/dist/client-v2/434.7a27051db18526c0.js +0 -10
- package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
|
@@ -1,345 +1,359 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from '
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
};
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { execFileSync } from 'child_process';
|
|
11
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'fs';
|
|
12
|
+
import { tmpdir } from 'os';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
|
|
15
|
+
import type { Database } from '@nocobase/database';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
RegistryGitContentService,
|
|
19
|
+
SkillHubGitContentService,
|
|
20
|
+
type RegistryGitAccessContext,
|
|
21
|
+
} from '../registry-content-service';
|
|
22
|
+
|
|
23
|
+
const scheduledSyncAccess: RegistryGitAccessContext = { kind: 'system', reason: 'scheduled-sync' };
|
|
24
|
+
|
|
25
|
+
describe('RegistryGitContentService', () => {
|
|
26
|
+
const originalRepositoryRoot = process.env.GIT_REPOS_BASE_PATH;
|
|
27
|
+
let repositoryRoot = '';
|
|
28
|
+
let repositoryPath = '';
|
|
29
|
+
let commitSha = '';
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
repositoryRoot = mkdtempSync(join(tmpdir(), 'registry-git-content-'));
|
|
33
|
+
repositoryPath = join(repositoryRoot, 'skills');
|
|
34
|
+
mkdirSync(repositoryPath, { recursive: true });
|
|
35
|
+
process.env.GIT_REPOS_BASE_PATH = repositoryRoot;
|
|
36
|
+
execFileSync('git', ['init', repositoryPath], { stdio: 'ignore' });
|
|
37
|
+
execFileSync('git', ['-C', repositoryPath, 'config', 'user.email', 'registry@example.test'], { stdio: 'ignore' });
|
|
38
|
+
execFileSync('git', ['-C', repositoryPath, 'config', 'user.name', 'Registry Test'], { stdio: 'ignore' });
|
|
39
|
+
writeFileSync(join(repositoryPath, 'payload.bin'), Buffer.from([0, 255, 128, 17]));
|
|
40
|
+
execFileSync('git', ['-C', repositoryPath, 'add', 'payload.bin'], { stdio: 'ignore' });
|
|
41
|
+
execFileSync('git', ['-C', repositoryPath, 'commit', '-m', 'binary payload'], { stdio: 'ignore' });
|
|
42
|
+
commitSha = execFileSync('git', ['-C', repositoryPath, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
rmSync(repositoryRoot, { recursive: true, force: true });
|
|
47
|
+
if (originalRepositoryRoot === undefined) {
|
|
48
|
+
delete process.env.GIT_REPOS_BASE_PATH;
|
|
49
|
+
} else {
|
|
50
|
+
process.env.GIT_REPOS_BASE_PATH = originalRepositoryRoot;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('preserves binary skill files when reading from a pinned commit', async () => {
|
|
55
|
+
const database = {
|
|
56
|
+
getRepository: () => ({
|
|
57
|
+
findOne: vi.fn().mockResolvedValue({
|
|
58
|
+
get: (attribute: string) => {
|
|
59
|
+
if (attribute === 'localPath') {
|
|
60
|
+
return 'skills';
|
|
61
|
+
}
|
|
62
|
+
if (attribute === 'registryExportEnabled') {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
}),
|
|
69
|
+
} as unknown as Database;
|
|
70
|
+
const service = new RegistryGitContentService(database);
|
|
71
|
+
const treeRequest = { repositoryId: 1, commitSha, rootPath: '', recursive: true };
|
|
72
|
+
await expect(service.listTree({ ...treeRequest, maxTreeOutputBytes: 1 }, scheduledSyncAccess)).rejects.toThrow(
|
|
73
|
+
/output limit/,
|
|
74
|
+
);
|
|
75
|
+
await expect(service.listTree(treeRequest, scheduledSyncAccess)).resolves.toHaveLength(1);
|
|
76
|
+
|
|
77
|
+
await expect(
|
|
78
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, scheduledSyncAccess),
|
|
79
|
+
).resolves.toEqual(Buffer.from([0, 255, 128, 17]));
|
|
80
|
+
await expect(
|
|
81
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'missing.json' }, scheduledSyncAccess),
|
|
82
|
+
).rejects.toMatchObject({
|
|
83
|
+
code: 'REGISTRY_GIT_FILE_NOT_FOUND',
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('rejects repository reads unless Git Manager explicitly grants registry export', async () => {
|
|
88
|
+
const database = {
|
|
89
|
+
getRepository: () => ({
|
|
90
|
+
findOne: vi.fn().mockResolvedValue({
|
|
91
|
+
get: (attribute: string) => (attribute === 'registryExportEnabled' ? false : 'skills'),
|
|
92
|
+
}),
|
|
93
|
+
}),
|
|
94
|
+
} as unknown as Database;
|
|
95
|
+
const service = new RegistryGitContentService(database);
|
|
96
|
+
|
|
97
|
+
await expect(service.resolveCommit(1, 'HEAD', scheduledSyncAccess)).rejects.toMatchObject({
|
|
98
|
+
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
99
|
+
});
|
|
100
|
+
await expect(
|
|
101
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, scheduledSyncAccess),
|
|
102
|
+
).rejects.toMatchObject({
|
|
103
|
+
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('does not distinguish a missing repository from an ungranted repository', async () => {
|
|
108
|
+
const database = {
|
|
109
|
+
getRepository: () => ({ findOne: vi.fn().mockResolvedValue(null) }),
|
|
110
|
+
} as unknown as Database;
|
|
111
|
+
const service = new RegistryGitContentService(database);
|
|
112
|
+
|
|
113
|
+
await expect(service.resolveCommit(404, 'HEAD', scheduledSyncAccess)).rejects.toMatchObject({
|
|
114
|
+
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('waits for a killed Git process to close before returning an output-limit error', async () => {
|
|
119
|
+
// Keep Git writing after the first stdout chunk. This makes the test cover
|
|
120
|
+
// the Windows handle race: the repository must be removable immediately
|
|
121
|
+
// after `readFile()` rejects, without depending on afterEach timing.
|
|
122
|
+
writeFileSync(join(repositoryPath, 'payload.bin'), Buffer.alloc(8 * 1024 * 1024, 255));
|
|
123
|
+
execFileSync('git', ['-C', repositoryPath, 'add', 'payload.bin'], { stdio: 'ignore' });
|
|
124
|
+
execFileSync('git', ['-C', repositoryPath, 'commit', '--amend', '--no-edit'], { stdio: 'ignore' });
|
|
125
|
+
commitSha = execFileSync('git', ['-C', repositoryPath, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
|
|
126
|
+
|
|
127
|
+
const database = {
|
|
128
|
+
getRepository: () => ({
|
|
129
|
+
findOne: vi.fn().mockResolvedValue({
|
|
130
|
+
get: (attribute: string) => {
|
|
131
|
+
if (attribute === 'localPath') {
|
|
132
|
+
return 'skills';
|
|
133
|
+
}
|
|
134
|
+
if (attribute === 'registryExportEnabled') {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
}),
|
|
141
|
+
} as unknown as Database;
|
|
142
|
+
const service = new RegistryGitContentService(database, {
|
|
143
|
+
maxFileBytes: 2,
|
|
144
|
+
maxTreeEntries: 10,
|
|
145
|
+
maxTreeOutputBytes: 1024,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
await expect(
|
|
149
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, scheduledSyncAccess),
|
|
150
|
+
).rejects.toThrow('Git file exceeds the registry source-file limit.');
|
|
151
|
+
expect(() => rmSync(repositoryRoot, { recursive: true, force: true, maxRetries: 0 })).not.toThrow();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('rejects a Git tree that exceeds the configured entry limit', async () => {
|
|
155
|
+
const database = {
|
|
156
|
+
getRepository: () => ({
|
|
157
|
+
findOne: vi.fn().mockResolvedValue({
|
|
158
|
+
get: (attribute: string) => {
|
|
159
|
+
if (attribute === 'localPath') {
|
|
160
|
+
return 'skills';
|
|
161
|
+
}
|
|
162
|
+
if (attribute === 'registryExportEnabled') {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
},
|
|
167
|
+
}),
|
|
168
|
+
}),
|
|
169
|
+
} as unknown as Database;
|
|
170
|
+
const service = new RegistryGitContentService(database, {
|
|
171
|
+
maxFileBytes: 1024,
|
|
172
|
+
maxTreeEntries: 0,
|
|
173
|
+
maxTreeOutputBytes: 1024,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
await expect(
|
|
177
|
+
service.listTree({ repositoryId: 1, commitSha, rootPath: '', recursive: true }, scheduledSyncAccess),
|
|
178
|
+
).rejects.toThrow('Git tree contains too many entries for registry export.');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('requires an explicit actor instead of treating an internal call as a system sync', async () => {
|
|
182
|
+
const database = {
|
|
183
|
+
getRepository: vi.fn(),
|
|
184
|
+
} as unknown as Database;
|
|
185
|
+
const service = new RegistryGitContentService(database);
|
|
186
|
+
|
|
187
|
+
expect(service.contractVersion).toBe(2);
|
|
188
|
+
expect(service.capabilities).toEqual(
|
|
189
|
+
expect.arrayContaining(['registry-content-with-actor', 'registry-content-authorize-source']),
|
|
190
|
+
);
|
|
191
|
+
await expect(service.assertRepositoryAccess(1)).rejects.toMatchObject({
|
|
192
|
+
code: 'REGISTRY_REPOSITORY_ACCESS_DENIED',
|
|
193
|
+
});
|
|
194
|
+
expect(database.getRepository).not.toHaveBeenCalled();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('allows a user whose Git Manager file-content scope includes the repository', async () => {
|
|
198
|
+
const acl = {
|
|
199
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
200
|
+
};
|
|
201
|
+
const database = {
|
|
202
|
+
getRepository: () => ({
|
|
203
|
+
findOne: vi.fn().mockResolvedValue({
|
|
204
|
+
get: (attribute: string) => {
|
|
205
|
+
if (attribute === 'localPath') return 'skills';
|
|
206
|
+
if (attribute === 'registryExportEnabled') return true;
|
|
207
|
+
return null;
|
|
208
|
+
},
|
|
209
|
+
}),
|
|
210
|
+
}),
|
|
211
|
+
} as unknown as Database;
|
|
212
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
213
|
+
|
|
214
|
+
await expect(service.resolveCommit(1, 'HEAD', { kind: 'user', roles: ['developer'] })).resolves.toBe(commitSha);
|
|
215
|
+
expect(acl.can).toHaveBeenCalledWith({
|
|
216
|
+
roles: ['developer'],
|
|
217
|
+
resource: 'gitManager',
|
|
218
|
+
action: 'fileContent',
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('rejects a user whose Git Manager scope excludes the requested repository', async () => {
|
|
223
|
+
const acl = {
|
|
224
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
225
|
+
};
|
|
226
|
+
const repositoryLookup = vi.fn();
|
|
227
|
+
const database = {
|
|
228
|
+
getRepository: repositoryLookup,
|
|
229
|
+
} as unknown as Database;
|
|
230
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
231
|
+
|
|
232
|
+
await expect(service.assertRepositoryAccess(2, { kind: 'user', roles: ['developer'] })).rejects.toMatchObject({
|
|
233
|
+
code: 'REGISTRY_REPOSITORY_ACCESS_DENIED',
|
|
234
|
+
});
|
|
235
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('allows root without evaluating repository scope', async () => {
|
|
239
|
+
const acl = { can: vi.fn() };
|
|
240
|
+
const database = {
|
|
241
|
+
getRepository: () => ({
|
|
242
|
+
findOne: vi.fn().mockResolvedValue({
|
|
243
|
+
get: (attribute: string) => {
|
|
244
|
+
if (attribute === 'localPath') return 'skills';
|
|
245
|
+
if (attribute === 'registryExportEnabled') return true;
|
|
246
|
+
return null;
|
|
247
|
+
},
|
|
248
|
+
}),
|
|
249
|
+
}),
|
|
250
|
+
} as unknown as Database;
|
|
251
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
252
|
+
|
|
253
|
+
await expect(service.resolveCommit(1, 'HEAD', { kind: 'user', roles: ['root'] })).resolves.toBe(commitSha);
|
|
254
|
+
expect(acl.can).not.toHaveBeenCalled();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('allows a scheduled system sync but still requires the repository export opt-in', async () => {
|
|
258
|
+
const acl = { can: vi.fn() };
|
|
259
|
+
const database = {
|
|
260
|
+
getRepository: () => ({
|
|
261
|
+
findOne: vi.fn().mockResolvedValue({
|
|
262
|
+
get: (attribute: string) => {
|
|
263
|
+
if (attribute === 'localPath') return 'skills';
|
|
264
|
+
if (attribute === 'registryExportEnabled') return true;
|
|
265
|
+
return null;
|
|
266
|
+
},
|
|
267
|
+
}),
|
|
268
|
+
}),
|
|
269
|
+
} as unknown as Database;
|
|
270
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
271
|
+
|
|
272
|
+
await expect(service.resolveCommit(1, 'HEAD', scheduledSyncAccess)).resolves.toBe(commitSha);
|
|
273
|
+
expect(acl.can).not.toHaveBeenCalled();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('rejects an otherwise authorized user when repository export is disabled', async () => {
|
|
277
|
+
const acl = {
|
|
278
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
279
|
+
};
|
|
280
|
+
const database = {
|
|
281
|
+
getRepository: () => ({
|
|
282
|
+
findOne: vi.fn().mockResolvedValue({
|
|
283
|
+
get: (attribute: string) => (attribute === 'registryExportEnabled' ? false : 'skills'),
|
|
284
|
+
}),
|
|
285
|
+
}),
|
|
286
|
+
} as unknown as Database;
|
|
287
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
288
|
+
|
|
289
|
+
await expect(service.assertRepositoryAccess(1, { kind: 'user', roles: ['developer'] })).rejects.toMatchObject({
|
|
290
|
+
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('allows Skill Hub reads for a scoped user even when Registry export is disabled', async () => {
|
|
295
|
+
const acl = {
|
|
296
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
297
|
+
};
|
|
298
|
+
const database = {
|
|
299
|
+
getRepository: () => ({
|
|
300
|
+
findOne: vi.fn().mockResolvedValue({
|
|
301
|
+
get: (attribute: string) => {
|
|
302
|
+
if (attribute === 'localPath') return 'skills';
|
|
303
|
+
if (attribute === 'registryExportEnabled') return false;
|
|
304
|
+
return null;
|
|
305
|
+
},
|
|
306
|
+
}),
|
|
307
|
+
}),
|
|
308
|
+
} as unknown as Database;
|
|
309
|
+
const service = new SkillHubGitContentService(database, undefined, acl);
|
|
310
|
+
|
|
311
|
+
expect(service.contractVersion).toBe(2);
|
|
312
|
+
expect(service.capabilities).toContain('skill-hub-content-with-actor');
|
|
313
|
+
await expect(
|
|
314
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, { kind: 'user', roles: ['developer'] }),
|
|
315
|
+
).resolves.toEqual(Buffer.from([0, 255, 128, 17]));
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('rejects a Skill Hub user outside repository scope before reading the database', async () => {
|
|
319
|
+
const acl = {
|
|
320
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
321
|
+
};
|
|
322
|
+
const repositoryLookup = vi.fn();
|
|
323
|
+
const database = {
|
|
324
|
+
getRepository: repositoryLookup,
|
|
325
|
+
} as unknown as Database;
|
|
326
|
+
const service = new SkillHubGitContentService(database, undefined, acl);
|
|
327
|
+
|
|
328
|
+
await expect(service.assertRepositoryAccess(2, { kind: 'user', roles: ['developer'] })).rejects.toMatchObject({
|
|
329
|
+
code: 'SKILL_HUB_REPOSITORY_ACCESS_DENIED',
|
|
330
|
+
});
|
|
331
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('rejects a Skill Hub call without an actor before reading the database', async () => {
|
|
335
|
+
const repositoryLookup = vi.fn();
|
|
336
|
+
const database = {
|
|
337
|
+
getRepository: repositoryLookup,
|
|
338
|
+
} as unknown as Database;
|
|
339
|
+
const service = new SkillHubGitContentService(database);
|
|
340
|
+
|
|
341
|
+
await expect(service.assertRepositoryAccess(1)).rejects.toMatchObject({
|
|
342
|
+
code: 'SKILL_HUB_REPOSITORY_ACCESS_DENIED',
|
|
343
|
+
});
|
|
344
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('rejects a scheduled system actor from Skill Hub before reading the database', async () => {
|
|
348
|
+
const repositoryLookup = vi.fn();
|
|
349
|
+
const database = {
|
|
350
|
+
getRepository: repositoryLookup,
|
|
351
|
+
} as unknown as Database;
|
|
352
|
+
const service = new SkillHubGitContentService(database);
|
|
353
|
+
|
|
354
|
+
await expect(service.assertRepositoryAccess(1, scheduledSyncAccess)).rejects.toMatchObject({
|
|
355
|
+
code: 'SKILL_HUB_REPOSITORY_ACCESS_DENIED',
|
|
356
|
+
});
|
|
357
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
358
|
+
});
|
|
359
|
+
});
|