Skip to content

Commit 356512b

Browse files
committed
fix tests
1 parent 49bfac4 commit 356512b

File tree

10 files changed

+27
-29
lines changed

10 files changed

+27
-29
lines changed

tests/accuracy/aggregate.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ describeAccuracyTests([
1313
pipeline: [
1414
{ $group: { _id: "$release_year", count: { $sum: 1 } } },
1515
// For the sake of accuracy, we allow any sort order
16-
Matcher.composite(
16+
Matcher.anyOf(
1717
Matcher.undefined,
18-
Matcher.unknown({
18+
Matcher.value({
1919
$sort: Matcher.anyValue,
2020
})
2121
),

tests/accuracy/createIndex.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describeAccuracyTests([
1010
parameters: {
1111
database: "mflix",
1212
collection: "movies",
13-
name: Matcher.composite(Matcher.undefined, Matcher.string()),
13+
name: Matcher.anyOf(Matcher.undefined, Matcher.string()),
1414
keys: {
1515
release_year: 1,
1616
},
@@ -26,7 +26,7 @@ describeAccuracyTests([
2626
parameters: {
2727
database: "mflix",
2828
collection: "movies",
29-
name: Matcher.composite(Matcher.undefined, Matcher.string()),
29+
name: Matcher.anyOf(Matcher.undefined, Matcher.string()),
3030
keys: {
3131
title: "text",
3232
},

tests/accuracy/find.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describeAccuracyTests([
6868
collection: "movies",
6969
projection: {
7070
title: 1,
71-
_id: Matcher.composite(
71+
_id: Matcher.anyOf(
7272
Matcher.undefined,
7373
Matcher.number((value) => value === 0)
7474
),
@@ -89,7 +89,7 @@ describeAccuracyTests([
8989
filter: { title: "Certain Fish" },
9090
projection: {
9191
cast: 1,
92-
_id: Matcher.composite(Matcher.undefined, Matcher.number()),
92+
_id: Matcher.anyOf(Matcher.undefined, Matcher.number()),
9393
},
9494
limit: Matcher.number((value) => value > 0),
9595
},

tests/accuracy/insertMany.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
2+
import { Matcher } from "./sdk/matcher.js";
23

34
describeAccuracyTests([
45
{
@@ -16,15 +17,15 @@ describeAccuracyTests([
1617
documents: [
1718
{
1819
id: 1,
19-
title: "name1",
20+
name: "name1",
2021
},
2122
{
2223
id: 2,
23-
title: "name2",
24+
name: "name2",
2425
},
2526
{
2627
id: 3,
27-
title: "name3",
28+
name: "name3",
2829
},
2930
],
3031
},
@@ -39,7 +40,7 @@ describeAccuracyTests([
3940
parameters: {
4041
database: "mflix",
4142
collection: "movies",
42-
documents: [{}, {}, {}],
43+
documents: [{ _id: Matcher.anyValue }, { _id: Matcher.anyValue }, { _id: Matcher.anyValue }],
4344
},
4445
},
4546
],

tests/accuracy/logs.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
2+
import { Matcher } from "./sdk/matcher.js";
23

34
describeAccuracyTests([
45
{
@@ -18,7 +19,7 @@ describeAccuracyTests([
1819
{
1920
toolName: "mongodb-logs",
2021
parameters: {
21-
type: "global",
22+
type: Matcher.anyOf(Matcher.undefined, Matcher.value("global")),
2223
limit: 10,
2324
},
2425
},

tests/accuracy/sdk/accuracyScorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function calculateToolCallingAccuracy(
7575
.map(({ call, index }) => ({
7676
call,
7777
index,
78-
score: Matcher.unknown(expectedCall.parameters).match(call.parameters),
78+
score: Matcher.value(expectedCall.parameters).match(call.parameters),
7979
}))
8080
.filter(({ score }) => score >= 0.75)
8181
.sort((a, b) => b.score - a.score || a.index - b.index);

tests/accuracy/sdk/matcher.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export abstract class Matcher {
1616
return new NumberMatcher(additionalFilter);
1717
}
1818

19-
public static composite(...matchers: Matcher[]): Matcher {
19+
public static anyOf(...matchers: Matcher[]): Matcher {
2020
return new CompositeMatcher(matchers);
2121
}
2222

@@ -32,12 +32,12 @@ export abstract class Matcher {
3232
return new StringMatcher();
3333
}
3434

35-
public static unknown(expected: unknown): Matcher {
35+
public static value(expected: unknown): Matcher {
3636
if (typeof expected === "object" && expected !== null && MATCHER_SYMBOL in expected) {
3737
return expected as Matcher;
3838
}
3939

40-
return new UnknownMatcher(expected);
40+
return new ValueMatcher(expected);
4141
}
4242
}
4343

@@ -114,7 +114,7 @@ class StringMatcher extends Matcher {
114114
}
115115
}
116116

117-
class UnknownMatcher extends Matcher {
117+
class ValueMatcher extends Matcher {
118118
constructor(private expected: unknown) {
119119
super();
120120
}
@@ -145,7 +145,7 @@ class UnknownMatcher extends Matcher {
145145
}
146146

147147
for (let i = 0; i < this.expected.length; i++) {
148-
currentScore = Math.min(currentScore, Matcher.unknown(this.expected[i]).match(actual[i]));
148+
currentScore = Math.min(currentScore, Matcher.value(this.expected[i]).match(actual[i]));
149149
if (currentScore === 0) {
150150
// If we already found a mismatch, we can stop early
151151
return 0;
@@ -174,7 +174,7 @@ class UnknownMatcher extends Matcher {
174174
for (const key of expectedKeys) {
175175
currentScore = Math.min(
176176
currentScore,
177-
Matcher.unknown((this.expected as Record<string, unknown>)[key]).match(
177+
Matcher.value((this.expected as Record<string, unknown>)[key]).match(
178178
(actual as Record<string, unknown>)[key]
179179
)
180180
);
@@ -184,6 +184,8 @@ class UnknownMatcher extends Matcher {
184184
return 0;
185185
}
186186
}
187+
} else {
188+
return 0;
187189
}
188190

189191
return currentScore;

tests/accuracy/updateMany.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describeAccuracyTests([
1515
new_field: 1,
1616
},
1717
},
18-
upsert: Matcher.composite(Matcher.undefined, Matcher.boolean()),
18+
upsert: Matcher.anyOf(Matcher.undefined, Matcher.boolean()),
1919
},
2020
},
2121
],
@@ -34,7 +34,7 @@ describeAccuracyTests([
3434
new_field: 1,
3535
},
3636
},
37-
upsert: Matcher.composite(Matcher.undefined, Matcher.boolean()),
37+
upsert: Matcher.anyOf(Matcher.undefined, Matcher.boolean()),
3838
},
3939
},
4040
],

tests/integration/tools/mongodb/read/find.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describeWithMongoDB("find tool", (integration) => {
3434
{
3535
name: "sort",
3636
description:
37-
"A document, describing the sort order, matching the syntax of the sort argument of cursor.sort()",
37+
"A document, describing the sort order, matching the syntax of the sort argument of cursor.sort(). The keys of the object are the fields to sort on, while the values are the sort directions (1 for ascending, -1 for descending).",
3838
type: "object",
3939
required: false,
4040
},

tests/unit/accuracyScorer.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,7 @@ describe("calculateToolCallingAccuracy", () => {
230230
parameters: {
231231
database: "mflix",
232232
collection: "movies",
233-
pipeline: [
234-
{ $match: { genre: "Horror" } },
235-
Matcher.composite(Matcher.undefined, Matcher.anyValue),
236-
],
233+
pipeline: [{ $match: { genre: "Horror" } }, Matcher.anyOf(Matcher.undefined, Matcher.anyValue)],
237234
},
238235
},
239236
];
@@ -261,10 +258,7 @@ describe("calculateToolCallingAccuracy", () => {
261258
parameters: {
262259
database: "mflix",
263260
collection: "movies",
264-
pipeline: [
265-
{ $match: { genre: "Horror" } },
266-
Matcher.composite(Matcher.undefined, Matcher.anyValue),
267-
],
261+
pipeline: [{ $match: { genre: "Horror" } }, Matcher.anyOf(Matcher.undefined, Matcher.anyValue)],
268262
},
269263
},
270264
];

0 commit comments

Comments
 (0)