π OpenHands: AI-Driven Development
Stabilize mock frontend flows\n\nCo-authored-by: openhands <[email protected]>
openhands7f975475c057
diff --git a/AGENTS.md b/AGENTS.mdindex 26ba9a6ab5..74d8237b19 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -14,3 +14,11 @@- `VITE_ENABLE_BROWSER_TOOLS=false` to omit `BrowserToolSet` from new conversation payloads.- The UI keeps most OpenHands routes/layout intact, but SaaS/org/billing/integration behavior is intentionally hidden or stubbed via the fabricated OSS config because there is no separate app backend.- Verification command: `npm run typecheck && npm run build`.+- `npm run dev:mock` needs MSW handlers for the direct agent-server routes used by the adapted frontend, not the original OpenHands mock paths. Key routes that must stay covered are:+ - bootstrap/model loading: `/server_info`, `/api/llm/models/verified`, `/api/llm/providers`+ - settings schemas: `/api/settings/agent-schema`, `/api/settings/conversation-schema`+ - conversation browsing/loading: `/api/conversations/search`, `/api/conversations?ids=...`, `/api/conversations/:id`, `/api/conversations/:id/events/*`+ - runtime git panels: `/api/git/changes`, `/api/git/diff`+- Useful regression tests for mock mode live in `__tests__/api/option-service.test.ts`, `__tests__/api/mock-conversation-handlers.test.ts`, and `__tests__/api/mock-settings-handlers.test.ts`.+- Browser-verified mock-mode tour artifact was generated at `artifacts/frontend-tour.gif`.+diff --git a/__tests__/api/mock-conversation-handlers.test.ts b/__tests__/api/mock-conversation-handlers.test.tsnew file mode 100644index 0000000000..9c8ad6e1f8--- /dev/null+++ b/__tests__/api/mock-conversation-handlers.test.ts@@ -0,0 +1,33 @@+import { describe, expect, it } from "vitest";+import V1ConversationService from "#/api/conversation-service/v1-conversation-service.api";+import V1GitService from "#/api/git-service/v1-git-service.api";++describe("mock conversation handlers", () => {+ it("returns adapted conversations for batch lookups", async () => {+ const [conversation] = await V1ConversationService.batchGetAppConversations([+ "1",+ ]);++ expect(conversation?.id).toBe("1");+ expect(conversation?.title).toBe("My New Project");+ expect(conversation?.conversation_url).toContain("/api/conversations/1");+ });++ it("returns adapted conversation pages for search", async () => {+ const page = await V1ConversationService.searchConversations(10);++ expect(page.items.length).toBeGreaterThan(0);+ expect(page.next_page_id).toBeNull();+ expect(page.items[0]?.title).toBeTruthy();+ });++ it("returns empty git changes for mock conversations", async () => {+ const changes = await V1GitService.getGitChanges(+ "http://localhost:3000/api/conversations/1",+ null,+ "/workspace/project",+ );++ expect(changes).toEqual([]);+ });+});diff --git a/__tests__/api/mock-settings-handlers.test.ts b/__tests__/api/mock-settings-handlers.test.tsnew file mode 100644index 0000000000..4a68064d71--- /dev/null+++ b/__tests__/api/mock-settings-handlers.test.ts@@ -0,0 +1,18 @@+import { describe, expect, it } from "vitest";+import SettingsService from "#/api/settings-service/settings-service.api";++describe("mock settings handlers", () => {+ it("returns the agent settings schema on the paths used by the UI", async () => {+ const schema = await SettingsService.getSettingsSchema();++ expect(schema.sections.some((section) => section.key === "llm")).toBe(true);+ });++ it("returns the conversation settings schema on the paths used by the UI", async () => {+ const schema = await SettingsService.getConversationSettingsSchema();++ expect(+ schema.sections.some((section) => section.key === "verification"),+ ).toBe(true);+ });+});diff --git a/__tests__/api/option-service.test.ts b/__tests__/api/option-service.test.tsnew file mode 100644index 0000000000..d163d55078--- /dev/null+++ b/__tests__/api/option-service.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from "vitest";+import OptionService from "#/api/option-service/option-service.api";++describe("OptionService", () => {+ it("returns config in mock mode without a live backend", async () => {+ const config = await OptionService.getConfig();++ expect(config.app_mode).toBe("oss");+ expect(config.feature_flags.deployment_mode).toBe("self_hosted");+ expect(config.updated_at).toBeTruthy();+ });++ it("returns models from mocked LLM endpoints", async () => {+ const models = await OptionService.getModels();++ expect(models.models).toContain("openhands/claude-opus-4-5-20251101");+ expect(models.verified_models).toContain("claude-opus-4-5-20251101");+ expect(models.verified_providers).toEqual(["anthropic", "openhands"]);+ expect(models.default_model).toBeTruthy();+ });+});diff --git a/artifacts/frontend-tour.gif b/artifacts/frontend-tour.gifnew file mode 100644index 0000000000..2ae6f5f910Binary files /dev/null and b/artifacts/frontend-tour.gif differdiff --git a/src/mocks/conversation-handlers.ts b/src/mocks/conversation-handlers.tsindex 80da1c4551..bb4527205a 100644--- a/src/mocks/conversation-handlers.ts+++ b/src/mocks/conversation-handlers.ts@@ -1,115 +1,132 @@import { http, delay, HttpResponse } from "msw";-import {- Conversation,- GetMicroagentsResponse,- ResultSet,-} from "#/api/open-hands.types";+import type { DirectConversationInfo } from "#/api/agent-server-adapter";+import { GetMicroagentsResponse } from "#/api/open-hands.types";-const conversations: Conversation[] = [+const now = Date.now();++type MockConversation = DirectConversationInfo & {+ selected_repository?: string | null;+ selected_branch?: string | null;+ git_provider?: string | null;+};++const conversations: MockConversation[] = [{- conversation_id: "1",+ id: "1",title: "My New Project",- selected_repository: null,- git_provider: null,- selected_branch: null,- last_updated_at: new Date().toISOString(),- created_at: new Date().toISOString(),- status: "RUNNING",- runtime_status: "STATUS$READY",- url: null,- session_api_key: null,+ created_at: new Date(now).toISOString(),+ updated_at: new Date(now).toISOString(),+ execution_status: "waiting_for_confirmation",},{- conversation_id: "2",+ id: "2",title: "Repo Testing",+ created_at: new Date(now - 2 * 24 * 60 * 60 * 1000).toISOString(),+ updated_at: new Date(now - 2 * 24 * 60 * 60 * 1000).toISOString(),+ execution_status: "idle",selected_repository: "octocat/hello-world",git_provider: "github",- selected_branch: null,- last_updated_at: new Date(- Date.now() - 2 * 24 * 60 * 60 * 1000,- ).toISOString(),- created_at: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString(),- status: "STOPPED",- runtime_status: null,- url: null,- session_api_key: null,},{- conversation_id: "3",+ id: "3",title: "Another Project",+ created_at: new Date(now - 5 * 24 * 60 * 60 * 1000).toISOString(),+ updated_at: new Date(now - 5 * 24 * 60 * 60 * 1000).toISOString(),+ execution_status: "idle",selected_repository: "octocat/earth",- git_provider: null,selected_branch: "main",- last_updated_at: new Date(- Date.now() - 5 * 24 * 60 * 60 * 1000,- ).toISOString(),- created_at: new Date(Date.now() - 5 * 24 * 60 * 60 * 1000).toISOString(),- status: "STOPPED",- runtime_status: null,- url: null,- session_api_key: null,},];-const CONVERSATIONS = new Map<string, Conversation>(- conversations.map((c) => [c.conversation_id, c]),+const CONVERSATIONS = new Map<string, MockConversation>(+ conversations.map((conversation) => [conversation.id, conversation]),);+function createConversationResponse(+ conversation: MockConversation,+): DirectConversationInfo {+ return {+ id: conversation.id,+ title: conversation.title ?? null,+ created_at: conversation.created_at,+ updated_at: conversation.updated_at,+ execution_status: conversation.execution_status ?? "idle",+ metrics: conversation.metrics ?? null,+ agent: conversation.agent ?? null,+ workspace: conversation.workspace ?? null,+ };+}++function listConversationResponses(ids?: string[] | null) {+ if (!ids || ids.length === 0) {+ return Array.from(CONVERSATIONS.values()).map(createConversationResponse);+ }++ return ids.map((id) => {+ const conversation = CONVERSATIONS.get(id);+ return conversation ? createConversationResponse(conversation) : null;+ });+}+export const CONVERSATION_HANDLERS = [- http.get("/api/conversations", async () => {- const values = Array.from(CONVERSATIONS.values());- const results: ResultSet<Conversation> = {- results: values,- next_page_id: null,- };- return HttpResponse.json(results);+ http.get("/api/conversations/search", async ({ request }) => {+ const url = new URL(request.url);+ const limit = Number(url.searchParams.get("limit") ?? "20");+ const items = Array.from(CONVERSATIONS.values())+ .sort((a, b) => b.updated_at.localeCompare(a.updated_at))+ .slice(0, limit)+ .map(createConversationResponse);++ return HttpResponse.json({ items, next_page_id: null });+ }),++ http.get("/api/conversations", async ({ request }) => {+ const url = new URL(request.url);+ const ids = url.searchParams.getAll("ids");+ return HttpResponse.json(listConversationResponses(ids));}),http.get("/api/conversations/:conversationId", async ({ params }) => {const conversationId = params.conversationId as string;- const project = CONVERSATIONS.get(conversationId);- if (project) return HttpResponse.json(project);+ const conversation = CONVERSATIONS.get(conversationId);+ if (conversation) {+ return HttpResponse.json(createConversationResponse(conversation));+ }return HttpResponse.json(null, { status: 404 });}),http.post("/api/conversations", async () => {await delay();- const conversation: Conversation = {- conversation_id: (Math.random() * 100).toString(),+ const conversation: MockConversation = {+ id: `${Math.floor(Math.random() * 100000)}`,title: "New Conversation",- selected_repository: null,- git_provider: null,- selected_branch: null,- last_updated_at: new Date().toISOString(),created_at: new Date().toISOString(),- status: "RUNNING",- runtime_status: "STATUS$READY",- url: null,- session_api_key: null,+ updated_at: new Date().toISOString(),+ execution_status: "idle",};- CONVERSATIONS.set(conversation.conversation_id, conversation);- return HttpResponse.json(conversation, { status: 201 });+ CONVERSATIONS.set(conversation.id, conversation);+ return HttpResponse.json(createConversationResponse(conversation), {+ status: 201,+ });}),- http.patch(- "/api/conversations/:conversationId",- async ({ params, request }) => {- const conversationId = params.conversationId as string;- const conversation = CONVERSATIONS.get(conversationId);-- if (conversation) {- const body = await request.json();- if (typeof body === "object" && body?.title) {- CONVERSATIONS.set(conversationId, {- ...conversation,- title: body.title,- });- return HttpResponse.json(null, { status: 200 });- }+ http.patch("/api/conversations/:conversationId", async ({ params, request }) => {+ const conversationId = params.conversationId as string;+ const conversation = CONVERSATIONS.get(conversationId);++ if (conversation) {+ const body = (await request.json()) as { title?: string } | null;+ if (body?.title) {+ CONVERSATIONS.set(conversationId, {+ ...conversation,+ title: body.title,+ updated_at: new Date().toISOString(),+ });+ return HttpResponse.json(null, { status: 200 });}- return HttpResponse.json(null, { status: 404 });- },- ),+ }+ return HttpResponse.json(null, { status: 404 });+ }),http.delete("/api/conversations/:conversationId", async ({ params }) => {const conversationId = params.conversationId as string;@@ -120,6 +137,34 @@ export const CONVERSATION_HANDLERS = [return HttpResponse.json(null, { status: 404 });}),+ http.get("/api/conversations/:conversationId/events/count", async () =>+ HttpResponse.json(0),+ ),++ http.get("/api/conversations/:conversationId/events/search", async () =>+ HttpResponse.json({ items: [] }),+ ),++ http.post("/api/conversations/:conversationId/events", async () =>+ HttpResponse.json({ ok: true }),+ ),++ http.post("/api/conversations/:conversationId/pause", async () =>+ HttpResponse.json({ success: true }),+ ),++ http.post("/api/conversations/:conversationId/run", async () =>+ HttpResponse.json({ success: true }),+ ),++ http.post("/api/conversations/:conversationId/ask_agent", async () =>+ HttpResponse.json({ response: "Mock agent response" }),+ ),++ http.get("/api/vscode/url", async () => HttpResponse.json({ url: null })),++ http.post("/api/skills", async () => HttpResponse.json({ skills: [] })),+http.post("/api/v1/conversations/:conversationId/pending-messages",async () => HttpResponse.json({ id: "mock-pending-id", position: 0 }),diff --git a/src/mocks/git-repository-handlers.ts b/src/mocks/git-repository-handlers.tsindex 3002b02237..ac2591cf43 100644--- a/src/mocks/git-repository-handlers.ts+++ b/src/mocks/git-repository-handlers.ts@@ -230,4 +230,11 @@ export const GIT_REPOSITORY_HANDLERS = [return HttpResponse.json(limitedBranches);}),++ http.get("/api/git/changes", async () => HttpResponse.json([])),++ http.get(+ "/api/git/diff",+ async () => HttpResponse.json({ original: "", modified: "" }),+ ),];diff --git a/src/mocks/settings-handlers.ts b/src/mocks/settings-handlers.tsindex 10cc432fe4..06f89189b6 100644--- a/src/mocks/settings-handlers.ts+++ b/src/mocks/settings-handlers.ts@@ -275,7 +275,7 @@ export const MOCK_DEFAULT_USER_SETTINGS: Settings = {const MOCK_USER_PREFERENCES: {settings: Settings | null;} = {- settings: null,+ settings: structuredClone(MOCK_DEFAULT_USER_SETTINGS),};export const resetTestHandlersMockSettings = () => {@@ -319,9 +319,51 @@ const MOCK_VERIFIED_PROVIDERS = ["minimax",];+const MOCK_MODEL_PROVIDERS = Array.from(+ new Set(+ MOCK_MODELS.map((model) => model.split("/")[0]).filter(+ (provider): provider is string => Boolean(provider),+ ),+ ),+);++const MOCK_VERIFIED_MODELS_BY_PROVIDER = MOCK_MODELS.reduce<+ Record<string, string[]>+>((acc, model) => {+ if (!MOCK_VERIFIED_MODELS.has(model)) return acc;++ const [provider, ...rest] = model.split("/");+ if (!provider || rest.length === 0) return acc;++ acc[provider] ??= [];+ acc[provider].push(rest.join("/"));+ return acc;+}, {});+// --- Handlers for options/config/settings ---export const SETTINGS_HANDLERS = [+ http.get("/server_info", async () =>+ HttpResponse.json({+ agents: ["CodeActAgent"],+ default_agent: "CodeActAgent",+ models: MOCK_MODELS,+ security_analyzers: ["llm", "none"],+ }),+ ),++ http.get("/api/llm/models", async () =>+ HttpResponse.json({ models: MOCK_MODELS }),+ ),++ http.get("/api/llm/models/verified", async () =>+ HttpResponse.json({ models: MOCK_VERIFIED_MODELS_BY_PROVIDER }),+ ),++ http.get("/api/llm/providers", async () =>+ HttpResponse.json({ providers: MOCK_MODEL_PROVIDERS }),+ ),+// V0 (legacy) models endpoint β still used for default_modelhttp.get("/api/options/models", async () =>HttpResponse.json({@@ -430,6 +472,11 @@ export const SETTINGS_HANDLERS = [return HttpResponse.json(config);}),+ http.get("/api/settings/conversation-schema", async () => {+ await delay();+ return HttpResponse.json(MOCK_CONVERSATION_SETTINGS_SCHEMA);+ }),+http.get("/api/v1/settings/conversation-schema", async () => {await delay();return HttpResponse.json(MOCK_CONVERSATION_SETTINGS_SCHEMA);@@ -444,6 +491,11 @@ export const SETTINGS_HANDLERS = [return HttpResponse.json(settings);}),+ http.get("/api/settings/agent-schema", async () => {+ await delay();+ return HttpResponse.json(MOCK_AGENT_SETTINGS_SCHEMA);+ }),+http.get("/api/v1/settings/agent-schema", async () => {await delay();return HttpResponse.json(MOCK_AGENT_SETTINGS_SCHEMA);