Skip to content

Conversation

@luxass
Copy link
Member

@luxass luxass commented Jan 8, 2026

🔗 Linked issue

📚 Description

This PR apply some test utils modifications from #420, most tests will fail for now. But that is fine, we will fix it in all the other open PRs.

Summary by CodeRabbit

  • New Features

    • Added file tree creation utilities for constructing mock test file structures
    • Enhanced mock file handling with per-version file trees and content-based responses
    • Included default content for Unicode data files in test utilities
    • Changed default mock endpoint behavior from enabled to disabled unless explicitly configured
  • Chores

    • Added new project dependencies for utility support

✏️ Tip: You can customize this high-level summary in your review settings.

luxass added 4 commits January 8, 2026 04:20
- Introduced `addPathsToFileNodes` function to recursively add paths to file nodes.
- Added `createFileTree` function for generating file tree structures from simplified input formats.
- Enhanced `filesRoute` and `fileTreeRoute` handlers to utilize new utilities for path management.
- Updated type definitions for better clarity and structure in mock store files.
…ling

- Added `@unicode-utils/core` as a dependency for improved path handling.
- Updated `well-known.ts` to utilize `addPathsToFileNodes` for better file structure management.
- Refactored type definitions in `types.ts` for clarity and consistency.
@changeset-bot
Copy link

changeset-bot bot commented Jan 8, 2026

⚠️ No Changeset found

Latest commit: 4df64e4

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.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR enhances the test-utils mock-store by introducing new dependencies, utilities for managing versioned file trees with path augmentation, default Unicode data constants, and refactored handlers for dynamically serving file structures with content and directory listing support.

Changes

Cohort / File(s) Summary
Dependencies
packages/test-utils/package.json
Added three public dependencies: @luxass/utils, @ucdjs/env, @unicode-utils/core for utilities and utility functions.
File Tree Infrastructure
packages/test-utils/src/mock-store/file-tree.ts, packages/test-utils/src/mock-store/add-paths.ts
Introduced createFileTree() for recursive file-tree generation from input mappings and addPathsToFileNodes() for augmenting nodes with computed paths, including versioned prefixes and base-path logic.
Default Unicode Content
packages/test-utils/src/mock-store/default-files/arabic-shaping.ts, packages/test-utils/src/mock-store/default-files/bidi-brackets.ts
Added new modules exporting large Unicode data constants (defaultArabicShapingFileContent, defaultBidiBracketsFileContent) for test fixtures.
Type Refactoring
packages/test-utils/src/mock-store/types.ts, packages/test-utils/src/mock-store/utils.ts
Replaced UnicodeFileTree with node-based MockStoreNode and MockStoreNodeWithPath types; added DeepOmit, omitContentRecursively(), and omitChildrenAndContent() utilities for recursive content/children filtering.
Handler Updates
packages/test-utils/src/mock-store/handlers/files.ts, packages/test-utils/src/mock-store/handlers/file-tree.ts, packages/test-utils/src/mock-store/handlers/well-known.ts
Substantially enhanced files handler with per-version file trees, HEAD/GET routing, dynamic path resolution, directory listing, and file content delivery with metadata headers; updated file-tree and well-known handlers to use new path augmentation and content omission utilities.
Public Exports
packages/test-utils/src/mock-store/index.ts
Updated mock-store default files to use _content instead of path; added public exports for createFileTree, FileTreeInput, and FileTreeNodeWithContent; changed endpoint response default from true to false.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Handler as Files Handler
    participant FileTree as File Tree
    participant PathAugment as Path Augmentation
    participant ContentOmit as Content Omission
    participant Response

    Client->>Handler: GET /v15.0.0/ucd/extracted/DerivedBidiClass.txt
    Handler->>FileTree: createFileTree(files[version])
    FileTree-->>Handler: FileTreeNodeWithContent[]
    Handler->>PathAugment: addPathsToFileNodes(nodes, "v15.0.0", "ucd")
    PathAugment-->>Handler: MockStoreNodeWithPath[]
    Handler->>ContentOmit: omitContentRecursively(nodes)
    ContentOmit-->>Handler: MockStoreNode[] (no _content)
    Handler->>Handler: findFileByPath() → locate requested file
    Handler->>Response: 200 + Content-Length + file data
    Response-->>Client: File content with metadata
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐰 Through versioned paths the mock-trees grow,
With augmented nodes in careful flow,
Unicode data bundled tight,
Content served with headers bright,
File-forests dance with bidi's grace! ✨

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b20f27 and 4df64e4.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • packages/test-utils/package.json
  • packages/test-utils/src/mock-store/add-paths.ts
  • packages/test-utils/src/mock-store/default-files/arabic-shaping.ts
  • packages/test-utils/src/mock-store/default-files/bidi-brackets.ts
  • packages/test-utils/src/mock-store/default-files/derived-bidi-class.ts
  • packages/test-utils/src/mock-store/file-tree.ts
  • packages/test-utils/src/mock-store/handlers/file-tree.ts
  • packages/test-utils/src/mock-store/handlers/files.ts
  • packages/test-utils/src/mock-store/handlers/well-known.ts
  • packages/test-utils/src/mock-store/index.ts
  • packages/test-utils/src/mock-store/types.ts
  • packages/test-utils/src/mock-store/utils.ts

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.

@github-actions github-actions bot added the pkg: test-utils Changes related to the test-utils package. label Jan 8, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

🌏 Preview Deployments

Note

No deployable apps affected by changes in this PR.

Built from commit: 4df64e48b285a658d2f33cc0d37abf39a37b8cf9


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

@luxass luxass marked this pull request as ready for review January 8, 2026 03:24
Copilot AI review requested due to automatic review settings January 8, 2026 03:24
@luxass luxass merged commit 59ef91b into main Jan 8, 2026
27 of 30 checks passed
@luxass luxass deleted the feat/test-utils-improvements-redo branch January 8, 2026 03:25
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 introduces significant improvements to the test-utils package by adding new utility functions for managing mock file stores, enhanced type definitions, and default file content. The changes enable more flexible test file tree creation and better handling of file paths in the mock store API. These changes are extracted from #420 and are expected to cause test failures until other related PRs are merged.

Key Changes:

  • Added new utility functions for file tree manipulation (omitContentRecursively, omitChildrenAndContent, addPathsToFileNodes, createFileTree)
  • Enhanced type definitions for mock store nodes with optional paths and content
  • Implemented comprehensive file/directory request handling in the files handler
  • Added default file content for Arabic shaping, bidi brackets, and derived bidi class

Reviewed changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/test-utils/package.json Added new dependencies: @luxass/utils, @ucdjs/env, @unicode-utils/core
pnpm-lock.yaml Updated lock file to reflect new package dependencies
packages/test-utils/src/mock-store/types.ts Enhanced type definitions with MockStoreNode, MockStoreNodeWithPath, and updated MockStoreFiles
packages/test-utils/src/mock-store/utils.ts Added DeepOmit type utility and helper functions for omitting content/children from nodes
packages/test-utils/src/mock-store/add-paths.ts New utility to recursively add paths to file tree nodes
packages/test-utils/src/mock-store/file-tree.ts New utility for creating file trees from simplified input format
packages/test-utils/src/mock-store/index.ts Updated default file structure to use _content and removed path properties
packages/test-utils/src/mock-store/handlers/well-known.ts Updated to use addPathsToFileNodes for manifest generation
packages/test-utils/src/mock-store/handlers/files.ts Comprehensive rewrite to handle file/directory requests with proper headers
packages/test-utils/src/mock-store/handlers/file-tree.ts Updated to normalize file trees and add paths
packages/test-utils/src/mock-store/default-files/*.ts Added default file content for testing
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps
Copy link

greptile-apps bot commented Jan 8, 2026

Greptile Summary

Enhanced test utilities for mocking UCD store API with improved file tree handling, path management, and default Unicode data files. Adds support for version-prefixed paths and synthetic ucd directory structure to align with real API behavior.

Key Changes

  • Added three new dependencies: @luxass/utils, @ucdjs/env, and @unicode-utils/core
  • Introduced addPathsToFileNodes() utility to recursively add path properties to file tree nodes
  • Added createFileTree() helper for creating file trees from simplified nested object format
  • Enhanced file and file-tree handlers to support version-prefixed paths (e.g., /16.0.0/ucd/UnicodeData.txt)
  • Added comprehensive default Unicode file content (ArabicShaping, BidiBrackets, DerivedBidiClass)
  • Improved file response handling with proper headers (UCD_STAT_* headers for type, size, children counts)
  • Integrated hasUCDFolderPath() from @unicode-utils/core for version-specific path handling
  • Added utilities for cleaning file tree nodes: omitContentRecursively() and omitChildrenAndContent()

Architecture

The changes improve the mock store's fidelity to the real UCD API by properly handling the synthetic ucd subdirectory that exists in newer Unicode versions. The file handler now correctly parses version-prefixed paths and serves both file content and directory listings with appropriate headers.

Confidence Score: 4/5

  • Safe to merge with minor testing considerations
  • Score reflects well-structured implementation with clear separation of concerns and comprehensive type safety. The changes are focused on test utilities and won't affect production code. However, as noted in the PR description, tests will fail until other PRs are merged, which is expected and acceptable for this incremental refactor.
  • Pay close attention to packages/test-utils/src/mock-store/handlers/files.ts due to complex path parsing logic and multiple edge cases for handling versioned/unversioned requests

Important Files Changed

Filename Overview
packages/test-utils/src/mock-store/add-paths.ts New utility to recursively add path properties to file tree nodes, handling both files and directories
packages/test-utils/src/mock-store/file-tree.ts New helper to create file tree structures from simplified nested object format with _content support
packages/test-utils/src/mock-store/handlers/file-tree.ts Enhanced to normalize file trees by handling synthetic ucd directory and properly prefix paths with version
packages/test-utils/src/mock-store/handlers/files.ts Major refactor to support version-prefixed paths, synthetic ucd directory handling, and improved file/directory responses with proper headers
packages/test-utils/src/mock-store/utils.ts Added omitContentRecursively and omitChildrenAndContent utilities for cleaning file tree nodes before responses

Sequence Diagram

sequenceDiagram
    participant Test as Test Suite
    participant MockStore as mockStoreApi()
    participant FileTree as file-tree handler
    participant Files as files handler
    participant WellKnown as well-known handler
    participant AddPaths as addPathsToFileNodes()
    
    Test->>MockStore: mockStoreApi(config)
    activate MockStore
    MockStore->>MockStore: Setup default files with mock content
    MockStore->>MockStore: Normalize base URL
    MockStore->>MockStore: Loop through MOCK_ROUTES
    
    Note over MockStore: For each endpoint, setup handlers
    
    MockStore->>FileTree: setup file-tree handler
    activate FileTree
    FileTree->>FileTree: Register GET /api/v1/versions/{version}/file-tree
    FileTree->>AddPaths: addPathsToFileNodes(nodes, version, "ucd")
    AddPaths-->>FileTree: Nodes with paths
    FileTree->>FileTree: omitContentRecursively()
    FileTree-->>MockStore: Handler registered
    deactivate FileTree
    
    MockStore->>Files: setup files handler
    activate Files
    Files->>Files: Register GET/HEAD /api/v1/files/{wildcard}
    Files->>AddPaths: addPathsToFileNodes() for version files
    AddPaths-->>Files: Nodes with paths
    Files->>Files: findFileByPath() for specific file
    Files->>Files: Return file content or directory listing
    Files-->>MockStore: Handler registered
    deactivate Files
    
    MockStore->>WellKnown: setup well-known handlers
    activate WellKnown
    WellKnown->>WellKnown: Register GET /.well-known/ucd-config.json
    WellKnown->>WellKnown: Register GET /.well-known/ucd-store/{version}.json
    WellKnown->>AddPaths: addPathsToFileNodes() for manifest
    AddPaths-->>WellKnown: Nodes with paths
    WellKnown->>WellKnown: flattenFilePaths() for expectedFiles
    WellKnown-->>MockStore: Handlers registered
    deactivate WellKnown
    
    MockStore->>MockStore: Register custom responses if provided
    deactivate MockStore
    
    Note over Test,WellKnown: Test execution
    
    Test->>Files: GET /api/v1/files/16.0.0/ucd/UnicodeData.txt
    activate Files
    Files->>Files: Parse wildcard path
    Files->>Files: Find file in tree
    Files-->>Test: Return file content with headers
    deactivate Files
    
    Test->>FileTree: GET /api/v1/versions/16.0.0/file-tree
    activate FileTree
    FileTree->>FileTree: Get version files
    FileTree->>FileTree: Normalize tree (handle synthetic ucd directory)
    FileTree-->>Test: Return file tree without _content
    deactivate FileTree
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: test-utils Changes related to the test-utils package.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants