Skip to content

Commit 337b5da

Browse files
authored
Condensing fixes (#4107)
* Add missing telemetry types * Give IconButton the pointer cursor when enabled * Change context condensing to use a Lucide icon * Mock Lucide icons globally
1 parent c03b9f9 commit 337b5da

File tree

10 files changed

+31
-71
lines changed

10 files changed

+31
-71
lines changed

packages/types/src/telemetry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ export const rooCodeTelemetryEventSchema = z.discriminatedUnion("type", [
109109
TelemetryEventName.DIFF_APPLICATION_ERROR,
110110
TelemetryEventName.SHELL_INTEGRATION_ERROR,
111111
TelemetryEventName.CONSECUTIVE_MISTAKE_ERROR,
112+
TelemetryEventName.CONTEXT_CONDENSED,
113+
TelemetryEventName.SLIDING_WINDOW_TRUNCATION,
112114
]),
113115
properties: telemetryPropertiesSchema,
114116
}),

webview-ui/jest.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
77
transform: { "^.+\\.(ts|tsx)$": ["ts-jest", { tsconfig: { jsx: "react-jsx", module: "ESNext" } }] },
88
testMatch: ["<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}", "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"],
9-
setupFilesAfterEnv: ["<rootDir>/src/setupTests.ts"],
9+
setupFilesAfterEnv: ["<rootDir>/src/setupTests.tsx"],
1010
moduleNameMapper: {
1111
"\\.(css|less|scss|sass)$": "identity-obj-proxy",
1212
"^vscrui$": "<rootDir>/src/__mocks__/vscrui.ts",

webview-ui/src/components/chat/IconButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const IconButton: React.FC<IconButtonProps> = ({
2727
"hover:opacity-100 hover:bg-[rgba(255,255,255,0.03)] hover:border-[rgba(255,255,255,0.15)]",
2828
"focus:outline-none focus-visible:ring-1 focus-visible:ring-vscode-focusBorder",
2929
"active:bg-[rgba(255,255,255,0.1)]",
30+
!disabled && "cursor-pointer",
3031
disabled &&
3132
"opacity-40 cursor-not-allowed grayscale-[30%] hover:bg-transparent hover:border-[rgba(255,255,255,0.08)] active:bg-transparent",
3233
className,

webview-ui/src/components/chat/TaskHeader.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { memo, useRef, useState } from "react"
22
import { useWindowSize } from "react-use"
33
import { useTranslation } from "react-i18next"
44
import { VSCodeBadge } from "@vscode/webview-ui-toolkit/react"
5-
import { CloudUpload, CloudDownload } from "lucide-react"
5+
import { CloudUpload, CloudDownload, FoldVertical } from "lucide-react"
66

77
import type { ClineMessage } from "@roo-code/types"
88

@@ -19,7 +19,6 @@ import Thumbnails from "../common/Thumbnails"
1919
import { TaskActions } from "./TaskActions"
2020
import { ContextWindowProgress } from "./ContextWindowProgress"
2121
import { Mention } from "./Mention"
22-
import { IconButton } from "./IconButton"
2322

2423
export interface TaskHeaderProps {
2524
task: ClineMessage
@@ -108,13 +107,13 @@ const TaskHeader = ({
108107
: undefined
109108
}
110109
/>
111-
<IconButton
112-
iconClass="codicon-fold"
110+
<button
113111
title={t("chat:task.condenseContext")}
114112
disabled={buttonsDisabled}
115113
onClick={() => currentTaskItem && handleCondenseContext(currentTaskItem.id)}
116-
className="shrink-0 min-h-[20px] min-w-[20px] p-[2px]"
117-
/>
114+
className="shrink-0 min-h-[20px] min-w-[20px] p-[2px] cursor-pointer disabled:cursor-not-allowed opacity-85 hover:opacity-100 bg-transparent border-none rounded-md">
115+
<FoldVertical size={16} />
116+
</button>
118117
{!!totalCost && <VSCodeBadge>${totalCost.toFixed(2)}</VSCodeBadge>}
119118
</div>
120119
)}

webview-ui/src/components/common/__tests__/CodeBlock.test.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ jest.mock("shiki", () => ({
2828
},
2929
}))
3030

31-
// Mock all lucide-react icons with a proxy to handle any icon requested
32-
jest.mock("lucide-react", () => {
33-
return new Proxy(
34-
{},
35-
{
36-
get: function (_obj, prop) {
37-
// Return a component factory for any icon that's requested
38-
if (prop === "__esModule") {
39-
return true
40-
}
41-
return () => <div data-testid={`${String(prop)}-icon`}>{String(prop)}</div>
42-
},
43-
},
44-
)
45-
})
46-
4731
// Mock the highlighter utility
4832
jest.mock("../../../utils/highlighter", () => {
4933
const mockHighlighter = {

webview-ui/src/components/modes/__tests__/ModesView.test.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@ jest.mock("@src/utils/vscode", () => ({
1212
},
1313
}))
1414

15-
// Mock all lucide-react icons with a proxy to handle any icon requested
16-
jest.mock("lucide-react", () => {
17-
return new Proxy(
18-
{},
19-
{
20-
get: function (_obj, prop) {
21-
// Return a component factory for any icon that's requested
22-
if (prop === "__esModule") {
23-
return true
24-
}
25-
return () => <div data-testid={`${String(prop)}-icon`}>{String(prop)}</div>
26-
},
27-
},
28-
)
29-
})
30-
3115
const mockExtensionState = {
3216
customModePrompts: {},
3317
listApiConfigMeta: [

webview-ui/src/components/settings/ContextManagementSettings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HTMLAttributes } from "react"
22
import { useAppTranslation } from "@/i18n/TranslationContext"
33
import { VSCodeCheckbox, VSCodeTextArea } from "@vscode/webview-ui-toolkit/react"
4-
import { Database } from "lucide-react"
4+
import { Database, FoldVertical } from "lucide-react"
55

66
import { cn } from "@/lib/utils"
77
import { Button, Input, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Slider } from "@/components/ui"
@@ -197,7 +197,7 @@ export const ContextManagementSettings = ({
197197
{autoCondenseContext && (
198198
<div className="flex flex-col gap-3 pl-3 border-l-2 border-vscode-button-background">
199199
<div className="flex items-center gap-4 font-bold">
200-
<span className="codicon codicon-fold" />
200+
<FoldVertical size={16} />
201201
<div>{t("settings:contextManagement.autoCondenseContextPercent.label")}</div>
202202
</div>
203203
<div>

webview-ui/src/components/settings/__tests__/ContextManagementSettings.test.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ class MockResizeObserver {
1313

1414
global.ResizeObserver = MockResizeObserver
1515

16-
// Mock lucide-react icons - these don't work well in Jest/JSDOM environment
17-
jest.mock("lucide-react", () => {
18-
return {
19-
Database: React.forwardRef((props: any, ref: any) => <div ref={ref} data-testid="database-icon" {...props} />),
20-
ChevronDown: React.forwardRef((props: any, ref: any) => (
21-
<div ref={ref} data-testid="chevron-down-icon" {...props} />
22-
)),
23-
ChevronUp: React.forwardRef((props: any, ref: any) => (
24-
<div ref={ref} data-testid="chevron-up-icon" {...props} />
25-
)),
26-
Check: React.forwardRef((props: any, ref: any) => <div ref={ref} data-testid="check-icon" {...props} />),
27-
}
28-
})
29-
3016
// Mock translation hook to return the key as the translation
3117
jest.mock("@/i18n/TranslationContext", () => ({
3218
useAppTranslation: () => ({

webview-ui/src/components/settings/__tests__/SettingsView.test.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@ import SettingsView from "../SettingsView"
1010
// Mock vscode API
1111
jest.mock("@src/utils/vscode", () => ({ vscode: { postMessage: jest.fn() } }))
1212

13-
// Mock all lucide-react icons with a proxy to handle any icon requested
14-
jest.mock("lucide-react", () => {
15-
return new Proxy(
16-
{},
17-
{
18-
get: function (_obj, prop) {
19-
// Return a component factory for any icon that's requested
20-
if (prop === "__esModule") {
21-
return true
22-
}
23-
return () => <div data-testid={`${String(prop)}-icon`}>{String(prop)}</div>
24-
},
25-
},
26-
)
27-
})
28-
2913
// Mock ApiConfigManager component
3014
jest.mock("../ApiConfigManager", () => ({
3115
__esModule: true,

webview-ui/src/setupTests.ts renamed to webview-ui/src/setupTests.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,23 @@ Object.defineProperty(window, "matchMedia", {
3030
dispatchEvent: jest.fn(),
3131
})),
3232
})
33+
34+
// Mock lucide-react icons globally using Proxy for dynamic icon handling
35+
jest.mock("lucide-react", () => {
36+
return new Proxy(
37+
{},
38+
{
39+
get: function (_obj, prop) {
40+
// Return a component factory for any icon that's requested
41+
if (prop === "__esModule") {
42+
return true
43+
}
44+
return (props: any) => (
45+
<div {...props} data-testid={`${String(prop)}-icon`}>
46+
{String(prop)}
47+
</div>
48+
)
49+
},
50+
},
51+
)
52+
})

0 commit comments

Comments
 (0)