Roo-Code/test-jupyter-fix.js
Roo Code 0115755f60 Fixes #4956: Add proper Jupyter notebook support for apply_diff and write_to_file tools
- Created jupyter-notebook-handler.ts with utilities for parsing and handling .ipynb files
- Modified applyDiffTool.ts to extract cell content for editing and reconstruct notebook JSON
- Modified multiApplyDiffTool.ts to handle Jupyter notebooks in batch operations
- Modified writeToFileTool.ts to detect and properly handle notebook content vs raw JSON
- Added comprehensive test suite for all notebook operations
- Prevents notebook corruption by maintaining proper JSON structure
- Supports both extracted content editing and direct JSON editing workflows
2025-06-20 23:28:09 +00:00

41 lines
1.2 KiB
JavaScript

const fs = require("fs").promises
const path = require("path")
// Simple test to verify the Jupyter notebook handler works
async function testJupyterHandler() {
try {
// Import the handler functions
const {
isJupyterNotebook,
parseJupyterNotebook,
applyChangesToNotebook,
writeJupyterNotebook,
validateJupyterNotebookJson,
} = require("./src/core/tools/jupyter-notebook-handler.ts")
console.log("✓ Jupyter notebook handler imported successfully")
// Test isJupyterNotebook
console.log("Testing isJupyterNotebook...")
console.log("test.ipynb:", isJupyterNotebook("test.ipynb")) // should be true
console.log("test.py:", isJupyterNotebook("test.py")) // should be false
// Test validateJupyterNotebookJson
console.log("Testing validateJupyterNotebookJson...")
const validNotebook = JSON.stringify({
cells: [],
metadata: {},
nbformat: 4,
nbformat_minor: 2,
})
const validation = validateJupyterNotebookJson(validNotebook)
console.log("Valid notebook validation:", validation)
console.log("✓ All basic tests passed")
} catch (error) {
console.error("✗ Test failed:", error.message)
process.exit(1)
}
}
testJupyterHandler()