diff --git a/libs/langchain-scripts/bin/validate_notebook.js b/libs/langchain-scripts/bin/validate_notebook.js index 2ff6aa968a34..cac5f69d91e8 100755 --- a/libs/langchain-scripts/bin/validate_notebook.js +++ b/libs/langchain-scripts/bin/validate_notebook.js @@ -1 +1 @@ -import "../dist/validate_notebook.js"; +import "../dist/notebooks/index.js"; diff --git a/libs/langchain-scripts/src/validate_notebook.ts b/libs/langchain-scripts/src/notebooks/check_notebook_type_errors.ts similarity index 98% rename from libs/langchain-scripts/src/validate_notebook.ts rename to libs/langchain-scripts/src/notebooks/check_notebook_type_errors.ts index 65907c159566..358f2aaa10eb 100644 --- a/libs/langchain-scripts/src/validate_notebook.ts +++ b/libs/langchain-scripts/src/notebooks/check_notebook_type_errors.ts @@ -69,7 +69,7 @@ if (!pathname) { throw new Error("No pathname provided."); } -const run = async () => { +export async function checkNotebookTypeErrors() { if (!pathname.endsWith(".ipynb")) { throw new Error("Only .ipynb files are supported."); } @@ -130,10 +130,4 @@ const run = async () => { // Do nothing } } -}; - -try { - void run(); -} catch { - process.exit(1); } diff --git a/libs/langchain-scripts/src/notebooks/check_unexpected_rebuild_timer.ts b/libs/langchain-scripts/src/notebooks/check_unexpected_rebuild_timer.ts new file mode 100644 index 000000000000..19cc3c4afcc2 --- /dev/null +++ b/libs/langchain-scripts/src/notebooks/check_unexpected_rebuild_timer.ts @@ -0,0 +1,26 @@ +import fs from "fs"; + +const [pathname] = process.argv.slice(2); + +if (!pathname) { + throw new Error("No pathname provided."); +} + +/** + * tslab will sometimes throw an error inside the output cells of a notebook + * if the notebook is being rebuilt. This function checks for that error, + * because we do not want to commit that to our docs. + */ +export async function checkUnexpectedRebuildError() { + if (!pathname.endsWith(".ipynb")) { + throw new Error("Only .ipynb files are supported."); + } + const notebookContents = await fs.promises.readFile(pathname, "utf-8"); + if ( + notebookContents.includes( + "UncaughtException: Error: Unexpected pending rebuildTimer" + ) + ) { + throw new Error(`Found unexpected pending rebuildTimer in ${pathname}`); + } +} diff --git a/libs/langchain-scripts/src/notebooks/index.ts b/libs/langchain-scripts/src/notebooks/index.ts new file mode 100644 index 000000000000..3eccf3906de2 --- /dev/null +++ b/libs/langchain-scripts/src/notebooks/index.ts @@ -0,0 +1,12 @@ +import { checkNotebookTypeErrors } from "./check_notebook_type_errors.js"; +import { checkUnexpectedRebuildError } from "./check_unexpected_rebuild_timer.js"; + +async function main() { + await Promise.all([checkNotebookTypeErrors(), checkUnexpectedRebuildError()]); +} + +try { + void main(); +} catch { + process.exit(1); +}