Skip to content

feat: implement analyze method on store#183

Merged
luxass merged 33 commits intomainfrom
store-analyze
Jul 31, 2025
Merged

feat: implement analyze method on store#183
luxass merged 33 commits intomainfrom
store-analyze

Conversation

@luxass
Copy link
Member

@luxass luxass commented Jul 30, 2025

🔗 Linked issue

resolves #133

📚 Description

This PR implements the analyze method on the UCD Store.

Summary by CodeRabbit

  • New Features

    • Introduced an "analyze" command to the CLI for checking the completeness of Unicode Character Database (UCD) stores, including detection of missing and orphaned files across multiple versions.
    • Added new analysis capabilities to the UCD store, allowing users to retrieve file trees and analyze store contents by version.
  • Bug Fixes

    • Improved file path handling and recursive directory listing in the filesystem bridge to ensure accurate results.
  • Chores

    • Updated build scripts across multiple packages to use explicit TypeScript configuration files.
    • Enhanced ESLint configurations to ignore additional test patterns.
    • Adjusted dependency management, moving "memfs" to development dependencies.
  • Tests

    • Added comprehensive tests for the new analyze functionality and file path retrieval, increasing reliability and coverage.
  • Refactor

    • Removed unused decorators and capability checks from internal code for simplification and maintainability.
  • Documentation

    • Added and updated changeset documentation to reflect new features and version updates.

luxass added 5 commits July 30, 2025 10:12
- Added `versions` property to `CLIStoreCmdSharedFlags` interface.
- Implemented `createStoreFromFlags` function to handle both remote and local UCD store creation.
- Introduced `runVersionPrompt` function for selecting Unicode versions during store initialization.
- Updated error handling to ensure either `--remote` or `--store-dir` is specified.
…ommand

* Enhanced error messages for unsupported features and store initialization failures.
* Updated version selection logic to prompt users when no versions are specified.
* Refined command usage documentation for clarity.
* Moved error exports to improve structure and readability.
* Ensures better organization of error handling in the UCD store module.
- Introduced `analyze` method to perform analysis on specified Unicode versions.
- Added `AnalyzeOptions` interface to define options for analysis, including orphaned file checks.
- Implemented error handling for version validation and analysis process.
- Created `VersionAnalysis` interface to structure the results of the analysis.
@changeset-bot
Copy link

changeset-bot bot commented Jul 30, 2025

🦋 Changeset detected

Latest commit: 6a43284

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@ucdjs/ucd-store Minor
@ucdjs/cli Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 32c5e73 and 6a43284.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (26)
  • .changeset/proud-mangos-look.md (1 hunks)
  • packages/cli/package.json (1 hunks)
  • packages/cli/src/cmd/store/analyze.ts (1 hunks)
  • packages/cli/src/cmd/store/root.ts (2 hunks)
  • packages/cli/src/cmd/store/status.ts (0 hunks)
  • packages/env/package.json (1 hunks)
  • packages/fetch/package.json (1 hunks)
  • packages/fs-bridge/eslint.config.js (1 hunks)
  • packages/fs-bridge/package.json (1 hunks)
  • packages/fs-bridge/src/bridges/http.ts (1 hunks)
  • packages/fs-bridge/test/bridges/http.test.ts (6 hunks)
  • packages/schema-gen/package.json (1 hunks)
  • packages/schemas/package.json (1 hunks)
  • packages/ucd-store/eslint.config.js (1 hunks)
  • packages/ucd-store/package.json (2 hunks)
  • packages/ucd-store/src/internal/capabilities.ts (0 hunks)
  • packages/ucd-store/src/internal/files.ts (1 hunks)
  • packages/ucd-store/src/store.ts (6 hunks)
  • packages/ucd-store/src/types.ts (1 hunks)
  • packages/ucd-store/test/__shared.ts (2 hunks)
  • packages/ucd-store/test/internal/files.test.ts (1 hunks)
  • packages/ucd-store/test/store-analyze.test.ts (1 hunks)
  • packages/ucd-store/tsconfig.build.json (0 hunks)
  • packages/utils/package.json (1 hunks)
  • packages/utils/src/flatten.ts (1 hunks)
  • pnpm-workspace.yaml (2 hunks)
 ________________________
< Code review is my jam. >
 ------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

Walkthrough

This change introduces a comprehensive "analyze" capability to the UCD Store ecosystem. It adds a new CLI subcommand, implements versioned file completeness/orphan checks in the store, introduces supporting types and utilities, updates tests, and removes the old "status" command. Several package build scripts are also updated to use explicit TypeScript configs.

Changes

Cohort / File(s) Change Summary
CLI Analyze Command
packages/cli/src/cmd/store/analyze.ts, packages/cli/src/cmd/store/root.ts, packages/cli/src/cmd/store/status.ts
Adds a new "analyze" CLI subcommand, removes the "status" command, and updates root command logic to route to analyze.
UCD Store: Analyze Implementation
packages/ucd-store/src/store.ts, packages/ucd-store/src/internal/files.ts, packages/ucd-store/src/types.ts
Implements UCDStore.analyze() and supporting methods/types, adds file tree retrieval and analysis logic, and introduces API interaction for expected file paths.
UCD Store: Internal/Decorator Removal
packages/ucd-store/src/internal/capabilities.ts, packages/ucd-store/tsconfig.build.json
Removes the requiresCapabilities decorator and its interface; disables experimental decorators in tsconfig.
UCD Store: Testing Enhancements
packages/ucd-store/test/store-analyze.test.ts, packages/ucd-store/test/internal/files.test.ts, packages/ucd-store/test/__shared.ts
Adds comprehensive tests for analyze functionality, expected file path retrieval, and enhances the in-memory mock filesystem to support recursive directory trees.
Flatten Utility Update
packages/utils/src/flatten.ts
Adds runtime type validation to flattenFilePaths.
Test Path Adjustments
packages/fs-bridge/src/bridges/http.ts, packages/fs-bridge/test/bridges/http.test.ts
Updates recursive directory listing logic and test expectations to ensure correct path handling.
ESLint Ignore Updates
packages/fs-bridge/eslint.config.js, packages/ucd-store/eslint.config.js
Expands ESLint ignore patterns using GLOB_TESTS from shared config.
Build Script Updates
packages/cli/package.json, packages/env/package.json, packages/fetch/package.json, packages/fs-bridge/package.json, packages/schema-gen/package.json, packages/schemas/package.json, packages/ucd-store/package.json, packages/utils/package.json
Updates build scripts to use explicit tsconfig.build.json; adjusts dependencies (notably, moves/removes memfs).
Changeset and Workspace Metadata
.changeset/proud-mangos-look.md, pnpm-workspace.yaml
Adds a changeset documenting the new feature, updates workspace dependency catalogs.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI
  participant UCDStore
  participant API
  participant FS

  User->>CLI: Run "store analyze" [flags, versions]
  CLI->>UCDStore: new UCDStore(options)
  CLI->>UCDStore: analyze({checkOrphaned, versions})
  loop For each version
    UCDStore->>API: GET /api/v1/versions/{version}/file-tree
    API-->>UCDStore: [expected file tree]
    UCDStore->>FS: List actual files for version
    FS-->>UCDStore: [actual file paths]
    UCDStore->>UCDStore: Compare expected vs actual, find missing/orphaned
  end
  UCDStore-->>CLI: [VersionAnalysis[]]
  CLI-->>User: Output results (JSON or text)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Assessment against linked issues

Objective Addressed Explanation
Implement analyze method on UCDStore with AnalyzeOptions and VersionAnalysis interface as described (#133)
Include checkOrphaned option and correct completeness/orphaned/missing file logic in analysis (#133)
Support analysis for multiple Unicode versions, returning results per version (#133)
Expose CLI interface for invoking analyze functionality (#133)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Update build scripts to use explicit tsconfig files (e.g., packages/cli/package.json, packages/utils/package.json, etc.) Build script changes are not described in the linked issue and are unrelated to the analyze method feature.
Remove requiresCapabilities decorator and experimentalDecorators option (e.g., packages/ucd-store/src/internal/capabilities.ts, packages/ucd-store/tsconfig.build.json) Decorator and related config removal are not mentioned in the issue and are not required for implementing analyze functionality.
ESLint ignore pattern updates (e.g., packages/fs-bridge/eslint.config.js, packages/ucd-store/eslint.config.js) Lint config changes are not part of the analyze method requirements.
Test path and mock filesystem adjustments (e.g., packages/fs-bridge/src/bridges/http.ts, packages/fs-bridge/test/bridges/http.test.ts, packages/ucd-store/test/__shared.ts) Some test utility and path normalization changes are not directly required for the analyze method, though they may support improved testing.

Possibly related PRs

Poem

In Unicode forests, the rabbits explore,
They count every file—are there less, are there more?
Orphaned and missing, now easy to see,
With "analyze" magic, as quick as can be.
CLI commands hop, and tests multiply,
This patch brings completeness—oh my, oh my!
🐇✨

Tip

You can customize the tone of the review comments and chat replies.

Set the tone_instructions setting in your project's settings in CodeRabbit to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch store-analyze

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added pkg: cli Changes related to the CLI package. pkg: ucd-store Changes related to the UCD Store package. labels Jul 30, 2025
luxass added 7 commits July 30, 2025 10:17
* Introduced `runAnalyzeStore` function to analyze UCD store versions.
* Added flags for JSON output and orphaned file checks.
* Updated `runStoreRoot` to include the new `analyze` subcommand.
* Removed obsolete `status` command and its related files.
* Added a type check to validate that 'entries' is an array of UnicodeTreeNode.
* Throws a TypeError if the validation fails, improving error handling.
- Added functionality to analyze a specific version of files in the store.
- Checks for orphaned files if the `checkOrphaned` option is enabled.
- Throws an error if the specified version is not found in the store.
- Returns an analysis object containing details about orphaned and missing files.
…aths for Unicode versions

- Implements `getExpectedFilePaths` to fetch expected file paths from the API.
- Handles API errors by throwing `UCDStoreError` with a descriptive message.
- Includes tests for valid version retrieval and error handling scenarios.
* Improved error handling to account for additional error scenarios.
* Added new methods `getFileTree` and `getFilePaths` for better file management.
* Updated tests to cover new error handling and file retrieval logic.
@codecov
Copy link

codecov bot commented Jul 30, 2025

Codecov Report

❌ Patch coverage is 45.09804% with 56 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/cli/src/cmd/store/analyze.ts 0.00% 36 Missing and 11 partials ⚠️
packages/ucd-store/src/store.ts 88.63% 5 Missing ⚠️
packages/cli/src/cmd/store/root.ts 0.00% 2 Missing and 1 partial ⚠️
packages/utils/src/flatten.ts 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

luxass added 13 commits July 31, 2025 08:16
* Enables the use of experimental decorators in the TypeScript configuration.
This is because when using the Node FS Bridge we are using a base path, and the base path that is being used by the different features inside the ucd-store will also use this basePath. So in the end the base path will be duplicated.
* Moved the version selection logic inside the try block to ensure that the remote or store directory is validated before prompting for versions.
* This change prevents potential errors when no versions are provided and improves error handling during the initialization process.
- Updated the constructor to accept a `versions` parameter.
- Initialized the private `#versions` property with the provided versions.
* Eliminated the import of `UCDStoreVersionNotFoundError` as it was not utilized in the test file.
* Updated `listdir` calls to use `joinURL` for correct path resolution.
* Simplified return values in `getExpectedFilePaths` by removing unnecessary version prefix.
* Enhanced filtering logic in `analyze` methods to improve clarity and correctness.
* Introduced `stripChildrenFromEntries` utility function for cleaner entry processing in tests.
* Adjusted test cases to reflect changes in expected file paths and analysis results.
* Changed `describe` to `describe.todo` for custom store analyze operations.
* Enhanced assertions in the test for analyzing a store with no files.
* Improved clarity and consistency in the test structure.
luxass added 4 commits July 31, 2025 15:30
* Added `memfs` as a dependency for improved memory filesystem handling.
* Updated `createMemoryMockFS` to utilize `memfs` for file operations.
* Enhanced `listdir` functionality to support recursive directory listing.
* Refactored tests to ensure compatibility with the new filesystem bridge.
* Added `GLOB_TESTS` to the ignores list in ESLint configuration for better file handling.
* Updated `createMemoryMockFS` to ensure type safety by casting return values.
* Improved path handling in `createFSEntry` and `entryMap` for consistency.
* Cleaned up the test file by removing the unused `vi` import.
* This improves code readability and maintains a cleaner codebase.
* Modified the `build` script in multiple package.json files to use `tsdown --tsconfig=./tsconfig.build.json`.
* Removed experimental decorators from TypeScript configuration files.
* Improved consistency across packages regarding build configurations.
@github-actions
Copy link
Contributor

github-actions bot commented Jul 31, 2025

Preview Deployment for Web

The Web worker has been deployed successfully.

Preview URL: https://preview.ucdjs.dev

This preview was built from commit 6a43284


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

@github-actions
Copy link
Contributor

github-actions bot commented Jul 31, 2025

Preview Deployment for Api

The Api worker has been deployed successfully.

Preview URL: https://preview.api.ucdjs.dev

This preview was built from commit 6a43284


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

@luxass luxass marked this pull request as ready for review July 31, 2025 14:55
@luxass luxass requested a review from Copilot July 31, 2025 14:55
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 the analyze method on the UCD Store to enable analysis of Unicode version data integrity and completeness. The implementation provides comprehensive store analysis capabilities including orphaned file detection and missing file identification.

Key changes include:

  • Implementation of the core analyze method with version-specific analysis logic
  • Addition of comprehensive test coverage for both local and remote store analysis scenarios
  • Introduction of supporting infrastructure for file path comparison and validation

Reviewed Changes

Copilot reviewed 25 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/ucd-store/src/store.ts Implements the main analyze method and version-specific analysis logic
packages/ucd-store/src/internal/files.ts Adds utility function to fetch expected file paths from the API
packages/ucd-store/src/types.ts Defines AnalyzeOptions and VersionAnalysis interfaces for the analyze functionality
packages/ucd-store/test/store-analyze.test.ts Comprehensive test suite covering various analysis scenarios
packages/cli/src/cmd/store/analyze.ts CLI command implementation for the analyze functionality
packages/utils/src/flatten.ts Adds input validation to the flattenFilePaths function
packages/ucd-store/test/__shared.ts Updates memory mock filesystem to support listdir operations
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

luxass added 3 commits July 31, 2025 16:57
* Updated the log message to accurately reflect that all versions will be analyzed when no specific versions are provided.
@luxass luxass merged commit 1297cbd into main Jul 31, 2025
3 checks passed
@luxass luxass deleted the store-analyze branch July 31, 2025 15:05
@github-actions github-actions bot added pkg: schema-gen Changes related to the Schema Gen package. pkg: utils Changes related to the Utils package. pkg: fetch Changes related to the UCD Store package. pkg: env Changes related to the Env package. pkg: schemas Changes related to the FS Bridge package. pkg: fs-bridge Changes related to the FS Bridge package. labels Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: cli Changes related to the CLI package. pkg: env Changes related to the Env package. pkg: fetch Changes related to the UCD Store package. pkg: fs-bridge Changes related to the FS Bridge package. pkg: schema-gen Changes related to the Schema Gen package. pkg: schemas Changes related to the FS Bridge package. pkg: ucd-store Changes related to the UCD Store package. pkg: utils Changes related to the Utils package.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

analyze method

1 participant