-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-byot-ai.spec.ts
More file actions
769 lines (677 loc) · 25.7 KB
/
github-byot-ai.spec.ts
File metadata and controls
769 lines (677 loc) · 25.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
import { expect, test } from '@playwright/test'
import { defaultGitHubChatModel } from '../src/modules/github-api.js'
import type { ChatRequestBody, ChatRequestMessage } from './helpers/app-test-helpers.js'
import {
appEntryPath,
connectByotWithSingleRepo,
ensureAiChatDrawerOpen,
ensureOpenPrDrawerOpen,
mockRepositoryBranches,
setComponentEditorSource,
setStylesEditorSource,
waitForAppReady,
} from './helpers/app-test-helpers.js'
test('PR/BYOT controls are visible and chat stays hidden until token connect', async ({
page,
}) => {
await waitForAppReady(page)
const byotControls = page.getByRole('group', { name: 'GitHub controls' })
const prToggle = page.getByRole('button', {
name: 'Open pull request',
exact: true,
includeHidden: true,
})
await expect(byotControls).toBeVisible()
await expect(page.getByRole('textbox', { name: 'GitHub token' })).toBeVisible()
await expect(page.getByRole('button', { name: 'Add GitHub token' })).toBeVisible()
await expect(page.getByRole('button', { name: 'Chat' })).toBeHidden()
await expect(page.getByRole('heading', { name: 'AI Chat' })).toBeHidden()
await expect(prToggle).toHaveCount(1)
await expect(prToggle).toBeHidden()
})
test('chat becomes available after token connect', async ({ page }) => {
await waitForAppReady(page)
await connectByotWithSingleRepo(page)
await expect(page.getByRole('button', { name: 'Open pull request' })).toBeVisible()
await expect(page.getByRole('button', { name: 'Chat' })).toBeVisible()
})
test('BYOT controls render with default app entry', async ({ page }) => {
await waitForAppReady(page, appEntryPath)
const byotControls = page.getByRole('group', { name: 'GitHub controls' })
const prToggle = page.getByRole('button', {
name: 'Open pull request',
exact: true,
includeHidden: true,
})
await expect(byotControls).toBeVisible()
await expect(page.getByRole('textbox', { name: 'GitHub token' })).toBeVisible()
await expect(page.getByRole('button', { name: 'Add GitHub token' })).toBeVisible()
await expect(page.getByRole('button', { name: 'Chat' })).toBeHidden()
await expect(prToggle).toHaveCount(1)
await expect(prToggle).toBeHidden()
})
test('GitHub token info panel reflects missing and present token states', async ({
page,
}) => {
await waitForAppReady(page, `${appEntryPath}`)
const infoButtonMissing = page.getByRole('button', {
name: 'About GitHub token features and privacy',
})
const infoButtonPresent = page.getByRole('button', {
name: 'About GitHub token privacy',
})
const missingMessage = page.getByText('Provide a GitHub PAT', { exact: false })
const presentMessage = page.getByText(
'This token is stored only in your browser and is sent only to GitHub APIs you invoke. Use the trash icon to remove it from storage.',
)
await expect(infoButtonMissing).toHaveAttribute('data-token-state', 'missing')
await expect(infoButtonMissing).toHaveAttribute(
'aria-label',
'About GitHub token features and privacy',
)
await expect(presentMessage).toBeHidden()
await infoButtonMissing.click()
await expect(missingMessage).toBeVisible()
await expect(missingMessage).toContainText('Provide a GitHub PAT')
await expect(page.getByRole('link', { name: 'docs' })).toHaveAttribute(
'href',
'https://github.com/knightedcodemonkey/develop/blob/main/docs/byot.md',
)
await expect(presentMessage).toBeHidden()
await connectByotWithSingleRepo(page)
await expect(infoButtonPresent).toHaveAttribute('data-token-state', 'present')
await expect(infoButtonPresent).toHaveAttribute(
'aria-label',
'About GitHub token privacy',
)
await infoButtonPresent.click()
await expect(presentMessage).toBeVisible()
await expect(presentMessage).toContainText(
'Use the trash icon to remove it from storage.',
)
await expect(missingMessage).toBeHidden()
})
test('deleting saved GitHub token requires confirmation modal', async ({ page }) => {
await waitForAppReady(page, `${appEntryPath}`)
await connectByotWithSingleRepo(page)
const dialog = page.getByRole('dialog', {
name: 'Remove saved GitHub token?',
includeHidden: true,
})
const tokenDelete = page.getByRole('button', { name: 'Delete GitHub token' })
const tokenAdd = page.getByRole('button', { name: 'Add GitHub token' })
const tokenInput = page.getByRole('textbox', { name: 'GitHub token' })
await expect(tokenDelete).toBeVisible()
await tokenDelete.click()
await expect(dialog).toHaveAttribute('open', '')
await expect(page.getByText('Remove saved GitHub token?', { exact: true })).toHaveText(
'Remove saved GitHub token?',
)
await expect(
page.getByText(
'This action removes the token from browser storage. You can add another token at any time.',
),
).toHaveText(
'This action removes the token from browser storage. You can add another token at any time.',
)
const removeButton = dialog.getByRole('button', { name: 'Remove' })
await expect(removeButton).toBeVisible()
await expect(removeButton).not.toHaveAttribute('aria-label')
await dialog.getByRole('button', { name: 'Cancel' }).click()
await expect(dialog).not.toHaveAttribute('open', '')
await expect(tokenDelete).toBeVisible()
await expect(tokenAdd).toBeHidden()
await tokenDelete.click()
await expect(dialog).toHaveAttribute('open', '')
await removeButton.click()
await expect(dialog).not.toHaveAttribute('open', '')
await expect(page.getByRole('status', { name: 'App status' })).toHaveText(
'GitHub token removed',
)
await expect(tokenAdd).toBeVisible()
await expect(tokenDelete).toBeHidden()
await expect(tokenInput).toHaveValue('')
})
test('AI chat drawer opens and closes', async ({ page }) => {
await waitForAppReady(page, appEntryPath)
await connectByotWithSingleRepo(page)
const chatToggle = page.getByRole('button', { name: 'Chat', exact: true })
const chatDrawer = page.getByRole('heading', { name: 'AI Chat' })
await expect(chatToggle).toBeVisible()
await expect(chatToggle).toHaveAttribute('aria-expanded', 'false')
await chatToggle.click()
await expect(chatDrawer).toBeVisible()
await expect(chatToggle).toHaveAttribute('aria-expanded', 'true')
await page.getByRole('button', { name: 'Close AI chat drawer' }).click()
await expect(chatDrawer).toBeHidden()
await expect(chatToggle).toHaveAttribute('aria-expanded', 'false')
})
test('AI chat prefers streaming responses when available', async ({ page }) => {
let streamRequestBody: ChatRequestBody | undefined
await page.route('https://models.github.ai/inference/chat/completions', async route => {
streamRequestBody = route.request().postDataJSON() as ChatRequestBody
await route.fulfill({
status: 200,
contentType: 'text/event-stream',
body: [
'data: {"choices":[{"delta":{"content":"Streaming "}}]}',
'',
'data: {"choices":[{"delta":{"content":"response ready"}}]}',
'',
'data: [DONE]',
'',
].join('\n'),
})
})
await waitForAppReady(page, `${appEntryPath}`)
await connectByotWithSingleRepo(page)
await ensureAiChatDrawerOpen(page)
await page.getByLabel('Ask AI assistant').fill('Summarize this repository.')
await page.getByRole('button', { name: 'Send' }).click()
await expect(
page.getByText('Response streamed from GitHub.', { exact: true }),
).toHaveText('Response streamed from GitHub.')
await expect(page.getByText('Summarize this repository.')).toBeVisible()
await expect(page.getByText('Streaming response ready')).toBeVisible()
expect(streamRequestBody?.metadata).toBeUndefined()
expect(streamRequestBody?.model).toBe(defaultGitHubChatModel)
expect(streamRequestBody?.tool_choice).toBe('auto')
expect(
streamRequestBody?.tools?.some(
tool => tool.type === 'function' && tool.function?.name === 'propose_editor_update',
),
).toBe(true)
expect(streamRequestBody?.messages?.[0]?.role).toBe('system')
expect(streamRequestBody?.messages?.[0]?.content).toContain(
'expert software development assistant focused on CSS dialects and JSX syntax',
)
const systemMessages = streamRequestBody?.messages?.filter(
(message: ChatRequestMessage) => message.role === 'system',
)
const repositorySystemMessage = systemMessages?.find((message: ChatRequestMessage) =>
message.content?.includes('Selected repository context'),
)
expect(repositorySystemMessage?.content).toContain(
'Repository: knightedcodemonkey/develop',
)
expect(repositorySystemMessage?.content).toContain(
'Repository URL: https://github.com/knightedcodemonkey/develop',
)
expect(
systemMessages?.some((message: ChatRequestMessage) =>
message.content?.includes('Editor context:'),
),
).toBe(true)
})
test('AI chat can disable editor context payload via checkbox', async ({ page }) => {
let streamRequestBody: ChatRequestBody | undefined
await page.route('https://models.github.ai/inference/chat/completions', async route => {
streamRequestBody = route.request().postDataJSON() as ChatRequestBody
await route.fulfill({
status: 200,
contentType: 'text/event-stream',
body: [
'data: {"choices":[{"delta":{"content":"ok"}}]}',
'',
'data: [DONE]',
'',
].join('\n'),
})
})
await waitForAppReady(page, `${appEntryPath}`)
await connectByotWithSingleRepo(page)
await ensureAiChatDrawerOpen(page)
const includeEditorsToggle = page.getByLabel('Send JSX + CSS editor context')
await expect(includeEditorsToggle).toBeChecked()
await includeEditorsToggle.uncheck()
await page.getByLabel('Ask AI assistant').fill('No editor source this time.')
await page.getByRole('button', { name: 'Send' }).click()
await expect(
page.getByText('Response streamed from GitHub.', { exact: true }),
).toHaveText('Response streamed from GitHub.')
expect(streamRequestBody?.metadata).toBeUndefined()
expect(streamRequestBody?.tool_choice).toBe('none')
const systemMessages = streamRequestBody?.messages?.filter(
(message: ChatRequestMessage) => message.role === 'system',
)
expect(
systemMessages?.some((message: ChatRequestMessage) =>
message.content?.includes('Selected repository context'),
),
).toBe(true)
expect(
systemMessages?.some((message: ChatRequestMessage) =>
message.content?.includes(
'Repository URL: https://github.com/knightedcodemonkey/develop',
),
),
).toBe(true)
expect(
systemMessages?.some((message: ChatRequestMessage) =>
message.content?.includes('Editor context:'),
),
).toBe(false)
})
test('AI chat proposals can be confirmed, applied, and undone for component and styles editors', async ({
page,
}) => {
await page.route('https://models.github.ai/inference/chat/completions', async route => {
const body = route.request().postDataJSON() as ChatRequestBody | null
if (body?.stream) {
await route.fulfill({
status: 502,
contentType: 'application/json',
body: JSON.stringify({ message: 'stream intentionally disabled in this test' }),
})
return
}
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
choices: [
{
message: {
role: 'assistant',
content: 'Prepared updates for both editors.',
tool_calls: [
{
id: 'call_component',
type: 'function',
function: {
name: 'propose_editor_update',
arguments: JSON.stringify({
target: 'component',
content: 'const App = () => <button type="button">Updated</button>',
rationale: 'Use explicit App component output.',
}),
},
},
{
id: 'call_styles',
type: 'function',
function: {
name: 'propose_editor_update',
arguments: JSON.stringify({
target: 'styles',
content: '.button { color: rgb(10 20 30); }',
rationale: 'Provide deterministic button styling.',
}),
},
},
],
},
},
],
}),
})
})
await waitForAppReady(page, `${appEntryPath}`)
await connectByotWithSingleRepo(page)
await setComponentEditorSource(page, 'const App = () => <button>Before</button>')
await setStylesEditorSource(page, '.button { color: red; }')
await ensureAiChatDrawerOpen(page)
await page.getByLabel('Ask AI assistant').fill('Suggest updates for both editors.')
await page.getByRole('button', { name: 'Send' }).click()
await expect(
page.getByText('Prepared updates for both editors.', { exact: true }),
).toBeVisible()
const assistantResponseMessage = page
.locator('.ai-chat-message--assistant')
.filter({ hasText: 'Prepared updates for both editors.' })
.first()
await expect(
page.getByRole('button', { name: 'Apply update to both editors' }),
).toBeVisible()
await page.getByRole('button', { name: 'Apply update to both editors' }).click()
await expect(
page.getByRole('button', { name: 'Apply update to both editors' }),
).toBeHidden()
await expect(
page.getByRole('button', { name: 'Apply update to Component editor' }),
).toBeHidden()
await expect(
page.getByRole('button', { name: 'Apply update to Styles editor' }),
).toBeHidden()
await expect(
assistantResponseMessage.getByRole('button', { name: 'Undo last Component apply' }),
).toHaveCount(0)
await expect(
assistantResponseMessage.getByRole('button', { name: 'Undo last Styles apply' }),
).toHaveCount(0)
await expect(
page.getByRole('button', { name: 'Undo last Component apply' }),
).toBeVisible()
await expect(page.getByRole('button', { name: 'Undo last Styles apply' })).toBeVisible()
await expect(page.locator('.component-panel .cm-content').first()).toContainText(
'Updated',
)
await expect(page.locator('.styles-panel .cm-content').first()).toContainText(
'rgb(10 20 30)',
)
await page.getByRole('button', { name: 'Undo last Component apply' }).click()
await expect(page.locator('.component-panel .cm-content').first()).toContainText(
'Before',
)
await page.getByRole('button', { name: 'Undo last Styles apply' }).click()
await expect(page.locator('.styles-panel .cm-content').first()).toContainText('red')
})
test('AI chat shows a single apply action when both editor proposals are available', async ({
page,
}) => {
await page.route('https://models.github.ai/inference/chat/completions', async route => {
const body = route.request().postDataJSON() as ChatRequestBody | null
if (body?.stream) {
await route.fulfill({
status: 502,
contentType: 'application/json',
body: JSON.stringify({ message: 'stream intentionally disabled in this test' }),
})
return
}
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
choices: [
{
message: {
role: 'assistant',
content: 'Prepared updates for both editors.',
tool_calls: [
{
id: 'call_component',
type: 'function',
function: {
name: 'propose_editor_update',
arguments: JSON.stringify({
target: 'component',
content: 'const App = () => <button type="button">Updated</button>',
}),
},
},
{
id: 'call_styles',
type: 'function',
function: {
name: 'propose_editor_update',
arguments: JSON.stringify({
target: 'styles',
content: '.button { color: rgb(10 20 30); }',
}),
},
},
],
},
},
],
}),
})
})
await waitForAppReady(page, `${appEntryPath}`)
await connectByotWithSingleRepo(page)
await setComponentEditorSource(page, 'const App = () => <button>Before</button>')
await setStylesEditorSource(page, '.button { color: red; }')
await ensureAiChatDrawerOpen(page)
await page.getByLabel('Ask AI assistant').fill('Suggest updates for both editors.')
await page.getByRole('button', { name: 'Send' }).click()
await expect(
page.getByText('Prepared updates for both editors.', { exact: true }),
).toBeVisible()
await expect(
page.getByRole('button', { name: 'Apply update to both editors' }),
).toBeVisible()
await expect(
page.getByRole('button', { name: 'Apply update to Component editor' }),
).toBeHidden()
await expect(
page.getByRole('button', { name: 'Apply update to Styles editor' }),
).toBeHidden()
})
test('AI chat streaming text still updates while latest undo actions are visible', async ({
page,
}) => {
let requestCount = 0
await page.route('https://models.github.ai/inference/chat/completions', async route => {
requestCount += 1
const body = route.request().postDataJSON() as ChatRequestBody | null
if (requestCount <= 2) {
if (body?.stream) {
await route.fulfill({
status: 502,
contentType: 'application/json',
body: JSON.stringify({ message: 'force fallback for proposal setup' }),
})
return
}
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
choices: [
{
message: {
role: 'assistant',
content: 'Prepared updates for styles editor.',
tool_calls: [
{
id: 'call_styles',
type: 'function',
function: {
name: 'propose_editor_update',
arguments: JSON.stringify({
target: 'styles',
content: '.button { color: rgb(10 20 30); }',
}),
},
},
],
},
},
],
}),
})
return
}
if (body?.stream) {
await route.fulfill({
status: 200,
contentType: 'text/event-stream',
body: [
'data: {"choices":[{"delta":{"content":"Streaming "}}]}',
'',
'data: {"choices":[{"delta":{"content":"works with undo visible."}}]}',
'',
'data: [DONE]',
'',
].join('\n'),
})
return
}
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
choices: [{ message: { role: 'assistant', content: 'fallback text' } }],
}),
})
})
await waitForAppReady(page, `${appEntryPath}`)
await connectByotWithSingleRepo(page)
await setStylesEditorSource(page, '.button { color: red; }')
await ensureAiChatDrawerOpen(page)
await page.getByLabel('Ask AI assistant').fill('Suggest a styles update.')
await page.getByRole('button', { name: 'Send' }).click()
await expect(
page.getByText('Prepared updates for styles editor.', { exact: true }),
).toBeVisible()
await page.getByRole('button', { name: 'Apply update to Styles editor' }).click()
await expect(page.getByRole('button', { name: 'Undo last Styles apply' })).toBeVisible()
await page
.getByLabel('Ask AI assistant')
.fill('Are you still working on that last request?')
await page.getByRole('button', { name: 'Send' }).click()
await expect(page.getByText('Streaming works with undo visible.')).toBeVisible()
})
test('AI chat falls back to non-streaming response when streaming fails', async ({
page,
}) => {
let streamAttemptCount = 0
let fallbackAttemptCount = 0
const attemptedModels: string[] = []
await page.route('https://models.github.ai/inference/chat/completions', async route => {
const body = route.request().postDataJSON() as ChatRequestBody | null
if (typeof body?.model === 'string') {
attemptedModels.push(body.model)
}
if (body?.stream) {
streamAttemptCount += 1
await route.fulfill({
status: 502,
contentType: 'application/json',
body: JSON.stringify({ message: 'stream failed' }),
})
return
}
fallbackAttemptCount += 1
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
rate_limit: {
remaining: 17,
reset: 1704067200,
},
choices: [
{
message: {
role: 'assistant',
content: 'Fallback response from JSON path.',
},
},
],
}),
})
})
await waitForAppReady(page, `${appEntryPath}`)
await connectByotWithSingleRepo(page)
await ensureAiChatDrawerOpen(page)
const selectedModel = 'openai/gpt-5-mini'
await page.getByLabel('Chat model').selectOption(selectedModel)
await expect(page.getByLabel('Chat model')).toHaveValue(selectedModel)
await page.getByLabel('Ask AI assistant').fill('Use fallback path.')
await page.getByRole('button', { name: 'Send' }).click()
await expect(page.getByText('Fallback response loaded.', { exact: true })).toHaveText(
'Fallback response loaded.',
)
await expect(page.getByText('Fallback response from JSON path.')).toBeVisible()
expect(streamAttemptCount).toBeGreaterThan(0)
expect(fallbackAttemptCount).toBeGreaterThan(0)
expect(attemptedModels.length).toBeGreaterThan(0)
expect(attemptedModels.every(model => model === selectedModel)).toBe(true)
})
test('clearing chat removes previous conversation context from new request', async ({
page,
}) => {
const streamBodies: ChatRequestBody[] = []
await page.route('https://models.github.ai/inference/chat/completions', async route => {
const body = route.request().postDataJSON() as ChatRequestBody
if (body?.stream) {
streamBodies.push(body)
await route.fulfill({
status: 200,
contentType: 'text/event-stream',
body: [
'data: {"choices":[{"delta":{"content":"ok"}}]}',
'',
'data: [DONE]',
'',
].join('\n'),
})
return
}
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
choices: [{ message: { role: 'assistant', content: 'ok' } }],
}),
})
})
await waitForAppReady(page, `${appEntryPath}`)
await connectByotWithSingleRepo(page)
await ensureAiChatDrawerOpen(page)
await page.getByLabel('Ask AI assistant').fill('First conversation prompt')
await page.getByRole('button', { name: 'Send' }).click()
await expect(
page.getByText('Response streamed from GitHub.', { exact: true }),
).toBeVisible()
await page.getByRole('button', { name: 'Clear', exact: true }).click()
await expect(page.getByText('Chat cleared.', { exact: true })).toBeVisible()
await page.getByLabel('Ask AI assistant').fill('Second conversation prompt')
await page.getByRole('button', { name: 'Send' }).click()
await expect(
page.getByText('Response streamed from GitHub.', { exact: true }),
).toBeVisible()
expect(streamBodies.length).toBeGreaterThanOrEqual(2)
const latestMessages = streamBodies[streamBodies.length - 1]?.messages ?? []
const allLatestContent = latestMessages.map(message => message.content ?? '').join('\n')
expect(allLatestContent).toContain('Second conversation prompt')
expect(allLatestContent).not.toContain('First conversation prompt')
})
test('BYOT remembers selected repository across reloads', async ({ page }) => {
test.setTimeout(90_000)
await page.route('https://api.github.com/user/repos**', async route => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify([
{
id: 2,
owner: { login: 'knightedcodemonkey' },
name: 'develop',
full_name: 'knightedcodemonkey/develop',
default_branch: 'main',
permissions: { push: true },
},
{
id: 1,
owner: { login: 'knightedcodemonkey' },
name: 'css',
full_name: 'knightedcodemonkey/css',
default_branch: 'main',
permissions: { push: true },
},
]),
})
})
await mockRepositoryBranches(page, {
'knightedcodemonkey/develop': ['main', 'release'],
'knightedcodemonkey/css': ['main', 'release/1.x'],
})
await waitForAppReady(page, `${appEntryPath}`)
await page
.getByRole('textbox', { name: 'GitHub token' })
.fill('github_pat_fake_1234567890')
await page.getByRole('button', { name: 'Add GitHub token' }).click()
await ensureOpenPrDrawerOpen(page)
const repoSelect = page.getByLabel('Pull request repository')
await expect(repoSelect).toBeEnabled()
await expect(page.getByRole('status', { name: 'App status' })).toHaveText(
'Loaded 2 writable repositories',
)
await repoSelect.selectOption('knightedcodemonkey/develop')
await expect(repoSelect).toHaveValue('knightedcodemonkey/develop')
await page.reload()
await expect(page.getByRole('heading', { name: '@knighted/develop' })).toBeVisible()
await expect(page.getByRole('status', { name: 'App status' })).toHaveText(
'Loaded 2 writable repositories',
{
timeout: 60_000,
},
)
await expect(page.getByRole('button', { name: 'Add GitHub token' })).toBeHidden()
await expect(page.getByRole('button', { name: 'Delete GitHub token' })).toBeVisible()
await ensureOpenPrDrawerOpen(page)
await expect(repoSelect).toHaveValue('knightedcodemonkey/develop')
})