Skip to content

feat: Prevent MaxCacheSize validation bypass via object initializers#1939

Merged
DaveSkender merged 3 commits intotest-pruningfrom
copilot/sub-pr-1937-again
Jan 26, 2026
Merged

feat: Prevent MaxCacheSize validation bypass via object initializers#1939
DaveSkender merged 3 commits intotest-pruningfrom
copilot/sub-pr-1937-again

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

MaxCacheSize could be set through object initializers, bypassing constructor validation that enforces bounds checking (0 < size < 0.8 * int.MaxValue).

Changes

  • StreamHub.Observable.cs: Changed MaxCacheSize from { get; init; } to { get; private set; }
  • BaseProvider.cs: Added constructor parameter to accept and store maxCacheSize
  • Quote.StreamHub.cs: Extracted validation logic to static helper method, passes validated value through BaseProvider to StreamHub base constructor
  • Test files: Updated object initializer syntax to constructor parameter syntax in test files and simulation tools

Before/After

// Before - could bypass validation
QuoteHub hub = new() { MaxCacheSize = int.MaxValue }; // No validation!

// After - validation enforced through constructor
QuoteHub hub = new(int.MaxValue); // Throws ArgumentOutOfRangeException
QuoteHub hub = new(1500); // Valid

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Changes MaxCacheSize from `init` to `private set` to prevent circumventing size validation through object initializers. The property can now only be set through the QuoteHub constructor which performs proper validation.

- Changed StreamHub.MaxCacheSize accessor from `init` to `private set`
- Updated BaseProvider to accept maxCacheSize parameter in constructor
- Refactored QuoteHub to validate maxCacheSize and pass to BaseProvider
- Updated all references using object initializer syntax to use constructor parameter
- All tests passing, no build or lint issues

Co-authored-by: DaveSkender <[email protected]>
Copilot AI changed the title [WIP] Add additional stream hub pruning test coverage feat: Prevent MaxCacheSize validation bypass via object initializers Jan 26, 2026
Copilot AI requested a review from DaveSkender January 26, 2026 06:27
@DaveSkender DaveSkender marked this pull request as ready for review January 26, 2026 06:27
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request refactors cache size configuration in the QuoteHub and BaseProvider classes. QuoteHub now validates the maximum cache size parameter through a new private helper method before passing it to the base provider. BaseProvider introduces a constructor parameter to accept and store a configurable maximum cache size, replacing the previous hardcoded behavior. The StreamHub MaxCacheSize property changes from an init-only property to a privately settable property. Test files are updated to pass cache size values through the constructor rather than using object initializer syntax.

Possibly related PRs


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@DaveSkender
Copy link
Owner

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2026

✅ Actions performed

Full review triggered.

Copy link
Contributor

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/_common/Quotes/Quote.StreamHub.cs (1)

34-47: Include offending value in the out-of-range message (and align bounds wording).

The message omits the actual value and implies a strict “less than” bound even though the code allows the inclusive upper bound.

✏️ Proposed update
-            string message
-                = $"'{nameof(maxCacheSize)}' must be greater than 0 and less than {absoluteMaxCacheSize}.";
+            string message
+                = $"'{nameof(maxCacheSize)}' must be between 1 and {absoluteMaxCacheSize}. Actual: {maxCacheSize}.";
As per coding guidelines, error messages should include the parameter name and offending value.

@DaveSkender DaveSkender merged commit 9898601 into test-pruning Jan 26, 2026
9 checks passed
@DaveSkender DaveSkender deleted the copilot/sub-pr-1937-again branch January 26, 2026 07:09
Copilot AI added a commit that referenced this pull request Jan 26, 2026
- Fixed MaxCacheSize setter errors from base PR #1939 (now constructor param)
- Increased Hurst cache to 120 (100-period + 20 extra)
- Increased PMO cache to 100 (35-period + 65 extra) - NOW PASSING
- Increased EPMA cache to 100 (20-period + 80 extra)
- Increased Slope cache to 100 (14-period + 86 extra)
- Fixed Renko formatting issues (whitespace)
- 77/80 tests passing (96.25%), 3 remaining require algorithm investigation

Co-authored-by: DaveSkender <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants