@zereight/mcp-gitlab 2.1.70 → 2.2.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/README.ko.md +3 -1
- package/README.md +6 -2
- package/README.pt-BR.md +1 -1
- package/README.zh-CN.md +3 -1
- package/build/config.js +12 -4
- package/build/deprecated-env.js +47 -0
- package/build/index.js +369 -184
- package/build/oauth-device-flow.js +80 -0
- package/build/oauth.js +135 -18
- package/build/schemas.js +1 -1
- package/build/server/remote-http-stack.js +39 -0
- package/build/tools/discover-activation.js +38 -0
- package/build/tools/exposed-tools.js +35 -0
- package/build/tools/listed-tools.js +76 -0
- package/build/tools/registry.js +226 -57
- package/build/tools/tool-profile.js +66 -0
- package/build/utils/compact-tool-allowlist.js +14 -0
- package/build/utils/logger.js +34 -12
- package/package.json +3 -3
- package/build/scripts/check-skill-sync.js +0 -143
- package/build/scripts/generate-server-card.js +0 -39
- package/build/scripts/generate-tool-coverage.js +0 -58
- package/build/scripts/generate-tool-docs.js +0 -430
- package/build/scripts/tool-coverage/coverage.js +0 -341
- package/build/scripts/tool-coverage/coverage.test.js +0 -142
- package/build/test/callback-proxy-tests.js +0 -321
- package/build/test/cli/args.test.js +0 -175
- package/build/test/cli/boolean-flags.test.js +0 -106
- package/build/test/cli/compact-mcp-result.test.js +0 -93
- package/build/test/cli/credentials.test.js +0 -153
- package/build/test/cli/exposure.test.js +0 -104
- package/build/test/cli/load-config-snapshot.js +0 -5
- package/build/test/cli/output.test.js +0 -74
- package/build/test/cli/replay-command.test.js +0 -37
- package/build/test/cli/router.test.js +0 -183
- package/build/test/client-pool-test.js +0 -109
- package/build/test/clients/client.js +0 -34
- package/build/test/clients/custom-header-client.js +0 -122
- package/build/test/clients/sse-client.js +0 -95
- package/build/test/clients/stdio-client.js +0 -113
- package/build/test/clients/streamable-http-client.js +0 -95
- package/build/test/config-allowed-groups.test.js +0 -97
- package/build/test/create-commit-actions.test.js +0 -102
- package/build/test/draft-note-schema.test.js +0 -44
- package/build/test/dynamic-api-url-allowlist.test.js +0 -121
- package/build/test/dynamic-api-url-test.js +0 -304
- package/build/test/dynamic-routing-tests.js +0 -495
- package/build/test/get-merge-request-discussion-schema.test.js +0 -30
- package/build/test/gitlab-api-tool-errors.test.js +0 -112
- package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
- package/build/test/gitlab-diff-schema.test.js +0 -36
- package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
- package/build/test/gitlab-tag-schema.test.js +0 -51
- package/build/test/group-milestone-schema.test.js +0 -45
- package/build/test/mcp-oauth-tests.js +0 -905
- package/build/test/mcp-server-name.test.js +0 -87
- package/build/test/merge-merge-request-schema.test.js +0 -75
- package/build/test/multi-server-test.js +0 -190
- package/build/test/no-proxy-integration-test.js +0 -183
- package/build/test/no-proxy-test.js +0 -149
- package/build/test/nullable-gitlab-response-fields.test.js +0 -37
- package/build/test/nullish-tool-arguments-schema.test.js +0 -118
- package/build/test/oauth-device-flow-tests.js +0 -450
- package/build/test/oauth-download-url.test.js +0 -157
- package/build/test/oauth-startup.test.js +0 -204
- package/build/test/oauth-tests.js +0 -428
- package/build/test/path-segment-encoding.test.js +0 -98
- package/build/test/remote-auth-simple-test.js +0 -277
- package/build/test/remote-auth-tests.js +0 -314
- package/build/test/response-masking.test.js +0 -445
- package/build/test/schema-tests.js +0 -1679
- package/build/test/server/metrics.test.js +0 -47
- package/build/test/server/request-helpers.test.js +0 -48
- package/build/test/server/version.test.js +0 -13
- package/build/test/sse-auth-guard.test.js +0 -96
- package/build/test/sse-session-limits.test.js +0 -273
- package/build/test/stateless/callback-proxy.test.js +0 -510
- package/build/test/stateless/client-id.test.js +0 -177
- package/build/test/stateless/codec.test.js +0 -328
- package/build/test/stateless/config-ttl.test.js +0 -149
- package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
- package/build/test/stateless/session-id-integration.test.js +0 -675
- package/build/test/stateless/session-id.test.js +0 -157
- package/build/test/streamable-http-concurrent-session.test.js +0 -171
- package/build/test/streamable-http-dns-rebinding.test.js +0 -185
- package/build/test/streamable-http-sse-stream.test.js +0 -350
- package/build/test/streamable-http-static-token-auth.test.js +0 -157
- package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
- package/build/test/test-all-transport-server.js +0 -255
- package/build/test/test-auth-retry.js +0 -195
- package/build/test/test-blank-filters.js +0 -156
- package/build/test/test-ci-catalog.js +0 -177
- package/build/test/test-ci-lint.js +0 -191
- package/build/test/test-ci-variables.js +0 -309
- package/build/test/test-create-repository.js +0 -120
- package/build/test/test-dependency-proxy.js +0 -195
- package/build/test/test-deployment-tools.js +0 -463
- package/build/test/test-download-attachment.js +0 -190
- package/build/test/test-dynamic-project-scope.js +0 -524
- package/build/test/test-empty-toolsets.js +0 -535
- package/build/test/test-get-file-blame.js +0 -145
- package/build/test/test-get-file-contents.js +0 -128
- package/build/test/test-geteffectiveprojectid.js +0 -804
- package/build/test/test-health-check.js +0 -115
- package/build/test/test-issue-description-patch.js +0 -256
- package/build/test/test-job-artifacts.js +0 -275
- package/build/test/test-json-schema.js +0 -166
- package/build/test/test-list-group-members.js +0 -150
- package/build/test/test-list-group-merge-requests.js +0 -165
- package/build/test/test-list-issues.js +0 -170
- package/build/test/test-list-merge-requests.js +0 -201
- package/build/test/test-list-milestones.js +0 -145
- package/build/test/test-list-project-members.js +0 -132
- package/build/test/test-merge-request-approval-state-tools.js +0 -213
- package/build/test/test-merge-request-approvals.js +0 -187
- package/build/test/test-merge-request-pipelines.js +0 -106
- package/build/test/test-mr-diffs-filter.js +0 -132
- package/build/test/test-mr-file-diffs.js +0 -251
- package/build/test/test-oauth-proxy-rate-limit.js +0 -133
- package/build/test/test-orbit.js +0 -155
- package/build/test/test-permission-mode.js +0 -424
- package/build/test/test-pipeline-schedules.js +0 -484
- package/build/test/test-protected-branches.js +0 -174
- package/build/test/test-remote-downloads.js +0 -510
- package/build/test/test-search-code.js +0 -275
- package/build/test/test-snippets.js +0 -735
- package/build/test/test-tags.js +0 -220
- package/build/test/test-todos.js +0 -195
- package/build/test/test-token-optimizations.js +0 -691
- package/build/test/test-toolset-filtering.js +0 -499
- package/build/test/test-update-issue-slim.js +0 -141
- package/build/test/test-update-project.js +0 -112
- package/build/test/test-upload-markdown.js +0 -206
- package/build/test/test-vulnerabilities.js +0 -399
- package/build/test/test-webhooks.js +0 -218
- package/build/test/tool-description-quality.test.js +0 -50
- package/build/test/utils/bulk-publish-options.test.js +0 -32
- package/build/test/utils/download-token.test.js +0 -35
- package/build/test/utils/forwarded-public-base-url.test.js +0 -46
- package/build/test/utils/gitlab-instance-version.test.js +0 -32
- package/build/test/utils/gitlab-version-gate.test.js +0 -74
- package/build/test/utils/graphql-query.test.js +0 -168
- package/build/test/utils/helpers-path.test.js +0 -104
- package/build/test/utils/jmespath-tool-result.test.js +0 -91
- package/build/test/utils/masking.test.js +0 -384
- package/build/test/utils/merge-request-position.test.js +0 -57
- package/build/test/utils/mock-gitlab-server.js +0 -614
- package/build/test/utils/proxy-client-ip.test.js +0 -28
- package/build/test/utils/redact-sensitive.test.js +0 -32
- package/build/test/utils/safe-redirect-fetch.test.js +0 -463
- package/build/test/utils/server-launcher.js +0 -231
- package/build/test/utils/tool-args.test.js +0 -210
- package/build/test/utils/url.test.js +0 -141
- package/build/test/utils/version-check.test.js +0 -239
- package/build/test/utils/wiki-title.test.js +0 -21
- package/build/test-note.js +0 -54
- package/build/test-resolve-issue-note.js +0 -127
|
@@ -1,1679 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
import { GetFileContentsSchema, GitLabFileContentSchema, GitLabRepositorySchema, CreatePipelineSchema, CreateCommitStatusSchema, ListCommitStatusesSchema, CreateIssueNoteSchema, CreateMergeRequestEmojiReactionSchema, CreateIssueEmojiReactionSchema, DeleteMergeRequestEmojiReactionSchema, DeleteIssueEmojiReactionSchema, CreateWorkItemEmojiReactionSchema, CreateWorkItemNoteEmojiReactionSchema, CreateIssueSchema, ListIssuesSchema, ListMergeRequestsSchema, ListLabelsSchema, GitLabMergeRequestSchema, GitLabTreeItemSchema, GetMergeRequestSchema, ListMergeRequestPipelinesSchema, GetRepositoryTreeSchema, GitLabUserFullSchema, GitLabMarkdownUploadSchema, GitLabDependencyProxySchema, GitLabDependencyProxyBlobSchema, PushFilesSchema, CreateOrUpdateFileSchema, } from '../schemas.js';
|
|
3
|
-
function runGetFileContentsSchemaTests() {
|
|
4
|
-
console.log('🧪 Testing GetFileContentsSchema...');
|
|
5
|
-
const cases = [
|
|
6
|
-
{
|
|
7
|
-
name: 'schema:get_file_contents:path-only',
|
|
8
|
-
input: { path: 'package.json' },
|
|
9
|
-
expected: { file_path: 'package.json', project_id: undefined, ref: undefined }
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
name: 'schema:get_file_contents:file-path-precedence',
|
|
13
|
-
input: { file_path: ' README.md ', path: 'package.json' },
|
|
14
|
-
expected: { file_path: 'README.md', project_id: undefined, ref: undefined }
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
name: 'schema:get_file_contents:project-id-trim',
|
|
18
|
-
input: { project_id: ' 123 ', file_path: 'a.txt' },
|
|
19
|
-
expected: { project_id: '123', file_path: 'a.txt', ref: undefined }
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
name: 'schema:get_file_contents:ref-trim-to-undefined',
|
|
23
|
-
input: { file_path: 'a.txt', ref: ' ' },
|
|
24
|
-
expected: { file_path: 'a.txt', project_id: undefined, ref: undefined }
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'schema:get_file_contents:file-path-empty-fallback-to-path',
|
|
28
|
-
input: { file_path: ' ', path: ' src/index.ts ' },
|
|
29
|
-
expected: { file_path: 'src/index.ts', project_id: undefined, ref: undefined }
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: 'schema:get_file_contents:project-id-omitted-remains-undefined',
|
|
33
|
-
input: { file_path: 'README.md' },
|
|
34
|
-
expected: { file_path: 'README.md', project_id: undefined, ref: undefined }
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'schema:get_file_contents:reject-empty-path',
|
|
38
|
-
input: { path: ' ' },
|
|
39
|
-
shouldFail: true
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: 'schema:get_file_contents:reject-both-empty-after-trim',
|
|
43
|
-
input: { file_path: ' ', path: ' ' },
|
|
44
|
-
shouldFail: true
|
|
45
|
-
}
|
|
46
|
-
];
|
|
47
|
-
let passed = 0;
|
|
48
|
-
let failed = 0;
|
|
49
|
-
cases.forEach(testCase => {
|
|
50
|
-
const result = {
|
|
51
|
-
name: testCase.name,
|
|
52
|
-
status: 'failed'
|
|
53
|
-
};
|
|
54
|
-
const parsed = GetFileContentsSchema.safeParse(testCase.input);
|
|
55
|
-
if (testCase.shouldFail) {
|
|
56
|
-
if (parsed.success) {
|
|
57
|
-
result.error = 'Expected schema validation to fail';
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
result.status = 'passed';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else if (parsed.success) {
|
|
64
|
-
const { project_id, file_path, ref } = parsed.data;
|
|
65
|
-
const expected = testCase.expected || {};
|
|
66
|
-
const matches = project_id === expected.project_id && file_path === expected.file_path && ref === expected.ref;
|
|
67
|
-
if (matches) {
|
|
68
|
-
result.status = 'passed';
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
76
|
-
}
|
|
77
|
-
if (result.status === 'passed') {
|
|
78
|
-
passed++;
|
|
79
|
-
console.log(`✅ ${result.name}`);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
failed++;
|
|
83
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
87
|
-
return { passed, failed };
|
|
88
|
-
}
|
|
89
|
-
function runGitLabFileContentSchemaTests() {
|
|
90
|
-
console.log('\n🧪 Testing GitLabFileContentSchema...');
|
|
91
|
-
const cases = [
|
|
92
|
-
{
|
|
93
|
-
name: 'schema:gitlab_file_content:minimal-required-fields',
|
|
94
|
-
input: {
|
|
95
|
-
file_path: 'README.md',
|
|
96
|
-
encoding: 'base64',
|
|
97
|
-
content: 'IyBSRUFETUU='
|
|
98
|
-
},
|
|
99
|
-
expected: {
|
|
100
|
-
file_path: 'README.md',
|
|
101
|
-
encoding: 'base64',
|
|
102
|
-
content: 'IyBSRUFETUU='
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
name: 'schema:gitlab_file_content:optional-size-coerces-to-number',
|
|
107
|
-
input: {
|
|
108
|
-
file_name: 'README.md',
|
|
109
|
-
file_path: 'README.md',
|
|
110
|
-
size: '42',
|
|
111
|
-
encoding: 'base64',
|
|
112
|
-
content: 'IyBSRUFETUU=',
|
|
113
|
-
ref: 'main'
|
|
114
|
-
},
|
|
115
|
-
expected: {
|
|
116
|
-
file_name: 'README.md',
|
|
117
|
-
file_path: 'README.md',
|
|
118
|
-
size: 42,
|
|
119
|
-
encoding: 'base64',
|
|
120
|
-
content: 'IyBSRUFETUU=',
|
|
121
|
-
ref: 'main'
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: 'schema:gitlab_file_content:reject-missing-content',
|
|
126
|
-
input: {
|
|
127
|
-
file_path: 'README.md',
|
|
128
|
-
encoding: 'base64'
|
|
129
|
-
},
|
|
130
|
-
shouldFail: true
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
name: 'schema:gitlab_file_content:reject-missing-encoding',
|
|
134
|
-
input: {
|
|
135
|
-
file_path: 'README.md',
|
|
136
|
-
content: 'IyBSRUFETUU='
|
|
137
|
-
},
|
|
138
|
-
shouldFail: true
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
name: 'schema:gitlab_file_content:reject-missing-file-path',
|
|
142
|
-
input: {
|
|
143
|
-
encoding: 'base64',
|
|
144
|
-
content: 'IyBSRUFETUU='
|
|
145
|
-
},
|
|
146
|
-
shouldFail: true
|
|
147
|
-
}
|
|
148
|
-
];
|
|
149
|
-
let passed = 0;
|
|
150
|
-
let failed = 0;
|
|
151
|
-
cases.forEach(testCase => {
|
|
152
|
-
const result = {
|
|
153
|
-
name: testCase.name,
|
|
154
|
-
status: 'failed'
|
|
155
|
-
};
|
|
156
|
-
const parsed = GitLabFileContentSchema.safeParse(testCase.input);
|
|
157
|
-
if (testCase.shouldFail) {
|
|
158
|
-
if (parsed.success) {
|
|
159
|
-
result.error = 'Expected schema validation to fail';
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
result.status = 'passed';
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else if (parsed.success) {
|
|
166
|
-
const expected = testCase.expected || {};
|
|
167
|
-
const matches = Object.entries(expected).every(([key, value]) => {
|
|
168
|
-
return parsed.data[key] === value;
|
|
169
|
-
});
|
|
170
|
-
if (matches) {
|
|
171
|
-
result.status = 'passed';
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
179
|
-
}
|
|
180
|
-
if (result.status === 'passed') {
|
|
181
|
-
passed++;
|
|
182
|
-
console.log(`✅ ${result.name}`);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
failed++;
|
|
186
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
190
|
-
return { passed, failed };
|
|
191
|
-
}
|
|
192
|
-
function runCreatePipelineSchemaTests() {
|
|
193
|
-
console.log('\n🧪 Testing CreatePipelineSchema...');
|
|
194
|
-
const cases = [
|
|
195
|
-
{
|
|
196
|
-
name: 'schema:create_pipeline:minimal-required-fields',
|
|
197
|
-
input: { project_id: 'my/project', ref: 'main' },
|
|
198
|
-
expected: { project_id: 'my/project', ref: 'main' }
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
name: 'schema:create_pipeline:with-variables-only',
|
|
202
|
-
input: {
|
|
203
|
-
project_id: 'my/project',
|
|
204
|
-
ref: 'main',
|
|
205
|
-
variables: [{ key: 'ENV', value: 'production' }]
|
|
206
|
-
},
|
|
207
|
-
expected: {
|
|
208
|
-
project_id: 'my/project',
|
|
209
|
-
ref: 'main',
|
|
210
|
-
variables: [{ key: 'ENV', value: 'production' }]
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
name: 'schema:create_pipeline:with-inputs-only',
|
|
215
|
-
input: {
|
|
216
|
-
project_id: 'my/project',
|
|
217
|
-
ref: 'main',
|
|
218
|
-
inputs: { deploy_target: 'staging', version: '1.0.0' }
|
|
219
|
-
},
|
|
220
|
-
expected: {
|
|
221
|
-
project_id: 'my/project',
|
|
222
|
-
ref: 'main',
|
|
223
|
-
inputs: { deploy_target: 'staging', version: '1.0.0' }
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
name: 'schema:create_pipeline:with-variables-and-inputs',
|
|
228
|
-
input: {
|
|
229
|
-
project_id: 'my/project',
|
|
230
|
-
ref: 'develop',
|
|
231
|
-
variables: [{ key: 'CI', value: 'true' }],
|
|
232
|
-
inputs: { env: 'test' }
|
|
233
|
-
},
|
|
234
|
-
expected: {
|
|
235
|
-
project_id: 'my/project',
|
|
236
|
-
ref: 'develop',
|
|
237
|
-
variables: [{ key: 'CI', value: 'true' }],
|
|
238
|
-
inputs: { env: 'test' }
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
name: 'schema:create_pipeline:project-id-coercion',
|
|
243
|
-
input: { project_id: 123, ref: 'main' },
|
|
244
|
-
expected: { project_id: '123', ref: 'main' }
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
name: 'schema:create_pipeline:reject-missing-ref',
|
|
248
|
-
input: { project_id: 'my/project' },
|
|
249
|
-
shouldFail: true
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
name: 'schema:create_pipeline:reject-invalid-inputs-type',
|
|
253
|
-
input: { project_id: 'my/project', ref: 'main', inputs: 'not-an-object' },
|
|
254
|
-
shouldFail: true
|
|
255
|
-
}
|
|
256
|
-
];
|
|
257
|
-
let passed = 0;
|
|
258
|
-
let failed = 0;
|
|
259
|
-
cases.forEach(testCase => {
|
|
260
|
-
const result = {
|
|
261
|
-
name: testCase.name,
|
|
262
|
-
status: 'failed'
|
|
263
|
-
};
|
|
264
|
-
const parsed = CreatePipelineSchema.safeParse(testCase.input);
|
|
265
|
-
if (testCase.shouldFail) {
|
|
266
|
-
if (parsed.success) {
|
|
267
|
-
result.error = 'Expected schema validation to fail';
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
result.status = 'passed';
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
else if (parsed.success) {
|
|
274
|
-
const expected = testCase.expected || {};
|
|
275
|
-
const matches = Object.entries(expected).every(([key, value]) => {
|
|
276
|
-
const actual = parsed.data[key];
|
|
277
|
-
return JSON.stringify(actual) === JSON.stringify(value);
|
|
278
|
-
});
|
|
279
|
-
if (matches) {
|
|
280
|
-
result.status = 'passed';
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
288
|
-
}
|
|
289
|
-
if (result.status === 'passed') {
|
|
290
|
-
passed++;
|
|
291
|
-
console.log(`✅ ${result.name}`);
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
failed++;
|
|
295
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
299
|
-
return { passed, failed };
|
|
300
|
-
}
|
|
301
|
-
function runCommitStatusSchemaTests() {
|
|
302
|
-
console.log('\n🧪 Testing Commit Status Schemas...');
|
|
303
|
-
const cases = [
|
|
304
|
-
{
|
|
305
|
-
name: 'schema:create_commit_status:minimal-required-fields',
|
|
306
|
-
schema: CreateCommitStatusSchema,
|
|
307
|
-
input: { project_id: 'my/project', sha: 'abc123', state: 'success' },
|
|
308
|
-
expected: { project_id: 'my/project', sha: 'abc123', state: 'success' }
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
name: 'schema:create_commit_status:with-optional-fields',
|
|
312
|
-
schema: CreateCommitStatusSchema,
|
|
313
|
-
input: {
|
|
314
|
-
project_id: 'my/project',
|
|
315
|
-
sha: 'abc123',
|
|
316
|
-
state: 'failed',
|
|
317
|
-
name: 'external/check',
|
|
318
|
-
target_url: 'https://ci.example.com/build/1',
|
|
319
|
-
description: 'External check failed',
|
|
320
|
-
coverage: '87.5',
|
|
321
|
-
pipeline_id: '42'
|
|
322
|
-
},
|
|
323
|
-
expected: {
|
|
324
|
-
project_id: 'my/project',
|
|
325
|
-
sha: 'abc123',
|
|
326
|
-
state: 'failed',
|
|
327
|
-
name: 'external/check',
|
|
328
|
-
target_url: 'https://ci.example.com/build/1',
|
|
329
|
-
description: 'External check failed',
|
|
330
|
-
coverage: 87.5,
|
|
331
|
-
pipeline_id: 42
|
|
332
|
-
}
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
name: 'schema:create_commit_status:context-alias',
|
|
336
|
-
schema: CreateCommitStatusSchema,
|
|
337
|
-
input: { project_id: 123, sha: 'abc123', state: 'pending', context: 'external/check' },
|
|
338
|
-
expected: { project_id: '123', sha: 'abc123', state: 'pending', context: 'external/check' }
|
|
339
|
-
},
|
|
340
|
-
{
|
|
341
|
-
name: 'schema:create_commit_status:reject-invalid-state',
|
|
342
|
-
schema: CreateCommitStatusSchema,
|
|
343
|
-
input: { project_id: 'my/project', sha: 'abc123', state: 'passing' },
|
|
344
|
-
shouldFail: true
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
name: 'schema:create_commit_status:reject-missing-state',
|
|
348
|
-
schema: CreateCommitStatusSchema,
|
|
349
|
-
input: { project_id: 'my/project', sha: 'abc123' },
|
|
350
|
-
shouldFail: true
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
name: 'schema:list_commit_statuses:filters',
|
|
354
|
-
schema: ListCommitStatusesSchema,
|
|
355
|
-
input: {
|
|
356
|
-
project_id: 'my/project',
|
|
357
|
-
sha: 'abc123',
|
|
358
|
-
ref: 'main',
|
|
359
|
-
name: 'external/check',
|
|
360
|
-
pipeline_id: '42',
|
|
361
|
-
order_by: 'pipeline_id',
|
|
362
|
-
sort: 'desc',
|
|
363
|
-
all: 'true',
|
|
364
|
-
page: '2',
|
|
365
|
-
per_page: '50'
|
|
366
|
-
},
|
|
367
|
-
expected: {
|
|
368
|
-
project_id: 'my/project',
|
|
369
|
-
sha: 'abc123',
|
|
370
|
-
ref: 'main',
|
|
371
|
-
name: 'external/check',
|
|
372
|
-
pipeline_id: 42,
|
|
373
|
-
order_by: 'pipeline_id',
|
|
374
|
-
sort: 'desc',
|
|
375
|
-
all: true,
|
|
376
|
-
page: 2,
|
|
377
|
-
per_page: 50
|
|
378
|
-
}
|
|
379
|
-
},
|
|
380
|
-
{
|
|
381
|
-
name: 'schema:list_commit_statuses:all-false-string',
|
|
382
|
-
schema: ListCommitStatusesSchema,
|
|
383
|
-
input: { project_id: 'my/project', sha: 'abc123', all: 'false' },
|
|
384
|
-
expected: { project_id: 'my/project', sha: 'abc123', all: false }
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
name: 'schema:list_commit_statuses:reject-invalid-all-string',
|
|
388
|
-
schema: ListCommitStatusesSchema,
|
|
389
|
-
input: { project_id: 'my/project', sha: 'abc123', all: 'yes' },
|
|
390
|
-
shouldFail: true
|
|
391
|
-
}
|
|
392
|
-
];
|
|
393
|
-
let passed = 0;
|
|
394
|
-
let failed = 0;
|
|
395
|
-
cases.forEach(testCase => {
|
|
396
|
-
const result = {
|
|
397
|
-
name: testCase.name,
|
|
398
|
-
status: 'failed'
|
|
399
|
-
};
|
|
400
|
-
const parsed = testCase.schema.safeParse(testCase.input);
|
|
401
|
-
if (testCase.shouldFail) {
|
|
402
|
-
if (parsed.success) {
|
|
403
|
-
result.error = 'Expected schema validation to fail';
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
result.status = 'passed';
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
else if (parsed.success) {
|
|
410
|
-
const expected = testCase.expected || {};
|
|
411
|
-
const matches = Object.entries(expected).every(([key, value]) => {
|
|
412
|
-
const actual = parsed.data[key];
|
|
413
|
-
return JSON.stringify(actual) === JSON.stringify(value);
|
|
414
|
-
});
|
|
415
|
-
if (matches) {
|
|
416
|
-
result.status = 'passed';
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
424
|
-
}
|
|
425
|
-
if (result.status === 'passed') {
|
|
426
|
-
passed++;
|
|
427
|
-
console.log(`✅ ${result.name}`);
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
failed++;
|
|
431
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
435
|
-
return { passed, failed };
|
|
436
|
-
}
|
|
437
|
-
function runCreateIssueNoteSchemaTests() {
|
|
438
|
-
console.log('\n🧪 Testing CreateIssueNoteSchema...');
|
|
439
|
-
const cases = [
|
|
440
|
-
{
|
|
441
|
-
name: 'schema:create_issue_note:top-level-note-without-discussion-id',
|
|
442
|
-
input: { project_id: 'my/project', issue_iid: '42', body: 'A comment' },
|
|
443
|
-
expected: { project_id: 'my/project', issue_iid: '42', body: 'A comment', discussion_id: undefined }
|
|
444
|
-
},
|
|
445
|
-
{
|
|
446
|
-
name: 'schema:create_issue_note:reply-with-discussion-id',
|
|
447
|
-
input: { project_id: 'my/project', issue_iid: '42', discussion_id: 'abc123', body: 'A reply' },
|
|
448
|
-
expected: { project_id: 'my/project', issue_iid: '42', discussion_id: 'abc123', body: 'A reply' }
|
|
449
|
-
},
|
|
450
|
-
{
|
|
451
|
-
name: 'schema:create_issue_note:with-created-at',
|
|
452
|
-
input: { project_id: 'my/project', issue_iid: '7', body: 'Note', created_at: '2025-01-01T00:00:00Z' },
|
|
453
|
-
expected: { project_id: 'my/project', issue_iid: '7', body: 'Note', created_at: '2025-01-01T00:00:00Z' }
|
|
454
|
-
},
|
|
455
|
-
{
|
|
456
|
-
name: 'schema:create_issue_note:numeric-issue-iid-coerced',
|
|
457
|
-
input: { project_id: 'my/project', issue_iid: 99, body: 'Coerced' },
|
|
458
|
-
expected: { project_id: 'my/project', issue_iid: '99', body: 'Coerced' }
|
|
459
|
-
},
|
|
460
|
-
{
|
|
461
|
-
name: 'schema:create_issue_note:reject-missing-body',
|
|
462
|
-
input: { project_id: 'my/project', issue_iid: '1' },
|
|
463
|
-
shouldFail: true
|
|
464
|
-
}
|
|
465
|
-
];
|
|
466
|
-
let passed = 0;
|
|
467
|
-
let failed = 0;
|
|
468
|
-
cases.forEach(testCase => {
|
|
469
|
-
const result = {
|
|
470
|
-
name: testCase.name,
|
|
471
|
-
status: 'failed'
|
|
472
|
-
};
|
|
473
|
-
const parsed = CreateIssueNoteSchema.safeParse(testCase.input);
|
|
474
|
-
if (testCase.shouldFail) {
|
|
475
|
-
if (parsed.success) {
|
|
476
|
-
result.error = 'Expected schema validation to fail';
|
|
477
|
-
}
|
|
478
|
-
else {
|
|
479
|
-
result.status = 'passed';
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
else if (parsed.success) {
|
|
483
|
-
const expected = testCase.expected || {};
|
|
484
|
-
const matches = Object.entries(expected).every(([key, value]) => {
|
|
485
|
-
const actual = parsed.data[key];
|
|
486
|
-
return actual === value;
|
|
487
|
-
});
|
|
488
|
-
if (matches) {
|
|
489
|
-
result.status = 'passed';
|
|
490
|
-
}
|
|
491
|
-
else {
|
|
492
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
497
|
-
}
|
|
498
|
-
if (result.status === 'passed') {
|
|
499
|
-
passed++;
|
|
500
|
-
console.log(`✅ ${result.name}`);
|
|
501
|
-
}
|
|
502
|
-
else {
|
|
503
|
-
failed++;
|
|
504
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
508
|
-
return { passed, failed };
|
|
509
|
-
}
|
|
510
|
-
function runGetMergeRequestSchemaTests() {
|
|
511
|
-
console.log('\n🧪 Testing GetMergeRequestSchema...');
|
|
512
|
-
const cases = [
|
|
513
|
-
{
|
|
514
|
-
name: 'schema:get_merge_request:with-project-id-and-merge-request-iid',
|
|
515
|
-
input: { project_id: 'my/project', merge_request_iid: '42' },
|
|
516
|
-
expected: { project_id: 'my/project', merge_request_iid: '42' },
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
name: 'schema:get_merge_request:with-project-id-and-source-branch',
|
|
520
|
-
input: { project_id: 'my/project', source_branch: 'feature-branch' },
|
|
521
|
-
expected: { project_id: 'my/project', source_branch: 'feature-branch' },
|
|
522
|
-
},
|
|
523
|
-
{
|
|
524
|
-
name: 'schema:get_merge_request:with-all-params',
|
|
525
|
-
input: { project_id: 'my/project', merge_request_iid: '42', source_branch: 'feature-branch' },
|
|
526
|
-
expected: {
|
|
527
|
-
project_id: 'my/project',
|
|
528
|
-
merge_request_iid: '42',
|
|
529
|
-
source_branch: 'feature-branch',
|
|
530
|
-
},
|
|
531
|
-
},
|
|
532
|
-
{
|
|
533
|
-
name: 'schema:get_merge_request:coerced-merge-request-iid',
|
|
534
|
-
input: { project_id: 'my/project', merge_request_iid: 24 },
|
|
535
|
-
expected: { project_id: 'my/project', merge_request_iid: '24' },
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
name: 'schema:get_merge_request:coerced-project-id',
|
|
539
|
-
input: { project_id: 123, merge_request_iid: '42' },
|
|
540
|
-
expected: { project_id: '123', merge_request_iid: '42' },
|
|
541
|
-
},
|
|
542
|
-
{
|
|
543
|
-
name: 'schema:get_merge_request:coerced-source-branch',
|
|
544
|
-
input: { project_id: 'my/project', source_branch: 'feature' },
|
|
545
|
-
expected: { project_id: 'my/project', source_branch: 'feature' },
|
|
546
|
-
},
|
|
547
|
-
{
|
|
548
|
-
name: 'schema:get_merge_request:reject-missing-project-id-with-merge-request-iid',
|
|
549
|
-
input: { merge_request_iid: '42' },
|
|
550
|
-
shouldFail: true,
|
|
551
|
-
},
|
|
552
|
-
{
|
|
553
|
-
name: 'schema:get_merge_request:reject-missing-project-id-with-source-branch',
|
|
554
|
-
input: { source_branch: 'feature' },
|
|
555
|
-
shouldFail: true,
|
|
556
|
-
},
|
|
557
|
-
{
|
|
558
|
-
name: 'schema:get_merge_request:allow-empty-project-id-for-default-project',
|
|
559
|
-
input: { project_id: '', merge_request_iid: '42' },
|
|
560
|
-
expected: { project_id: '', merge_request_iid: '42' },
|
|
561
|
-
},
|
|
562
|
-
{
|
|
563
|
-
name: 'schema:get_merge_request:reject-whitespace-project-id',
|
|
564
|
-
input: { project_id: ' ', merge_request_iid: '42' },
|
|
565
|
-
shouldFail: true,
|
|
566
|
-
},
|
|
567
|
-
];
|
|
568
|
-
let passed = 0;
|
|
569
|
-
let failed = 0;
|
|
570
|
-
cases.forEach(testCase => {
|
|
571
|
-
const result = {
|
|
572
|
-
name: testCase.name,
|
|
573
|
-
status: 'failed'
|
|
574
|
-
};
|
|
575
|
-
const parsed = GetMergeRequestSchema.safeParse(testCase.input);
|
|
576
|
-
if (testCase.shouldFail) {
|
|
577
|
-
if (parsed.success) {
|
|
578
|
-
result.error = 'Expected schema validation to fail';
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
result.status = 'passed';
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
else if (parsed.success) {
|
|
585
|
-
const expected = testCase.expected || {};
|
|
586
|
-
const matches = Object.entries(expected).every(([key, value]) => {
|
|
587
|
-
const actual = parsed.data[key];
|
|
588
|
-
return actual === value;
|
|
589
|
-
});
|
|
590
|
-
if (matches) {
|
|
591
|
-
result.status = 'passed';
|
|
592
|
-
}
|
|
593
|
-
else {
|
|
594
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
else {
|
|
598
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
599
|
-
}
|
|
600
|
-
if (result.status === 'passed') {
|
|
601
|
-
passed++;
|
|
602
|
-
console.log(`✅ ${result.name}`);
|
|
603
|
-
}
|
|
604
|
-
else {
|
|
605
|
-
failed++;
|
|
606
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
610
|
-
return { passed, failed };
|
|
611
|
-
}
|
|
612
|
-
function runListMergeRequestPipelinesSchemaTests() {
|
|
613
|
-
console.log('\n🧪 Testing ListMergeRequestPipelinesSchema...');
|
|
614
|
-
const cases = [
|
|
615
|
-
{
|
|
616
|
-
name: 'schema:list_merge_request_pipelines:minimal-required-fields',
|
|
617
|
-
input: { project_id: 'my/project', merge_request_iid: '42' },
|
|
618
|
-
expected: { project_id: 'my/project', merge_request_iid: '42' },
|
|
619
|
-
},
|
|
620
|
-
{
|
|
621
|
-
name: 'schema:list_merge_request_pipelines:coerces-pagination',
|
|
622
|
-
input: { project_id: 123, merge_request_iid: 42, page: '2', per_page: '10' },
|
|
623
|
-
expected: { project_id: '123', merge_request_iid: '42', page: 2, per_page: 10 },
|
|
624
|
-
},
|
|
625
|
-
{
|
|
626
|
-
name: 'schema:list_merge_request_pipelines:reject-missing-merge-request-iid',
|
|
627
|
-
input: { project_id: 'my/project' },
|
|
628
|
-
shouldFail: true,
|
|
629
|
-
},
|
|
630
|
-
];
|
|
631
|
-
let passed = 0;
|
|
632
|
-
let failed = 0;
|
|
633
|
-
cases.forEach(testCase => {
|
|
634
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
635
|
-
const parsed = ListMergeRequestPipelinesSchema.safeParse(testCase.input);
|
|
636
|
-
if (testCase.shouldFail) {
|
|
637
|
-
result.status = parsed.success ? 'failed' : 'passed';
|
|
638
|
-
if (parsed.success)
|
|
639
|
-
result.error = 'Expected schema validation to fail';
|
|
640
|
-
}
|
|
641
|
-
else if (parsed.success) {
|
|
642
|
-
const expected = testCase.expected || {};
|
|
643
|
-
const matches = Object.entries(expected).every(([key, value]) => {
|
|
644
|
-
const actual = parsed.data[key];
|
|
645
|
-
return actual === value;
|
|
646
|
-
});
|
|
647
|
-
result.status = matches ? 'passed' : 'failed';
|
|
648
|
-
if (!matches)
|
|
649
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
650
|
-
}
|
|
651
|
-
else {
|
|
652
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
653
|
-
}
|
|
654
|
-
if (result.status === 'passed') {
|
|
655
|
-
passed++;
|
|
656
|
-
console.log(`✅ ${result.name}`);
|
|
657
|
-
}
|
|
658
|
-
else {
|
|
659
|
-
failed++;
|
|
660
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
661
|
-
}
|
|
662
|
-
});
|
|
663
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
664
|
-
return { passed, failed };
|
|
665
|
-
}
|
|
666
|
-
function runGitLabMergeRequestSchemaTests() {
|
|
667
|
-
console.log('\n🧪 Testing GitLabMergeRequestSchema...');
|
|
668
|
-
const baseMergeRequest = {
|
|
669
|
-
id: '1001',
|
|
670
|
-
iid: '42',
|
|
671
|
-
project_id: '123',
|
|
672
|
-
title: 'Add milestone exposure',
|
|
673
|
-
description: 'Expose MR milestone',
|
|
674
|
-
state: 'opened',
|
|
675
|
-
author: {
|
|
676
|
-
id: '1',
|
|
677
|
-
username: 'octocat',
|
|
678
|
-
name: 'Octo Cat',
|
|
679
|
-
avatar_url: null,
|
|
680
|
-
web_url: 'https://gitlab.example.com/octocat',
|
|
681
|
-
},
|
|
682
|
-
assignees: [],
|
|
683
|
-
reviewers: [],
|
|
684
|
-
source_branch: 'feature/milestone',
|
|
685
|
-
target_branch: 'main',
|
|
686
|
-
web_url: 'https://gitlab.example.com/group/project/-/merge_requests/42',
|
|
687
|
-
created_at: '2026-05-07T00:00:00.000Z',
|
|
688
|
-
updated_at: '2026-05-07T00:00:00.000Z',
|
|
689
|
-
merged_at: null,
|
|
690
|
-
closed_at: null,
|
|
691
|
-
merge_commit_sha: null,
|
|
692
|
-
};
|
|
693
|
-
const cases = [
|
|
694
|
-
{
|
|
695
|
-
name: 'schema:gitlab_merge_request:preserves-milestone',
|
|
696
|
-
input: {
|
|
697
|
-
...baseMergeRequest,
|
|
698
|
-
milestone: {
|
|
699
|
-
id: '5',
|
|
700
|
-
iid: '2',
|
|
701
|
-
title: 'v1.0',
|
|
702
|
-
description: 'Version 1.0',
|
|
703
|
-
state: 'active',
|
|
704
|
-
web_url: 'https://gitlab.example.com/group/project/-/milestones/2',
|
|
705
|
-
},
|
|
706
|
-
},
|
|
707
|
-
validate: (data) => data.milestone?.title === 'v1.0' &&
|
|
708
|
-
data.milestone?.id === '5' &&
|
|
709
|
-
data.milestone?.iid === '2',
|
|
710
|
-
},
|
|
711
|
-
{
|
|
712
|
-
name: 'schema:gitlab_merge_request:allows-null-milestone',
|
|
713
|
-
input: {
|
|
714
|
-
...baseMergeRequest,
|
|
715
|
-
milestone: null,
|
|
716
|
-
},
|
|
717
|
-
validate: (data) => data.milestone === null,
|
|
718
|
-
},
|
|
719
|
-
{
|
|
720
|
-
name: 'schema:gitlab_merge_request:allows-omitted-milestone',
|
|
721
|
-
input: {
|
|
722
|
-
...baseMergeRequest,
|
|
723
|
-
},
|
|
724
|
-
validate: (data) => data.milestone === undefined,
|
|
725
|
-
},
|
|
726
|
-
{
|
|
727
|
-
name: 'schema:gitlab_merge_request:labels-string-array',
|
|
728
|
-
input: {
|
|
729
|
-
...baseMergeRequest,
|
|
730
|
-
labels: ['bug', 'enhancement'],
|
|
731
|
-
},
|
|
732
|
-
validate: (data) => Array.isArray(data.labels) &&
|
|
733
|
-
data.labels.length === 2 &&
|
|
734
|
-
data.labels[0] === 'bug' &&
|
|
735
|
-
data.labels[1] === 'enhancement',
|
|
736
|
-
},
|
|
737
|
-
{
|
|
738
|
-
name: 'schema:gitlab_merge_request:labels-object-array',
|
|
739
|
-
input: {
|
|
740
|
-
...baseMergeRequest,
|
|
741
|
-
labels: [
|
|
742
|
-
{
|
|
743
|
-
id: 1,
|
|
744
|
-
name: 'bug',
|
|
745
|
-
color: '#ff0000',
|
|
746
|
-
text_color: '#ffffff',
|
|
747
|
-
description: null,
|
|
748
|
-
description_html: null,
|
|
749
|
-
},
|
|
750
|
-
{
|
|
751
|
-
id: 2,
|
|
752
|
-
name: 'enhancement',
|
|
753
|
-
color: '#00ff00',
|
|
754
|
-
text_color: '#000000',
|
|
755
|
-
description: 'Improvements',
|
|
756
|
-
description_html: '<p>Improvements</p>',
|
|
757
|
-
},
|
|
758
|
-
],
|
|
759
|
-
},
|
|
760
|
-
validate: (data) => Array.isArray(data.labels) &&
|
|
761
|
-
data.labels.length === 2 &&
|
|
762
|
-
data.labels[0].name === 'bug' &&
|
|
763
|
-
data.labels[0].id === '1' &&
|
|
764
|
-
data.labels[1].name === 'enhancement' &&
|
|
765
|
-
data.labels[1].id === '2',
|
|
766
|
-
},
|
|
767
|
-
{
|
|
768
|
-
name: 'schema:gitlab_merge_request:labels-omitted',
|
|
769
|
-
input: {
|
|
770
|
-
...baseMergeRequest,
|
|
771
|
-
},
|
|
772
|
-
validate: (data) => data.labels === undefined,
|
|
773
|
-
},
|
|
774
|
-
{
|
|
775
|
-
name: 'schema:gitlab_merge_request:preserves-merge-user',
|
|
776
|
-
input: {
|
|
777
|
-
...baseMergeRequest,
|
|
778
|
-
state: 'merged',
|
|
779
|
-
merged_at: '2026-05-08T00:00:00.000Z',
|
|
780
|
-
merge_commit_sha: 'abc123',
|
|
781
|
-
merge_user: {
|
|
782
|
-
id: '7',
|
|
783
|
-
username: 'merger',
|
|
784
|
-
name: 'Merge Bot',
|
|
785
|
-
avatar_url: null,
|
|
786
|
-
web_url: 'https://gitlab.example.com/merger',
|
|
787
|
-
},
|
|
788
|
-
},
|
|
789
|
-
validate: (data) => data.merge_user?.id === '7' &&
|
|
790
|
-
data.merge_user?.username === 'merger' &&
|
|
791
|
-
data.merge_user?.name === 'Merge Bot',
|
|
792
|
-
},
|
|
793
|
-
{
|
|
794
|
-
name: 'schema:gitlab_merge_request:preserves-merged-by',
|
|
795
|
-
input: {
|
|
796
|
-
...baseMergeRequest,
|
|
797
|
-
state: 'merged',
|
|
798
|
-
merged_by: {
|
|
799
|
-
id: '8',
|
|
800
|
-
username: 'legacy-merger',
|
|
801
|
-
name: 'Legacy Merger',
|
|
802
|
-
avatar_url: null,
|
|
803
|
-
web_url: 'https://gitlab.example.com/legacy-merger',
|
|
804
|
-
},
|
|
805
|
-
},
|
|
806
|
-
validate: (data) => data.merged_by?.id === '8' &&
|
|
807
|
-
data.merged_by?.username === 'legacy-merger',
|
|
808
|
-
},
|
|
809
|
-
{
|
|
810
|
-
name: 'schema:gitlab_merge_request:allows-null-merge-user',
|
|
811
|
-
input: {
|
|
812
|
-
...baseMergeRequest,
|
|
813
|
-
merge_user: null,
|
|
814
|
-
merged_by: null,
|
|
815
|
-
},
|
|
816
|
-
validate: (data) => data.merge_user === null && data.merged_by === null,
|
|
817
|
-
},
|
|
818
|
-
{
|
|
819
|
-
name: 'schema:gitlab_merge_request:allows-omitted-merge-user',
|
|
820
|
-
input: {
|
|
821
|
-
...baseMergeRequest,
|
|
822
|
-
},
|
|
823
|
-
validate: (data) => data.merge_user === undefined && data.merged_by === undefined,
|
|
824
|
-
},
|
|
825
|
-
{
|
|
826
|
-
name: 'schema:gitlab_merge_request:preserves-sha',
|
|
827
|
-
input: {
|
|
828
|
-
...baseMergeRequest,
|
|
829
|
-
sha: 'e82eb4a098e32c796079ca3915e07487fc4db24c',
|
|
830
|
-
},
|
|
831
|
-
validate: (data) => data.sha === 'e82eb4a098e32c796079ca3915e07487fc4db24c',
|
|
832
|
-
},
|
|
833
|
-
{
|
|
834
|
-
name: 'schema:gitlab_merge_request:allows-omitted-sha',
|
|
835
|
-
input: {
|
|
836
|
-
...baseMergeRequest,
|
|
837
|
-
},
|
|
838
|
-
validate: (data) => data.sha === undefined,
|
|
839
|
-
},
|
|
840
|
-
];
|
|
841
|
-
let passed = 0;
|
|
842
|
-
let failed = 0;
|
|
843
|
-
cases.forEach(testCase => {
|
|
844
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
845
|
-
const parsed = GitLabMergeRequestSchema.safeParse(testCase.input);
|
|
846
|
-
if (parsed.success && testCase.validate(parsed.data)) {
|
|
847
|
-
result.status = 'passed';
|
|
848
|
-
}
|
|
849
|
-
else if (parsed.success) {
|
|
850
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
851
|
-
}
|
|
852
|
-
else {
|
|
853
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
854
|
-
}
|
|
855
|
-
if (result.status === 'passed') {
|
|
856
|
-
passed++;
|
|
857
|
-
console.log(`✅ ${result.name}`);
|
|
858
|
-
}
|
|
859
|
-
else {
|
|
860
|
-
failed++;
|
|
861
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
862
|
-
}
|
|
863
|
-
});
|
|
864
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
865
|
-
return { passed, failed };
|
|
866
|
-
}
|
|
867
|
-
function runEmojiReactionSchemaTests() {
|
|
868
|
-
console.log('\n🧪 Testing Emoji Reaction Schemas...');
|
|
869
|
-
const cases = [
|
|
870
|
-
{ name: 'schema:create_mr_emoji:valid', schema: CreateMergeRequestEmojiReactionSchema, input: { project_id: 'my/project', merge_request_iid: '42', name: 'thumbsup' }, expected: { project_id: 'my/project', merge_request_iid: '42', name: 'thumbsup' } },
|
|
871
|
-
{ name: 'schema:create_mr_emoji:numeric-iid-coerced', schema: CreateMergeRequestEmojiReactionSchema, input: { project_id: 'my/project', merge_request_iid: 42, name: 'rocket' }, expected: { merge_request_iid: '42', name: 'rocket' } },
|
|
872
|
-
{ name: 'schema:create_mr_emoji:reject-missing-name', schema: CreateMergeRequestEmojiReactionSchema, input: { project_id: 'my/project', merge_request_iid: '42' }, shouldFail: true },
|
|
873
|
-
{ name: 'schema:delete_mr_emoji:valid', schema: DeleteMergeRequestEmojiReactionSchema, input: { project_id: 'my/project', merge_request_iid: '42', award_id: '123' }, expected: { merge_request_iid: '42', award_id: '123' } },
|
|
874
|
-
{ name: 'schema:create_issue_emoji:valid', schema: CreateIssueEmojiReactionSchema, input: { project_id: 'my/project', issue_iid: '10', name: 'thumbsdown' }, expected: { issue_iid: '10', name: 'thumbsdown' } },
|
|
875
|
-
{ name: 'schema:create_issue_emoji:reject-missing-name', schema: CreateIssueEmojiReactionSchema, input: { project_id: 'my/project', issue_iid: '10' }, shouldFail: true },
|
|
876
|
-
{ name: 'schema:delete_issue_emoji:valid', schema: DeleteIssueEmojiReactionSchema, input: { project_id: 'my/project', issue_iid: '10', award_id: '99' }, expected: { issue_iid: '10', award_id: '99' } },
|
|
877
|
-
{ name: 'schema:create_work_item_emoji:valid', schema: CreateWorkItemEmojiReactionSchema, input: { project_id: 'my/project', iid: 5, name: 'rocket' }, expected: { iid: 5, name: 'rocket' } },
|
|
878
|
-
{ name: 'schema:create_work_item_emoji:reject-missing-name', schema: CreateWorkItemEmojiReactionSchema, input: { project_id: 'my/project', iid: 5 }, shouldFail: true },
|
|
879
|
-
{ name: 'schema:create_work_item_note_emoji:valid', schema: CreateWorkItemNoteEmojiReactionSchema, input: { project_id: 'my/project', iid: 5, note_id: 'gid://gitlab/Note/123', name: 'thumbsup' }, expected: { iid: 5, note_id: 'gid://gitlab/Note/123', name: 'thumbsup' } },
|
|
880
|
-
{ name: 'schema:create_work_item_note_emoji:reject-missing-note-id', schema: CreateWorkItemNoteEmojiReactionSchema, input: { project_id: 'my/project', iid: 5, name: 'thumbsup' }, shouldFail: true },
|
|
881
|
-
];
|
|
882
|
-
let passed = 0;
|
|
883
|
-
let failed = 0;
|
|
884
|
-
cases.forEach(testCase => {
|
|
885
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
886
|
-
const parsed = testCase.schema.safeParse(testCase.input);
|
|
887
|
-
if (testCase.shouldFail) {
|
|
888
|
-
if (parsed.success) {
|
|
889
|
-
result.error = 'Expected schema validation to fail';
|
|
890
|
-
}
|
|
891
|
-
else {
|
|
892
|
-
result.status = 'passed';
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
else if (parsed.success) {
|
|
896
|
-
const expected = testCase.expected || {};
|
|
897
|
-
const matches = Object.entries(expected).every(([key, value]) => {
|
|
898
|
-
return parsed.data[key] === value;
|
|
899
|
-
});
|
|
900
|
-
if (matches) {
|
|
901
|
-
result.status = 'passed';
|
|
902
|
-
}
|
|
903
|
-
else {
|
|
904
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
else {
|
|
908
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
909
|
-
}
|
|
910
|
-
if (result.status === 'passed') {
|
|
911
|
-
passed++;
|
|
912
|
-
console.log(`✅ ${result.name}`);
|
|
913
|
-
}
|
|
914
|
-
else {
|
|
915
|
-
failed++;
|
|
916
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
917
|
-
}
|
|
918
|
-
});
|
|
919
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
920
|
-
return { passed, failed };
|
|
921
|
-
}
|
|
922
|
-
function runGitLabRepositorySchemaTests() {
|
|
923
|
-
console.log('🧪 Testing GitLabRepositorySchema...');
|
|
924
|
-
const baseProject = {
|
|
925
|
-
id: '42',
|
|
926
|
-
name: 'my-project',
|
|
927
|
-
path_with_namespace: 'group/my-project',
|
|
928
|
-
description: null,
|
|
929
|
-
};
|
|
930
|
-
const cases = [
|
|
931
|
-
{
|
|
932
|
-
name: 'schema:repository:default_branch-null',
|
|
933
|
-
input: { ...baseProject, default_branch: null },
|
|
934
|
-
shouldFail: false,
|
|
935
|
-
},
|
|
936
|
-
{
|
|
937
|
-
name: 'schema:repository:default_branch-string',
|
|
938
|
-
input: { ...baseProject, default_branch: 'main' },
|
|
939
|
-
shouldFail: false,
|
|
940
|
-
},
|
|
941
|
-
{
|
|
942
|
-
name: 'schema:repository:default_branch-omitted',
|
|
943
|
-
input: { ...baseProject },
|
|
944
|
-
shouldFail: false,
|
|
945
|
-
},
|
|
946
|
-
];
|
|
947
|
-
let passed = 0;
|
|
948
|
-
let failed = 0;
|
|
949
|
-
cases.forEach(testCase => {
|
|
950
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
951
|
-
const parsed = GitLabRepositorySchema.safeParse(testCase.input);
|
|
952
|
-
if (testCase.shouldFail) {
|
|
953
|
-
if (parsed.success) {
|
|
954
|
-
result.error = 'Expected schema validation to fail';
|
|
955
|
-
}
|
|
956
|
-
else {
|
|
957
|
-
result.status = 'passed';
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
else if (parsed.success) {
|
|
961
|
-
result.status = 'passed';
|
|
962
|
-
}
|
|
963
|
-
else {
|
|
964
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
965
|
-
}
|
|
966
|
-
if (result.status === 'passed') {
|
|
967
|
-
passed++;
|
|
968
|
-
console.log(`✅ ${result.name}`);
|
|
969
|
-
}
|
|
970
|
-
else {
|
|
971
|
-
failed++;
|
|
972
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
973
|
-
}
|
|
974
|
-
});
|
|
975
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
976
|
-
return { passed, failed };
|
|
977
|
-
}
|
|
978
|
-
function runLabelsCoercionSchemaTests() {
|
|
979
|
-
console.log('\n=== Labels Coercion Schema Tests ===');
|
|
980
|
-
const cases = [
|
|
981
|
-
{
|
|
982
|
-
name: 'schema:create_issue:labels-native-array',
|
|
983
|
-
schema: CreateIssueSchema,
|
|
984
|
-
input: { project_id: 'my/project', title: 'Test', labels: ['bug', 'enhancement'] },
|
|
985
|
-
expectedLabels: ['bug', 'enhancement'],
|
|
986
|
-
},
|
|
987
|
-
{
|
|
988
|
-
name: 'schema:create_issue:labels-stringified-array',
|
|
989
|
-
schema: CreateIssueSchema,
|
|
990
|
-
input: { project_id: 'my/project', title: 'Test', labels: '["bug","enhancement"]' },
|
|
991
|
-
expectedLabels: ['bug', 'enhancement'],
|
|
992
|
-
},
|
|
993
|
-
{
|
|
994
|
-
name: 'schema:create_issue:labels-omitted',
|
|
995
|
-
schema: CreateIssueSchema,
|
|
996
|
-
input: { project_id: 'my/project', title: 'Test' },
|
|
997
|
-
expectedLabels: undefined,
|
|
998
|
-
},
|
|
999
|
-
{
|
|
1000
|
-
name: 'schema:list_issues:labels-native-array',
|
|
1001
|
-
schema: ListIssuesSchema,
|
|
1002
|
-
input: { project_id: 'my/project', labels: ['bug'] },
|
|
1003
|
-
expectedLabels: ['bug'],
|
|
1004
|
-
},
|
|
1005
|
-
{
|
|
1006
|
-
name: 'schema:list_issues:labels-stringified-array',
|
|
1007
|
-
schema: ListIssuesSchema,
|
|
1008
|
-
input: { project_id: 'my/project', labels: '["bug","enhancement"]' },
|
|
1009
|
-
expectedLabels: ['bug', 'enhancement'],
|
|
1010
|
-
},
|
|
1011
|
-
{
|
|
1012
|
-
name: 'schema:list_merge_requests:labels-native-array',
|
|
1013
|
-
schema: ListMergeRequestsSchema,
|
|
1014
|
-
input: { labels: ['feature'] },
|
|
1015
|
-
expectedLabels: ['feature'],
|
|
1016
|
-
},
|
|
1017
|
-
{
|
|
1018
|
-
name: 'schema:list_merge_requests:labels-stringified-array',
|
|
1019
|
-
schema: ListMergeRequestsSchema,
|
|
1020
|
-
input: { labels: '["feature","bugfix"]' },
|
|
1021
|
-
expectedLabels: ['feature', 'bugfix'],
|
|
1022
|
-
},
|
|
1023
|
-
];
|
|
1024
|
-
let passed = 0;
|
|
1025
|
-
let failed = 0;
|
|
1026
|
-
function checkLabelResult(testCase, parsed) {
|
|
1027
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
1028
|
-
if (!parsed.success) {
|
|
1029
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
1030
|
-
return result;
|
|
1031
|
-
}
|
|
1032
|
-
const actualLabels = parsed.data['labels'];
|
|
1033
|
-
if (testCase.expectedLabels === undefined) {
|
|
1034
|
-
result.status = actualLabels === undefined ? 'passed' : 'failed';
|
|
1035
|
-
if (actualLabels !== undefined) {
|
|
1036
|
-
result.error = `Expected labels to be undefined, got ${JSON.stringify(actualLabels)}`;
|
|
1037
|
-
}
|
|
1038
|
-
return result;
|
|
1039
|
-
}
|
|
1040
|
-
const match = Array.isArray(actualLabels) &&
|
|
1041
|
-
actualLabels.length === testCase.expectedLabels.length &&
|
|
1042
|
-
testCase.expectedLabels.every((v, i) => actualLabels[i] === v);
|
|
1043
|
-
result.status = match ? 'passed' : 'failed';
|
|
1044
|
-
if (!match) {
|
|
1045
|
-
result.error = `Expected ${JSON.stringify(testCase.expectedLabels)}, got ${JSON.stringify(actualLabels)}`;
|
|
1046
|
-
}
|
|
1047
|
-
return result;
|
|
1048
|
-
}
|
|
1049
|
-
cases.forEach(testCase => {
|
|
1050
|
-
const parsed = testCase.schema.safeParse(testCase.input);
|
|
1051
|
-
let result;
|
|
1052
|
-
if (testCase.shouldFail) {
|
|
1053
|
-
result = { name: testCase.name, status: parsed.success ? 'failed' : 'passed' };
|
|
1054
|
-
if (parsed.success)
|
|
1055
|
-
result.error = 'Expected schema validation to fail';
|
|
1056
|
-
}
|
|
1057
|
-
else {
|
|
1058
|
-
result = checkLabelResult(testCase, parsed);
|
|
1059
|
-
}
|
|
1060
|
-
if (result.status === 'passed') {
|
|
1061
|
-
passed++;
|
|
1062
|
-
console.log(`✅ ${result.name}`);
|
|
1063
|
-
}
|
|
1064
|
-
else {
|
|
1065
|
-
failed++;
|
|
1066
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1067
|
-
}
|
|
1068
|
-
});
|
|
1069
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1070
|
-
return { passed, failed };
|
|
1071
|
-
}
|
|
1072
|
-
function runApprovedByUsernamesSchemaTests() {
|
|
1073
|
-
console.log('\n=== ListMergeRequestsSchema approved_by_usernames Tests ===');
|
|
1074
|
-
const cases = [
|
|
1075
|
-
{
|
|
1076
|
-
name: 'schema:list_merge_requests:approved_by_usernames-native-array',
|
|
1077
|
-
input: { approved_by_usernames: ['alice', 'bob'] },
|
|
1078
|
-
expected: ['alice', 'bob'],
|
|
1079
|
-
},
|
|
1080
|
-
{
|
|
1081
|
-
name: 'schema:list_merge_requests:approved_by_usernames-stringified-array',
|
|
1082
|
-
input: { approved_by_usernames: '["alice","bob"]' },
|
|
1083
|
-
expected: ['alice', 'bob'],
|
|
1084
|
-
},
|
|
1085
|
-
{
|
|
1086
|
-
name: 'schema:list_merge_requests:approved_by_usernames-omitted',
|
|
1087
|
-
input: {},
|
|
1088
|
-
expected: undefined,
|
|
1089
|
-
},
|
|
1090
|
-
];
|
|
1091
|
-
let passed = 0;
|
|
1092
|
-
let failed = 0;
|
|
1093
|
-
cases.forEach(testCase => {
|
|
1094
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
1095
|
-
const parsed = ListMergeRequestsSchema.safeParse(testCase.input);
|
|
1096
|
-
if (testCase.shouldFail) {
|
|
1097
|
-
if (parsed.success) {
|
|
1098
|
-
result.error = 'Expected schema validation to fail';
|
|
1099
|
-
}
|
|
1100
|
-
else {
|
|
1101
|
-
result.status = 'passed';
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
else if (!parsed.success) {
|
|
1105
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
1106
|
-
}
|
|
1107
|
-
else {
|
|
1108
|
-
const actual = parsed.data['approved_by_usernames'];
|
|
1109
|
-
if (testCase.expected === undefined) {
|
|
1110
|
-
result.status = actual === undefined ? 'passed' : 'failed';
|
|
1111
|
-
if (actual !== undefined) {
|
|
1112
|
-
result.error = `Expected approved_by_usernames to be undefined, got ${JSON.stringify(actual)}`;
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
else {
|
|
1116
|
-
const match = Array.isArray(actual) &&
|
|
1117
|
-
actual.length === testCase.expected.length &&
|
|
1118
|
-
testCase.expected.every((v, i) => actual[i] === v);
|
|
1119
|
-
result.status = match ? 'passed' : 'failed';
|
|
1120
|
-
if (!match) {
|
|
1121
|
-
result.error = `Expected ${JSON.stringify(testCase.expected)}, got ${JSON.stringify(actual)}`;
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
if (result.status === 'passed') {
|
|
1126
|
-
passed++;
|
|
1127
|
-
console.log(`✅ ${result.name}`);
|
|
1128
|
-
}
|
|
1129
|
-
else {
|
|
1130
|
-
failed++;
|
|
1131
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1132
|
-
}
|
|
1133
|
-
});
|
|
1134
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1135
|
-
return { passed, failed };
|
|
1136
|
-
}
|
|
1137
|
-
function runListLabelsSchemaTests() {
|
|
1138
|
-
console.log('\n=== List Labels Schema Tests ===');
|
|
1139
|
-
const cases = [
|
|
1140
|
-
{
|
|
1141
|
-
name: 'schema:list_labels:pagination-coercion',
|
|
1142
|
-
input: { project_id: 'my/project', page: '2', per_page: '100' },
|
|
1143
|
-
expected: { project_id: 'my/project', page: 2, per_page: 100 },
|
|
1144
|
-
},
|
|
1145
|
-
{
|
|
1146
|
-
name: 'schema:list_labels:filters-with-pagination',
|
|
1147
|
-
input: { project_id: 'my/project', search: 'backend', with_counts: 'true', page: 3, per_page: 50 },
|
|
1148
|
-
expected: { project_id: 'my/project', search: 'backend', with_counts: true, page: 3, per_page: 50 },
|
|
1149
|
-
},
|
|
1150
|
-
];
|
|
1151
|
-
let passed = 0;
|
|
1152
|
-
let failed = 0;
|
|
1153
|
-
cases.forEach(testCase => {
|
|
1154
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
1155
|
-
const parsed = ListLabelsSchema.safeParse(testCase.input);
|
|
1156
|
-
if (!parsed.success) {
|
|
1157
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
1158
|
-
}
|
|
1159
|
-
else {
|
|
1160
|
-
const matches = Object.entries(testCase.expected).every(([key, value]) => {
|
|
1161
|
-
const actual = parsed.data[key];
|
|
1162
|
-
return actual === value;
|
|
1163
|
-
});
|
|
1164
|
-
if (matches) {
|
|
1165
|
-
result.status = 'passed';
|
|
1166
|
-
}
|
|
1167
|
-
else {
|
|
1168
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
if (result.status === 'passed') {
|
|
1172
|
-
passed++;
|
|
1173
|
-
console.log(`✅ ${result.name}`);
|
|
1174
|
-
}
|
|
1175
|
-
else {
|
|
1176
|
-
failed++;
|
|
1177
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1178
|
-
}
|
|
1179
|
-
});
|
|
1180
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1181
|
-
return { passed, failed };
|
|
1182
|
-
}
|
|
1183
|
-
function runGitLabTreeItemSchemaTests() {
|
|
1184
|
-
console.log('\n=== GitLabTreeItem Schema Tests ===');
|
|
1185
|
-
const cases = [
|
|
1186
|
-
{
|
|
1187
|
-
name: 'schema:tree_item:type-blob',
|
|
1188
|
-
input: { id: 'abc123', name: 'README.md', type: 'blob', path: 'README.md', mode: '100644' },
|
|
1189
|
-
},
|
|
1190
|
-
{
|
|
1191
|
-
name: 'schema:tree_item:type-tree',
|
|
1192
|
-
input: { id: 'def456', name: 'src', type: 'tree', path: 'src', mode: '040000' },
|
|
1193
|
-
},
|
|
1194
|
-
{
|
|
1195
|
-
name: 'schema:tree_item:type-commit-submodule',
|
|
1196
|
-
input: { id: 'ghi789', name: 'vendor', type: 'commit', path: 'vendor', mode: '160000' },
|
|
1197
|
-
},
|
|
1198
|
-
{
|
|
1199
|
-
name: 'schema:tree_item:reject-unknown-type',
|
|
1200
|
-
input: { id: 'xyz', name: 'foo', type: 'symlink', path: 'foo', mode: '120000' },
|
|
1201
|
-
shouldFail: true,
|
|
1202
|
-
},
|
|
1203
|
-
];
|
|
1204
|
-
let passed = 0;
|
|
1205
|
-
let failed = 0;
|
|
1206
|
-
cases.forEach(testCase => {
|
|
1207
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
1208
|
-
const parsed = GitLabTreeItemSchema.safeParse(testCase.input);
|
|
1209
|
-
if (testCase.shouldFail) {
|
|
1210
|
-
result.status = parsed.success ? 'failed' : 'passed';
|
|
1211
|
-
if (parsed.success)
|
|
1212
|
-
result.error = 'Expected schema validation to fail';
|
|
1213
|
-
}
|
|
1214
|
-
else if (parsed.success) {
|
|
1215
|
-
result.status = 'passed';
|
|
1216
|
-
}
|
|
1217
|
-
else {
|
|
1218
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
1219
|
-
}
|
|
1220
|
-
if (result.status === 'passed') {
|
|
1221
|
-
passed++;
|
|
1222
|
-
console.log(`✅ ${result.name}`);
|
|
1223
|
-
}
|
|
1224
|
-
else {
|
|
1225
|
-
failed++;
|
|
1226
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1227
|
-
}
|
|
1228
|
-
});
|
|
1229
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1230
|
-
return { passed, failed };
|
|
1231
|
-
}
|
|
1232
|
-
function runGetRepositoryTreeSchemaTests() {
|
|
1233
|
-
console.log('\n=== GetRepositoryTree Schema Tests ===');
|
|
1234
|
-
const cases = [
|
|
1235
|
-
{
|
|
1236
|
-
name: 'schema:get_repository_tree:minimal-project-id',
|
|
1237
|
-
input: { project_id: 'my/project' },
|
|
1238
|
-
expected: { project_id: 'my/project', path: undefined, ref: undefined, recursive: undefined, per_page: undefined, page_token: undefined, pagination: undefined },
|
|
1239
|
-
},
|
|
1240
|
-
{
|
|
1241
|
-
name: 'schema:get_repository_tree:with-keyset-pagination',
|
|
1242
|
-
input: { project_id: 'my/project', pagination: 'keyset', per_page: 100 },
|
|
1243
|
-
expected: { project_id: 'my/project', pagination: 'keyset', per_page: 100 },
|
|
1244
|
-
},
|
|
1245
|
-
{
|
|
1246
|
-
name: 'schema:get_repository_tree:page-token-for-next-page',
|
|
1247
|
-
input: { project_id: 'my/project', pagination: 'keyset', per_page: 100, page_token: 'eyJpZCI6IjEyMyJ9' },
|
|
1248
|
-
expected: { project_id: 'my/project', pagination: 'keyset', per_page: 100, page_token: 'eyJpZCI6IjEyMyJ9' },
|
|
1249
|
-
},
|
|
1250
|
-
{
|
|
1251
|
-
name: 'schema:get_repository_tree:per-page-coerces-from-string',
|
|
1252
|
-
input: { project_id: 'my/project', per_page: '50' },
|
|
1253
|
-
expected: { project_id: 'my/project', per_page: 50 },
|
|
1254
|
-
},
|
|
1255
|
-
{
|
|
1256
|
-
name: 'schema:get_repository_tree:recursive-coerces-from-string',
|
|
1257
|
-
input: { project_id: 'my/project', recursive: 'true' },
|
|
1258
|
-
expected: { project_id: 'my/project', recursive: true },
|
|
1259
|
-
},
|
|
1260
|
-
{
|
|
1261
|
-
name: 'schema:get_repository_tree:with-path-and-ref',
|
|
1262
|
-
input: { project_id: 'my/project', path: 'src/', ref: 'main' },
|
|
1263
|
-
expected: { project_id: 'my/project', path: 'src/', ref: 'main' },
|
|
1264
|
-
},
|
|
1265
|
-
];
|
|
1266
|
-
let passed = 0;
|
|
1267
|
-
let failed = 0;
|
|
1268
|
-
cases.forEach(testCase => {
|
|
1269
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
1270
|
-
const parsed = GetRepositoryTreeSchema.safeParse(testCase.input);
|
|
1271
|
-
if (testCase.shouldFail) {
|
|
1272
|
-
result.status = parsed.success ? 'failed' : 'passed';
|
|
1273
|
-
if (parsed.success)
|
|
1274
|
-
result.error = 'Expected schema validation to fail';
|
|
1275
|
-
}
|
|
1276
|
-
else if (parsed.success) {
|
|
1277
|
-
const expected = testCase.expected || {};
|
|
1278
|
-
const matches = Object.entries(expected).every(([key, value]) => {
|
|
1279
|
-
const actual = parsed.data[key];
|
|
1280
|
-
return JSON.stringify(actual) === JSON.stringify(value);
|
|
1281
|
-
});
|
|
1282
|
-
if (matches) {
|
|
1283
|
-
result.status = 'passed';
|
|
1284
|
-
}
|
|
1285
|
-
else {
|
|
1286
|
-
result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
else {
|
|
1290
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
1291
|
-
}
|
|
1292
|
-
if (result.status === 'passed') {
|
|
1293
|
-
passed++;
|
|
1294
|
-
console.log(`✅ ${result.name}`);
|
|
1295
|
-
}
|
|
1296
|
-
else {
|
|
1297
|
-
failed++;
|
|
1298
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1299
|
-
}
|
|
1300
|
-
});
|
|
1301
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1302
|
-
return { passed, failed };
|
|
1303
|
-
}
|
|
1304
|
-
function runGitLabMarkdownUploadSchemaTests() {
|
|
1305
|
-
console.log('\n=== GitLabMarkdownUpload Schema Tests ===');
|
|
1306
|
-
const idlessUpload = {
|
|
1307
|
-
alt: 'report.md',
|
|
1308
|
-
url: '/uploads/c617e74a47dfb1a6dd59d419619b725d/report.md',
|
|
1309
|
-
full_path: '/group/project/uploads/c617e74a47dfb1a6dd59d419619b725d/report.md',
|
|
1310
|
-
markdown: '[report.md](/uploads/c617e74a47dfb1a6dd59d419619b725d/report.md)',
|
|
1311
|
-
};
|
|
1312
|
-
const cases = [
|
|
1313
|
-
{
|
|
1314
|
-
name: 'schema:markdown_upload:accepts-idless-response',
|
|
1315
|
-
input: idlessUpload,
|
|
1316
|
-
expectedId: 'absent',
|
|
1317
|
-
},
|
|
1318
|
-
{
|
|
1319
|
-
name: 'schema:markdown_upload:accepts-numeric-id',
|
|
1320
|
-
input: { ...idlessUpload, id: 42 },
|
|
1321
|
-
expectedId: 42,
|
|
1322
|
-
},
|
|
1323
|
-
{
|
|
1324
|
-
name: 'schema:markdown_upload:coerces-string-id',
|
|
1325
|
-
input: { ...idlessUpload, id: '99' },
|
|
1326
|
-
expectedId: 99,
|
|
1327
|
-
},
|
|
1328
|
-
{
|
|
1329
|
-
name: 'schema:markdown_upload:treats-null-id-as-absent',
|
|
1330
|
-
input: { ...idlessUpload, id: null },
|
|
1331
|
-
expectedId: 'absent',
|
|
1332
|
-
},
|
|
1333
|
-
{
|
|
1334
|
-
name: 'schema:markdown_upload:rejects-invalid-id',
|
|
1335
|
-
input: { ...idlessUpload, id: 'not-a-number' },
|
|
1336
|
-
shouldFail: true,
|
|
1337
|
-
},
|
|
1338
|
-
];
|
|
1339
|
-
let passed = 0;
|
|
1340
|
-
let failed = 0;
|
|
1341
|
-
cases.forEach(testCase => {
|
|
1342
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
1343
|
-
const parsed = GitLabMarkdownUploadSchema.safeParse(testCase.input);
|
|
1344
|
-
if (testCase.shouldFail) {
|
|
1345
|
-
result.status = parsed.success ? 'failed' : 'passed';
|
|
1346
|
-
if (parsed.success)
|
|
1347
|
-
result.error = 'Expected schema validation to fail';
|
|
1348
|
-
}
|
|
1349
|
-
else if (!parsed.success) {
|
|
1350
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
1351
|
-
}
|
|
1352
|
-
else if (testCase.expectedId === 'absent' && parsed.data.id !== undefined) {
|
|
1353
|
-
result.error = `Expected id undefined, got ${parsed.data.id}`;
|
|
1354
|
-
}
|
|
1355
|
-
else if (typeof testCase.expectedId === 'number' && parsed.data.id !== testCase.expectedId) {
|
|
1356
|
-
result.error = `Expected id ${testCase.expectedId}, got ${parsed.data.id}`;
|
|
1357
|
-
}
|
|
1358
|
-
else {
|
|
1359
|
-
result.status = 'passed';
|
|
1360
|
-
}
|
|
1361
|
-
if (result.status === 'passed') {
|
|
1362
|
-
passed++;
|
|
1363
|
-
console.log(`✅ ${result.name}`);
|
|
1364
|
-
}
|
|
1365
|
-
else {
|
|
1366
|
-
failed++;
|
|
1367
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1368
|
-
}
|
|
1369
|
-
});
|
|
1370
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1371
|
-
return { passed, failed };
|
|
1372
|
-
}
|
|
1373
|
-
function runGitLabUserFullSchemaTests() {
|
|
1374
|
-
console.log('🧪 Testing GitLabUserFullSchema...');
|
|
1375
|
-
const adminResponse = {
|
|
1376
|
-
id: 1,
|
|
1377
|
-
username: 'root',
|
|
1378
|
-
name: 'Administrator',
|
|
1379
|
-
state: 'active',
|
|
1380
|
-
avatar_url: 'https://gitlab.example.com/uploads/-/system/user/avatar/1/avatar.png',
|
|
1381
|
-
web_url: 'https://gitlab.example.com/root',
|
|
1382
|
-
created_at: '2012-09-22T16:50:56.000Z',
|
|
1383
|
-
bio: null,
|
|
1384
|
-
location: null,
|
|
1385
|
-
public_email: '',
|
|
1386
|
-
website_url: '',
|
|
1387
|
-
organization: null,
|
|
1388
|
-
job_title: null,
|
|
1389
|
-
pronouns: null,
|
|
1390
|
-
work_information: null,
|
|
1391
|
-
followers: 0,
|
|
1392
|
-
following: 0,
|
|
1393
|
-
is_followed: false,
|
|
1394
|
-
local_time: null,
|
|
1395
|
-
last_sign_in_at: null,
|
|
1396
|
-
confirmed_at: '2012-09-22T16:50:56.000Z',
|
|
1397
|
-
last_activity_on: '2026-05-12',
|
|
1398
|
-
email: 'admin@example.com',
|
|
1399
|
-
theme_id: 1,
|
|
1400
|
-
color_scheme_id: 1,
|
|
1401
|
-
projects_limit: 100000,
|
|
1402
|
-
current_sign_in_at: '2026-05-12T08:14:22.885Z',
|
|
1403
|
-
identities: [],
|
|
1404
|
-
can_create_group: true,
|
|
1405
|
-
can_create_project: true,
|
|
1406
|
-
two_factor_enabled: false,
|
|
1407
|
-
external: false,
|
|
1408
|
-
private_profile: false,
|
|
1409
|
-
is_admin: true,
|
|
1410
|
-
};
|
|
1411
|
-
const cases = [
|
|
1412
|
-
{
|
|
1413
|
-
name: 'schema:user_full:admin-response-no-bot',
|
|
1414
|
-
input: { ...adminResponse },
|
|
1415
|
-
shouldFail: false,
|
|
1416
|
-
},
|
|
1417
|
-
{
|
|
1418
|
-
name: 'schema:user_full:admin-response-with-bot',
|
|
1419
|
-
input: { ...adminResponse, bot: false },
|
|
1420
|
-
shouldFail: false,
|
|
1421
|
-
},
|
|
1422
|
-
];
|
|
1423
|
-
let passed = 0;
|
|
1424
|
-
let failed = 0;
|
|
1425
|
-
cases.forEach(testCase => {
|
|
1426
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
1427
|
-
const parsed = GitLabUserFullSchema.safeParse(testCase.input);
|
|
1428
|
-
if (testCase.shouldFail) {
|
|
1429
|
-
if (parsed.success) {
|
|
1430
|
-
result.error = 'Expected schema validation to fail';
|
|
1431
|
-
}
|
|
1432
|
-
else {
|
|
1433
|
-
result.status = 'passed';
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
else if (parsed.success) {
|
|
1437
|
-
result.status = 'passed';
|
|
1438
|
-
}
|
|
1439
|
-
else {
|
|
1440
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
1441
|
-
}
|
|
1442
|
-
if (result.status === 'passed') {
|
|
1443
|
-
passed++;
|
|
1444
|
-
console.log(`✅ ${result.name}`);
|
|
1445
|
-
}
|
|
1446
|
-
else {
|
|
1447
|
-
failed++;
|
|
1448
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1449
|
-
}
|
|
1450
|
-
});
|
|
1451
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1452
|
-
return { passed, failed };
|
|
1453
|
-
}
|
|
1454
|
-
function runGitLabDependencyProxySchemaTests() {
|
|
1455
|
-
console.log('🧪 Testing GitLabDependencyProxySchema...');
|
|
1456
|
-
const cases = [
|
|
1457
|
-
{
|
|
1458
|
-
name: 'schema:dependency_proxy:minimal',
|
|
1459
|
-
input: { enabled: true, blob_count: 0, total_size: '0' },
|
|
1460
|
-
shouldFail: false,
|
|
1461
|
-
},
|
|
1462
|
-
{
|
|
1463
|
-
name: 'schema:dependency_proxy:full',
|
|
1464
|
-
input: {
|
|
1465
|
-
enabled: true,
|
|
1466
|
-
blob_count: 42,
|
|
1467
|
-
total_size: '1234567890',
|
|
1468
|
-
image_prefix: 'gitlab.example.com:5050/my-group/dependency_proxy/containers',
|
|
1469
|
-
ttl_policy: { enabled: true, ttl: 90 },
|
|
1470
|
-
},
|
|
1471
|
-
shouldFail: false,
|
|
1472
|
-
},
|
|
1473
|
-
{
|
|
1474
|
-
name: 'schema:dependency_proxy:nulls-allowed',
|
|
1475
|
-
input: { enabled: false, blob_count: null, total_size: null, image_prefix: null, ttl_policy: null },
|
|
1476
|
-
shouldFail: false,
|
|
1477
|
-
},
|
|
1478
|
-
];
|
|
1479
|
-
let passed = 0;
|
|
1480
|
-
let failed = 0;
|
|
1481
|
-
cases.forEach(testCase => {
|
|
1482
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
1483
|
-
const parsed = GitLabDependencyProxySchema.safeParse(testCase.input);
|
|
1484
|
-
if (testCase.shouldFail) {
|
|
1485
|
-
result.status = parsed.success ? 'failed' : 'passed';
|
|
1486
|
-
if (parsed.success)
|
|
1487
|
-
result.error = 'Expected schema validation to fail';
|
|
1488
|
-
}
|
|
1489
|
-
else if (parsed.success) {
|
|
1490
|
-
result.status = 'passed';
|
|
1491
|
-
}
|
|
1492
|
-
else {
|
|
1493
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
1494
|
-
}
|
|
1495
|
-
if (result.status === 'passed') {
|
|
1496
|
-
passed++;
|
|
1497
|
-
console.log(`✅ ${result.name}`);
|
|
1498
|
-
}
|
|
1499
|
-
else {
|
|
1500
|
-
failed++;
|
|
1501
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1502
|
-
}
|
|
1503
|
-
});
|
|
1504
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1505
|
-
return { passed, failed };
|
|
1506
|
-
}
|
|
1507
|
-
function runGitLabDependencyProxyBlobSchemaTests() {
|
|
1508
|
-
console.log('🧪 Testing GitLabDependencyProxyBlobSchema...');
|
|
1509
|
-
const cases = [
|
|
1510
|
-
{
|
|
1511
|
-
name: 'schema:dependency_proxy_blob:basic',
|
|
1512
|
-
input: { file_name: 'sha256:abc123', size: '2.5 MiB', created_at: '2026-01-01T00:00:00Z' },
|
|
1513
|
-
shouldFail: false,
|
|
1514
|
-
},
|
|
1515
|
-
{
|
|
1516
|
-
name: 'schema:dependency_proxy_blob:no-created-at',
|
|
1517
|
-
input: { file_name: 'sha256:def456', size: '512 KiB' },
|
|
1518
|
-
shouldFail: false,
|
|
1519
|
-
},
|
|
1520
|
-
{
|
|
1521
|
-
name: 'schema:dependency_proxy_blob:size-must-be-string',
|
|
1522
|
-
input: { file_name: 'sha256:ghi789', size: 12345 },
|
|
1523
|
-
shouldFail: true,
|
|
1524
|
-
},
|
|
1525
|
-
];
|
|
1526
|
-
let passed = 0;
|
|
1527
|
-
let failed = 0;
|
|
1528
|
-
cases.forEach(testCase => {
|
|
1529
|
-
const result = { name: testCase.name, status: 'failed' };
|
|
1530
|
-
const parsed = GitLabDependencyProxyBlobSchema.safeParse(testCase.input);
|
|
1531
|
-
if (testCase.shouldFail) {
|
|
1532
|
-
result.status = parsed.success ? 'failed' : 'passed';
|
|
1533
|
-
if (parsed.success)
|
|
1534
|
-
result.error = 'Expected schema validation to fail';
|
|
1535
|
-
}
|
|
1536
|
-
else if (parsed.success) {
|
|
1537
|
-
result.status = 'passed';
|
|
1538
|
-
}
|
|
1539
|
-
else {
|
|
1540
|
-
result.error = parsed.error?.message || 'Schema validation failed';
|
|
1541
|
-
}
|
|
1542
|
-
if (result.status === 'passed') {
|
|
1543
|
-
passed++;
|
|
1544
|
-
console.log(`✅ ${result.name}`);
|
|
1545
|
-
}
|
|
1546
|
-
else {
|
|
1547
|
-
failed++;
|
|
1548
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1549
|
-
}
|
|
1550
|
-
});
|
|
1551
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1552
|
-
return { passed, failed };
|
|
1553
|
-
}
|
|
1554
|
-
function runPushFilesSchemaTests() {
|
|
1555
|
-
console.log('🧪 Testing PushFilesSchema / CreateOrUpdateFileSchema (per-file action + encoding)...');
|
|
1556
|
-
const base = { project_id: '1', branch: 'main', commit_message: 'm' };
|
|
1557
|
-
function record(name, ok, error) {
|
|
1558
|
-
const result = { name, status: ok ? 'passed' : 'failed', error };
|
|
1559
|
-
if (result.status === 'passed') {
|
|
1560
|
-
console.log(`✅ ${result.name}`);
|
|
1561
|
-
}
|
|
1562
|
-
else {
|
|
1563
|
-
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1564
|
-
}
|
|
1565
|
-
return result;
|
|
1566
|
-
}
|
|
1567
|
-
const results = [];
|
|
1568
|
-
{
|
|
1569
|
-
const parsed = PushFilesSchema.safeParse({ ...base, files: [{ file_path: 'a.txt', content: 'hi' }] });
|
|
1570
|
-
results.push(record('schema:push_files:plain-text-default', parsed.success &&
|
|
1571
|
-
parsed.data.files[0]?.action === undefined &&
|
|
1572
|
-
parsed.data.files[0]?.encoding === undefined, parsed.success ? undefined : parsed.error.message));
|
|
1573
|
-
}
|
|
1574
|
-
{
|
|
1575
|
-
const parsed = PushFilesSchema.safeParse({
|
|
1576
|
-
...base,
|
|
1577
|
-
files: [{ file_path: 'logo.png', content: 'aGk=', encoding: 'base64' }],
|
|
1578
|
-
});
|
|
1579
|
-
results.push(record('schema:push_files:binary-base64', parsed.success && parsed.data.files[0]?.encoding === 'base64', parsed.success ? undefined : parsed.error.message));
|
|
1580
|
-
}
|
|
1581
|
-
{
|
|
1582
|
-
const parsed = PushFilesSchema.safeParse({
|
|
1583
|
-
...base,
|
|
1584
|
-
files: [{ file_path: 'a.txt', content: 'new', action: 'update' }],
|
|
1585
|
-
});
|
|
1586
|
-
results.push(record('schema:push_files:action-update', parsed.success && parsed.data.files[0]?.action === 'update', parsed.success ? undefined : parsed.error.message));
|
|
1587
|
-
}
|
|
1588
|
-
{
|
|
1589
|
-
const parsed = PushFilesSchema.safeParse({
|
|
1590
|
-
...base,
|
|
1591
|
-
files: [{ file_path: 'a.txt', action: 'delete' }],
|
|
1592
|
-
});
|
|
1593
|
-
results.push(record('schema:push_files:action-delete-content-optional', parsed.success &&
|
|
1594
|
-
parsed.data.files[0]?.action === 'delete' &&
|
|
1595
|
-
parsed.data.files[0]?.content === undefined, parsed.success ? undefined : parsed.error.message));
|
|
1596
|
-
}
|
|
1597
|
-
{
|
|
1598
|
-
const parsed = PushFilesSchema.safeParse({
|
|
1599
|
-
...base,
|
|
1600
|
-
files: [{ file_path: 'b.txt', action: 'move', previous_path: 'a.txt' }],
|
|
1601
|
-
});
|
|
1602
|
-
results.push(record('schema:push_files:action-move-previous-path', parsed.success &&
|
|
1603
|
-
parsed.data.files[0]?.action === 'move' &&
|
|
1604
|
-
parsed.data.files[0]?.previous_path === 'a.txt', parsed.success ? undefined : parsed.error.message));
|
|
1605
|
-
}
|
|
1606
|
-
{
|
|
1607
|
-
const parsed = PushFilesSchema.safeParse({
|
|
1608
|
-
...base,
|
|
1609
|
-
files: [{ file_path: 'a.txt', content: 'hi', encoding: 'text' }],
|
|
1610
|
-
});
|
|
1611
|
-
results.push(record('schema:push_files:explicit-text-encoding', parsed.success && parsed.data.files[0]?.encoding === 'text', parsed.success ? undefined : parsed.error.message));
|
|
1612
|
-
}
|
|
1613
|
-
results.push(record('schema:push_files:reject-create-without-content', !PushFilesSchema.safeParse({ ...base, files: [{ file_path: 'a.txt' }] }).success, 'Expected schema validation to fail'));
|
|
1614
|
-
results.push(record('schema:push_files:reject-update-without-content', !PushFilesSchema.safeParse({ ...base, files: [{ file_path: 'a.txt', action: 'update' }] }).success, 'Expected schema validation to fail'));
|
|
1615
|
-
results.push(record('schema:push_files:reject-move-without-previous-path', !PushFilesSchema.safeParse({ ...base, files: [{ file_path: 'b.txt', action: 'move' }] }).success, 'Expected schema validation to fail'));
|
|
1616
|
-
results.push(record('schema:push_files:reject-invalid-action', !PushFilesSchema.safeParse({
|
|
1617
|
-
...base,
|
|
1618
|
-
files: [{ file_path: 'a.txt', content: 'hi', action: 'copy' }],
|
|
1619
|
-
}).success, 'Expected schema validation to fail'));
|
|
1620
|
-
results.push(record('schema:push_files:reject-invalid-encoding', !PushFilesSchema.safeParse({
|
|
1621
|
-
...base,
|
|
1622
|
-
files: [{ file_path: 'a.txt', content: 'hi', encoding: 'utf16' }],
|
|
1623
|
-
}).success, 'Expected schema validation to fail'));
|
|
1624
|
-
{
|
|
1625
|
-
const parsed = CreateOrUpdateFileSchema.safeParse({
|
|
1626
|
-
...base,
|
|
1627
|
-
file_path: 'a.txt',
|
|
1628
|
-
content: 'hi',
|
|
1629
|
-
});
|
|
1630
|
-
results.push(record('schema:create_or_update_file:plain-text-default', parsed.success && parsed.data.encoding === undefined, parsed.success ? undefined : parsed.error.message));
|
|
1631
|
-
}
|
|
1632
|
-
{
|
|
1633
|
-
const parsed = CreateOrUpdateFileSchema.safeParse({
|
|
1634
|
-
...base,
|
|
1635
|
-
file_path: 'logo.png',
|
|
1636
|
-
content: 'aGk=',
|
|
1637
|
-
encoding: 'base64',
|
|
1638
|
-
});
|
|
1639
|
-
results.push(record('schema:create_or_update_file:encoding-base64', parsed.success && parsed.data.encoding === 'base64', parsed.success ? undefined : parsed.error.message));
|
|
1640
|
-
}
|
|
1641
|
-
results.push(record('schema:create_or_update_file:reject-invalid-encoding', !CreateOrUpdateFileSchema.safeParse({
|
|
1642
|
-
...base,
|
|
1643
|
-
file_path: 'a.txt',
|
|
1644
|
-
content: 'hi',
|
|
1645
|
-
encoding: 'utf16',
|
|
1646
|
-
}).success, 'Expected schema validation to fail'));
|
|
1647
|
-
const passed = results.filter(result => result.status === 'passed').length;
|
|
1648
|
-
const failed = results.filter(result => result.status === 'failed').length;
|
|
1649
|
-
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1650
|
-
return { passed, failed };
|
|
1651
|
-
}
|
|
1652
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
1653
|
-
const getFileContentsResult = runGetFileContentsSchemaTests();
|
|
1654
|
-
const fileContentResult = runGitLabFileContentSchemaTests();
|
|
1655
|
-
const createPipelineResult = runCreatePipelineSchemaTests();
|
|
1656
|
-
const commitStatusResult = runCommitStatusSchemaTests();
|
|
1657
|
-
const createIssueNoteResult = runCreateIssueNoteSchemaTests();
|
|
1658
|
-
const getMergeRequestResult = runGetMergeRequestSchemaTests();
|
|
1659
|
-
const listMergeRequestPipelinesResult = runListMergeRequestPipelinesSchemaTests();
|
|
1660
|
-
const gitLabMergeRequestResult = runGitLabMergeRequestSchemaTests();
|
|
1661
|
-
const emojiReactionResult = runEmojiReactionSchemaTests();
|
|
1662
|
-
const repositorySchemaResult = runGitLabRepositorySchemaTests();
|
|
1663
|
-
const labelsCoercionResult = runLabelsCoercionSchemaTests();
|
|
1664
|
-
const approvedByUsernamesResult = runApprovedByUsernamesSchemaTests();
|
|
1665
|
-
const listLabelsResult = runListLabelsSchemaTests();
|
|
1666
|
-
const treeItemResult = runGitLabTreeItemSchemaTests();
|
|
1667
|
-
const repositoryTreeResult = runGetRepositoryTreeSchemaTests();
|
|
1668
|
-
const gitLabUserFullResult = runGitLabUserFullSchemaTests();
|
|
1669
|
-
const gitLabMarkdownUploadResult = runGitLabMarkdownUploadSchemaTests();
|
|
1670
|
-
const dependencyProxyResult = runGitLabDependencyProxySchemaTests();
|
|
1671
|
-
const dependencyProxyBlobResult = runGitLabDependencyProxyBlobSchemaTests();
|
|
1672
|
-
const pushFilesResult = runPushFilesSchemaTests();
|
|
1673
|
-
const totalPassed = getFileContentsResult.passed + fileContentResult.passed + createPipelineResult.passed + commitStatusResult.passed + createIssueNoteResult.passed + getMergeRequestResult.passed + listMergeRequestPipelinesResult.passed + gitLabMergeRequestResult.passed + emojiReactionResult.passed + repositorySchemaResult.passed + labelsCoercionResult.passed + approvedByUsernamesResult.passed + listLabelsResult.passed + treeItemResult.passed + repositoryTreeResult.passed + gitLabUserFullResult.passed + gitLabMarkdownUploadResult.passed + dependencyProxyResult.passed + dependencyProxyBlobResult.passed + pushFilesResult.passed;
|
|
1674
|
-
const totalFailed = getFileContentsResult.failed + fileContentResult.failed + createPipelineResult.failed + commitStatusResult.failed + createIssueNoteResult.failed + getMergeRequestResult.failed + listMergeRequestPipelinesResult.failed + gitLabMergeRequestResult.failed + emojiReactionResult.failed + repositorySchemaResult.failed + labelsCoercionResult.failed + approvedByUsernamesResult.failed + listLabelsResult.failed + treeItemResult.failed + repositoryTreeResult.failed + gitLabUserFullResult.failed + gitLabMarkdownUploadResult.failed + dependencyProxyResult.failed + dependencyProxyBlobResult.failed + pushFilesResult.failed;
|
|
1675
|
-
console.log(`\nTotal Results: ${totalPassed} passed, ${totalFailed} failed`);
|
|
1676
|
-
if (totalFailed > 0) {
|
|
1677
|
-
process.exit(1);
|
|
1678
|
-
}
|
|
1679
|
-
}
|