🙌 OpenHands: AI-Driven Development
chore: address post-merge feedback on #284 + small cleanups (#288)
Robert Brennan0068b5f46521
diff --git a/__tests__/conversation-local-storage.test.ts b/__tests__/conversation-local-storage.test.tsindex 9b285d3da8..0566b29a52 100644--- a/__tests__/conversation-local-storage.test.ts+++ b/__tests__/conversation-local-storage.test.ts@@ -544,12 +544,12 @@ describe("conversation localStorage utilities", () => {setConversationState("files-diff-convA", { filesTabDiffView: true });setConversationState("files-diff-convB", { filesTabDiffView: false });- expect(- getConversationState("files-diff-convA").filesTabDiffView,- ).toBe(true);- expect(- getConversationState("files-diff-convB").filesTabDiffView,- ).toBe(false);+ expect(getConversationState("files-diff-convA").filesTabDiffView).toBe(+ true,+ );+ expect(getConversationState("files-diff-convB").filesTabDiffView).toBe(+ false,+ );});});@@ -571,9 +571,9 @@ describe("conversation localStorage utilities", () => {filesTabContentViewMode: "plain",});- expect(- getConversationState(conversationId).filesTabContentViewMode,- ).toBe("plain");+ expect(getConversationState(conversationId).filesTabContentViewMode).toBe(+ "plain",+ );const raw = localStorage.getItem(`${LOCAL_STORAGE_KEYS.CONVERSATION_STATE}-${conversationId}`,@@ -587,9 +587,9 @@ describe("conversation localStorage utilities", () => {filesTabContentViewMode: "rich",});- expect(- getConversationState(conversationId).filesTabContentViewMode,- ).toBe("rich");+ expect(getConversationState(conversationId).filesTabContentViewMode).toBe(+ "rich",+ );});it("is isolated per conversation", () => {@@ -607,5 +607,21 @@ describe("conversation localStorage utilities", () => {getConversationState("files-view-convB").filesTabContentViewMode,).toBe("rich");});++ it("falls back to the 'rich' default when localStorage holds a junk value", () => {+ // A corrupted entry (older build with a renamed mode, a hand-edited+ // value in devtools, …) must not leak through to the ViewMode-typed+ // consumer — the sanitizer drops the bad value so the merged result+ // re-applies the typed default.+ const conversationId = "files-view-corrupt";+ const key = `${LOCAL_STORAGE_KEYS.CONVERSATION_STATE}-${conversationId}`;+ localStorage.setItem(+ key,+ JSON.stringify({ filesTabContentViewMode: "fancy" }),+ );++ const state = getConversationState(conversationId);+ expect(state.filesTabContentViewMode).toBe("rich");+ });});});diff --git a/__tests__/routes/files-tab.test.tsx b/__tests__/routes/files-tab.test.tsxindex a7e3bfe540..1ea8fcbf35 100644--- a/__tests__/routes/files-tab.test.tsx+++ b/__tests__/routes/files-tab.test.tsx@@ -410,6 +410,10 @@ describe("FilesTab", () => {const refresh = screen.getByTestId("files-tab-refresh");expect(refresh).toBeInTheDocument();+ // The button should describe its *action* (refresh), not the surrounding+ // section name ("Files") — the old `COMMON$FILES` aria-label was+ // ambiguous for screen-reader users who couldn't see the refresh icon.+ expect(refresh).toHaveAttribute("aria-label", "FILES$REFRESH");await user.click(refresh);expect(refetchGitChangesMock).toHaveBeenCalledTimes(1);});diff --git a/__tests__/utils/file-priority.test.ts b/__tests__/utils/file-priority.test.tsindex 551f2442db..450f7788a4 100644--- a/__tests__/utils/file-priority.test.ts+++ b/__tests__/utils/file-priority.test.ts@@ -1,9 +1,6 @@import { describe, it, expect } from "vitest";-import {- sortFilesByPriority,- filePriorityScore,-} from "#/utils/file-priority";+import { sortFilesByPriority, filePriorityScore } from "#/utils/file-priority";describe("file-priority", () => {it("places index.html before other files", () => {@@ -25,10 +22,7 @@ describe("file-priority", () => {});it("prefers top-level index.html over a nested one", () => {- const sorted = sortFilesByPriority([- "src/nested/index.html",- "index.html",- ]);+ const sorted = sortFilesByPriority(["src/nested/index.html", "index.html"]);expect(sorted[0]).toBe("index.html");expect(sorted[1]).toBe("src/nested/index.html");});@@ -69,4 +63,31 @@ describe("file-priority", () => {sortFilesByPriority(input);expect(input).toEqual(original);});++ // Regression for the depth-calculation bug where empty path segments+ // produced by leading / trailing / double slashes (e.g. agent-server+ // payloads that happen to start with `/`) inflated the computed depth+ // and caused a top-level file to sort below an actually-nested one.+ describe("depth calculation tolerates non-canonical path forms", () => {+ it("treats a leading-slash path the same as the unprefixed form", () => {+ const sorted = sortFilesByPriority([+ "src/nested/index.html",+ "/index.html",+ ]);+ expect(sorted[0]).toBe("/index.html");+ expect(sorted[1]).toBe("src/nested/index.html");+ });++ it("collapses double slashes when computing depth", () => {+ // `src//index.html` should sort identically to `src/index.html` (both+ // depth 1 — one nesting level under root), beating a genuinely+ // deeper path even though `index.html` is high-priority either way.+ const sorted = sortFilesByPriority([+ "deeply/nested/index.html",+ "src//index.html",+ ]);+ expect(sorted[0]).toBe("src//index.html");+ expect(sorted[1]).toBe("deeply/nested/index.html");+ });+ });});diff --git a/src/components/shared/buttons/refresh-button.tsx b/src/components/shared/buttons/refresh-button.tsxdeleted file mode 100644index 4fe67a0489..0000000000--- a/src/components/shared/buttons/refresh-button.tsx+++ /dev/null@@ -1,13 +0,0 @@-import Refresh from "#/icons/refresh.svg?react";--interface RefreshButtonProps {- onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;-}--export function RefreshButton({ onClick }: RefreshButtonProps) {- return (- <button type="button" onClick={onClick}>- <Refresh width={14} height={14} />- </button>- );-}diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex b16fe821c8..fdd73b8089 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -18755,6 +18755,23 @@"uk": "Відкрити в новому вікні","ca": "Obre en una finestra nova"},+ "FILES$REFRESH": {+ "en": "Refresh files",+ "ja": "ファイルを更新",+ "zh-CN": "刷新文件",+ "zh-TW": "重新整理檔案",+ "ko-KR": "파일 새로 고침",+ "no": "Oppdater filer",+ "it": "Aggiorna file",+ "pt": "Atualizar arquivos",+ "es": "Actualizar archivos",+ "ar": "تحديث الملفات",+ "fr": "Actualiser les fichiers",+ "tr": "Dosyaları yenile",+ "de": "Dateien aktualisieren",+ "uk": "Оновити файли",+ "ca": "Actualitza els fitxers"+ },"FILES$NO_FILE_SELECTED": {"en": "Select a file to view its contents","ja": "内容を表示するファイルを選択してください",diff --git a/src/icons/refresh.svg b/src/icons/refresh.svgdeleted file mode 100644index 4bba1daa1a..0000000000--- a/src/icons/refresh.svg+++ /dev/null@@ -1,5 +0,0 @@-<svg width="8" height="8" viewBox="0 0 8 8" fill="none" xmlns="http://www.w3.org/2000/svg">- <path- d="M4.26446 0.763647C4.39463 0.633472 4.60569 0.633472 4.73586 0.763647L5.73586 1.76365C5.86604 1.89382 5.86604 2.10488 5.73586 2.23505L4.73586 3.23505C4.60569 3.36523 4.39463 3.36523 4.26446 3.23505C4.13429 3.10488 4.13429 2.89382 4.26446 2.76365L4.69542 2.33268H4.16683C2.98426 2.33268 2.00016 3.31678 2.00016 4.49935C2.00016 5.68192 2.98426 6.66602 4.16683 6.66602C5.3494 6.66602 6.3335 5.68192 6.3335 4.49935C6.3335 4.31525 6.48273 4.16602 6.66683 4.16602C6.85092 4.16602 7.00016 4.31525 7.00016 4.49935C7.00016 6.05011 5.71759 7.33268 4.16683 7.33268C2.61607 7.33268 1.3335 6.05011 1.3335 4.49935C1.3335 2.94859 2.61607 1.66602 4.16683 1.66602H4.69542L4.26446 1.23505C4.13429 1.10488 4.13429 0.893821 4.26446 0.763647Z"- fill="white" />-</svg>diff --git a/src/routes/files-tab.tsx b/src/routes/files-tab.tsxindex 3fb7af5242..15dfdfdf5b 100644--- a/src/routes/files-tab.tsx+++ b/src/routes/files-tab.tsx@@ -152,7 +152,8 @@ function FilesTab() {type="button"onClick={refreshFiles}disabled={isFetchingGitChanges}- aria-label={t(I18nKey.COMMON$FILES)}+ aria-label={t(I18nKey.FILES$REFRESH)}+ title={t(I18nKey.FILES$REFRESH)}data-testid="files-tab-refresh"className="flex items-center justify-center w-[26px] py-1 rounded-[7px] hover:enabled:bg-[#474A54] cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed">diff --git a/src/utils/conversation-local-storage.ts b/src/utils/conversation-local-storage.tsindex 2ef8dcce94..746bf361d3 100644--- a/src/utils/conversation-local-storage.ts+++ b/src/utils/conversation-local-storage.ts@@ -72,6 +72,8 @@ const REMOVED_CONVERSATION_TABS: ReadonlySet<string> = new Set(["app",]);+const VALID_VIEW_MODES: ReadonlySet<ViewMode> = new Set(["rich", "plain"]);+function sanitizeStoredState(stored: Partial<ConversationState>,): Partial<ConversationState> {@@ -95,6 +97,19 @@ function sanitizeStoredState(}}+ // Drop a corrupt/manually-edited `filesTabContentViewMode` so it falls+ // back to the typed default ("rich") instead of leaking a junk string+ // into ViewMode-typed consumers. TypeScript can't help us here — the+ // value comes from `JSON.parse(localStorage.getItem(...))` which is+ // unknown at runtime.+ if (+ result.filesTabContentViewMode != null &&+ !VALID_VIEW_MODES.has(result.filesTabContentViewMode)+ ) {+ result = { ...result };+ delete result.filesTabContentViewMode;+ }+return result;}diff --git a/src/utils/file-priority.ts b/src/utils/file-priority.tsindex 6f2fb8c75f..49d2ad55ec 100644--- a/src/utils/file-priority.ts+++ b/src/utils/file-priority.ts@@ -56,7 +56,11 @@ function getBasename(path: string): string {}function pathDepth(path: string): number {- return path.split("/").length - 1;+ // Filter empty segments so leading/trailing/double slashes don't inflate+ // depth (e.g. `/src/index.html`, `src//index.html`, `src/` should all+ // count the same as `src/index.html`). Matches the convention already+ // used by `buildFileTree` in `file-tree.ts`.+ return path.split("/").filter(Boolean).length - 1;}/**