Skip to content

Commit

Permalink
fix csv export test
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt committed Nov 18, 2024
1 parent db62c4f commit db9d3dc
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 66 deletions.
87 changes: 55 additions & 32 deletions e2e/logs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);

Expand All @@ -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();
Expand Down
37 changes: 5 additions & 32 deletions e2e/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "{}",
},
{
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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: "[email protected]" },
template_slug: null,
parent_feedback: { thumbs: "down" },
evaluation_results: [],
},
];
await sql`insert into run ${sql(logs)}`;
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
1 change: 0 additions & 1 deletion packages/frontend/pages/logs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ export default function Logs() {
"filters",
parser.withDefault(DEFAULT_CHECK).withOptions({ clearOnDefault: true }),
);
console.log(checks);

const { sortParams } = useSortParams();

Expand Down

0 comments on commit db9d3dc

Please sign in to comment.