From a6daab695c24ddc09f74cf8dbde4f77d400e34f5 Mon Sep 17 00:00:00 2001 From: Will Faithfull Date: Mon, 4 Mar 2024 15:25:04 +0000 Subject: [PATCH] 954: Adds a sanity check test that the import command can actually import an openAPI spec, and fix a race condition bug arising from it. --- .../breadboard-cli/src/commands/import.ts | 2 +- packages/breadboard-cli/tests/index.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/breadboard-cli/src/commands/import.ts b/packages/breadboard-cli/src/commands/import.ts index c5cabd485ce..d797473b29a 100644 --- a/packages/breadboard-cli/src/commands/import.ts +++ b/packages/breadboard-cli/src/commands/import.ts @@ -82,7 +82,7 @@ export const importGraph = async (url: string, options: ImportOptions) => { const board = apiRef; if (outputPath != undefined) { - outputBoard(board.board.board, api, outputPath); + await outputBoard(board.board.board, api, outputPath); } else { console.log(JSON.stringify(board.board.board, null, 2)); } diff --git a/packages/breadboard-cli/tests/index.ts b/packages/breadboard-cli/tests/index.ts index 9dd3e4d4e17..c912ed66600 100644 --- a/packages/breadboard-cli/tests/index.ts +++ b/packages/breadboard-cli/tests/index.ts @@ -9,6 +9,7 @@ import test from "ava"; import { ExecException, exec } from "child_process"; import * as fs from "fs"; import path from "path"; +import { importGraph } from "../src/commands/import.js"; const packageDir = getPackageDir("@google-labs/breadboard-cli"); console.debug("packageDir", packageDir); @@ -203,6 +204,25 @@ test.after.always(() => { fs.rmSync(testDataDir, { recursive: true }); }); +test("import can import an openapi spec", async (t) => { + await importGraph("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/3.1.0/examples/v3.0/petstore.yaml", { + api: undefined, + output: testDataDir, + root: "", + save: false, + watch: false + }) + + const routes: string[] = ["createPets.json", "listPets.json", "showPetById.json"] + .map(f => + path.resolve(testDataDir, f) + ) + + routes.forEach(f => { + t.true(fs.existsSync(f)) + }) +}) + ////////////////////////////////////////////////// test("all test files exist", (t) => { testFiles.forEach((p) => {