-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Add ESLint rules for type safety and fix violations #46
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
Merged
saltenasl
merged 16 commits into
main
from
devin/1761239803-add-eslint-type-safety-rules
Oct 27, 2025
Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
18782e5
Add ESLint rules for type safety and fix violations
devin-ai-integration[bot] 87b67d5
Add test for error handling in NotebookPicker constructor
devin-ai-integration[bot] 9e2eda0
Add comprehensive test coverage for NotebookPicker
devin-ai-integration[bot] 0e32ba8
Merge test coverage from PR #45
devin-ai-integration[bot] 684667c
fix: remove mocks, test real implementation
dinohamzic b7738b4
chore: format
dinohamzic 10562ab
chore: remove out of scope tests
dinohamzic 6659212
chore: remove out of scope test
dinohamzic 8887ef7
refactor: fix test and format
dinohamzic ccc6169
chore: remove out of scope test
dinohamzic c2223c9
fix: address violations
dinohamzic 03da012
refactor: improve test
dinohamzic e4e92ba
refactor: TypeError
dinohamzic e09f7e6
fix: drop unnecessary property
dinohamzic 9849c7b
refactor: simplify promise
dinohamzic edbd6c1
chore: improve "dirty" test
dinohamzic 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
249 changes: 249 additions & 0 deletions
249
src/__tests__/convert-deepnote-block-to-jupyter-cell.spec.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,249 @@ | ||
| // Copyright (c) Deepnote | ||
| // Distributed under the terms of the Modified BSD License. | ||
|
|
||
| import type { DeepnoteBlock } from '@deepnote/blocks'; | ||
| import { convertDeepnoteBlockToJupyterCell } from '../convert-deepnote-block-to-jupyter-cell'; | ||
|
|
||
| describe('convertDeepnoteBlockToJupyterCell', () => { | ||
| describe('code cells', () => { | ||
| it('should convert a basic code block to a Jupyter code cell', () => { | ||
| const block: DeepnoteBlock = { | ||
| id: 'block-1', | ||
| type: 'code', | ||
| content: 'print("hello")', | ||
| metadata: { foo: 'bar' }, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('code'); | ||
| expect(result.metadata).toEqual({ foo: 'bar', cell_id: 'block-1' }); | ||
| expect(result.source).toBe('print("hello")'); | ||
| expect(result.execution_count).toBeNull(); | ||
| expect(result.outputs).toEqual([]); | ||
| }); | ||
|
|
||
| it('should include execution count if present', () => { | ||
| const block: DeepnoteBlock = { | ||
| id: 'block-2', | ||
| type: 'code', | ||
| content: 'x = 1', | ||
| metadata: {}, | ||
| executionCount: 5, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('code'); | ||
| expect(result.execution_count).toBe(5); | ||
| }); | ||
|
|
||
| it('should include outputs if present', () => { | ||
| const blockOutputs = [ | ||
| { | ||
| output_type: 'stream', | ||
| name: 'stdout', | ||
| text: 'hello\n' | ||
| } | ||
| ]; | ||
|
|
||
| const block: DeepnoteBlock = { | ||
| id: 'block-3', | ||
| type: 'code', | ||
| content: 'print("hello")', | ||
| metadata: {}, | ||
| outputs: blockOutputs, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('code'); | ||
| expect(result.outputs).toEqual(blockOutputs); | ||
| }); | ||
|
|
||
| it('should remove truncated property from outputs', () => { | ||
| const blockOutputs = [ | ||
| { | ||
| output_type: 'stream', | ||
| name: 'stdout', | ||
| text: 'hello\n', | ||
| truncated: true | ||
| } | ||
| ]; | ||
|
|
||
| const block: DeepnoteBlock = { | ||
| id: 'block-4', | ||
| type: 'code', | ||
| content: 'print("hello")', | ||
| metadata: {}, | ||
| outputs: blockOutputs, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('code'); | ||
| expect(result.outputs).toHaveLength(1); | ||
| const resultOutputs = result.outputs as Array<{ output_type: string; name: string; text: string }>; | ||
| expect(resultOutputs[0]).not.toHaveProperty('truncated'); | ||
| expect(resultOutputs[0]).toEqual({ | ||
| output_type: 'stream', | ||
| name: 'stdout', | ||
| text: 'hello\n' | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle multiple outputs with truncated properties', () => { | ||
| const blockOutputs = [ | ||
| { | ||
| output_type: 'stream', | ||
| name: 'stdout', | ||
| text: 'line1\n', | ||
| truncated: true | ||
| }, | ||
| { | ||
| output_type: 'stream', | ||
| name: 'stdout', | ||
| text: 'line2\n', | ||
| truncated: false | ||
| } | ||
| ]; | ||
|
|
||
| const block: DeepnoteBlock = { | ||
| id: 'block-5', | ||
| type: 'code', | ||
| content: 'print("test")', | ||
| metadata: {}, | ||
| outputs: blockOutputs, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('code'); | ||
| expect(result.outputs).toHaveLength(2); | ||
| const resultOutputs = result.outputs as Array<{ output_type: string; name: string; text: string }>; | ||
| expect(resultOutputs[0]).not.toHaveProperty('truncated'); | ||
| expect(resultOutputs[1]).not.toHaveProperty('truncated'); | ||
| }); | ||
|
|
||
| it('should not mutate the original block', () => { | ||
| const blockOutputs = [ | ||
| { | ||
| output_type: 'stream', | ||
| name: 'stdout', | ||
| text: 'hello\n', | ||
| truncated: true | ||
| } | ||
| ]; | ||
|
|
||
| const block: DeepnoteBlock = { | ||
| id: 'block-6', | ||
| type: 'code', | ||
| content: 'print("hello")', | ||
| metadata: { test: 'value' }, | ||
| outputs: blockOutputs, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(block.outputs?.[0]).toHaveProperty('truncated'); | ||
| expect(block.metadata).toEqual({ test: 'value' }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('markdown cells', () => { | ||
| it('should convert a basic markdown block to a Jupyter markdown cell', () => { | ||
| const block: DeepnoteBlock = { | ||
| id: 'block-7', | ||
| type: 'markdown', | ||
| content: '# Hello', | ||
| metadata: { foo: 'bar' }, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('markdown'); | ||
| expect(result.metadata).toEqual({}); | ||
| expect(result.source).toBe('# Hello'); | ||
| }); | ||
|
|
||
| it('should convert text-cell-h1 to markdown cell', () => { | ||
| const block: DeepnoteBlock = { | ||
| id: 'block-8', | ||
| type: 'text-cell-h1', | ||
| content: 'Heading 1', | ||
| metadata: {}, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('markdown'); | ||
| }); | ||
|
|
||
| it('should convert image block to markdown cell', () => { | ||
| const block: DeepnoteBlock = { | ||
| id: 'block-9', | ||
| type: 'image', | ||
| content: '', | ||
| metadata: {}, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('markdown'); | ||
| }); | ||
|
|
||
| it('should not include metadata from Deepnote block in markdown cells', () => { | ||
| const block: DeepnoteBlock = { | ||
| id: 'block-10', | ||
| type: 'markdown', | ||
| content: 'Text', | ||
| metadata: { deepnoteMetadata: 'should not appear' }, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('markdown'); | ||
| expect(result.metadata).toEqual({}); | ||
| }); | ||
| }); | ||
|
|
||
| describe('special block types', () => { | ||
| it('should convert sql block to code cell', () => { | ||
| const block: DeepnoteBlock = { | ||
| id: 'block-11', | ||
| type: 'sql', | ||
| content: 'SELECT * FROM table', | ||
| metadata: {}, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('code'); | ||
| }); | ||
|
|
||
| it('should convert visualization block to code cell', () => { | ||
| const block: DeepnoteBlock = { | ||
| id: 'block-12', | ||
| type: 'visualization', | ||
| content: 'chart_data', | ||
| metadata: {}, | ||
| sortingKey: '1' | ||
| }; | ||
|
|
||
| const result = convertDeepnoteBlockToJupyterCell(block); | ||
|
|
||
| expect(result.cell_type).toBe('code'); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.