Open History to see the last commit
1import type { Route } from '@playwright/test'
2import { test, expect } from '../fixtures'
3import {
4 selectScenario,
5 runTest,
6 waitForApproval,
7 waitForPendingApprovals,
8 waitForTestComplete,
9 getMetadata,
10 getEventLog,
11 approveEachItem,
12 approveAll,
13 denyAll,
14 cancelAll,
15 resolveAllMixed,
16} from './helpers'
17
18/**
19 * Batch interrupt resolution — several approvals raised at once, resolved via
20 * the root helpers (`resolveInterrupts(true|false)`, `cancelInterrupts()`, and
21 * the resolver form) as well as per-item within the batch.
22 */
23test.describe('Batch interrupt resolution', () => {
24 test('batch - approve all (root, boolean)', async ({
25 page,
26 testId,
27 aimockPort,
28 }) => {
29 await selectScenario(page, 'batch', testId, aimockPort)
30 await runTest(page)
31 await waitForApproval(page)
32 await waitForPendingApprovals(page, 3)
33
34 await approveAll(page)
35 await waitForTestComplete(page)
36
37 const meta = await getMetadata(page)
38 expect(meta.hasError).toBe('false')
39 expect(meta.testComplete).toBe('true')
40 expect(parseInt(meta.completeToolCount)).toBe(3)
41 })
42
43 test('batch - deny all (root, boolean)', async ({
44 page,
45 testId,
46 aimockPort,
47 }) => {
48 await selectScenario(page, 'batch', testId, aimockPort)
49 await runTest(page)
50 await waitForApproval(page)
51 await waitForPendingApprovals(page, 3)
52 await denyAll(page)
53 await waitForTestComplete(page)
54
55 const meta = await getMetadata(page)
56 expect(meta.hasError).toBe('false')
57 expect(meta.testComplete).toBe('true')
58 expect(parseInt(meta.approvalDeniedCount)).toBe(1)
59 })
60
61 test('batch - cancel all (root)', async ({ page, testId, aimockPort }) => {
62 await selectScenario(page, 'batch', testId, aimockPort)
63 await runTest(page)
64 await waitForApproval(page)
65 await waitForPendingApprovals(page, 3)
66 await cancelAll(page)
67 await page.waitForTimeout(500)
68
69 const meta = await getMetadata(page)
70 expect(meta.hasError).toBe('false')
71 expect(parseInt(meta.approvalCancelledCount)).toBe(1)
72 })
73
74 test('batch - approve each item', async ({ page, testId, aimockPort }) => {
75 await selectScenario(page, 'batch', testId, aimockPort)
76 await runTest(page)
77 await waitForApproval(page)
78 await waitForPendingApprovals(page, 3)
79
80 const clicked = await approveEachItem(page)
81 expect(clicked).toBe(3)
82
83 await waitForTestComplete(page)
84 const meta = await getMetadata(page)
85 expect(meta.hasError).toBe('false')
86 expect(parseInt(meta.completeToolCount)).toBe(3)
87 })
88
89 test('batch-mixed - resolve all (root, resolver form)', async ({
90 page,
91 testId,
92 aimockPort,
93 }) => {
94 await selectScenario(page, 'batch-mixed', testId, aimockPort)
95 await runTest(page)
96 await waitForApproval(page)
97 await waitForPendingApprovals(page, 3)
98
99 await resolveAllMixed(page)
100 await waitForTestComplete(page)
101
102 const meta = await getMetadata(page)
103 expect(meta.hasError).toBe('false')
104 expect(meta.testComplete).toBe('true')
105 expect(parseInt(meta.completeToolCount)).toBe(3)
106
107 // The client tool in the mixed batch must have executed.
108 const events = await getEventLog(page)
109 expect(
110 events.some(
111 (e) =>
112 e.type === 'execution-complete' && e.toolName === 'printIntakeTag',
113 ),
114 ).toBe(true)
115 })
116
117 test('clear ignores a late interrupt submission failure', async ({
118 page,
119 testId,
120 aimockPort,
121 }) => {
122 const pageErrors: Array<Error> = []
123 page.on('pageerror', (error) => pageErrors.push(error))
124
125 await selectScenario(page, 'batch', testId, aimockPort)
126 await runTest(page)
127 await waitForApproval(page)
128 await waitForPendingApprovals(page, 3)
129
130 // Hold the resume request. Without this, a fast resume ends before the
131 // clear, and the test never sees a late failure.
132 let heldRoute: Route | undefined
133 await page.route(
134 '**/api/interrupts-test',
135 (route) => {
136 heldRoute = route
137 },
138 { times: 1 },
139 )
140
141 await approveAll(page)
142 await expect.poll(() => heldRoute).toBeDefined()
143 await page.click('#clear-button')
144 // The submission fails after the clear. The clear can already have
145 // aborted the request, so the route can be handled already.
146 await heldRoute?.abort('failed').catch(() => undefined)
147 await page.waitForTimeout(200)
148
149 const meta = await getMetadata(page)
150 expect(meta.hasError).toBe('false')
151 expect(meta.isLoading).toBe('false')
152 expect(meta.interruptCount).toBe('0')
153 expect(pageErrors).toEqual([])
154 })
155
156 test.afterEach(async ({ page }, testInfo) => {
157 if (testInfo.status !== testInfo.expectedStatus) {
158 console.log('Metadata:', await getMetadata(page))
159 console.log('Events:', await getEventLog(page))
160 }
161 })
162})