Repository navigation
refactor: complexity, duplication and coverage clean-up (stacked on #33) - #34
Conversation
…terns; drop dead duplicate tool types
… duplicates and repeated code
…cape the document GUID, add tests
…re source helpers, clean up CSS and scripts, test the real extraction
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | -39 |
| Duplication | -67 |
🟢 Coverage 92.47% diff coverage · +45.88% coverage variation
Metric Results Coverage variation ✅ +45.88% coverage variation (-1.00%) Diff coverage ✅ 92.47% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (a8aae7b) 791 363 45.89% Head commit (35f56f3) 547 (-244) 502 (+139) 91.77% (+45.88%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#34) 478 442 92.47% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
Two high-risk issues should be addressed before merging: the browser launcher may permit command injection through a caller-controlled path, and user-editable grouping patterns can trigger catastrophic regular-expression backtracking on the UI thread.
Additional logic regressions were identified in per-file discovery error handling and saved grouping-rule preservation. Several acceptance areas remain only partially covered, particularly CLI/web behavior, fallback paths, and template interaction behavior.
About this PR
- Automated coverage does not yet exercise several newly refactored CLI, web-service, fallback, and template-interaction paths. Add focused tests for these branches before relying on the cleanup as a coverage improvement.
Test suggestions
- Core discovery, inheritance, comments, snapshots, fallback entities, and failure paths
- GUID escaping, CSS merging, default CSS, and HTML placeholder replacement
- GitHubSourceHelpers URL parsing, DbContext detection, entity extraction, and directory prioritization
- Malformed source and exceptional filesystem/project-search paths produce warnings without crashing
- Embedded-template fallback to filesystem resources
- CLI GitHub analysis, entity-file discovery, rate-limit behavior, output creation, and browser launching
- Web GitHub service and asynchronous schema analysis behavior
- Template JavaScript UI actions: grouping, selection, zoom, dragging, auto-layout, toggles, and downloaded state
- Large-schema layout and relationship rendering after JavaScript extraction
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Malformed source and exceptional filesystem/project-search paths produce warnings without crashing
2. Embedded-template fallback to filesystem resources
3. CLI GitHub analysis, entity-file discovery, rate-limit behavior, output creation, and browser launching
4. Web GitHub service and asynchronous schema analysis behavior
5. Template JavaScript UI actions: grouping, selection, zoom, dragging, auto-layout, toggles, and downloaded state
6. Large-schema layout and relationship rendering after JavaScript extraction
TIP Add a Jira or Linear ticket key to the branch or title so the reviewer can check the PR against it. Using another tracker? Tell us.
TIP How was this review? Give us feedback
| if (NESTED_QUANTIFIER.test(pattern)) { | ||
| throw new Error("Pattern contains nested quantifiers"); | ||
| } | ||
| return new RegExp(pattern, "i"); |
There was a problem hiding this comment.
🔴 HIGH RISK
Make grouping-pattern matching resistant to ReDoS by using a linear-time approach or rejecting unsupported constructs with execution safeguards. Add tests for adversarial and normal patterns.
See Issue in Codacy
See Issue in Codacy
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| throw new FileNotFoundException("Only an existing .html file can be opened.", fullPath); | ||
| } | ||
|
|
||
| using var process = Process.Start(CreateStartInfo(fullPath)); |
There was a problem hiding this comment.
🔴 HIGH RISK
Avoid passing an uncontrolled path directly to a platform command. Constrain targets to an application-owned directory and use safe platform-specific APIs or validated filenames; add traversal and invalid-extension tests.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| Array.from(document.querySelectorAll("[data-entity]")).find( | ||
| (element) => element.getAttribute("data-entity") === entityName, |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Replace the repeated full-DOM scans with a safe direct lookup or entity-to-element map while retaining support for unusual entity names.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| const matches = findRuleMatches(rule, entityNames); | ||
| return matches !== null && matches.length > 0; |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Do not silently delete saved rules that fail the new pattern restrictions. Preserve them for editing and surface an appropriate validation message.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| Console.WriteLine($"📁 Looking for entity models in: {modelsDirectory}"); | ||
| foreach (var modelFile in Directory.GetFiles(modelsDirectory, "*.cs")) | ||
| { | ||
| modelClasses.AddRange(TryParseClasses(File.ReadAllText(modelFile), Path.GetFileName(modelFile))); |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Restore per-file error handling around model-file reads so unreadable files produce warnings and analysis continues for the remaining models.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| @@ -1,3 +1,4 @@ | |||
| using System.Linq.Expressions; | |||
There was a problem hiding this comment.
🟡 MEDIUM RISK
Suggestion: Split the fixture into focused context, relationship-configuration, and entity files without changing the example schema or discoverability.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| fullHeightMode = settings.fullHeightMode ?? false; | ||
| snapToGrid = settings.snapToGrid ?? true; | ||
| legendVisible = settings.legendVisible ?? true; | ||
| function applySavedViewSettings(settings) { |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Suggestion: Normalize settings against a defaults object, then update the DOM separately, preserving behavior for empty, partial, and complete settings.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| return foreignKeys; | ||
| } | ||
|
|
||
| private static void CollectSnapshotForeignKeys(string snapshotContent, Dictionary<string, List<string>> foreignKeys) |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Suggestion: Split snapshot parsing into focused helpers and add coverage for malformed lines, multiple foreign keys, multiline fluent chains, and provider-specific formatting.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| } | ||
|
|
||
| public async Task<List<DbContextInfo>> FindDbContextFilesAsync(string repoUrl, string? accessToken = null) | ||
| public async Task<List<DbContextInfo>> FindDbContextFilesAsync(string repoUrl, string? accessToken) |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Suggestion: Extract the repository validation and search strategies into focused helpers, preserving user-facing errors and adding tests for invalid URLs, access failures, rate limits, and fallback search failures.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
…file URI argument
…s handling; move fixture entities to Models
Stacked on #33 (merge that first; this branch contains its commits).