fix(workspace): skip queries for missing jobs
This commit is contained in:
@@ -65,17 +65,27 @@ export const AgentWorkspaceShell = ({ jobId }: { jobId: Id<'agentJobs'> }) => {
|
|||||||
| null
|
| null
|
||||||
| undefined;
|
| undefined;
|
||||||
const messages =
|
const messages =
|
||||||
useQuery(api.agentJobs.listMessages, { jobId, limit: 200 }) ?? [];
|
useQuery(
|
||||||
|
api.agentJobs.listMessages,
|
||||||
|
job ? { jobId, limit: 200 } : 'skip',
|
||||||
|
) ?? [];
|
||||||
const events =
|
const events =
|
||||||
useQuery(api.agentJobs.listEvents, { jobId, limit: 200 }) ?? [];
|
useQuery(api.agentJobs.listEvents, job ? { jobId, limit: 200 } : 'skip') ??
|
||||||
|
[];
|
||||||
const workspaceChanges =
|
const workspaceChanges =
|
||||||
useQuery(api.agentJobs.listWorkspaceChanges, { jobId, limit: 200 }) ?? [];
|
useQuery(
|
||||||
|
api.agentJobs.listWorkspaceChanges,
|
||||||
|
job ? { jobId, limit: 200 } : 'skip',
|
||||||
|
) ?? [];
|
||||||
const interactions =
|
const interactions =
|
||||||
useQuery(api.agentJobs.listInteractionRequests, {
|
useQuery(
|
||||||
jobId,
|
api.agentJobs.listInteractionRequests,
|
||||||
status: 'all',
|
job ? { jobId, status: 'all' } : 'skip',
|
||||||
}) ?? [];
|
) ?? [];
|
||||||
const uiState = useQuery(api.agentJobs.getWorkspaceUiState, { jobId });
|
const uiState = useQuery(
|
||||||
|
api.agentJobs.getWorkspaceUiState,
|
||||||
|
job ? { jobId } : 'skip',
|
||||||
|
);
|
||||||
const patchUiState = useMutation(api.agentJobs.patchWorkspaceUiState);
|
const patchUiState = useMutation(api.agentJobs.patchWorkspaceUiState);
|
||||||
const createJobForThread = useMutation(api.agentJobs.createForThread);
|
const createJobForThread = useMutation(api.agentJobs.createForThread);
|
||||||
const deleteWorkspace = useMutation(api.agentJobs.deleteWorkspace);
|
const deleteWorkspace = useMutation(api.agentJobs.deleteWorkspace);
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import { getFunctionName } from 'convex/server';
|
||||||
import { describe, expect, it, vi } from 'vitest';
|
import { describe, expect, it, vi } from 'vitest';
|
||||||
|
|
||||||
import { AgentWorkspaceShell } from '../../src/components/agent-workspace/agent-workspace-shell';
|
import { AgentWorkspaceShell } from '../../src/components/agent-workspace/agent-workspace-shell';
|
||||||
|
|
||||||
const { mockUseMutation, mockUseQuery } = vi.hoisted(() => ({
|
const { mockUseMutation, mockUseQuery } = vi.hoisted(() => ({
|
||||||
mockUseMutation: vi.fn(() => vi.fn()),
|
mockUseMutation: vi.fn(() => vi.fn()),
|
||||||
mockUseQuery: vi.fn(() => null),
|
mockUseQuery: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('convex/react', () => ({
|
vi.mock('convex/react', () => ({
|
||||||
@@ -21,11 +22,29 @@ vi.mock('sonner', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
describe('AgentWorkspaceShell', () => {
|
describe('AgentWorkspaceShell', () => {
|
||||||
it('renders a missing state when the job query returns null', () => {
|
it('renders a missing state and skips dependent queries for a null job', () => {
|
||||||
|
mockUseQuery.mockImplementation((query) =>
|
||||||
|
getFunctionName(query) === 'agentJobs:get' ? null : undefined,
|
||||||
|
);
|
||||||
|
|
||||||
render(<AgentWorkspaceShell jobId={'job-1' as never} />);
|
render(<AgentWorkspaceShell jobId={'job-1' as never} />);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
screen.getByText('This workspace was not found.'),
|
screen.getByText('This workspace was not found.'),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
mockUseQuery.mock.calls.map(([query]) => getFunctionName(query)),
|
||||||
|
).toEqual([
|
||||||
|
'agentJobs:get',
|
||||||
|
'agentJobs:listMessages',
|
||||||
|
'agentJobs:listEvents',
|
||||||
|
'agentJobs:listWorkspaceChanges',
|
||||||
|
'agentJobs:listInteractionRequests',
|
||||||
|
'agentJobs:getWorkspaceUiState',
|
||||||
|
]);
|
||||||
|
expect(mockUseQuery.mock.calls[0]?.[1]).toEqual({ jobId: 'job-1' });
|
||||||
|
for (let call = 2; call <= 6; call += 1) {
|
||||||
|
expect(mockUseQuery.mock.calls[call - 1]?.[1]).toBe('skip');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user