@aaronshaf/ger 0.2.2 → 0.2.5
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/CLAUDE.md +3 -3
- package/README.md +49 -0
- package/package.json +1 -1
- package/src/cli/commands/build-status.ts +116 -0
- package/src/cli/commands/show.ts +138 -64
- package/src/cli/index.ts +58 -0
- package/tests/abandon.test.ts +178 -111
- package/tests/build-status.test.ts +691 -0
- package/tests/mine.test.ts +130 -163
- package/tests/show-auto-detect.test.ts +20 -2
- package/tests/show.test.ts +226 -8
- package/tests/mocks/fetch-mock.ts +0 -142
- package/tests/setup.ts +0 -13
package/tests/abandon.test.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, mock } from 'bun:test'
|
|
1
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, mock } from 'bun:test'
|
|
2
|
+
import { Effect, Layer } from 'effect'
|
|
3
|
+
import { HttpResponse, http } from 'msw'
|
|
4
|
+
import { setupServer } from 'msw/node'
|
|
5
|
+
import { GerritApiServiceLive } from '@/api/gerrit'
|
|
6
|
+
import { abandonCommand } from '@/cli/commands/abandon'
|
|
7
|
+
import { ConfigService } from '@/services/config'
|
|
8
|
+
import { createMockConfigService } from './helpers/config-mock'
|
|
2
9
|
import type { ChangeInfo } from '@/schemas/gerrit'
|
|
3
10
|
|
|
4
11
|
const mockChange: ChangeInfo = {
|
|
@@ -28,136 +35,196 @@ const mockChange: ChangeInfo = {
|
|
|
28
35
|
submittable: false,
|
|
29
36
|
}
|
|
30
37
|
|
|
38
|
+
// Create MSW server
|
|
39
|
+
const server = setupServer(
|
|
40
|
+
// Default handler for auth check
|
|
41
|
+
http.get('*/a/accounts/self', ({ request }) => {
|
|
42
|
+
const auth = request.headers.get('Authorization')
|
|
43
|
+
if (!auth || !auth.startsWith('Basic ')) {
|
|
44
|
+
return HttpResponse.text('Unauthorized', { status: 401 })
|
|
45
|
+
}
|
|
46
|
+
return HttpResponse.json({
|
|
47
|
+
_account_id: 1000,
|
|
48
|
+
name: 'Test User',
|
|
49
|
+
email: 'test@example.com',
|
|
50
|
+
})
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
53
|
+
|
|
31
54
|
describe('abandon command', () => {
|
|
32
|
-
let
|
|
55
|
+
let mockConsoleLog: ReturnType<typeof mock>
|
|
56
|
+
let mockConsoleError: ReturnType<typeof mock>
|
|
57
|
+
|
|
58
|
+
beforeAll(() => {
|
|
59
|
+
server.listen({ onUnhandledRequest: 'bypass' })
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
afterAll(() => {
|
|
63
|
+
server.close()
|
|
64
|
+
})
|
|
33
65
|
|
|
34
66
|
beforeEach(() => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
67
|
+
mockConsoleLog = mock(() => {})
|
|
68
|
+
mockConsoleError = mock(() => {})
|
|
69
|
+
console.log = mockConsoleLog
|
|
70
|
+
console.error = mockConsoleError
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
afterEach(() => {
|
|
74
|
+
server.resetHandlers()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('should abandon a change with a message', async () => {
|
|
78
|
+
server.use(
|
|
79
|
+
http.get('*/a/changes/12345', () => {
|
|
80
|
+
return HttpResponse.text(`)]}'\n${JSON.stringify(mockChange)}`)
|
|
81
|
+
}),
|
|
82
|
+
http.post('*/a/changes/12345/abandon', async ({ request }) => {
|
|
83
|
+
const body = (await request.json()) as { message?: string }
|
|
84
|
+
expect(body.message).toBe('No longer needed')
|
|
85
|
+
return HttpResponse.text(")]}'\n{}")
|
|
41
86
|
}),
|
|
42
87
|
)
|
|
43
|
-
|
|
88
|
+
|
|
89
|
+
const mockConfigLayer = Layer.succeed(ConfigService, createMockConfigService())
|
|
90
|
+
const program = abandonCommand('12345', {
|
|
91
|
+
message: 'No longer needed',
|
|
92
|
+
}).pipe(Effect.provide(GerritApiServiceLive), Effect.provide(mockConfigLayer))
|
|
93
|
+
|
|
94
|
+
await Effect.runPromise(program)
|
|
95
|
+
|
|
96
|
+
const output = mockConsoleLog.mock.calls.map((call) => call[0]).join('\n')
|
|
97
|
+
expect(output).toContain('Abandoned change 12345')
|
|
98
|
+
expect(output).toContain('Test change to abandon')
|
|
99
|
+
expect(output).toContain('Message: No longer needed')
|
|
44
100
|
})
|
|
45
101
|
|
|
46
|
-
it('should
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"subject": "Test change to abandon",
|
|
58
|
-
"status": "NEW",
|
|
59
|
-
"_number": 12345
|
|
60
|
-
}`,
|
|
61
|
-
})
|
|
62
|
-
.mockResolvedValueOnce({
|
|
63
|
-
ok: true,
|
|
64
|
-
text: async () => ')]}\n{}',
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
// Note: This is a unit test demonstrating the API calls
|
|
68
|
-
// Actual integration would require running the full command
|
|
69
|
-
// which we avoid to prevent hitting production
|
|
70
|
-
|
|
71
|
-
// Verify the mock setup
|
|
72
|
-
const response = await mockFetch('https://test.gerrit.com/a/changes/12345')
|
|
73
|
-
const text = await response.text()
|
|
74
|
-
expect(text).toContain('Test change to abandon')
|
|
75
|
-
|
|
76
|
-
// Verify abandon endpoint would be called
|
|
77
|
-
const abandonResponse = await mockFetch('https://test.gerrit.com/a/changes/12345/abandon', {
|
|
78
|
-
method: 'POST',
|
|
79
|
-
body: JSON.stringify({ message: 'No longer needed' }),
|
|
80
|
-
})
|
|
81
|
-
expect(abandonResponse.ok).toBe(true)
|
|
102
|
+
it('should abandon a change without a message', async () => {
|
|
103
|
+
server.use(
|
|
104
|
+
http.get('*/a/changes/12345', () => {
|
|
105
|
+
return HttpResponse.text(`)]}'\n${JSON.stringify(mockChange)}`)
|
|
106
|
+
}),
|
|
107
|
+
http.post('*/a/changes/12345/abandon', async ({ request }) => {
|
|
108
|
+
const body = (await request.json()) as { message?: string }
|
|
109
|
+
expect(body.message).toBeUndefined()
|
|
110
|
+
return HttpResponse.text(")]}'\n{}")
|
|
111
|
+
}),
|
|
112
|
+
)
|
|
82
113
|
|
|
83
|
-
|
|
84
|
-
|
|
114
|
+
const mockConfigLayer = Layer.succeed(ConfigService, createMockConfigService())
|
|
115
|
+
const program = abandonCommand('12345', {}).pipe(
|
|
116
|
+
Effect.provide(GerritApiServiceLive),
|
|
117
|
+
Effect.provide(mockConfigLayer),
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
await Effect.runPromise(program)
|
|
121
|
+
|
|
122
|
+
const output = mockConsoleLog.mock.calls.map((call) => call[0]).join('\n')
|
|
123
|
+
expect(output).toContain('Abandoned change 12345')
|
|
124
|
+
expect(output).toContain('Test change to abandon')
|
|
125
|
+
expect(output).not.toContain('Message:')
|
|
85
126
|
})
|
|
86
127
|
|
|
87
|
-
it('should
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
128
|
+
it('should output XML format when --xml flag is used', async () => {
|
|
129
|
+
server.use(
|
|
130
|
+
http.get('*/a/changes/12345', () => {
|
|
131
|
+
return HttpResponse.text(`)]}'\n${JSON.stringify(mockChange)}`)
|
|
132
|
+
}),
|
|
133
|
+
http.post('*/a/changes/12345/abandon', async ({ request }) => {
|
|
134
|
+
const body = (await request.json()) as { message?: string }
|
|
135
|
+
expect(body.message).toBe('Abandoning for testing')
|
|
136
|
+
return HttpResponse.text(")]}'\n{}")
|
|
137
|
+
}),
|
|
138
|
+
)
|
|
92
139
|
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
140
|
+
const mockConfigLayer = Layer.succeed(ConfigService, createMockConfigService())
|
|
141
|
+
const program = abandonCommand('12345', {
|
|
142
|
+
xml: true,
|
|
143
|
+
message: 'Abandoning for testing',
|
|
144
|
+
}).pipe(Effect.provide(GerritApiServiceLive), Effect.provide(mockConfigLayer))
|
|
145
|
+
|
|
146
|
+
await Effect.runPromise(program)
|
|
147
|
+
|
|
148
|
+
const output = mockConsoleLog.mock.calls.map((call) => call[0]).join('\n')
|
|
149
|
+
expect(output).toContain('<?xml version="1.0" encoding="UTF-8"?>')
|
|
150
|
+
expect(output).toContain('<abandon_result>')
|
|
151
|
+
expect(output).toContain('<status>success</status>')
|
|
152
|
+
expect(output).toContain('<change_number>12345</change_number>')
|
|
153
|
+
expect(output).toContain('<subject><![CDATA[Test change to abandon]]></subject>')
|
|
154
|
+
expect(output).toContain('<message><![CDATA[Abandoning for testing]]></message>')
|
|
155
|
+
expect(output).toContain('</abandon_result>')
|
|
156
|
+
})
|
|
97
157
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
158
|
+
it('should output XML format without message when no message provided', async () => {
|
|
159
|
+
server.use(
|
|
160
|
+
http.get('*/a/changes/12345', () => {
|
|
161
|
+
return HttpResponse.text(`)]}'\n${JSON.stringify(mockChange)}`)
|
|
162
|
+
}),
|
|
163
|
+
http.post('*/a/changes/12345/abandon', async () => {
|
|
164
|
+
return HttpResponse.text(")]}'\n{}")
|
|
165
|
+
}),
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
const mockConfigLayer = Layer.succeed(ConfigService, createMockConfigService())
|
|
169
|
+
const program = abandonCommand('12345', { xml: true }).pipe(
|
|
170
|
+
Effect.provide(GerritApiServiceLive),
|
|
171
|
+
Effect.provide(mockConfigLayer),
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
await Effect.runPromise(program)
|
|
175
|
+
|
|
176
|
+
const output = mockConsoleLog.mock.calls.map((call) => call[0]).join('\n')
|
|
177
|
+
expect(output).toContain('<abandon_result>')
|
|
178
|
+
expect(output).toContain('<status>success</status>')
|
|
179
|
+
expect(output).not.toContain('<message>')
|
|
103
180
|
})
|
|
104
181
|
|
|
105
|
-
it('should handle
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
182
|
+
it('should handle not found errors gracefully', async () => {
|
|
183
|
+
server.use(
|
|
184
|
+
http.get('*/a/changes/99999', () => {
|
|
185
|
+
return HttpResponse.text('Change not found', { status: 404 })
|
|
186
|
+
}),
|
|
187
|
+
)
|
|
111
188
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
189
|
+
const mockConfigLayer = Layer.succeed(ConfigService, createMockConfigService())
|
|
190
|
+
const program = abandonCommand('99999', {
|
|
191
|
+
message: 'Test message',
|
|
192
|
+
}).pipe(Effect.provide(GerritApiServiceLive), Effect.provide(mockConfigLayer))
|
|
115
193
|
|
|
116
|
-
|
|
117
|
-
expect(
|
|
194
|
+
// Should fail when change is not found
|
|
195
|
+
await expect(Effect.runPromise(program)).rejects.toThrow()
|
|
118
196
|
})
|
|
119
197
|
|
|
120
|
-
it('should
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
198
|
+
it('should show error when change ID is not provided', async () => {
|
|
199
|
+
const mockConfigLayer = Layer.succeed(ConfigService, createMockConfigService())
|
|
200
|
+
const program = abandonCommand(undefined, {}).pipe(
|
|
201
|
+
Effect.provide(GerritApiServiceLive),
|
|
202
|
+
Effect.provide(mockConfigLayer),
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
await Effect.runPromise(program)
|
|
206
|
+
|
|
207
|
+
const errorOutput = mockConsoleError.mock.calls.map((call) => call[0]).join('\n')
|
|
208
|
+
expect(errorOutput).toContain('Change ID is required')
|
|
209
|
+
expect(errorOutput).toContain('Usage: ger abandon <change-id>')
|
|
132
210
|
})
|
|
133
211
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
'https://test.gerrit.com/a/changes/?q=owner:self+status:open',
|
|
144
|
-
)
|
|
145
|
-
const text = await response.text()
|
|
146
|
-
expect(text).toContain('Test change to abandon')
|
|
147
|
-
})
|
|
212
|
+
it('should handle abandon API failure', async () => {
|
|
213
|
+
server.use(
|
|
214
|
+
http.get('*/a/changes/12345', () => {
|
|
215
|
+
return HttpResponse.text(`)]}'\n${JSON.stringify(mockChange)}`)
|
|
216
|
+
}),
|
|
217
|
+
http.post('*/a/changes/12345/abandon', () => {
|
|
218
|
+
return HttpResponse.text('Forbidden', { status: 403 })
|
|
219
|
+
}),
|
|
220
|
+
)
|
|
148
221
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
'https://test.gerrit.com/a/changes/?q=owner:self+status:open',
|
|
157
|
-
)
|
|
158
|
-
const text = await response.text()
|
|
159
|
-
const parsed = JSON.parse(text.replace(")]}'\n", ''))
|
|
160
|
-
expect(parsed).toEqual([])
|
|
161
|
-
})
|
|
222
|
+
const mockConfigLayer = Layer.succeed(ConfigService, createMockConfigService())
|
|
223
|
+
const program = abandonCommand('12345', {
|
|
224
|
+
message: 'Test',
|
|
225
|
+
}).pipe(Effect.provide(GerritApiServiceLive), Effect.provide(mockConfigLayer))
|
|
226
|
+
|
|
227
|
+
// Should throw/fail
|
|
228
|
+
await expect(Effect.runPromise(program)).rejects.toThrow()
|
|
162
229
|
})
|
|
163
230
|
})
|