Skip to content

test(api): clean global registry in setup file#314

Merged
luxass merged 8 commits intomainfrom
fix-zod-registry
Oct 11, 2025
Merged

test(api): clean global registry in setup file#314
luxass merged 8 commits intomainfrom
fix-zod-registry

Conversation

@luxass
Copy link
Member

@luxass luxass commented Oct 10, 2025

🔗 Linked issue

📚 Description

This PR is moving each schema to use custom zod registry, to prevent issues with double registering schemas. Even though that change did not prevent the tests from being flaky with the double zod registering. I kept it in.

The actual fix was to set aliases on the vitest worker project config, which will use the source files, and not the dist. I don't know why it was imported twice, when we used dist, but it was? Or maybe it could have been because they were getting registered at load time, and then again at reference?

This PR makes the API worker clear the schemas in a test setup file, but that broke the index.test.ts openapi tests, which has worked before? It seems to have something to do with zod lazy.

I will just keep this as is, and then try implementing h3-openapi which will become more usable, and not have all of these issues.

Summary by CodeRabbit

  • New Features
    • Exposed a schema registry for easier integrations.
  • Refactor
    • Standardized schema registration across packages for consistency.
  • Tests
    • Simplified test setup and reduced dependencies to improve reliability and speed.
  • Chores
    • Centralized Vitest path alias configuration for smoother developer workflows.

@changeset-bot
Copy link

changeset-bot bot commented Oct 10, 2025

⚠️ No Changeset found

Latest commit: 4899d7c

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

@github-actions github-actions bot added apps: api Changes related to the API. pkg: schemas Changes related to the FS Bridge package. labels Oct 10, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 10, 2025

📋 OpenAPI Schema Analysis

No changes detected - The OpenAPI schema is identical to the main branch.

🤖 This comment is automatically updated when you push new commits.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Centralizes Vitest alias configuration via a new vitest.aliases.ts and updates root/worker Vitest configs to use it. Moves Zod global registry clearing into a shared test setup file referenced by setupFiles and removes per-file beforeEach hooks. Adds exported types in packages/schemas/src/index.ts. Marks the OpenAPI test suite as todo.

Changes

Cohort / File(s) Summary
API test suite setup and tweaks
apps/api/test/__setup.ts, apps/api/test/routes/v1_files.test.ts, apps/api/test/routes/v1_versions.test.ts, apps/api/test/routes/well-known.test.ts, apps/api/test/index.test.ts
Adds shared test setup that clears Zod’s global registry before each test; removes zod imports and per-file beforeEach hooks; converts OpenAPI suite to describe.todo.
Vitest alias centralization
vitest.aliases.ts, vitest.config.ts, apps/api/vitest.config.worker.ts
Introduces dynamic alias discovery module and switches configs to import it; adds resolve.alias usage and setupFiles in worker config; streamlines onConsoleLog/hiddenLogs placement.
Schemas public exports
packages/schemas/src/index.ts
Re-exports types from fs and unicode modules: FileEntry, FileEntryList, UCDStoreManifest, UnicodeTree, UnicodeTreeNode, UnicodeVersion, UnicodeVersionList.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant V as Vitest Runner
  participant S as setupFiles (__setup.ts)
  participant Z as Zod Global Registry
  participant T as Test Files

  V->>S: Load setupFiles
  Note right of S: Register beforeEach hook
  loop For each test
    V->>S: beforeEach()
    S->>Z: z.globalRegistry.clear()
    Note over Z: Registry cleared
    V->>T: Execute test
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

I tidied my tests with a hop and a sweep,
Moved aliases burrow-deep where they keep.
Zod’s little crumbs? Brushed clean each run—
beforeEach no more, less fuss, more fun.
New types sprout fresh in the meadow of code,
I thump with joy—onward we goad! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title accurately reflects the relocation of Zod’s global registry clearing into the API test setup file, which corresponds to the addition of apps/api/test/__setup.ts and removal of per-test beforeEach hooks.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-zod-registry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Base automatically changed from better-deployment to main October 10, 2025 16:12
Copilot AI review requested due to automatic review settings October 10, 2025 16:13
- Added a new `ucdRegistry` in `zod-registry.ts` to manage schema metadata for OpenAPI generation.
- Updated existing schemas in `api.ts`, `fs.ts`, `unicode.ts` to register with `ucdRegistry`.
- Enhanced `index.ts` to export `ucdRegistry` for broader access.
- Introduced `vitest.aliases.ts` to manage package aliases.
- Updated `vitest.config.ts` to import and use the new aliases.
- Simplified the configuration by removing inline alias definitions.
* Eliminated `beforeEach` hooks that cleared the global registry in `v1_files.test.ts`, `v1_versions.test.ts`, and `well-known.test.ts`.
* This change simplifies the test setup as the global registry was not being utilized.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a custom Zod registry system to prevent schema double registration issues and resolves test flakiness by configuring Vitest worker projects to use source files instead of distribution files.

  • Introduces a custom ucdRegistry for managing UCD schema metadata without polluting the global registry
  • Migrates all schema definitions from .meta() to .register(ucdRegistry, ...)
  • Extracts alias configuration into a shared module and applies it to worker test configurations

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vitest.config.ts Refactored to extract alias configuration into separate module
vitest.aliases.ts New shared alias configuration module using NodeURL for worker compatibility
packages/schemas/src/zod-registry.ts Introduces custom UCD registry with typed metadata
packages/schemas/src/unicode.ts Updates schemas to use custom registry instead of global meta
packages/schemas/src/index.ts Exports the new custom registry
packages/schemas/src/fs.ts Updates schemas to use custom registry instead of global meta
packages/schemas/src/api.ts Updates schemas to use custom registry instead of global meta
apps/api/vitest.config.worker.ts Adds alias configuration to resolve source files
apps/api/test/routes/well-known.test.ts Removes global registry clearing from test setup
apps/api/test/routes/v1_versions.test.ts Removes global registry clearing from test setup
apps/api/test/routes/v1_files.test.ts Removes global registry clearing from test setup
Comments suppressed due to low confidence (1)

packages/schemas/src/api.ts:1

  • The ApiErrorSchema is still using .meta() instead of .register(ucdRegistry, ...) like other schemas in the file. This inconsistency could lead to the schema not being properly registered in the custom registry.
import { dedent } from "@luxass/utils";

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/schemas/src/api.ts (1)

5-22: Inconsistent schema registration approach.

ApiErrorSchema uses .meta({ id: "ApiError", ... }) while UCDWellKnownConfigSchema (lines 57-64) uses .register(ucdRegistry, { id: "UCDWellKnownConfig", ... }). For consistency and to fully leverage the custom registry, both schemas should use .register().

Apply this diff to standardize the registration:

-export const ApiErrorSchema = z.object({
+const ApiErrorSchemaBase = z.object({
   message: z.string().meta({
     description: "Human-readable error message describing what went wrong",
   }),
   status: z.number().meta({
     description: "HTTP status code matching the response status",
   }),
   timestamp: z.string().meta({
     description: "ISO 8601 timestamp when the error occurred",
   }),
-}).meta({
-  id: "ApiError",
+});
+
+export const ApiErrorSchema = ApiErrorSchemaBase.register(ucdRegistry, {
+  id: "ApiError",
   description: dedent`
     Standard error response format used consistently across all API endpoints.
 
     Contains essential information for debugging and user feedback. The specific error scenarios and status codes are documented in the individual endpoint response definitions.
   `,
 });
packages/schemas/src/fs.ts (1)

43-52: Inconsistent schema registration approach.

FileEntrySchema still uses .meta() while UCDStoreManifestSchema and FileEntryListSchema in this file have been migrated to .register(ucdRegistry, ...). For consistency with the registry-based approach introduced in this PR, consider either:

  1. Registering FileEntrySchema with the registry (if it needs an ID for OpenAPI generation):
export const FileEntrySchema = z.union([
  DirectoryResponseSchema,
  FileResponseSchema,
]).register(ucdRegistry, {
  id: "FileEntry",
  description: dedent`
    Response schema for a file entry in the UCD store.

    This schema represents either a directory listing or a file response.
  `,
});
  1. Or keeping .meta() if this schema doesn't need registry-based ID tracking.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5436d92 and 8c907d9.

📒 Files selected for processing (11)
  • apps/api/test/routes/v1_files.test.ts (1 hunks)
  • apps/api/test/routes/v1_versions.test.ts (1 hunks)
  • apps/api/test/routes/well-known.test.ts (1 hunks)
  • apps/api/vitest.config.worker.ts (2 hunks)
  • packages/schemas/src/api.ts (3 hunks)
  • packages/schemas/src/fs.ts (2 hunks)
  • packages/schemas/src/index.ts (1 hunks)
  • packages/schemas/src/unicode.ts (4 hunks)
  • packages/schemas/src/zod-registry.ts (1 hunks)
  • vitest.aliases.ts (1 hunks)
  • vitest.config.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{test,spec}.?(c|m)[jt]s?(x)

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{test,spec}.?(c|m)[jt]s?(x): Name test files using the pattern **/*.{test,spec}.?(c|m)[jt]s?(x)
In tests, import utilities via the aliases #test-utils/* instead of @ucdjs/test-utils
Use setupMockStore() from #test-utils/mock-store for UCD API mocking in tests
For filesystem-related tests, use testdir() from vitest-testdirs

Files:

  • apps/api/test/routes/v1_versions.test.ts
  • apps/api/test/routes/well-known.test.ts
  • apps/api/test/routes/v1_files.test.ts
apps/api/test/!(unit)/**

📄 CodeRabbit inference engine (AGENTS.md)

Place Cloudflare Worker tests under apps/api/test/** excluding test/unit/** (Workers environment)

Files:

  • apps/api/test/routes/v1_versions.test.ts
  • apps/api/test/routes/well-known.test.ts
  • apps/api/test/routes/v1_files.test.ts
🧠 Learnings (1)
📚 Learning: 2025-10-10T08:18:24.243Z
Learnt from: CR
PR: ucdjs/ucd#0
File: AGENTS.md:0-0
Timestamp: 2025-10-10T08:18:24.243Z
Learning: Applies to **/*.{test,spec}.?(c|m)[jt]s?(x) : In tests, import utilities via the aliases `#test-utils/*` instead of `ucdjs/test-utils`

Applied to files:

  • vitest.aliases.ts
🧬 Code graph analysis (5)
apps/api/vitest.config.worker.ts (1)
vitest.aliases.ts (1)
  • aliases (11-22)
packages/schemas/src/zod-registry.ts (1)
packages/schemas/src/index.ts (1)
  • ucdRegistry (29-29)
packages/schemas/src/fs.ts (1)
packages/schemas/src/zod-registry.ts (1)
  • ucdRegistry (21-29)
packages/schemas/src/api.ts (1)
packages/schemas/src/zod-registry.ts (1)
  • ucdRegistry (21-29)
packages/schemas/src/unicode.ts (1)
packages/schemas/src/zod-registry.ts (1)
  • ucdRegistry (21-29)
🪛 GitHub Actions: openapi artifacts
apps/api/test/routes/v1_versions.test.ts

[error] 1-1: Command failed: pnpm --filter=@ucdjs/api-worker build:openapi. Exit code 1.

apps/api/test/routes/well-known.test.ts

[error] 1-1: Command failed: pnpm --filter=@ucdjs/api-worker build:openapi. Exit code 1.

apps/api/vitest.config.worker.ts

[error] 1-1: Command failed: pnpm --filter=@ucdjs/api-worker build:openapi. Exit code 1.

apps/api/test/routes/v1_files.test.ts

[error] 1-1: Command failed: pnpm --filter=@ucdjs/api-worker build:openapi. Exit code 1.

🔇 Additional comments (16)
apps/api/test/routes/well-known.test.ts (1)

9-9: LGTM! Test cleanup aligns with custom registry approach.

The removal of the beforeEach import and zod global registry reset is correct. The custom registry (ucdRegistry) introduced in this PR eliminates the need for manual registry cleanup between tests.

apps/api/test/routes/v1_versions.test.ts (1)

11-11: LGTM! Consistent test cleanup.

Removal of zod imports and global registry resets is appropriate given the new custom registry approach.

packages/schemas/src/index.ts (1)

29-29: LGTM! Custom registry now available to consumers.

Exporting ucdRegistry allows external packages to register schemas with the same registry, maintaining consistency across the ecosystem.

apps/api/test/routes/v1_files.test.ts (1)

9-9: LGTM! Consistent test cleanup.

apps/api/vitest.config.worker.ts (1)

3-3: Excellent! This is the key fix for test flakiness.

Adding path aliases to the worker configuration ensures tests resolve to source files rather than distributed files. According to the PR description, this prevents the double-registration issue that was causing flaky tests.

The centralized alias approach (imported from vitest.aliases.ts) maintains consistency with the main Vitest configuration.

Based on learnings: Vitest 3.x supports project-based configuration, and this change correctly applies aliases at the project level.

Also applies to: 33-35

packages/schemas/src/api.ts (1)

57-64: LGTM! Proper registry-based registration.

The migration from .meta() to .register(ucdRegistry, ...) correctly uses the custom registry pattern.

packages/schemas/src/unicode.ts (2)

23-52: LGTM! Consistent registry-based schema registration.

The migration to .register(ucdRegistry, ...) is correctly implemented, preserving the schema metadata and examples.


56-59: LGTM! All schemas consistently use the custom registry.

Also applies to: 114-117, 121-124

vitest.config.ts (1)

4-4: LGTM! Centralized alias configuration improves maintainability.

Importing aliases from a shared module (vitest.aliases.ts) ensures consistency across all Vitest configurations and eliminates duplication.

Based on learnings: Vitest 3.x's project-based configuration benefits from centralized resolver settings.

Also applies to: 62-62

packages/schemas/src/zod-registry.ts (2)

16-29: LGTM! Well-designed custom registry.

The custom registry is properly typed with JSONSchemaMeta and additional OpenAPI-compatible fields. The deprecation notice for example in favor of examples aligns with OpenAPI specification recommendations.


1-1: Import path is correct.

JSONSchemaMeta is only available from "zod/v4/core", so no change is needed.

Likely an incorrect or invalid review comment.

packages/schemas/src/fs.ts (3)

3-3: LGTM! Correct import for registry usage.

The import of ucdRegistry is necessary for the schema registrations below and follows the correct relative path.


8-25: LGTM! Correct registry usage.

The schema correctly uses .register(ucdRegistry, ...) instead of .meta(...), aligning with the new registry-based approach introduced in this PR.


56-59: LGTM! Correct registry usage.

The schema correctly uses .register(ucdRegistry, ...) instead of .meta(...), aligning with the new registry-based approach.

vitest.aliases.ts (2)

1-9: LGTM! Clean helper functions.

The import statements and helper functions (pkgRoot and alias) are well-structured and correctly use Node.js built-ins to compute file paths.

Note: The unnecessary blank line at line 8 was already flagged in a previous review.


11-22: LGTM! Correct alias resolution logic.

The aliases construction correctly:

  • Scans the packages directory and filters for valid packages
  • Builds @ucdjs/<pkg> mappings to source directories
  • Includes predefined test-utils aliases that align with the project's test utility import patterns

The logic properly handles edge cases (e.g., checking for package.json existence) and uses appropriate types.

Based on learnings.

@luxass luxass marked this pull request as draft October 10, 2025 16:18
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
vitest.aliases.ts (1)

8-8: Remove unnecessary blank line.

There's an unnecessary blank line between the pkgRoot and alias function definitions.

Apply this diff:

 const pkgRoot = (pkg: string) =>
   fileURLToPath(new NodeURL(`./packages/${pkg}`, import.meta.url));
-
 const alias = (pkg: string) => `${pkgRoot(pkg)}/src`;
🧹 Nitpick comments (4)
packages/schemas/src/fs.ts (1)

56-59: Also register FileEntrySchema for consistency and reuse.

Top-level/public schemas should be in the registry to enable $ref reuse. Consider giving FileEntrySchema an id and registering it.

Apply this change to FileEntrySchema:

export const FileEntrySchema = z.union([
  DirectoryResponseSchema,
  FileResponseSchema,
]).register(ucdRegistry, {
  id: "FileEntry",
  description: dedent`
    Response schema for a file entry in the UCD store.

    This schema represents either a directory listing or a file response.
  `,
});
packages/schemas/src/zod-registry.ts (2)

4-15: Remove commented-out prototype patch; prefer a safe helper.

Prototype monkey-patching is fragile. Drop the commented code and add a small idempotent helper instead.

Add alongside the registry:

export type UcdRegistryMeta = JSONSchemaMeta & {
  examples?: z.$output[];
  /** @deprecated use `examples` */
  example?: z.$output;
  id?: string;
};

export function registerOnce<T extends z.ZodTypeAny>(schema: T, meta: UcdRegistryMeta): T {
  if (meta.id && ucdRegistry.has(meta.id)) return schema;
  return schema.register(ucdRegistry, meta);
}

Then replace .register(ucdRegistry, {...}) with registerOnce(schema, {...}) where id collisions are possible (e.g., tests).


21-29: Type alias for metadata improves reuse.

Export a UcdRegistryMeta type and reuse it across schemas to keep metadata shape consistent.

packages/schemas/src/api.ts (1)

16-16: Register ApiErrorSchema with the registry for consistency.

Move from .meta({ id: "ApiError", ... }) to .register(ucdRegistry, { id: "ApiError", ... }) to avoid global registration drift and align with the rest.

-}).meta({
-  id: "ApiError",
+}).register(ucdRegistry, {
+  id: "ApiError",
   description: dedent`
     Standard error response format used consistently across all API endpoints.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5436d92 and 8c907d9.

📒 Files selected for processing (11)
  • apps/api/test/routes/v1_files.test.ts (1 hunks)
  • apps/api/test/routes/v1_versions.test.ts (1 hunks)
  • apps/api/test/routes/well-known.test.ts (1 hunks)
  • apps/api/vitest.config.worker.ts (2 hunks)
  • packages/schemas/src/api.ts (3 hunks)
  • packages/schemas/src/fs.ts (2 hunks)
  • packages/schemas/src/index.ts (1 hunks)
  • packages/schemas/src/unicode.ts (4 hunks)
  • packages/schemas/src/zod-registry.ts (1 hunks)
  • vitest.aliases.ts (1 hunks)
  • vitest.config.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{test,spec}.?(c|m)[jt]s?(x)

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{test,spec}.?(c|m)[jt]s?(x): Name test files using the pattern **/*.{test,spec}.?(c|m)[jt]s?(x)
In tests, import utilities via the aliases #test-utils/* instead of @ucdjs/test-utils
Use setupMockStore() from #test-utils/mock-store for UCD API mocking in tests
For filesystem-related tests, use testdir() from vitest-testdirs

Files:

  • apps/api/test/routes/v1_versions.test.ts
  • apps/api/test/routes/well-known.test.ts
  • apps/api/test/routes/v1_files.test.ts
apps/api/test/!(unit)/**

📄 CodeRabbit inference engine (AGENTS.md)

Place Cloudflare Worker tests under apps/api/test/** excluding test/unit/** (Workers environment)

Files:

  • apps/api/test/routes/v1_versions.test.ts
  • apps/api/test/routes/well-known.test.ts
  • apps/api/test/routes/v1_files.test.ts
🧬 Code graph analysis (5)
packages/schemas/src/zod-registry.ts (1)
packages/schemas/src/index.ts (1)
  • ucdRegistry (29-29)
packages/schemas/src/fs.ts (1)
packages/schemas/src/zod-registry.ts (1)
  • ucdRegistry (21-29)
packages/schemas/src/api.ts (2)
packages/schemas/src/index.ts (1)
  • ucdRegistry (29-29)
packages/schemas/src/zod-registry.ts (1)
  • ucdRegistry (21-29)
packages/schemas/src/unicode.ts (1)
packages/schemas/src/zod-registry.ts (1)
  • ucdRegistry (21-29)
apps/api/vitest.config.worker.ts (1)
vitest.aliases.ts (1)
  • aliases (11-22)
🔇 Additional comments (15)
apps/api/vitest.config.worker.ts (1)

3-3: LGTM! Alias configuration correctly applied.

The import and resolve configuration properly integrate the centralized aliases, ensuring worker tests use source files instead of dist files as intended by the PR objective.

Also applies to: 33-35

vitest.config.ts (2)

4-4: LGTM! Centralized alias import.

The static import from vitest.aliases.ts consolidates alias resolution logic effectively, eliminating code duplication.


32-32: Verify empty hiddenLogs is intentional.

The hiddenLogs array is initialized empty but used in onConsoleLog (line 48-54). Confirm this is intentional and that no log filtering is currently required, or if specific log patterns should be added.

vitest.aliases.ts (1)

11-22: LGTM! Alias discovery logic is correct.

The dynamic package discovery and alias mapping correctly:

  • Filters valid packages by checking for package.json
  • Maps each package to @ucdjs/<pkg> pointing to source files
  • Includes predefined test-utils and internal test utility aliases
  • Uses NodeURL to avoid type issues in worker test contexts

This centralization supports the PR objective of ensuring tests use source files instead of dist files.

apps/api/test/routes/v1_versions.test.ts (1)

11-11: LGTM! Removal aligns with custom registry approach.

The removal of beforeEach from imports is correct since the global Zod registry reset is no longer needed. The PR's fix using Vitest aliases ensures the test environment uses source files instead of dist files, eliminating the need for per-test registry resets.

apps/api/test/routes/well-known.test.ts (1)

9-9: LGTM! Consistent with registry cleanup across test files.

The removal of beforeEach is correct and mirrors the changes in other test files (v1_versions.test.ts, v1_files.test.ts). The custom registry and alias-based resolution eliminate the need for manual registry resets between tests.

apps/api/test/routes/v1_files.test.ts (1)

9-9: LGTM! Registry reset removal completes the pattern.

The removal of beforeEach is appropriate and completes the consistent cleanup across all three test files. With the Vitest aliases ensuring source file usage, the manual Zod registry management is no longer necessary.

packages/schemas/src/index.ts (1)

29-29: Publicly exporting the registry is good.

Makes registry reuse explicit across packages.

packages/schemas/src/fs.ts (1)

8-25: LGTM on registry registration for UCDStoreManifest.

Correct use of .register with id and description.

packages/schemas/src/api.ts (1)

57-64: LGTM on registry registration for UCDWellKnownConfig.

Matches the new pattern and includes a stable id.

packages/schemas/src/unicode.ts (4)

23-52: LGTM on UnicodeVersionSchema registration.

Good use of id and examples with the custom registry.


56-59: LGTM on UnicodeVersionListSchema registration.


114-117: LGTM on UnicodeTreeNodeSchema registration.

Manual $ref in children meta aligns with the recursion workaround.


121-124: LGTM on UnicodeTreeSchema registration.

packages/schemas/src/zod-registry.ts (1)

1-2: Zod version consistency verified: every package.json lists zod as catalog:prod, so no mixed Zod versions will be installed.

* Changed the registration method for `FileEntrySchema` from `.meta()` to `.register(ucdRegistry, {...})`.
* This aligns the schema registration with the established pattern used in other schemas.
- Removed the `ucdRegistry` import and its usage from multiple schema files.
- Updated schema definitions to use `.meta()` instead of `.register()`.
- This change simplifies the schema registration process and improves code clarity.
* Introduced a new setup file `__setup.ts` to clear the global registry before each test.
* Updated `vitest.config.worker.ts` to include the new setup file for test initialization.
* Marked the "openapi" describe block as todo in `index.test.ts`.
@github-actions
Copy link
Contributor

github-actions bot commented Oct 11, 2025

🌏 Preview Deployments

Application Status Preview URL
API ✅ Deployed View Preview
Website ✅ Deployed View Preview
Documentation ✅ Deployed View Preview

Built from commit: 4899d7c9e9e0a65fe64686d66630a60cc4006180


🤖 This comment will be updated automatically when you push new commits to this PR.

@codecov
Copy link

codecov bot commented Oct 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@luxass luxass marked this pull request as ready for review October 11, 2025 04:36
@luxass luxass changed the title feat(schemas): use custom registry test(api): clean global registry in setup file Oct 11, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/api/test/index.test.ts (1)

54-54: Document the reason for deferring OpenAPI tests.

The OpenAPI test suite has been marked as .todo, but there's no explanation for why these tests are being skipped. This makes it difficult for future maintainers to know when or how to re-enable them.

Please clarify:

  1. Why are these tests being deferred? Is it related to the Zod registry changes, the Vitest alias configuration, or another issue?
  2. Is there a tracking issue for re-enabling these tests?

Consider adding a comment above the test block explaining the reason for deferral and linking to any relevant tracking issue. For example:

// TODO: Re-enable once [issue link] is resolved
// Currently deferred due to [specific reason]
describe.todo("openapi", () => {

If the tests are failing due to the changes in this PR, I can help investigate the root cause. Would you like me to analyze the OpenAPI implementation or test setup to identify potential issues?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c907d9 and 4899d7c.

📒 Files selected for processing (5)
  • apps/api/test/__setup.ts (1 hunks)
  • apps/api/test/index.test.ts (1 hunks)
  • apps/api/vitest.config.worker.ts (2 hunks)
  • packages/schemas/src/index.ts (1 hunks)
  • vitest.aliases.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • vitest.aliases.ts
  • packages/schemas/src/index.ts
  • apps/api/vitest.config.worker.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{test,spec}.?(c|m)[jt]s?(x)

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{test,spec}.?(c|m)[jt]s?(x): Name test files using the pattern **/*.{test,spec}.?(c|m)[jt]s?(x)
In tests, import utilities via the aliases #test-utils/* instead of @ucdjs/test-utils
Use setupMockStore() from #test-utils/mock-store for UCD API mocking in tests
For filesystem-related tests, use testdir() from vitest-testdirs

Files:

  • apps/api/test/index.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: update deployment comment
🔇 Additional comments (1)
apps/api/test/__setup.ts (1)

1-7: Confirm necessity of global Zod registry clearing

  • Clearing is centralized in apps/api/test/__setup.ts; no other tests invoke z.globalRegistry.clear().
  • If no tests register schemas globally, remove this hook; otherwise keep it to prevent cross-test state bleed.

@luxass luxass merged commit 51a170b into main Oct 11, 2025
31 checks passed
@luxass luxass deleted the fix-zod-registry branch October 11, 2025 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apps: api Changes related to the API. pkg: schemas Changes related to the FS Bridge package.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant