Skip to content

Commit 8ca73b2

Browse files
committed
apply copilot suggestions
1 parent 1006e09 commit 8ca73b2

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

tests/accuracy/untrustedData.test.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1+
import path from "path";
12
import { AccuracyTestConfig, describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
23
import { Matcher } from "./sdk/matcher.js";
4+
import * as fs from "fs";
5+
6+
function getDocumentCounts(): Array<{ severity: number; tickets: number }> {
7+
const ticketsPath = path.resolve(__dirname, "test-data-dumps", "support.tickets.json");
8+
9+
const ticketsData = JSON.parse(fs.readFileSync(ticketsPath, "utf-8")) as { severity: number }[];
10+
11+
const counts: Record<number, number> = {};
12+
13+
for (const ticket of ticketsData) {
14+
counts[ticket.severity] = (counts[ticket.severity] || 0) + 1;
15+
}
16+
17+
return Object.entries(counts)
18+
19+
.map(([severity, tickets]) => ({ severity: Number(severity), tickets }));
20+
}
321

422
const describeAggregationWithUpdate = (): AccuracyTestConfig => {
523
// This test is validating the model can execute an aggregation and also access the data
624
// from the result and then use it to update another collection.
7-
const documentCounts = [
8-
{ severity: 1, tickets: 3 },
9-
{ severity: 2, tickets: 4 },
10-
{ severity: 3, tickets: 3 },
11-
];
25+
const documentCounts = getDocumentCounts();
1226

1327
return {
1428
prompt: "Create an aggregation that groups the support tickets from the 'support.tickets' namespace by their severity. Then for each group update the 'statistics' collection in the 'support' database and increase the count of tickets filed for that severity level. If there's no document corresponding to the severity level, you should create it. The final state should look something similar to { severity: 2, tickets: 5 }.",

tests/integration/tools/mongodb/mongodbHelpers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ export function prepareTestData(integration: MongoDBIntegrationTest): {
243243
}
244244

245245
export function getDocsFromUntrustedContent(content: string): unknown[] {
246-
const json = content.split("\n").slice(3, -3).join("\n");
246+
const lines = content.split("\n");
247+
const startIdx = lines.findIndex((line) => line.trim().startsWith("["));
248+
const endIdx = lines.length - 1 - [...lines].reverse().findIndex((line) => line.trim().endsWith("]"));
249+
if (startIdx === -1 || endIdx === -1 || endIdx < startIdx) {
250+
throw new Error("Could not find JSON array in content");
251+
}
252+
const json = lines.slice(startIdx, endIdx + 1).join("\n");
247253
return JSON.parse(json) as unknown[];
248254
}

0 commit comments

Comments
 (0)