Skip to content

Conversation

@MeteorsLiu
Copy link
Collaborator

@MeteorsLiu MeteorsLiu commented Feb 2, 2026

Introduce a module-scoped formula source pipeline that resolves formulas by version from repository filesystems.

The implementation includes:

  • A new internal/modules/source.go with formulaModule, lazy comparator() loading, at() formula caching by fromVer, and findMaxFromVer selection of the highest applicable formula file.
  • Comparator fallback behavior in comparator() that uses loadComparatorFS when a custom comparator is available and falls back to gnu.Compare when comparator loading fails.
  • New AST-based helpers fromVerOf, fromVerFrom, and parseCallArg to extract and validate fromVer from *_llar.gox files, including explicit error handling for missing, empty, or non-string arguments.
  • Refactoring of comparator loading in internal/modules/comparator.go from path-based loadComparator to filesystem-based loadComparatorFS(fs.ReadFileFS, path), plus corresponding updates in internal/modules/comparator_test.go.
  • A comprehensive internal/modules/source_test.go suite covering comparator behavior, version matching, caching semantics, parsing edge cases, and integration with repo.Store.

This change makes module formula resolution more deterministic and filesystem-agnostic, while improving correctness and debuggability for comparator and fromVer parsing paths.

@gemini-code-assist
Copy link

Summary of Changes

Hello @MeteorsLiu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust caching system for module formulas, designed to optimize performance by intelligently handling formula loading and version resolution. It allows the system to quickly locate and apply the correct formula for a given module version, preventing unnecessary file I/O and parsing, and supports flexible version comparison strategies.

Highlights

  • New Formula Caching Mechanism: Introduced a classfileCache to efficiently manage and retrieve module formulas, significantly reducing redundant file system operations and parsing.
  • Version-Aware Formula Resolution: The cache supports version-aware lookups, finding the most appropriate formula based on a module's version. It can utilize custom version comparators or default to GNU version ordering.
  • AST-based Version Extraction: Implemented logic to parse formula files' Abstract Syntax Trees (AST) to extract the fromVer information, which is crucial for version comparison.
  • Configurable Search Paths: Formulas are resolved using a configurable set of search paths, applying a 'first-match-wins' strategy to locate the correct formula file.
  • Module Directory Management: Added utility functions to determine and create specific directories for module formulas and source caches, ensuring proper organization and persistence.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 91.30435% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.24%. Comparing base (a3fa8fa) to head (3637607).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/modules/source.go 90.80% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #91      +/-   ##
==========================================
+ Coverage   68.58%   70.24%   +1.66%     
==========================================
  Files          25       26       +1     
  Lines        1009     1099      +90     
==========================================
+ Hits          692      772      +80     
- Misses        254      259       +5     
- Partials       63       68       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a classfileCache for managing formula loading and caching, with version-aware lookups. The implementation is well-structured and includes comprehensive tests. My review focuses on improving code clarity by fixing typos, addressing a critical compilation issue in the tests, and promoting better error handling and code reuse.

@MeteorsLiu
Copy link
Collaborator Author

/review

@MeteorsLiu
Copy link
Collaborator Author

/review

@xgopilot
Copy link
Contributor

xgopilot bot commented Feb 5, 2026

Code Review Summary

Good architecture with clean separation: moduleSourceformulaModuleformula. The caching strategy for formulas and comparators is well-designed, and test coverage is comprehensive.

Key findings:

  1. Performance - findMaxFromVer() re-walks the filesystem on every at() call before checking cache. Consider caching fromVer metadata after first scan.

  2. Type safety - Unchecked fs.ReadFileFS type assertions at multiple locations could panic. Validate at construction or use safe assertions.

  3. Input validation - mod.Version in sourceCacheDirOf is used directly in path construction without validation.

See inline comments for details.

if err != nil {
return "", err
}
moduleDir := filepath.Join(formulaDir, escapedModPath)
Copy link
Member

Choose a reason for hiding this comment

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

what's the structure under this folder?

MeteorsLiu and others added 10 commits February 6, 2026 16:23
Implement classfileCache to manage formula loading and caching with
version-aware lookups. The cache:

- Maintains loaded formulas and version comparators
- Supports configurable search paths with first-match-wins strategy
- Parses formula files to extract version information (fromVer)
- Provides version comparison using custom or GNU version ordering
- Includes comprehensive test coverage for version parsing

This enables efficient formula resolution across different module
versions while avoiding redundant file system operations and parsing.
Add test suite for the formulaOf method in classfileCache covering:
- Successful formula retrieval and loading
- Formula caching behavior verification
- Error handling for comparator failures
- Error handling for missing formulas (FindMaxFromVer failures)
- Error handling for invalid formula loading
- Version resolution to formula mapping

Import required packages (fmt and internal/formula) to support
the new test implementations. Tests ensure proper formula caching,
version matching, and error propagation in the formula lookup flow.
Redesign the module loading system with cleaner separation of concerns:

- Remove classfileCache which mixed caching, loading, and version matching
- Add moduleSource to manage formula repositories and handle sync
- Add formulaModule to represent a single module's formula collection
- moduleSource.module() handles sync and caches formulaModule instances
- formulaModule.comparator() lazily loads and caches version comparator
- formulaModule.at(version) handles version matching and formula loading

This refactoring improves:
- Clear ownership: sync in moduleSource, loading in formulaModule
- Better abstraction: moduleSource -> formulaModule -> formula
- Testability: each component has focused responsibilities

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change moduleSource.module() to store sync errors in formulaModule
instead of returning them immediately. Errors are now returned when
comparator() or at() methods are called, allowing module creation to
always succeed while still propagating sync failures at usage time.

This improves error handling by:
- Simplifying the module() API (no error return)
- Deferring sync errors until actual module usage
- Maintaining error propagation through comparator() and at()

Updated tests to verify deferred error behavior and added test case
for permission-denied scenarios.
Refactor parseCallArg() to use a switch statement for type assertion and
explicitly reject non-string literal arguments with an error instead of
silently returning an empty string. Update corresponding test to validate
that non-string arguments properly return an error.
Add documentation comment explaining that if the custom comparator
cannot be loaded, the module falls back to GNU version comparison.
This improves code clarity by explicitly documenting the fallback
mechanism in the comparator() function.
Added validation to check if fromVer is empty after parsing from the formula AST. Returns a descriptive error message when fromVer cannot be parsed, preventing silent failures and improving debugging.

Also added a TODO comment to optimize max fromVer searching using a trie tree data structure for better performance.
Update test cases in source_test.go to check for error conditions using wantErr assertions instead of wantFromVer expectations. This change improves test clarity by explicitly verifying that empty source and invalid configurations correctly return errors, with minor formatting improvements for better readability.
Remove the moduleSource struct and its module caching/synchronization logic,
pushing this responsibility to the caller. Simplify formulaModule to work with
fs.FS already positioned at the module directory, eliminating the need for path
escaping and error state management. This reduces complexity and makes the API
clearer by separating concerns.
Copy link
Member

@luoliwoshang luoliwoshang left a comment

Choose a reason for hiding this comment

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

LGTM

@luoliwoshang luoliwoshang merged commit 29d5717 into goplus:main Feb 6, 2026
4 checks passed
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