Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions packages/web-shell/client/hooks/useSessionArtifacts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,73 @@ describe('useSessionArtifacts', () => {
'replacement',
]);
});

it('keeps automatic refresh failures silent and recovers on the next refresh (#7427)', async () => {
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
// A transient `Failed to fetch` on an automatic refresh is noise the user
// cannot act on. The panel keeps last-good artifacts when it has them,
// clears `loading`, and exposes no error state.
sdkMock.actions.loadArtifacts
.mockRejectedValueOnce(new Error('Failed to fetch'))
.mockResolvedValueOnce({ artifacts: [artifact('current-artifact')] })
.mockRejectedValueOnce(new Error('Failed to fetch'))
.mockRejectedValueOnce(new Error('Failed to fetch'))
.mockResolvedValueOnce({ artifacts: [artifact('recovered-artifact')] });

await renderHookHost();

// Automatic refresh #1: initial mount fails before any last-good data exists.
await act(async () => {
await Promise.resolve();
});
expect(latestState?.loading).toBe(false);
expect(latestState?.error).toBeNull();
expect(latestState?.artifacts).toEqual([]);

// Automatic refresh #2: artifactsVersion recovers and establishes last-good.
sdkMock.artifactsVersion = 1;
await rerenderHookHost();
await act(async () => {
await Promise.resolve();
});
expect(latestState?.artifacts.map((item) => item.id)).toEqual([
'current-artifact',
]);
expect(latestState?.loading).toBe(false);

// Automatic refresh #3: prompt settling back to idle fails transiently.
sdkMock.promptStatus = 'running';
await rerenderHookHost();
sdkMock.promptStatus = 'idle';
await rerenderHookHost();
await act(async () => {
await Promise.resolve();
});
expect(latestState?.loading).toBe(false);
expect(latestState?.error).toBeNull();
expect(latestState?.artifacts.map((item) => item.id)).toEqual([
'current-artifact',
]);

// Automatic refresh #4: artifactsVersion fails and still keeps last-good.
sdkMock.artifactsVersion = 2;
await rerenderHookHost();
await act(async () => {
await Promise.resolve();
});
expect(latestState?.loading).toBe(false);
expect(latestState?.error).toBeNull();
expect(latestState?.artifacts.map((item) => item.id)).toEqual([
'current-artifact',
]);

// The panel is not wedged: the next automatic refresh recovers.
sdkMock.artifactsVersion = 3;
await rerenderHookHost();
await act(async () => {
await Promise.resolve();
});
expect(latestState?.artifacts.map((item) => item.id)).toEqual([
'recovered-artifact',
]);
});
});
Loading