use builtin vitest file snapshots for OpenAPI json file#1801
use builtin vitest file snapshots for OpenAPI json file#1801dimaMachina merged 6 commits intomainfrom
Conversation
… OpenAPI json file
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
| poolOptions: { | ||
| threads: { | ||
| maxThreads: 10, // Increase for GitHub Actions runners (have more cores) | ||
| minThreads: 4, |
There was a problem hiding this comment.
looks like this option was removed in vitest 4
|
@claude verify and wdyt |
|
No docs changes detected - this PR updates internal testing infrastructure (vitest upgrade and snapshot testing refactor) with no user-facing changes. |
There was a problem hiding this comment.
PR Review Summary
2 Key Findings | Risk: Low
This PR cleanly upgrades vitest from v3.2.4 to v4.0.18 in agents-api and replaces ~230 lines of custom OpenAPI snapshot logic with vitest's built-in toMatchFileSnapshot(). The migration is well-executed with proper breaking change handling (poolOptions.threads → maxWorkers).
🟠⚠️ Major (1) 🟠⚠️
🟠 1) agents-api/src/domains/evals/workflow/functions/*.ts, agents-api/src/domains/run/agents/Agent.ts, agents-api/src/middleware/ref.ts Incomplete import path migration
Issue: This PR changes 4 files from src/... absolute imports to relative imports, but 5 other files in agents-api still use src/ imports:
src/domains/run/agents/generateTaskHandler.ts:15src/domains/run/agents/relationTools.ts:19src/domains/manage/routes/projects.ts:29src/domains/manage/routes/projectFull.ts:27src/domains/manage/routes/evals/datasetRunConfigs.ts:27
Why: This creates inconsistency. If vitest v4 broke src/ imports (requiring the changes in this PR), the remaining files will also break when they're touched or when tests exercise those code paths. If src/ imports still work, then the changes in this PR may be unnecessary churn.
Fix: Either:
- Update all remaining
src/imports to relative paths for consistency, OR - Revert these import changes if they weren't actually necessary for vitest v4
Refs: evaluateConversation.ts:11-12 · generateTaskHandler.ts:15
🟡 Minor (1) 🟡
🟡 1) agents-api/vitest.config.ts:21 Lost minThreads configuration
Issue: The old config specified both maxThreads: 10 and minThreads: 4. The new config only specifies maxWorkers: 10, dropping the minimum thread guarantee.
Why: This may cause slower test startup in CI environments where vitest might spin up fewer workers initially.
Fix: Vitest v4 uses minWorkers for minimum:
maxWorkers: 10,
minWorkers: 4, // Add this if minimum thread guarantee is desiredRefs: vitest.config.ts:21
💭 Consider (3) 💭
💭 1) agents-api/src/__tests__/openapi.test.ts:127 Server normalization was removed
Issue + Why: The old implementation normalized servers to [{ url: 'http://localhost:3002', description: 'API Server' }] before comparison. The new implementation snapshots cachedSpec directly. While the current snapshot already has this value hardcoded, if the OpenAPI generator ever produces different server URLs based on environment, this could cause flaky tests.
Suggestion: Monitor for flakiness; restore normalization if needed.
💭 2) agents-api/src/__tests__/openapi.test.ts:4-12 sortObjectKeys lacks test coverage
Issue + Why: This utility is critical for consistent snapshot comparisons but has no unit tests verifying edge cases (nested objects, arrays, null values).
Suggestion: Consider adding basic unit tests for the utility function.
💭 3) pnpm-lock.yaml Monorepo vitest version inconsistency
Issue + Why: After this PR, the monorepo will have 3 vitest versions: v3.2.4 (most packages), v4.0.18 (agents-api), and v4.1.0-beta.3 (agents-manage-ui). This creates maintenance overhead but is technically safe since vitest is a devDependency.
Suggestion: Consider aligning versions across the monorepo in a future PR.
📌 Inline Comments (1)
- 🟡
openapi.test.ts:4Type safety: parameter usesanywhile return type usesunknown
💡 APPROVE WITH SUGGESTIONS
Summary: This is a solid cleanup PR that significantly reduces code complexity by leveraging vitest's built-in file snapshot functionality. The core changes are well-executed. The main consideration is whether to complete the import path migration for consistency — either fix all src/ imports or revert the changes if they weren't necessary. The lost minWorkers config is minor but worth noting.
Discarded (4)
| Location | Issue | Reason Discarded |
|---|---|---|
openapi.test.ts:129 |
Custom error message may be less informative than old detailed diff | vitest's built-in diff is generally sufficient; custom message still provides update instructions |
openapi.test.ts |
No test for toMatchFileSnapshot() failure behavior |
Testing vitest's own functionality is out of scope; the feature is well-documented |
package.json |
No changeset for vitest upgrade | Correct — vitest is a devDependency and doesn't affect published package |
openapi.test.ts |
Snapshot update workflow not tested | This is a documented vitest feature; manual verification is appropriate |
Reviewer Stats
| Reviewer | Returned | Inline Comments | Main Findings | Pending Recs | Discarded |
|---|---|---|---|---|---|
pr-review-standards |
3 | 0 | 2 | 0 | 1 |
pr-review-tests |
4 | 1 | 1 | 0 | 2 |
pr-review-devops |
4 | 0 | 0 | 0 | 4 |
| Total | 11 | 1 | 3 | 0 | 7 |
| import { makeRequest } from './utils/testRequest'; | ||
|
|
||
| function sortObjectKeys(obj: any): any { | ||
| function sortObjectKeys(obj: any): unknown { |
There was a problem hiding this comment.
MINOR Type safety: obj parameter still uses any
The return type was improved from any to unknown, but the parameter still accepts any. For full type safety, consider using unknown for the parameter as well.
| function sortObjectKeys(obj: any): unknown { | |
| function sortObjectKeys(obj: unknown): unknown { |
There was a problem hiding this comment.
PR Review Summary
2 Key Findings | Risk: Medium
This PR upgrades vitest from v3.2.4 to v4.0.18 and replaces ~230 lines of custom OpenAPI snapshot logic with vitest's built-in toMatchFileSnapshot(). The core migration is well-executed, but there are two issues to address before merging.
🔴❗ Critical (1) ❗🔴
🔴 1) agents-api/src/__tests__/openapi.test.ts:127 Server URL normalization removed — creates environment-dependent test
Issue: The old implementation normalized the servers field to [{ url: 'http://localhost:3002', description: 'API Server' }] before snapshot comparison (see removed code at lines 133-135). The new implementation snapshots cachedSpec directly without normalization.
Why: The server URL is dynamically resolved based on VERCEL_ENV, VERCEL_URL, and VERCEL_PROJECT_PRODUCTION_URL in openapi.ts:47-52. Without normalization:
- Test passes locally (no Vercel env vars)
- Test fails in Vercel preview/production deployments with false positive
- Developer may incorrectly update the snapshot, polluting it for other environments
This defeats the purpose of the test — catching API structure changes, not environment configuration differences.
Fix: Restore server URL normalization:
const normalizedSpec = sortObjectKeys({
...cachedSpec,
servers: [{ url: 'http://localhost:3002', description: 'API Server' }],
});
const openApiJsonSnapshot = `${JSON.stringify(normalizedSpec, null, 2)}\n`;Refs: openapi.test.ts:127 · openapi.ts:47-52
🟠⚠️ Major (1) 🟠⚠️
🟠 1) agents-api/vitest.integration.config.ts:28-33 Vitest v4 migration incomplete — integration config uses deprecated options
Issue: The integration test config still uses poolOptions.threads.maxThreads/minThreads, which was deprecated and removed in vitest v4. Since agents-api/package.json now specifies vitest ^4.0.18, this configuration will emit deprecation warnings or potentially break.
Why: Creates an inconsistent state where vitest.config.ts uses the new maxWorkers pattern while vitest.integration.config.ts uses the deprecated pattern.
Fix: Update to use maxWorkers: 1 (same pattern as main config).
Refs: vitest.integration.config.ts:28-33
💭 Consider (2) 💭
💭 1) agents-api/src/domains/**/*.ts Incomplete import path migration creates inconsistency
Issue + Why: This PR changes 4 files from src/ absolute imports to relative imports, but 5 other files still use src/ imports. While both patterns work (thanks to vite-tsconfig-paths), this creates stylistic inconsistency.
Suggestion: Either update all remaining src/ imports for consistency, or revert these changes if they weren't necessary for vitest v4.
💭 2) pnpm-lock.yaml Monorepo vitest version inconsistency
Issue + Why: After this PR, the monorepo will have vitest at 3 versions: v3.2.4 (most packages), v4.0.18 (agents-api), v4.1.0-beta.3 (agents-manage-ui). Safe but adds maintenance overhead.
Suggestion: Consider aligning versions across the monorepo in a future PR.
📌 Inline Comments (2)
- 🔴
openapi.test.ts:127Missing server URL normalization - 🟠
vitest.integration.config.ts:28-33Deprecated poolOptions.threads config
🕐 Pending Recommendations (2)
From review threads:
- 🟡
openapi.test.ts:4Type safety:objparameter still usesany
From previous reviews:
- 🟡
vitest.config.ts:21LostminThreadsconfiguration (nowminWorkers)
🚫 REQUEST CHANGES
Summary: This is a solid cleanup PR that significantly reduces code complexity. However, the removed server URL normalization will cause environment-dependent test failures in CI/CD and preview deployments. Additionally, the integration config needs to be updated for vitest v4 consistency. Both issues have 1-click suggestions in the inline comments.
Discarded (3)
| Location | Issue | Reason Discarded |
|---|---|---|
openapi.test.ts |
sortObjectKeys lacks unit tests |
Internal utility, adequately tested through integration usage |
package.json |
No changeset needed | Correct — vitest is a devDependency, no user-facing impact |
openapi.test.ts |
Custom diff output was more informative | vitest's built-in diff is sufficient; the trade-off (66 fewer lines) is worth it |
Reviewer Stats
| Reviewer | Returned | Inline Comments | Main Findings | Pending Recs | Discarded |
|---|---|---|---|---|---|
pr-review-tests |
1 | 1 | 1 | 0 | 0 |
pr-review-devops |
2 | 1 | 0 | 0 | 1 |
pr-review-standards |
0 | 0 | 0 | 0 | 0 |
pr-review-consistency |
0 | 0 | 0 | 2 | 0 |
| Prior review | N/A | 0 | 0 | 2 | 2 |
| Total | 3 | 2 | 1 | 2 | 3 |
|
|
||
| throw new Error(lines.join('\n')); | ||
| } | ||
| const openApiJsonSnapshot = `${JSON.stringify(sortObjectKeys(cachedSpec), null, 2)}\n`; |
There was a problem hiding this comment.
CRITICAL Missing server URL normalization — environment-dependent test
The old implementation normalized servers to a hardcoded value before snapshot comparison (see removed code at line 133-135). Without normalization, this test will fail with false positives when VERCEL_ENV, VERCEL_URL, or VERCEL_PROJECT_PRODUCTION_URL are set (e.g., in CI/CD, preview deployments, or developer environments).
The server URL is dynamically resolved in openapi.ts:47-52.
| const openApiJsonSnapshot = `${JSON.stringify(sortObjectKeys(cachedSpec), null, 2)}\n`; | |
| const normalizedSpec = sortObjectKeys({ | |
| ...cachedSpec, | |
| servers: [{ url: 'http://localhost:3002', description: 'API Server' }], | |
| }); | |
| const openApiJsonSnapshot = `${JSON.stringify(normalizedSpec, null, 2)}\n`; |
There was a problem hiding this comment.
@dimaMachina Did you consider this feedback? I remember building in the normalization when I first built the snapshot test. Is it not required anymore with vitest or something?
agents-api and use builtin vitest file snapshots for OpenAPI json fileThere was a problem hiding this comment.
PR Review Summary
1 Key Finding | Risk: Medium
Good news: The latest commit (3f90837a) rolled back vitest to v3.2.4, which resolves the vitest v4 config compatibility concerns from prior reviews. The PR now focuses purely on replacing ~230 lines of custom OpenAPI snapshot logic with vitest's built-in toMatchFileSnapshot().
However, one critical issue remains unaddressed from the previous review.
🔴❗ Critical (1) ❗🔴
🔴 1) openapi.test.ts:127 Server URL normalization removed — creates environment-dependent test
Issue: The old implementation normalized servers to [{ url: 'http://localhost:3002', description: 'API Server' }] before snapshot comparison. The new implementation snapshots cachedSpec directly without normalization.
Why: The server URL is dynamically resolved in openapi.ts:47-52 based on VERCEL_ENV:
- Production →
https://${VERCEL_PROJECT_PRODUCTION_URL} - Preview →
https://${VERCEL_URL} - Local/Test →
http://localhost:3002
Without normalization:
- ✅ Test passes locally (no Vercel env vars)
- ❌ Test fails in Vercel preview/production with false positive
- ❌ Developer may incorrectly update snapshot, polluting it for other environments
Fix: Restore server URL normalization (see inline comment with 1-click suggestion).
📌 Inline Comments (1)
- 🔴
openapi.test.ts:127Missing server URL normalization
🕐 Pending Recommendations (1)
From previous review threads:
- 🟡
openapi.test.ts:4Type safety:objparameter still usesanyinstead ofunknown
💭 Note on Previous Issues
The vitest v4 compatibility issues (deprecated poolOptions.threads, minWorkers config) from my previous review are no longer applicable since vitest was rolled back to v3.2.4. Those findings are now discarded.
🚫 REQUEST CHANGES
Summary: The refactoring to use vitest's built-in file snapshot is clean and eliminates ~230 lines of custom code. However, the server URL normalization must be restored to prevent environment-dependent test failures. The inline comment provides a 1-click fix.
Discarded (3)
| Location | Issue | Reason Discarded |
|---|---|---|
vitest.config.ts |
Deprecated poolOptions.threads option |
Vitest rolled back to v3.2.4 — no longer deprecated |
vitest.integration.config.ts |
Deprecated poolOptions.threads option |
Vitest rolled back to v3.2.4 — no longer deprecated |
vitest.config.ts |
Lost minThreads configuration |
Vitest rolled back to v3.2.4 — original config preserved |
Reviewer Stats
| Reviewer | Returned | Inline Comments | Main Findings | Pending Recs | Discarded |
|---|---|---|---|---|---|
| Prior review carryover | 1 | 1 | 1 | 1 | 3 |
| Total | 1 | 1 | 1 | 1 | 3 |
|
|
||
| throw new Error(lines.join('\n')); | ||
| } | ||
| const openApiJsonSnapshot = `${JSON.stringify(sortObjectKeys(cachedSpec), null, 2)}\n`; |
There was a problem hiding this comment.
🔴 CRITICAL Missing server URL normalization — environment-dependent test
The old implementation normalized servers to a hardcoded value before snapshot comparison. Without normalization, this test will fail with false positives when VERCEL_ENV, VERCEL_URL, or VERCEL_PROJECT_PRODUCTION_URL are set (e.g., in CI/CD, preview deployments).
The server URL is dynamically resolved in openapi.ts:47-52:
- Production:
https://${VERCEL_PROJECT_PRODUCTION_URL} - Preview:
https://${VERCEL_URL} - Local:
http://localhost:3002
| const openApiJsonSnapshot = `${JSON.stringify(sortObjectKeys(cachedSpec), null, 2)}\n`; | |
| const normalizedSpec = sortObjectKeys({ | |
| ...cachedSpec, | |
| servers: [{ url: 'http://localhost:3002', description: 'API Server' }], | |
| }); | |
| const openApiJsonSnapshot = `${JSON.stringify(normalizedSpec, null, 2)}\n`; |
| } from 'ai'; | ||
| import manageDbPool from 'src/data/db/manageDbPool'; | ||
| import { env } from 'src/env'; | ||
| import manageDbPool from '../../../data/db/manageDbPool'; |
There was a problem hiding this comment.
@dimaMachina Why are we using relative references instead of path alias?
There was a problem hiding this comment.
we don't use path aliases in this package, it was silently working with tsdown I guess, I updated vitest to v4 and it complained about these paths, but I did rollback of vitest v4 due some typecheck problems
This reverts commit bcb3013.
Uh oh!
There was an error while loading. Please reload this page.