Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js): Fix multiple datasets in same test file for Vitest, improve reporter output #1475

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith",
"version": "0.3.3",
"version": "0.3.4",
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
"packageManager": "[email protected]",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export { RunTree, type RunTreeConfig } from "./run_trees.js";
export { overrideFetchImplementation } from "./singletons/fetch.js";

// Update using yarn bump-version
export const __version__ = "0.3.3";
export const __version__ = "0.3.4";
14 changes: 13 additions & 1 deletion js/src/jest/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { printReporterTable } from "../utils/jestlike/reporter.js";

class LangSmithEvalReporter extends DefaultReporter {
async onTestResult(test: any, testResult: any, aggregatedResults: any) {
if (testResult.failureMessage) {
console.log(testResult.failureMessage);
}
const groupedTestResults = testResult.testResults.reduce(
(groups: Record<string, any>, testResult: any) => {
const ancestorTitle = testResult.ancestorTitles.join(" > ");
Expand All @@ -19,7 +22,16 @@ class LangSmithEvalReporter extends DefaultReporter {
try {
for (const testGroupName of Object.keys(groupedTestResults)) {
const resultGroup = groupedTestResults[testGroupName];
await printReporterTable(resultGroup, testResult.failureMessage);
const unskippedTests = resultGroup.filter(
(result: any) => result.status !== "pending"
);
const overallResult =
unskippedTests.length === 0
? "skip"
: unskippedTests.every((result: any) => result.status === "passed")
? "pass"
: "fail";
await printReporterTable(testGroupName, resultGroup, overallResult);
}
} catch (e: any) {
console.log("Failed to display LangSmith eval results:", e.message);
Expand Down
40 changes: 40 additions & 0 deletions js/src/tests/jestlike/vitest_separate_file.vitesteval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,43 @@ ls.describe(
},
}
);

ls.describe(
"js vitest 3",
() => {
ls.test.each(
[
{
inputs: {
one: "uno",
},
referenceOutputs: {
ein: "un",
},
},
{
inputs: {
two: "dos",
},
referenceOutputs: {
zwei: "deux",
},
},
],
{ iterations: 3, metadata: { something: "cool" } }
)("Does the thing", async ({ inputs, referenceOutputs }) => {
const myApp = () => {
return { bar: "bad" };
};
const res = myApp();
const evaluator = ls.wrapEvaluator(myEvaluator);
await evaluator({ inputs, referenceOutputs, outputs: res });
return res;
});
},
{
metadata: {
model: "test-model",
},
}
);
30 changes: 22 additions & 8 deletions js/src/utils/jestlike/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ function formatTestName(name: string, duration: number) {

function getFormattedStatus(status: string) {
const s = status.toLowerCase();
if (s === "pending") {
if (s === "pending" || s === "skipped") {
return chalk.yellow("○ Skipped");
} else if (s === "passed") {
} else if (s.includes("pass")) {
return chalk.green("✓ Passed");
} else if (s === "failed") {
} else if (s.includes("fail")) {
return chalk.red("✕ Failed");
} else {
return status;
Expand All @@ -43,11 +43,11 @@ function getFormattedStatus(status: string) {

function getColorParam(status: string) {
const s = status.toLowerCase();
if (s === "pending") {
if (s === "pending" || s === "skipped") {
return { color: "yellow" };
} else if (s === "passed") {
} else if (s.includes("pass")) {
return { color: "grey" };
} else if (s === "failed") {
} else if (s.includes("fail")) {
return { color: "red" };
} else {
return {};
Expand Down Expand Up @@ -75,7 +75,13 @@ function formatValue(value: unknown) {
}

export async function printReporterTable(
results: { title: string; duration: number; status: string }[],
testSuiteName: string,
results: {
title: string;
duration: number;
status: "pass" | "passed" | "fail" | "failed" | "pending" | "skipped";
}[],
testStatus: "pass" | "skip" | "fail",
failureMessage?: string
) {
const rows = [];
Expand All @@ -101,7 +107,7 @@ export async function printReporterTable(
},
getColorParam(status),
]);
} else if (status === "pending") {
} else if (status === "pending" || status === "skipped") {
// Skipped
rows.push([
{
Expand Down Expand Up @@ -265,6 +271,14 @@ export async function printReporterTable(
for (const row of rows) {
table.addRow(row[0], row[1]);
}
const testStatusColor = testStatus.includes("pass")
? chalk.green
: testStatus.includes("fail")
? chalk.red
: chalk.yellow;
if (testSuiteName) {
console.log(testStatusColor(`› ${testSuiteName}`));
}
if (failureMessage) {
console.log(failureMessage);
}
Expand Down
25 changes: 16 additions & 9 deletions js/src/vitest/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ class LangSmithEvalReporter extends DefaultReporter {
async onFinished(files: RunnerTestFile[], errors: unknown[]) {
super.onFinished(files, errors);
for (const file of files) {
const testModule = this.ctx.state.getReportedEntity(file) as TestModule;
const tests = [...testModule.children.allTests()].map((test) => {
return {
title: test.name,
status: test.result()?.state ?? "skipped",
duration: Math.round(test.diagnostic()?.duration ?? 0),
};
});
await printReporterTable(tests);
for (const task of file.tasks) {
const testModule = this.ctx.state.getReportedEntity(task) as TestModule;
const tests = [...testModule.children.allTests()].map((test) => {
return {
title: test.name,
status: test.result()?.state ?? "skipped",
duration: Math.round(test.diagnostic()?.duration ?? 0),
};
});
const result = ["pass", "fail", "skip"].includes(
task.result?.state ?? ""
)
? (task.result?.state as "pass" | "fail" | "skip")
: "skip";
await printReporterTable(task.name, tests, result);
}
}
}
}
Expand Down
Loading