Repository navigation
feat: vibed cli for valdiating the deepnote files - #108
jamesbhobbs wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## filipzitny/mar-250-create-examples-for-open-source #108 +/- ##
======================================================================================
- Coverage 95.24% 86.53% -8.72%
======================================================================================
Files 25 25
Lines 715 787 +72
Branches 207 225 +18
======================================================================================
Hits 681 681
- Misses 34 106 +72 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📝 WalkthroughWalkthroughExtends the convert package CLI from single-command to multi-command architecture supporting both Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant Validate Function
participant File System
participant Schema Validator
User->>CLI: pnpm run validate:deepnote-files
CLI->>Validate Function: validate(inputPath, cwd)
alt Is Single File
Validate Function->>File System: Read .deepnote file
File System-->>Validate Function: YAML content
else Is Directory
Validate Function->>File System: Find all .deepnote files recursively
File System-->>Validate Function: File list
loop For each file
Validate Function->>File System: Read file
File System-->>Validate Function: YAML content
end
end
loop Validate each file
Validate Function->>Validate Function: Parse YAML
Validate Function->>Schema Validator: Validate against deepnoteFileSchema
Schema Validator-->>Validate Function: { valid, errors? }
end
Validate Function->>CLI: Report per-file results (colored output)
CLI->>User: Exit with code (0 if all valid, 1 if any invalid)
Possibly related PRs
Suggested reviewers
Pre-merge checks✅ Passed checks (2 passed)
Comment |
* feat: vibed cli for valdiating the deepnote files * chore: fix lock
There was a problem hiding this comment.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (6)
.github/workflows/ci.yml(1 hunks)package.json(1 hunks)packages/convert/package.json(1 hunks)packages/convert/src/bin.ts(1 hunks)packages/convert/src/cli.ts(2 hunks)packages/convert/tsdown.config.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
packages/*/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
packages/*/src/**/*.{ts,tsx}: Use strict type checking and prefer type safety over convenience
Use const for immutable values
Avoid any; use proper type definitions and type guards
Files:
packages/convert/src/bin.tspackages/convert/src/cli.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx}: Follow Biome's lint rules as configured in biome.json
Use literal keys (dot notation) instead of bracket notation when possible
Prefer single quotes for strings (except when avoiding escapes)
Files:
packages/convert/src/bin.tspackages/convert/tsdown.config.tspackages/convert/src/cli.ts
packages/*/src/**/*
📄 CodeRabbit inference engine (CLAUDE.md)
Place source code under packages/*/src/
Files:
packages/convert/src/bin.tspackages/convert/src/cli.ts
🧬 Code graph analysis (2)
packages/convert/src/bin.ts (1)
packages/convert/src/cli.ts (2)
convert(16-111)validate(170-254)
packages/convert/src/cli.ts (1)
packages/blocks/src/deserialize-file/parse-yaml.ts (1)
parseYaml(3-12)
🔇 Additional comments (6)
packages/convert/tsdown.config.ts (1)
1-8: LGTM!The tsdown configuration correctly defines entry points, output format, and target runtime. Aligns with the package's Node 18+ requirement.
package.json (1)
28-29: LGTM!The validation script correctly targets the built CLI. CI workflow appropriately runs build before validation.
.github/workflows/ci.yml (1)
41-66: LGTM!The CI job follows existing patterns and correctly builds before validating. Timeout and steps are appropriate.
packages/convert/package.json (1)
31-33: LGTM!Simplified scripts by moving configuration to tsdown.config.ts. Cleaner and follows best practices.
packages/convert/src/cli.ts (2)
142-168: LGTM!Clean validation logic with proper error handling. safeParse prevents throws, and error formatting is clear.
170-254: LGTM on overall structure and exit handling.The validate function appropriately handles both directory and single-file cases. Exit code 1 on failure is correct for CI integration.
| cli({ | ||
| name: 'deepnote-convert', | ||
| parameters: ['<path>'], | ||
| flags: { | ||
| projectName: { | ||
| description: 'The name of the Deepnote project.', | ||
| type: String, | ||
| }, | ||
| outputPath: { | ||
| alias: 'o', | ||
| description: 'The path where the .deepnote file will be saved.', | ||
| type: String, | ||
| }, | ||
| cwd: { | ||
| description: 'The working directory to resolve paths relative to.', | ||
| type: String, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| await convert({ | ||
| inputPath: argv._.path, | ||
| projectName: argv.flags.projectName, | ||
| outputPath: argv.flags.outputPath, | ||
| cwd: argv.flags.cwd ?? process.cwd(), | ||
| version: '1.2.0', | ||
| commands: [ | ||
| command( | ||
| { | ||
| name: 'convert', | ||
| alias: 'c', | ||
| parameters: ['<path>'], | ||
| flags: { | ||
| projectName: { | ||
| description: 'The name of the Deepnote project.', | ||
| type: String, | ||
| }, | ||
| outputPath: { | ||
| alias: 'o', | ||
| description: 'The path where the .deepnote file will be saved.', | ||
| type: String, | ||
| }, | ||
| cwd: { | ||
| description: 'The working directory to resolve paths relative to.', | ||
| type: String, | ||
| }, | ||
| }, | ||
| }, | ||
| async argv => { | ||
| await convert({ | ||
| inputPath: argv._.path, | ||
| projectName: argv.flags.projectName, | ||
| outputPath: argv.flags.outputPath, | ||
| cwd: argv.flags.cwd ?? process.cwd(), | ||
| }) | ||
| } | ||
| ), | ||
| command( | ||
| { | ||
| name: 'validate', | ||
| alias: 'v', | ||
| parameters: ['<path>'], | ||
| flags: { | ||
| cwd: { | ||
| description: 'The working directory to resolve paths relative to.', | ||
| type: String, | ||
| }, | ||
| }, | ||
| }, | ||
| async argv => { | ||
| await validate({ | ||
| inputPath: argv._.path, | ||
| cwd: argv.flags.cwd ?? process.cwd(), | ||
| }) | ||
| } | ||
| ), | ||
| ], | ||
| }) |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Consider importing version from package.json.
The version is hardcoded at line 8, duplicating the value in package.json. This creates maintenance overhead.
You could import it from package.json:
+import { readFileSync } from 'node:fs'
+import { resolve, dirname } from 'node:path'
+import { fileURLToPath } from 'node:url'
import { cli, command } from 'cleye'
import { convert, validate } from './cli.js'
+const __dirname = dirname(fileURLToPath(import.meta.url))
+const pkg = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf-8'))
+
async function main() {
cli({
name: 'deepnote-convert',
- version: '1.2.0',
+ version: pkg.version,
commands: [Or keep it simple if manual sync is acceptable.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In packages/convert/src/bin.ts around lines 6 to 60, the CLI version is
hardcoded ("1.2.0") which duplicates package.json; import the version field from
the package.json (e.g., const { version } = require('../package.json') or the
appropriate relative path / ES import) at the top of the file and replace the
hardcoded string with that imported version value so the CLI always reflects
package.json.
| import { deepnoteFileSchema } from '@deepnote/blocks' | ||
| import chalk from 'chalk' | ||
| import ora from 'ora' | ||
| import { parse as parseYaml } from 'yaml' |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Consider using @deepnote/blocks parseYaml wrapper.
The blocks package has a parseYaml wrapper (packages/blocks/src/deserialize-file/parse-yaml.ts) that adds error handling. Currently importing directly from yaml library duplicates this logic at line 149.
If the wrapper is exported, prefer it:
-import { parse as parseYaml } from 'yaml'
+import { parseYaml } from '@deepnote/blocks'Otherwise, current approach is acceptable but involves slight duplication.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In packages/convert/src/cli.ts around line 6 (and usage at line 149), the file
imports parse from 'yaml' directly which duplicates error-handling logic;
replace the direct import with the @deepnote/blocks parseYaml wrapper
(packages/blocks/src/deserialize-file/parse-yaml.ts) by importing the exported
wrapper and use it where parseYaml is currently called; if that wrapper is not
exported from the blocks package, leave the existing direct import but add a
TODO comment referencing the wrapper export so we can switch once it’s
available.
| /** | ||
| * Recursively find all .deepnote files in a directory | ||
| */ | ||
| async function findDeepnoteFiles(dir: string): Promise<string[]> { | ||
| const files: string[] = [] | ||
| const entries = await fs.readdir(dir, { withFileTypes: true }) | ||
|
|
||
| for (const entry of entries) { | ||
| const fullPath = resolve(dir, entry.name) | ||
|
|
||
| if (entry.isDirectory()) { | ||
| // Skip node_modules and hidden directories | ||
| if (entry.name === 'node_modules' || entry.name.startsWith('.')) { | ||
| continue | ||
| } | ||
| files.push(...(await findDeepnoteFiles(fullPath))) | ||
| } else if (entry.name.endsWith('.deepnote')) { | ||
| files.push(fullPath) | ||
| } | ||
| } | ||
|
|
||
| return files | ||
| } |
There was a problem hiding this comment.
Extension check is case-sensitive.
Line 134 checks entry.name.endsWith('.deepnote') which won't match files like .Deepnote or .DEEPNOTE. If these exist in the wild, validation will skip them silently.
If case-insensitivity is desired:
- } else if (entry.name.endsWith('.deepnote')) {
+ } else if (entry.name.toLowerCase().endsWith('.deepnote')) {Otherwise, document that validation is case-sensitive.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** | |
| * Recursively find all .deepnote files in a directory | |
| */ | |
| async function findDeepnoteFiles(dir: string): Promise<string[]> { | |
| const files: string[] = [] | |
| const entries = await fs.readdir(dir, { withFileTypes: true }) | |
| for (const entry of entries) { | |
| const fullPath = resolve(dir, entry.name) | |
| if (entry.isDirectory()) { | |
| // Skip node_modules and hidden directories | |
| if (entry.name === 'node_modules' || entry.name.startsWith('.')) { | |
| continue | |
| } | |
| files.push(...(await findDeepnoteFiles(fullPath))) | |
| } else if (entry.name.endsWith('.deepnote')) { | |
| files.push(fullPath) | |
| } | |
| } | |
| return files | |
| } | |
| /** | |
| * Recursively find all .deepnote files in a directory | |
| */ | |
| async function findDeepnoteFiles(dir: string): Promise<string[]> { | |
| const files: string[] = [] | |
| const entries = await fs.readdir(dir, { withFileTypes: true }) | |
| for (const entry of entries) { | |
| const fullPath = resolve(dir, entry.name) | |
| if (entry.isDirectory()) { | |
| // Skip node_modules and hidden directories | |
| if (entry.name === 'node_modules' || entry.name.startsWith('.')) { | |
| continue | |
| } | |
| files.push(...(await findDeepnoteFiles(fullPath))) | |
| } else if (entry.name.toLowerCase().endsWith('.deepnote')) { | |
| files.push(fullPath) | |
| } | |
| } | |
| return files | |
| } |
🤖 Prompt for AI Agents
In packages/convert/src/cli.ts around lines 118 to 140 the extension check
entry.name.endsWith('.deepnote') is case-sensitive and will miss files like
.Deepnote or .DEEPNOTE; update the condition to perform a case-insensitive
comparison (e.g. use entry.name.toLowerCase().endsWith('.deepnote')) so all case
variants are matched, and keep the rest of the logic unchanged.
| for (const file of deepnoteFiles) { | ||
| const relativePath = basename(file) | ||
| const result = await validateSingleFile(file) | ||
| results.push({ file: relativePath, ...result }) |
There was a problem hiding this comment.
File display loses directory context.
Line 192 uses basename(file) for display. If multiple .deepnote files have the same name in different subdirectories, the output becomes ambiguous—you won't know which file failed.
Consider using relative path instead:
+ const relativePath = relative(absolutePath, file)
- const relativePath = basename(file)
const result = await validateSingleFile(file)Or keep basename if directory structure is guaranteed flat.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In packages/convert/src/cli.ts around lines 191 to 194, the code uses
basename(file) which drops directory context and can make multiple files with
the same name ambiguous; change it to a relative path (e.g.,
path.relative(process.cwd(), file) or relative to the input directory you
expect) so the display preserves subdirectory structure, and use that
relativePath variable when pushing results instead of basename.
…o val-deepnotefiles
Summary by CodeRabbit
validate:deepnote-filesscript available for manual validation