Skip to content

Commit c0338c2

Browse files
committed
chore(dependencies): upgrade vitest and coverage packages
- Updated `@vitest/coverage-v8` and `vitest` to version `4.1.7` in multiple package.json files. - Refactored AI filter response schema in `aiRunFilterService.server.ts` to comply with OpenAI's JSON structure requirements. - Removed unused pool options from vitest configuration files across several internal packages.
1 parent ea7de16 commit c0338c2

15 files changed

Lines changed: 69 additions & 76 deletions

File tree

apps/webapp/app/v3/services/aiRunFilterService.server.ts

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,25 @@ const AIFilters = TaskRunListSearchFilters.omit({
1414
to: z.string().optional().describe("The ISO datetime to filter to"),
1515
});
1616

17+
// The response is wrapped in an object with a single `response` field because
18+
// OpenAI structured outputs (both the Chat and Responses APIs) require the root
19+
// JSON Schema to be `type: "object"`. A bare `z.discriminatedUnion` compiles to
20+
// a root-level `anyOf`, which OpenAI rejects ("schema must be of type object").
21+
// Nesting the union under a property keeps the discriminated-union ergonomics
22+
// while satisfying the root-object constraint.
1723
const AIFilterResponseSchema = z
18-
.discriminatedUnion("success", [
19-
z.object({
20-
success: z.literal(true),
21-
filters: AIFilters,
22-
}),
23-
z.object({
24-
success: z.literal(false),
25-
error: z.string().describe("A short human-readable error message"),
26-
}),
27-
])
24+
.object({
25+
response: z.discriminatedUnion("success", [
26+
z.object({
27+
success: z.literal(true),
28+
filters: AIFilters,
29+
}),
30+
z.object({
31+
success: z.literal(false),
32+
error: z.string().describe("A short human-readable error message"),
33+
}),
34+
]),
35+
})
2836
.describe("The response from the AI filter service");
2937

3038
export interface QueryQueues {
@@ -88,6 +96,16 @@ export class AIRunFilterService {
8896
const result = await generateText({
8997
model: this.model,
9098
experimental_output: Output.object({ schema: AIFilterResponseSchema }),
99+
// Disable OpenAI strict JSON-schema mode. The filters schema has many
100+
// optional fields, and strict mode requires every property to appear in
101+
// `required` (it rejects bare optionals). Non-strict mode treats the
102+
// schema as guidance; the `AIFilters.safeParse` below still validates
103+
// the result, so correctness is preserved.
104+
providerOptions: {
105+
openai: {
106+
strictJsonSchema: false,
107+
},
108+
},
91109
tools: {
92110
lookupTags: tool({
93111
description: "Look up available tags in the environment",
@@ -198,21 +216,24 @@ export class AIRunFilterService {
198216
199217
The filters object should only contain the fields that are actually being filtered. Do not include fields with empty arrays or undefined values.
200218
201-
CRITICAL: The response must be a valid JSON object with exactly this structure:
219+
CRITICAL: The response must be a valid JSON object with a single top-level "response" key wrapping this structure:
202220
{
203-
"success": true,
204-
"filters": {
205-
// only include fields that have actual values
206-
},
207-
"explanation": "string explaining what filters were applied"
221+
"response": {
222+
"success": true,
223+
"filters": {
224+
// only include fields that have actual values
225+
}
226+
}
208227
}
209-
228+
210229
or if you can't figure out the filters then return:
211230
{
212-
"success": false,
213-
"error": "<short human understandable suggestion>"
231+
"response": {
232+
"success": false,
233+
"error": "<short human understandable suggestion>"
234+
}
214235
}
215-
236+
216237
Make the error no more than 8 words.
217238
`,
218239
prompt: text,
@@ -224,19 +245,21 @@ export class AIRunFilterService {
224245
},
225246
});
226247

227-
if (!result.experimental_output.success) {
248+
const output = result.experimental_output.response;
249+
250+
if (!output.success) {
228251
return {
229252
success: false,
230-
error: result.experimental_output.error,
253+
error: output.error,
231254
};
232255
}
233256

234257
// Validate the filters against the schema to catch any issues
235-
const validationResult = AIFilters.safeParse(result.experimental_output.filters);
258+
const validationResult = AIFilters.safeParse(output.filters);
236259
if (!validationResult.success) {
237260
logger.error("AI filter validation failed", {
238261
errors: validationResult.error.errors,
239-
filters: result.experimental_output.filters,
262+
filters: output.filters,
240263
});
241264

242265
return {

internal-packages/clickhouse/vitest.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ export default defineConfig({
66
globals: true,
77
isolate: true,
88
fileParallelism: false,
9-
poolOptions: {
10-
threads: {
11-
singleThread: true,
12-
},
13-
},
149
testTimeout: 60_000,
1510
coverage: {
1611
provider: "v8",

internal-packages/llm-model-catalog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"devDependencies": {
1313
"@internal/testcontainers": "workspace:*",
14-
"vitest": "3.1.4"
14+
"vitest": "4.1.7"
1515
},
1616
"scripts": {
1717
"test": "vitest --sequence.concurrent=false --no-file-parallelism",

internal-packages/llm-model-catalog/vitest.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ export default defineConfig({
66
globals: true,
77
isolate: true,
88
fileParallelism: false,
9-
poolOptions: {
10-
threads: {
11-
singleThread: true,
12-
},
13-
},
149
testTimeout: 120_000,
1510
},
1611
});

internal-packages/replication/vitest.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ export default defineConfig({
66
globals: true,
77
isolate: true,
88
fileParallelism: false,
9-
poolOptions: {
10-
threads: {
11-
singleThread: true,
12-
},
13-
},
149
testTimeout: 60_000,
1510
coverage: {
1611
provider: "v8",

internal-packages/run-engine/src/engine/tests/utils/engineTest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TaskContext, test, TestAPI } from "vitest";
1+
import { TestContext, test, TestAPI } from "vitest";
22
import {
33
logCleanup,
44
network,
@@ -36,7 +36,7 @@ type EngineOptions = {
3636
};
3737
};
3838

39-
const engineOptions = async ({}: TaskContext, use: Use<EngineOptions>) => {
39+
const engineOptions = async ({}: TestContext, use: Use<EngineOptions>) => {
4040
const options: EngineOptions = {
4141
worker: {
4242
workers: 1,
@@ -74,7 +74,7 @@ const engine = async (
7474
engineOptions: EngineOptions;
7575
redisOptions: RedisOptions;
7676
prisma: PrismaClient;
77-
} & TaskContext,
77+
} & TestContext,
7878
use: Use<RunEngine>
7979
) => {
8080
const engine = new RunEngine({

internal-packages/run-engine/vitest.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ export default defineConfig({
66
globals: true,
77
isolate: true,
88
fileParallelism: false,
9-
poolOptions: {
10-
threads: {
11-
singleThread: true,
12-
},
13-
},
149
testTimeout: 120_000,
1510
coverage: {
1611
provider: "v8",

internal-packages/sdk-compat-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"esbuild": "^0.24.0",
1616
"execa": "^9.3.0",
1717
"typescript": "^5.5.0",
18-
"vitest": "3.1.4"
18+
"vitest": "4.1.7"
1919
}
2020
}

internal-packages/testcontainers/src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { StartedRedisContainer } from "@testcontainers/redis";
33
import { PrismaClient } from "@trigger.dev/database";
44
import { RedisOptions } from "ioredis";
55
import { Network, type StartedNetwork } from "testcontainers";
6-
import { TaskContext, test } from "vitest";
6+
import { TestContext, test } from "vitest";
77
import {
88
createClickHouseContainer,
99
createElectricContainer,
@@ -58,7 +58,7 @@ export type {
5858

5959
type Use<T> = (value: T) => Promise<void>;
6060

61-
export const network = async ({ task }: TaskContext, use: Use<StartedNetwork>) => {
61+
export const network = async ({ task }: TestContext, use: Use<StartedNetwork>) => {
6262
const testName = task.name;
6363

6464
logSetup("network: starting", { testName });
@@ -85,7 +85,7 @@ export const network = async ({ task }: TaskContext, use: Use<StartedNetwork>) =
8585
};
8686

8787
export const postgresContainer = async (
88-
{ network, task }: { network: StartedNetwork } & TaskContext,
88+
{ network, task }: { network: StartedNetwork } & TestContext,
8989
use: Use<StartedPostgreSqlContainer>
9090
) => {
9191
const { container, metadata } = await withContainerSetup({
@@ -98,7 +98,7 @@ export const postgresContainer = async (
9898
};
9999

100100
export const prisma = async (
101-
{ postgresContainer, task }: { postgresContainer: StartedPostgreSqlContainer } & TaskContext,
101+
{ postgresContainer, task }: { postgresContainer: StartedPostgreSqlContainer } & TestContext,
102102
use: Use<PrismaClient>
103103
) => {
104104
const testName = task.name;
@@ -123,7 +123,7 @@ export const prisma = async (
123123
export const postgresTest = test.extend<PostgresContext>({ network, postgresContainer, prisma });
124124

125125
export const redisContainer = async (
126-
{ network, task }: { network: StartedNetwork } & TaskContext,
126+
{ network, task }: { network: StartedNetwork } & TestContext,
127127
use: Use<StartedRedisContainer>
128128
) => {
129129
const { container, metadata } = await withContainerSetup({
@@ -180,7 +180,7 @@ const electricOrigin = async (
180180
postgresContainer,
181181
network,
182182
task,
183-
}: { postgresContainer: StartedPostgreSqlContainer; network: StartedNetwork } & TaskContext,
183+
}: { postgresContainer: StartedPostgreSqlContainer; network: StartedNetwork } & TestContext,
184184
use: Use<string>
185185
) => {
186186
const { origin, container, metadata } = await withContainerSetup({
@@ -193,7 +193,7 @@ const electricOrigin = async (
193193
};
194194

195195
const clickhouseContainer = async (
196-
{ network, task }: { network: StartedNetwork } & TaskContext,
196+
{ network, task }: { network: StartedNetwork } & TestContext,
197197
use: Use<StartedClickHouseContainer>
198198
) => {
199199
const { container, metadata } = await withContainerSetup({
@@ -206,7 +206,7 @@ const clickhouseContainer = async (
206206
};
207207

208208
const clickhouseClient = async (
209-
{ clickhouseContainer, task }: { clickhouseContainer: StartedClickHouseContainer } & TaskContext,
209+
{ clickhouseContainer, task }: { clickhouseContainer: StartedClickHouseContainer } & TestContext,
210210
use: Use<ClickHouseClient>
211211
) => {
212212
const testName = task.name;
@@ -268,7 +268,7 @@ export const containerWithElectricAndRedisTest = test.extend<ContainerWithElectr
268268
});
269269

270270
const minioContainer = async (
271-
{ network, task }: { network: StartedNetwork } & TaskContext,
271+
{ network, task }: { network: StartedNetwork } & TestContext,
272272
use: Use<StartedMinIOContainer>
273273
) => {
274274
const { container, metadata } = await withContainerSetup({

internal-packages/testcontainers/src/logs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { env, isCI } from "std-env";
2-
import { TaskContext } from "vitest";
2+
import { TestContext } from "vitest";
33
import { DockerDiagnostics, getDockerDiagnostics } from "./docker";
44
import { StartedTestContainer } from "testcontainers";
55

@@ -31,7 +31,7 @@ export function getContainerMetadata(container: StartedTestContainer) {
3131
};
3232
}
3333

34-
export function getTaskMetadata(task: TaskContext["task"]) {
34+
export function getTaskMetadata(task: TestContext["task"]) {
3535
return {
3636
testName: task.name,
3737
};

0 commit comments

Comments
 (0)