Skip to content

fix: JSONL files not opening in preview (ASTD-261)#427

Open
marcusds wants to merge 6 commits into
mainfrom
astd-261-bug-investigate-why-jsonl-file-is-not-opening-in-preview/mschwab
Open

fix: JSONL files not opening in preview (ASTD-261)#427
marcusds wants to merge 6 commits into
mainfrom
astd-261-bug-investigate-why-jsonl-file-is-not-opening-in-preview/mschwab

Conversation

@marcusds

@marcusds marcusds commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Problem

JSONL files were showing 'Text preview not available for binary files' in the fileset preview panel.

Root Cause

The backend HEAD endpoint returns application/octet-stream for all files. useIsBinaryFile relied solely on the Content-Type header to determine if a file is text, so .jsonl (and other text files like .json, .csv, .py, etc.) were incorrectly classified as binary.

Fix

Added a KNOWN_TEXT_EXTENSIONS allowlist (50+ extensions) that short-circuits the HEAD request for recognized text file extensions. The detection strategy is now four-tiered:

  1. Extension in KNOWN_TEXT_EXTENSIONS → text immediately (no network)
  2. Extension in BINARY_FILE_EXTENSIONS → binary immediately (no network)
  3. Unknown extension → HEAD request; Content-Type decides
  4. HEAD fails → assume text (fail-open)

Changes

  • useIsBinaryFile.ts: Added KNOWN_TEXT_EXTENSIONS set and isKnownTextExtension helper. Restructured hook to check text extensions before binary blocklist.
  • useIsBinaryFile.test.ts: New test file with 10 tests covering JSONL, JSON, CSV, PY, YAML, MD, undefined path, PNG, ZIP, and unknown extensions.

Summary by CodeRabbit

  • Improvements
    • Speed up file type detection by classifying common text formats from file extensions (e.g., .json, .csv, .py, .yaml, .md) without server requests.
    • Update binary detection to resolve immediately; isLoading is no longer used, and unknown extensions default to non-binary.
    • Centralize the text-extension list via a new KNOWN_TEXT_EXTENSIONS constant.
  • Tests
    • Added coverage for text, binary, unknown, and undefined file-path scenarios for the binary detection hook.

The backend HEAD endpoint returns application/octet-stream for all files,
causing useIsBinaryFile to incorrectly classify .jsonl and other text files
as binary. Added KNOWN_TEXT_EXTENSIONS allowlist that short-circuits the
HEAD request for recognized text extensions.

- Add 50+ known text extensions (json, jsonl, csv, py, yaml, md, etc.)
- Restructure hook to check text extensions before binary blocklist
- Add unit tests for useIsBinaryFile hook

Signed-off-by: mschwab <mschwab@nvidia.com>
@marcusds marcusds requested review from a team as code owners June 23, 2026 23:26
@github-actions github-actions Bot added the fix label Jun 23, 2026
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 81adcc7d-b70b-4d37-90a2-9fbb0d4dc829

📥 Commits

Reviewing files that changed from the base of the PR and between 5f76ed1 and 596c80e.

📒 Files selected for processing (1)
  • web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts

📝 Walkthrough

Walkthrough

useIsBinaryFile now classifies files synchronously from extensions. A shared text-extension set was added, the preview panel call site was updated, and tests cover text, binary, undefined, and unknown-path outcomes.

Changes

Synchronous binary-file detection

Layer / File(s) Summary
Extension-based hook and constants
web/packages/studio/src/constants/constants.ts, web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.ts, web/packages/studio/src/components/FilesetFilePreviewPanel/FilesetFilePreviewContent/index.tsx
Adds KNOWN_TEXT_EXTENSIONS, rewrites useIsBinaryFile to use filePath only with synchronous extension checks, and updates the preview panel call site to pass the new argument shape.
Hook behavior tests
web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts
Adds coverage for known text extensions, undefined paths, binary extensions, and unknown extensions against the synchronous return values.

Possibly related PRs

Suggested reviewers

  • htolentino-nvidia
  • dmariali
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: fixing JSONL preview handling for binary-file detection.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch astd-261-bug-investigate-why-jsonl-file-is-not-opening-in-preview/mschwab

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts`:
- Line 5: The import statement on line 5 mixes value and type imports from
`@tanstack/react-query`. Separate UseQueryResult into a type-only import using
import type syntax, keeping useQuery in the regular import statement. This
follows coding guidelines by explicitly marking type-only imports and allows the
compiler to properly tree-shake unused types.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b07f9cd4-47a7-49c2-946c-0a532a0b5fee

📥 Commits

Reviewing files that changed from the base of the PR and between d8ea9e2 and 4dc4cdc.

📒 Files selected for processing (2)
  • web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts
  • web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.ts

Comment thread web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts Outdated
@marcusds marcusds marked this pull request as draft June 23, 2026 23:35
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 21322/27924 76.4% 61.4%
Integration Tests 12350/26693 46.3% 19.7%

marcusds added 4 commits June 26, 2026 09:42
…end always returns application/octet-stream

Signed-off-by: mschwab <mschwab@nvidia.com>
Signed-off-by: mschwab <mschwab@nvidia.com>
…ilePath

Signed-off-by: mschwab <mschwab@nvidia.com>
Signed-off-by: mschwab <mschwab@nvidia.com>
@marcusds marcusds marked this pull request as ready for review June 26, 2026 17:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts`:
- Around line 32-35: The test named for .yaml and .yml only exercises
useIsBinaryFile with config.yaml, so the .yml allowlist path is unverified;
update the useIsBinaryFile test case to also invoke the hook with a .yml
filename and assert the same { isBinary: false, isLoading: false } result,
keeping the existing yaml check so both extensions are covered.

In `@web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.ts`:
- Around line 18-30: The useIsBinaryFile hook is now failing open for every
unknown extension, which lets non-text files reach preview paths. Keep the
existing fast checks in useIsBinaryFile, but change the fallback for
unrecognized filePath values to perform a real binary detection instead of
returning false; use the existing isKnownTextExtension and isBinaryExtension
helpers as the named entry points to update, and ensure unknown extensions do
not default to text.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8e5dad57-33da-4ebe-8302-d885dd6eebfa

📥 Commits

Reviewing files that changed from the base of the PR and between 4dc4cdc and 5f76ed1.

📒 Files selected for processing (4)
  • web/packages/studio/src/components/FilesetFilePreviewPanel/FilesetFilePreviewContent/index.tsx
  • web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts
  • web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.ts
  • web/packages/studio/src/constants/constants.ts

Comment thread web/packages/studio/src/components/filesets/hooks/useIsBinaryFile.test.ts Outdated
…yFile

Signed-off-by: mschwab <mschwab@nvidia.com>
@marcusds marcusds enabled auto-merge June 26, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant