Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 5 additions & 7 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@

from tests import postgres_testdb

# One fixed key for every test process: the controller, the xdist workers, and
# the subprocesses they start (e.g. ``alembic`` in ``run_alembic``). Without
# it, each worker reads or creates ``~/.openhands/.keys`` while it imports the
# test modules, the workers can each create a different key, and a test that
# encrypts in pytest and decrypts in a subprocess fails on some workers.
# Set here, before any test module is imported, so the key that
# ``storage.encrypt_utils`` caches at import time comes from this value.
# One fixed key for every test process: xdist workers that each create their
# own ``~/.openhands/.keys`` key would fail when pytest encrypts and a
# subprocess (e.g. ``alembic`` in ``run_alembic``) decrypts. Set before any
# test module is imported, because ``storage.encrypt_utils`` caches the key
# at import time.
os.environ['JWT_SECRET'] = 'test-jwt-secret'


Expand Down
2 changes: 0 additions & 2 deletions frontend/__mocks__/zustand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export * from "zustand";
const { create: actualCreate, createStore: actualCreateStore } =
await vi.importActual<typeof ZustandExportedTypes>("zustand");

// a variable to hold reset functions for all stores declared in the app
export const storeResetFns = new Set<() => void>();

const createUncurried = <T>(
Expand Down Expand Up @@ -50,7 +49,6 @@ export const createStore = (<T>(
? createStoreUncurried(stateCreator)
: createStoreUncurried) as typeof ZustandExportedTypes.createStore;

// reset all stores after each test run
afterEach(() => {
act(() => {
storeResetFns.forEach((resetFn) => {
Expand Down
2 changes: 0 additions & 2 deletions frontend/__tests__/api/v1-conversation-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ describe("V1ConversationService", () => {
expect(axios.post).toHaveBeenCalledTimes(1);
const callArgs = (axios.post as Mock).mock.calls[0];

// Verify FormData is sent
const formData = callArgs[1];
expect(formData).toBeInstanceOf(FormData);
expect(formData.get("file")).toBe(file);

// Verify headers include session API key and content type
const headers = callArgs[2].headers;
expect(headers).toHaveProperty("X-Session-API-Key", sessionApiKey);
expect(headers).toHaveProperty("Content-Type", "multipart/form-data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { render, screen } from "@testing-library/react";
import { test, expect, describe, vi } from "vitest";
import { CopyToClipboardButton } from "#/components/shared/buttons/copy-to-clipboard-button";

// Mock react-i18next
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string) => key,
Expand Down
11 changes: 0 additions & 11 deletions frontend/__tests__/components/chat/chat-interface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ vi.mock("#/hooks/use-agent-state", () => ({
})),
}));

// Helper function to render with Router context
const renderChatInterfaceWithRouter = () =>
renderWithProviders(
<MemoryRouter>
Expand All @@ -72,7 +71,6 @@ const renderChatInterface = (messages: Message[]) =>
</MemoryRouter>,
);

// Helper function to render with QueryClientProvider and Router (for newer tests)
const renderWithQueryClient = (
ui: React.ReactElement,
queryClient: QueryClient,
Expand All @@ -97,7 +95,6 @@ beforeEach(() => {
});

describe("ChatInterface - Chat Suggestions", () => {
// Create a new QueryClient for each test
let queryClient: QueryClient;

beforeEach(() => {
Expand Down Expand Up @@ -158,7 +155,6 @@ describe("ChatInterface - Chat Suggestions", () => {

renderWithQueryClient(<ChatInterface />, queryClient);

// Check if ChatSuggestions is not rendered with user events
expect(screen.queryByTestId("chat-suggestions")).not.toBeInTheDocument();
});

Expand All @@ -169,7 +165,6 @@ describe("ChatInterface - Chat Suggestions", () => {

renderWithQueryClient(<ChatInterface />, queryClient);

// Check if ChatSuggestions is not rendered with optimistic user message
expect(screen.queryByTestId("chat-suggestions")).not.toBeInTheDocument();
});
});
Expand Down Expand Up @@ -200,11 +195,9 @@ describe("ChatInterface - Empty state", () => {
const suggestions = screen.getByTestId("chat-suggestions");
const repoSuggestions = Object.keys(SUGGESTIONS.repo);

// check that there are at most 4 suggestions displayed
const displayedSuggestions = within(suggestions).getAllByRole("button");
expect(displayedSuggestions.length).toBeLessThanOrEqual(4);

// Check that each displayed suggestion is one of the repo suggestions
displayedSuggestions.forEach((suggestion) => {
expect(repoSuggestions).toContain(suggestion.textContent);
});
Expand Down Expand Up @@ -296,7 +289,6 @@ describe('ChatInterface - Status Indicator', () => {

describe.skip("ChatInterface - General functionality", () => {
beforeAll(() => {
// mock useScrollToBottom hook
vi.mock("#/hooks/useScrollToBottom", () => ({
useScrollToBottom: vi.fn(() => ({
scrollDomToBottom: vi.fn(),
Expand Down Expand Up @@ -487,18 +479,15 @@ describe.skip("ChatInterface - General functionality", () => {
const { rerender } = renderChatInterface(messages);
const user = userEvent.setup();

// Click the "Push & Create PR" button
const prButton = screen.getByRole("button", { name: "Push & Create PR" });
await user.click(prButton);

// Re-render to trigger state update
rerender(
<MemoryRouter>
<ChatInterface />
</MemoryRouter>,
);

// Verify only one button is shown
const pushToPrButton = screen.getByRole("button", {
name: "Push changes to PR",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { useAgentState } from "#/hooks/use-agent-state";
import { AgentState } from "#/types/agent-state";
import { OpenHandsAction } from "#/types/core/actions";

// Module-level mocks
vi.mock("#/context/ws-client-provider");
vi.mock("#/hooks/query/use-config");
vi.mock("#/hooks/mutation/use-get-trajectory");
Expand Down Expand Up @@ -49,7 +48,6 @@ vi.mock("#/hooks/use-agent-state", () => ({
})),
}));

// Helper to render with QueryClient and route params
const renderWithQueryClient = (
ui: React.ReactElement,
queryClient: QueryClient,
Expand Down Expand Up @@ -115,13 +113,11 @@ describe("ChatInterface – message display continuity (spec 3.1)", () => {
data: undefined,
} as ReturnType<typeof useActiveConversation>);

// Default: no websocket context
vi.mocked(useConversationWebSocket).mockReturnValue(null);
});

describe("V1 conversations", () => {
beforeEach(() => {
// Set up V1 conversation
vi.mocked(useActiveConversation).mockReturnValue({
data: {},
} as ReturnType<typeof useActiveConversation>);
Expand All @@ -135,7 +131,6 @@ describe("ChatInterface – message display continuity (spec 3.1)", () => {
sendMessage: vi.fn(),
});

// Put V1 user events in the store
const v1UserEvent = createUserMessageEvent("evt-1");
useEventStore.setState({
events: [v1UserEvent],
Expand All @@ -159,7 +154,6 @@ describe("ChatInterface – message display continuity (spec 3.1)", () => {
sendMessage: vi.fn(),
});

// Store is empty
useEventStore.setState({
events: [],
uiEvents: [],
Expand Down
11 changes: 2 additions & 9 deletions frontend/__tests__/components/conversation-tab-title.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-
import { AgentState } from "#/types/agent-state";
import { createChatMessage } from "#/services/chat-service";

// Mock the hook that provides git changes functionality
vi.mock("#/hooks/query/use-unified-get-git-changes", () => ({
useUnifiedGetGitChanges: vi.fn(() => ({
refetch: vi.fn(),
Expand All @@ -18,7 +17,6 @@ vi.mock("#/hooks/query/use-unified-get-git-changes", () => ({
})),
}));

// Mock i18n
vi.mock("react-i18next", async (importOriginal) => {
const actual = await importOriginal<typeof import("react-i18next")>();
return {
Expand All @@ -29,7 +27,6 @@ vi.mock("react-i18next", async (importOriginal) => {
};
});

// Mock services for Build button
const mockSend = vi.fn();

vi.mock("#/hooks/use-send-message", () => ({
Expand All @@ -45,7 +42,6 @@ vi.mock("#/services/chat-service", () => ({
})),
}));

// Mock the hooks that useUnifiedGetGitChanges depends on
vi.mock("#/hooks/use-conversation-id", () => ({
useConversationId: () => ({
conversationId: "test-conversation-id",
Expand Down Expand Up @@ -90,7 +86,6 @@ describe("ConversationTabTitle", () => {
},
});

// Reset stores for Build button tests
useConversationStore.setState({
planContent: null,
conversationMode: "plan",
Expand Down Expand Up @@ -164,7 +159,6 @@ describe("ConversationTabTitle", () => {
const title = "Changes";
const mockRefetch = vi.fn();

// Import the hook mock to get a reference to it
const { useUnifiedGetGitChanges } = await import(
"#/hooks/query/use-unified-get-git-changes"
);
Expand Down Expand Up @@ -238,9 +232,8 @@ describe("ConversationTabTitle", () => {
});

it("should disable Build button when agent is running", () => {
// Note: This test is now covered by the useHandleBuildPlanClick hook tests
// because the component now uses useAgentState hook which is mocked to always
// return AWAITING_USER_INPUT in this test file
// Covered by the useHandleBuildPlanClick hook tests; the component reads
// useAgentState, which this file mocks to always return AWAITING_USER_INPUT
// Arrange
useConversationStore.setState({ planContent: null });
useAgentStore.setState({ curAgentState: AgentState.RUNNING });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { I18nKey } from "#/i18n/declaration";

describe("formatShortDate", () => {
// Date-only API strings parse as UTC midnight; labels must not shift
// with the viewer's timezone (previously "2026-07-01" showed "Jun 30"
// for viewers west of UTC).
// with the viewer's timezone (west of UTC, 2026-07-01 would read Jun 30).
it("renders the UTC calendar date regardless of local timezone", () => {
expect(formatShortDate("2026-07-01")).toBe("Jul 1");
expect(formatShortDate("2026-06-23")).toBe("Jun 23");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { act } from "react";
import { MemoryRouter } from "react-router";
import { AlertBanner } from "#/components/features/alerts/alert-banner";

// Mock react-i18next
vi.mock("react-i18next", async () => {
const actual =
await vi.importActual<typeof import("react-i18next")>("react-i18next");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ import { ChangeAgentButton } from "#/components/features/chat/change-agent-butto
import { renderWithProviders } from "../../../../test-utils";
import { useConversationStore } from "#/stores/conversation-store";

// Mock WebSocket status
vi.mock("#/hooks/use-unified-websocket-status", () => ({
useUnifiedWebSocketStatus: () => "CONNECTED",
}));

// Mock agent state
vi.mock("#/hooks/use-agent-state", () => ({
useAgentState: () => ({ curAgentState: "IDLE", isArchived: false }),
}));

// Track invalidateQueries calls
const mockInvalidateQueries = vi.fn();

// Mock react-query to track invalidateQueries calls
vi.mock("@tanstack/react-query", async () => {
const actual = await vi.importActual("@tanstack/react-query");
return {
Expand All @@ -29,7 +25,6 @@ vi.mock("@tanstack/react-query", async () => {
};
});

// Mock the active conversation hook
const mockConversationData = {
id: "parent-conversation-123",
sub_conversation_ids: [],
Expand All @@ -43,7 +38,6 @@ vi.mock("#/hooks/query/use-active-conversation", () => ({
}),
}));

// Mock the sub-conversation task polling hook to control task status
const mockTaskPollingResult = {
task: null as any,
taskStatus: undefined as string | undefined,
Expand All @@ -57,7 +51,6 @@ vi.mock("#/hooks/query/use-sub-conversation-task-polling", () => ({
useSubConversationTaskPolling: () => mockTaskPollingResult,
}));

// Mock the handle plan click hook
vi.mock("#/hooks/use-handle-plan-click", () => ({
useHandlePlanClick: () => ({
handlePlanClick: vi.fn(),
Expand All @@ -68,12 +61,10 @@ vi.mock("#/hooks/use-handle-plan-click", () => ({
describe("ChangeAgentButton - Cache Invalidation", () => {
beforeEach(() => {
vi.clearAllMocks();
// Reset store state
useConversationStore.setState({
conversationMode: "code",
subConversationTaskId: null,
});
// Reset mock task polling result
mockTaskPollingResult.taskStatus = undefined;
mockTaskPollingResult.subConversationId = undefined;
});
Expand All @@ -88,7 +79,6 @@ describe("ChangeAgentButton - Cache Invalidation", () => {
subConversationTaskId: "task-456",
});

// Simulate task becoming READY
mockTaskPollingResult.taskStatus = "READY";
mockTaskPollingResult.subConversationId = "sub-conversation-789";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ import { render, screen } from "@testing-library/react";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { GitControlBarRepoButton } from "#/components/features/chat/git-control-bar-repo-button";

// Mock react-i18next
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string) => key,
}),
}));

// Mock GitProviderIcon
vi.mock("#/components/shared/git-provider-icon", () => ({
GitProviderIcon: ({ gitProvider }: { gitProvider: string }) => (
<span data-testid="git-provider-icon">{gitProvider}</span>
),
}));

// Mock GitExternalLinkIcon
vi.mock(
"#/components/features/chat/git-external-link-icon",
() => ({
Expand All @@ -26,7 +23,6 @@ vi.mock(
}),
);

// Mock RepoForkedIcon
vi.mock("#/icons/repo-forked.svg?react", () => ({
default: () => <span data-testid="repo-forked-icon">forked</span>,
}));
Expand All @@ -35,7 +31,6 @@ vi.mock("#/hooks/use-provider-host", () => ({
useProviderHost: () => null,
}));

// Mock constructRepositoryUrl
vi.mock("#/utils/utils", async (importOriginal) => {
const actual = await importOriginal<typeof import("#/utils/utils")>();
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { describe, it, expect, vi } from "vitest";
import { TaskTrackingObservationContent } from "#/components/features/chat/task-tracking-observation-content";
import { TaskTrackingObservation } from "#/types/core/observations";

// Mock the translation hook
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string) => {
Expand Down
Loading
Loading