Skip to content

Fix reset function#192

Merged
nadilas merged 3 commits intomainfrom
fix/reset_fn
Mar 29, 2025
Merged

Fix reset function#192
nadilas merged 3 commits intomainfrom
fix/reset_fn

Conversation

@nadilas
Copy link
Copy Markdown
Member

@nadilas nadilas commented Mar 29, 2025

fix: reset function

refactor: type imports

Summary by CodeRabbit

  • New Features

    • Enhanced repository reset capabilities now support reverting to specific commit hashes or version tags for more precise branch updates.
  • Refactor

    • Updated import statements to clarify type usage, improving code clarity and potentially optimizing module loading behavior.
    • Streamlined reference handling in the reset method for improved performance.
  • Tests

    • Expanded test coverage validates logging and reset behaviors, ensuring a more stable and predictable experience for users.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
ogre ⬜️ Ignored (Inspect) Visit Preview Mar 29, 2025 8:21am

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2025

Walkthrough

This pull request updates multiple modules in the ogre package to use TypeScript’s type-only import/export syntax. The changes differentiate between runtime code and type annotations by converting several imports and exports to type declarations, thereby optimizing module loading. Additionally, the repository reset functionality has been refined by adjusting how references are computed and moved. New tests have been added to verify logging and reset operations. A new utility function is introduced, and a TypeScript compiler option is added to improve module syntax handling.

Changes

File(s) Change Summary
packages/ogre/src/commit.ts, packages/ogre/src/git2json.ts, packages/ogre/src/index.ts, packages/ogre/src/interfaces.ts, packages/ogre/src/checkout.test.ts, packages/ogre/src/commit.test.ts, packages/ogre/src/test.utils.ts, packages/ogre/src/utils.test.ts Modified import/export statements to use TypeScript’s import type and export type syntax for entities like Operation, Commit, History, and Reference.
packages/ogre/src/repository.ts Updated reference handling in the reset method: replaced refsAtCommit with refKeysAtCommit and simplified filtering/movement logic; updated type imports for Observer and Operation.
packages/ogre/src/utils.ts Changed function signature for refsAtCommit to explicitly return an array; added new utility function refKeysAtCommit; updated import statements to type-only; modified printChangeLog logging.
packages/ogre/src/repository.test.ts Enhanced test suite: added assertions for logging via repo.logs(), renamed and updated reset tests to await asynchronous calls, and introduced tests for resetting to an earlier commit and version tag.
packages/ogre/tsconfig.json Added the new compiler option "verbatimModuleSyntax": true to the compilerOptions section.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Repo as Repository
    participant Utils as Utils Module
    Test->>Repo: Call reset (hard/target commit)
    Repo->>Utils: Execute refKeysAtCommit(refs, commit)
    Utils-->>Repo: Return matching reference keys
    Repo->>Repo: Filter & update references (moveRef)
    Test->>Repo: Invoke logs() and validate repository state
Loading

Poem

I'm a hopping rabbit in a code forest so vast,
Skipping through type-only imports that make our load fast.
References now align, each commit in its place,
Logs and resets all singing with elegant grace.
With a twitch of my ears and a bounce in my stride,
I celebrate our changes with joy I cannot hide!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Copy link
Copy Markdown
Member Author

nadilas commented Mar 29, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 701e767 and 212e989.

📒 Files selected for processing (8)
  • packages/ogre/src/commit.ts (1 hunks)
  • packages/ogre/src/git2json.ts (1 hunks)
  • packages/ogre/src/index.ts (1 hunks)
  • packages/ogre/src/interfaces.ts (1 hunks)
  • packages/ogre/src/repository.test.ts (3 hunks)
  • packages/ogre/src/repository.ts (3 hunks)
  • packages/ogre/src/utils.ts (3 hunks)
  • packages/ogre/tsconfig.json (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
packages/ogre/src/repository.test.ts (2)
packages/ogre/src/repository.ts (2)
  • logs (589-600)
  • diff (424-437)
packages/ogre/src/test.utils.ts (2)
  • getBaseline (20-41)
  • updateHeaderData (43-49)
packages/ogre/src/utils.ts (2)
packages/ogre/src/interfaces.ts (1)
  • Reference (3-8)
packages/ogre/src/commit.ts (1)
  • Commit (4-26)
🪛 GitHub Actions: Test coverage
packages/ogre/src/repository.test.ts

[error] not ok 5 - src/repository.test.ts # time=4087.507ms

🔇 Additional comments (19)
packages/ogre/src/interfaces.ts (1)

1-1: Good use of TypeScript's type-only import

This change properly leverages TypeScript's type-only import feature, which indicates that Commit is only needed for type checking, not runtime. This helps optimize bundle size by excluding type information from the compiled JavaScript.

packages/ogre/tsconfig.json (1)

11-12: Good addition of verbatimModuleSyntax compiler option

Adding "verbatimModuleSyntax": true is an excellent choice that complements the type-only import changes across the codebase. This option enforces proper handling of import type statements during compilation, ensuring they're excluded from runtime code.

packages/ogre/src/commit.ts (1)

2-2: Good use of TypeScript's type-only import

Converting to import type {Operation} is appropriate since Operation is only used for type declarations in the interfaces and not as a runtime value. This change helps with tree-shaking and bundle size optimization.

packages/ogre/src/git2json.ts (1)

1-2: Good use of TypeScript's type-only imports

Converting these imports to type-only imports is appropriate since these types are only used for type annotations in function parameters and not as runtime values. This change is consistent with the other type import refactoring across the codebase.

packages/ogre/src/index.ts (2)

3-3: Good use of TypeScript's type-only export

Changing to export type { Commit } properly indicates that Commit should only be used for type checking, not as a runtime value. This maintains consistency with the import changes in other files.


9-11: Good separation of value and type exports

This change correctly separates the runtime exports (compare, deepClone, JsonPatchError) from the type-only export (Operation). This distinction helps with proper tree-shaking and bundle optimization.

packages/ogre/src/repository.test.ts (4)

63-69: Added test coverage for the logs() method.

Good addition of test cases for the logs() method with different arguments. This verifies that:

  1. repo.logs() returns all logs
  2. repo.logs(1) returns only one log
  3. repo.logs(100) returns all logs when there are fewer than 100
🧰 Tools
🪛 GitHub Actions: Test coverage

[error] not ok 5 - src/repository.test.ts # time=4087.507ms


290-290: Better test name improves clarity.

Changing from "reset hard" to "discard uncommitted changes" better describes the purpose of this test, making the test suite more readable and maintainable.

🧰 Tools
🪛 GitHub Actions: Test coverage

[error] not ok 5 - src/repository.test.ts # time=4087.507ms


307-329: Added test coverage for resetting to a specific commit.

This is a valuable addition to the test suite that verifies the repository can be reset to an earlier commit hash. The test properly:

  1. Creates a baseline with initial commit
  2. Makes additional changes with a second commit
  3. Resets to the first commit
  4. Verifies the reset worked correctly including reference updates
🧰 Tools
🪛 GitHub Actions: Test coverage

[error] not ok 5 - src/repository.test.ts # time=4087.507ms


331-355: Added test coverage for resetting to a version tag.

Good test case that verifies the repository can be reset to a specific tag. This complements the previous test by ensuring tag-based reference resets work correctly, enhancing the overall test coverage of the reset functionality.

🧰 Tools
🪛 GitHub Actions: Test coverage

[error] not ok 5 - src/repository.test.ts # time=4087.507ms

packages/ogre/src/repository.ts (5)

8-9: Improved type safety with type-only imports.

Converting Observer and Operation to type-only imports is a good TypeScript practice that differentiates between runtime code and type annotations, potentially reducing bundle size in the compiled output.


24-24: Added new utility import for reference handling.

The addition of refKeysAtCommit import supports the improved reset functionality implementation and aligns with the changes in utils.ts.


382-384: Improved reset functionality with better reference handling.

The changes here extract the HEAD commit and use the new refKeysAtCommit function to get reference keys, improving how references are computed during reset operations. This addresses part of the PR objective to fix the reset function.


386-388: Simplified reference filtering logic.

The filter now checks if the reference key starts with the local head path prefix directly, which is more straightforward than checking the reference object's name property.


391-392: Simplified reference movement during reset.

Directly passing the reference key to moveRef instead of accessing a property simplifies the code and aligns with the other changes in the reset implementation.

packages/ogre/src/utils.ts (4)

2-7: Improved type safety with type-only imports.

Converting imports to use TypeScript's type-only import/export syntax is a good practice that:

  1. Makes the distinction between runtime and compile-time dependencies clear
  2. Can help reduce bundle size in the compiled output
  3. Helps prevent accidental runtime dependencies on type information

126-128: Improved type annotations and unused variable handling.

The changes to refsAtCommit function improve the code by:

  1. Explicitly specifying the return type as Array<Reference>
  2. Using _ to indicate the first parameter is not used, which prevents linting warnings

136-147: Added new utility function for reference key handling.

The new refKeysAtCommit function is a great addition that:

  1. Returns just the keys (strings) instead of full Reference objects
  2. Complements the existing refsAtCommit function
  3. Supports the improved reset implementation in repository.ts
  4. Follows the same pattern as existing code for consistency

233-238: Improved changelog output formatting.

The changes to printChangeLog function improve the code by:

  1. Separating the reference formatting logic from the logging
  2. Adding clearer HEAD indicator in the output
  3. Making the code more readable and maintainable


// reset
repo.reset("hard");
await repo.reset("hard");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fixed async operation handling.

Adding await to the repo.reset("hard") call properly handles the asynchronous reset operation, ensuring the test waits for the reset to complete before checking its effects.

🧰 Tools
🪛 GitHub Actions: Test coverage

[error] not ok 5 - src/repository.test.ts # time=4087.507ms

Copy link
Copy Markdown

@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)
packages/ogre/src/test.utils.ts (1)

2-3: Good use of TypeScript's type-only import syntax

Converting RepositoryObject and Commit to type-only imports improves type clarity and follows TypeScript best practices. This is consistent with the changes in other files and aligns with the type imports refactoring mentioned in the PR description.

There's a minor spacing issue in line 3 after the type keyword. For consistency with line 2, consider adding a space: import type { Commit } from "./commit.js";

-import type {Commit} from "./commit.js";
+import type { Commit } from "./commit.js";
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 212e989 and 1791ddc.

📒 Files selected for processing (5)
  • packages/ogre/src/checkout.test.ts (1 hunks)
  • packages/ogre/src/commit.test.ts (1 hunks)
  • packages/ogre/src/repository.test.ts (4 hunks)
  • packages/ogre/src/test.utils.ts (1 hunks)
  • packages/ogre/src/utils.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/ogre/src/commit.test.ts
  • packages/ogre/src/checkout.test.ts
🧰 Additional context used
🧬 Code Definitions (1)
packages/ogre/src/repository.test.ts (2)
packages/ogre/src/repository.ts (2)
  • logs (589-600)
  • diff (424-437)
packages/ogre/src/test.utils.ts (2)
  • getBaseline (20-41)
  • updateHeaderData (43-49)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: release
🔇 Additional comments (7)
packages/ogre/src/utils.test.ts (1)

4-4: Good use of TypeScript's type-only import syntax

Converting ComplexObject to a type-only import helps distinguish between runtime values and compile-time types. This change is part of the broader type imports refactoring mentioned in the PR description and follows TypeScript best practices.

packages/ogre/src/repository.test.ts (6)

8-8: Good use of TypeScript's type-only import syntax

Converting ComplexObject and Reference to type-only imports aligns with TypeScript best practices and is consistent with the changes in other files.

Also applies to: 14-14


63-69: Improved test coverage for logging functionality

Adding these test cases for the logs() method with different parameter values provides better validation of the logging functionality:

  1. No parameter to retrieve all logs
  2. Limit to 1 log
  3. Limit exceeding available logs (100)

This is a good improvement to the test suite.


290-290: Better test description

Changing from "reset hard" to "discard uncommitted changes" improves the test description by focusing on the intent/behavior rather than the implementation details.


302-302: Fixed async operation handling

Adding await to the repo.reset("hard") call properly handles the asynchronous reset operation, ensuring the test waits for the reset to complete before checking its effects.


307-329: Good addition: Test for resetting to a specific commit

This new test thoroughly verifies that the repository can be reset to an earlier commit by:

  1. Creating baseline data with multiple commits
  2. Resetting to a specific commit hash
  3. Verifying that the diff is empty after reset
  4. Confirming the main branch points to the correct commit hash

This is an important test case for the reset functionality fix mentioned in the PR description.


331-355: Good addition: Test for resetting to a version tag

This test complements the previous one by verifying that the repository can be reset using a tag reference instead of a direct commit hash. The test ensures that:

  1. Version tags can be properly used as references for reset operations
  2. The main branch points to the correct commit after reset

Together with the previous test, this provides comprehensive coverage for the reset functionality that was fixed in this PR.

@nadilas nadilas merged commit 7b5f99d into main Mar 29, 2025
8 checks passed
@nadilas nadilas deleted the fix/reset_fn branch March 29, 2025 08:24
@github-actions
Copy link
Copy Markdown

🚀 PR was released in @dotinc/ogre-cli@0.12.1, @dotinc/ogre-react@0.15.1, @dotinc/ogre@0.15.1 🚀

@github-actions github-actions bot added the released This issue/pull request has been released. label Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released This issue/pull request has been released.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant