danmayer / coverband

Ruby production code coverage collection and reporting (line of code usage)
https://github.com/danmayer/coverband
MIT License
2.46k stars 157 forks source link

Rails routes being mounted counts as runtime line hits, but should be load time #543

Open kieran-flex opened 2 months ago

kieran-flex commented 2 months ago

Describe the bug When doing "mount API:RootAPI => '/' at startup to mount all of our APIs in Rails (we use Grape for the actual APIs) then it cascades through all of the initialisation code in those Controllers an related code and includes them in coverage but marks it all as runtime. It then makes it really hard to tell if an API is actually used because it says lots of code is used at runtime, when really none is and it is all just load time. How is load time versus runtime worked out? Can I force anything that happens during route mounting to be considered load time?

Screenshots below:

Screenshot 2024-06-26 at 17 46 46 Screenshot 2024-06-26 at 17 48 04
danmayer commented 2 months ago

hmmm... so runtime vs loading is triggered based on when we think the full app has been eagerly loaded... this might be different for how grape hooks into routes... Does our app have eager_loading for rails, I would assume it loads all of your grape files at that time.... I know some graphql libraries have problems where most of the graph is defining a schema and not used at run time... I don't use grape, so I might need a small sample app or PR on the coverband_rails demo app reproducing the issue for me to fix it.