From db9d3dc2de5212cdef83b4ee7afa3d689ac5a278 Mon Sep 17 00:00:00 2001 From: hughcrt Date: Mon, 18 Nov 2024 20:23:25 +0100 Subject: [PATCH] fix csv export test --- e2e/logs.spec.ts | 87 ++++++++++++++++---------- e2e/utils/db.ts | 37 ++--------- package-lock.json | 1 + package.json | 3 +- packages/frontend/pages/logs/index.tsx | 1 - 5 files changed, 63 insertions(+), 66 deletions(-) diff --git a/e2e/logs.spec.ts b/e2e/logs.spec.ts index 0665c763..214e04b3 100644 --- a/e2e/logs.spec.ts +++ b/e2e/logs.spec.ts @@ -4,40 +4,13 @@ import { PlaywrightTestOptions, test, } from "@playwright/test"; +import { setOrgPro } from "./utils/db"; +import fs from "fs"; test.describe.configure({ mode: "serial" }); let publicLogUrl: string; -function exportTest(buttonID: string) { - return async ({ page }: PlaywrightTestArgs) => { - const contentPromise = new Promise((resolve, reject) => { - page.on("download", async (download) => { - const stream = await download.createReadStream(); - const chunks: string[] = []; - - stream.on("readable", () => { - let chunk; - while (null !== (chunk = stream.read())) { - chunks.push(chunk); - } - }); - - stream.on("end", () => resolve(chunks.join(""))); - stream.on("error", reject); - }); - }); - - await page.goto("/logs?type=trace"); - await page.waitForLoadState("networkidle"); - - await page.getByTestId("export-menu").click(); - await page.getByTestId(buttonID).click(); - - await contentPromise; - }; -} - test("make a log public", async ({ page, context }) => { await context.grantPermissions(["clipboard-read", "clipboard-write"]); @@ -56,9 +29,59 @@ test("make a log public", async ({ page, context }) => { }); }); -test("test export csv", exportTest("export-csv-button")); -test("test export jsonl", exportTest("export-raw-jsonl-button")); -test("test export ojsonl", exportTest("export-openai-jsonl-button")); +test("test export csv", async ({ page }) => { + page.on("console", (msg) => { + console.log(msg); + }); + await setOrgPro(); + + await page.goto("/logs?type=llm"); + await page.waitForLoadState("networkidle"); + + const downloadPromise = page.waitForEvent("download"); + + await page.getByTestId("export-menu").click(); + await page.getByTestId("export-csv-button").click(); + + const file = await downloadPromise; + const path = await file.path(); + const content = fs.readFileSync(path, "utf-8"); + + const expectedHeaders = [ + "id", + "projectId", + "isPublic", + "feedback", + "parentFeedback", + "type", + "name", + "createdAt", + "endedAt", + "duration", + "templateVersionId", + "templateSlug", + "cost", + "tokens", + "tags", + "input", + "output", + "error", + "status", + "siblingRunId", + "params", + "metadata", + "user", + "traceId", + "scores", + ]; + const actualHeaderLine = content.split("\n")[0].trim(); + expect(actualHeaderLine).toBe(`"${expectedHeaders.join('","')}"`); + + // TODO: check that the content of each column for each row is correct (use json-2-csv to convert the csv to json + // TODO: do the same thing for threads and traces (do not forget to check that children has the right) +}); + +// TODO: test export-raw-jsonl-button and export-openai-jsonl-button test("unauthenticated user can access public log URL", async ({ browser }) => { const context = await browser.newContext(); diff --git a/e2e/utils/db.ts b/e2e/utils/db.ts index 14387d7b..1ed0281d 100644 --- a/e2e/utils/db.ts +++ b/e2e/utils/db.ts @@ -45,7 +45,7 @@ export async function populateLogs() { external_user_id: 91823, feedback: null, template_version_id: null, - runtime: "langchain-js", + runtime: "langchain-py", metadata: "{}", }, { @@ -65,21 +65,12 @@ export async function populateLogs() { prompt_tokens: null, completion_tokens: null, cost: null, - external_user_id: 25, + external_user_id: 91823, feedback: null, is_public: false, template_version_id: null, runtime: "lunary-py", metadata: null, - total_tokens: null, - user_id: 25, - user_external_id: "123", - user_created_at: "2024-11-14T03:54:12.157Z", - user_last_seen: "2024-11-14T03:55:51.596Z", - user_props: null, - template_slug: null, - parent_feedback: null, - evaluation_results: [], }, { created_at: "2024-11-14T03:54:11.773Z", @@ -98,21 +89,12 @@ export async function populateLogs() { prompt_tokens: null, completion_tokens: null, cost: null, - external_user_id: 25, + external_user_id: 91823, feedback: null, is_public: false, template_version_id: null, runtime: "lunary-py", metadata: null, - total_tokens: null, - user_id: 25, - user_external_id: "123", - user_created_at: "2024-11-14T03:54:12.157Z", - user_last_seen: "2024-11-14T03:55:51.596Z", - user_props: null, - template_slug: null, - parent_feedback: null, - evaluation_results: [], }, { created_at: "2024-09-28T11:42:37.770Z", @@ -140,21 +122,12 @@ export async function populateLogs() { prompt_tokens: null, completion_tokens: null, cost: null, - external_user_id: 112, + external_user_id: 91823, feedback: null, is_public: false, template_version_id: null, - runtime: "lunary-js", + runtime: "lunary-py", metadata: null, - total_tokens: null, - user_id: 112, - user_external_id: "demo-user-4", - user_created_at: "2024-09-28T11:39:05.167Z", - user_last_seen: "2024-09-28T11:42:41.159Z", - user_props: { name: "Test User 2", email: "test.user2@example.org" }, - template_slug: null, - parent_feedback: { thumbs: "down" }, - evaluation_results: [], }, ]; await sql`insert into run ${sql(logs)}`; diff --git a/package-lock.json b/package-lock.json index e7187d0c..2102a79b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "@playwright/test": "^1.47.0", "@types/node": "^22.5.4", "dotenv": "^16.4.5", + "json-2-csv": "^5.5.6", "prettier": "^3.3.3", "tsup": "^8.2.4", "tsx": "^4.19.0", diff --git a/package.json b/package.json index 92f8332e..d292e64d 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,10 @@ "@playwright/test": "^1.47.0", "@types/node": "^22.5.4", "dotenv": "^16.4.5", + "json-2-csv": "^5.5.6", "prettier": "^3.3.3", "tsup": "^8.2.4", "tsx": "^4.19.0", "typescript": "^5.5.4" } -} \ No newline at end of file +} diff --git a/packages/frontend/pages/logs/index.tsx b/packages/frontend/pages/logs/index.tsx index be2ce89f..8739c4fb 100644 --- a/packages/frontend/pages/logs/index.tsx +++ b/packages/frontend/pages/logs/index.tsx @@ -218,7 +218,6 @@ export default function Logs() { "filters", parser.withDefault(DEFAULT_CHECK).withOptions({ clearOnDefault: true }), ); - console.log(checks); const { sortParams } = useSortParams();