|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { exec } from "child_process"; |
| 3 | +import fs from "fs"; |
| 4 | +import path from "path"; |
| 5 | +import util from "util"; |
| 6 | +import { TemplateVectorDB } from "../helpers/types"; |
| 7 | +import { createTestDir, runCreateLlama } from "./utils"; |
| 8 | + |
| 9 | +const execAsync = util.promisify(exec); |
| 10 | + |
| 11 | +const vectorDbs: TemplateVectorDB[] = [ |
| 12 | + "mongo", |
| 13 | + "pg", |
| 14 | + "pinecone", |
| 15 | + "milvus", |
| 16 | + "astra", |
| 17 | + "qdrant", |
| 18 | + "chroma", |
| 19 | + "weaviate", |
| 20 | +]; |
| 21 | + |
| 22 | +const toolOptions = [ |
| 23 | + "wikipedia.WikipediaToolSpec", |
| 24 | + "google.GoogleSearchToolSpec", |
| 25 | +]; |
| 26 | + |
| 27 | +// TODO: Add data sources to the test |
| 28 | + |
| 29 | +test.describe("Test resolve python dependencies", () => { |
| 30 | + for (const vectorDb of vectorDbs) { |
| 31 | + for (const tool of toolOptions) { |
| 32 | + const optionDescription = `vectorDb: ${vectorDb}, tools: ${tool}`; |
| 33 | + |
| 34 | + test(`options: ${optionDescription}`, async () => { |
| 35 | + const cwd = await createTestDir(); |
| 36 | + |
| 37 | + const result = await runCreateLlama( |
| 38 | + cwd, |
| 39 | + "streaming", |
| 40 | + "fastapi", |
| 41 | + "--example-file", |
| 42 | + vectorDb, |
| 43 | + 3000, // port |
| 44 | + 8000, // externalPort |
| 45 | + "none", // postInstallAction |
| 46 | + undefined, // ui |
| 47 | + "--no-frontend", // appType |
| 48 | + undefined, // llamaCloudProjectName |
| 49 | + undefined, // llamaCloudIndexName |
| 50 | + tool, |
| 51 | + ); |
| 52 | + const name = result.projectName; |
| 53 | + |
| 54 | + // Check if the app folder exists |
| 55 | + const dirExists = fs.existsSync(path.join(cwd, name)); |
| 56 | + expect(dirExists).toBeTruthy(); |
| 57 | + |
| 58 | + // Check if pyproject.toml exists |
| 59 | + const pyprojectPath = path.join(cwd, name, "pyproject.toml"); |
| 60 | + const pyprojectExists = fs.existsSync(pyprojectPath); |
| 61 | + expect(pyprojectExists).toBeTruthy(); |
| 62 | + |
| 63 | + // Run poetry lock |
| 64 | + try { |
| 65 | + const { stdout, stderr } = await execAsync( |
| 66 | + // Config poetry to create virtualenv in project directory. |
| 67 | + // so that we can easily prune the e2e cache to avoid overloading the storage. |
| 68 | + "poetry config virtualenvs.in-project true && poetry lock --no-update", |
| 69 | + { |
| 70 | + cwd: path.join(cwd, name), |
| 71 | + }, |
| 72 | + ); |
| 73 | + console.log("poetry lock stdout:", stdout); |
| 74 | + console.error("poetry lock stderr:", stderr); |
| 75 | + } catch (error) { |
| 76 | + console.error("Error running poetry lock:", error); |
| 77 | + throw error; |
| 78 | + } |
| 79 | + |
| 80 | + // Check if poetry.lock file was created |
| 81 | + const poetryLockExists = fs.existsSync( |
| 82 | + path.join(cwd, name, "poetry.lock"), |
| 83 | + ); |
| 84 | + expect(poetryLockExists).toBeTruthy(); |
| 85 | + |
| 86 | + // Verify that specific dependencies are in pyproject.toml |
| 87 | + const pyprojectContent = fs.readFileSync(pyprojectPath, "utf-8"); |
| 88 | + if (vectorDb !== "none") { |
| 89 | + if (vectorDb === "pg") { |
| 90 | + expect(pyprojectContent).toContain( |
| 91 | + "llama-index-vector-stores-postgres", |
| 92 | + ); |
| 93 | + } else { |
| 94 | + expect(pyprojectContent).toContain( |
| 95 | + `llama-index-vector-stores-${vectorDb}`, |
| 96 | + ); |
| 97 | + } |
| 98 | + } |
| 99 | + if (tool !== "none") { |
| 100 | + if (tool === "wikipedia.WikipediaToolSpec") { |
| 101 | + expect(pyprojectContent).toContain("wikipedia"); |
| 102 | + } |
| 103 | + if (tool === "google.GoogleSearchToolSpec") { |
| 104 | + expect(pyprojectContent).toContain("google"); |
| 105 | + } |
| 106 | + } |
| 107 | + }); |
| 108 | + } |
| 109 | + } |
| 110 | +}); |
0 commit comments