Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions packages/api/src/models/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.5.2",
"@total-typescript/shoehorn": "^0.1.2",
"@types/crypto-js": "^4",
"@types/flat": "^5.0.5",
"@types/identity-obj-proxy": "^3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { TSource } from '@hyperdx/common-utils/dist/types';
import { MantineProvider } from '@mantine/core';
import { fireEvent, render, screen } from '@testing-library/react';

import { fromPartial } from '@total-typescript/shoehorn';
// Controlled, in-memory replacement for nuqs' useQueryState so each side-panel
// URL param can be seeded and its setter inspected independently. Values are
// the already-parsed shapes the component consumes (arrays / strings), not URL
Expand Down Expand Up @@ -30,7 +30,7 @@ jest.mock('nuqs', () => {
);
const fallback =
parser && 'defaultValue' in parser ? parser.defaultValue : null;
const value = hasValue ? mockQueryStore[key] : (fallback ?? null);
const value = hasValue ? mockQueryStore[key] : fallback ?? null;
if (!mockSetters[key]) mockSetters[key] = jest.fn();
return [value, mockSetters[key]];
},
Expand Down Expand Up @@ -158,13 +158,13 @@ import useSidePanelStack from '@/hooks/useSidePanelStack';
import { getRowLookupWindow } from '@/utils/rowTimestamps';

// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const ROOT_SOURCE = {
const ROOT_SOURCE = fromPartial<TSource>({
id: 'log-src',
kind: 'log',
traceSourceId: 'trace-src',
timestampValueExpression: 'Timestamp',
resourceAttributesExpression: 'ResourceAttributes',
} as TSource;
}) as TSource;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant fixture type assertions

fromPartial<TSource> already returns TSource, so the trailing as TSource is unnecessary and conflicts with the repository guidance to prefer inference over casts. The same redundant pattern appears on the newly converted fixtures in DBTimeChart.test.tsx and MetricTableModelForm.test.tsx, obscuring that fromPartial itself supplies and validates the target type.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex


const TRACE_ID = '7316d5a2ab0dc2efa72258f64a98a405';
const SPAN_ID = 'e3748131832d6176';
Expand Down
84 changes: 48 additions & 36 deletions packages/app/src/components/__tests__/DBTimeChart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { MantineProvider } from '@mantine/core';
import { Notifications } from '@mantine/notifications';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { fromPartial } from '@total-typescript/shoehorn';
import { DisplayType } from '@hyperdx/common-utils/dist/types';

import api from '@/api';
import { ChartKeyJoiner } from '@/ChartUtils';
Expand Down Expand Up @@ -155,9 +157,11 @@ describe('DBTimeChart', () => {

it('passes the same config to useMVOptimizationExplanation, useQueriedChartConfig, 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' },
}) as ReturnType<typeof useSource>,
);

renderWithMantine(<DBTimeChart config={baseTestConfig} />);

Expand All @@ -183,9 +187,11 @@ describe('DBTimeChart', () => {
});

it('disables the MV-optimization query when both MV and date-range indicators are hidden', () => {
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' },
}) as ReturnType<typeof useSource>,
);

renderWithMantine(
<DBTimeChart
Expand All @@ -201,9 +207,11 @@ describe('DBTimeChart', () => {
});

it('keeps the MV-optimization query enabled when only the date-range indicator is shown', () => {
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' },
}) as ReturnType<typeof useSource>,
);

renderWithMantine(
<DBTimeChart
Expand Down Expand Up @@ -424,25 +432,27 @@ describe('DBTimeChart', () => {
};

// 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,
}) as ReturnType<typeof useMVOptimizationExplanation>,
);

renderWithMantine(<DBTimeChart config={config} />);

Expand Down Expand Up @@ -477,14 +487,16 @@ describe('DBTimeChart', () => {
};

// Mock useMVOptimizationExplanation to return no 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,
}) as ReturnType<typeof useMVOptimizationExplanation>,
);

renderWithMantine(<DBTimeChart config={config} />);

Expand All @@ -511,7 +523,7 @@ describe('DBTimeChart', () => {
sqlTemplate:
'SELECT toStartOfInterval(ts, INTERVAL {intervalSeconds:Int64} SECOND) AS ts, count() AS count FROM logs GROUP BY ts ORDER BY ts ASC',
connection: 'test-connection',
displayType: 'line' as any,
displayType: DisplayType.Line,
dateRange: [new Date('2024-01-01'), new Date('2024-01-02')] as [
Date,
Date,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect } from 'react';
import { useForm } from 'react-hook-form';
import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types';
import { fromPartial } from '@total-typescript/shoehorn';
import { MantineProvider } from '@mantine/core';
import { render, waitFor } from '@testing-library/react';

Expand Down Expand Up @@ -122,8 +123,7 @@ function autofilledTables() {
.map(([path, value]) => [path, value]);
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const SAVED_SOURCE: TSource = {
const SAVED_SOURCE = fromPartial<TSource>({
id: 'metric-source-1',
kind: SourceKind.Metric,
name: 'Metrics',
Expand All @@ -134,7 +134,7 @@ const SAVED_SOURCE: TSource = {
gauge: 'otel_metrics_gauge',
sum: 'otel_metrics_sum',
},
} as any;
}) as TSource;

describe('MetricTableModelForm metric table autofill', () => {
beforeEach(() => {
Expand Down Expand Up @@ -238,11 +238,11 @@ describe('MetricTableModelForm metric table autofill', () => {
// tables to preserve, so it autofills like a new source.
it('autofills for an existing source switched to the metrics kind', async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
savedSource = {
savedSource = fromPartial<TSource>({
...SAVED_SOURCE,
kind: SourceKind.Log,
metricTables: undefined,
} as any;
}) as TSource;

renderHarness(
<Harness databaseName="otel_v2" sourceId="metric-source-1" />,
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4734,6 +4734,7 @@ __metadata:
"@testing-library/jest-dom": "npm:^6.4.2"
"@testing-library/react": "npm:^16.3.0"
"@testing-library/user-event": "npm:^14.5.2"
"@total-typescript/shoehorn": "npm:^0.1.2"
"@types/crypto-js": "npm:^4"
"@types/flat": "npm:^5.0.5"
"@types/identity-obj-proxy": "npm:^3"
Expand Down Expand Up @@ -9976,6 +9977,13 @@ __metadata:
languageName: node
linkType: hard

"@total-typescript/shoehorn@npm:^0.1.2":
version: 0.1.2
resolution: "@total-typescript/shoehorn@npm:0.1.2"
checksum: 10c0/e1bb904a3c46bd00a3a31a4f24a07a5de8f6c4aebb811f4ac108dfad066d2797c682b49bbcd09e98e2bd12e8b67db9bcb793e02e2ed8a996e1fe0d232a7efcf1
languageName: node
linkType: hard

"@tsconfig/node10@npm:^1.0.7":
version: 1.0.9
resolution: "@tsconfig/node10@npm:1.0.9"
Expand Down
Loading