Skip to content

use builtin vitest file snapshots for OpenAPI json file#1801

Merged
dimaMachina merged 6 commits intomainfrom
use-builtin-vitest-snapshots-for-openapi
Feb 7, 2026
Merged

use builtin vitest file snapshots for OpenAPI json file#1801
dimaMachina merged 6 commits intomainfrom
use-builtin-vitest-snapshots-for-openapi

Conversation

@dimaMachina
Copy link
Collaborator

@dimaMachina dimaMachina commented Feb 7, 2026

image

@changeset-bot
Copy link

changeset-bot bot commented Feb 7, 2026

⚠️ No Changeset found

Latest commit: 3f90837

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Feb 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agents-api Ready Ready Preview, Comment Feb 7, 2026 7:35pm
agents-manage-ui Ready Ready Preview, Comment Feb 7, 2026 7:35pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
agents-docs Skipped Skipped Feb 7, 2026 7:35pm

Request Review

poolOptions: {
threads: {
maxThreads: 10, // Increase for GitHub Actions runners (have more cores)
minThreads: 4,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this option was removed in vitest 4

@dimaMachina
Copy link
Collaborator Author

@claude verify and wdyt

@inkeep
Copy link
Contributor

inkeep bot commented Feb 7, 2026

No docs changes detected - this PR updates internal testing infrastructure (vitest upgrade and snapshot testing refactor) with no user-facing changes.

Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.threadsmaxWorkers).

🟠⚠️ 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:15
  • src/domains/run/agents/relationTools.ts:19
  • src/domains/manage/routes/projects.ts:29
  • src/domains/manage/routes/projectFull.ts:27
  • src/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:

  1. Update all remaining src/ imports to relative paths for consistency, OR
  2. 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 desired

Refs: 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:4 Type safety: parameter uses any while return type uses unknown

💡 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
function sortObjectKeys(obj: any): unknown {
function sortObjectKeys(obj: unknown): unknown {

@github-actions github-actions bot deleted a comment from claude bot Feb 7, 2026
Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:127 Missing server URL normalization
  • 🟠 vitest.integration.config.ts:28-33 Deprecated poolOptions.threads config

🕐 Pending Recommendations (2)

From review threads:

From previous reviews:


🚫 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`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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`;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

@github-actions github-actions bot deleted a comment from claude bot Feb 7, 2026
@vercel vercel bot temporarily deployed to Preview – agents-docs February 7, 2026 19:33 Inactive
@dimaMachina dimaMachina changed the title update vitest in agents-api and use builtin vitest file snapshots for OpenAPI json file use builtin vitest file snapshots for OpenAPI json file Feb 7, 2026
Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:127 Missing server URL normalization

🕐 Pending Recommendations (1)

From previous review threads:

  • 🟡 openapi.test.ts:4 Type safety: obj parameter still uses any instead of unknown

💭 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`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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
Suggested change
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`;

@github-actions github-actions bot deleted a comment from claude bot Feb 7, 2026
} from 'ai';
import manageDbPool from 'src/data/db/manageDbPool';
import { env } from 'src/env';
import manageDbPool from '../../../data/db/manageDbPool';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dimaMachina Why are we using relative references instead of path alias?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@dimaMachina dimaMachina merged commit bcb3013 into main Feb 7, 2026
17 checks passed
@dimaMachina dimaMachina deleted the use-builtin-vitest-snapshots-for-openapi branch February 7, 2026 23:33
robert-inkeep added a commit that referenced this pull request Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants