-
Notifications
You must be signed in to change notification settings - Fork 6
fix: JSONL files not opening in preview (ASTD-261) #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
marcusds
wants to merge
1
commit into
main
Choose a base branch
from
astd-261-bug-investigate-why-jsonl-file-is-not-opening-in-preview/mschwab
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+200
−9
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { useIsBinaryFile } from '@studio/components/filesets/hooks/useIsBinaryFile'; | ||
| import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
| import { renderHook } from '@testing-library/react'; | ||
|
|
||
| vi.mock('@tanstack/react-query'); | ||
| vi.mock('@nemo/sdk/generated/fetchers/platform'); | ||
| vi.mock('@nemo/sdk/generated/platform/api', () => ({ | ||
| getFilesDownloadFileQueryKey: vi.fn(() => ['/files/download']), | ||
| })); | ||
| vi.mock('axios', () => { | ||
| const mockInstance = { | ||
| head: vi.fn(), | ||
| interceptors: { | ||
| request: { use: vi.fn() }, | ||
| response: { use: vi.fn() }, | ||
| }, | ||
| }; | ||
| return { default: mockInstance }; | ||
| }); | ||
|
|
||
| const mockUseQuery = vi.mocked(useQuery); | ||
|
|
||
| describe('useIsBinaryFile', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mockUseQuery.mockReturnValue({ | ||
| data: false, | ||
| isPending: false, | ||
| refetch: vi.fn(), | ||
| isFetching: false, | ||
| isStale: false, | ||
| isError: false, | ||
| error: null, | ||
| failureCount: 0, | ||
| failureReason: null, | ||
| isFetchNextPageEnabled: undefined, | ||
| dataUpdateCount: 0, | ||
| dataUpdatedAt: 0, | ||
| errorUpdateCount: 0, | ||
| errorUpdatedAt: 0, | ||
| fetchStatus: 'idle', | ||
| status: 'success', | ||
| variables: undefined, | ||
| queryKey: [], | ||
| queryHash: '', | ||
| queryFn: undefined, | ||
| queryKeyHashFn: undefined, | ||
| meta: undefined, | ||
| isLoading: false, | ||
| isLoadingError: false, | ||
| isRefetchError: false, | ||
| isSuccess: true, | ||
| isObservingMisorderedIndex: false, | ||
| } as unknown as UseQueryResult<boolean, Error>); | ||
| }); | ||
|
|
||
| it('returns isBinary=false for .jsonl files without a HEAD request', () => { | ||
| const { result } = renderHook(() => | ||
| useIsBinaryFile('default', 'test-dataset', 'data/test.jsonl') | ||
| ); | ||
|
|
||
| expect(result.current).toEqual({ isBinary: false, isLoading: false }); | ||
| // Query should be disabled for known text extensions | ||
| expect(mockUseQuery).toHaveBeenCalledWith(expect.objectContaining({ enabled: false })); | ||
| }); | ||
|
|
||
| it('returns isBinary=false for .json files without a HEAD request', () => { | ||
| const { result } = renderHook(() => useIsBinaryFile('default', 'test-dataset', 'config.json')); | ||
|
|
||
| expect(result.current).toEqual({ isBinary: false, isLoading: false }); | ||
| }); | ||
|
|
||
| it('returns isBinary=false for .csv files without a HEAD request', () => { | ||
| const { result } = renderHook(() => useIsBinaryFile('default', 'test-dataset', 'data.csv')); | ||
|
|
||
| expect(result.current).toEqual({ isBinary: false, isLoading: false }); | ||
| }); | ||
|
|
||
| it('returns isBinary=false for .py files without a HEAD request', () => { | ||
| const { result } = renderHook(() => useIsBinaryFile('default', 'test-dataset', 'script.py')); | ||
|
|
||
| expect(result.current).toEqual({ isBinary: false, isLoading: false }); | ||
| }); | ||
|
|
||
| it('returns isBinary=false for .yaml and .yml files', () => { | ||
| const { result } = renderHook(() => useIsBinaryFile('default', 'test-dataset', 'config.yaml')); | ||
|
|
||
| expect(result.current).toEqual({ isBinary: false, isLoading: false }); | ||
| }); | ||
|
|
||
| it('returns isBinary=false for .md files', () => { | ||
| const { result } = renderHook(() => useIsBinaryFile('default', 'test-dataset', 'README.md')); | ||
|
|
||
| expect(result.current).toEqual({ isBinary: false, isLoading: false }); | ||
| }); | ||
|
|
||
| it('returns isBinary=false when filePath is undefined', () => { | ||
| const { result } = renderHook(() => useIsBinaryFile('default', 'test-dataset', undefined)); | ||
|
|
||
| expect(result.current).toEqual({ isBinary: false, isLoading: false }); | ||
| }); | ||
|
|
||
| it('returns isBinary=true for .png files (binary blocklist)', () => { | ||
| const { result } = renderHook(() => useIsBinaryFile('default', 'test-dataset', 'image.png')); | ||
|
|
||
| expect(result.current).toEqual({ isBinary: true, isLoading: false }); | ||
| }); | ||
|
|
||
| it('returns isBinary=true for .zip files (binary blocklist)', () => { | ||
| const { result } = renderHook(() => useIsBinaryFile('default', 'test-dataset', 'archive.zip')); | ||
|
|
||
| expect(result.current).toEqual({ isBinary: true, isLoading: false }); | ||
| }); | ||
|
|
||
| it('enables the HEAD query for unknown extensions', () => { | ||
| renderHook(() => useIsBinaryFile('default', 'test-dataset', 'data.unknown')); | ||
|
|
||
| expect(mockUseQuery).toHaveBeenCalledWith(expect.objectContaining({ enabled: true })); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Separate type-only imports.
UseQueryResultis only used as a type. Per coding guidelines, useimport typefor type-only imports.📦 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines