diff --git a/packages/app/package.json b/packages/app/package.json index bffd7ec0d4..7dc5623be4 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -14,7 +14,7 @@ "build:clickhouse": "NEXT_PUBLIC_IS_LOCAL_MODE=true NEXT_PUBLIC_CLICKHOUSE_BUILD=true next build --webpack && node scripts/prepare-clickhouse-build-export.js", "run:clickhouse": "test -d out && npx rimraf tmp && mkdir tmp && cp -r out tmp/clickstack && echo 'visit http://localhost:3000/clickstack to start' && npx serve tmp -l 3000 || echo 'run build:clickhouse first'", "start": "next start", - "lint": "node ../../scripts/ci/oxlint-warnings.mjs --max-warnings 468 && yarn run -T oxfmt --check '**/*.{ts,tsx,css,scss}'", + "lint": "node ../../scripts/ci/oxlint-warnings.mjs --max-warnings 372 && yarn run -T oxfmt --check '**/*.{ts,tsx,css,scss}'", "lint:fix": "yarn run -T oxlint --fix && yarn run -T oxfmt '**/*.{ts,tsx,css,scss}'", "lint:styles": "stylelint **/*/*.{css,scss}", "ci:lint": "yarn lint && yarn tsc --noEmit && yarn lint:styles --quiet", diff --git a/packages/app/src/__tests__/DBDashboardImportPage.test.tsx b/packages/app/src/__tests__/DBDashboardImportPage.test.tsx index 7d4b97f661..804ad86341 100644 --- a/packages/app/src/__tests__/DBDashboardImportPage.test.tsx +++ b/packages/app/src/__tests__/DBDashboardImportPage.test.tsx @@ -342,7 +342,7 @@ describe('Dashboard import - all tile types', () => { expect(parsed.success).toBe(true); const displayTypes = new Set( - allTileTypesTemplate.tiles.map(t => (t.config as any).displayType), + allTileTypesTemplate.tiles.map(t => t.config.displayType), ); // markdown, number, line, stacked_bar, table, pie, heatmap, search expect(displayTypes.size).toBe(8); diff --git a/packages/app/src/__tests__/DBSearchPage.test.tsx b/packages/app/src/__tests__/DBSearchPage.test.tsx index 85b0e28c03..b1a06f52ce 100644 --- a/packages/app/src/__tests__/DBSearchPage.test.tsx +++ b/packages/app/src/__tests__/DBSearchPage.test.tsx @@ -1,5 +1,6 @@ import { SourceKind } from '@hyperdx/common-utils/dist/types'; import { renderHook } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { buildSavedSearchNavigationUrl, @@ -212,17 +213,21 @@ describe('useDefaultOrderBy', () => { sorting_key: testCase.sortingKey, }; - jest.spyOn(sourceModule, 'useSource').mockReturnValue({ - data: mockSource, - isLoading: false, - error: null, - } as any); - - jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue({ - data: mockTableMetadata, - isLoading: false, - error: null, - } as any); + jest.spyOn(sourceModule, 'useSource').mockReturnValue( + fromPartial({ + data: mockSource, + isLoading: false, + error: null, + }), + ); + + jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue( + fromPartial({ + data: mockTableMetadata, + isLoading: false, + error: null, + }), + ); const { result } = renderHook(() => useDefaultOrderBy('source-id')); @@ -232,17 +237,21 @@ describe('useDefaultOrderBy', () => { }); it('should handle null source ungracefully', () => { - jest.spyOn(sourceModule, 'useSource').mockReturnValue({ - data: null, - isLoading: false, - error: null, - } as any); - - jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue({ - data: null, - isLoading: false, - error: null, - } as any); + jest.spyOn(sourceModule, 'useSource').mockReturnValue( + fromPartial({ + data: undefined, + isLoading: false, + error: null, + }), + ); + + jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue( + fromPartial({ + data: undefined, + isLoading: false, + error: null, + }), + ); const { result } = renderHook(() => useDefaultOrderBy(null)); @@ -250,17 +259,21 @@ describe('useDefaultOrderBy', () => { }); it('should handle undefined sourceID ungracefully', () => { - jest.spyOn(sourceModule, 'useSource').mockReturnValue({ - data: null, - isLoading: false, - error: null, - } as any); - - jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue({ - data: null, - isLoading: false, - error: null, - } as any); + jest.spyOn(sourceModule, 'useSource').mockReturnValue( + fromPartial({ + data: undefined, + isLoading: false, + error: null, + }), + ); + + jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue( + fromPartial({ + data: undefined, + isLoading: false, + error: null, + }), + ); const { result } = renderHook(() => useDefaultOrderBy(undefined)); @@ -278,17 +291,21 @@ describe('useDefaultOrderBy', () => { sorting_key: 'toStartOfMinute(Timestamp), Timestamp', }; - jest.spyOn(sourceModule, 'useSource').mockReturnValue({ - data: mockSource, - isLoading: false, - error: null, - } as any); + jest.spyOn(sourceModule, 'useSource').mockReturnValue( + fromPartial({ + data: mockSource, + isLoading: false, + error: null, + }), + ); - jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue({ - data: mockTableMetadata, - isLoading: false, - error: null, - } as any); + jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue( + fromPartial({ + data: mockTableMetadata, + isLoading: false, + error: null, + }), + ); const { result } = renderHook(() => useDefaultOrderBy('source-id')); @@ -306,17 +323,21 @@ describe('useDefaultOrderBy', () => { sorting_key: 'toStartOfHour(Timestamp), Timestamp', }; - jest.spyOn(sourceModule, 'useSource').mockReturnValue({ - data: mockSource, - isLoading: false, - error: null, - } as any); + jest.spyOn(sourceModule, 'useSource').mockReturnValue( + fromPartial({ + data: mockSource, + isLoading: false, + error: null, + }), + ); - jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue({ - data: mockTableMetadata, - isLoading: false, - error: null, - } as any); + jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue( + fromPartial({ + data: mockTableMetadata, + isLoading: false, + error: null, + }), + ); const { result } = renderHook(() => useDefaultOrderBy('source-id')); @@ -333,17 +354,21 @@ describe('useDefaultOrderBy', () => { sorting_key: 'toStartOfHour(Timestamp), Timestamp', }; - jest.spyOn(sourceModule, 'useSource').mockReturnValue({ - data: mockSource, - isLoading: false, - error: null, - } as any); + jest.spyOn(sourceModule, 'useSource').mockReturnValue( + fromPartial({ + data: mockSource, + isLoading: false, + error: null, + }), + ); - jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue({ - data: mockTableMetadata, - isLoading: false, - error: null, - } as any); + jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue( + fromPartial({ + data: mockTableMetadata, + isLoading: false, + error: null, + }), + ); const { result } = renderHook(() => useDefaultOrderBy('source-id')); @@ -361,17 +386,21 @@ describe('useDefaultOrderBy', () => { 'toStartOfHour(toDateTime(timestamp_ms / 1000)), toDateTime(timestamp_ms / 1000)', }; - jest.spyOn(sourceModule, 'useSource').mockReturnValue({ - data: mockSource, - isLoading: false, - error: null, - } as any); + jest.spyOn(sourceModule, 'useSource').mockReturnValue( + fromPartial({ + data: mockSource, + isLoading: false, + error: null, + }), + ); - jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue({ - data: mockTableMetadata, - isLoading: false, - error: null, - } as any); + jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue( + fromPartial({ + data: mockTableMetadata, + isLoading: false, + error: null, + }), + ); const { result } = renderHook(() => useDefaultOrderBy('source-id')); @@ -391,17 +420,21 @@ describe('useDefaultOrderBy', () => { const useSourceSpy = jest .spyOn(sourceModule, 'useSource') - .mockReturnValue({ - data: mockSource1, + .mockReturnValue( + fromPartial({ + data: mockSource1, + isLoading: false, + error: null, + }), + ); + + jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue( + fromPartial({ + data: undefined, isLoading: false, error: null, - } as any); - - jest.spyOn(metadataModule, 'useTableMetadata').mockReturnValue({ - data: undefined, - isLoading: false, - error: null, - } as any); + }), + ); const { result, rerender } = renderHook(() => useDefaultOrderBy('source-id'), @@ -410,11 +443,13 @@ describe('useDefaultOrderBy', () => { expect(result.current).toBe('timestamp1 DESC'); // Update the mock to return different data - useSourceSpy.mockReturnValue({ - data: mockSource2, - isLoading: false, - error: null, - } as any); + useSourceSpy.mockReturnValue( + fromPartial({ + data: mockSource2, + isLoading: false, + error: null, + }), + ); rerender(); diff --git a/packages/app/src/__tests__/OnboardingChecklist.test.tsx b/packages/app/src/__tests__/OnboardingChecklist.test.tsx index 6e141b0e5f..d2510a4a11 100644 --- a/packages/app/src/__tests__/OnboardingChecklist.test.tsx +++ b/packages/app/src/__tests__/OnboardingChecklist.test.tsx @@ -1,8 +1,12 @@ -import { ONBOARDING_TASK_IDS } from '@hyperdx/common-utils/dist/types'; +import { + ONBOARDING_TASK_IDS, + OnboardingTaskId, +} from '@hyperdx/common-utils/dist/types'; import { MantineProvider } from '@mantine/core'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { act, render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { fromPartial } from '@total-typescript/shoehorn'; import api from '@/api'; import { useConnections } from '@/connection'; @@ -42,10 +46,12 @@ const dismissMutate = jest.fn(); // brand-new team so existing tests exercise the "eligible" path. function setTeamAgeDays(ageDays: number) { const createdAt = new Date(Date.now() - ageDays * 86_400_000).toISOString(); - mockUseTeam.mockReturnValue({ - data: { createdAt }, - isLoading: false, - } as unknown as ReturnType); + mockUseTeam.mockReturnValue( + fromPartial({ + data: { createdAt }, + isLoading: false, + }), + ); } // A real authenticated user carries a 24-hex ObjectId; the all-in-one-noauth @@ -53,23 +59,28 @@ function setTeamAgeDays(ageDays: number) { const REAL_USER_ID = '507f1f77bcf86cd799439011'; function setMe( - onboardingData: { completedTasks: string[]; isDismissed: boolean } | null, + onboardingData: { + completedTasks: OnboardingTaskId[]; + isDismissed: boolean; + } | null, id: string = REAL_USER_ID, ) { - mockUseMe.mockReturnValue({ - data: - onboardingData === null - ? null - : { - id, - email: 'a@b.com', - accessKey: 'k', - name: 'User', - createdAt: '', - onboardingData, - }, - isLoading: false, - } as unknown as ReturnType); + mockUseMe.mockReturnValue( + fromPartial({ + data: + onboardingData === null + ? null + : { + id, + email: 'a@b.com', + accessKey: 'k', + name: 'User', + createdAt: '', + onboardingData, + }, + isLoading: false, + }), + ); } // setupComplete=false -> no connections/sources/data (setup phase visible). @@ -86,18 +97,30 @@ function setSetup(complete: boolean, loading = false) { }, ] : []; - mockUseConnections.mockReturnValue({ - data: loading ? undefined : conn, - isLoading: loading, - } as unknown as ReturnType); - mockUseSources.mockReturnValue({ - data: loading ? undefined : src, - isLoading: loading, - } as unknown as ReturnType); - mockUseQueriedChartConfig.mockReturnValue({ - data: loading ? undefined : { data: [{ total_rows: complete ? 10 : 0 }] }, - isLoading: loading, - } as unknown as ReturnType); + // Literal isLoading per branch: a widened boolean fits no UseQueryResult + // union member. + if (loading) { + mockUseConnections.mockReturnValue( + fromPartial({ data: undefined, isLoading: true }), + ); + mockUseSources.mockReturnValue( + fromPartial({ data: undefined, isLoading: true }), + ); + mockUseQueriedChartConfig.mockReturnValue( + fromPartial({ data: undefined, isLoading: true }), + ); + return; + } + mockUseConnections.mockReturnValue( + fromPartial({ data: conn, isLoading: false }), + ); + mockUseSources.mockReturnValue(fromPartial({ data: src, isLoading: false })); + mockUseQueriedChartConfig.mockReturnValue( + fromPartial({ + data: { data: [{ total_rows: complete ? 10 : 0 }] }, + isLoading: false, + }), + ); } function renderChecklist() { @@ -117,10 +140,12 @@ describe('OnboardingChecklist', () => { beforeEach(() => { jest.clearAllMocks(); setTeamAgeDays(0); - mockUseDismiss.mockReturnValue({ - mutate: dismissMutate, - isPending: false, - } as unknown as ReturnType); + mockUseDismiss.mockReturnValue( + fromPartial({ + mutate: dismissMutate, + isPending: false, + }), + ); }); it('renders the setup phase before setup is complete', () => { @@ -366,16 +391,18 @@ describe('OnboardingChecklist', () => { // both the quote and backslash paths independently. setMe({ completedTasks: [], isDismissed: false }); setSetup(true); - mockUseSources.mockReturnValue({ - data: [ - { - id: 's1', - connection: 'c1', - from: { databaseName: 'db\\x', tableName: "t' OR 1=1 --" }, - }, - ], - isLoading: false, - } as unknown as ReturnType); + mockUseSources.mockReturnValue( + fromPartial({ + data: [ + { + id: 's1', + connection: 'c1', + from: { databaseName: 'db\\x', tableName: "t' OR 1=1 --" }, + }, + ], + isLoading: false, + }), + ); renderChecklist(); diff --git a/packages/app/src/__tests__/serviceDashboard.test.ts b/packages/app/src/__tests__/serviceDashboard.test.ts index ae862f6b63..5075b0dc24 100644 --- a/packages/app/src/__tests__/serviceDashboard.test.ts +++ b/packages/app/src/__tests__/serviceDashboard.test.ts @@ -4,6 +4,7 @@ import { parseQuery } from '@hyperdx/common-utils/dist/filters'; import type { TTraceSource } from '@hyperdx/common-utils/dist/types'; import { SourceKind } from '@hyperdx/common-utils/dist/types'; import { renderHook } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import * as metadataModule from '@/hooks/useMetadata'; import { @@ -304,14 +305,18 @@ describe('Service Dashboard', () => { }); it('should return loading state when source is undefined', () => { - jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue({ - data: undefined, - isLoading: false, - } as any); - jest.spyOn(metadataModule, 'useColumns').mockReturnValue({ - data: undefined, - isLoading: false, - } as any); + jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue( + fromPartial({ + data: undefined, + isLoading: false, + }), + ); + jest.spyOn(metadataModule, 'useColumns').mockReturnValue( + fromPartial({ + data: undefined, + isLoading: false, + }), + ); const { result } = renderHook(() => useServiceDashboardExpressions({ source: undefined }), @@ -322,14 +327,18 @@ describe('Service Dashboard', () => { }); it('should return loading state when columns are loading', () => { - jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue({ - data: undefined, - isLoading: true, - } as any); - jest.spyOn(metadataModule, 'useColumns').mockReturnValue({ - data: undefined, - isLoading: true, - } as any); + jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue( + fromPartial({ + data: undefined, + isLoading: true, + }), + ); + jest.spyOn(metadataModule, 'useColumns').mockReturnValue( + fromPartial({ + data: undefined, + isLoading: true, + }), + ); const { result } = renderHook(() => useServiceDashboardExpressions({ source: mockSource }), @@ -340,14 +349,18 @@ describe('Service Dashboard', () => { }); it('should return loading state when jsonColumns are loading', () => { - jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue({ - data: undefined, - isLoading: true, - } as any); - jest.spyOn(metadataModule, 'useColumns').mockReturnValue({ - data: mockColumns, - isLoading: false, - } as any); + jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue( + fromPartial({ + data: undefined, + isLoading: true, + }), + ); + jest.spyOn(metadataModule, 'useColumns').mockReturnValue( + fromPartial({ + data: mockColumns, + isLoading: false, + }), + ); const { result } = renderHook(() => useServiceDashboardExpressions({ source: mockSource }), @@ -358,14 +371,18 @@ describe('Service Dashboard', () => { }); it('should return expressions when data is loaded with non-JSON columns', () => { - jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue({ - data: mockJsonColumns, - isLoading: false, - } as any); - jest.spyOn(metadataModule, 'useColumns').mockReturnValue({ - data: mockColumns, - isLoading: false, - } as any); + jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue( + fromPartial({ + data: mockJsonColumns, + isLoading: false, + }), + ); + jest.spyOn(metadataModule, 'useColumns').mockReturnValue( + fromPartial({ + data: mockColumns, + isLoading: false, + }), + ); const { result } = renderHook(() => useServiceDashboardExpressions({ source: mockSource }), @@ -383,14 +400,18 @@ describe('Service Dashboard', () => { }); it('should return expressions when data is loaded with JSON columns', () => { - jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue({ - data: ['SpanAttributes'], - isLoading: false, - } as any); - jest.spyOn(metadataModule, 'useColumns').mockReturnValue({ - data: mockColumns, - isLoading: false, - } as any); + jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue( + fromPartial({ + data: ['SpanAttributes'], + isLoading: false, + }), + ); + jest.spyOn(metadataModule, 'useColumns').mockReturnValue( + fromPartial({ + data: mockColumns, + isLoading: false, + }), + ); const { result } = renderHook(() => useServiceDashboardExpressions({ source: mockSource }), @@ -409,14 +430,18 @@ describe('Service Dashboard', () => { { name: 'endpoint', type: 'String' }, ] as ColumnMeta[]; - jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue({ - data: mockJsonColumns, - isLoading: false, - } as any); - jest.spyOn(metadataModule, 'useColumns').mockReturnValue({ - data: columnsWithEndpoint, - isLoading: false, - } as any); + jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue( + fromPartial({ + data: mockJsonColumns, + isLoading: false, + }), + ); + jest.spyOn(metadataModule, 'useColumns').mockReturnValue( + fromPartial({ + data: columnsWithEndpoint, + isLoading: false, + }), + ); const { result } = renderHook(() => useServiceDashboardExpressions({ source: mockSource }), @@ -427,14 +452,18 @@ describe('Service Dashboard', () => { }); it('should fallback to spanName when materialized endpoint column is not available', () => { - jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue({ - data: mockJsonColumns, - isLoading: false, - } as any); - jest.spyOn(metadataModule, 'useColumns').mockReturnValue({ - data: mockColumns, - isLoading: false, - } as any); + jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue( + fromPartial({ + data: mockJsonColumns, + isLoading: false, + }), + ); + jest.spyOn(metadataModule, 'useColumns').mockReturnValue( + fromPartial({ + data: mockColumns, + isLoading: false, + }), + ); const { result } = renderHook(() => useServiceDashboardExpressions({ source: mockSource }), @@ -445,14 +474,18 @@ describe('Service Dashboard', () => { }); it('should include filter expressions', () => { - jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue({ - data: mockJsonColumns, - isLoading: false, - } as any); - jest.spyOn(metadataModule, 'useColumns').mockReturnValue({ - data: mockColumns, - isLoading: false, - } as any); + jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue( + fromPartial({ + data: mockJsonColumns, + isLoading: false, + }), + ); + jest.spyOn(metadataModule, 'useColumns').mockReturnValue( + fromPartial({ + data: mockColumns, + isLoading: false, + }), + ); const { result } = renderHook(() => useServiceDashboardExpressions({ source: mockSource }), @@ -471,14 +504,18 @@ describe('Service Dashboard', () => { }); it('should include auxiliary expressions', () => { - jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue({ - data: mockJsonColumns, - isLoading: false, - } as any); - jest.spyOn(metadataModule, 'useColumns').mockReturnValue({ - data: mockColumns, - isLoading: false, - } as any); + jest.spyOn(metadataModule, 'useJsonColumns').mockReturnValue( + fromPartial({ + data: mockJsonColumns, + isLoading: false, + }), + ); + jest.spyOn(metadataModule, 'useColumns').mockReturnValue( + fromPartial({ + data: mockColumns, + isLoading: false, + }), + ); const { result } = renderHook(() => useServiceDashboardExpressions({ source: mockSource }), diff --git a/packages/app/src/__tests__/utils.test.ts b/packages/app/src/__tests__/utils.test.ts index c92427366a..c790a90446 100644 --- a/packages/app/src/__tests__/utils.test.ts +++ b/packages/app/src/__tests__/utils.test.ts @@ -7,6 +7,7 @@ import { TSource, } from '@hyperdx/common-utils/dist/types'; import { act, renderHook } from '@testing-library/react'; +import { fromAny } from '@total-typescript/shoehorn'; import { MetricsDataType, NumberFormat } from '@/types'; import * as utils from '@/utils'; @@ -360,7 +361,7 @@ describe('getTableConnectionsForConnection', () => { describe('formatNumber', () => { it('handles undefined/null values', () => { expect(formatNumber(undefined)).toBe('N/A'); - expect(formatNumber(null as any)).toBe('N/A'); + expect(formatNumber(fromAny(null))).toBe('N/A'); }); it('returns string representation when no format options provided', () => { @@ -1111,10 +1112,10 @@ describe('stripTrailingSlash', () => { }); it('should throw an error for non-string values', () => { - expect(() => stripTrailingSlash(123 as any)).toThrow( + expect(() => stripTrailingSlash(fromAny(123))).toThrow( 'URL must be a non-empty string', ); - expect(() => stripTrailingSlash({} as any)).toThrow( + expect(() => stripTrailingSlash(fromAny({}))).toThrow( 'URL must be a non-empty string', ); }); diff --git a/packages/app/src/components/AdhocDashboardFilter/__tests__/useAdhocFilterOptions.test.tsx b/packages/app/src/components/AdhocDashboardFilter/__tests__/useAdhocFilterOptions.test.tsx index 755d36e428..6c9e2970f8 100644 --- a/packages/app/src/components/AdhocDashboardFilter/__tests__/useAdhocFilterOptions.test.tsx +++ b/packages/app/src/components/AdhocDashboardFilter/__tests__/useAdhocFilterOptions.test.tsx @@ -8,6 +8,7 @@ import { } from '@hyperdx/common-utils/dist/types'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { renderHook, waitFor } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { getSourcesWithKey, @@ -193,13 +194,15 @@ describe('useAdhocFilterOptions', () => { columnsBySource: ColumnMeta[][], { isLoading = false } = {}, ) => - jest.mocked(useMultipleAllFields).mockReturnValue({ - fieldsByTableConnection: new Map(), - columnsByTableConnection: new Map(columnsBySource.entries()), - isFieldMetadataDisabled: true, - isLoading, - isError: false, - } as unknown as ReturnType); + jest.mocked(useMultipleAllFields).mockReturnValue( + fromPartial({ + fieldsByTableConnection: new Map(), + columnsByTableConnection: new Map(columnsBySource.entries()), + isFieldMetadataDisabled: true, + isLoading, + isError: false, + }), + ); const renderOptions = ( adhocFilter: AdhocDashboardFilter, diff --git a/packages/app/src/components/ChartEditor/__tests__/utils.test.ts b/packages/app/src/components/ChartEditor/__tests__/utils.test.ts index 24f910d616..41b760f310 100644 --- a/packages/app/src/components/ChartEditor/__tests__/utils.test.ts +++ b/packages/app/src/components/ChartEditor/__tests__/utils.test.ts @@ -328,7 +328,7 @@ describe('convertFormStateToSavedChartConfig', () => { { ...seriesItem, metricName: 'cpu.usage', - metricType: 'gauge' as any, + metricType: MetricsDataType.Gauge, }, ], }; @@ -2079,7 +2079,7 @@ describe('color round-trip (sql/promql Number tile)', () => { }; const result = convertFormStateToChartConfig(form, dateRange, undefined); expect(result).toBeDefined(); - expect((result as any).color).toBe('chart-orange'); + expect(result).toMatchObject({ color: 'chart-orange' }); }); it('preserves color through convertFormStateToSavedChartConfig for promql Number tile', () => { @@ -2093,7 +2093,7 @@ describe('color round-trip (sql/promql Number tile)', () => { }; const result = convertFormStateToSavedChartConfig(form, undefined); expect(result).toBeDefined(); - expect((result as any).color).toBe('chart-warning'); + expect(result).toMatchObject({ color: 'chart-warning' }); }); it('preserves color through convertFormStateToChartConfig for promql Number tile', () => { @@ -2107,7 +2107,7 @@ describe('color round-trip (sql/promql Number tile)', () => { }; const result = convertFormStateToChartConfig(form, dateRange, undefined); expect(result).toBeDefined(); - expect((result as any).color).toBe('chart-error'); + expect(result).toMatchObject({ color: 'chart-error' }); }); it('preserves colorRules through both conversions for sql Number tile', () => { diff --git a/packages/app/src/components/__tests__/DBNumberChart.test.tsx b/packages/app/src/components/__tests__/DBNumberChart.test.tsx index 6578cfbf72..901ee8d72c 100644 --- a/packages/app/src/components/__tests__/DBNumberChart.test.tsx +++ b/packages/app/src/components/__tests__/DBNumberChart.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { DisplayType } from '@hyperdx/common-utils/dist/types'; import { act, screen } from '@testing-library/react'; -import { fromPartial } from '@total-typescript/shoehorn'; +import { fromAny, fromPartial } from '@total-typescript/shoehorn'; import DateRangeIndicator from '@/components/charts/DateRangeIndicator'; import DBNumberChart from '@/components/DBNumberChart'; @@ -14,7 +14,7 @@ import { import { useMVOptimizationExplanation } from '@/hooks/useMVOptimizationExplanation'; import { useSource } from '@/source'; import { NumberFormat } from '@/types'; -import { formatNumber, getColorFromCSSToken } from '@/utils'; +import { ChartPaletteToken, formatNumber, getColorFromCSSToken } from '@/utils'; // Mock dependencies jest.mock('@/hooks/useChartConfig', () => ({ @@ -576,7 +576,7 @@ describe('DBNumberChart', () => { ...baseTestConfig, // Simulate a legacy or hand-edited dashboard with an unknown // value sneaking past the schema (e.g. an old hex code). - color: 'definitely-not-a-token' as any, + color: fromAny('definitely-not-a-token'), }; renderWithMantine(); @@ -595,7 +595,7 @@ describe('DBNumberChart', () => { // CSS-token lookup. const config = { ...baseTestConfig, - color: 'chart-1' as any, + color: fromAny('chart-1'), }; renderWithMantine(); diff --git a/packages/app/src/components/__tests__/DBRowTable.test.tsx b/packages/app/src/components/__tests__/DBRowTable.test.tsx index 8b8290942d..b072962674 100644 --- a/packages/app/src/components/__tests__/DBRowTable.test.tsx +++ b/packages/app/src/components/__tests__/DBRowTable.test.tsx @@ -3,6 +3,7 @@ import type { ReactElement } from 'react'; import type { BuilderChartConfigWithDateRange } from '@hyperdx/common-utils/dist/types'; import { renderHook, screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { fromPartial } from '@total-typescript/shoehorn'; import { appendSelectWithAdditionalKeys, @@ -55,11 +56,13 @@ describe('RawLogTable', () => { jest.clearAllMocks(); jest .spyOn(useChartConfigModule, 'useAliasMapFromChartConfig') - .mockReturnValue({ - data: {}, - isLoading: false, - error: null, - } as any); + .mockReturnValue( + fromPartial({ + data: {}, + isLoading: false, + error: null, + }), + ); // Suppress console errors for expected errors in tests. Keeps the test output clean. jest.spyOn(console, 'error').mockImplementation(() => { @@ -195,14 +198,16 @@ describe('RawLogTable', () => { it('Should reference alias map when possible', async () => { jest .spyOn(useChartConfigModule, 'useAliasMapFromChartConfig') - .mockReturnValue({ - data: { - col1: 'col1_alias', - col2: 'col2_alias', - }, - isLoading: false, - error: null, - } as any); + .mockReturnValue( + fromPartial({ + data: { + col1: 'col1_alias', + col2: 'col2_alias', + }, + isLoading: false, + error: null, + }), + ); const callback = jest.fn(); renderWithMantine( diff --git a/packages/app/src/components/__tests__/DBSearchPageFilters.test.tsx b/packages/app/src/components/__tests__/DBSearchPageFilters.test.tsx index d018bae071..3a9f3c345b 100644 --- a/packages/app/src/components/__tests__/DBSearchPageFilters.test.tsx +++ b/packages/app/src/components/__tests__/DBSearchPageFilters.test.tsx @@ -1,6 +1,6 @@ -import { UseQueryResult } from '@tanstack/react-query'; import { screen, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { fromPartial } from '@total-typescript/shoehorn'; import { cleanedFacetName, @@ -75,11 +75,13 @@ const mockDistribution = ( data: Map | undefined, error: Error | null = null, ) => - jest.mocked(useGetValuesDistribution).mockReturnValue({ - data, - isFetching: false, - error, - } as UseQueryResult>); + jest.mocked(useGetValuesDistribution).mockReturnValue( + fromPartial({ + data, + isFetching: false, + error, + }), + ); describe('cleanedFacetName', () => { describe('basic functionality', () => { diff --git a/packages/app/src/components/__tests__/DBTableChart.test.tsx b/packages/app/src/components/__tests__/DBTableChart.test.tsx index 304659972a..5d77bbc180 100644 --- a/packages/app/src/components/__tests__/DBTableChart.test.tsx +++ b/packages/app/src/components/__tests__/DBTableChart.test.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { isBuilderChartConfig } from '@hyperdx/common-utils/dist/guards'; import { act } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import DateRangeIndicator from '@/components/charts/DateRangeIndicator'; import DBTableChart from '@/components/DBTableChart'; @@ -79,35 +80,39 @@ describe('DBTableChart', () => { beforeEach(() => { jest.clearAllMocks(); - jest.mocked(useOffsetPaginatedQuery).mockReturnValue({ - data: { - data: [{ column1: 'value1', column2: 'value2' }], - meta: [ - { name: 'column1', type: 'String' }, - { name: 'column2', type: 'String' }, - ], - chSql: { sql: '', params: {} }, - window: { - startTime: new Date(), - endTime: new Date(), - windowIndex: 0, - direction: 'DESC' as const, + jest.mocked(useOffsetPaginatedQuery).mockReturnValue( + fromPartial({ + data: { + data: [{ column1: 'value1', column2: 'value2' }], + meta: [ + { name: 'column1', type: 'String' }, + { name: 'column2', type: 'String' }, + ], + chSql: { sql: '', params: {} }, + window: { + startTime: new Date(), + endTime: new Date(), + windowIndex: 0, + direction: 'DESC' as const, + }, }, - }, - fetchNextPage: jest.fn(), - hasNextPage: false, - isLoading: false, - isFetching: false, - isError: false, - error: null, - } as any); + fetchNextPage: jest.fn(), + hasNextPage: false, + isLoading: false, + isFetching: false, + isError: false, + error: null, + }), + ); }); it('passes the same config to useMVOptimizationExplanation, useOffsetPaginatedQuery, and MVOptimizationIndicator', () => { // Mock useSource to return a source so MVOptimizationIndicator is rendered - jest.mocked(useSource).mockReturnValue({ - data: { id: 'test-source', name: 'Test Source' }, - } as any); + jest.mocked(useSource).mockReturnValue( + fromPartial({ + data: { id: 'test-source', name: 'Test Source' }, + }), + ); renderWithMantine(); @@ -144,25 +149,27 @@ describe('DBTableChart', () => { }; // Mock useMVOptimizationExplanation to return an optimized config with aligned date range - jest.mocked(useMVOptimizationExplanation).mockReturnValue({ - data: { - optimizedConfig: { - ...config, - dateRange: [alignedStartDate, alignedEndDate] as [Date, Date], - }, - explanations: [ - { - success: true, - mvConfig: { - minGranularity: '1 minute', - tableName: 'metrics_rollup_1m', - }, + jest.mocked(useMVOptimizationExplanation).mockReturnValue( + fromPartial({ + data: { + optimizedConfig: { + ...config, + dateRange: [alignedStartDate, alignedEndDate] as [Date, Date], }, - ], - }, - isLoading: false, - isPlaceholderData: false, - } as any); + explanations: [ + { + success: true, + mvConfig: { + minGranularity: '1 minute', + tableName: 'metrics_rollup_1m', + }, + }, + ], + }, + isLoading: false, + isPlaceholderData: false, + }), + ); renderWithMantine(); @@ -268,32 +275,34 @@ describe('DBTableChart', () => { // Emulates how the ClickHouse query returns rows for a builder table chart: // series columns are produced before groupBy columns. beforeEach(() => { - jest.mocked(useOffsetPaginatedQuery).mockReturnValue({ - data: { - data: [ - { - Count: 10, - AvgDuration: 42, - ServiceName: 'web', - SpanName: 'GET /', + jest.mocked(useOffsetPaginatedQuery).mockReturnValue( + fromPartial({ + data: { + data: [ + { + Count: 10, + AvgDuration: 42, + ServiceName: 'web', + SpanName: 'GET /', + }, + ], + meta: [], + chSql: { sql: '', params: {} }, + window: { + startTime: new Date(), + endTime: new Date(), + windowIndex: 0, + direction: 'DESC' as const, }, - ], - meta: [], - chSql: { sql: '', params: {} }, - window: { - startTime: new Date(), - endTime: new Date(), - windowIndex: 0, - direction: 'DESC' as const, }, - }, - fetchNextPage: jest.fn(), - hasNextPage: false, - isLoading: false, - isFetching: false, - isError: false, - error: null, - } as any); + fetchNextPage: jest.fn(), + hasNextPage: false, + isLoading: false, + isFetching: false, + isError: false, + error: null, + }), + ); }); const configWithGroupBy = { @@ -342,31 +351,33 @@ describe('DBTableChart', () => { // single computed column for the ratio — not one column per select. The // row shape reflects this: 1 series column followed by the groupBy // columns. - jest.mocked(useOffsetPaginatedQuery).mockReturnValue({ - data: { - data: [ - { - 'divide(count(), count())': 0.5, - ServiceName: 'web', - SpanName: 'GET /', + jest.mocked(useOffsetPaginatedQuery).mockReturnValue( + fromPartial({ + data: { + data: [ + { + 'divide(count(), count())': 0.5, + ServiceName: 'web', + SpanName: 'GET /', + }, + ], + meta: [], + chSql: { sql: '', params: {} }, + window: { + startTime: new Date(), + endTime: new Date(), + windowIndex: 0, + direction: 'DESC' as const, }, - ], - meta: [], - chSql: { sql: '', params: {} }, - window: { - startTime: new Date(), - endTime: new Date(), - windowIndex: 0, - direction: 'DESC' as const, }, - }, - fetchNextPage: jest.fn(), - hasNextPage: false, - isLoading: false, - isFetching: false, - isError: false, - error: null, - } as any); + fetchNextPage: jest.fn(), + hasNextPage: false, + isLoading: false, + isFetching: false, + isError: false, + error: null, + }), + ); const ratioConfig = { ...baseTestConfig, @@ -402,32 +413,34 @@ describe('DBTableChart', () => { groupByColumnsOnLeft: true, }; - jest.mocked(useOffsetPaginatedQuery).mockReturnValue({ - data: { - data: [ - { - Count: 10, - AvgDuration: 42, - ServiceName: 'web', - SpanName: 'GET /', + jest.mocked(useOffsetPaginatedQuery).mockReturnValue( + fromPartial({ + data: { + data: [ + { + Count: 10, + AvgDuration: 42, + ServiceName: 'web', + SpanName: 'GET /', + }, + ], + meta: [], + chSql: { sql: '', params: {} }, + window: { + startTime: new Date(), + endTime: new Date(), + windowIndex: 0, + direction: 'DESC' as const, }, - ], - meta: [], - chSql: { sql: '', params: {} }, - window: { - startTime: new Date(), - endTime: new Date(), - windowIndex: 0, - direction: 'DESC' as const, }, - }, - fetchNextPage: jest.fn(), - hasNextPage: false, - isLoading: false, - isFetching: false, - isError: false, - error: null, - } as any); + fetchNextPage: jest.fn(), + hasNextPage: false, + isLoading: false, + isFetching: false, + isError: false, + error: null, + }), + ); renderWithMantine(); @@ -688,14 +701,16 @@ describe('DBTableChart', () => { it('does not render DateRangeIndicator when MV optimization has no optimized date range', () => { // Mock useMVOptimizationExplanation to return data without an optimized config - jest.mocked(useMVOptimizationExplanation).mockReturnValue({ - data: { - optimizedConfig: undefined, - explanations: [], - }, - isLoading: false, - isPlaceholderData: false, - } as any); + jest.mocked(useMVOptimizationExplanation).mockReturnValue( + fromPartial({ + data: { + optimizedConfig: undefined, + explanations: [], + }, + isLoading: false, + isPlaceholderData: false, + }), + ); renderWithMantine(); diff --git a/packages/app/src/components/__tests__/DBTraceWaterfallChart.test.tsx b/packages/app/src/components/__tests__/DBTraceWaterfallChart.test.tsx index 4400f10249..8d3ce6658e 100644 --- a/packages/app/src/components/__tests__/DBTraceWaterfallChart.test.tsx +++ b/packages/app/src/components/__tests__/DBTraceWaterfallChart.test.tsx @@ -1539,8 +1539,8 @@ describe('useEventsAroundFocus', () => { // Verify results were combined correctly expect(result.rows.length).toBe(2); - expect((result.rows[0] as any).Body).toBe('before focus'); - expect((result.rows[1] as any).Body).toBe('after focus'); + expect(result.rows[0]).toMatchObject({ Body: 'before focus' }); + expect(result.rows[1]).toMatchObject({ Body: 'after focus' }); }); it('handles empty data correctly', () => { diff --git a/packages/app/src/hooks/__tests__/useAlertAnnotations.test.tsx b/packages/app/src/hooks/__tests__/useAlertAnnotations.test.tsx index b25228f9f0..b2cc0cbfbe 100644 --- a/packages/app/src/hooks/__tests__/useAlertAnnotations.test.tsx +++ b/packages/app/src/hooks/__tests__/useAlertAnnotations.test.tsx @@ -1,5 +1,10 @@ -import { AlertState, AlertTransition } from '@hyperdx/common-utils/dist/types'; +import { + AlertHistoryRangeApiResponse, + AlertState, + AlertTransition, +} from '@hyperdx/common-utils/dist/types'; import { renderHook } from '@testing-library/react'; +import { fromPartial, PartialDeep } from '@total-typescript/shoehorn'; import api from '@/api'; import { @@ -108,8 +113,8 @@ describe('useAlertAnnotations', () => { new Date('2026-07-01T01:00:00.000Z'), ]; - const mockHistory = (data: unknown) => - jest.spyOn(api, 'useAlertHistory').mockReturnValue({ data } as any); + const mockHistory = (data: PartialDeep) => + jest.spyOn(api, 'useAlertHistory').mockReturnValue(fromPartial({ data })); afterEach(() => jest.restoreAllMocks()); diff --git a/packages/app/src/hooks/__tests__/useAvailableMetricNames.test.ts b/packages/app/src/hooks/__tests__/useAvailableMetricNames.test.ts index 1137357214..6c4f0053f0 100644 --- a/packages/app/src/hooks/__tests__/useAvailableMetricNames.test.ts +++ b/packages/app/src/hooks/__tests__/useAvailableMetricNames.test.ts @@ -3,6 +3,7 @@ import { TMetricSource, } from '@hyperdx/common-utils/dist/types'; import { renderHook } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { useAvailableMetricNames } from '@/hooks/useAvailableMetricNames'; import { useGetKeyValues } from '@/hooks/useMetadata'; @@ -29,15 +30,6 @@ const DATE_RANGE: [Date, Date] = [ const METRIC_NAMES = ['hw.gpu.utilization', 'hw.gpu.memory.utilization']; -function mockQuery(overrides: Record) { - mockUseGetKeyValues.mockReturnValue({ - data: undefined, - isLoading: false, - isPlaceholderData: false, - ...overrides, - } as unknown as ReturnType); -} - function render() { return renderHook(() => useAvailableMetricNames({ @@ -53,7 +45,13 @@ describe('useAvailableMetricNames', () => { afterEach(() => jest.resetAllMocks()); it('reports the metric names the query returned', () => { - mockQuery({ data: [{ key: 'MetricName', value: METRIC_NAMES }] }); + mockUseGetKeyValues.mockReturnValue( + fromPartial({ + data: [{ key: 'MetricName', value: METRIC_NAMES }], + isLoading: false, + isPlaceholderData: false, + }), + ); const { result } = render(); expect([...result.current.availableMetrics].sort()).toEqual( [...METRIC_NAMES].sort(), @@ -62,7 +60,13 @@ describe('useAvailableMetricNames', () => { }); it('reports loading while the first query is in flight', () => { - mockQuery({ isLoading: true }); + mockUseGetKeyValues.mockReturnValue( + fromPartial({ + data: undefined, + isLoading: true, + isPlaceholderData: false, + }), + ); expect(render().result.current.isLoading).toBe(true); }); @@ -71,17 +75,25 @@ describe('useAvailableMetricNames', () => { // `isLoading` false. Reporting that as settled would leak one host's chart // set onto the next. it('reports loading while showing another resource placeholder data', () => { - mockQuery({ - data: [{ key: 'MetricName', value: METRIC_NAMES }], - isLoading: false, - isPlaceholderData: true, - }); + mockUseGetKeyValues.mockReturnValue( + fromPartial({ + data: [{ key: 'MetricName', value: METRIC_NAMES }], + isLoading: false, + isPlaceholderData: true, + }), + ); const { result } = render(); expect(result.current.isLoading).toBe(true); }); it('returns an empty set when the query has no data', () => { - mockQuery({ data: undefined }); + mockUseGetKeyValues.mockReturnValue( + fromPartial({ + data: undefined, + isLoading: false, + isPlaceholderData: false, + }), + ); expect(render().result.current.availableMetrics.size).toBe(0); }); }); diff --git a/packages/app/src/hooks/__tests__/useChartConfig.test.tsx b/packages/app/src/hooks/__tests__/useChartConfig.test.tsx index b5c6535ec9..b429b9eeff 100644 --- a/packages/app/src/hooks/__tests__/useChartConfig.test.tsx +++ b/packages/app/src/hooks/__tests__/useChartConfig.test.tsx @@ -2191,20 +2191,26 @@ describe('useChartConfig', () => { let resolvePromise2: (value: any) => void; let resolvePromise1: (value: any) => void; - const promise1 = new Promise(resolve => { + const promise1 = new Promise< + ResponseJSON> + >(resolve => { resolvePromise1 = resolve; }); - const promise2 = new Promise(resolve => { + const promise2 = new Promise< + ResponseJSON> + >(resolve => { resolvePromise2 = resolve; }); - const promise3 = new Promise(resolve => { + const promise3 = new Promise< + ResponseJSON> + >(resolve => { resolvePromise3 = resolve; }); mockClickhouseClient.queryChartConfig - .mockReturnValueOnce(promise1 as any) - .mockReturnValueOnce(promise2 as any) - .mockReturnValueOnce(promise3 as any); + .mockReturnValueOnce(promise1) + .mockReturnValueOnce(promise2) + .mockReturnValueOnce(promise3); const { result } = renderHook( () => @@ -2325,12 +2331,17 @@ describe('useChartConfig', () => { }, ], }); + if (!isBuilderChartConfig(optimizedConfig)) { + throw new Error('Expected a BuilderChartConfig'); + } // Mock useMVOptimizationExplanation to be in loading state - jest.mocked(useMVOptimizationExplanation).mockReturnValue({ - data: undefined, - isLoading: true, // MV optimization is still loading - } as any); + jest.mocked(useMVOptimizationExplanation).mockReturnValue( + fromPartial({ + data: undefined, + isLoading: true, // MV optimization is still loading + }), + ); renderHook( () => useQueriedChartConfig(config, { enableQueryChunking: true }), @@ -2346,21 +2357,23 @@ describe('useChartConfig', () => { expect(mockClickhouseClient.queryChartConfig).not.toHaveBeenCalled(); // Now mock the MV optimization to finish loading with an optimized config - jest.mocked(useMVOptimizationExplanation).mockReturnValue({ - data: { - optimizedConfig: optimizedConfig, - explanations: [ - { - success: true, - mvConfig: { - minGranularity: '1 hour', - tableName: 'metrics_rollup_1h', + jest.mocked(useMVOptimizationExplanation).mockReturnValue( + fromPartial({ + data: { + optimizedConfig: optimizedConfig, + explanations: [ + { + success: true, + mvConfig: { + minGranularity: '1 hour', + tableName: 'metrics_rollup_1h', + }, }, - }, - ], - }, - isLoading: false, // MV optimization finished loading - } as any); + ], + }, + isLoading: false, // MV optimization finished loading + }), + ); const mockResponse = createMockQueryResponse([ { diff --git a/packages/app/src/hooks/__tests__/useCsvExport.test.tsx b/packages/app/src/hooks/__tests__/useCsvExport.test.tsx index 4fb37808b1..a4f8ee80a0 100644 --- a/packages/app/src/hooks/__tests__/useCsvExport.test.tsx +++ b/packages/app/src/hooks/__tests__/useCsvExport.test.tsx @@ -1,4 +1,5 @@ import { renderHook } from '@testing-library/react'; +import { fromAny } from '@total-typescript/shoehorn'; import { CsvColumn, useCsvExport } from '@/hooks/useCsvExport'; @@ -241,7 +242,7 @@ describe('useCsvExport', () => { it('handles non-array data', () => { const { result } = renderHook(() => - useCsvExport('not an array' as any, mockColumns), + useCsvExport(fromAny('not an array'), mockColumns), ); expect(result.current.csvData).toEqual([]); @@ -256,10 +257,10 @@ describe('useCsvExport', () => { }); it('handles invalid column structure', () => { - const invalidColumns = [ + const invalidColumns: CsvColumn[] = [ { dataKey: 'name', displayName: 'Name' }, { dataKey: '', displayName: 'Invalid' }, // Empty dataKey - { dataKey: 'age' } as any, // Missing displayName + fromAny({ dataKey: 'age' }), // Missing displayName ]; const { result } = renderHook(() => diff --git a/packages/app/src/hooks/__tests__/useFieldExpressionGenerator.test.tsx b/packages/app/src/hooks/__tests__/useFieldExpressionGenerator.test.tsx index 99ba371804..a7e0350770 100644 --- a/packages/app/src/hooks/__tests__/useFieldExpressionGenerator.test.tsx +++ b/packages/app/src/hooks/__tests__/useFieldExpressionGenerator.test.tsx @@ -1,5 +1,6 @@ import { TSource } from '@hyperdx/common-utils/dist/types'; import { renderHook } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import useFieldExpressionGenerator from '@/hooks/useFieldExpressionGenerator'; import { useJsonColumns } from '@/hooks/useMetadata'; @@ -23,10 +24,12 @@ describe('useFieldExpressionGenerator', () => { }); it('should return undefined getFieldExpression when source is undefined', () => { - jest.mocked(useJsonColumns).mockReturnValue({ - data: undefined, - isLoading: false, - } as any); + jest.mocked(useJsonColumns).mockReturnValue( + fromPartial({ + data: undefined, + isLoading: false, + }), + ); const { result } = renderHook(() => useFieldExpressionGenerator(undefined)); @@ -35,10 +38,12 @@ describe('useFieldExpressionGenerator', () => { }); it('should return isLoading true when data is loading', () => { - jest.mocked(useJsonColumns).mockReturnValue({ - data: undefined, - isLoading: true, - } as any); + jest.mocked(useJsonColumns).mockReturnValue( + fromPartial({ + data: undefined, + isLoading: true, + }), + ); const { result } = renderHook(() => useFieldExpressionGenerator(mockSource), @@ -49,10 +54,12 @@ describe('useFieldExpressionGenerator', () => { }); it('should generate JSON column expression with default convertFn (toString)', () => { - jest.mocked(useJsonColumns).mockReturnValue({ - data: ['Body', 'Metadata'], - isLoading: false, - } as any); + jest.mocked(useJsonColumns).mockReturnValue( + fromPartial({ + data: ['Body', 'Metadata'], + isLoading: false, + }), + ); const { result } = renderHook(() => useFieldExpressionGenerator(mockSource), @@ -69,10 +76,12 @@ describe('useFieldExpressionGenerator', () => { }); it('should generate JSON column expression with custom convertFn', () => { - jest.mocked(useJsonColumns).mockReturnValue({ - data: ['Body', 'Metadata'], - isLoading: false, - } as any); + jest.mocked(useJsonColumns).mockReturnValue( + fromPartial({ + data: ['Body', 'Metadata'], + isLoading: false, + }), + ); const { result } = renderHook(() => useFieldExpressionGenerator(mockSource), @@ -89,10 +98,12 @@ describe('useFieldExpressionGenerator', () => { }); it('should generate Map column expression with bracket notation', () => { - jest.mocked(useJsonColumns).mockReturnValue({ - data: ['Body', 'Metadata'], - isLoading: false, - } as any); + jest.mocked(useJsonColumns).mockReturnValue( + fromPartial({ + data: ['Body', 'Metadata'], + isLoading: false, + }), + ); const { result } = renderHook(() => useFieldExpressionGenerator(mockSource), @@ -108,10 +119,12 @@ describe('useFieldExpressionGenerator', () => { }); it('should handle mixed JSON and Map columns correctly', () => { - jest.mocked(useJsonColumns).mockReturnValue({ - data: ['Body'], - isLoading: false, - } as any); + jest.mocked(useJsonColumns).mockReturnValue( + fromPartial({ + data: ['Body'], + isLoading: false, + }), + ); const { result } = renderHook(() => useFieldExpressionGenerator(mockSource), @@ -130,10 +143,12 @@ describe('useFieldExpressionGenerator', () => { }); it('should handle empty jsonColumns array', () => { - jest.mocked(useJsonColumns).mockReturnValue({ - data: [], - isLoading: false, - } as any); + jest.mocked(useJsonColumns).mockReturnValue( + fromPartial({ + data: [], + isLoading: false, + }), + ); const { result } = renderHook(() => useFieldExpressionGenerator(mockSource), @@ -150,10 +165,12 @@ describe('useFieldExpressionGenerator', () => { }); it('should pass correct tableConnection to useJsonColumns', () => { - jest.mocked(useJsonColumns).mockReturnValue({ - data: [], - isLoading: false, - } as any); + jest.mocked(useJsonColumns).mockReturnValue( + fromPartial({ + data: [], + isLoading: false, + }), + ); renderHook(() => useFieldExpressionGenerator(mockSource)); @@ -165,10 +182,12 @@ describe('useFieldExpressionGenerator', () => { }); it('should handle special characters in keys correctly', () => { - jest.mocked(useJsonColumns).mockReturnValue({ - data: ['Body'], - isLoading: false, - } as any); + jest.mocked(useJsonColumns).mockReturnValue( + fromPartial({ + data: ['Body'], + isLoading: false, + }), + ); const { result } = renderHook(() => useFieldExpressionGenerator(mockSource), diff --git a/packages/app/src/hooks/__tests__/useMetadata.test.tsx b/packages/app/src/hooks/__tests__/useMetadata.test.tsx index cefcb44b5f..4443c78c27 100644 --- a/packages/app/src/hooks/__tests__/useMetadata.test.tsx +++ b/packages/app/src/hooks/__tests__/useMetadata.test.tsx @@ -9,9 +9,15 @@ import { MetadataCache, } from '@hyperdx/common-utils/dist/core/metadata'; import { FilterState } from '@hyperdx/common-utils/dist/filters'; -import { BuilderChartConfigWithDateRange } from '@hyperdx/common-utils/dist/types'; +import { + BuilderChartConfigWithDateRange, + MapKeyIndexPartSelection, + SourceKind, + TSource, +} from '@hyperdx/common-utils/dist/types'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { renderHook, waitFor } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import api from '@/api'; import { @@ -455,28 +461,30 @@ describe('useGetKeyValues', () => { }); // Sources here only carry the fields the hook reads. - const mockSources = (data: Record[]) => - jest.mocked(useSources).mockReturnValue({ - data, - isLoading: false, - } as unknown as ReturnType); + const mockSources = (data: Parameters>[0][]) => + jest + .mocked(useSources) + .mockReturnValue(fromPartial({ data, isLoading: false })); it("passes log and trace sources' part settings to 'all' mode lookups, and no others", async () => { const defaultSources = jest.mocked(useSources)(); + // Not a log or trace source, so its fields don't apply. Declared outside + // the array literal so the part settings, which metric sources don't + // define, aren't rejected as excess properties. + const metricsSource = { + id: 'metrics', + kind: SourceKind.Metric as const, + mapKeyIndexMaxParts: 9, + mapKeyIndexPartSelection: MapKeyIndexPartSelection.Smallest, + }; mockSources([ { id: 'logs', - kind: 'log', + kind: SourceKind.Log, mapKeyIndexMaxParts: 7, - mapKeyIndexPartSelection: 'largest', - }, - // Not a log or trace source, so its fields don't apply. - { - id: 'metrics', - kind: 'metric', - mapKeyIndexMaxParts: 9, - mapKeyIndexPartSelection: 'smallest', + mapKeyIndexPartSelection: MapKeyIndexPartSelection.Largest, }, + metricsSource, ]); const streamAllKeyValues = mockLookups.all([], []); @@ -511,7 +519,7 @@ describe('useGetKeyValues', () => { it("refetches 'all' mode values when the source's part settings change", async () => { const defaultSources = jest.mocked(useSources)(); const withParts = (mapKeyIndexMaxParts: number) => - mockSources([{ id: 'logs', kind: 'log', mapKeyIndexMaxParts }]); + mockSources([{ id: 'logs', kind: SourceKind.Log, mapKeyIndexMaxParts }]); const streamAllKeyValues = mockLookups.all([], []); try { @@ -738,11 +746,13 @@ describe('useGetKeyValues', () => { }); it('should be in a loading state while fetching sources', async () => { - jest.mocked(useSources).mockReturnValue({ - data: undefined, - isLoading: true, - isFetching: true, - } as any); + jest.mocked(useSources).mockReturnValue( + fromPartial({ + data: undefined, + isLoading: true, + isFetching: true, + }), + ); // Arrange const mockChartConfig = createMockChartConfig(); diff --git a/packages/app/src/hooks/__tests__/useOffsetPaginatedQuery.test.tsx b/packages/app/src/hooks/__tests__/useOffsetPaginatedQuery.test.tsx index f516cd93fc..a9edd3b699 100644 --- a/packages/app/src/hooks/__tests__/useOffsetPaginatedQuery.test.tsx +++ b/packages/app/src/hooks/__tests__/useOffsetPaginatedQuery.test.tsx @@ -10,6 +10,7 @@ import { UseQueryResult, } from '@tanstack/react-query'; import { renderHook, waitFor } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import useOffsetPaginatedQuery from '@/hooks/useOffsetPaginatedQuery'; @@ -156,7 +157,9 @@ describe('useOffsetPaginatedQuery', () => { mockMetadata = { getSetting: jest.fn().mockResolvedValue(null), }; - jest.mocked(useMetadataWithSettings).mockReturnValue(mockMetadata as any); + jest + .mocked(useMetadataWithSettings) + .mockReturnValue(fromPartial(mockMetadata)); }); describe('Time Window Generation', () => { diff --git a/packages/app/src/hooks/__tests__/useOnClickLinkBuilder.test.tsx b/packages/app/src/hooks/__tests__/useOnClickLinkBuilder.test.tsx index fa78feda9e..6ab1c48c06 100644 --- a/packages/app/src/hooks/__tests__/useOnClickLinkBuilder.test.tsx +++ b/packages/app/src/hooks/__tests__/useOnClickLinkBuilder.test.tsx @@ -1,10 +1,12 @@ -import type { - OnClickDashboard, - OnClickExternal, - OnClickSearch, +import { + type OnClickDashboard, + type OnClickExternal, + type OnClickSearch, + SourceKind, } from '@hyperdx/common-utils/dist/types'; import { notifications } from '@mantine/notifications'; import { renderHook } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import { useDashboards } from '@/dashboard'; import { useOnClickLinkBuilder } from '@/hooks/useOnClickLinkBuilder'; @@ -37,21 +39,25 @@ const dateRange: [Date, Date] = [ describe('useOnClickLinkBuilder', () => { beforeEach(() => { jest.clearAllMocks(); - jest.mocked(useSources).mockReturnValue({ - data: [ - { - id: 'src_1', - name: 'HyperDX Logs', - kind: 'log', - connection: 'c', - from: { databaseName: 'd', tableName: 't' }, - timestampValueExpression: 'Timestamp', - }, - ], - } as any); - jest.mocked(useDashboards).mockReturnValue({ - data: [{ id: 'dash_1', name: 'API Latency Drilldown', tiles: [] }], - } as any); + jest.mocked(useSources).mockReturnValue( + fromPartial({ + data: [ + { + id: 'src_1', + name: 'HyperDX Logs', + kind: SourceKind.Log, + connection: 'c', + from: { databaseName: 'd', tableName: 't' }, + timestampValueExpression: 'Timestamp', + }, + ], + }), + ); + jest.mocked(useDashboards).mockReturnValue( + fromPartial({ + data: [{ id: 'dash_1', name: 'API Latency Drilldown', tiles: [] }], + }), + ); }); it('returns null when no onClick is configured', () => { diff --git a/packages/app/src/hooks/__tests__/usePresetDashboardFilters.test.tsx b/packages/app/src/hooks/__tests__/usePresetDashboardFilters.test.tsx index c8f871e87c..8424018ef2 100644 --- a/packages/app/src/hooks/__tests__/usePresetDashboardFilters.test.tsx +++ b/packages/app/src/hooks/__tests__/usePresetDashboardFilters.test.tsx @@ -6,6 +6,7 @@ import { PresetDashboardFilter, } from '@hyperdx/common-utils/dist/types'; import { act, renderHook } from '@testing-library/react'; +import { fromPartial } from '@total-typescript/shoehorn'; import api from '@/api'; import useDashboardFilters from '@/hooks/useDashboardFilters'; @@ -87,25 +88,33 @@ describe('usePresetDashboardFilters', () => { mockSetFilterValue = jest.fn(); // Mock usePresetDashboardFilters query - jest.mocked(api.usePresetDashboardFilters).mockReturnValue({ - data: mockFilters, - refetch: mockRefetch, - } as any); + jest.mocked(api.usePresetDashboardFilters).mockReturnValue( + fromPartial({ + data: mockFilters, + refetch: mockRefetch, + }), + ); // Mock create mutation - jest.mocked(api.useCreatePresetDashboardFilter).mockReturnValue({ - mutate: mockCreateMutate, - } as any); + jest.mocked(api.useCreatePresetDashboardFilter).mockReturnValue( + fromPartial({ + mutate: mockCreateMutate, + }), + ); // Mock update mutation - jest.mocked(api.useUpdatePresetDashboardFilter).mockReturnValue({ - mutate: mockUpdateMutate, - } as any); + jest.mocked(api.useUpdatePresetDashboardFilter).mockReturnValue( + fromPartial({ + mutate: mockUpdateMutate, + }), + ); // Mock delete mutation - jest.mocked(api.useDeletePresetDashboardFilter).mockReturnValue({ - mutate: mockDeleteMutate, - } as any); + jest.mocked(api.useDeletePresetDashboardFilter).mockReturnValue( + fromPartial({ + mutate: mockDeleteMutate, + }), + ); // Mock useDashboardFilters jest.mocked(useDashboardFilters).mockReturnValue({ @@ -146,10 +155,12 @@ describe('usePresetDashboardFilters', () => { }); it('should return empty array when no data is available', () => { - jest.mocked(api.usePresetDashboardFilters).mockReturnValue({ - data: undefined, - refetch: mockRefetch, - } as any); + jest.mocked(api.usePresetDashboardFilters).mockReturnValue( + fromPartial({ + data: undefined, + refetch: mockRefetch, + }), + ); const { result } = renderHook(() => usePresetDashboardFilters({ @@ -220,10 +231,12 @@ describe('usePresetDashboardFilters', () => { }); it('should pass empty array to useDashboardFilters when no data', () => { - jest.mocked(api.usePresetDashboardFilters).mockReturnValue({ - data: undefined, - refetch: mockRefetch, - } as any); + jest.mocked(api.usePresetDashboardFilters).mockReturnValue( + fromPartial({ + data: undefined, + refetch: mockRefetch, + }), + ); renderHook(() => usePresetDashboardFilters({ diff --git a/packages/app/src/hooks/__tests__/useRowWhere.test.tsx b/packages/app/src/hooks/__tests__/useRowWhere.test.tsx index 8def46be7e..9bbd77661e 100644 --- a/packages/app/src/hooks/__tests__/useRowWhere.test.tsx +++ b/packages/app/src/hooks/__tests__/useRowWhere.test.tsx @@ -8,6 +8,7 @@ import { leftUtf8Prefix, } from '@hyperdx/common-utils/dist/core/utils'; import { renderHook } from '@testing-library/react'; +import { fromAny } from '@total-typescript/shoehorn'; import useRowWhere, { processRowToWhereClause } from '@/hooks/useRowWhere'; @@ -496,7 +497,7 @@ describe('processRowToWhereClause', () => { { name: 'test', type: 'String', - valueExpr: null as any, + valueExpr: fromAny(null), jsType: JSDataType.String, }, ], diff --git a/packages/app/src/hooks/__tests__/useServiceMap.test.ts b/packages/app/src/hooks/__tests__/useServiceMap.test.ts index 0308cef719..36b5c89c75 100644 --- a/packages/app/src/hooks/__tests__/useServiceMap.test.ts +++ b/packages/app/src/hooks/__tests__/useServiceMap.test.ts @@ -1,5 +1,6 @@ import { renderChartConfig } from '@hyperdx/common-utils/dist/core/renderChartConfig'; import { SourceKind, TTraceSource } from '@hyperdx/common-utils/dist/types'; +import { fromPartial } from '@total-typescript/shoehorn'; import { aggregateServiceMapData, @@ -445,7 +446,7 @@ describe('getServiceMapQuery', () => { const query = await getServiceMapQuery({ source, dateRange, - metadata: {} as any, + metadata: fromPartial({}), samplingFactor: 1, groupBy, }); diff --git a/scripts/ci/ratchet-baseline.json b/scripts/ci/ratchet-baseline.json index 0f8ebd9218..b9e61835d8 100644 --- a/scripts/ci/ratchet-baseline.json +++ b/scripts/ci/ratchet-baseline.json @@ -6,7 +6,7 @@ "@source": 0 }, "app": { - "as-any": 184, + "as-any": 99, "ts-ignore": 0, "eslint-disable": 119, "@source": 0