Skip to content

ref: revert accessibility change in AssemblyStoreReader#4868

Closed
Flash0ver wants to merge 3 commits intomainfrom
test/use-TestAccessor-pattern
Closed

ref: revert accessibility change in AssemblyStoreReader#4868
Flash0ver wants to merge 3 commits intomainfrom
test/use-TestAccessor-pattern

Conversation

@Flash0ver
Copy link
Member

@Flash0ver Flash0ver commented Jan 23, 2026

Follow-up to

I wanted to give The TestAccessor Pattern from Roslyn a try.
See comments.

But changed to deriving a file-local type and use it in the test, as originally suggested.

We eventually decided against this change.
Making one member internal is just less code to maintain than derived types and/or Test-Accessors.

@Flash0ver Flash0ver self-assigned this Jan 23, 2026
Comment on lines 5 to 18
internal TestAccessor GetTestAccessor()
=> new(this);

internal readonly struct TestAccessor
{
private readonly StoreReader _instance;

internal TestAccessor(StoreReader instance)
{
_instance = instance;
}

internal bool IsSupported() => _instance.IsSupported();
}
Copy link
Member Author

@Flash0ver Flash0ver Jan 23, 2026

Choose a reason for hiding this comment

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

question: What do you think about Roslyn's TestAccessor Pattern in this case?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like there are pros and cons.

Pros:

  • I like the fact that it's explicit about what is being exposed and why.
  • It would allow us to leave some stuff private... although I can't remember a time when we got into trouble over the distinction between private and internal so I think in practice this is a negligible benefit

Cons:

  • It is way more verbose than just changing the visibility of stuff to internal

I think we could do it for new code if we really wanted to. It's really a styling choice. For existing code, it's a whole lot of work for practically no benefit at all...

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your feedback.
I removed the TestAccessor, and replaced it with a derived file-local type, as originally suggested in https://github.com/getsentry/sentry-dotnet/pull/4814/changes#r2707861556.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't that also sometimes require changing member visibility just for testing (e.g. private -> protected)? And we couldn't do this for sealed classes either.

What is the key problem we're trying to solve here?

  1. The risk of one of the maintainers using an internal member when they shouldn't?
  2. The lack of clarity around why some members are internal?
  3. Something else?

I don't think 1 is a serious concern... especially given our review process. 2 is usually handled by the compiler... if you try to make those internal members private, the tests won't compile anymore... 3 then?

It would be nice/pretty if C# had an attribute you could decorate members with to say they're public only to test assemblies... but short of that, I don't think there are any workarounds that don't come with both pros and cons. I think the approach we've been taking so far (using InternalsVisibleTo) is probably the best available alternative... it requires very little work, doesn't affect the source types at all for SDK users and has very little risk. It's not 'pretty' is about my only complaint with it but I think we have to be pragmatic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point!
You convinced me.

Let's keep it as is.
Thanks for your feedback.

@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.86%. Comparing base (a45876f) to head (1b42e1e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4868   +/-   ##
=======================================
  Coverage   73.85%   73.86%           
=======================================
  Files         483      483           
  Lines       17577    17577           
  Branches     3464     3464           
=======================================
+ Hits        12982    12983    +1     
  Misses       3741     3741           
+ Partials      854      853    -1     

☔ 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.

@Flash0ver Flash0ver marked this pull request as ready for review January 24, 2026 18:04
@Flash0ver
Copy link
Member Author

@sentry review

@Flash0ver Flash0ver changed the title test: use TestAccessor pattern ref: revert accessibility change in AssemblyStoreReader Jan 27, 2026
@Flash0ver Flash0ver closed this Jan 28, 2026
@Flash0ver Flash0ver deleted the test/use-TestAccessor-pattern branch January 28, 2026 13:42
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