85 phase 2 implement smart migration path with hybrid generator - #88
Conversation
- Introduced `HybridGenerator` to support both programmatic and template-based markdown generation, allowing for gradual migration. - Added `generateWithHybridGenerator` function to streamline output generation based on user-defined options. - Updated command flags to enhance custom template functionality. - Created comprehensive tests to validate output consistency between programmatic and template generation modes. All tests passed successfully; no tests were affected by these changes.
…st coverage - Introduced a caching mechanism for template loading to optimize IO/CPU operations, reducing redundant template parsing. - Added comprehensive tests for `getCachedTemplate` to validate caching behavior and error handling for various scenarios. - Enhanced command flags to support filename completion for custom templates, improving user experience. - Updated existing tests to ensure compatibility with the new caching functionality. All tests passed successfully; no tests were affected by these changes.
…ance test coverage - Implemented an LRU caching mechanism for template instances to optimize loading and reduce redundant I/O operations. - Refactored existing template handling to utilize the new cache, improving performance and memory management. - Expanded test coverage for template caching functionality, including concurrent access and cache size verification. - Updated command flags to allow configuration of the template cache size for better user control. All tests passed successfully; no tests were affected by these changes.
|
Caution Review failedFailed to post review comments. Configuration used: .coderabbit.yaml ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
💤 Files with no reviewable changes (1)
🧰 Additional context used📓 Path-based instructions (14)**/go.mod📄 CodeRabbit Inference Engine (.cursor/rules/go-organization.mdc)
Files:
{go.mod,go.sum}📄 CodeRabbit Inference Engine (.cursor/rules/go-standards.mdc)
Files:
go.mod📄 CodeRabbit Inference Engine (.cursor/rules/go-standards.mdc)
Files:
**/*.go📄 CodeRabbit Inference Engine (.cursor/rules/core-concepts.mdc)
Files:
**/*_test.go📄 CodeRabbit Inference Engine (.cursor/rules/core-concepts.mdc)
Files:
**/*.{go,md}📄 CodeRabbit Inference Engine (.cursor/rules/go-documentation.mdc)
Files:
**/*.{go,_example_test.go}📄 CodeRabbit Inference Engine (.cursor/rules/go-documentation.mdc)
Files:
**/internal/**/*.go📄 CodeRabbit Inference Engine (.cursor/rules/go-organization.mdc)
Files:
internal/**/*.go📄 CodeRabbit Inference Engine (.cursor/rules/go-standards.mdc)
Files:
{cmd,internal,pkg,testdata,docs}/**📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)
Files:
internal/**📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)
Files:
internal/{audit,config,converter,display,export,log,markdown,model,parser,plugin,plugins,processor,templates,validator,constants}/**📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)
Files:
cmd/**/*.go📄 CodeRabbit Inference Engine (.cursor/rules/compliance-standards.mdc)
Files:
cmd/*.go📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)
Files:
🧬 Code Graph Analysis (6)internal/markdown/hybrid_generator_comparison_test.go (8)
internal/markdown/hybrid_generator_test.go (6)
internal/markdown/hybrid_generator.go (7)
cmd/shared_flags.go (1)
cmd/convert.go (8)
cmd/convert_test.go (1)
🔇 Additional comments (1)
Summary by CodeRabbit
WalkthroughAdds a thread-safe LRU template cache and wires it into convert’s flow; introduces a HybridGenerator for markdown supporting template/programmatic modes; adds a new CLI flag for cache sizing with template file completion; updates dependency on golang-lru; removes deprecation comments; adds extensive tests for cache and hybrid generator. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI as convert cmd
participant Flags as shared flags
participant Cache as TemplateCache (LRU)
participant FS as Filesystem
participant Gen as HybridGenerator
User->>CLI: run convert --format [md/json/yaml] [--custom-template T] [--template-cache-size N]
CLI->>Flags: parse flags
Flags-->>CLI: format, template path, cache size
CLI->>Cache: instantiate(size=N)
alt custom template provided
CLI->>Cache: Get(T)
alt cache miss
Cache->>FS: read T
FS-->>Cache: template bytes
Cache->>Cache: parse and store
end
end
CLI->>Gen: create (builder, optional pre-parsed template)
CLI->>Gen: Generate(data, options)
Gen-->>CLI: output (md/json/yaml)
CLI->>Cache: Clear() (post-batch)
CLI-->>User: write output
sequenceDiagram
participant Gen as HybridGenerator
participant Builder as MarkdownBuilder
participant Tmpl as Template Engine
Gen->>Gen: shouldUseTemplate?(format, opts, template presence)
alt Use template (markdown)
Gen->>Tmpl: render(md with context)
Tmpl-->>Gen: markdown string
else Programmatic path
Gen->>Builder: Build report (standard/comprehensive)
Builder-->>Gen: markdown string
end
Gen-->>Caller: result
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Suggested labels
Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ code/snyk check is complete. No issues have been found. (View Details) |
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces a thread-safe, configurable LRU template cache system to the convert command to improve performance and memory management when using custom Go text/template files. It implements a hybrid generator architecture that supports both template-based and programmatic markdown generation with seamless migration capabilities.
Key changes:
- Added
TemplateCachewith LRU eviction and configurable size via--template-cache-sizeflag - Implemented
HybridGeneratorfor dual-mode markdown generation (template vs programmatic) - Enhanced template flag completion and error handling for better user experience
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
cmd/convert.go |
Added TemplateCache implementation with LRU eviction, new format constants, and refactored output generation to use hybrid approach |
cmd/convert_test.go |
Added comprehensive unit tests for template cache functionality including concurrency safety tests |
cmd/shared_flags.go |
Enhanced --custom-template flag description, added shell completion for .tmpl files, and new --template-cache-size flag |
internal/markdown/hybrid_generator.go |
New hybrid generator implementation supporting both template and programmatic generation modes |
internal/markdown/hybrid_generator_test.go |
Comprehensive unit tests for the hybrid generator covering all generation modes and edge cases |
internal/markdown/hybrid_generator_comparison_test.go |
Comparison tests ensuring output equivalence between generation modes and feature flag testing |
internal/converter/markdown.go |
Removed deprecated comments for code clarity |
go.mod |
Added github.com/hashicorp/golang-lru/v2 dependency for LRU cache implementation |
…n docs Batch 7 of tech debt cleanup: - Document plugin loading trust model in plugin-development.md and GOTCHAS.md §2.5 — no verification on .so loading (#88) - Add t.Run() subtests to TestRedact_AuthServerConfig for per-case isolation (#60) - Replace strings.Join with running currentPath in sanitizer for reduced allocations on hot path (#78) - Fix action.yml/README docs: add pfSense mentions, list all formats and subcommands, clarify @main vs @v1, document args whitespace splitting (#93) Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
This pull request introduces a thread-safe, configurable LRU template cache to the
convertcommand, improving performance and memory management when using custom Go text/template files for report generation. It also adds new command-line flags for template cache size, enhances template flag completion, and refactors output generation to leverage the cache. Comprehensive unit tests are included to ensure cache correctness and concurrency safety.Template Caching and Output Generation Enhancements:
TemplateCachetype with LRU eviction, supporting thread-safe caching of parsed templates, and integrated it into the batch processing flow incmd/convert.go. The cache size is configurable via a new--template-cache-sizeflag. [1] [2] [3] [4]generateOutputByFormatfunction, which utilizes the cached template for markdown and template output, and gracefully falls back to programmatic generation for other formats. [1] [2]User Experience Improvements:
--custom-templateflag to clarify that it accepts Go text/template files and added shell completion for.tmplfiles to improve usability.Testing and Dependencies:
cmd/convert_test.go.github.com/hashicorp/golang-lru/v2dependency for efficient LRU cache implementation.Minor Cleanups:
internal/converter/markdown.gofor clarity. [1] [2]