Skip to content

Commit f6b2e7d

Browse files
chore: rebase fixes and move to vitest
1 parent 9f05fc0 commit f6b2e7d

File tree

6 files changed

+68
-17
lines changed

6 files changed

+68
-17
lines changed

package-lock.json

Lines changed: 33 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/accuracy/run-accuracy-tests.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@ export MDB_ACCURACY_RUN_ID=$(npx uuid v4)
1616
# By default we run all the tests under tests/accuracy folder unless a path is
1717
# specified in the command line. Such as:
1818
# npm run test:accuracy -- tests/accuracy/some-test.test.ts
19-
if [ $# -gt 0 ]; then
20-
TEST_PATH_PATTERN="$1"
21-
shift
22-
else
23-
TEST_PATH_PATTERN="tests/accuracy"
24-
fi
25-
echo "Running accuracy tests with MDB_ACCURACY_RUN_ID '$MDB_ACCURACY_RUN_ID' and TEST_PATH_PATTERN '$TEST_PATH_PATTERN'"
26-
node --experimental-vm-modules node_modules/jest/bin/jest.js --bail --testPathPatterns "$TEST_PATH_PATTERN" "$@"
19+
echo "Running accuracy tests with MDB_ACCURACY_RUN_ID '$MDB_ACCURACY_RUN_ID'"
20+
vitest --config vitest.config.ts --project=accuracy --coverage=false --run --testTimeout=3600000 "$@"
2721

2822
# Preserving the exit code from test run to correctly notify in the CI
2923
# environments when the tests fail.
30-
JEST_EXIT_CODE=$?
24+
TEST_EXIT_CODE=$?
3125

3226
# Each test run submits an accuracy result with the accuracyRunStatus:
3327
# "in-progress". When all the tests are done and jest exits with an exit code of
@@ -42,10 +36,10 @@ JEST_EXIT_CODE=$?
4236

4337
# This is necessary when comparing one accuracy run with another as we wouldn't
4438
# want to compare against an incomplete run.
45-
export MDB_ACCURACY_RUN_STATUS=$([ $JEST_EXIT_CODE -eq 0 ] && echo "done" || echo "failed")
39+
export MDB_ACCURACY_RUN_STATUS=$([ $TEST_EXIT_CODE -eq 0 ] && echo "done" || echo "failed")
4640
npx tsx scripts/accuracy/update-accuracy-run-status.ts || echo "Warning: Failed to update accuracy run status to '$MDB_ACCURACY_RUN_STATUS'"
4741

4842
# This is optional but we do it anyways to generate a readable summary of report.
4943
npx tsx scripts/accuracy/generate-test-summary.ts || echo "Warning: Failed to generate test summary HTML report"
5044

51-
exit $JEST_EXIT_CODE
45+
exit $TEST_EXIT_CODE

tests/accuracy/sdk/accuracy-result-storage/disk-storage.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class DiskBasedResultStorage implements AccuracyResultStorage {
5252
// commit so that we can use that during baseline comparison.
5353
if (status === AccuracyRunStatus.Done) {
5454
const latestResultFilePath = this.getLatestResultFilePath(commitSHA);
55+
await this.ensureFileWithInitialData(latestResultFilePath, JSON.stringify({}));
5556
await this.withFileLock(latestResultFilePath, async () => {
5657
await fs.unlink(latestResultFilePath);
5758
await fs.link(resultFilePath, latestResultFilePath);
@@ -86,7 +87,7 @@ export class DiskBasedResultStorage implements AccuracyResultStorage {
8687
],
8788
};
8889
const resultFilePath = this.getAccuracyResultFilePath(commitSHA, runId);
89-
const { fileCreatedWithInitialData } = await this.ensureAccuracyResultFile(
90+
const { fileCreatedWithInitialData } = await this.ensureFileWithInitialData(
9091
resultFilePath,
9192
JSON.stringify(initialData, null, 2)
9293
);
@@ -143,7 +144,7 @@ export class DiskBasedResultStorage implements AccuracyResultStorage {
143144
}
144145
}
145146

146-
private async ensureAccuracyResultFile(
147+
private async ensureFileWithInitialData(
147148
filePath: string,
148149
initialData: string
149150
): Promise<{

tests/accuracy/sdk/describe-accuracy-tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, beforeAll, beforeEach, afterAll } from "vitest";
12
import { TestableModels } from "./models.js";
23
import { calculateToolCallingAccuracy } from "./accuracy-scorer.js";
34
import { getVercelToolCallingAgent, VercelAgent } from "./agent.js";

tests/unit/accuracy-scorer.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it } from "vitest";
12
import { calculateToolCallingAccuracy } from "../accuracy/sdk/accuracy-scorer.js";
23
import { ExpectedToolCall, LLMToolCall } from "../accuracy/sdk/accuracy-result-storage/result-storage.js";
34

vitest.config.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11
import { defineConfig } from "vitest/config";
22

3+
// Shared exclusions for all projects
4+
// Ref: https://vitest.dev/config/#exclude
5+
const vitestDefaultExcludes = [
6+
"**/node_modules/**",
7+
"**/dist/**",
8+
"**/cypress/**",
9+
"**/.{idea,git,cache,output,temp}/**",
10+
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*",
11+
];
12+
313
export default defineConfig({
414
test: {
515
environment: "node",
616
testTimeout: 3600000,
717
hookTimeout: 3600000,
8-
include: ["**/*.test.ts"],
918
setupFiles: ["./tests/setup.ts"],
1019
coverage: {
1120
exclude: ["node_modules", "tests", "dist"],
1221
reporter: ["lcov"],
1322
},
23+
projects: [
24+
{
25+
test: {
26+
name: "unit-and-integration",
27+
include: ["**/*.test.ts"],
28+
exclude: [...vitestDefaultExcludes, "tests/accuracy/**"],
29+
},
30+
},
31+
{
32+
test: {
33+
name: "accuracy",
34+
include: ["**/accuracy/*.test.ts"],
35+
},
36+
},
37+
],
1438
},
1539
});

0 commit comments

Comments
 (0)