Skip to content

Commit e692917

Browse files
committed
fix(report-ui): refresh policy_pending state during derivation
Entire-Checkpoint: de45e72e5f88
1 parent 7619852 commit e692917

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

packages/report-ui/src/components/ReportPage.test.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,56 @@ describe('ReportPage', () => {
174174
expect(screen.getByText('Review review_123')).toBeInTheDocument();
175175
});
176176

177+
it('polls review status while policy derivation is pending', async () => {
178+
const fetchMock = vi
179+
.fn()
180+
.mockResolvedValueOnce({
181+
ok: true,
182+
json: async () => ({
183+
review: {
184+
...mockReview,
185+
status: 'policy_pending',
186+
findings: [],
187+
summary: undefined,
188+
summaryText: undefined,
189+
markdownSummary: null,
190+
},
191+
}),
192+
})
193+
.mockResolvedValue({
194+
ok: true,
195+
json: async () => ({
196+
review: {
197+
...mockReview,
198+
status: 'policy_ready',
199+
findings: [],
200+
summary: undefined,
201+
summaryText: undefined,
202+
markdownSummary: null,
203+
derivedPolicy: {
204+
goal: 'Reduce risk quickly',
205+
prohibitions: ['Do not alter public API behavior'],
206+
constraints: ['Prefer small isolated changes'],
207+
},
208+
},
209+
}),
210+
});
211+
vi.stubGlobal('fetch', fetchMock);
212+
213+
render(
214+
<MemoryRouter initialEntries={['/reports/review_123']}>
215+
<Routes>
216+
<Route path="/reports/:reviewId" element={<ReportPage />} />
217+
</Routes>
218+
</MemoryRouter>
219+
);
220+
221+
await screen.findByText('Preparing policy draft');
222+
expect(fetchMock).toHaveBeenCalledTimes(1);
223+
expect(await screen.findByText('Policy review required', {}, { timeout: 2900 })).toBeInTheDocument();
224+
expect(fetchMock.mock.calls.length).toBeGreaterThan(1);
225+
});
226+
177227
it('renders policy_ready editor and approves policy with accepted payload response', async () => {
178228
const fetchMock = vi
179229
.fn()

packages/report-ui/src/components/ReportPage.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ function statusFromReviewEventType(eventType: string): ReviewResponse['status']
134134
case 'review_created':
135135
case 'review_enqueued':
136136
return 'queued';
137+
case 'review_policy_derivation_started':
138+
return 'policy_pending';
139+
case 'review_policy_derivation_completed':
140+
return 'policy_ready';
137141
case 'review_succeeded':
138142
return 'succeeded';
139143
case 'review_failed':
@@ -858,6 +862,20 @@ export function ReportPage(): JSX.Element {
858862
};
859863
}, [review?.status, policyProgressCycle]);
860864

865+
useEffect(() => {
866+
if (!review || review.status !== 'policy_pending') {
867+
return;
868+
}
869+
870+
const timer = window.setTimeout(() => {
871+
setRefreshCycle((value) => value + 1);
872+
}, 2000);
873+
874+
return () => {
875+
window.clearTimeout(timer);
876+
};
877+
}, [review?.id, review?.status, refreshCycle]);
878+
861879
useEffect(() => {
862880
if (state !== 'loaded' || !review) {
863881
return;

0 commit comments

Comments
 (0)